hy-app 0.3.1 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/common/shakeService.ts +31 -29
- package/components/avatar.zip +0 -0
- package/components/hy-action-sheet/hy-action-sheet.vue +71 -46
- package/components/hy-address-picker/hy-address-picker.vue +94 -83
- package/components/hy-avatar/hy-avatar.vue +84 -85
- package/components/hy-badge/hy-badge.vue +47 -46
- package/components/hy-button/hy-button.vue +117 -93
- package/components/hy-calendar/hy-calendar.vue +168 -160
- package/components/hy-card/hy-card.vue +50 -43
- package/components/hy-card/typing.d.ts +33 -32
- package/components/hy-cell/hy-cell.vue +73 -51
- package/components/hy-check-button/hy-check-button.vue +54 -47
- package/components/hy-checkbox/hy-checkbox.vue +97 -105
- package/components/hy-code-input/hy-code-input.vue +80 -89
- package/components/hy-config-provider/hy-config-provider.vue +19 -20
- package/components/hy-count-down/hy-count-down.vue +66 -67
- package/components/hy-count-to/hy-count-to.vue +105 -99
- package/components/hy-count-to/typing.d.ts +13 -12
- package/components/hy-datetime-picker/hy-datetime-picker.vue +261 -253
- package/components/hy-datetime-picker/typing.d.ts +42 -40
- package/components/hy-divider/hy-divider.vue +68 -73
- package/components/hy-dropdown/hy-dropdown.vue +20 -19
- package/components/hy-dropdown-item/hy-dropdown-item.vue +66 -61
- package/components/hy-dropdown-item/typing.d.ts +9 -9
- package/components/hy-empty/hy-empty.vue +42 -42
- package/components/hy-flex/hy-flex.vue +52 -26
- package/components/hy-float-button/hy-float-button.vue +218 -210
- package/components/hy-folding-panel/hy-folding-panel.vue +32 -33
- package/components/hy-form/hy-form.vue +264 -259
- package/components/hy-grid/hy-grid.vue +44 -43
- package/components/hy-icon/hy-icon.vue +61 -67
- package/components/hy-image/hy-image.vue +112 -88
- package/components/hy-image/typing.d.ts +27 -23
- package/components/hy-input/hy-input.vue +157 -127
- package/components/hy-input/typing.d.ts +53 -47
- package/components/hy-line/hy-line.vue +26 -26
- package/components/hy-line-progress/hy-line-progress.vue +42 -35
- package/components/hy-list/hy-list.vue +76 -85
- package/components/hy-loading/hy-loading.vue +26 -23
- package/components/hy-menu/hy-menu.vue +48 -43
- package/components/hy-menu/typing.d.ts +18 -17
- package/components/hy-modal/hy-modal.vue +39 -35
- package/components/hy-navbar/hy-navbar.vue +25 -25
- package/components/hy-navbar/typing.d.ts +24 -22
- package/components/hy-notice-bar/hy-notice-bar.vue +26 -27
- package/components/hy-notify/hy-notify.vue +53 -53
- package/components/hy-number-step/hy-number-step.vue +134 -146
- package/components/hy-number-step/typing.d.ts +35 -35
- package/components/hy-overlay/hy-overlay.vue +23 -21
- package/components/hy-pagination/hy-pagination.vue +41 -36
- package/components/hy-picker/hy-picker.vue +184 -154
- package/components/hy-picker/typing.d.ts +39 -39
- package/components/hy-popover/hy-popover.vue +97 -77
- package/components/hy-popup/hy-popup.vue +107 -98
- package/components/hy-price/hy-price.vue +38 -34
- package/components/hy-qrcode/hy-qrcode.vue +50 -51
- package/components/hy-radio/hy-radio.vue +101 -113
- package/components/hy-rate/hy-rate.vue +107 -88
- package/components/hy-read-more/hy-read-more.vue +64 -49
- package/components/hy-scroll-list/hy-scroll-list.vue +45 -48
- package/components/hy-search/hy-search.vue +73 -66
- package/components/hy-search/typing.d.ts +36 -35
- package/components/hy-signature/hy-signature.vue +282 -240
- package/components/hy-slider/hy-slider.vue +195 -153
- package/components/hy-slider/typing.d.ts +21 -21
- package/components/hy-steps/hy-steps.vue +118 -90
- package/components/hy-steps/index.scss +31 -21
- package/components/hy-submit-bar/hy-submit-bar.vue +61 -70
- package/components/hy-subsection/hy-subsection.vue +99 -102
- package/components/hy-subsection/typing.d.ts +19 -19
- package/components/hy-swipe-action/hy-swipe-action.vue +131 -118
- package/components/hy-swiper/hy-swiper.vue +85 -71
- package/components/hy-switch/hy-switch.vue +67 -72
- package/components/hy-switch/typing.d.ts +21 -19
- package/components/hy-tabs/hy-tabs.vue +168 -113
- package/components/hy-tag/hy-tag.vue +90 -86
- package/components/hy-tag/typing.d.ts +26 -21
- package/components/hy-text/hy-text.vue +119 -111
- package/components/hy-textarea/hy-textarea.vue +100 -93
- package/components/hy-textarea/typing.d.ts +36 -31
- package/components/hy-toast/hy-toast.vue +77 -67
- package/components/hy-tooltip/hy-tooltip.vue +109 -91
- package/components/hy-transition/hy-transition.vue +62 -66
- package/components/hy-upload/hy-upload.vue +294 -152
- package/components/hy-upload/typing.d.ts +41 -36
- package/components/hy-warn/hy-warn.vue +34 -27
- package/components/hy-waterfall/hy-waterfall.vue +83 -74
- package/components/hy-watermark/hy-watermark.vue +134 -115
- package/composables/usePopover.ts +236 -221
- package/composables/useQueue.ts +53 -52
- package/package.json +2 -2
- package/store/index.ts +9 -1
- package/typing/index.ts +0 -1
- package/typing/modules/common.d.ts +0 -2
- package/web-types.json +1 -1
|
@@ -16,33 +16,37 @@
|
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
18
|
export default {
|
|
19
|
-
name:
|
|
19
|
+
name: "hy-watermark",
|
|
20
20
|
options: {
|
|
21
21
|
addGlobalClass: true,
|
|
22
22
|
virtualHost: true,
|
|
23
|
-
styleIsolation:
|
|
23
|
+
styleIsolation: "shared",
|
|
24
24
|
},
|
|
25
|
-
}
|
|
25
|
+
};
|
|
26
26
|
</script>
|
|
27
27
|
|
|
28
28
|
<script lang="ts" setup>
|
|
29
|
-
import { computed, onMounted, ref, watch, nextTick
|
|
30
|
-
import {
|
|
29
|
+
import { computed, onMounted, ref, watch, nextTick } from "vue";
|
|
30
|
+
import type { CSSProperties } from "vue";
|
|
31
|
+
import { addUnit, guid } from "../../utils";
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* 在页面或组件上添加指定的图片或文字,可用于版权保护、品牌宣传等场景。
|
|
34
35
|
* @displayName hy-watermark
|
|
35
36
|
*/
|
|
36
|
-
defineOptions({})
|
|
37
|
+
defineOptions({});
|
|
37
38
|
|
|
38
39
|
// const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
39
40
|
const props = defineProps({
|
|
40
41
|
/** 显示内容 */
|
|
41
|
-
content:
|
|
42
|
+
content: {
|
|
43
|
+
type: String,
|
|
44
|
+
default: "",
|
|
45
|
+
},
|
|
42
46
|
/** 显示图片的地址,支持网络图片和base64(钉钉小程序仅支持网络图片) */
|
|
43
47
|
image: {
|
|
44
48
|
type: String,
|
|
45
|
-
default:
|
|
49
|
+
default: "",
|
|
46
50
|
},
|
|
47
51
|
/** 图片高度 */
|
|
48
52
|
imageHeight: {
|
|
@@ -82,7 +86,7 @@ const props = defineProps({
|
|
|
82
86
|
/** 水印字体颜色 */
|
|
83
87
|
color: {
|
|
84
88
|
type: String,
|
|
85
|
-
default:
|
|
89
|
+
default: "#8c8c8c",
|
|
86
90
|
},
|
|
87
91
|
/** 水印字体大小,单位px */
|
|
88
92
|
size: {
|
|
@@ -92,17 +96,17 @@ const props = defineProps({
|
|
|
92
96
|
/** 水印字体样式(仅微信和h5支持) */
|
|
93
97
|
fontStyle: {
|
|
94
98
|
type: String,
|
|
95
|
-
default:
|
|
99
|
+
default: "",
|
|
96
100
|
},
|
|
97
101
|
/** 水印字体的粗细 */
|
|
98
102
|
fontWeight: {
|
|
99
103
|
type: String,
|
|
100
|
-
default:
|
|
104
|
+
default: "",
|
|
101
105
|
},
|
|
102
106
|
/** 水印字体系列(仅微信和h5支持) */
|
|
103
107
|
fontFamily: {
|
|
104
108
|
type: String,
|
|
105
|
-
default:
|
|
109
|
+
default: "PingFang SC",
|
|
106
110
|
},
|
|
107
111
|
/** 水印旋转角度 */
|
|
108
112
|
rotate: {
|
|
@@ -119,36 +123,40 @@ const props = defineProps({
|
|
|
119
123
|
type: Number,
|
|
120
124
|
default: 0.5,
|
|
121
125
|
},
|
|
122
|
-
})
|
|
126
|
+
});
|
|
123
127
|
|
|
124
128
|
watch(
|
|
125
129
|
() => props,
|
|
126
130
|
() => {
|
|
127
|
-
doReset()
|
|
131
|
+
doReset();
|
|
128
132
|
},
|
|
129
133
|
{ deep: true },
|
|
130
|
-
)
|
|
134
|
+
);
|
|
131
135
|
|
|
132
|
-
const canvasId = ref<string>(`watermark--${guid()}`) // canvas 组件的唯一标识符
|
|
133
|
-
const waterMarkUrl = ref<string>(
|
|
136
|
+
const canvasId = ref<string>(`watermark--${guid()}`); // canvas 组件的唯一标识符
|
|
137
|
+
const waterMarkUrl = ref<string>(""); // canvas生成base64水印
|
|
134
138
|
const canvasOffScreenable = ref<boolean>(
|
|
135
|
-
uni.canIUse(
|
|
136
|
-
) // 是否可以使用离屏canvas
|
|
137
|
-
const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio) // 像素比
|
|
138
|
-
const canvasHeight = ref<number>(
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
uni.canIUse("createOffscreenCanvas") && Boolean(uni.createOffscreenCanvas),
|
|
140
|
+
); // 是否可以使用离屏canvas
|
|
141
|
+
const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio); // 像素比
|
|
142
|
+
const canvasHeight = ref<number>(
|
|
143
|
+
(props.height + props.gutterY) * pixelRatio.value,
|
|
144
|
+
); // canvas画布高度
|
|
145
|
+
const canvasWidth = ref<number>(
|
|
146
|
+
(props.width + props.gutterX) * pixelRatio.value,
|
|
147
|
+
); // canvas画布宽度
|
|
148
|
+
const showCanvas = ref<boolean>(true); // 是否展示canvas
|
|
141
149
|
|
|
142
150
|
/**
|
|
143
151
|
* @description 水印css类
|
|
144
152
|
*/
|
|
145
153
|
const rootClass = computed(() => {
|
|
146
|
-
const classes: string[] = [
|
|
154
|
+
const classes: string[] = ["hy-watermark"];
|
|
147
155
|
if (props.fullScreen) {
|
|
148
|
-
classes.push(
|
|
156
|
+
classes.push("is-fullscreen");
|
|
149
157
|
}
|
|
150
|
-
return classes
|
|
151
|
-
})
|
|
158
|
+
return classes;
|
|
159
|
+
});
|
|
152
160
|
|
|
153
161
|
/**
|
|
154
162
|
* @description 水印样式
|
|
@@ -157,30 +165,30 @@ const rootStyle = computed(() => {
|
|
|
157
165
|
const style: CSSProperties = {
|
|
158
166
|
opacity: props.opacity,
|
|
159
167
|
backgroundSize: addUnit(props.width + props.gutterX),
|
|
160
|
-
}
|
|
168
|
+
};
|
|
161
169
|
if (waterMarkUrl.value) {
|
|
162
|
-
style[
|
|
170
|
+
style["backgroundImage"] = `url('${waterMarkUrl.value}')`;
|
|
163
171
|
}
|
|
164
|
-
return style
|
|
165
|
-
})
|
|
172
|
+
return style;
|
|
173
|
+
});
|
|
166
174
|
|
|
167
175
|
onMounted(() => {
|
|
168
|
-
doInit()
|
|
169
|
-
})
|
|
176
|
+
doInit();
|
|
177
|
+
});
|
|
170
178
|
|
|
171
179
|
function doReset() {
|
|
172
|
-
showCanvas.value = true
|
|
173
|
-
canvasHeight.value = (props.height + props.gutterY) * pixelRatio.value
|
|
174
|
-
canvasWidth.value = (props.width + props.gutterX) * pixelRatio.value
|
|
180
|
+
showCanvas.value = true;
|
|
181
|
+
canvasHeight.value = (props.height + props.gutterY) * pixelRatio.value;
|
|
182
|
+
canvasWidth.value = (props.width + props.gutterX) * pixelRatio.value;
|
|
175
183
|
nextTick(() => {
|
|
176
|
-
doInit()
|
|
177
|
-
})
|
|
184
|
+
doInit();
|
|
185
|
+
});
|
|
178
186
|
}
|
|
179
187
|
|
|
180
188
|
function doInit() {
|
|
181
189
|
// #ifdef H5
|
|
182
190
|
// h5使用document.createElement创建canvas,不用展示canvas标签
|
|
183
|
-
showCanvas.value = false
|
|
191
|
+
showCanvas.value = false;
|
|
184
192
|
// #endif
|
|
185
193
|
const {
|
|
186
194
|
width,
|
|
@@ -197,7 +205,7 @@ function doInit() {
|
|
|
197
205
|
image,
|
|
198
206
|
imageHeight,
|
|
199
207
|
imageWidth,
|
|
200
|
-
} = props
|
|
208
|
+
} = props;
|
|
201
209
|
|
|
202
210
|
// 创建水印
|
|
203
211
|
createWaterMark(
|
|
@@ -215,7 +223,7 @@ function doInit() {
|
|
|
215
223
|
image,
|
|
216
224
|
imageHeight,
|
|
217
225
|
imageWidth,
|
|
218
|
-
)
|
|
226
|
+
);
|
|
219
227
|
}
|
|
220
228
|
|
|
221
229
|
/**
|
|
@@ -251,11 +259,11 @@ function createWaterMark(
|
|
|
251
259
|
imageHeight: number,
|
|
252
260
|
imageWidth: number,
|
|
253
261
|
) {
|
|
254
|
-
const canvasHeight = (height + gutterY) * pixelRatio.value
|
|
255
|
-
const canvasWidth = (width + gutterX) * pixelRatio.value
|
|
256
|
-
const contentWidth = width * pixelRatio.value
|
|
257
|
-
const contentHeight = height * pixelRatio.value
|
|
258
|
-
const fontSize = size * pixelRatio.value
|
|
262
|
+
const canvasHeight = (height + gutterY) * pixelRatio.value;
|
|
263
|
+
const canvasWidth = (width + gutterX) * pixelRatio.value;
|
|
264
|
+
const contentWidth = width * pixelRatio.value;
|
|
265
|
+
const contentHeight = height * pixelRatio.value;
|
|
266
|
+
const fontSize = size * pixelRatio.value;
|
|
259
267
|
// #ifndef H5
|
|
260
268
|
if (canvasOffScreenable.value) {
|
|
261
269
|
createOffscreenCanvas(
|
|
@@ -273,7 +281,7 @@ function createWaterMark(
|
|
|
273
281
|
image,
|
|
274
282
|
imageHeight,
|
|
275
283
|
imageWidth,
|
|
276
|
-
)
|
|
284
|
+
);
|
|
277
285
|
} else {
|
|
278
286
|
createCanvas(
|
|
279
287
|
canvasHeight,
|
|
@@ -285,7 +293,7 @@ function createWaterMark(
|
|
|
285
293
|
image,
|
|
286
294
|
imageHeight,
|
|
287
295
|
imageWidth,
|
|
288
|
-
)
|
|
296
|
+
);
|
|
289
297
|
}
|
|
290
298
|
// #endif
|
|
291
299
|
// #ifdef H5
|
|
@@ -304,7 +312,7 @@ function createWaterMark(
|
|
|
304
312
|
image,
|
|
305
313
|
imageHeight,
|
|
306
314
|
imageWidth,
|
|
307
|
-
)
|
|
315
|
+
);
|
|
308
316
|
// #endif
|
|
309
317
|
}
|
|
310
318
|
|
|
@@ -345,12 +353,12 @@ function createOffscreenCanvas(
|
|
|
345
353
|
const canvas: any = uni.createOffscreenCanvas({
|
|
346
354
|
height: canvasHeight,
|
|
347
355
|
width: canvasWidth,
|
|
348
|
-
type:
|
|
349
|
-
})
|
|
350
|
-
const ctx: any = canvas.getContext(
|
|
356
|
+
type: "2d",
|
|
357
|
+
});
|
|
358
|
+
const ctx: any = canvas.getContext("2d");
|
|
351
359
|
if (ctx) {
|
|
352
360
|
if (image) {
|
|
353
|
-
const img = canvas.createImage() as HTMLImageElement
|
|
361
|
+
const img = canvas.createImage() as HTMLImageElement;
|
|
354
362
|
drawImageOffScreen(
|
|
355
363
|
ctx,
|
|
356
364
|
img,
|
|
@@ -361,7 +369,7 @@ function createOffscreenCanvas(
|
|
|
361
369
|
contentWidth,
|
|
362
370
|
contentHeight,
|
|
363
371
|
canvas,
|
|
364
|
-
)
|
|
372
|
+
);
|
|
365
373
|
} else {
|
|
366
374
|
drawTextOffScreen(
|
|
367
375
|
ctx,
|
|
@@ -375,10 +383,10 @@ function createOffscreenCanvas(
|
|
|
375
383
|
fontWeight,
|
|
376
384
|
color,
|
|
377
385
|
canvas,
|
|
378
|
-
)
|
|
386
|
+
);
|
|
379
387
|
}
|
|
380
388
|
} else {
|
|
381
|
-
console.error(
|
|
389
|
+
console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
|
|
382
390
|
}
|
|
383
391
|
}
|
|
384
392
|
|
|
@@ -406,15 +414,23 @@ function createCanvas(
|
|
|
406
414
|
imageHeight: number,
|
|
407
415
|
imageWidth: number,
|
|
408
416
|
) {
|
|
409
|
-
const ctx = uni.createCanvasContext(canvasId.value)
|
|
417
|
+
const ctx = uni.createCanvasContext(canvasId.value);
|
|
410
418
|
if (ctx) {
|
|
411
419
|
if (image) {
|
|
412
|
-
drawImageOnScreen(
|
|
420
|
+
drawImageOnScreen(
|
|
421
|
+
ctx,
|
|
422
|
+
image,
|
|
423
|
+
imageHeight,
|
|
424
|
+
imageWidth,
|
|
425
|
+
rotate,
|
|
426
|
+
contentWidth,
|
|
427
|
+
contentHeight,
|
|
428
|
+
);
|
|
413
429
|
} else {
|
|
414
|
-
drawTextOnScreen(ctx, content, contentWidth, rotate, fontSize, color)
|
|
430
|
+
drawTextOnScreen(ctx, content, contentWidth, rotate, fontSize, color);
|
|
415
431
|
}
|
|
416
432
|
} else {
|
|
417
|
-
console.error(
|
|
433
|
+
console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
|
|
418
434
|
}
|
|
419
435
|
}
|
|
420
436
|
|
|
@@ -431,6 +447,9 @@ function createCanvas(
|
|
|
431
447
|
* @param fontWeight 水印字体字重
|
|
432
448
|
* @param color 水印字体颜色
|
|
433
449
|
* @param content 水印内容
|
|
450
|
+
* @param image canvas图片
|
|
451
|
+
* @param imageHeight canvas图片高度
|
|
452
|
+
* @param imageWidth canvas图片宽度
|
|
434
453
|
*/
|
|
435
454
|
function createH5Canvas(
|
|
436
455
|
canvasHeight: number,
|
|
@@ -448,13 +467,13 @@ function createH5Canvas(
|
|
|
448
467
|
imageHeight: number,
|
|
449
468
|
imageWidth: number,
|
|
450
469
|
) {
|
|
451
|
-
const canvas = document.createElement(
|
|
452
|
-
const ctx = canvas.getContext(
|
|
453
|
-
canvas.setAttribute(
|
|
454
|
-
canvas.setAttribute(
|
|
470
|
+
const canvas = document.createElement("canvas");
|
|
471
|
+
const ctx = canvas.getContext("2d");
|
|
472
|
+
canvas.setAttribute("width", `${canvasWidth}px`);
|
|
473
|
+
canvas.setAttribute("height", `${canvasHeight}px`);
|
|
455
474
|
if (ctx) {
|
|
456
475
|
if (image) {
|
|
457
|
-
const img = new Image()
|
|
476
|
+
const img = new Image();
|
|
458
477
|
drawImageOffScreen(
|
|
459
478
|
ctx,
|
|
460
479
|
img,
|
|
@@ -465,7 +484,7 @@ function createH5Canvas(
|
|
|
465
484
|
contentWidth,
|
|
466
485
|
contentHeight,
|
|
467
486
|
canvas,
|
|
468
|
-
)
|
|
487
|
+
);
|
|
469
488
|
} else {
|
|
470
489
|
drawTextOffScreen(
|
|
471
490
|
ctx,
|
|
@@ -479,10 +498,10 @@ function createH5Canvas(
|
|
|
479
498
|
fontWeight,
|
|
480
499
|
color,
|
|
481
500
|
canvas,
|
|
482
|
-
)
|
|
501
|
+
);
|
|
483
502
|
}
|
|
484
503
|
} else {
|
|
485
|
-
console.error(
|
|
504
|
+
console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
|
|
486
505
|
}
|
|
487
506
|
}
|
|
488
507
|
|
|
@@ -513,15 +532,15 @@ function drawTextOffScreen(
|
|
|
513
532
|
color: string,
|
|
514
533
|
canvas: HTMLCanvasElement,
|
|
515
534
|
) {
|
|
516
|
-
ctx.textBaseline =
|
|
517
|
-
ctx.textAlign =
|
|
518
|
-
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
519
|
-
ctx.rotate((Math.PI / 180) * rotate)
|
|
520
|
-
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px ${fontFamily}
|
|
521
|
-
ctx.fillStyle = color
|
|
522
|
-
ctx.fillText(content, 0, 0)
|
|
523
|
-
ctx.restore()
|
|
524
|
-
waterMarkUrl.value = canvas.toDataURL()
|
|
535
|
+
ctx.textBaseline = "middle";
|
|
536
|
+
ctx.textAlign = "center";
|
|
537
|
+
ctx.translate(contentWidth / 2, contentWidth / 2);
|
|
538
|
+
ctx.rotate((Math.PI / 180) * rotate);
|
|
539
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px ${fontFamily}`;
|
|
540
|
+
ctx.fillStyle = color;
|
|
541
|
+
ctx.fillText(content, 0, 0);
|
|
542
|
+
ctx.restore();
|
|
543
|
+
waterMarkUrl.value = canvas.toDataURL();
|
|
525
544
|
}
|
|
526
545
|
|
|
527
546
|
/**
|
|
@@ -541,32 +560,32 @@ function drawTextOnScreen(
|
|
|
541
560
|
fontSize: number,
|
|
542
561
|
color: string,
|
|
543
562
|
) {
|
|
544
|
-
ctx.setTextBaseline(
|
|
545
|
-
ctx.setTextAlign(
|
|
546
|
-
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
547
|
-
ctx.rotate((Math.PI / 180) * rotate)
|
|
548
|
-
ctx.setFillStyle(color)
|
|
549
|
-
ctx.setFontSize(fontSize)
|
|
550
|
-
ctx.fillText(content, 0, 0)
|
|
551
|
-
ctx.restore()
|
|
552
|
-
ctx.draw()
|
|
563
|
+
ctx.setTextBaseline("middle");
|
|
564
|
+
ctx.setTextAlign("center");
|
|
565
|
+
ctx.translate(contentWidth / 2, contentWidth / 2);
|
|
566
|
+
ctx.rotate((Math.PI / 180) * rotate);
|
|
567
|
+
ctx.setFillStyle(color);
|
|
568
|
+
ctx.setFontSize(fontSize);
|
|
569
|
+
ctx.fillText(content, 0, 0);
|
|
570
|
+
ctx.restore();
|
|
571
|
+
ctx.draw();
|
|
553
572
|
// #ifdef MP-DINGTALK
|
|
554
573
|
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
555
|
-
|
|
574
|
+
(ctx as any).toTempFilePath({
|
|
556
575
|
success(res: any) {
|
|
557
|
-
showCanvas.value = false
|
|
558
|
-
waterMarkUrl.value = res.filePath
|
|
576
|
+
showCanvas.value = false;
|
|
577
|
+
waterMarkUrl.value = res.filePath;
|
|
559
578
|
},
|
|
560
|
-
})
|
|
579
|
+
});
|
|
561
580
|
// #endif
|
|
562
581
|
// #ifndef MP-DINGTALK
|
|
563
582
|
uni.canvasToTempFilePath({
|
|
564
583
|
canvasId: canvasId.value,
|
|
565
584
|
success: (res) => {
|
|
566
|
-
showCanvas.value = false
|
|
567
|
-
waterMarkUrl.value = res.tempFilePath
|
|
585
|
+
showCanvas.value = false;
|
|
586
|
+
waterMarkUrl.value = res.tempFilePath;
|
|
568
587
|
},
|
|
569
|
-
})
|
|
588
|
+
});
|
|
570
589
|
// #endif
|
|
571
590
|
}
|
|
572
591
|
|
|
@@ -593,12 +612,12 @@ async function drawImageOffScreen(
|
|
|
593
612
|
contentHeight: number,
|
|
594
613
|
canvas: HTMLCanvasElement,
|
|
595
614
|
) {
|
|
596
|
-
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
597
|
-
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
598
|
-
img.crossOrigin =
|
|
599
|
-
img.referrerPolicy =
|
|
615
|
+
ctx.translate(contentWidth / 2, contentHeight / 2);
|
|
616
|
+
ctx.rotate((Math.PI / 180) * Number(rotate));
|
|
617
|
+
img.crossOrigin = "anonymous";
|
|
618
|
+
img.referrerPolicy = "no-referrer";
|
|
600
619
|
|
|
601
|
-
img.src = image
|
|
620
|
+
img.src = image;
|
|
602
621
|
img.onload = () => {
|
|
603
622
|
ctx.drawImage(
|
|
604
623
|
img,
|
|
@@ -606,10 +625,10 @@ async function drawImageOffScreen(
|
|
|
606
625
|
(-imageHeight * pixelRatio.value) / 2,
|
|
607
626
|
imageWidth * pixelRatio.value,
|
|
608
627
|
imageHeight * pixelRatio.value,
|
|
609
|
-
)
|
|
610
|
-
ctx.restore()
|
|
611
|
-
waterMarkUrl.value = canvas.toDataURL()
|
|
612
|
-
}
|
|
628
|
+
);
|
|
629
|
+
ctx.restore();
|
|
630
|
+
waterMarkUrl.value = canvas.toDataURL();
|
|
631
|
+
};
|
|
613
632
|
}
|
|
614
633
|
|
|
615
634
|
/**
|
|
@@ -631,8 +650,8 @@ function drawImageOnScreen(
|
|
|
631
650
|
contentWidth: number,
|
|
632
651
|
contentHeight: number,
|
|
633
652
|
) {
|
|
634
|
-
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
635
|
-
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
653
|
+
ctx.translate(contentWidth / 2, contentHeight / 2);
|
|
654
|
+
ctx.rotate((Math.PI / 180) * Number(rotate));
|
|
636
655
|
|
|
637
656
|
ctx.drawImage(
|
|
638
657
|
image,
|
|
@@ -640,31 +659,31 @@ function drawImageOnScreen(
|
|
|
640
659
|
(-imageHeight * pixelRatio.value) / 2,
|
|
641
660
|
imageWidth * pixelRatio.value,
|
|
642
661
|
imageHeight * pixelRatio.value,
|
|
643
|
-
)
|
|
644
|
-
ctx.restore()
|
|
662
|
+
);
|
|
663
|
+
ctx.restore();
|
|
645
664
|
ctx.draw(false, () => {
|
|
646
665
|
// #ifdef MP-DINGTALK
|
|
647
666
|
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
648
|
-
|
|
667
|
+
(ctx as any).toTempFilePath({
|
|
649
668
|
success(res: any) {
|
|
650
|
-
showCanvas.value = false
|
|
651
|
-
waterMarkUrl.value = res.filePath
|
|
669
|
+
showCanvas.value = false;
|
|
670
|
+
waterMarkUrl.value = res.filePath;
|
|
652
671
|
},
|
|
653
|
-
})
|
|
672
|
+
});
|
|
654
673
|
// #endif
|
|
655
674
|
// #ifndef MP-DINGTALK
|
|
656
675
|
uni.canvasToTempFilePath({
|
|
657
676
|
canvasId: canvasId.value,
|
|
658
677
|
success: (res) => {
|
|
659
|
-
showCanvas.value = false
|
|
660
|
-
waterMarkUrl.value = res.tempFilePath
|
|
678
|
+
showCanvas.value = false;
|
|
679
|
+
waterMarkUrl.value = res.tempFilePath;
|
|
661
680
|
},
|
|
662
|
-
})
|
|
681
|
+
});
|
|
663
682
|
// #endif
|
|
664
|
-
})
|
|
683
|
+
});
|
|
665
684
|
}
|
|
666
685
|
</script>
|
|
667
686
|
|
|
668
687
|
<style lang="scss" scoped>
|
|
669
|
-
@import
|
|
688
|
+
@import "./index.scss";
|
|
670
689
|
</style>
|