hy-app 0.4.13 → 0.5.0
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-action-sheet/hy-action-sheet.vue +155 -238
- package/components/hy-action-sheet/props.ts +68 -15
- package/components/hy-action-sheet/typing.d.ts +115 -115
- package/components/hy-address-picker/hy-address-picker.vue +185 -289
- package/components/hy-address-picker/props.ts +97 -21
- package/components/hy-address-picker/typing.d.ts +90 -89
- package/components/hy-avatar/hy-avatar.vue +121 -204
- package/components/hy-avatar/props.ts +76 -18
- package/components/hy-avatar/typing.d.ts +63 -62
- package/components/hy-back-top/hy-back-top.vue +65 -120
- package/components/hy-back-top/props.ts +57 -16
- package/components/hy-back-top/typing.d.ts +43 -42
- package/components/hy-badge/hy-badge.vue +66 -138
- package/components/hy-badge/props.ts +73 -17
- package/components/hy-badge/typing.d.ts +59 -58
- package/components/hy-button/hy-button.vue +226 -375
- package/components/hy-button/props.ts +129 -158
- package/components/hy-calendar/header.vue +48 -64
- package/components/hy-calendar/hy-calendar.vue +274 -438
- package/components/hy-calendar/month.vue +508 -516
- package/components/hy-calendar/props.ts +157 -35
- package/components/hy-calendar/typing.d.ts +129 -128
- package/components/hy-card/hy-card.vue +118 -240
- package/components/hy-card/index.scss +1 -2
- package/components/hy-card/props.ts +122 -27
- package/components/hy-card/typing.d.ts +119 -118
- package/components/hy-cell/hy-cell.vue +176 -258
- package/components/hy-cell/props.ts +71 -17
- package/components/hy-cell/typing.d.ts +87 -86
- package/components/hy-check-button/hy-check-button.vue +69 -139
- package/components/hy-check-button/props.ts +72 -18
- package/components/hy-check-button/typing.d.ts +74 -73
- package/components/hy-checkbox/hy-checkbox.vue +170 -263
- package/components/hy-checkbox/props.ts +94 -24
- package/components/hy-checkbox/typing.d.ts +72 -72
- package/components/hy-checkbox-group/hy-checkbox-group.vue +25 -100
- package/components/hy-checkbox-group/props.ts +80 -0
- package/components/hy-checkbox-group/typing.d.ts +65 -65
- package/components/hy-checkbox-item/hy-checkbox-item.vue +140 -177
- package/components/hy-checkbox-item/props.ts +24 -0
- package/components/hy-checkbox-item/typing.d.ts +4 -3
- package/components/hy-code-input/hy-code-input.vue +179 -262
- package/components/hy-code-input/props.ts +84 -18
- package/components/hy-code-input/typing.d.ts +71 -71
- package/components/hy-config-provider/hy-config-provider.vue +28 -50
- package/components/hy-config-provider/props.ts +26 -11
- package/components/hy-config-provider/typing.d.ts +20 -20
- package/components/hy-count-down/hy-count-down.vue +103 -131
- package/components/hy-count-down/props.ts +30 -8
- package/components/hy-count-down/typing.d.ts +25 -25
- package/components/hy-count-to/hy-count-to.vue +148 -213
- package/components/hy-count-to/props.ts +60 -15
- package/components/hy-count-to/typing.d.ts +46 -46
- package/components/hy-coupon/README.md +133 -0
- package/components/hy-coupon/hy-coupon.vue +180 -0
- package/components/hy-coupon/index.scss +553 -0
- package/components/hy-coupon/props.ts +129 -0
- package/components/hy-coupon/typing.d.ts +146 -0
- package/components/hy-datetime-picker/hy-datetime-picker.vue +415 -580
- package/components/hy-datetime-picker/props.ts +142 -32
- package/components/hy-datetime-picker/typing.d.ts +132 -132
- package/components/hy-divider/hy-divider.vue +90 -169
- package/components/hy-divider/props.ts +78 -19
- package/components/hy-divider/typing.d.ts +60 -60
- package/components/hy-dropdown/hy-dropdown.vue +37 -71
- package/components/hy-dropdown/props.ts +38 -15
- package/components/hy-dropdown/typing.d.ts +44 -44
- package/components/hy-dropdown-item/hy-dropdown-item.vue +141 -173
- package/components/hy-dropdown-item/props.ts +19 -8
- package/components/hy-empty/hy-empty.vue +75 -129
- package/components/hy-empty/props.ts +57 -15
- package/components/hy-empty/typing.d.ts +84 -84
- package/components/hy-flex/hy-flex.vue +33 -88
- package/components/hy-flex/props.ts +58 -0
- package/components/hy-flex/typing.d.ts +14 -16
- package/components/hy-float-button/hy-float-button.vue +289 -406
- package/components/hy-float-button/props.ts +109 -25
- package/components/hy-folding-panel/hy-folding-panel.vue +86 -374
- package/components/hy-folding-panel/props.ts +40 -15
- package/components/hy-folding-panel/typing.d.ts +52 -63
- package/components/hy-folding-panel-item/hy-folding-panel-item.vue +186 -228
- package/components/hy-folding-panel-item/index.scss +87 -0
- package/components/hy-folding-panel-item/props.ts +81 -0
- package/components/hy-folding-panel-item/typing.d.ts +23 -0
- package/components/hy-form/hy-form.vue +172 -212
- package/components/hy-form/props.ts +37 -0
- package/components/hy-form/typing.d.ts +68 -61
- package/components/hy-form-group/typing.d.ts +74 -74
- package/components/hy-form-item/hy-form-item.vue +100 -129
- package/components/hy-form-item/props.ts +25 -0
- package/components/hy-form-item/typing.d.ts +40 -37
- package/components/hy-grid/hy-grid.vue +76 -132
- package/components/hy-grid/props.ts +58 -16
- package/components/hy-grid/typing.d.ts +66 -66
- package/components/hy-icon/hy-icon.vue +84 -161
- package/components/hy-icon/props.ts +76 -22
- package/components/hy-icon/typing.d.ts +83 -82
- package/components/hy-image/hy-image.vue +142 -272
- package/components/hy-image/props.ts +105 -23
- package/components/hy-image/typing.d.ts +84 -87
- package/components/hy-input/hy-input.vue +230 -421
- package/components/hy-input/props.ts +183 -35
- package/components/hy-input/typing.d.ts +169 -169
- package/components/hy-line/hy-line.vue +34 -72
- package/components/hy-line/props.ts +41 -10
- package/components/hy-line/typing.d.ts +29 -29
- package/components/hy-line-progress/hy-line-progress.vue +66 -101
- package/components/hy-line-progress/props.ts +31 -10
- package/components/hy-line-progress/typing.d.ts +29 -29
- package/components/hy-list/hy-list.vue +151 -220
- package/components/hy-list/props.ts +67 -16
- package/components/hy-list/typing.d.ts +52 -52
- package/components/hy-loading/hy-loading.vue +63 -119
- package/components/hy-loading/props.ts +63 -15
- package/components/hy-loading/typing.d.ts +49 -49
- package/components/hy-menu/hy-menu.vue +124 -166
- package/components/hy-menu/props.ts +42 -10
- package/components/hy-menu/typing.d.ts +60 -60
- package/components/hy-modal/hy-modal.vue +127 -218
- package/components/hy-modal/props.ts +89 -24
- package/components/hy-navbar/hy-navbar.vue +104 -177
- package/components/hy-navbar/props.ts +76 -22
- package/components/hy-navbar/typing.d.ts +81 -81
- package/components/hy-notice-bar/hy-notice-bar.vue +67 -144
- package/components/hy-notice-bar/props.ts +80 -19
- package/components/hy-notice-bar/typing.d.ts +62 -62
- package/components/hy-notify/hy-notify.vue +128 -177
- package/components/hy-notify/props.ts +49 -12
- package/components/hy-notify/typing.d.ts +45 -41
- package/components/hy-number-step/hy-number-step.vue +281 -394
- package/components/hy-number-step/props.ts +110 -27
- package/components/hy-number-step/typing.d.ts +120 -120
- package/components/hy-overlay/hy-overlay.vue +39 -66
- package/components/hy-overlay/props.ts +31 -8
- package/components/hy-pagination/hy-pagination.vue +100 -155
- package/components/hy-pagination/props.ts +53 -13
- package/components/hy-picker/hy-picker.vue +309 -430
- package/components/hy-picker/index.scss +8 -12
- package/components/hy-picker/props.ts +110 -26
- package/components/hy-popover/hy-popover.vue +190 -252
- package/components/hy-popover/props.ts +48 -10
- package/components/hy-popup/hy-popup.vue +162 -248
- package/components/hy-popup/props.ts +82 -18
- package/components/hy-price/hy-price.vue +45 -104
- package/components/hy-price/props.ts +52 -12
- package/components/hy-price/typing.d.ts +41 -36
- package/components/hy-qrcode/hy-qrcode.vue +115 -185
- package/components/hy-qrcode/props.ts +68 -18
- package/components/hy-qrcode/typing.d.ts +67 -66
- package/components/hy-radio/hy-radio.vue +161 -259
- package/components/hy-radio/props.ts +95 -25
- package/components/hy-radio/typing.d.ts +85 -84
- package/components/hy-rate/hy-rate.vue +185 -270
- package/components/hy-rate/props.ts +76 -18
- package/components/hy-rate/typing.d.ts +61 -60
- package/components/hy-read-more/hy-read-more.vue +93 -136
- package/components/hy-read-more/props.ts +43 -13
- package/components/hy-scroll-list/hy-scroll-list.vue +81 -102
- package/components/hy-scroll-list/props.ts +22 -11
- package/components/hy-search/hy-search.vue +155 -284
- package/components/hy-search/props.ts +130 -25
- package/components/hy-signature/hy-signature.vue +491 -635
- package/components/hy-signature/props.ts +115 -26
- package/components/hy-signature/typing.d.ts +138 -138
- package/components/hy-slider/hy-slider.vue +388 -477
- package/components/hy-slider/props.ts +75 -19
- package/components/hy-steps/hy-steps.vue +212 -279
- package/components/hy-steps/props.ts +47 -13
- package/components/hy-submit-bar/hy-submit-bar.vue +137 -222
- package/components/hy-submit-bar/props.ts +89 -20
- package/components/hy-submit-bar/typing.d.ts +86 -85
- package/components/hy-subsection/hy-subsection.vue +132 -185
- package/components/hy-subsection/props.ts +50 -17
- package/components/hy-subsection/typing.d.ts +52 -52
- package/components/hy-swipe-action/hy-swipe-action.vue +228 -283
- package/components/hy-swipe-action/props.ts +43 -18
- package/components/hy-swipe-action/typing.d.ts +46 -46
- package/components/hy-swiper/hy-swiper.vue +159 -286
- package/components/hy-swiper/props.ts +126 -28
- package/components/hy-swiper/typing.d.ts +115 -115
- package/components/hy-switch/hy-switch.vue +112 -176
- package/components/hy-switch/props.ts +60 -15
- package/components/hy-switch/typing.d.ts +63 -63
- package/components/hy-tabBar/hy-tabBar.vue +64 -60
- package/components/hy-tabs/hy-tabs.vue +277 -380
- package/components/hy-tabs/props.ts +75 -18
- package/components/hy-tag/hy-tag.vue +111 -204
- package/components/hy-tag/props.ts +81 -19
- package/components/hy-text/hy-text.vue +200 -322
- package/components/hy-text/props.ts +107 -28
- package/components/hy-textarea/hy-textarea.vue +147 -256
- package/components/hy-textarea/props.ts +112 -25
- package/components/hy-textarea/typing.d.ts +42 -42
- package/components/hy-toast/hy-toast.vue +135 -143
- package/components/hy-tooltip/hy-tooltip.vue +220 -306
- package/components/hy-tooltip/props.ts +79 -15
- package/components/hy-transition/hy-transition.vue +111 -138
- package/components/hy-transition/props.ts +30 -8
- package/components/hy-upload/hy-upload.vue +320 -469
- package/components/hy-upload/props.ts +130 -27
- package/components/hy-warn/hy-warn.vue +80 -129
- package/components/hy-warn/props.ts +47 -12
- package/components/hy-waterfall/hy-waterfall.vue +139 -163
- package/components/hy-waterfall/props.ts +19 -7
- package/components/hy-watermark/hy-watermark.vue +762 -870
- package/components/hy-watermark/props.ts +103 -22
- package/global.d.ts +2 -0
- package/libs/css/theme.scss +3 -3
- package/package.json +2 -2
- package/web-types.json +1 -1
- package/components/hy-folding-panel/index.scss +0 -9
|
@@ -1,246 +1,141 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
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
15
|
</template>
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
18
|
export default {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
19
|
+
name: 'hy-watermark',
|
|
20
|
+
options: {
|
|
21
|
+
addGlobalClass: true,
|
|
22
|
+
virtualHost: true,
|
|
23
|
+
styleIsolation: 'shared'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
26
|
</script>
|
|
27
27
|
|
|
28
28
|
<script lang="ts" setup>
|
|
29
|
-
import { computed, onMounted, ref, watch, nextTick } from
|
|
30
|
-
import type { CSSProperties } from
|
|
31
|
-
import { addUnit, guid } from
|
|
29
|
+
import { computed, onMounted, ref, watch, nextTick } from 'vue'
|
|
30
|
+
import type { CSSProperties } from 'vue'
|
|
31
|
+
import { addUnit, guid } from '../../libs'
|
|
32
|
+
import watermarkProps from './props'
|
|
32
33
|
|
|
33
34
|
/**
|
|
34
35
|
* 在页面或组件上添加指定的图片或文字,可用于版权保护、品牌宣传等场景。
|
|
35
36
|
* @displayName hy-watermark
|
|
36
37
|
*/
|
|
37
|
-
defineOptions({})
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const props = defineProps({
|
|
41
|
-
/** 显示主标题 */
|
|
42
|
-
title: {
|
|
43
|
-
type: String,
|
|
44
|
-
default: "",
|
|
45
|
-
},
|
|
46
|
-
/** 主标题颜色 */
|
|
47
|
-
titleColor: {
|
|
48
|
-
type: String,
|
|
49
|
-
default: "",
|
|
50
|
-
},
|
|
51
|
-
/** 主标题字体大小,单位px */
|
|
52
|
-
titleSize: {
|
|
53
|
-
type: Number,
|
|
54
|
-
default: 0,
|
|
55
|
-
},
|
|
56
|
-
/** 显示副标题内容 */
|
|
57
|
-
content: {
|
|
58
|
-
type: String,
|
|
59
|
-
default: "",
|
|
60
|
-
},
|
|
61
|
-
/** 显示图片的地址,支持网络图片和base64(钉钉小程序仅支持网络图片) */
|
|
62
|
-
image: {
|
|
63
|
-
type: String,
|
|
64
|
-
default: "",
|
|
65
|
-
},
|
|
66
|
-
/** 图片高度 */
|
|
67
|
-
imageHeight: {
|
|
68
|
-
type: Number,
|
|
69
|
-
default: 50,
|
|
70
|
-
},
|
|
71
|
-
/** 图片宽度 */
|
|
72
|
-
imageWidth: {
|
|
73
|
-
type: Number,
|
|
74
|
-
default: 70,
|
|
75
|
-
},
|
|
76
|
-
/** X轴间距,单位px */
|
|
77
|
-
gutterX: {
|
|
78
|
-
type: Number,
|
|
79
|
-
default: 0,
|
|
80
|
-
},
|
|
81
|
-
/** Y轴间距,单位px */
|
|
82
|
-
gutterY: {
|
|
83
|
-
type: Number,
|
|
84
|
-
default: 0,
|
|
85
|
-
},
|
|
86
|
-
/** canvas画布宽度,单位px */
|
|
87
|
-
width: {
|
|
88
|
-
type: Number,
|
|
89
|
-
default: 100,
|
|
90
|
-
},
|
|
91
|
-
/** canvas画布高度,单位px */
|
|
92
|
-
height: {
|
|
93
|
-
type: Number,
|
|
94
|
-
default: 100,
|
|
95
|
-
},
|
|
96
|
-
/** 是否为全屏水印 */
|
|
97
|
-
fullScreen: {
|
|
98
|
-
type: Boolean,
|
|
99
|
-
default: true,
|
|
100
|
-
},
|
|
101
|
-
/** 水印字体颜色 */
|
|
102
|
-
color: {
|
|
103
|
-
type: String,
|
|
104
|
-
default: "#8c8c8c",
|
|
105
|
-
},
|
|
106
|
-
/** 水印字体大小,单位px */
|
|
107
|
-
size: {
|
|
108
|
-
type: Number,
|
|
109
|
-
default: 14,
|
|
110
|
-
},
|
|
111
|
-
/** 水印字体样式(仅微信和h5支持) */
|
|
112
|
-
fontStyle: {
|
|
113
|
-
type: String,
|
|
114
|
-
default: "",
|
|
115
|
-
},
|
|
116
|
-
/** 水印字体的粗细 */
|
|
117
|
-
fontWeight: {
|
|
118
|
-
type: String,
|
|
119
|
-
default: "",
|
|
120
|
-
},
|
|
121
|
-
/** 水印字体系列(仅微信和h5支持) */
|
|
122
|
-
fontFamily: {
|
|
123
|
-
type: String,
|
|
124
|
-
default: "PingFang SC",
|
|
125
|
-
},
|
|
126
|
-
/** 水印旋转角度 */
|
|
127
|
-
rotate: {
|
|
128
|
-
type: Number,
|
|
129
|
-
default: -25,
|
|
130
|
-
},
|
|
131
|
-
/** 自定义层级 */
|
|
132
|
-
zIndex: {
|
|
133
|
-
type: Number,
|
|
134
|
-
default: 10086,
|
|
135
|
-
},
|
|
136
|
-
/** 自定义透明度,取值 0~1 */
|
|
137
|
-
opacity: {
|
|
138
|
-
type: Number,
|
|
139
|
-
default: 0.5,
|
|
140
|
-
},
|
|
141
|
-
});
|
|
38
|
+
defineOptions({})
|
|
39
|
+
|
|
40
|
+
const props = defineProps(watermarkProps)
|
|
142
41
|
|
|
143
42
|
watch(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
)
|
|
150
|
-
|
|
151
|
-
const canvasId = ref<string>(`watermark--${guid()}`)
|
|
152
|
-
const waterMarkUrl = ref<string>(
|
|
43
|
+
() => props,
|
|
44
|
+
() => {
|
|
45
|
+
doReset()
|
|
46
|
+
},
|
|
47
|
+
{ deep: true }
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const canvasId = ref<string>(`watermark--${guid()}`) // canvas 组件的唯一标识符
|
|
51
|
+
const waterMarkUrl = ref<string>('') // canvas生成base64水印
|
|
153
52
|
const canvasOffScreenable = ref<boolean>(
|
|
154
|
-
|
|
155
|
-
)
|
|
156
|
-
const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio)
|
|
157
|
-
const canvasHeight = ref<number>(
|
|
158
|
-
|
|
159
|
-
)
|
|
160
|
-
const canvasWidth = ref<number>(
|
|
161
|
-
(props.width + props.gutterX) * pixelRatio.value,
|
|
162
|
-
); // canvas画布宽度
|
|
163
|
-
const showCanvas = ref<boolean>(true); // 是否展示canvas
|
|
53
|
+
uni.canIUse('createOffscreenCanvas') && Boolean(uni.createOffscreenCanvas)
|
|
54
|
+
) // 是否可以使用离屏canvas
|
|
55
|
+
const pixelRatio = ref<number>(uni.getSystemInfoSync().pixelRatio) // 像素比
|
|
56
|
+
const canvasHeight = ref<number>((props.height + props.gutterY) * pixelRatio.value) // canvas画布高度
|
|
57
|
+
const canvasWidth = ref<number>((props.width + props.gutterX) * pixelRatio.value) // canvas画布宽度
|
|
58
|
+
const showCanvas = ref<boolean>(true) // 是否展示canvas
|
|
164
59
|
|
|
165
60
|
/**
|
|
166
61
|
* @description 水印css类
|
|
167
62
|
*/
|
|
168
63
|
const rootClass = computed(() => {
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
})
|
|
64
|
+
const classes: string[] = ['hy-watermark']
|
|
65
|
+
if (props.fullScreen) {
|
|
66
|
+
classes.push('is-fullscreen')
|
|
67
|
+
}
|
|
68
|
+
return classes
|
|
69
|
+
})
|
|
175
70
|
|
|
176
71
|
/**
|
|
177
72
|
* @description 水印样式
|
|
178
73
|
*/
|
|
179
74
|
const rootStyle = computed(() => {
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
})
|
|
75
|
+
const style: CSSProperties = {
|
|
76
|
+
opacity: props.opacity,
|
|
77
|
+
backgroundSize: addUnit(props.width + props.gutterX)
|
|
78
|
+
}
|
|
79
|
+
if (waterMarkUrl.value) {
|
|
80
|
+
style['backgroundImage'] = `url('${waterMarkUrl.value}')`
|
|
81
|
+
}
|
|
82
|
+
return style
|
|
83
|
+
})
|
|
189
84
|
|
|
190
85
|
onMounted(() => {
|
|
191
|
-
|
|
192
|
-
})
|
|
86
|
+
doInit()
|
|
87
|
+
})
|
|
193
88
|
|
|
194
89
|
function doReset() {
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
90
|
+
showCanvas.value = true
|
|
91
|
+
canvasHeight.value = (props.height + props.gutterY) * pixelRatio.value
|
|
92
|
+
canvasWidth.value = (props.width + props.gutterX) * pixelRatio.value
|
|
93
|
+
nextTick(() => {
|
|
94
|
+
doInit()
|
|
95
|
+
})
|
|
201
96
|
}
|
|
202
97
|
|
|
203
98
|
function doInit() {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
99
|
+
// #ifdef H5
|
|
100
|
+
// h5使用document.createElement创建canvas,不用展示canvas标签
|
|
101
|
+
showCanvas.value = false
|
|
102
|
+
// #endif
|
|
103
|
+
const {
|
|
104
|
+
width,
|
|
105
|
+
height,
|
|
106
|
+
color,
|
|
107
|
+
size,
|
|
108
|
+
fontStyle,
|
|
109
|
+
fontWeight,
|
|
110
|
+
fontFamily,
|
|
111
|
+
content,
|
|
112
|
+
rotate,
|
|
113
|
+
gutterX,
|
|
114
|
+
gutterY,
|
|
115
|
+
image,
|
|
116
|
+
imageHeight,
|
|
117
|
+
imageWidth,
|
|
118
|
+
title
|
|
119
|
+
} = props
|
|
120
|
+
|
|
121
|
+
// 创建水印
|
|
122
|
+
createWaterMark(
|
|
123
|
+
width,
|
|
124
|
+
height,
|
|
125
|
+
color,
|
|
126
|
+
size,
|
|
127
|
+
fontStyle,
|
|
128
|
+
fontWeight,
|
|
129
|
+
fontFamily,
|
|
130
|
+
content,
|
|
131
|
+
rotate,
|
|
132
|
+
gutterX,
|
|
133
|
+
gutterY,
|
|
134
|
+
image,
|
|
135
|
+
imageHeight,
|
|
136
|
+
imageWidth,
|
|
137
|
+
title
|
|
138
|
+
)
|
|
244
139
|
}
|
|
245
140
|
|
|
246
141
|
/**
|
|
@@ -262,86 +157,86 @@ function doInit() {
|
|
|
262
157
|
* @param title 标题
|
|
263
158
|
*/
|
|
264
159
|
function createWaterMark(
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
160
|
+
width: number,
|
|
161
|
+
height: number,
|
|
162
|
+
color: string,
|
|
163
|
+
size: number,
|
|
164
|
+
fontStyle: string,
|
|
165
|
+
fontWeight: number | string,
|
|
166
|
+
fontFamily: string,
|
|
167
|
+
content: string,
|
|
168
|
+
rotate: number,
|
|
169
|
+
gutterX: number,
|
|
170
|
+
gutterY: number,
|
|
171
|
+
image: string,
|
|
172
|
+
imageHeight: number,
|
|
173
|
+
imageWidth: number,
|
|
174
|
+
title: string
|
|
280
175
|
) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
176
|
+
const canvasHeight = (height + gutterY) * pixelRatio.value
|
|
177
|
+
const canvasWidth = (width + gutterX) * pixelRatio.value
|
|
178
|
+
const contentWidth = width * pixelRatio.value
|
|
179
|
+
const contentHeight = height * pixelRatio.value
|
|
180
|
+
const fontSize = size * pixelRatio.value
|
|
181
|
+
// 标题字体大小:如果设置了titleSize则使用titleSize,否则使用size的1.2倍
|
|
182
|
+
const titleFontSize = props.titleSize > 0 ? props.titleSize * pixelRatio.value : fontSize * 1.2
|
|
183
|
+
|
|
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
|
+
title,
|
|
202
|
+
titleFontSize
|
|
203
|
+
)
|
|
204
|
+
} else {
|
|
205
|
+
createCanvas(
|
|
206
|
+
canvasHeight,
|
|
207
|
+
contentWidth,
|
|
208
|
+
rotate,
|
|
209
|
+
fontSize,
|
|
210
|
+
color,
|
|
211
|
+
content,
|
|
212
|
+
image,
|
|
213
|
+
imageHeight,
|
|
214
|
+
imageWidth,
|
|
215
|
+
title,
|
|
216
|
+
titleFontSize
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
// #endif
|
|
220
|
+
// #ifdef H5
|
|
221
|
+
createH5Canvas(
|
|
222
|
+
canvasHeight,
|
|
223
|
+
canvasWidth,
|
|
224
|
+
contentWidth,
|
|
225
|
+
contentHeight,
|
|
226
|
+
rotate,
|
|
227
|
+
fontSize,
|
|
228
|
+
fontFamily,
|
|
229
|
+
fontStyle,
|
|
230
|
+
fontWeight,
|
|
231
|
+
color,
|
|
232
|
+
content,
|
|
233
|
+
image,
|
|
234
|
+
imageHeight,
|
|
235
|
+
imageWidth,
|
|
236
|
+
title,
|
|
237
|
+
titleFontSize
|
|
238
|
+
)
|
|
239
|
+
// #endif
|
|
345
240
|
}
|
|
346
241
|
|
|
347
242
|
/**
|
|
@@ -362,86 +257,86 @@ function createWaterMark(
|
|
|
362
257
|
* @param imageWidth canvas图片宽度
|
|
363
258
|
*/
|
|
364
259
|
function createOffscreenCanvas(
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
260
|
+
canvasHeight: number,
|
|
261
|
+
canvasWidth: number,
|
|
262
|
+
contentWidth: number,
|
|
263
|
+
contentHeight: number,
|
|
264
|
+
rotate: number,
|
|
265
|
+
fontSize: number,
|
|
266
|
+
fontFamily: string,
|
|
267
|
+
fontStyle: string,
|
|
268
|
+
fontWeight: string | number,
|
|
269
|
+
color: string,
|
|
270
|
+
content: string,
|
|
271
|
+
image: string,
|
|
272
|
+
imageHeight: number,
|
|
273
|
+
imageWidth: number,
|
|
274
|
+
title: string,
|
|
275
|
+
titleFontSize: number
|
|
381
276
|
) {
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
277
|
+
// 创建离屏canvas
|
|
278
|
+
const canvas: any = uni.createOffscreenCanvas({
|
|
279
|
+
height: canvasHeight,
|
|
280
|
+
width: canvasWidth,
|
|
281
|
+
type: '2d'
|
|
282
|
+
})
|
|
283
|
+
const ctx: any = canvas.getContext('2d')
|
|
284
|
+
if (ctx) {
|
|
285
|
+
if (image && (title || content)) {
|
|
286
|
+
// 图片和文字同时显示
|
|
287
|
+
const img = canvas.createImage() as HTMLImageElement
|
|
288
|
+
drawImageAndTextOffScreen(
|
|
289
|
+
ctx,
|
|
290
|
+
img,
|
|
291
|
+
image,
|
|
292
|
+
imageHeight,
|
|
293
|
+
imageWidth,
|
|
294
|
+
title,
|
|
295
|
+
content,
|
|
296
|
+
rotate,
|
|
297
|
+
contentWidth,
|
|
298
|
+
contentHeight,
|
|
299
|
+
fontSize,
|
|
300
|
+
titleFontSize,
|
|
301
|
+
fontFamily,
|
|
302
|
+
fontStyle,
|
|
303
|
+
fontWeight,
|
|
304
|
+
color,
|
|
305
|
+
canvas
|
|
306
|
+
)
|
|
307
|
+
} else if (image) {
|
|
308
|
+
const img = canvas.createImage() as HTMLImageElement
|
|
309
|
+
drawImageOffScreen(
|
|
310
|
+
ctx,
|
|
311
|
+
img,
|
|
312
|
+
image,
|
|
313
|
+
imageHeight,
|
|
314
|
+
imageWidth,
|
|
315
|
+
rotate,
|
|
316
|
+
contentWidth,
|
|
317
|
+
contentHeight,
|
|
318
|
+
canvas
|
|
319
|
+
)
|
|
320
|
+
} else {
|
|
321
|
+
drawTextOffScreen(
|
|
322
|
+
ctx,
|
|
323
|
+
title,
|
|
324
|
+
contentWidth,
|
|
325
|
+
contentHeight,
|
|
326
|
+
rotate,
|
|
327
|
+
fontSize,
|
|
328
|
+
fontFamily,
|
|
329
|
+
fontStyle,
|
|
330
|
+
fontWeight,
|
|
331
|
+
color,
|
|
332
|
+
canvas,
|
|
333
|
+
content,
|
|
334
|
+
titleFontSize
|
|
335
|
+
)
|
|
336
|
+
}
|
|
425
337
|
} else {
|
|
426
|
-
|
|
427
|
-
ctx,
|
|
428
|
-
title,
|
|
429
|
-
contentWidth,
|
|
430
|
-
contentHeight,
|
|
431
|
-
rotate,
|
|
432
|
-
fontSize,
|
|
433
|
-
fontFamily,
|
|
434
|
-
fontStyle,
|
|
435
|
-
fontWeight,
|
|
436
|
-
color,
|
|
437
|
-
canvas,
|
|
438
|
-
content,
|
|
439
|
-
titleFontSize
|
|
440
|
-
);
|
|
338
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
441
339
|
}
|
|
442
|
-
} else {
|
|
443
|
-
console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
|
|
444
|
-
}
|
|
445
340
|
}
|
|
446
341
|
|
|
447
342
|
/**
|
|
@@ -458,52 +353,61 @@ function createOffscreenCanvas(
|
|
|
458
353
|
* @param imageWidth canvas图片宽度
|
|
459
354
|
*/
|
|
460
355
|
function createCanvas(
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
356
|
+
contentHeight: number,
|
|
357
|
+
contentWidth: number,
|
|
358
|
+
rotate: number,
|
|
359
|
+
fontSize: number,
|
|
360
|
+
color: string,
|
|
361
|
+
content: string,
|
|
362
|
+
image: string,
|
|
363
|
+
imageHeight: number,
|
|
364
|
+
imageWidth: number,
|
|
365
|
+
title: string,
|
|
366
|
+
titleFontSize: number
|
|
472
367
|
) {
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
368
|
+
const ctx = uni.createCanvasContext(canvasId.value)
|
|
369
|
+
if (ctx) {
|
|
370
|
+
if (image && (title || content)) {
|
|
371
|
+
// 图片和文字同时显示
|
|
372
|
+
drawImageAndTextOnScreen(
|
|
373
|
+
ctx,
|
|
374
|
+
image,
|
|
375
|
+
imageHeight,
|
|
376
|
+
imageWidth,
|
|
377
|
+
title,
|
|
378
|
+
content,
|
|
379
|
+
rotate,
|
|
380
|
+
contentWidth,
|
|
381
|
+
contentHeight,
|
|
382
|
+
fontSize,
|
|
383
|
+
titleFontSize,
|
|
384
|
+
color
|
|
385
|
+
)
|
|
386
|
+
} else if (image) {
|
|
387
|
+
drawImageOnScreen(
|
|
388
|
+
ctx,
|
|
389
|
+
image,
|
|
390
|
+
imageHeight,
|
|
391
|
+
imageWidth,
|
|
392
|
+
rotate,
|
|
393
|
+
contentWidth,
|
|
394
|
+
contentHeight
|
|
395
|
+
)
|
|
396
|
+
} else {
|
|
397
|
+
drawTextOnScreen(
|
|
398
|
+
ctx,
|
|
399
|
+
title,
|
|
400
|
+
contentWidth,
|
|
401
|
+
rotate,
|
|
402
|
+
fontSize,
|
|
403
|
+
color,
|
|
404
|
+
content,
|
|
405
|
+
titleFontSize
|
|
406
|
+
)
|
|
407
|
+
}
|
|
501
408
|
} else {
|
|
502
|
-
|
|
409
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
503
410
|
}
|
|
504
|
-
} else {
|
|
505
|
-
console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
|
|
506
|
-
}
|
|
507
411
|
}
|
|
508
412
|
|
|
509
413
|
/**
|
|
@@ -524,83 +428,83 @@ function createCanvas(
|
|
|
524
428
|
* @param imageWidth canvas图片宽度
|
|
525
429
|
*/
|
|
526
430
|
function createH5Canvas(
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
431
|
+
canvasHeight: number,
|
|
432
|
+
canvasWidth: number,
|
|
433
|
+
contentWidth: number,
|
|
434
|
+
contentHeight: number,
|
|
435
|
+
rotate: number,
|
|
436
|
+
fontSize: number,
|
|
437
|
+
fontFamily: string,
|
|
438
|
+
fontStyle: string,
|
|
439
|
+
fontWeight: string | number,
|
|
440
|
+
color: string,
|
|
441
|
+
content: string,
|
|
442
|
+
image: string,
|
|
443
|
+
imageHeight: number,
|
|
444
|
+
imageWidth: number,
|
|
445
|
+
title: string,
|
|
446
|
+
titleFontSize: number
|
|
543
447
|
) {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
448
|
+
const canvas = document.createElement('canvas')
|
|
449
|
+
const ctx = canvas.getContext('2d')
|
|
450
|
+
canvas.setAttribute('width', `${canvasWidth}px`)
|
|
451
|
+
canvas.setAttribute('height', `${canvasHeight}px`)
|
|
452
|
+
if (ctx) {
|
|
453
|
+
if (image && (title || content)) {
|
|
454
|
+
// 图片和文字同时显示
|
|
455
|
+
const img = new Image()
|
|
456
|
+
drawImageAndTextOffScreen(
|
|
457
|
+
ctx,
|
|
458
|
+
img,
|
|
459
|
+
image,
|
|
460
|
+
imageHeight,
|
|
461
|
+
imageWidth,
|
|
462
|
+
title,
|
|
463
|
+
content,
|
|
464
|
+
rotate,
|
|
465
|
+
contentWidth,
|
|
466
|
+
contentHeight,
|
|
467
|
+
fontSize,
|
|
468
|
+
titleFontSize,
|
|
469
|
+
fontFamily,
|
|
470
|
+
fontStyle,
|
|
471
|
+
fontWeight,
|
|
472
|
+
color,
|
|
473
|
+
canvas
|
|
474
|
+
)
|
|
475
|
+
} else if (image) {
|
|
476
|
+
const img = new Image()
|
|
477
|
+
drawImageOffScreen(
|
|
478
|
+
ctx,
|
|
479
|
+
img,
|
|
480
|
+
image,
|
|
481
|
+
imageHeight,
|
|
482
|
+
imageWidth,
|
|
483
|
+
rotate,
|
|
484
|
+
contentWidth,
|
|
485
|
+
contentHeight,
|
|
486
|
+
canvas
|
|
487
|
+
)
|
|
488
|
+
} else {
|
|
489
|
+
drawTextOffScreen(
|
|
490
|
+
ctx,
|
|
491
|
+
title,
|
|
492
|
+
contentWidth,
|
|
493
|
+
contentHeight,
|
|
494
|
+
rotate,
|
|
495
|
+
fontSize,
|
|
496
|
+
fontFamily,
|
|
497
|
+
fontStyle,
|
|
498
|
+
fontWeight,
|
|
499
|
+
color,
|
|
500
|
+
canvas,
|
|
501
|
+
content,
|
|
502
|
+
titleFontSize
|
|
503
|
+
)
|
|
504
|
+
}
|
|
584
505
|
} else {
|
|
585
|
-
|
|
586
|
-
ctx,
|
|
587
|
-
title,
|
|
588
|
-
contentWidth,
|
|
589
|
-
contentHeight,
|
|
590
|
-
rotate,
|
|
591
|
-
fontSize,
|
|
592
|
-
fontFamily,
|
|
593
|
-
fontStyle,
|
|
594
|
-
fontWeight,
|
|
595
|
-
color,
|
|
596
|
-
canvas,
|
|
597
|
-
content,
|
|
598
|
-
titleFontSize
|
|
599
|
-
);
|
|
506
|
+
console.error('无法获取canvas上下文,请确认当前环境是否支持canvas')
|
|
600
507
|
}
|
|
601
|
-
} else {
|
|
602
|
-
console.error("无法获取canvas上下文,请确认当前环境是否支持canvas");
|
|
603
|
-
}
|
|
604
508
|
}
|
|
605
509
|
|
|
606
510
|
/**
|
|
@@ -619,85 +523,85 @@ function createH5Canvas(
|
|
|
619
523
|
*/
|
|
620
524
|
// 测量文本宽度并自动换行
|
|
621
525
|
function wrapText(ctx: CanvasRenderingContext2D, text: string, maxWidth: number, fontSize: number) {
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
526
|
+
const words = text.split('')
|
|
527
|
+
const lines: string[] = []
|
|
528
|
+
let currentLine = ''
|
|
529
|
+
|
|
530
|
+
for (let i = 0; i < words.length; i++) {
|
|
531
|
+
const testLine = currentLine + words[i]
|
|
532
|
+
const metrics = ctx.measureText(testLine)
|
|
533
|
+
const testWidth = metrics.width
|
|
534
|
+
|
|
535
|
+
// 当文字宽度超过容器宽度的80%时换行
|
|
536
|
+
if (testWidth > maxWidth * 0.8 && currentLine !== '') {
|
|
537
|
+
lines.push(currentLine)
|
|
538
|
+
currentLine = words[i]
|
|
539
|
+
} else {
|
|
540
|
+
currentLine = testLine
|
|
541
|
+
}
|
|
637
542
|
}
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
return lines;
|
|
543
|
+
lines.push(currentLine)
|
|
544
|
+
return lines
|
|
641
545
|
}
|
|
642
546
|
|
|
643
547
|
function drawTextOffScreen(
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
548
|
+
ctx: CanvasRenderingContext2D,
|
|
549
|
+
title: string,
|
|
550
|
+
contentWidth: number,
|
|
551
|
+
contentHeight: number,
|
|
552
|
+
rotate: number,
|
|
553
|
+
fontSize: number,
|
|
554
|
+
fontFamily: string,
|
|
555
|
+
fontStyle: string,
|
|
556
|
+
fontWeight: string | number,
|
|
557
|
+
color: string,
|
|
558
|
+
canvas: HTMLCanvasElement,
|
|
559
|
+
content: string = '',
|
|
560
|
+
titleFontSize: number = 0
|
|
657
561
|
) {
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// 起始Y坐标
|
|
670
|
-
let startY = -totalTextHeight / 2;
|
|
671
|
-
|
|
672
|
-
// 绘制主标题(支持自动换行)
|
|
673
|
-
if (title) {
|
|
674
|
-
ctx.font = `${fontStyle} normal ${fontWeight} ${titleFontSize}px/${contentHeight}px ${fontFamily}`;
|
|
675
|
-
// 使用titleColor或默认color
|
|
676
|
-
ctx.fillStyle = props.titleColor || color;
|
|
677
|
-
const titleLines = wrapText(ctx, title, contentWidth, titleFontSize);
|
|
678
|
-
const titleLineHeight = titleFontSize * 1.2;
|
|
679
|
-
|
|
680
|
-
for (let i = 0; i < titleLines.length; i++) {
|
|
681
|
-
ctx.fillText(titleLines[i], 0, startY + i * titleLineHeight);
|
|
562
|
+
ctx.textBaseline = 'middle'
|
|
563
|
+
ctx.textAlign = 'center'
|
|
564
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
565
|
+
ctx.rotate((Math.PI / 180) * rotate)
|
|
566
|
+
|
|
567
|
+
// 计算总高度
|
|
568
|
+
let totalTextHeight = titleFontSize
|
|
569
|
+
if (content) {
|
|
570
|
+
totalTextHeight += fontSize + 5 // 标题和副标题之间的间距
|
|
682
571
|
}
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
572
|
+
|
|
573
|
+
// 起始Y坐标
|
|
574
|
+
let startY = -totalTextHeight / 2
|
|
575
|
+
|
|
576
|
+
// 绘制主标题(支持自动换行)
|
|
577
|
+
if (title) {
|
|
578
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${titleFontSize}px/${contentHeight}px ${fontFamily}`
|
|
579
|
+
// 使用titleColor或默认color
|
|
580
|
+
ctx.fillStyle = props.titleColor || color
|
|
581
|
+
const titleLines = wrapText(ctx, title, contentWidth, titleFontSize)
|
|
582
|
+
const titleLineHeight = titleFontSize * 1.2
|
|
583
|
+
|
|
584
|
+
for (let i = 0; i < titleLines.length; i++) {
|
|
585
|
+
ctx.fillText(titleLines[i], 0, startY + i * titleLineHeight)
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
startY += titleLines.length * titleLineHeight + 5
|
|
696
589
|
}
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
590
|
+
|
|
591
|
+
// 绘制副标题(支持自动换行)
|
|
592
|
+
if (content) {
|
|
593
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px/${contentHeight}px ${fontFamily}`
|
|
594
|
+
ctx.fillStyle = color
|
|
595
|
+
const contentLines = wrapText(ctx, content, contentWidth, fontSize)
|
|
596
|
+
const contentLineHeight = fontSize * 1.2
|
|
597
|
+
|
|
598
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
599
|
+
ctx.fillText(contentLines[i], 0, startY + i * contentLineHeight)
|
|
600
|
+
}
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
ctx.restore()
|
|
604
|
+
waterMarkUrl.value = canvas.toDataURL()
|
|
701
605
|
}
|
|
702
606
|
|
|
703
607
|
/**
|
|
@@ -711,97 +615,97 @@ function drawTextOffScreen(
|
|
|
711
615
|
*/
|
|
712
616
|
// 简化版本的文字换行(UniApp CanvasContext不支持measureText)
|
|
713
617
|
function simpleWrapText(text: string, maxLength: number) {
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
618
|
+
const lines: string[] = []
|
|
619
|
+
let currentLine = ''
|
|
620
|
+
|
|
621
|
+
// 基于字符数估算换行(适用于UniApp CanvasContext)
|
|
622
|
+
for (let i = 0; i < text.length; i++) {
|
|
623
|
+
currentLine += text[i]
|
|
624
|
+
if (currentLine.length >= maxLength) {
|
|
625
|
+
lines.push(currentLine)
|
|
626
|
+
currentLine = ''
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
if (currentLine) {
|
|
630
|
+
lines.push(currentLine)
|
|
723
631
|
}
|
|
724
|
-
|
|
725
|
-
if (currentLine) {
|
|
726
|
-
lines.push(currentLine);
|
|
727
|
-
}
|
|
728
|
-
return lines;
|
|
632
|
+
return lines
|
|
729
633
|
}
|
|
730
634
|
|
|
731
635
|
function drawTextOnScreen(
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
636
|
+
ctx: UniApp.CanvasContext,
|
|
637
|
+
title: string,
|
|
638
|
+
contentWidth: number,
|
|
639
|
+
rotate: number,
|
|
640
|
+
fontSize: number,
|
|
641
|
+
color: string,
|
|
642
|
+
content: string = '',
|
|
643
|
+
titleFontSize: number = 0
|
|
740
644
|
) {
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
}
|
|
754
|
-
|
|
755
|
-
// 起始Y坐标
|
|
756
|
-
let startY = -totalTextHeight / 2;
|
|
757
|
-
|
|
758
|
-
// 绘制主标题(支持自动换行)
|
|
759
|
-
if (title) {
|
|
760
|
-
// 使用titleColor或默认color
|
|
761
|
-
ctx.setFillStyle(props.titleColor || color);
|
|
762
|
-
ctx.setFontSize(titleFontSize);
|
|
763
|
-
const titleLines = simpleWrapText(title, maxChars);
|
|
764
|
-
const titleLineHeight = titleFontSize * 1.2;
|
|
765
|
-
|
|
766
|
-
for (let i = 0; i < titleLines.length; i++) {
|
|
767
|
-
ctx.fillText(titleLines[i], 0, startY + i * titleLineHeight);
|
|
645
|
+
ctx.setTextBaseline('middle')
|
|
646
|
+
ctx.setTextAlign('center')
|
|
647
|
+
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
648
|
+
ctx.rotate((Math.PI / 180) * rotate)
|
|
649
|
+
|
|
650
|
+
// 估算每行最大字符数
|
|
651
|
+
const maxChars = Math.floor(contentWidth / (fontSize * 0.5))
|
|
652
|
+
|
|
653
|
+
// 计算总高度
|
|
654
|
+
let totalTextHeight = titleFontSize
|
|
655
|
+
if (content) {
|
|
656
|
+
totalTextHeight += fontSize + 5
|
|
768
657
|
}
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
658
|
+
|
|
659
|
+
// 起始Y坐标
|
|
660
|
+
let startY = -totalTextHeight / 2
|
|
661
|
+
|
|
662
|
+
// 绘制主标题(支持自动换行)
|
|
663
|
+
if (title) {
|
|
664
|
+
// 使用titleColor或默认color
|
|
665
|
+
ctx.setFillStyle(props.titleColor || color)
|
|
666
|
+
ctx.setFontSize(titleFontSize)
|
|
667
|
+
const titleLines = simpleWrapText(title, maxChars)
|
|
668
|
+
const titleLineHeight = titleFontSize * 1.2
|
|
669
|
+
|
|
670
|
+
for (let i = 0; i < titleLines.length; i++) {
|
|
671
|
+
ctx.fillText(titleLines[i], 0, startY + i * titleLineHeight)
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
startY += titleLines.length * titleLineHeight + 5
|
|
782
675
|
}
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
676
|
+
|
|
677
|
+
// 绘制副标题(支持自动换行)
|
|
678
|
+
if (content) {
|
|
679
|
+
ctx.setFillStyle(color)
|
|
680
|
+
ctx.setFontSize(fontSize)
|
|
681
|
+
const contentLines = simpleWrapText(content, maxChars)
|
|
682
|
+
const contentLineHeight = fontSize * 1.2
|
|
683
|
+
|
|
684
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
685
|
+
ctx.fillText(contentLines[i], 0, startY + i * contentLineHeight)
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
ctx.restore()
|
|
690
|
+
ctx.draw()
|
|
691
|
+
// #ifdef MP-DINGTALK
|
|
692
|
+
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
693
|
+
;(ctx as any).toTempFilePath({
|
|
694
|
+
success(res: any) {
|
|
695
|
+
showCanvas.value = false
|
|
696
|
+
waterMarkUrl.value = res.filePath
|
|
697
|
+
}
|
|
698
|
+
})
|
|
699
|
+
// #endif
|
|
700
|
+
// #ifndef MP-DINGTALK
|
|
701
|
+
uni.canvasToTempFilePath({
|
|
702
|
+
canvasId: canvasId.value,
|
|
703
|
+
success: (res) => {
|
|
704
|
+
showCanvas.value = false
|
|
705
|
+
waterMarkUrl.value = res.tempFilePath
|
|
706
|
+
}
|
|
707
|
+
})
|
|
708
|
+
// #endif
|
|
805
709
|
}
|
|
806
710
|
|
|
807
711
|
/**
|
|
@@ -817,215 +721,203 @@ function drawTextOnScreen(
|
|
|
817
721
|
* @param canvas canvas实例
|
|
818
722
|
*/
|
|
819
723
|
async function drawImageOffScreen(
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
724
|
+
ctx: CanvasRenderingContext2D,
|
|
725
|
+
img: HTMLImageElement,
|
|
726
|
+
image: string,
|
|
727
|
+
imageHeight: number,
|
|
728
|
+
imageWidth: number,
|
|
729
|
+
rotate: number,
|
|
730
|
+
contentWidth: number,
|
|
731
|
+
contentHeight: number,
|
|
732
|
+
canvas: HTMLCanvasElement
|
|
829
733
|
) {
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
734
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
735
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
736
|
+
img.crossOrigin = 'anonymous'
|
|
737
|
+
img.referrerPolicy = 'no-referrer'
|
|
834
738
|
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
739
|
+
img.src = image
|
|
740
|
+
img.onload = () => {
|
|
741
|
+
ctx.drawImage(
|
|
742
|
+
img,
|
|
743
|
+
(-imageWidth * pixelRatio.value) / 2,
|
|
744
|
+
(-imageHeight * pixelRatio.value) / 2,
|
|
745
|
+
imageWidth * pixelRatio.value,
|
|
746
|
+
imageHeight * pixelRatio.value
|
|
747
|
+
)
|
|
748
|
+
ctx.restore()
|
|
749
|
+
waterMarkUrl.value = canvas.toDataURL()
|
|
750
|
+
}
|
|
847
751
|
}
|
|
848
752
|
|
|
849
753
|
// 绘制图片和文字(离屏)
|
|
850
754
|
async function drawImageAndTextOffScreen(
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
755
|
+
ctx: CanvasRenderingContext2D,
|
|
756
|
+
img: HTMLImageElement,
|
|
757
|
+
image: string,
|
|
758
|
+
imageHeight: number,
|
|
759
|
+
imageWidth: number,
|
|
760
|
+
title: string,
|
|
761
|
+
content: string,
|
|
762
|
+
rotate: number,
|
|
763
|
+
contentWidth: number,
|
|
764
|
+
contentHeight: number,
|
|
765
|
+
fontSize: number,
|
|
766
|
+
titleFontSize: number,
|
|
767
|
+
fontFamily: string,
|
|
768
|
+
fontStyle: string,
|
|
769
|
+
fontWeight: string | number,
|
|
770
|
+
color: string,
|
|
771
|
+
canvas: HTMLCanvasElement
|
|
868
772
|
) {
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
773
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
774
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
775
|
+
img.crossOrigin = 'anonymous'
|
|
776
|
+
img.referrerPolicy = 'no-referrer'
|
|
777
|
+
|
|
778
|
+
const imgHeight = imageHeight * pixelRatio.value
|
|
779
|
+
const imgWidth = imageWidth * pixelRatio.value
|
|
780
|
+
|
|
781
|
+
img.src = image
|
|
782
|
+
img.onload = () => {
|
|
783
|
+
// 计算总高度
|
|
784
|
+
let totalHeight = imgHeight
|
|
785
|
+
const textSpacing = 10
|
|
786
|
+
|
|
787
|
+
if (title) totalHeight += textSpacing + titleFontSize
|
|
788
|
+
if (content) totalHeight += fontSize
|
|
789
|
+
|
|
790
|
+
// 起始Y坐标
|
|
791
|
+
let startY = -totalHeight / 2
|
|
792
|
+
|
|
793
|
+
// 绘制图片
|
|
794
|
+
ctx.drawImage(img, -imgWidth / 2, startY, imgWidth, imgHeight)
|
|
795
|
+
|
|
796
|
+
startY += imgHeight + textSpacing
|
|
797
|
+
|
|
798
|
+
// 设置文字样式
|
|
799
|
+
ctx.textBaseline = 'top'
|
|
800
|
+
ctx.textAlign = 'center'
|
|
801
|
+
|
|
802
|
+
// 绘制主标题
|
|
803
|
+
if (title) {
|
|
804
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${titleFontSize}px/${contentHeight}px ${fontFamily}`
|
|
805
|
+
// 使用titleColor或默认color
|
|
806
|
+
ctx.fillStyle = props.titleColor || color
|
|
807
|
+
const titleLines = wrapText(ctx, title, contentWidth * 0.9, titleFontSize)
|
|
808
|
+
const titleLineHeight = titleFontSize * 1.2
|
|
809
|
+
|
|
810
|
+
for (let i = 0; i < titleLines.length; i++) {
|
|
811
|
+
ctx.fillText(titleLines[i], 0, startY + i * titleLineHeight)
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
startY += titleLines.length * titleLineHeight + 5
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// 绘制副标题
|
|
818
|
+
if (content) {
|
|
819
|
+
ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px/${contentHeight}px ${fontFamily}`
|
|
820
|
+
ctx.fillStyle = color
|
|
821
|
+
const contentLines = wrapText(ctx, content, contentWidth * 0.9, fontSize)
|
|
822
|
+
const contentLineHeight = fontSize * 1.2
|
|
823
|
+
|
|
824
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
825
|
+
ctx.fillText(contentLines[i], 0, startY + i * contentLineHeight)
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
ctx.restore()
|
|
830
|
+
waterMarkUrl.value = canvas.toDataURL()
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// 绘制图片和文字(在屏)
|
|
835
|
+
function drawImageAndTextOnScreen(
|
|
836
|
+
ctx: UniApp.CanvasContext,
|
|
837
|
+
image: string,
|
|
838
|
+
imageHeight: number,
|
|
839
|
+
imageWidth: number,
|
|
840
|
+
title: string,
|
|
841
|
+
content: string,
|
|
842
|
+
rotate: number,
|
|
843
|
+
contentWidth: number,
|
|
844
|
+
contentHeight: number,
|
|
845
|
+
fontSize: number,
|
|
846
|
+
titleFontSize: number,
|
|
847
|
+
color: string
|
|
848
|
+
) {
|
|
849
|
+
ctx.setTextBaseline('top')
|
|
850
|
+
ctx.setTextAlign('center')
|
|
851
|
+
ctx.translate(contentWidth / 2, contentWidth / 2)
|
|
852
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
853
|
+
|
|
854
|
+
const imgHeight = imageHeight * pixelRatio.value
|
|
855
|
+
const imgWidth = imageWidth * pixelRatio.value
|
|
856
|
+
const maxChars = Math.floor(contentWidth / (fontSize * 0.5))
|
|
857
|
+
|
|
879
858
|
// 计算总高度
|
|
880
|
-
let totalHeight = imgHeight
|
|
881
|
-
const textSpacing = 10
|
|
882
|
-
|
|
883
|
-
if (title) totalHeight += textSpacing + titleFontSize
|
|
884
|
-
if (content) totalHeight += fontSize
|
|
885
|
-
|
|
859
|
+
let totalHeight = imgHeight
|
|
860
|
+
const textSpacing = 10
|
|
861
|
+
|
|
862
|
+
if (title) totalHeight += textSpacing + titleFontSize
|
|
863
|
+
if (content) totalHeight += fontSize
|
|
864
|
+
|
|
886
865
|
// 起始Y坐标
|
|
887
|
-
let startY = -totalHeight / 2
|
|
888
|
-
|
|
866
|
+
let startY = -totalHeight / 2
|
|
867
|
+
|
|
889
868
|
// 绘制图片
|
|
890
|
-
ctx.drawImage(
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
imgWidth,
|
|
895
|
-
imgHeight,
|
|
896
|
-
);
|
|
897
|
-
|
|
898
|
-
startY += imgHeight + textSpacing;
|
|
899
|
-
|
|
900
|
-
// 设置文字样式
|
|
901
|
-
ctx.textBaseline = "top";
|
|
902
|
-
ctx.textAlign = "center";
|
|
903
|
-
|
|
869
|
+
ctx.drawImage(image, -imgWidth / 2, startY, imgWidth, imgHeight)
|
|
870
|
+
|
|
871
|
+
startY += imgHeight + textSpacing
|
|
872
|
+
|
|
904
873
|
// 绘制主标题
|
|
905
874
|
if (title) {
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
875
|
+
// 使用titleColor或默认color
|
|
876
|
+
ctx.setFillStyle(props.titleColor || color)
|
|
877
|
+
ctx.setFontSize(titleFontSize)
|
|
878
|
+
const titleLines = simpleWrapText(title, maxChars)
|
|
879
|
+
const titleLineHeight = titleFontSize * 1.2
|
|
880
|
+
|
|
881
|
+
for (let i = 0; i < titleLines.length; i++) {
|
|
882
|
+
ctx.fillText(titleLines[i], 0, startY + i * titleLineHeight)
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
startY += titleLines.length * titleLineHeight + 5
|
|
917
886
|
}
|
|
918
|
-
|
|
887
|
+
|
|
919
888
|
// 绘制副标题
|
|
920
889
|
if (content) {
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
for (let i = 0; i < contentLines.length; i++) {
|
|
927
|
-
ctx.fillText(contentLines[i], 0, startY + i * contentLineHeight);
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
|
|
931
|
-
ctx.restore();
|
|
932
|
-
waterMarkUrl.value = canvas.toDataURL();
|
|
933
|
-
};
|
|
934
|
-
}
|
|
890
|
+
ctx.setFillStyle(color)
|
|
891
|
+
ctx.setFontSize(fontSize)
|
|
892
|
+
const contentLines = simpleWrapText(content, maxChars)
|
|
893
|
+
const contentLineHeight = fontSize * 1.2
|
|
935
894
|
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
image: string,
|
|
940
|
-
imageHeight: number,
|
|
941
|
-
imageWidth: number,
|
|
942
|
-
title: string,
|
|
943
|
-
content: string,
|
|
944
|
-
rotate: number,
|
|
945
|
-
contentWidth: number,
|
|
946
|
-
contentHeight: number,
|
|
947
|
-
fontSize: number,
|
|
948
|
-
titleFontSize: number,
|
|
949
|
-
color: string
|
|
950
|
-
) {
|
|
951
|
-
ctx.setTextBaseline("top");
|
|
952
|
-
ctx.setTextAlign("center");
|
|
953
|
-
ctx.translate(contentWidth / 2, contentWidth / 2);
|
|
954
|
-
ctx.rotate((Math.PI / 180) * Number(rotate));
|
|
955
|
-
|
|
956
|
-
const imgHeight = imageHeight * pixelRatio.value;
|
|
957
|
-
const imgWidth = imageWidth * pixelRatio.value;
|
|
958
|
-
const maxChars = Math.floor(contentWidth / (fontSize * 0.5));
|
|
959
|
-
|
|
960
|
-
// 计算总高度
|
|
961
|
-
let totalHeight = imgHeight;
|
|
962
|
-
const textSpacing = 10;
|
|
963
|
-
|
|
964
|
-
if (title) totalHeight += textSpacing + titleFontSize;
|
|
965
|
-
if (content) totalHeight += fontSize;
|
|
966
|
-
|
|
967
|
-
// 起始Y坐标
|
|
968
|
-
let startY = -totalHeight / 2;
|
|
969
|
-
|
|
970
|
-
// 绘制图片
|
|
971
|
-
ctx.drawImage(
|
|
972
|
-
image,
|
|
973
|
-
-imgWidth / 2,
|
|
974
|
-
startY,
|
|
975
|
-
imgWidth,
|
|
976
|
-
imgHeight,
|
|
977
|
-
);
|
|
978
|
-
|
|
979
|
-
startY += imgHeight + textSpacing;
|
|
980
|
-
|
|
981
|
-
// 绘制主标题
|
|
982
|
-
if (title) {
|
|
983
|
-
// 使用titleColor或默认color
|
|
984
|
-
ctx.setFillStyle(props.titleColor || color);
|
|
985
|
-
ctx.setFontSize(titleFontSize);
|
|
986
|
-
const titleLines = simpleWrapText(title, maxChars);
|
|
987
|
-
const titleLineHeight = titleFontSize * 1.2;
|
|
988
|
-
|
|
989
|
-
for (let i = 0; i < titleLines.length; i++) {
|
|
990
|
-
ctx.fillText(titleLines[i], 0, startY + i * titleLineHeight);
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
startY += titleLines.length * titleLineHeight + 5;
|
|
994
|
-
}
|
|
995
|
-
|
|
996
|
-
// 绘制副标题
|
|
997
|
-
if (content) {
|
|
998
|
-
ctx.setFillStyle(color);
|
|
999
|
-
ctx.setFontSize(fontSize);
|
|
1000
|
-
const contentLines = simpleWrapText(content, maxChars);
|
|
1001
|
-
const contentLineHeight = fontSize * 1.2;
|
|
1002
|
-
|
|
1003
|
-
for (let i = 0; i < contentLines.length; i++) {
|
|
1004
|
-
ctx.fillText(contentLines[i], 0, startY + i * contentLineHeight);
|
|
895
|
+
for (let i = 0; i < contentLines.length; i++) {
|
|
896
|
+
ctx.fillText(contentLines[i], 0, startY + i * contentLineHeight)
|
|
897
|
+
}
|
|
1005
898
|
}
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
});
|
|
899
|
+
|
|
900
|
+
ctx.restore()
|
|
901
|
+
ctx.draw(false, () => {
|
|
902
|
+
// #ifdef MP-DINGTALK
|
|
903
|
+
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
904
|
+
;(ctx as any).toTempFilePath({
|
|
905
|
+
success(res: any) {
|
|
906
|
+
showCanvas.value = false
|
|
907
|
+
waterMarkUrl.value = res.filePath
|
|
908
|
+
}
|
|
909
|
+
})
|
|
910
|
+
// #endif
|
|
911
|
+
// #ifndef MP-DINGTALK
|
|
912
|
+
uni.canvasToTempFilePath({
|
|
913
|
+
canvasId: canvasId.value,
|
|
914
|
+
success: (res) => {
|
|
915
|
+
showCanvas.value = false
|
|
916
|
+
waterMarkUrl.value = res.tempFilePath
|
|
917
|
+
}
|
|
918
|
+
})
|
|
919
|
+
// #endif
|
|
920
|
+
})
|
|
1029
921
|
}
|
|
1030
922
|
|
|
1031
923
|
/**
|
|
@@ -1039,48 +931,48 @@ function drawImageAndTextOnScreen(
|
|
|
1039
931
|
* @param contentHeight 水印高度
|
|
1040
932
|
*/
|
|
1041
933
|
function drawImageOnScreen(
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
934
|
+
ctx: UniApp.CanvasContext,
|
|
935
|
+
image: string,
|
|
936
|
+
imageHeight: number,
|
|
937
|
+
imageWidth: number,
|
|
938
|
+
rotate: number,
|
|
939
|
+
contentWidth: number,
|
|
940
|
+
contentHeight: number
|
|
1049
941
|
) {
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
942
|
+
ctx.translate(contentWidth / 2, contentHeight / 2)
|
|
943
|
+
ctx.rotate((Math.PI / 180) * Number(rotate))
|
|
944
|
+
|
|
945
|
+
ctx.drawImage(
|
|
946
|
+
image,
|
|
947
|
+
(-imageWidth * pixelRatio.value) / 2,
|
|
948
|
+
(-imageHeight * pixelRatio.value) / 2,
|
|
949
|
+
imageWidth * pixelRatio.value,
|
|
950
|
+
imageHeight * pixelRatio.value
|
|
951
|
+
)
|
|
952
|
+
ctx.restore()
|
|
953
|
+
ctx.draw(false, () => {
|
|
954
|
+
// #ifdef MP-DINGTALK
|
|
955
|
+
// 钉钉小程序的canvasToTempFilePath接口与其他平台不一样
|
|
956
|
+
;(ctx as any).toTempFilePath({
|
|
957
|
+
success(res: any) {
|
|
958
|
+
showCanvas.value = false
|
|
959
|
+
waterMarkUrl.value = res.filePath
|
|
960
|
+
}
|
|
961
|
+
})
|
|
962
|
+
// #endif
|
|
963
|
+
// #ifndef MP-DINGTALK
|
|
964
|
+
uni.canvasToTempFilePath({
|
|
965
|
+
canvasId: canvasId.value,
|
|
966
|
+
success: (res) => {
|
|
967
|
+
showCanvas.value = false
|
|
968
|
+
waterMarkUrl.value = res.tempFilePath
|
|
969
|
+
}
|
|
970
|
+
})
|
|
971
|
+
// #endif
|
|
972
|
+
})
|
|
1081
973
|
}
|
|
1082
974
|
</script>
|
|
1083
975
|
|
|
1084
976
|
<style lang="scss" scoped>
|
|
1085
|
-
@import
|
|
977
|
+
@import './index.scss';
|
|
1086
978
|
</style>
|