@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.
Files changed (69) hide show
  1. package/README.md +6 -6
  2. package/components/dd-album/dd-album.vue +280 -228
  3. package/components/dd-avatar/dd-avatar.vue +132 -75
  4. package/components/dd-avatar-group/dd-avatar-group.vue +52 -30
  5. package/components/dd-barcode/dd-barcode.vue +884 -947
  6. package/components/dd-button/dd-button.vue +47 -21
  7. package/components/dd-canvas/dd-canvas.vue +1156 -985
  8. package/components/dd-car-keyboard/dd-car-keyboard.vue +12 -12
  9. package/components/dd-champion-card/dd-champion-card.vue +49 -21
  10. package/components/dd-checkbox-group/dd-checkbox-group.vue +2 -0
  11. package/components/dd-copy/dd-copy.vue +51 -56
  12. package/components/dd-cropper/dd-cropper.vue +1224 -1135
  13. package/components/dd-divider/dd-divider.vue +9 -2
  14. package/components/dd-form/dd-form.vue +2 -0
  15. package/components/dd-goods-sku/dd-goods-sku.vue +6 -1
  16. package/components/dd-icon/dd-icon.vue +1 -1
  17. package/components/dd-keyboard/dd-keyboard.vue +95 -46
  18. package/components/dd-link/dd-link.vue +72 -49
  19. package/components/dd-markdown/dd-markdown.vue +154 -154
  20. package/components/dd-number-keyboard/dd-number-keyboard.vue +109 -94
  21. package/components/dd-package-sku/dd-package-sku.vue +24 -1
  22. package/components/dd-parse/dd-parse.vue +473 -442
  23. package/components/dd-poster/dd-poster.vue +579 -567
  24. package/components/dd-pull-refresh/dd-pull-refresh.vue +1 -9
  25. package/components/dd-qrcode/dd-qrcode.vue +431 -405
  26. package/components/dd-radio-group/dd-radio-group.vue +1 -1
  27. package/components/dd-segmented-tab/dd-segmented-tab.vue +61 -16
  28. package/components/dd-signature/dd-signature.vue +377 -357
  29. package/components/dd-step/dd-step.vue +1 -1
  30. package/components/dd-sticky/dd-sticky.vue +5 -10
  31. package/components/dd-swipe-action/dd-swipe-action.vue +1 -9
  32. package/components/dd-swipe-item/dd-swipe-item.vue +2 -0
  33. package/components/dd-swipeable-tab/dd-swipeable-tab.vue +1 -5
  34. package/components/dd-switch/dd-switch.vue +1 -1
  35. package/components/dd-text/dd-text.vue +304 -82
  36. package/components/dd-waterfall/dd-waterfall.vue +147 -0
  37. package/components/dd-waterfall/waterfall.ts +17 -0
  38. package/index.ts +4 -3
  39. package/libs/function/index.d.ts +88 -0
  40. package/libs/function/index.js +14 -0
  41. package/libs/function/test.d.ts +65 -0
  42. package/package.json +1 -1
  43. package/scss/_mixins.scss +8 -0
  44. package/scss/_theme-tokens.scss +7 -0
  45. package/scss/_variables.scss +283 -156
  46. package/components/dd-album/album.js +0 -19
  47. package/components/dd-album/props.js +0 -89
  48. package/components/dd-avatar/avatar.js +0 -19
  49. package/components/dd-avatar/props.js +0 -84
  50. package/components/dd-avatar-group/avatarGroup.js +0 -14
  51. package/components/dd-avatar-group/props.js +0 -57
  52. package/components/dd-keyboard/keyboard.js +0 -19
  53. package/components/dd-keyboard/props.js +0 -79
  54. package/components/dd-link/link.js +0 -17
  55. package/components/dd-link/props.js +0 -44
  56. package/components/dd-number-keyboard/numberKeyboard.js +0 -8
  57. package/components/dd-number-keyboard/props.js +0 -24
  58. package/components/dd-parse/props.js +0 -57
  59. package/components/dd-text/props.js +0 -120
  60. package/components/dd-text/text.js +0 -30
  61. package/components/dd-text/value.js +0 -87
  62. package/libs/config/color.js +0 -16
  63. package/libs/config/props.js +0 -184
  64. package/libs/mixin/button.js +0 -18
  65. package/libs/mixin/mixin.js +0 -44
  66. package/libs/mixin/mpMixin.js +0 -13
  67. package/libs/mixin/openType.js +0 -27
  68. package/libs/vue.js +0 -3
  69. package/scss/_dd-shared.scss +0 -40
@@ -41,437 +41,464 @@
41
41
  </view>
42
42
  </template>
43
43
 
44
- <script>
45
- import QRCode from "./qrcode.js"
46
- export default {
47
- name: "dd-qrcode",
48
- props: {
49
- cid: {
50
- type: String,
51
- default: () => {
52
- return `dd-qrcode-canvas${Math.floor(Math.random() * 1000000)}`
53
- }
54
- },
55
- size: {
56
- type: Number,
57
- default: 200
58
- },
59
- unit: {
60
- type: String,
61
- default: 'px'
62
- },
63
- show: {
64
- type: Boolean,
65
- default: true
66
- },
67
- val: {
68
- type: String,
69
- default: ''
70
- },
71
- background: {
72
- type: String,
73
- default: '#ffffff'
74
- },
75
- foreground: {
76
- type: String,
77
- default: '#000000'
78
- },
79
- pdground: {
80
- type: String,
81
- default: '#000000'
82
- },
83
- icon: {
84
- type: String,
85
- default: ''
86
- },
87
- iconSize: {
88
- type: Number,
89
- default: 40
90
- },
91
- lv: {
92
- type: Number,
93
- default: 3
94
- },
95
- quietZone: {
96
- type: Number,
97
- default: 0
98
- },
99
- onval: {
100
- type: Boolean,
101
- default: true
102
- },
103
- loadMake: {
104
- type: Boolean,
105
- default: true
106
- },
107
- usingComponents: {
108
- type: Boolean,
109
- default: true
110
- },
111
- showLoading: {
112
- type: Boolean,
113
- default: true
114
- },
115
- loadingText: {
116
- type: String,
117
- default: '生成中'
118
- },
119
- allowPreview: {
120
- type: Boolean,
121
- default: false
122
- },
123
- // 是否使用根节点宽高
124
- useRootHeightAndWidth: {
125
- type: Boolean,
126
- default: () => false
127
- },
128
- },
129
- emits: ['preview', 'result', 'longpressCallback'],
130
- data() {
131
- return {
132
- loading: false,
133
- result: '',
134
- popupShow: false,
135
- list: [
136
- {
137
- name: '保存二维码',
138
- }
139
- ],
140
- rootId: `rootId${Number(Math.random() * 100).toFixed(0)}`,
141
- canvasObj: {},
142
- sizeLocal: this.size,
143
- ctx: null,
144
- isNvue: false,
145
- canvasHost: null
146
- }
44
+ <script setup lang="ts">
45
+ import { getCurrentInstance, nextTick, onMounted, ref, watch } from 'vue'
46
+ // @ts-ignore qrcode.js 无类型声明
47
+ import QRCode from './qrcode.js'
48
+
49
+ interface Props {
50
+ cid?: string
51
+ size?: number
52
+ unit?: string
53
+ show?: boolean
54
+ val?: string
55
+ background?: string
56
+ foreground?: string
57
+ pdground?: string
58
+ icon?: string
59
+ iconSize?: number
60
+ lv?: number
61
+ quietZone?: number
62
+ onval?: boolean
63
+ loadMake?: boolean
64
+ usingComponents?: boolean
65
+ showLoading?: boolean
66
+ loadingText?: string
67
+ allowPreview?: boolean
68
+ // 是否使用根节点宽高
69
+ useRootHeightAndWidth?: boolean
70
+ }
71
+
72
+ const props = withDefaults(defineProps<Props>(), {
73
+ cid: () => {
74
+ return `dd-qrcode-canvas${Math.floor(Math.random() * 1000000)}`
147
75
  },
148
- created() {
149
- this._qrcode = null
76
+ size: 200,
77
+ unit: 'px',
78
+ show: true,
79
+ val: '',
80
+ background: '#ffffff',
81
+ foreground: '#000000',
82
+ pdground: '#000000',
83
+ icon: '',
84
+ iconSize: 40,
85
+ lv: 3,
86
+ quietZone: 0,
87
+ onval: true,
88
+ loadMake: true,
89
+ usingComponents: true,
90
+ showLoading: true,
91
+ loadingText: '生成中',
92
+ allowPreview: false,
93
+ useRootHeightAndWidth: () => false,
94
+ })
95
+
96
+ const emit = defineEmits<{
97
+ (e: 'preview', payload: { url: string }, event: any): void
98
+ (e: 'result', res: any): void
99
+ (e: 'longpressCallback', path: any): void
100
+ }>()
101
+
102
+ const instance = getCurrentInstance()
103
+ const qrcodeCanvas = ref<any>(null)
104
+
105
+ const loading = ref(false)
106
+ const result = ref('')
107
+ const popupShow = ref(false)
108
+ const list = [
109
+ {
110
+ name: '保存二维码',
150
111
  },
151
- async mounted(){
152
- // 如果使用根节点的宽高 则 重新设置 size
153
- if(this.useRootHeightAndWidth){
154
- await this.setNewSize()
155
- }
156
- // #ifdef APP-NVUE
157
- this.isNvue = true
158
- // #endif
159
- await this.initCanvas()
112
+ ]
113
+ const rootId = `rootId${Number(Math.random() * 100).toFixed(0)}`
114
+ const canvasObj = ref({})
115
+ const sizeLocal = ref(props.size)
116
+ const ctx = ref<any>(null)
117
+ const isNvue = ref(false)
118
+ const canvasHost = ref<any>(null)
160
119
 
161
- if (this.loadMake) {
162
- if (!this._empty(this.val)) {
120
+ let _qrcode: any = null
121
+
122
+ onMounted(async () => {
123
+ // 如果使用根节点的宽高 则 重新设置 size
124
+ if (props.useRootHeightAndWidth) {
125
+ await setNewSize()
126
+ }
127
+ // #ifdef APP-NVUE
128
+ isNvue.value = true
129
+ // #endif
130
+ await initCanvas()
131
+
132
+ if (props.loadMake) {
133
+ if (!_empty(props.val)) {
134
+ setTimeout(() => {
163
135
  setTimeout(() => {
164
- setTimeout(()=>{
165
- this._makeCode().catch(error => {
166
- console.error('二维码生成失败', error)
167
- })
136
+ _makeCode().catch(error => {
137
+ console.error('二维码生成失败', error)
168
138
  })
169
- }, 0);
170
- }
139
+ })
140
+ }, 0)
171
141
  }
172
- },
173
- methods: {
174
- async _makeCode() {
175
- let that = this
176
- if (this._empty(this.val)) {
177
- uni.showToast({
178
- title: '二维码内容不能为空',
179
- icon: 'none',
180
- duration: 2000
181
- });
182
- return ''
183
- }
184
- if (!this.ctx) {
185
- await this.initCanvas(true)
186
- }
187
- if (!this.ctx) throw new Error('无法获取二维码画布实例')
188
- return new Promise((resolve, reject) => {
189
- this.loading = true
190
- try {
191
- this._qrcode = new QRCode({
192
- vuectx: that, // 上下文环境
193
- canvasId: that.cid, // canvas-id
194
- ctx: that.ctx,
195
- canvasHost: that.canvasHost,
196
- isNvue: that.isNvue,
197
- usingComponents: that.usingComponents, // 是否是自定义组件
198
- showLoading: false, // 是否显示loading
199
- loadingText: that.loadingText, // loading文字
200
- text: that.val, // 生成内容
201
- size: that.sizeLocal, // 二维码大小
202
- width: that.sizeLocal,
203
- height: that.sizeLocal,
204
- background: that.background, // 背景色
205
- foreground: that.foreground, // 前景色
206
- pdground: that.pdground, // 定位角点颜色
207
- quietZone: that.quietZone, // 静区宽度
208
- correctLevel: that.lv, // 容错级别
209
- image: that.icon, // 二维码图标
210
- imageSize: that.iconSize,// 二维码图标大小
211
- cbResult: function (res) { // 生成二维码的回调
212
- if (typeof res === 'string') {
213
- that._result(res)
214
- resolve(res)
215
- } else {
216
- that.loading = false
217
- reject(res instanceof Error ? res : new Error(`二维码生成失败: ${JSON.stringify(res)}`))
218
- }
219
- },
220
- });
221
- } catch (error) {
222
- that.loading = false
223
- reject(error)
224
- }
142
+ }
143
+ })
144
+
145
+ async function _makeCode() {
146
+ if (_empty(props.val)) {
147
+ uni.showToast({
148
+ title: '二维码内容不能为空',
149
+ icon: 'none',
150
+ duration: 2000,
151
+ })
152
+ return ''
153
+ }
154
+ if (!ctx.value) {
155
+ await initCanvas(true)
156
+ }
157
+ if (!ctx.value) throw new Error('无法获取二维码画布实例')
158
+ return new Promise((resolve, reject) => {
159
+ loading.value = true
160
+ try {
161
+ _qrcode = new QRCode({
162
+ vuectx: { drawImage }, // 上下文环境
163
+ canvasId: props.cid, // canvas-id
164
+ ctx: ctx.value,
165
+ canvasHost: canvasHost.value,
166
+ isNvue: isNvue.value,
167
+ usingComponents: props.usingComponents, // 是否是自定义组件
168
+ showLoading: false, // 是否显示loading
169
+ loadingText: props.loadingText, // loading文字
170
+ text: props.val, // 生成内容
171
+ size: sizeLocal.value, // 二维码大小
172
+ width: sizeLocal.value,
173
+ height: sizeLocal.value,
174
+ background: props.background, // 背景色
175
+ foreground: props.foreground, // 前景色
176
+ pdground: props.pdground, // 定位角点颜色
177
+ quietZone: props.quietZone, // 静区宽度
178
+ correctLevel: props.lv, // 容错级别
179
+ image: props.icon, // 二维码图标
180
+ imageSize: props.iconSize, // 二维码图标大小
181
+ cbResult: function (res: any) {
182
+ // 生成二维码的回调
183
+ if (typeof res === 'string') {
184
+ _result(res)
185
+ resolve(res)
186
+ } else {
187
+ loading.value = false
188
+ reject(res instanceof Error ? res : new Error(`二维码生成失败: ${JSON.stringify(res)}`))
189
+ }
190
+ },
225
191
  })
226
- },
227
- _clearCode() {
228
- this._result('')
229
- if (this._qrcode) this._qrcode.clear()
230
- },
231
- _saveCode() {
232
- let that = this;
233
- if (this.result != "") {
192
+ } catch (error) {
193
+ loading.value = false
194
+ reject(error)
195
+ }
196
+ })
197
+ }
198
+
199
+ function _clearCode() {
200
+ _result('')
201
+ if (_qrcode) _qrcode.clear()
202
+ }
203
+
204
+ function _saveCode() {
205
+ if (result.value != '') {
206
+ uni.saveImageToPhotosAlbum({
207
+ filePath: result.value,
208
+ success: function () {
209
+ uni.showToast({
210
+ title: '二维码保存成功',
211
+ icon: 'success',
212
+ duration: 2000,
213
+ })
214
+ },
215
+ })
216
+ } else {
217
+ toTempFilePath({
218
+ success: (res: any) => {
219
+ result.value = res.tempFilePath
234
220
  uni.saveImageToPhotosAlbum({
235
- filePath: that.result,
221
+ filePath: result.value,
236
222
  success: function () {
237
223
  uni.showToast({
238
224
  title: '二维码保存成功',
239
225
  icon: 'success',
240
- duration: 2000
241
- });
242
- }
243
- });
244
- } else {
245
- this.toTempFilePath({
246
- success: res => {
247
- that.result = res.tempFilePath
248
- uni.saveImageToPhotosAlbum({
249
- filePath: that.result,
250
- success: function () {
251
- uni.showToast({
252
- title: '二维码保存成功',
253
- icon: 'success',
254
- duration: 2000
255
- });
256
- }
257
- });
258
- },
259
- fail: err => {
260
- }
261
- })
262
- }
263
- },
264
- preview(e) {
265
- // 预览图片
266
- // console.log(this.result)
267
- if (this.allowPreview) {
268
- uni.previewImage({
269
- urls: [this.result],
270
- longPressActions: {
271
- itemList: ['保存二维码图片'],
272
- success: function(data) {
273
- // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
274
- switch (data.tapIndex) {
275
- case 0:
276
- that._saveCode();
277
- break;
278
- }
279
- },
280
- fail: function(err) {
281
- console.log(err.errMsg);
282
- }
283
- }
284
- });
285
- }
286
- this.$emit('preview', {
287
- url: this.result
288
- }, e)
289
- },
290
- async toTempFilePath({success, fail} = {}) {
291
- try {
292
- if (!this.canvasHost) {
293
- await this.initCanvas(true)
294
- }
295
- if (!this.canvasHost) {
296
- throw new Error('无法获取二维码画布实例')
297
- }
298
- const res = await this.canvasHost.toTempFilePath({
299
- width: this.sizeLocal,
300
- height: this.sizeLocal
226
+ duration: 2000,
227
+ })
228
+ },
301
229
  })
302
- if (success) success(res)
303
- return res
304
- } catch (error) {
305
- if (fail) {
306
- fail(error)
307
- return false
308
- }
309
- throw error
310
- }
311
- },
312
- async longpress() {
313
- this.toTempFilePath({
314
- success: res => {
315
- this.$emit('longpressCallback', res.tempFilePath)
230
+ },
231
+ fail: (err: any) => {},
232
+ })
233
+ }
234
+ }
235
+
236
+ function preview(e: any) {
237
+ // 预览图片
238
+ // console.log(this.result)
239
+ if (props.allowPreview) {
240
+ uni.previewImage({
241
+ urls: [result.value],
242
+ longPressActions: {
243
+ itemList: ['保存二维码图片'],
244
+ success: function (data: any) {
245
+ // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
246
+ switch (data.tapIndex) {
247
+ case 0:
248
+ // ponytail: 原实现此处引用了未定义的 that(必然 ReferenceError),按原意直接保存
249
+ _saveCode()
250
+ break
251
+ }
316
252
  },
317
- fail: err => {
318
- }
319
- })
320
- },
253
+ fail: function (err: any) {
254
+ console.log(err.errMsg)
255
+ },
256
+ },
257
+ })
258
+ }
259
+ emit('preview', { url: result.value }, e)
260
+ }
321
261
 
322
- /**
323
- * 使用根节点宽高 设置新的size
324
- * @return {Promise<void>}
325
- */
326
- async setNewSize(){
327
- const rootNode = await this.getRootNode();
328
- if (!rootNode) return
329
- const { width , height } = rootNode;
330
- // 将最短的设置为二维码 的size
331
- if(width > height){
332
- this.sizeLocal = height
333
- }
334
- else{
335
- this.sizeLocal = width
336
- }
337
- },
262
+ async function toTempFilePath({ success, fail }: any = {}) {
263
+ try {
264
+ if (!canvasHost.value) {
265
+ await initCanvas(true)
266
+ }
267
+ if (!canvasHost.value) {
268
+ throw new Error('无法获取二维码画布实例')
269
+ }
270
+ const res = await canvasHost.value.toTempFilePath({
271
+ width: sizeLocal.value,
272
+ height: sizeLocal.value,
273
+ })
274
+ if (success) success(res)
275
+ return res
276
+ } catch (error) {
277
+ if (fail) {
278
+ fail(error)
279
+ return false
280
+ }
281
+ throw error
282
+ }
283
+ }
338
284
 
339
- async getRootNode() {
340
- return new Promise((resolve, reject) => {
341
- try {
342
- const query = uni.createSelectorQuery().in(this).select(`#${this.rootId}`);
343
- query.fields({
344
- size: true
345
- })
346
- .exec((res) => {
347
- resolve(res[0] || false)
348
- })
349
- } catch (e) {
350
- console.error("获取二维码根节点失败", e)
351
- resolve(false)
352
- }
353
- })
285
+ async function longpress() {
286
+ toTempFilePath({
287
+ success: (res: any) => {
288
+ emit('longpressCallback', res.tempFilePath)
354
289
  },
355
- async initCanvas(force = false) {
356
- await this.$nextTick()
357
- const canvasRef = this.$refs.qrcodeCanvas
358
- if (!canvasRef) return false
359
- const initialized = await canvasRef.initCanvas(force)
360
- if (!initialized) {
361
- this.canvasHost = null
362
- this.ctx = null
363
- return false
364
- }
365
- this.canvasHost = canvasRef
366
- this.ctx = canvasRef.getRawContext()
367
- return !!this.ctx
368
- },
369
- async refreshCanvas(force = false) {
370
- await this.$nextTick()
371
- return this.initCanvas(force)
372
- },
373
- getUPCanvasContext() {
374
- return this.canvasHost ? this.canvasHost.getRawContext() : null
375
- },
376
- async drawImage(url, x, y, w, h) {
377
- try {
378
- if (!this.canvasHost) {
379
- const initialized = await this.initCanvas(true)
380
- if (!initialized) {
381
- throw new Error('无法初始化二维码画布')
382
- }
383
- }
384
- if (!this.canvasHost || !this.ctx) {
385
- throw new Error('无法获取二维码画布实例')
386
- }
387
- await this.canvasHost.drawImage(url, x, y, w, h)
388
- } catch (error) {
389
- console.error('drawImage绘制出错', error)
390
- throw error
391
- }
392
- },
393
- _queueMakeCode(delay = 0) {
394
- if (this._empty(this.val)) return
395
- setTimeout(() => {
396
- this._makeCode().catch(error => {
397
- console.error('二维码生成失败', error)
290
+ fail: (err: any) => {},
291
+ })
292
+ }
293
+
294
+ /**
295
+ * 使用根节点宽高 设置新的size
296
+ * @return {Promise<void>}
297
+ */
298
+ async function setNewSize() {
299
+ const rootNode: any = await getRootNode()
300
+ if (!rootNode) return
301
+ const { width, height } = rootNode
302
+ // 将最短的设置为二维码 的size
303
+ if (width > height) {
304
+ sizeLocal.value = height
305
+ } else {
306
+ sizeLocal.value = width
307
+ }
308
+ }
309
+
310
+ async function getRootNode() {
311
+ return new Promise((resolve, reject) => {
312
+ try {
313
+ const query: any = uni.createSelectorQuery().in(instance?.proxy as any).select(`#${rootId}`)
314
+ query
315
+ .fields({
316
+ size: true,
398
317
  })
399
- }, delay)
400
- },
318
+ .exec((res: any) => {
319
+ resolve(res[0] || false)
320
+ })
321
+ } catch (e) {
322
+ console.error('获取二维码根节点失败', e)
323
+ resolve(false)
324
+ }
325
+ })
326
+ }
401
327
 
402
- selectClick(index) {
403
- switch (index) {
404
- case 0:
405
- alert('保存二维码')
406
- this._saveCode();
407
- break;
408
- }
409
- },
410
- _result(res) {
411
- this.loading = false;
412
- this.result = res;
413
- this.$emit('result', res);
414
- },
415
- _empty(v) {
416
- let tp = typeof v,
417
- rt = false;
418
- if (tp == "number" && String(v) == "") {
419
- rt = true
420
- } else if (tp == "undefined") {
421
- rt = true
422
- } else if (tp == "object") {
423
- if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) rt = true
424
- } else if (tp == "string") {
425
- if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") rt = true
426
- } else if (tp == "function") {
427
- rt = false
328
+ async function initCanvas(force = false) {
329
+ await nextTick()
330
+ const canvasRef = qrcodeCanvas.value
331
+ if (!canvasRef) return false
332
+ const initialized = await canvasRef.initCanvas(force)
333
+ if (!initialized) {
334
+ canvasHost.value = null
335
+ ctx.value = null
336
+ return false
337
+ }
338
+ canvasHost.value = canvasRef
339
+ ctx.value = canvasRef.getRawContext()
340
+ return !!ctx.value
341
+ }
342
+
343
+ async function refreshCanvas(force = false) {
344
+ await nextTick()
345
+ return initCanvas(force)
346
+ }
347
+
348
+ function getUPCanvasContext() {
349
+ return canvasHost.value ? canvasHost.value.getRawContext() : null
350
+ }
351
+
352
+ async function drawImage(url: any, x: any, y: any, w: any, h: any) {
353
+ try {
354
+ if (!canvasHost.value) {
355
+ const initialized = await initCanvas(true)
356
+ if (!initialized) {
357
+ throw new Error('无法初始化二维码画布')
428
358
  }
429
- return rt
430
- },
431
- },
432
- watch: {
433
- size: function (n, o) {
434
- if (n != o && !this._empty(n)) {
435
- this.sizeLocal = n
436
- if (this.onval) {
437
- this._queueMakeCode(100)
438
- }
359
+ }
360
+ if (!canvasHost.value || !ctx.value) {
361
+ throw new Error('无法获取二维码画布实例')
362
+ }
363
+ await canvasHost.value.drawImage(url, x, y, w, h)
364
+ } catch (error) {
365
+ console.error('drawImage绘制出错', error)
366
+ throw error
367
+ }
368
+ }
369
+
370
+ function _queueMakeCode(delay = 0) {
371
+ if (_empty(props.val)) return
372
+ setTimeout(() => {
373
+ _makeCode().catch(error => {
374
+ console.error('二维码生成失败', error)
375
+ })
376
+ }, delay)
377
+ }
378
+
379
+ function selectClick(index: number) {
380
+ switch (index) {
381
+ case 0:
382
+ alert('保存二维码')
383
+ _saveCode()
384
+ break
385
+ }
386
+ }
387
+
388
+ function _result(res: any) {
389
+ loading.value = false
390
+ result.value = res
391
+ emit('result', res)
392
+ }
393
+
394
+ function _empty(v: any) {
395
+ let tp = typeof v,
396
+ rt = false
397
+ if (tp == 'number' && String(v) == '') {
398
+ rt = true
399
+ } else if (tp == 'undefined') {
400
+ rt = true
401
+ } else if (tp == 'object') {
402
+ if (JSON.stringify(v) == '{}' || JSON.stringify(v) == '[]' || v == null) rt = true
403
+ } else if (tp == 'string') {
404
+ if (v == '' || v == 'undefined' || v == 'null' || v == '{}' || v == '[]') rt = true
405
+ } else if (tp == 'function') {
406
+ rt = false
407
+ }
408
+ return rt
409
+ }
410
+
411
+ watch(
412
+ () => props.size,
413
+ function (n, o) {
414
+ if (n != o && !_empty(n)) {
415
+ sizeLocal.value = n
416
+ if (props.onval) {
417
+ _queueMakeCode(100)
439
418
  }
440
- },
441
- val: function (n, o) {
442
- if (this.onval) {
443
- if (n != o && !this._empty(n)) {
444
- this._queueMakeCode()
445
- }
419
+ }
420
+ }
421
+ )
422
+ watch(
423
+ () => props.val,
424
+ function (n, o) {
425
+ if (props.onval) {
426
+ if (n != o && !_empty(n)) {
427
+ _queueMakeCode()
446
428
  }
447
- },
448
- icon: function (n, o) {
449
- if (n === o) return
450
- this._queueMakeCode(100)
451
- },
452
- background: function () {
453
- this._queueMakeCode()
454
- },
455
- foreground: function () {
456
- this._queueMakeCode()
457
- },
458
- iconSize: function () {
459
- this._queueMakeCode()
460
- },
461
- quietZone: function () {
462
- this._queueMakeCode()
463
- },
464
- lv: function () {
465
- this._queueMakeCode()
466
429
  }
467
- },
468
- computed: {
469
430
  }
470
- }
431
+ )
432
+ watch(
433
+ () => props.icon,
434
+ function (n, o) {
435
+ if (n === o) return
436
+ _queueMakeCode(100)
437
+ }
438
+ )
439
+ watch(
440
+ () => props.background,
441
+ function () {
442
+ _queueMakeCode()
443
+ }
444
+ )
445
+ watch(
446
+ () => props.foreground,
447
+ function () {
448
+ _queueMakeCode()
449
+ }
450
+ )
451
+ watch(
452
+ () => props.iconSize,
453
+ function () {
454
+ _queueMakeCode()
455
+ }
456
+ )
457
+ watch(
458
+ () => props.quietZone,
459
+ function () {
460
+ _queueMakeCode()
461
+ }
462
+ )
463
+ watch(
464
+ () => props.lv,
465
+ function () {
466
+ _queueMakeCode()
467
+ }
468
+ )
469
+
470
+ defineExpose({
471
+ loading,
472
+ result,
473
+ popupShow,
474
+ list,
475
+ rootId,
476
+ canvasObj,
477
+ sizeLocal,
478
+ ctx,
479
+ isNvue,
480
+ canvasHost,
481
+ _makeCode,
482
+ _clearCode,
483
+ _saveCode,
484
+ preview,
485
+ toTempFilePath,
486
+ longpress,
487
+ setNewSize,
488
+ getRootNode,
489
+ initCanvas,
490
+ refreshCanvas,
491
+ getUPCanvasContext,
492
+ drawImage,
493
+ _queueMakeCode,
494
+ selectClick,
495
+ _result,
496
+ _empty,
497
+ })
471
498
  </script>
472
499
  <style lang="scss" scoped>
473
500
  @import '../../scss/variables';
474
-
501
+ @import '../../scss/mixins';
475
502
  .dd-qrcode {
476
503
  &__loading {
477
504
  display: flex;
@@ -499,4 +526,3 @@ export default {
499
526
  }
500
527
  }
501
528
  </style>
502
-