當前位置:編程學習大全網 - 源碼下載 - uni-app添加水印,並且實現循環展示

uni-app添加水印,並且實現循環展示

<template>

<view>

<button @tap="add">增加</button>

<view class="file" v-if="filepath.length>0" v-for="(filepath,index) in filesArray" :key="index" >

<image? :src=filepath[0] mode="scaleToFill" v-on:click="preview(filepath)" >{{filepath}}</image>

<view class="del" @tap="deleleImg(index)">x</view>

</view>

<view style="position: absolute;top: -999999px;">

<canvas :style="{width:w,height: h}"? canvas-id="firstCanvas" id="firstCanvas"></canvas>

</view>

</view>

</template>

<style>

</style>

<script>

export default {

data() {

return {

w:'1980px',

h:'2340px',

filesArray: []

}

},

methods: {

preview(filepath){

console.log(filepath)

uni.previewImage({

urls:filepath,

current:0

})

},

add() {

uni.chooseImage({

count: 1,

sizeType: ['original', "compressed"],

sourceType: ['album', 'camera'],

success: (res => {

let array=[];

uni.getImageInfo({

src: res.tempFilePaths[0],

success: function(image) {

/*讀取成功進行cavens繪圖*/

this.w = image.width + 'px'

this.h = image.height + 'px'

const ctx = uni.createCanvasContext('firstCanvas')

ctx.drawImage(res.tempFilePaths[0], 0, 0, image.width, image.height)

ctx.setFontSize(60)

ctx.setFillStyle('#FFFFFF')

ctx.fillText(new Date(), 20, 80)

ctx.draw(false, () => {

uni.canvasToTempFilePath({

x: 0,

y: 0,

width: image.width,

height: image.width,

destWidth: image.width,

destHeight: image.width,

canvasId: 'firstCanvas',

success:function(res){

uni.saveImageToPhotosAlbum({

filePath:res.tempFilePath,

success: function () {

uni.showToast({

title: '標題',

duration: 2000

});

}

});

array.push(res.tempFilePath)

}

})

})

}

});

? this.filesArray.push(array)

})

})

},

deleleImg(index) {

uni.showModal({

title: '提示',

content: "確定要刪除此項嗎?",

success: res => {

if (res.confirm) {

this.filesArray.splice(index, 1);

}

}

})

},

upload(){

}

}

}

</script>

  • 上一篇:JAVA ssh項目人力資源管理系統的權限管理該怎麽設計
  • 下一篇:華為雲翻新不支持app
  • copyright 2024編程學習大全網