@didaoktv/didaoui-uniapp 1.0.0 → 1.2.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 +16 -7
- package/components/dd-action-sheet/dd-action-sheet.vue +3 -3
- package/components/dd-album/album.js +19 -0
- package/components/dd-album/dd-album.vue +345 -0
- package/components/dd-album/props.js +89 -0
- package/components/dd-avatar/avatar.js +19 -0
- package/components/dd-avatar/dd-avatar.vue +172 -160
- package/components/dd-avatar/props.js +84 -0
- package/components/dd-avatar-group/avatarGroup.js +14 -0
- package/components/dd-avatar-group/dd-avatar-group.vue +110 -0
- package/components/dd-avatar-group/props.js +57 -0
- package/components/dd-badge/dd-badge.vue +2 -2
- package/components/dd-barcode/dd-barcode.vue +1030 -0
- package/components/dd-bill-detail/dd-bill-detail.vue +265 -0
- package/components/dd-button/dd-button.vue +17 -17
- package/components/dd-calendar/dd-calendar.vue +357 -0
- package/components/dd-canvas/dd-canvas.vue +1088 -0
- package/components/dd-capsule-button/dd-capsule-button.vue +6 -6
- package/components/dd-car-keyboard/carKeyboard.js +6 -0
- package/components/dd-car-keyboard/dd-car-keyboard.vue +315 -0
- package/components/dd-car-keyboard/props.js +19 -0
- package/components/dd-cascader/dd-cascader.vue +405 -0
- package/components/dd-cell/dd-cell.vue +50 -23
- package/components/dd-cell-group/dd-cell-group.vue +32 -25
- package/components/dd-champion-card/dd-champion-card.vue +4 -4
- package/components/dd-checkbox/dd-checkbox.vue +30 -39
- package/components/dd-checkbox-group/dd-checkbox-group.vue +67 -0
- package/components/dd-copy/dd-copy.vue +74 -0
- package/components/dd-coupon/dd-coupon.vue +368 -0
- package/components/dd-cropper/dd-cropper.vue +1297 -0
- package/components/dd-dialog/dd-dialog.vue +1 -1
- package/components/dd-divider/dd-divider.vue +3 -3
- package/components/dd-dropdown-item/dd-dropdown-item.vue +5 -5
- package/components/dd-empty-state/dd-empty-state.vue +1 -1
- package/components/dd-field/dd-field.vue +531 -106
- package/components/dd-form/dd-form.vue +116 -0
- package/components/dd-form/rules.ts +84 -0
- package/components/dd-goods-sku/dd-goods-sku.vue +434 -0
- package/components/dd-icon/dd-icon.vue +2 -2
- package/components/dd-image/dd-image.vue +4 -4
- package/components/dd-input/dd-input.vue +5 -5
- package/components/dd-keyboard/dd-keyboard.vue +178 -0
- package/components/dd-keyboard/keyboard.js +22 -0
- package/components/dd-keyboard/props.js +89 -0
- package/components/dd-link/dd-link.vue +87 -0
- package/components/dd-link/link.js +18 -0
- package/components/dd-link/props.js +44 -0
- package/components/dd-list-cell/dd-list-cell.vue +4 -4
- package/components/dd-loading/dd-loading.vue +1 -1
- package/components/dd-loadmore/dd-loadmore.vue +2 -2
- package/components/dd-markdown/dd-markdown.vue +344 -0
- package/components/dd-markdown/marked.esm.mjs +7 -0
- package/components/dd-mini-program-navbar/dd-mini-program-navbar.vue +9 -9
- package/components/dd-navigation/dd-navigation.vue +5 -5
- package/components/dd-number-keyboard/dd-number-keyboard.vue +200 -0
- package/components/dd-number-keyboard/numberKeyboard.js +8 -0
- package/components/dd-number-keyboard/props.js +24 -0
- package/components/dd-parse/dd-parse.vue +534 -0
- package/components/dd-parse/node/handler.wxs +26 -0
- package/components/dd-parse/node/node.vue +603 -0
- package/components/dd-parse/parse.js +13 -0
- package/components/dd-parse/parser.js +1400 -0
- package/components/dd-parse/props.js +57 -0
- package/components/dd-popover/dd-popover.vue +10 -10
- package/components/dd-popover-item/dd-popover-item.vue +3 -3
- package/components/dd-popup/dd-popup.vue +5 -5
- package/components/dd-poster/dd-poster.vue +695 -0
- package/components/dd-progress/dd-progress.vue +3 -3
- package/components/dd-pull-refresh/dd-pull-refresh.vue +3 -3
- package/components/dd-qrcode/dd-qrcode.vue +509 -0
- package/components/dd-qrcode/qrcode.js +1283 -0
- package/components/dd-radio/dd-radio.vue +19 -20
- package/components/dd-radio-group/dd-radio-group.vue +53 -0
- package/components/dd-rate/dd-rate.vue +1 -1
- package/components/dd-room-card/dd-room-card.vue +3 -3
- package/components/dd-search-bar/dd-search-bar.vue +8 -8
- package/components/dd-segmented-tab/dd-segmented-tab.vue +6 -6
- package/components/dd-signature/dd-signature.vue +513 -0
- package/components/dd-skeleton/dd-skeleton.vue +1 -1
- package/components/dd-slider/dd-slider.vue +4 -4
- package/components/dd-stat-card/dd-stat-card.vue +5 -5
- package/components/dd-step/dd-step.vue +11 -11
- package/components/dd-stepper/dd-stepper.vue +6 -6
- package/components/dd-swipe-action/dd-swipe-action.vue +1 -1
- package/components/dd-swipeable-tab/dd-swipeable-tab.vue +1 -1
- package/components/dd-tabbar-item/dd-tabbar-item.vue +8 -8
- package/components/dd-tag/dd-tag.vue +17 -1
- package/components/dd-text/dd-text.vue +250 -0
- package/components/dd-text/props.js +120 -0
- package/components/dd-text/text.js +30 -0
- package/components/dd-text/value.js +87 -0
- package/components/dd-toast/dd-toast.vue +2 -2
- package/components/dd-upload/dd-upload.vue +4 -4
- package/components/dd-workorder-card/dd-workorder-card.vue +237 -0
- package/index.ts +50 -9
- package/libs/config/color.js +16 -0
- package/libs/config/config.js +25 -0
- package/libs/config/props.js +185 -0
- package/libs/config/zIndex.js +20 -0
- package/libs/function/digit.js +167 -0
- package/libs/function/index.js +932 -0
- package/libs/function/test.js +327 -0
- package/libs/i18n/index.d.ts +2 -0
- package/libs/i18n/index.js +89 -0
- package/libs/i18n/locales/zh-Hans.js +86 -0
- package/libs/mixin/button.js +18 -0
- package/libs/mixin/mixin.js +44 -0
- package/libs/mixin/mpMixin.js +13 -0
- package/libs/mixin/openType.js +27 -0
- package/libs/utils.ts +462 -0
- package/libs/vue.js +3 -0
- package/package.json +1 -1
- package/scss/_dd-shared.scss +40 -0
- package/scss/_variables.scss +4 -1
|
@@ -203,12 +203,12 @@ watch(
|
|
|
203
203
|
&__head-inner {
|
|
204
204
|
height: 100%;
|
|
205
205
|
@include dd-flex-center;
|
|
206
|
-
gap:
|
|
206
|
+
gap: $dd-space-2;
|
|
207
207
|
}
|
|
208
208
|
|
|
209
209
|
&__spinner {
|
|
210
|
-
width:
|
|
211
|
-
height:
|
|
210
|
+
width: $dd-size-icon-sm;
|
|
211
|
+
height: $dd-size-icon-sm;
|
|
212
212
|
border: 4rpx solid $dd-border-default;
|
|
213
213
|
border-top-color: $dd-primary-500;
|
|
214
214
|
border-radius: 50%;
|
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="dd-qrcode"
|
|
3
|
+
:id="rootId"
|
|
4
|
+
:style="{
|
|
5
|
+
width: useRootHeightAndWidth ? '100%' : 'auto',
|
|
6
|
+
height: useRootHeightAndWidth ? '100%' : 'auto',
|
|
7
|
+
}"
|
|
8
|
+
@longpress="longpress">
|
|
9
|
+
<view
|
|
10
|
+
class="dd-qrcode__content"
|
|
11
|
+
:style="{ width: sizeLocal + unit, height: sizeLocal + unit }"
|
|
12
|
+
@click="preview">
|
|
13
|
+
<!-- #ifdef APP-NVUE -->
|
|
14
|
+
<dd-canvas
|
|
15
|
+
ref="qrcodeCanvas"
|
|
16
|
+
class="dd-qrcode__canvas"
|
|
17
|
+
:canvas-id="cid"
|
|
18
|
+
:width="sizeLocal"
|
|
19
|
+
:height="sizeLocal"
|
|
20
|
+
:unit="unit"
|
|
21
|
+
bg-color="transparent"
|
|
22
|
+
:style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
|
|
23
|
+
<!-- #endif -->
|
|
24
|
+
<!-- #ifndef APP-NVUE -->
|
|
25
|
+
<dd-canvas
|
|
26
|
+
ref="qrcodeCanvas"
|
|
27
|
+
class="dd-qrcode__canvas"
|
|
28
|
+
:canvas-id="cid"
|
|
29
|
+
:width="sizeLocal"
|
|
30
|
+
:height="sizeLocal"
|
|
31
|
+
:unit="unit"
|
|
32
|
+
bg-color="transparent"
|
|
33
|
+
:style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
|
|
34
|
+
<!-- #endif -->
|
|
35
|
+
<view v-if="showLoading && loading" class="dd-qrcode__loading"
|
|
36
|
+
:style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
|
|
37
|
+
<dd-loading type="spinner" :text="loadingText" />
|
|
38
|
+
</view>
|
|
39
|
+
</view>
|
|
40
|
+
|
|
41
|
+
</view>
|
|
42
|
+
</template>
|
|
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
|
+
}
|
|
147
|
+
},
|
|
148
|
+
created() {
|
|
149
|
+
this._qrcode = null
|
|
150
|
+
},
|
|
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()
|
|
160
|
+
|
|
161
|
+
if (this.loadMake) {
|
|
162
|
+
if (!this._empty(this.val)) {
|
|
163
|
+
setTimeout(() => {
|
|
164
|
+
setTimeout(()=>{
|
|
165
|
+
this._makeCode().catch(error => {
|
|
166
|
+
console.error('二维码生成失败', error)
|
|
167
|
+
})
|
|
168
|
+
})
|
|
169
|
+
}, 0);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
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
|
+
}
|
|
225
|
+
})
|
|
226
|
+
},
|
|
227
|
+
_clearCode() {
|
|
228
|
+
this._result('')
|
|
229
|
+
if (this._qrcode) this._qrcode.clear()
|
|
230
|
+
},
|
|
231
|
+
_saveCode() {
|
|
232
|
+
let that = this;
|
|
233
|
+
if (this.result != "") {
|
|
234
|
+
uni.saveImageToPhotosAlbum({
|
|
235
|
+
filePath: that.result,
|
|
236
|
+
success: function () {
|
|
237
|
+
uni.showToast({
|
|
238
|
+
title: '二维码保存成功',
|
|
239
|
+
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
|
|
301
|
+
})
|
|
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)
|
|
316
|
+
},
|
|
317
|
+
fail: err => {
|
|
318
|
+
}
|
|
319
|
+
})
|
|
320
|
+
},
|
|
321
|
+
|
|
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
|
+
},
|
|
338
|
+
|
|
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
|
+
})
|
|
354
|
+
},
|
|
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)
|
|
398
|
+
})
|
|
399
|
+
}, delay)
|
|
400
|
+
},
|
|
401
|
+
|
|
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
|
|
428
|
+
}
|
|
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
|
+
}
|
|
439
|
+
}
|
|
440
|
+
},
|
|
441
|
+
val: function (n, o) {
|
|
442
|
+
if (this.onval) {
|
|
443
|
+
if (n != o && !this._empty(n)) {
|
|
444
|
+
this._queueMakeCode()
|
|
445
|
+
}
|
|
446
|
+
}
|
|
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
|
+
}
|
|
467
|
+
},
|
|
468
|
+
computed: {
|
|
469
|
+
}
|
|
470
|
+
}
|
|
471
|
+
</script>
|
|
472
|
+
<style lang="scss" scoped>
|
|
473
|
+
@import '../../scss/variables';
|
|
474
|
+
|
|
475
|
+
.dd-qrcode {
|
|
476
|
+
&__loading {
|
|
477
|
+
display: flex;
|
|
478
|
+
justify-content: center;
|
|
479
|
+
align-items: center;
|
|
480
|
+
background-color: #f7f7f7;
|
|
481
|
+
position: absolute;
|
|
482
|
+
top: 0;
|
|
483
|
+
bottom: 0;
|
|
484
|
+
left: 0;
|
|
485
|
+
right: 0;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/* #ifdef MP-TOUTIAO */
|
|
489
|
+
/**字节小程序在编译时会出现一个 [hidde]:{ display: none !important; } 这个样式
|
|
490
|
+
* 会导致canvas 隐藏掉 没有找到具体原因先这样处理
|
|
491
|
+
*/
|
|
492
|
+
&__canvas {
|
|
493
|
+
display: block !important;
|
|
494
|
+
}
|
|
495
|
+
/* #endif */
|
|
496
|
+
|
|
497
|
+
&__content {
|
|
498
|
+
position: relative;
|
|
499
|
+
|
|
500
|
+
&__canvas {
|
|
501
|
+
position: fixed;
|
|
502
|
+
top: -99999rpx;
|
|
503
|
+
left: -99999rpx;
|
|
504
|
+
z-index: -99999;
|
|
505
|
+
}
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
</style>
|
|
509
|
+
|