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