@didaoktv/didaoui-uniapp 2.13.0 → 2.15.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/README.md +6 -6
- package/components/dd-album/dd-album.vue +280 -228
- package/components/dd-avatar/dd-avatar.vue +132 -75
- package/components/dd-avatar-group/dd-avatar-group.vue +52 -30
- package/components/dd-barcode/dd-barcode.vue +884 -947
- package/components/dd-button/dd-button.vue +47 -21
- package/components/dd-canvas/dd-canvas.vue +1156 -985
- package/components/dd-car-keyboard/dd-car-keyboard.vue +12 -12
- package/components/dd-champion-card/dd-champion-card.vue +49 -21
- package/components/dd-checkbox-group/dd-checkbox-group.vue +2 -0
- package/components/dd-copy/dd-copy.vue +51 -56
- package/components/dd-cropper/dd-cropper.vue +1224 -1135
- package/components/dd-divider/dd-divider.vue +9 -2
- package/components/dd-form/dd-form.vue +2 -0
- package/components/dd-goods-sku/dd-goods-sku.vue +6 -1
- package/components/dd-icon/dd-icon.vue +1 -1
- package/components/dd-keyboard/dd-keyboard.vue +95 -46
- package/components/dd-link/dd-link.vue +72 -49
- package/components/dd-markdown/dd-markdown.vue +154 -154
- package/components/dd-number-keyboard/dd-number-keyboard.vue +109 -94
- package/components/dd-package-sku/dd-package-sku.vue +24 -1
- package/components/dd-parse/dd-parse.vue +473 -442
- package/components/dd-poster/dd-poster.vue +579 -567
- package/components/dd-pull-refresh/dd-pull-refresh.vue +1 -9
- package/components/dd-qrcode/dd-qrcode.vue +431 -405
- package/components/dd-radio-group/dd-radio-group.vue +1 -1
- package/components/dd-segmented-tab/dd-segmented-tab.vue +61 -16
- package/components/dd-signature/dd-signature.vue +377 -357
- package/components/dd-step/dd-step.vue +1 -1
- package/components/dd-sticky/dd-sticky.vue +5 -10
- package/components/dd-swipe-action/dd-swipe-action.vue +1 -9
- package/components/dd-swipe-item/dd-swipe-item.vue +2 -0
- package/components/dd-swipeable-tab/dd-swipeable-tab.vue +1 -5
- package/components/dd-switch/dd-switch.vue +1 -1
- package/components/dd-text/dd-text.vue +304 -82
- package/components/dd-waterfall/dd-waterfall.vue +147 -0
- package/components/dd-waterfall/waterfall.ts +17 -0
- package/index.ts +4 -3
- package/libs/function/index.d.ts +88 -0
- package/libs/function/index.js +14 -0
- package/libs/function/test.d.ts +65 -0
- package/package.json +1 -1
- package/scss/_mixins.scss +8 -0
- package/scss/_theme-tokens.scss +7 -0
- package/scss/_variables.scss +283 -156
- package/components/dd-album/album.js +0 -19
- package/components/dd-album/props.js +0 -89
- package/components/dd-avatar/avatar.js +0 -19
- package/components/dd-avatar/props.js +0 -84
- package/components/dd-avatar-group/avatarGroup.js +0 -14
- package/components/dd-avatar-group/props.js +0 -57
- package/components/dd-keyboard/keyboard.js +0 -19
- package/components/dd-keyboard/props.js +0 -79
- package/components/dd-link/link.js +0 -17
- package/components/dd-link/props.js +0 -44
- package/components/dd-number-keyboard/numberKeyboard.js +0 -8
- package/components/dd-number-keyboard/props.js +0 -24
- package/components/dd-parse/props.js +0 -57
- package/components/dd-text/props.js +0 -120
- package/components/dd-text/text.js +0 -30
- package/components/dd-text/value.js +0 -87
- package/libs/config/color.js +0 -16
- package/libs/config/props.js +0 -184
- package/libs/mixin/button.js +0 -18
- package/libs/mixin/mixin.js +0 -44
- package/libs/mixin/mpMixin.js +0 -13
- package/libs/mixin/openType.js +0 -27
- package/libs/vue.js +0 -3
- package/scss/_dd-shared.scss +0 -40
|
@@ -71,350 +71,370 @@
|
|
|
71
71
|
</view>
|
|
72
72
|
</template>
|
|
73
73
|
|
|
74
|
-
<script>
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
74
|
+
<script setup lang="ts">
|
|
75
|
+
import { computed, nextTick, onMounted, ref, watch } from 'vue'
|
|
76
|
+
|
|
77
|
+
interface Props {
|
|
78
|
+
// 画布宽度
|
|
79
|
+
width?: string | number
|
|
80
|
+
// 画布高度
|
|
81
|
+
height?: string | number
|
|
82
|
+
// 背景颜色
|
|
83
|
+
bgColor?: string
|
|
84
|
+
// 默认笔画颜色
|
|
85
|
+
color?: string
|
|
86
|
+
// 默认笔画粗细
|
|
87
|
+
thickness?: string | number
|
|
88
|
+
// 是否显示工具栏
|
|
89
|
+
showToolbar?: boolean
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const props = withDefaults(defineProps<Props>(), {
|
|
93
|
+
width: 300,
|
|
94
|
+
height: 200,
|
|
95
|
+
bgColor: '#ffffff',
|
|
96
|
+
color: '#000000',
|
|
97
|
+
thickness: 3,
|
|
98
|
+
showToolbar: true,
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const emit = defineEmits<{
|
|
102
|
+
(e: 'clear'): void
|
|
103
|
+
(e: 'confirm', path: string): void
|
|
104
|
+
(e: 'error', error: unknown): void
|
|
105
|
+
}>()
|
|
106
|
+
|
|
107
|
+
const canvasId = 'dd-signature-' + Math.random().toString(36).substr(2, 9)
|
|
108
|
+
const canvasWidth = ref(300)
|
|
109
|
+
const canvasHeight = ref(200)
|
|
110
|
+
const lineColor = ref('')
|
|
111
|
+
const lineWidth = ref(3)
|
|
112
|
+
const isDrawing = ref(false)
|
|
113
|
+
const pathStack = ref<any[]>([]) // 存储绘制路径用于回退
|
|
114
|
+
const currentPath = ref<any[]>([]) // 当前绘制路径
|
|
115
|
+
const isEmpty = ref(true)
|
|
116
|
+
const presetColors = [
|
|
117
|
+
'#000000', // 黑色
|
|
118
|
+
'#ff0000', // 红色
|
|
119
|
+
'#00ff00', // 绿色
|
|
120
|
+
'#0000ff', // 蓝色
|
|
121
|
+
'#ffff00', // 黄色
|
|
122
|
+
'#00ffff', // 青色
|
|
123
|
+
'#ff00ff', // 紫色
|
|
124
|
+
'#ffffff' // 白色
|
|
125
|
+
]
|
|
126
|
+
const showBrushSettings = ref(false)
|
|
127
|
+
const showColorSettings = ref(false)
|
|
128
|
+
const lastPoint = ref<any>(null) // 保存上一个点的坐标
|
|
129
|
+
const canvasInstance = ref<any>(null) // 缓存canvas实例
|
|
130
|
+
const signatureCanvas = ref<any>(null)
|
|
131
|
+
|
|
132
|
+
// ponytail: 剥离运行时主题;签名画布默认保持白底(导出图片需白底)
|
|
133
|
+
const resolvedBgColor = computed(() => props.bgColor)
|
|
134
|
+
const iconDefaultColor = computed(() => '#999999')
|
|
135
|
+
const iconDisabledColor = computed(() => '#5c5c5c')
|
|
136
|
+
|
|
137
|
+
onMounted(() => {
|
|
138
|
+
// 初始化时获取canvas实例
|
|
139
|
+
nextTick(() => {
|
|
140
|
+
getCanvasInstance()
|
|
141
|
+
clearCanvas()
|
|
142
|
+
})
|
|
143
|
+
})
|
|
144
|
+
|
|
145
|
+
watch(
|
|
146
|
+
() => props.width,
|
|
147
|
+
(newVal: any) => {
|
|
148
|
+
canvasWidth.value = Number(newVal)
|
|
149
|
+
},
|
|
150
|
+
{ immediate: true }
|
|
151
|
+
)
|
|
152
|
+
watch(
|
|
153
|
+
() => props.height,
|
|
154
|
+
(newVal: any) => {
|
|
155
|
+
canvasHeight.value = Number(newVal)
|
|
156
|
+
},
|
|
157
|
+
{ immediate: true }
|
|
158
|
+
)
|
|
159
|
+
watch(
|
|
160
|
+
() => props.color,
|
|
161
|
+
(newVal: any) => {
|
|
162
|
+
lineColor.value = resolveStrokeColor(newVal)
|
|
163
|
+
},
|
|
164
|
+
{ immediate: true }
|
|
165
|
+
)
|
|
166
|
+
watch(
|
|
167
|
+
() => props.thickness,
|
|
168
|
+
(newVal: any) => {
|
|
169
|
+
lineWidth.value = Number(newVal)
|
|
170
|
+
},
|
|
171
|
+
{ immediate: true }
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
function resolveStrokeColor(color: any) {
|
|
175
|
+
return color
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
// 获取签名画布实例
|
|
179
|
+
function getCanvasInstance() {
|
|
180
|
+
if (canvasInstance.value) {
|
|
181
|
+
return canvasInstance.value
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
const canvasRef = signatureCanvas.value
|
|
185
|
+
if (canvasRef) {
|
|
186
|
+
canvasInstance.value = canvasRef
|
|
187
|
+
return canvasRef
|
|
188
|
+
}
|
|
189
|
+
return null
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function touchStart(e: any) {
|
|
193
|
+
if (!canvasInstance.value || !canvasInstance.value.ctx) {
|
|
194
|
+
getCanvasInstance()
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
if (!canvasInstance.value || !canvasInstance.value.ctx) return
|
|
198
|
+
|
|
199
|
+
isDrawing.value = true
|
|
200
|
+
isEmpty.value = false
|
|
201
|
+
currentPath.value = []
|
|
202
|
+
|
|
203
|
+
const { x, y } = getCanvasPoint(e)
|
|
204
|
+
|
|
205
|
+
// 设置线条样式
|
|
206
|
+
canvasInstance.value.setLineStyle(lineColor.value, lineWidth.value)
|
|
207
|
+
|
|
208
|
+
// 开始路径
|
|
209
|
+
canvasInstance.value.beginPath()
|
|
210
|
+
canvasInstance.value.moveTo(x, y)
|
|
211
|
+
|
|
212
|
+
// 记录起始点
|
|
213
|
+
currentPath.value.push({
|
|
214
|
+
x,
|
|
215
|
+
y,
|
|
216
|
+
type: 'start',
|
|
217
|
+
color: lineColor.value,
|
|
218
|
+
width: lineWidth.value
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
// 保存上一个点
|
|
222
|
+
lastPoint.value = { x, y }
|
|
223
|
+
|
|
224
|
+
// 阻止默认事件以提高性能
|
|
225
|
+
e.preventDefault()
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
function touchMove(e: any) {
|
|
229
|
+
if (!isDrawing.value || !canvasInstance.value || !canvasInstance.value.ctx) return
|
|
230
|
+
|
|
231
|
+
// 阻止默认事件以提高性能
|
|
232
|
+
e.preventDefault()
|
|
233
|
+
|
|
234
|
+
const { x, y } = getCanvasPoint(e)
|
|
235
|
+
|
|
236
|
+
// 从上一个点画线到当前点
|
|
237
|
+
canvasInstance.value.lineTo(x, y)
|
|
238
|
+
canvasInstance.value.stroke() // 实时绘制当前线段
|
|
239
|
+
currentPath.value.push({
|
|
240
|
+
x,
|
|
241
|
+
y,
|
|
242
|
+
type: 'move'
|
|
243
|
+
})
|
|
244
|
+
canvasInstance.value.draw(false)
|
|
245
|
+
|
|
246
|
+
// 更新上一个点
|
|
247
|
+
lastPoint.value = { x, y }
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
function touchEnd(e: any) {
|
|
251
|
+
if (!isDrawing.value || !canvasInstance.value || !canvasInstance.value.ctx) return
|
|
252
|
+
|
|
253
|
+
isDrawing.value = false
|
|
254
|
+
canvasInstance.value.closePath()
|
|
255
|
+
lastPoint.value = null
|
|
256
|
+
|
|
257
|
+
// 将当前路径加入栈中用于回退
|
|
258
|
+
if (currentPath.value.length > 0) {
|
|
259
|
+
pathStack.value.push([...currentPath.value])
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// 最后统一执行一次绘制
|
|
263
|
+
canvasInstance.value.draw(true)
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
// 同步获取canvas坐标点(兼容处理)
|
|
267
|
+
function getCanvasPoint(e: any) {
|
|
268
|
+
let touch
|
|
269
|
+
// #ifdef MP-WEIXIN
|
|
270
|
+
touch = e.touches && e.touches[0] ? e.touches[0] : e.mp.touches[0]
|
|
271
|
+
// #endif
|
|
272
|
+
// #ifndef MP-WEIXIN
|
|
273
|
+
touch = e.touches[0]
|
|
274
|
+
// #endif
|
|
275
|
+
|
|
276
|
+
// 计算相对于canvas的坐标
|
|
277
|
+
// 由于无法直接获取canvas位置,这里简化处理
|
|
278
|
+
// 实际应用中可能需要通过uni.createSelectorQuery获取canvas位置
|
|
279
|
+
return {
|
|
280
|
+
x: touch.x,
|
|
281
|
+
y: touch.y
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// 选择颜色
|
|
286
|
+
function selectColor(color: string) {
|
|
287
|
+
lineColor.value = color
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
// 回退操作
|
|
291
|
+
function undo() {
|
|
292
|
+
if (pathStack.value.length === 0) return
|
|
293
|
+
|
|
294
|
+
// 弹出最后一个路径
|
|
295
|
+
pathStack.value.pop()
|
|
296
|
+
|
|
297
|
+
// 重新绘制
|
|
298
|
+
redraw()
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
// 重新绘制所有路径
|
|
302
|
+
function redraw() {
|
|
303
|
+
if (!canvasInstance.value) {
|
|
304
|
+
getCanvasInstance()
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
if (!canvasInstance.value) return
|
|
308
|
+
|
|
309
|
+
// 先清空画布
|
|
310
|
+
canvasInstance.value.clearCanvas()
|
|
311
|
+
|
|
312
|
+
if (pathStack.value.length === 0) {
|
|
313
|
+
isEmpty.value = true
|
|
314
|
+
return
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
isEmpty.value = false
|
|
318
|
+
|
|
319
|
+
// 逐个绘制路径
|
|
320
|
+
pathStack.value.forEach((path: any) => {
|
|
321
|
+
if (path.length === 0) return
|
|
322
|
+
|
|
323
|
+
canvasInstance.value.beginPath()
|
|
324
|
+
|
|
325
|
+
let lastPoint = null
|
|
326
|
+
path.forEach((point: any, index: number) => {
|
|
327
|
+
if (index === 0 && point.type === 'start') {
|
|
213
328
|
// 设置线条样式
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
touchEnd(e) {
|
|
259
|
-
if (!this.isDrawing || !this.canvasInstance || !this.canvasInstance.ctx) return;
|
|
260
|
-
|
|
261
|
-
this.isDrawing = false;
|
|
262
|
-
this.canvasInstance.closePath();
|
|
263
|
-
this.lastPoint = null;
|
|
264
|
-
|
|
265
|
-
// 将当前路径加入栈中用于回退
|
|
266
|
-
if (this.currentPath.length > 0) {
|
|
267
|
-
this.pathStack.push([...this.currentPath]);
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
// 最后统一执行一次绘制
|
|
271
|
-
this.canvasInstance.draw(true);
|
|
272
|
-
},
|
|
273
|
-
|
|
274
|
-
// 同步获取canvas坐标点(兼容处理)
|
|
275
|
-
getCanvasPoint(e) {
|
|
276
|
-
let touch;
|
|
277
|
-
// #ifdef MP-WEIXIN
|
|
278
|
-
touch = e.touches && e.touches[0] ? e.touches[0] : e.mp.touches[0];
|
|
279
|
-
// #endif
|
|
280
|
-
// #ifndef MP-WEIXIN
|
|
281
|
-
touch = e.touches[0];
|
|
282
|
-
// #endif
|
|
283
|
-
|
|
284
|
-
// 计算相对于canvas的坐标
|
|
285
|
-
// 由于无法直接获取canvas位置,这里简化处理
|
|
286
|
-
// 实际应用中可能需要通过uni.createSelectorQuery获取canvas位置
|
|
287
|
-
return {
|
|
288
|
-
x: touch.x,
|
|
289
|
-
y: touch.y
|
|
290
|
-
};
|
|
291
|
-
},
|
|
292
|
-
|
|
293
|
-
// 选择颜色
|
|
294
|
-
selectColor(color) {
|
|
295
|
-
this.lineColor = color
|
|
296
|
-
},
|
|
297
|
-
|
|
298
|
-
// 回退操作
|
|
299
|
-
undo() {
|
|
300
|
-
if (this.pathStack.length === 0) return
|
|
301
|
-
|
|
302
|
-
// 弹出最后一个路径
|
|
303
|
-
this.pathStack.pop()
|
|
304
|
-
|
|
305
|
-
// 重新绘制
|
|
306
|
-
this.redraw()
|
|
307
|
-
},
|
|
308
|
-
|
|
309
|
-
// 重新绘制所有路径
|
|
310
|
-
redraw() {
|
|
311
|
-
if (!this.canvasInstance) {
|
|
312
|
-
this.getCanvasInstance();
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
if (!this.canvasInstance) return;
|
|
316
|
-
|
|
317
|
-
// 先清空画布
|
|
318
|
-
this.canvasInstance.clearCanvas();
|
|
319
|
-
|
|
320
|
-
if (this.pathStack.length === 0) {
|
|
321
|
-
this.isEmpty = true;
|
|
322
|
-
return;
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
this.isEmpty = false;
|
|
326
|
-
|
|
327
|
-
// 逐个绘制路径
|
|
328
|
-
this.pathStack.forEach(path => {
|
|
329
|
-
if (path.length === 0) return;
|
|
330
|
-
|
|
331
|
-
this.canvasInstance.beginPath();
|
|
332
|
-
|
|
333
|
-
let lastPoint = null;
|
|
334
|
-
path.forEach((point, index) => {
|
|
335
|
-
if (index === 0 && point.type === 'start') {
|
|
336
|
-
// 设置线条样式
|
|
337
|
-
this.canvasInstance.setLineStyle(point.color, point.width);
|
|
338
|
-
this.canvasInstance.moveTo(point.x, point.y);
|
|
339
|
-
lastPoint = { x: point.x, y: point.y };
|
|
340
|
-
} else if (point.type === 'move') {
|
|
341
|
-
this.canvasInstance.lineTo(point.x, point.y);
|
|
342
|
-
lastPoint = { x: point.x, y: point.y };
|
|
343
|
-
}
|
|
344
|
-
});
|
|
345
|
-
this.canvasInstance.stroke();
|
|
346
|
-
this.canvasInstance.draw(true);
|
|
347
|
-
});
|
|
348
|
-
},
|
|
349
|
-
|
|
350
|
-
// 清空画布内容
|
|
351
|
-
clearCanvas() {
|
|
352
|
-
if (!this.canvasInstance) {
|
|
353
|
-
this.getCanvasInstance();
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
if (!this.canvasInstance) return;
|
|
357
|
-
|
|
358
|
-
this.canvasInstance.clearCanvas();
|
|
359
|
-
},
|
|
360
|
-
|
|
361
|
-
// 对外暴露的清空方法(供工具栏与ref调用)
|
|
362
|
-
clear() {
|
|
363
|
-
this.pathStack = []
|
|
364
|
-
this.currentPath = []
|
|
365
|
-
this.lastPoint = null
|
|
366
|
-
this.isDrawing = false
|
|
367
|
-
this.isEmpty = true
|
|
368
|
-
this.clearCanvas()
|
|
369
|
-
this.$emit('clear')
|
|
370
|
-
},
|
|
371
|
-
|
|
372
|
-
// 导出签名图片
|
|
373
|
-
async exportSignature() {
|
|
374
|
-
if (this.isEmpty) {
|
|
375
|
-
console.warn('签名为空,无法导出');
|
|
376
|
-
return;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (!this.canvasInstance) {
|
|
380
|
-
this.getCanvasInstance();
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
if (!this.canvasInstance) {
|
|
384
|
-
console.error('无法获取画布实例');
|
|
385
|
-
return;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
try {
|
|
389
|
-
// 先重绘整个签名内容
|
|
390
|
-
this.redraw();
|
|
391
|
-
|
|
392
|
-
// 导出图片
|
|
393
|
-
const imagePath = await this.canvasInstance.exportImage('png', 1);
|
|
394
|
-
this.$emit('confirm', imagePath);
|
|
395
|
-
} catch (error) {
|
|
396
|
-
console.error('导出签名图片失败:', error);
|
|
397
|
-
this.$emit('error', error);
|
|
398
|
-
}
|
|
399
|
-
},
|
|
400
|
-
|
|
401
|
-
// 切换笔画设置显示
|
|
402
|
-
toggleBrushSettings() {
|
|
403
|
-
this.showBrushSettings = !this.showBrushSettings;
|
|
404
|
-
if (this.showBrushSettings) {
|
|
405
|
-
this.showColorSettings = false;
|
|
406
|
-
}
|
|
407
|
-
},
|
|
408
|
-
|
|
409
|
-
// 切换颜色设置显示
|
|
410
|
-
toggleColorSettings() {
|
|
411
|
-
this.showColorSettings = !this.showColorSettings;
|
|
412
|
-
if (this.showColorSettings) {
|
|
413
|
-
this.showBrushSettings = false;
|
|
414
|
-
}
|
|
415
|
-
},
|
|
416
|
-
}
|
|
329
|
+
canvasInstance.value.setLineStyle(point.color, point.width)
|
|
330
|
+
canvasInstance.value.moveTo(point.x, point.y)
|
|
331
|
+
lastPoint = { x: point.x, y: point.y }
|
|
332
|
+
} else if (point.type === 'move') {
|
|
333
|
+
canvasInstance.value.lineTo(point.x, point.y)
|
|
334
|
+
lastPoint = { x: point.x, y: point.y }
|
|
335
|
+
}
|
|
336
|
+
})
|
|
337
|
+
canvasInstance.value.stroke()
|
|
338
|
+
canvasInstance.value.draw(true)
|
|
339
|
+
})
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
// 清空画布内容
|
|
343
|
+
function clearCanvas() {
|
|
344
|
+
if (!canvasInstance.value) {
|
|
345
|
+
getCanvasInstance()
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (!canvasInstance.value) return
|
|
349
|
+
|
|
350
|
+
canvasInstance.value.clearCanvas()
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// 对外暴露的清空方法(供工具栏与ref调用)
|
|
354
|
+
function clear() {
|
|
355
|
+
pathStack.value = []
|
|
356
|
+
currentPath.value = []
|
|
357
|
+
lastPoint.value = null
|
|
358
|
+
isDrawing.value = false
|
|
359
|
+
isEmpty.value = true
|
|
360
|
+
clearCanvas()
|
|
361
|
+
emit('clear')
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// 导出签名图片
|
|
365
|
+
async function exportSignature() {
|
|
366
|
+
if (isEmpty.value) {
|
|
367
|
+
console.warn('签名为空,无法导出')
|
|
368
|
+
return
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
if (!canvasInstance.value) {
|
|
372
|
+
getCanvasInstance()
|
|
417
373
|
}
|
|
374
|
+
|
|
375
|
+
if (!canvasInstance.value) {
|
|
376
|
+
console.error('无法获取画布实例')
|
|
377
|
+
return
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
try {
|
|
381
|
+
// 先重绘整个签名内容
|
|
382
|
+
redraw()
|
|
383
|
+
|
|
384
|
+
// 导出图片
|
|
385
|
+
const imagePath = await canvasInstance.value.exportImage('png', 1)
|
|
386
|
+
emit('confirm', imagePath)
|
|
387
|
+
} catch (error) {
|
|
388
|
+
console.error('导出签名图片失败:', error)
|
|
389
|
+
emit('error', error)
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
// 切换笔画设置显示
|
|
394
|
+
function toggleBrushSettings() {
|
|
395
|
+
showBrushSettings.value = !showBrushSettings.value
|
|
396
|
+
if (showBrushSettings.value) {
|
|
397
|
+
showColorSettings.value = false
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
// 切换颜色设置显示
|
|
402
|
+
function toggleColorSettings() {
|
|
403
|
+
showColorSettings.value = !showColorSettings.value
|
|
404
|
+
if (showColorSettings.value) {
|
|
405
|
+
showBrushSettings.value = false
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
defineExpose({
|
|
410
|
+
canvasId,
|
|
411
|
+
canvasWidth,
|
|
412
|
+
canvasHeight,
|
|
413
|
+
lineColor,
|
|
414
|
+
lineWidth,
|
|
415
|
+
isDrawing,
|
|
416
|
+
pathStack,
|
|
417
|
+
currentPath,
|
|
418
|
+
isEmpty,
|
|
419
|
+
presetColors,
|
|
420
|
+
showBrushSettings,
|
|
421
|
+
showColorSettings,
|
|
422
|
+
lastPoint,
|
|
423
|
+
resolveStrokeColor,
|
|
424
|
+
getCanvasInstance,
|
|
425
|
+
touchStart,
|
|
426
|
+
touchMove,
|
|
427
|
+
touchEnd,
|
|
428
|
+
getCanvasPoint,
|
|
429
|
+
selectColor,
|
|
430
|
+
undo,
|
|
431
|
+
redraw,
|
|
432
|
+
clearCanvas,
|
|
433
|
+
clear,
|
|
434
|
+
exportSignature,
|
|
435
|
+
toggleBrushSettings,
|
|
436
|
+
toggleColorSettings,
|
|
437
|
+
})
|
|
418
438
|
</script>
|
|
419
439
|
|
|
420
440
|
<style lang="scss" scoped>
|
|
@@ -426,7 +446,7 @@
|
|
|
426
446
|
|
|
427
447
|
&__canvas-wrap {
|
|
428
448
|
border: 1px solid var(--dd-border-default, #{$dd-border-default});
|
|
429
|
-
border-radius:
|
|
449
|
+
border-radius: $dd-radius-md;
|
|
430
450
|
overflow: hidden;
|
|
431
451
|
}
|
|
432
452
|
|
|
@@ -436,7 +456,7 @@
|
|
|
436
456
|
}
|
|
437
457
|
|
|
438
458
|
&__toolbar {
|
|
439
|
-
margin-top:
|
|
459
|
+
margin-top: 10rpx;
|
|
440
460
|
background-color: var(--dd-bg-elevated, #{$dd-bg-elevated});
|
|
441
461
|
}
|
|
442
462
|
|
|
@@ -446,38 +466,38 @@
|
|
|
446
466
|
align-items: center;
|
|
447
467
|
padding: 1px 0;
|
|
448
468
|
// border: 1px solid #e0e0e0;
|
|
449
|
-
border-radius:
|
|
469
|
+
border-radius: $dd-radius-md;
|
|
450
470
|
}
|
|
451
471
|
|
|
452
472
|
&__toolbar-icon {
|
|
453
|
-
padding:
|
|
473
|
+
padding: 10rpx;
|
|
454
474
|
}
|
|
455
475
|
|
|
456
476
|
&__brush-settings,
|
|
457
477
|
&__color-settings {
|
|
458
|
-
margin-top:
|
|
478
|
+
margin-top: 30rpx;
|
|
459
479
|
padding: 1px;
|
|
460
480
|
// border: 1px solid #e0e0e0;
|
|
461
|
-
border-radius:
|
|
481
|
+
border-radius: $dd-radius-md;
|
|
462
482
|
}
|
|
463
483
|
|
|
464
484
|
&__progress {
|
|
465
485
|
&-label {
|
|
466
486
|
display: block;
|
|
467
|
-
margin-bottom:
|
|
468
|
-
font-size:
|
|
487
|
+
margin-bottom: 20rpx;
|
|
488
|
+
font-size: $dd-font-size-body;
|
|
469
489
|
color: var(--dd-text-tertiary, #{$dd-text-tertiary});
|
|
470
490
|
}
|
|
471
491
|
}
|
|
472
492
|
|
|
473
493
|
&__color-picker {
|
|
474
|
-
margin-bottom:
|
|
494
|
+
margin-bottom: 20rpx;
|
|
475
495
|
}
|
|
476
496
|
|
|
477
497
|
&__color-label {
|
|
478
498
|
display: block;
|
|
479
|
-
margin-bottom:
|
|
480
|
-
font-size:
|
|
499
|
+
margin-bottom: 20rpx;
|
|
500
|
+
font-size: $dd-font-size-body;
|
|
481
501
|
color: var(--dd-text-tertiary, #{$dd-text-tertiary});
|
|
482
502
|
}
|
|
483
503
|
|
|
@@ -485,12 +505,12 @@
|
|
|
485
505
|
display: flex;
|
|
486
506
|
flex-direction: row;
|
|
487
507
|
flex-wrap: wrap;
|
|
488
|
-
gap:
|
|
508
|
+
gap: 20rpx;
|
|
489
509
|
}
|
|
490
510
|
|
|
491
511
|
&__color-item {
|
|
492
|
-
width:
|
|
493
|
-
height:
|
|
512
|
+
width: 60rpx;
|
|
513
|
+
height: 60rpx;
|
|
494
514
|
border-radius: 50%;
|
|
495
515
|
border: 2px solid var(--dd-border-default, #{$dd-border-default});
|
|
496
516
|
cursor: pointer;
|
|
@@ -504,7 +524,7 @@
|
|
|
504
524
|
&__actions {
|
|
505
525
|
display: flex;
|
|
506
526
|
flex-direction: row;
|
|
507
|
-
gap:
|
|
527
|
+
gap: 20rpx;
|
|
508
528
|
justify-content: center;
|
|
509
529
|
}
|
|
510
530
|
}
|