From fd4dc74849d0084290063165b256d8d984caf697 Mon Sep 17 00:00:00 2001 From: xhc <15171145581@163.com> Date: Mon, 9 Jun 2025 15:58:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B7=A1=E6=A3=80=E7=82=B9=E4=BD=8D=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=B0=B4=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/hpy-watermark.vue | 344 ------------------ src/components/image-watermark-picker.vue | 85 +++-- src/components/waterMarker.vue | 147 -------- src/pages/index/index.vue | 3 +- src/pages/my/my.vue | 8 +- src/pages/points/points.vue | 152 +++----- src/uni_modules/hpy-watermark/changelog.md | 5 - .../hpy-watermark/hpy-watermark.vue | 198 ---------- src/uni_modules/hpy-watermark/package.json | 83 ----- src/uni_modules/hpy-watermark/readme.md | 201 ---------- 10 files changed, 116 insertions(+), 1110 deletions(-) delete mode 100644 src/components/hpy-watermark.vue delete mode 100644 src/components/waterMarker.vue delete mode 100644 src/uni_modules/hpy-watermark/changelog.md delete mode 100644 src/uni_modules/hpy-watermark/components/hpy-watermark/hpy-watermark.vue delete mode 100644 src/uni_modules/hpy-watermark/package.json delete mode 100644 src/uni_modules/hpy-watermark/readme.md diff --git a/src/components/hpy-watermark.vue b/src/components/hpy-watermark.vue deleted file mode 100644 index e7f91c5..0000000 --- a/src/components/hpy-watermark.vue +++ /dev/null @@ -1,344 +0,0 @@ - - - - - \ No newline at end of file diff --git a/src/components/image-watermark-picker.vue b/src/components/image-watermark-picker.vue index 461b58b..b2bf448 100644 --- a/src/components/image-watermark-picker.vue +++ b/src/components/image-watermark-picker.vue @@ -18,7 +18,7 @@ - + { + await this.sleep(200) // 某些平台 canvas 渲染慢,需要等待 const ctx = uni.createCanvasContext('watermark-canvas', this) + ctx.clearRect(0, 0, res.width, res.height) ctx.beginPath() ctx.drawImage(tempFilePath, 0, 0, res.width, res.height) - - // 水印 字体大小,颜色,内容,位置 ctx.beginPath() ctx.setFontSize(24) ctx.setFillStyle('rgba(250,250,250,0.8)') - ctx.fillText('我是水印1', 60, res.height - 90) - ctx.fillText('我是水印2', 60, res.height - 60) - }) + // 动态绘制水印内容 + if (Array.isArray(this.watermarkTexts)) { + this.watermarkTexts.forEach((text, idx) => { + ctx.fillText(text, 60, res.height - 90 + idx * 30) + }) + } else if (typeof this.watermarkTexts === 'string') { + ctx.fillText('拍摄人:'+this.watermarkTexts, 60, res.height - 90) + } + ctx.fillText('拍摄时间:'+this.getCurrentDateTime(), 60, res.height - 60) + // 开始绘制 (canvas -> 临时文件路径) - ctx.draw(false, async () => { - await this.sleep(1000) // 某些平台 canvas 渲染慢,需要等待 + ctx.draw(false, async () => { + + await this.sleep(300) // 某些平台 canvas 渲染慢,需要等待 uni.canvasToTempFilePath( { @@ -198,7 +223,7 @@ export default { destHeight: res.height, fileType: 'jpg', quality: 0.8, - success: (fileRes) => { + success: (fileRes) => { resolve(fileRes.tempFilePath) }, fail: (err) => { @@ -246,6 +271,18 @@ export default { setTimeout(resolve, millisecond) }) }, + // 获取当前日期时间,格式:2025-06-09 14:30:15 + getCurrentDateTime() { + const now = new Date(); + const pad = n => n.toString().padStart(2, '0'); + const year = now.getFullYear(); + const month = pad(now.getMonth() + 1); + const day = pad(now.getDate()); + const hour = pad(now.getHours()); + const minute = pad(now.getMinutes()); + const second = pad(now.getSeconds()); + return `${year}-${month}-${day} ${hour}:${minute}:${second}`; + }, }, } @@ -254,13 +291,13 @@ export default { .image-picker { position: relative; - .form-item-column-center { - display: flex; - align-items: center; - justify-content: center; - flex: 1; - flex-direction: column; - } +// .form-item-column-center { +// display: flex; +// align-items: center; +// justify-content: center; +// flex: 1; +// flex-direction: column; +// } .watermark-canvas { position: absolute; diff --git a/src/components/waterMarker.vue b/src/components/waterMarker.vue deleted file mode 100644 index 7cdef7f..0000000 --- a/src/components/waterMarker.vue +++ /dev/null @@ -1,147 +0,0 @@ - - - \ No newline at end of file diff --git a/src/pages/index/index.vue b/src/pages/index/index.vue index 6b3a5ab..2e89d99 100644 --- a/src/pages/index/index.vue +++ b/src/pages/index/index.vue @@ -2,7 +2,7 @@ * @Author: XHC * @Date: 2025-05-19 11:07:37 * @LastEditors: XHC - * @LastEditTime: 2025-06-06 17:40:38 + * @LastEditTime: 2025-06-09 09:40:25 * @Description: 首页 -->