hy-app 0.2.2 → 0.2.5
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/components/hy-button/hy-button.vue +88 -120
- package/components/hy-button/index.scss +1 -3
- package/components/hy-calendar/index.scss +1 -1
- package/components/hy-cell/index.scss +2 -17
- package/components/hy-checkbox/index.scss +10 -10
- package/components/hy-code-input/hy-code-input.vue +85 -74
- package/components/hy-code-input/index.scss +31 -1
- package/components/hy-code-input/props.ts +8 -7
- package/components/hy-code-input/typing.d.ts +22 -18
- package/components/hy-config-provider/props.ts +1 -1
- package/components/hy-config-provider/typing.d.ts +7 -7
- package/components/hy-dropdown-item/hy-dropdown-item.vue +69 -75
- package/components/hy-dropdown-item/index.scss +1 -1
- package/components/hy-float-button/hy-float-button.vue +69 -86
- package/components/hy-form/index.scss +1 -1
- package/components/hy-grid/hy-grid.vue +2 -3
- package/components/hy-grid/props.ts +4 -0
- package/components/hy-grid/typing.d.ts +15 -0
- package/components/hy-icon/index.scss +2 -2
- package/components/hy-login/TheUserLogin.vue +0 -1
- package/components/hy-menu/hy-menu.vue +159 -0
- package/components/hy-menu/index.scss +58 -0
- package/components/hy-menu/props.ts +12 -0
- package/components/hy-menu/typing.d.ts +57 -0
- package/components/hy-navbar/index.scss +2 -2
- package/components/hy-notice-bar/index.scss +3 -3
- package/components/hy-notify/typing.d.ts +1 -1
- package/components/hy-pagination/typing.d.ts +1 -1
- package/components/hy-picker/hy-picker.vue +9 -8
- package/components/hy-picker/index.scss +6 -2
- package/components/hy-radio/index.scss +2 -2
- package/components/hy-scroll-list/index.scss +1 -1
- package/components/hy-signature/hy-signature.vue +50 -50
- package/components/hy-signature/index.scss +2 -4
- package/components/hy-signature/props.ts +2 -1
- package/components/hy-signature/typing.d.ts +5 -1
- package/components/hy-subsection/hy-subsection.vue +15 -13
- package/components/hy-subsection/props.ts +2 -2
- package/components/hy-subsection/typing.d.ts +1 -1
- package/components/hy-tabBar/hy-tabBar.vue +96 -0
- package/components/hy-tabBar/index.scss +169 -0
- package/components/hy-tabBar/props.ts +13 -0
- package/components/hy-tabBar/typing.d.ts +54 -0
- package/components/hy-text/hy-text.vue +76 -87
- package/components/hy-text/index.scss +8 -8
- package/components/hy-upload/index.scss +0 -1
- package/components/hy-watermark/hy-watermark.vue +583 -0
- package/components/hy-watermark/index.scss +17 -0
- package/components/hy-watermark/props.ts +23 -0
- package/components/hy-watermark/typing.d.ts +76 -0
- package/components/index.ts +2 -2
- package/index.scss +1 -1
- package/index.ts +1 -1
- package/libs/css/common.scss +9 -1
- package/libs/css/vars.css +5 -1
- package/package.json +2 -2
- package/theme.scss +8 -18
- package/typing/modules/common.d.ts +1 -1
- package/utils/inspect.ts +20 -0
- package/utils/utils.ts +52 -22
- package/components/yk-tabbar/props.ts +0 -49
- package/components/yk-tabbar/yk-tabbar.vue +0 -224
|
@@ -0,0 +1,583 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view :class="rootClass" :style="rootStyle">
|
|
3
|
+
<canvas
|
|
4
|
+
v-if="!canvasOffScreenable && showCanvas"
|
|
5
|
+
type="2d"
|
|
6
|
+
:style="{
|
|
7
|
+
height: canvasHeight + 'px',
|
|
8
|
+
width: canvasWidth + 'px',
|
|
9
|
+
visibility: 'hidden',
|
|
10
|
+
}"
|
|
11
|
+
:canvas-id="canvasId"
|
|
12
|
+
:id="canvasId"
|
|
13
|
+
/>
|
|
14
|
+
</view>
|
|
15
|
+
</template>
|
|
16
|
+
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
export default {
|
|
19
|
+
name: 'hy-watermark',
|
|
20
|
+
options: {
|
|
21
|
+
addGlobalClass: true,
|
|
22
|
+
virtualHost: true,
|
|
23
|
+
styleIsolation: 'shared',
|
|
24
|
+
},
|
|
25
|
+
}
|
|
26
|
+
</script>
|
|
27
|
+
|
|
28
|
+
<script lang="ts" setup>
|
|
29
|
+
import { computed, onMounted, ref, watch, nextTick, type CSSProperties, toRefs } from 'vue'
|
|
30
|
+
import { addUnit, guid } from '../../utils'
|
|
31
|
+
import type IProps from './typing'
|
|
32
|
+
import defaultProps from './props'
|
|
33
|
+
|
|
34
|
+
const props = withDefaults(defineProps<IProps>(), defaultProps)
|
|
35
|
+
const { customStyle } = toRefs(props)
|
|
36
|
+
|
|
37
|
+
watch(
|
|
38
|
+
() => props,
|
|
39
|
+
() => {
|
|
40
|
+
doReset()
|
|
41
|
+
},
|
|
42
|
+
{ deep: true },
|
|
43
|
+
)
|
|
44
|
+
|
|
45
|
+
const canvasId = ref<string>(`watermark--${guid()}`) // canvas 组件的唯一标识符
|
|
46
|
+
const waterMarkUrl = ref<string>('') // canvas生成base64水印
|
|
47
|
+
const canvasOffScreenable = ref<boolean>(
|
|
48
|
+
uni.canIUse('createOffscreenCanvas') && Boolean(uni.createOffscreenCanvas),
|
|
49
|
+
) // 是否可以使用离屏canvas
|
|
50
|
+
const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio) // 像素比
|
|
51
|
+
const canvasHeight = ref<number>((props.height + props.gutterY) * pixelRatio.value) // canvas画布高度
|
|
52
|
+
const canvasWidth = ref<number>((props.width + props.gutterX) * pixelRatio.value) // canvas画布宽度
|
|
53
|
+
const showCanvas = ref<boolean>(true) // 是否展示canvas
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* @description 水印css类
|
|
57
|
+
*/
|
|
58
|
+
const rootClass = computed(() => {
|
|
59
|
+
const classes: string[] = ['hy-watermark']
|
|
60
|
+
if (props.fullScreen) {
|
|
61
|
+
classes.push('is-fullscreen')
|
|
62
|
+
}
|
|
63
|
+
return classes
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @description 水印样式
|
|
68
|
+
*/
|
|
69
|
+
const rootStyle = computed(() => {
|
|
70
|
+
const style: CSSProperties = {
|
|
71
|
+
opacity: props.opacity,
|
|
72
|
+
backgroundSize: addUnit(props.width + props.gutterX),
|
|
73
|
+
}
|
|
74
|
+
if (waterMarkUrl.value) {
|
|
75
|
+
style['backgroundImage'] = `url('${waterMarkUrl.value}')`
|
|
76
|
+
}
|
|
77
|
+
return Object.assign(style, customStyle.value)
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
onMounted(() => {
|
|
81
|
+
doInit()
|
|
82
|
+
})
|
|
83
|
+
|
|
84
|
+
function doReset() {
|
|
85
|
+
showCanvas.value = true
|
|
86
|
+
canvasHeight.value = (props.height + props.gutterY) * pixelRatio.value
|
|
87
|
+
canvasWidth.value = (props.width + props.gutterX) * pixelRatio.value
|
|
88
|
+
nextTick(() => {
|
|
89
|
+
doInit()
|
|
90
|
+
})
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function doInit() {
|
|
94
|
+
// #ifdef H5
|
|
95
|
+
// h5使用document.createElement创建canvas,不用展示canvas标签
|
|
96
|
+
showCanvas.value = false
|
|
97
|
+
// #endif
|
|
98
|
+
const {
|
|
99
|
+
width,
|
|
100
|
+
height,
|
|
101
|
+
color,
|
|
102
|
+
size,
|
|
103
|
+
fontStyle,
|
|
104
|
+
fontWeight,
|
|
105
|
+
fontFamily,
|
|
106
|
+
content,
|
|
107
|
+
rotate,
|
|
108
|
+
gutterX,
|
|
109
|
+
gutterY,
|
|
110
|
+
image,
|
|
111
|
+
imageHeight,
|
|
112
|
+
imageWidth,
|
|
113
|
+
} = props
|
|
114
|
+
|
|
115
|
+
// 创建水印
|
|
116
|
+
createWaterMark(
|
|
117
|
+
width,
|
|
118
|
+
height,
|
|
119
|
+
color,
|
|
120
|
+
size,
|
|
121
|
+
fontStyle,
|
|
122
|
+
fontWeight,
|
|
123
|
+
fontFamily,
|
|
124
|
+
content,
|
|
125
|
+
rotate,
|
|
126
|
+
gutterX,
|
|
127
|
+
gutterY,
|
|
128
|
+
image,
|
|
129
|
+
imageHeight,
|
|
130
|
+
imageWidth,
|
|
131
|
+
)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* 创建水印图片
|
|
136
|
+
* @param width canvas宽度
|
|
137
|
+
* @param height canvas高度
|
|
138
|
+
* @param color canvas字体颜色
|
|
139
|
+
* @param size canvas字体大小
|
|
140
|
+
* @param fontStyle canvas字体样式
|
|
141
|
+
* @param fontWeight canvas字体字重
|
|
142
|
+
* @param fontFamily canvas字体系列
|
|
143
|
+
* @param content canvas内容
|
|
144
|
+
* @param rotate 倾斜角度
|
|
145
|
+
* @param gutterX X轴间距
|
|
146
|
+
* @param gutterY Y轴间距
|
|
147
|
+
* @param image canvas图片
|
|
148
|
+
* @param imageHeight canvas图片高度
|
|
149
|
+
* @param imageWidth canvas图片宽度
|
|
150
|
+
*/
|
|
151
|
+
function createWaterMark(
|
|
152
|
+
width: number,
|
|
153
|
+
height: number,
|
|
154
|
+
color: string,
|
|
155
|
+
size: number,
|
|
156
|
+
fontStyle: string,
|
|
157
|
+
fontWeight: number | string,
|
|
158
|
+
fontFamily: string,
|
|
159
|
+
content: string,
|
|
160
|
+
rotate: number,
|
|
161
|
+
gutterX: number,
|
|
162
|
+
gutterY: number,
|
|
163
|
+
image: string,
|
|
164
|
+
imageHeight: number,
|
|
165
|
+
imageWidth: number,
|
|
166
|
+
) {
|
|
167
|
+
const canvasHeight = (height + gutterY) * pixelRatio.value
|
|
168
|
+
const canvasWidth = (width + gutterX) * pixelRatio.value
|
|
169
|
+
const contentWidth = width * pixelRatio.value
|
|
170
|
+
const contentHeight = height * pixelRatio.value
|
|
171
|
+
const fontSize = size * pixelRatio.value
|
|
172
|
+
// #ifndef H5
|
|
173
|
+
if (canvasOffScreenable.value) {
|
|
174
|
+
createOffscreenCanvas(
|
|
175
|
+
canvasHeight,
|
|
176
|
+
canvasWidth,
|
|
177
|
+
contentWidth,
|
|
178
|
+
contentHeight,
|
|
179
|
+
rotate,
|
|
180
|
+
fontSize,
|
|
181
|
+
fontFamily,
|
|
182
|
+
fontStyle,
|
|
183
|
+
fontWeight,
|
|
184
|
+
color,
|
|
185
|
+
content,
|
|
186
|
+
image,
|
|
187
|
+
imageHeight,
|
|
188
|
+
imageWidth,
|
|
189
|
+
)
|
|
190
|
+
} else {
|
|
191
|
+
createCanvas(
|
|
192
|
+
canvasHeight,
|
|
193
|
+
contentWidth,
|
|
194
|
+
rotate,
|
|
195
|
+
fontSize,
|
|
196
|
+
color,
|
|
197
|
+
content,
|
|
198
|
+
image,
|
|
199
|
+
imageHeight,
|
|
200
|
+
imageWidth,
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
// #endif
|
|
204
|
+
// #ifdef H5
|
|
205
|
+
createH5Canvas(
|
|
206
|
+
canvasHeight,
|
|
207
|
+
canvasWidth,
|
|
208
|
+
contentWidth,
|
|
209
|
+
contentHeight,
|
|
210
|
+
rotate,
|
|
211
|
+
fontSize,
|
|
212
|
+
fontFamily,
|
|
213
|
+
fontStyle,
|
|
214
|
+
fontWeight,
|
|
215
|
+
color,
|
|
216
|
+
content,
|
|
217
|
+
image,
|
|
218
|
+
imageHeight,
|
|
219
|
+
imageWidth,
|
|
220
|
+
)
|
|
221
|
+
// #endif
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* 创建离屏canvas
|
|
226
|
+
* @param canvasHeight canvas高度
|
|
227
|
+
* @param canvasWidth canvas宽度
|
|
228
|
+
* @param contentWidth 内容宽度
|
|
229
|
+
* @param contentHeight 内容高度
|
|
230
|
+
* @param rotate 内容倾斜角度
|
|
231
|
+
* @param fontSize 字体大小
|
|
232
|
+
* @param fontFamily 字体系列
|
|
233
|
+
* @param fontStyle 字体样式
|
|
234
|
+
* @param fontWeight 字体字重
|
|
235
|
+
* @param color 字体颜色
|
|
236
|
+
* @param content 内容
|
|
237
|
+
* @param image canvas图片
|
|
238
|
+
* @param imageHeight canvas图片高度
|
|
239
|
+
* @param imageWidth canvas图片宽度
|
|
240
|
+
*/
|
|
241
|
+
function createOffscreenCanvas(
|
|
242
|
+
canvasHeight: number,
|
|
243
|
+
canvasWidth: number,
|
|
244
|
+
contentWidth: number,
|
|
245
|
+
contentHeight: number,
|
|
246
|
+
rotate: number,
|
|
247
|
+
fontSize: number,
|
|
248
|
+
fontFamily: string,
|
|
249
|
+
fontStyle: string,
|
|
250
|
+
fontWeight: string | number,
|
|
251
|
+
color: string,
|
|
252
|
+
content: string,
|
|
253
|
+
image: string,
|
|
254
|
+
imageHeight: number,
|
|
255
|
+
imageWidth: number,
|
|
256
|
+
) {
|
|
257
|
+
// 创建离屏canvas
|
|
258
|
+
const canvas: any = uni.createOffscreenCanvas({
|
|
259
|
+
height: canvasHeight,
|
|
260
|
+
width: canvasWidth,
|
|
261
|
+
type: '2d',
|
|
262
|
+
})
|
|
263
|
+
const ctx: any = canvas.getContext('2d')
|
|
264
|
+
if (ctx) {
|
|
265
|
+
if (image) {
|
|
266
|
+
const img = canvas.createImage() as HTMLImageElement
|
|
267
|
+
drawImageOffScreen(
|
|
268
|
+
ctx,
|
|
269
|
+
img,
|
|
270
|
+
image,
|
|
271
|
+
imageHeight,
|
|
272
|
+
imageWidth,
|
|
273
|
+
rotate,
|
|
274
|
+
contentWidth,
|
|
275
|
+
contentHeight,
|
|
276
|
+
canvas,
|
|
277
|
+
)
|
|
278
|
+
} else {
|
|
279
|
+
drawTextOffScreen(
|
|
280
|
+
ctx,
|
|
281
|
+
content,
|
|
282
|
+
contentWidth,
|
|
283
|
+
contentHeight,
|
|
284
|
+
rotate,
|
|
285
|
+
fontSize,
|
|
286
|
+
fontFamily,
|
|
287
|
+
fontStyle,
|
|
288
|
+
fontWeight,
|
|
289
|
+
color,
|
|
290
|
+
canvas,
|
|
291
|
+
)
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* 非H5创建canvas
|
|
300
|
+
* 不支持创建离屏canvas时调用
|
|
301
|
+
* @param contentHeight 内容高度
|
|
302
|
+
* @param contentWidth 内容宽度
|
|
303
|
+
* @param rotate 内容倾斜角度
|
|
304
|
+
* @param fontSize 字体大小
|
|
305
|
+
* @param color 字体颜色
|
|
306
|
+
* @param content 内容
|
|
307
|
+
* @param image canvas图片
|
|
308
|
+
* @param imageHeight canvas图片高度
|
|
309
|
+
* @param imageWidth canvas图片宽度
|
|
310
|
+
*/
|
|
311
|
+
function createCanvas(
|
|
312
|
+
contentHeight: number,
|
|
313
|
+
contentWidth: number,
|
|
314
|
+
rotate: number,
|
|
315
|
+
fontSize: number,
|
|
316
|
+
color: string,
|
|
317
|
+
content: string,
|
|
318
|
+
image: string,
|
|
319
|
+
imageHeight: number,
|
|
320
|
+
imageWidth: number,
|
|
321
|
+
) {
|
|
322
|
+
const ctx = uni.createCanvasContext(canvasId.value)
|
|
323
|
+
if (ctx) {
|
|
324
|
+
if (image) {
|
|
325
|
+
drawImageOnScreen(ctx, image, imageHeight, imageWidth, rotate, contentWidth, contentHeight)
|
|
326
|
+
} else {
|
|
327
|
+
drawTextOnScreen(ctx, content, contentWidth, rotate, fontSize, color)
|
|
328
|
+
}
|
|
329
|
+
} else {
|
|
330
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* h5创建canvas
|
|
336
|
+
* @param canvasHeight canvas高度
|
|
337
|
+
* @param canvasWidth canvas宽度
|
|
338
|
+
* @param contentWidth 水印内容宽度
|
|
339
|
+
* @param contentHeight 水印内容高度
|
|
340
|
+
* @param rotate 水印内容倾斜角度
|
|
341
|
+
* @param fontSize 水印字体大小
|
|
342
|
+
* @param fontFamily 水印字体系列
|
|
343
|
+
* @param fontStyle 水印字体样式
|
|
344
|
+
* @param fontWeight 水印字体字重
|
|
345
|
+
* @param color 水印字体颜色
|
|
346
|
+
* @param content 水印内容
|
|
347
|
+
*/
|
|
348
|
+
function createH5Canvas(
|
|
349
|
+
canvasHeight: number,
|
|
350
|
+
canvasWidth: number,
|
|
351
|
+
contentWidth: number,
|
|
352
|
+
contentHeight: number,
|
|
353
|
+
rotate: number,
|
|
354
|
+
fontSize: number,
|
|
355
|
+
fontFamily: string,
|
|
356
|
+
fontStyle: string,
|
|
357
|
+
fontWeight: string | number,
|
|
358
|
+
color: string,
|
|
359
|
+
content: string,
|
|
360
|
+
image: string,
|
|
361
|
+
imageHeight: number,
|
|
362
|
+
imageWidth: number,
|
|
363
|
+
) {
|
|
364
|
+
const canvas = document.createElement('canvas')
|
|
365
|
+
const ctx = canvas.getContext('2d')
|
|
366
|
+
canvas.setAttribute('width', `${canvasWidth}px`)
|
|
367
|
+
canvas.setAttribute('height', `${canvasHeight}px`)
|
|
368
|
+
if (ctx) {
|
|
369
|
+
if (image) {
|
|
370
|
+
const img = new Image()
|
|
371
|
+
drawImageOffScreen(
|
|
372
|
+
ctx,
|
|
373
|
+
img,
|
|
374
|
+
image,
|
|
375
|
+
imageHeight,
|
|
376
|
+
imageWidth,
|
|
377
|
+
rotate,
|
|
378
|
+
contentWidth,
|
|
379
|
+
contentHeight,
|
|
380
|
+
canvas,
|
|
381
|
+
)
|
|
382
|
+
} else {
|
|
383
|
+
drawTextOffScreen(
|
|
384
|
+
ctx,
|
|
385
|
+
content,
|
|
386
|
+
contentWidth,
|
|
387
|
+
contentHeight,
|
|
388
|
+
rotate,
|
|
389
|
+
fontSize,
|
|
390
|
+
fontFamily,
|
|
391
|
+
fontStyle,
|
|
392
|
+
fontWeight,
|
|
393
|
+
color,
|
|
394
|
+
canvas,
|
|
395
|
+
)
|
|
396
|
+
}
|
|
397
|
+
} else {
|
|
398
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* 绘制离屏文字canvas
|
|
404
|
+
* @param ctx canvas上下文
|
|
405
|
+
* @param content 水印内容
|
|
406
|
+
* @param contentWidth 水印宽度
|
|
407
|
+
* @param contentHeight 水印高度
|
|
408
|
+
* @param rotate 水印内容倾斜角度
|
|
409
|
+
* @param fontSize 水印字体大小
|
|
410
|
+
* @param fontFamily 水印字体系列
|
|
411
|
+
* @param fontStyle 水印字体样式
|
|
412
|
+
* @param fontWeight 水印字体字重
|
|
413
|
+
* @param color 水印字体颜色
|
|
414
|
+
* @param canvas canvas实例
|
|
415
|
+
*/
|
|
416
|
+
function drawTextOffScreen(
|
|
417
|
+
ctx: CanvasRenderingContext2D,
|
|
418
|
+
content: string,
|
|
419
|
+
contentWidth: number,
|
|
420
|
+
contentHeight: number,
|
|
421
|
+
rotate: number,
|
|
422
|
+
fontSize: number,
|
|
423
|
+
fontFamily: string,
|
|
424
|
+
fontStyle: string,
|
|
425
|
+
fontWeight: string | number,
|
|
426
|
+
color: string,
|
|
427
|
+
canvas: HTMLCanvasElement,
|
|
428
|
+
) {
|
|
429
|
+
ctx.textBaseline = 'middle'
|
|
430
|
+
ctx.textAlign = 'center'
|
|
431
|
+
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
432
|
+
ctx.rotate((Math.PI / 180) * rotate)
|
|
433
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px/${contentHeight}px ${fontFamily}`
|
|
434
|
+
ctx.fillStyle = color
|
|
435
|
+
ctx.fillText(content, 0, 0)
|
|
436
|
+
ctx.restore()
|
|
437
|
+
waterMarkUrl.value = canvas.toDataURL()
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
/**
|
|
441
|
+
* 绘制在屏文字canvas
|
|
442
|
+
* @param ctx canvas上下文
|
|
443
|
+
* @param content 水印内容
|
|
444
|
+
* @param contentWidth 水印宽度
|
|
445
|
+
* @param rotate 水印内容倾斜角度
|
|
446
|
+
* @param fontSize 水印字体大小
|
|
447
|
+
* @param color 水印字体颜色
|
|
448
|
+
*/
|
|
449
|
+
function drawTextOnScreen(
|
|
450
|
+
ctx: UniApp.CanvasContext,
|
|
451
|
+
content: string,
|
|
452
|
+
contentWidth: number,
|
|
453
|
+
rotate: number,
|
|
454
|
+
fontSize: number,
|
|
455
|
+
color: string,
|
|
456
|
+
) {
|
|
457
|
+
ctx.setTextBaseline('middle')
|
|
458
|
+
ctx.setTextAlign('center')
|
|
459
|
+
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
460
|
+
ctx.rotate((Math.PI / 180) * rotate)
|
|
461
|
+
ctx.setFillStyle(color)
|
|
462
|
+
ctx.setFontSize(fontSize)
|
|
463
|
+
ctx.fillText(content, 0, 0)
|
|
464
|
+
ctx.restore()
|
|
465
|
+
ctx.draw()
|
|
466
|
+
// #ifdef MP-DINGTALK
|
|
467
|
+
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
468
|
+
;(ctx as any).toTempFilePath({
|
|
469
|
+
success(res: any) {
|
|
470
|
+
showCanvas.value = false
|
|
471
|
+
waterMarkUrl.value = res.filePath
|
|
472
|
+
},
|
|
473
|
+
})
|
|
474
|
+
// #endif
|
|
475
|
+
// #ifndef MP-DINGTALK
|
|
476
|
+
uni.canvasToTempFilePath({
|
|
477
|
+
canvasId: canvasId.value,
|
|
478
|
+
success: (res) => {
|
|
479
|
+
showCanvas.value = false
|
|
480
|
+
waterMarkUrl.value = res.tempFilePath
|
|
481
|
+
},
|
|
482
|
+
})
|
|
483
|
+
// #endif
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* 绘制离屏图片canvas
|
|
488
|
+
* @param ctx canvas上下文
|
|
489
|
+
* @param img 水印图片对象
|
|
490
|
+
* @param image 水印图片地址
|
|
491
|
+
* @param imageHeight 水印图片高度
|
|
492
|
+
* @param imageWidth 水印图片宽度
|
|
493
|
+
* @param rotate 水印内容倾斜角度
|
|
494
|
+
* @param contentWidth 水印宽度
|
|
495
|
+
* @param contentHeight 水印高度
|
|
496
|
+
* @param canvas canvas实例
|
|
497
|
+
*/
|
|
498
|
+
async function drawImageOffScreen(
|
|
499
|
+
ctx: CanvasRenderingContext2D,
|
|
500
|
+
img: HTMLImageElement,
|
|
501
|
+
image: string,
|
|
502
|
+
imageHeight: number,
|
|
503
|
+
imageWidth: number,
|
|
504
|
+
rotate: number,
|
|
505
|
+
contentWidth: number,
|
|
506
|
+
contentHeight: number,
|
|
507
|
+
canvas: HTMLCanvasElement,
|
|
508
|
+
) {
|
|
509
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
510
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
511
|
+
img.crossOrigin = 'anonymous'
|
|
512
|
+
img.referrerPolicy = 'no-referrer'
|
|
513
|
+
|
|
514
|
+
img.src = image
|
|
515
|
+
img.onload = () => {
|
|
516
|
+
ctx.drawImage(
|
|
517
|
+
img,
|
|
518
|
+
(-imageWidth * pixelRatio.value) / 2,
|
|
519
|
+
(-imageHeight * pixelRatio.value) / 2,
|
|
520
|
+
imageWidth * pixelRatio.value,
|
|
521
|
+
imageHeight * pixelRatio.value,
|
|
522
|
+
)
|
|
523
|
+
ctx.restore()
|
|
524
|
+
waterMarkUrl.value = canvas.toDataURL()
|
|
525
|
+
}
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
/**
|
|
529
|
+
* 绘制在屏图片canvas
|
|
530
|
+
* @param ctx canvas上下文
|
|
531
|
+
* @param image 水印图片地址
|
|
532
|
+
* @param imageHeight 水印图片高度
|
|
533
|
+
* @param imageWidth 水印图片宽度
|
|
534
|
+
* @param rotate 水印内容倾斜角度
|
|
535
|
+
* @param contentWidth 水印宽度
|
|
536
|
+
* @param contentHeight 水印高度
|
|
537
|
+
*/
|
|
538
|
+
function drawImageOnScreen(
|
|
539
|
+
ctx: UniApp.CanvasContext,
|
|
540
|
+
image: string,
|
|
541
|
+
imageHeight: number,
|
|
542
|
+
imageWidth: number,
|
|
543
|
+
rotate: number,
|
|
544
|
+
contentWidth: number,
|
|
545
|
+
contentHeight: number,
|
|
546
|
+
) {
|
|
547
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
548
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
549
|
+
|
|
550
|
+
ctx.drawImage(
|
|
551
|
+
image,
|
|
552
|
+
(-imageWidth * pixelRatio.value) / 2,
|
|
553
|
+
(-imageHeight * pixelRatio.value) / 2,
|
|
554
|
+
imageWidth * pixelRatio.value,
|
|
555
|
+
imageHeight * pixelRatio.value,
|
|
556
|
+
)
|
|
557
|
+
ctx.restore()
|
|
558
|
+
ctx.draw(false, () => {
|
|
559
|
+
// #ifdef MP-DINGTALK
|
|
560
|
+
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
561
|
+
;(ctx as any).toTempFilePath({
|
|
562
|
+
success(res: any) {
|
|
563
|
+
showCanvas.value = false
|
|
564
|
+
waterMarkUrl.value = res.filePath
|
|
565
|
+
},
|
|
566
|
+
})
|
|
567
|
+
// #endif
|
|
568
|
+
// #ifndef MP-DINGTALK
|
|
569
|
+
uni.canvasToTempFilePath({
|
|
570
|
+
canvasId: canvasId.value,
|
|
571
|
+
success: (res) => {
|
|
572
|
+
showCanvas.value = false
|
|
573
|
+
waterMarkUrl.value = res.tempFilePath
|
|
574
|
+
},
|
|
575
|
+
})
|
|
576
|
+
// #endif
|
|
577
|
+
})
|
|
578
|
+
}
|
|
579
|
+
</script>
|
|
580
|
+
|
|
581
|
+
<style lang="scss" scoped>
|
|
582
|
+
@import './index.scss';
|
|
583
|
+
</style>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
@use "../../theme.scss" as *;
|
|
2
|
+
@use "../../libs/css/mixin.scss" as *;
|
|
3
|
+
|
|
4
|
+
@include b(watermark) {
|
|
5
|
+
position: absolute;
|
|
6
|
+
z-index: 1100;
|
|
7
|
+
opacity: 0.5;
|
|
8
|
+
left: 0;
|
|
9
|
+
right: 0;
|
|
10
|
+
top: 0;
|
|
11
|
+
bottom: 0;
|
|
12
|
+
pointer-events: none;
|
|
13
|
+
background-repeat: repeat;
|
|
14
|
+
@include is(fullscreen) {
|
|
15
|
+
position: fixed;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type IProps from "./typing";
|
|
2
|
+
|
|
3
|
+
const defaultProps: IProps = {
|
|
4
|
+
content: "",
|
|
5
|
+
image: "",
|
|
6
|
+
imageHeight: 50,
|
|
7
|
+
imageWidth: 70,
|
|
8
|
+
gutterX: 0,
|
|
9
|
+
gutterY: 0,
|
|
10
|
+
width: 100,
|
|
11
|
+
height: 100,
|
|
12
|
+
fullScreen: true,
|
|
13
|
+
color: "#8c8c8c",
|
|
14
|
+
size: 14,
|
|
15
|
+
fontStyle: "",
|
|
16
|
+
fontWeight: "",
|
|
17
|
+
fontFamily: "PingFang SC",
|
|
18
|
+
rotate: -25,
|
|
19
|
+
zIndex: 10086,
|
|
20
|
+
opacity: 0.5,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export default defaultProps;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { CSSProperties } from "vue";
|
|
2
|
+
|
|
3
|
+
export default interface HyOverlayProps {
|
|
4
|
+
/**
|
|
5
|
+
* @description 显示内容
|
|
6
|
+
* */
|
|
7
|
+
content?: string;
|
|
8
|
+
/**
|
|
9
|
+
* @description 显示图片的地址,支持网络图片和base64(钉钉小程序仅支持网络图片)
|
|
10
|
+
* */
|
|
11
|
+
image?: string;
|
|
12
|
+
/**
|
|
13
|
+
* @description 图片高度
|
|
14
|
+
* */
|
|
15
|
+
imageHeight?: number;
|
|
16
|
+
/**
|
|
17
|
+
* @description 图片高度
|
|
18
|
+
* */
|
|
19
|
+
imageWidth?: number;
|
|
20
|
+
/**
|
|
21
|
+
* @description X轴间距,单位px
|
|
22
|
+
* */
|
|
23
|
+
gutterX?: number;
|
|
24
|
+
/**
|
|
25
|
+
* @description Y轴间距,单位px
|
|
26
|
+
* */
|
|
27
|
+
gutterY?: number;
|
|
28
|
+
/**
|
|
29
|
+
* @description canvas画布宽度,单位px
|
|
30
|
+
* */
|
|
31
|
+
width?: number;
|
|
32
|
+
/**
|
|
33
|
+
* @description canvas画布高度,单位px
|
|
34
|
+
* */
|
|
35
|
+
height?: number;
|
|
36
|
+
/**
|
|
37
|
+
* @description 是否为全屏水印
|
|
38
|
+
* */
|
|
39
|
+
fullScreen?: boolean;
|
|
40
|
+
/**
|
|
41
|
+
* @description 水印字体颜色
|
|
42
|
+
* */
|
|
43
|
+
color?: string;
|
|
44
|
+
/**
|
|
45
|
+
* @description 水印字体大小,单位px
|
|
46
|
+
* */
|
|
47
|
+
size?: number;
|
|
48
|
+
/**
|
|
49
|
+
* @description 水印字体样式(仅微信和h5支持),可能的值:normal、italic、oblique
|
|
50
|
+
* */
|
|
51
|
+
fontStyle?: string;
|
|
52
|
+
/**
|
|
53
|
+
* @description 水印字体的粗细(仅微信和h5支持)
|
|
54
|
+
* */
|
|
55
|
+
fontWeight?: string;
|
|
56
|
+
/**
|
|
57
|
+
* @description 水印字体系列(仅微信和h5支持)
|
|
58
|
+
* */
|
|
59
|
+
fontFamily?: string;
|
|
60
|
+
/**
|
|
61
|
+
* @description 水印旋转角度
|
|
62
|
+
* */
|
|
63
|
+
rotate?: number;
|
|
64
|
+
/**
|
|
65
|
+
* @description 自定义层级
|
|
66
|
+
* */
|
|
67
|
+
zIndex?: number;
|
|
68
|
+
/**
|
|
69
|
+
* @description 自定义透明度,取值 0~1
|
|
70
|
+
* */
|
|
71
|
+
opacity?: number;
|
|
72
|
+
/**
|
|
73
|
+
* @description 定义需要用到的外部样式
|
|
74
|
+
* */
|
|
75
|
+
customStyle?: CSSProperties;
|
|
76
|
+
}
|
package/components/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import HyTabBr from "./hy-tabBar/hy-tabBar.vue";
|
|
2
2
|
import Dialog from "./dialog";
|
|
3
3
|
/* #ifdef H5 */
|
|
4
4
|
import DialogService from "./message";
|
|
@@ -63,7 +63,7 @@ import HyUpload from "./hy-upload/hy-upload.vue";
|
|
|
63
63
|
import HyWarn from "./hy-warn/hy-warn.vue";
|
|
64
64
|
|
|
65
65
|
const install = (Vue: any) => {
|
|
66
|
-
Vue.component("
|
|
66
|
+
Vue.component("hy-tabBar", HyTabBr);
|
|
67
67
|
|
|
68
68
|
Vue.component("HyAddressPicker", HyAddressPicker);
|
|
69
69
|
Vue.component("HyAvatar", HyAvatar);
|
package/index.scss
CHANGED