@didaoktv/didaoui-uniapp 2.13.0 → 2.14.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-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-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 +22 -14
- 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 +89 -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/scss/_dd-shared.scss +0 -40
|
@@ -41,437 +41,464 @@
|
|
|
41
41
|
</view>
|
|
42
42
|
</template>
|
|
43
43
|
|
|
44
|
-
<script>
|
|
45
|
-
import
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
149
|
-
|
|
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
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
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
|
-
|
|
162
|
-
|
|
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
|
-
|
|
165
|
-
|
|
166
|
-
console.error('二维码生成失败', error)
|
|
167
|
-
})
|
|
136
|
+
_makeCode().catch(error => {
|
|
137
|
+
console.error('二维码生成失败', error)
|
|
168
138
|
})
|
|
169
|
-
}
|
|
170
|
-
}
|
|
139
|
+
})
|
|
140
|
+
}, 0)
|
|
171
141
|
}
|
|
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
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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:
|
|
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
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
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
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
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
|
-
|
|
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
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
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
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
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
|
-
|