uview-plus 3.4.40 → 3.4.42

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 (129) hide show
  1. package/changelog.md +10 -0
  2. package/components/u-action-sheet/u-action-sheet.vue +0 -1
  3. package/components/u-album/u-album.vue +0 -2
  4. package/components/u-alert/u-alert.vue +0 -1
  5. package/components/u-avatar/u-avatar.vue +0 -1
  6. package/components/u-avatar-group/u-avatar-group.vue +0 -1
  7. package/components/u-back-top/u-back-top.vue +0 -1
  8. package/components/u-badge/u-badge.vue +0 -1
  9. package/components/u-box/u-box.vue +0 -1
  10. package/components/u-button/u-button.vue +0 -2
  11. package/components/u-calendar/header.vue +0 -1
  12. package/components/u-calendar/month.vue +0 -1
  13. package/components/u-calendar/u-calendar.vue +0 -2
  14. package/components/u-car-keyboard/u-car-keyboard.vue +0 -1
  15. package/components/u-card/u-card.vue +0 -2
  16. package/components/u-cell/u-cell.vue +0 -1
  17. package/components/u-cell-group/u-cell-group.vue +0 -1
  18. package/components/u-checkbox/u-checkbox.vue +0 -1
  19. package/components/u-checkbox-group/u-checkbox-group.vue +0 -1
  20. package/components/u-circle-progress/u-circle-progress.vue +0 -1
  21. package/components/u-code/u-code.vue +0 -1
  22. package/components/u-code-input/u-code-input.vue +0 -1
  23. package/components/u-col/u-col.vue +0 -1
  24. package/components/u-collapse/u-collapse.vue +0 -1
  25. package/components/u-collapse-item/u-collapse-item.vue +0 -1
  26. package/components/u-column-notice/u-column-notice.vue +0 -1
  27. package/components/u-count-down/u-count-down.vue +0 -1
  28. package/components/u-count-to/u-count-to.vue +0 -2
  29. package/components/u-datetime-picker/u-datetime-picker.vue +0 -1
  30. package/components/u-divider/u-divider.vue +0 -1
  31. package/components/u-dropdown/u-dropdown.vue +0 -1
  32. package/components/u-dropdown-item/u-dropdown-item.vue +0 -1
  33. package/components/u-empty/u-empty.vue +0 -1
  34. package/components/u-float-button/u-float-button.vue +0 -2
  35. package/components/u-form-item/u-form-item.vue +0 -1
  36. package/components/u-gap/u-gap.vue +0 -1
  37. package/components/u-grid/u-grid.vue +0 -1
  38. package/components/u-grid-item/u-grid-item.vue +0 -1
  39. package/components/u-icon/u-icon.vue +0 -1
  40. package/components/u-image/u-image.vue +0 -2
  41. package/components/u-index-anchor/u-index-anchor.vue +0 -1
  42. package/components/u-index-item/u-index-item.vue +0 -1
  43. package/components/u-index-list/u-index-list.vue +0 -1
  44. package/components/u-input/u-input.vue +0 -2
  45. package/components/u-keyboard/u-keyboard.vue +0 -1
  46. package/components/u-lazy-load/u-lazy-load.vue +0 -2
  47. package/components/u-line/u-line.vue +0 -1
  48. package/components/u-line-progress/u-line-progress.vue +0 -1
  49. package/components/u-link/u-link.vue +0 -1
  50. package/components/u-list/u-list.vue +0 -1
  51. package/components/u-list-item/u-list-item.vue +0 -1
  52. package/components/u-loading-icon/u-loading-icon.vue +0 -1
  53. package/components/u-loading-page/u-loading-page.vue +0 -2
  54. package/components/u-loadmore/u-loadmore.vue +0 -1
  55. package/components/u-modal/u-modal.vue +0 -1
  56. package/components/u-navbar/u-navbar.vue +0 -1
  57. package/components/u-navbar-mini/u-navbar-mini.vue +0 -1
  58. package/components/u-no-network/u-no-network.vue +0 -1
  59. package/components/u-notice-bar/u-notice-bar.vue +0 -1
  60. package/components/u-notify/u-notify.vue +0 -1
  61. package/components/u-number-box/u-number-box.vue +0 -2
  62. package/components/u-number-keyboard/u-number-keyboard.vue +0 -1
  63. package/components/u-overlay/u-overlay.vue +0 -1
  64. package/components/u-picker/u-picker.vue +0 -1
  65. package/components/u-picker-column/u-picker-column.vue +0 -1
  66. package/components/u-popup/u-popup.vue +0 -1
  67. package/components/u-qrcode/qrcode.js +24 -10
  68. package/components/u-qrcode/u-qrcode.vue +412 -281
  69. package/components/u-radio/u-radio.vue +0 -1
  70. package/components/u-radio-group/u-radio-group.vue +0 -1
  71. package/components/u-rate/u-rate.vue +0 -1
  72. package/components/u-read-more/u-read-more.vue +0 -2
  73. package/components/u-row/u-row.vue +0 -1
  74. package/components/u-row-notice/u-row-notice.vue +0 -1
  75. package/components/u-scroll-list/u-scroll-list.vue +0 -2
  76. package/components/u-search/u-search.vue +0 -1
  77. package/components/u-skeleton/u-skeleton.vue +0 -1
  78. package/components/u-slider/u-slider.vue +0 -1
  79. package/components/u-steps/u-steps.vue +0 -1
  80. package/components/u-steps-item/u-steps-item.vue +0 -1
  81. package/components/u-subsection/u-subsection.vue +0 -2
  82. package/components/u-swipe-action-item/u-swipe-action-item.vue +0 -1
  83. package/components/u-swiper/u-swiper.vue +0 -1
  84. package/components/u-swiper-indicator/u-swiper-indicator.vue +0 -1
  85. package/components/u-switch/u-switch.vue +0 -1
  86. package/components/u-tabbar/u-tabbar.vue +0 -1
  87. package/components/u-tabbar-item/u-tabbar-item.vue +0 -1
  88. package/components/u-table/u-table.vue +0 -1
  89. package/components/u-tabs/u-tabs.vue +0 -1
  90. package/components/u-tag/u-tag.vue +0 -1
  91. package/components/u-td/u-td.vue +0 -1
  92. package/components/u-text/u-text.vue +4 -6
  93. package/components/u-textarea/u-textarea.vue +9 -11
  94. package/components/u-th/u-th.vue +0 -1
  95. package/components/u-toast/u-toast.vue +2 -2
  96. package/components/u-toolbar/u-toolbar.vue +0 -1
  97. package/components/u-tooltip/u-tooltip.vue +0 -1
  98. package/components/u-tr/u-tr.vue +0 -1
  99. package/components/u-transition/u-transition.vue +114 -3
  100. package/components/u-upload/u-upload.vue +0 -1
  101. package/components/u-view/u-view.vue +0 -2
  102. package/components/u-waterfall/u-waterfall.vue +0 -2
  103. package/index.scss +2 -1
  104. package/libs/util/gcanvas/bridge/bridge-weex.js +0 -0
  105. package/libs/util/gcanvas/context-2d/FillStyleLinearGradient.js +0 -0
  106. package/libs/util/gcanvas/context-2d/FillStylePattern.js +0 -0
  107. package/libs/util/gcanvas/context-2d/FillStyleRadialGradient.js +0 -0
  108. package/libs/util/gcanvas/context-2d/RenderingContext.js +0 -0
  109. package/libs/util/gcanvas/context-webgl/ActiveInfo.js +0 -0
  110. package/libs/util/gcanvas/context-webgl/Buffer.js +0 -0
  111. package/libs/util/gcanvas/context-webgl/Framebuffer.js +0 -0
  112. package/libs/util/gcanvas/context-webgl/GLenum.js +0 -0
  113. package/libs/util/gcanvas/context-webgl/GLmethod.js +0 -0
  114. package/libs/util/gcanvas/context-webgl/GLtype.js +0 -0
  115. package/libs/util/gcanvas/context-webgl/Program.js +0 -0
  116. package/libs/util/gcanvas/context-webgl/Renderbuffer.js +0 -0
  117. package/libs/util/gcanvas/context-webgl/RenderingContext.js +0 -0
  118. package/libs/util/gcanvas/context-webgl/Shader.js +0 -0
  119. package/libs/util/gcanvas/context-webgl/ShaderPrecisionFormat.js +0 -0
  120. package/libs/util/gcanvas/context-webgl/Texture.js +0 -0
  121. package/libs/util/gcanvas/context-webgl/UniformLocation.js +0 -0
  122. package/libs/util/gcanvas/context-webgl/classUtils.js +0 -0
  123. package/libs/util/gcanvas/env/canvas.js +0 -0
  124. package/libs/util/gcanvas/env/image.js +0 -0
  125. package/libs/util/gcanvas/env/tool.js +0 -0
  126. package/libs/util/gcanvas/index.js +0 -0
  127. package/package.json +1 -1
  128. package/types/comps/qrcode.d.ts +77 -0
  129. package/types/comps.d.ts +1 -0
@@ -1,26 +1,50 @@
1
1
  <template>
2
- <view class="u-qrcode" @longpress="longpress">
3
- <view class="u-qrcode__content" @click="preview">
4
- <!-- #ifndef APP-NVUE -->
5
- <canvas
2
+ <view class="u-qrcode"
3
+ :id="rootId"
4
+ :style="{
5
+ width: useRootHeightAndWidth ? '100%' : 'auto',
6
+ height: useRootHeightAndWidth ? '100%' : 'auto',
7
+ }"
8
+ @longpress="longpress">
9
+ <view class="u-qrcode__content" @click="preview">
10
+
11
+ <!-- #ifndef APP-NVUE || APP-PLUS -->
12
+ <canvas
6
13
  class="u-qrcode__canvas"
7
- :id="cid"
14
+ :id="cid"
8
15
  :canvas-id="cid"
9
16
  type="2d"
10
- :style="{ width: size + unit, height: size + unit }" />
11
- <!-- #endif -->
12
- <!-- #ifdef APP-NVUE -->
13
- <gcanvas class="u-qrcode__canvas" ref="gcanvess"
14
- :style="{ width: size + unit, height: size + unit }">
15
- </gcanvas>
16
- <!-- #endif -->
17
- <view v-if="showLoading && loading" class="u-qrcode__loading"
18
- :style="{ width: size + unit, height: size + unit }">
19
- <up-loading-icon vertical :text="loadingText" textSize="14px"></up-loading-icon>
20
- </view>
21
- </view>
17
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
18
+ <!-- #endif -->
19
+
20
+ <!-- #ifdef APP-PLUS -->
21
+ <canvas
22
+ class="u-qrcode__canvas"
23
+ :id="cid"
24
+ :canvas-id="cid"
25
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
26
+ <!-- #endif -->
27
+
28
+ <!-- #ifdef APP-PLUS -->
29
+ <canvas
30
+ class="u-qrcode__canvas"
31
+ :id="cid"
32
+ :canvas-id="cid"
33
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
34
+ <!-- #endif -->
35
+
36
+ <!-- #ifdef APP-NVUE -->
37
+ <gcanvas class="u-qrcode__canvas" ref="gcanvess"
38
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
39
+ </gcanvas>
40
+ <!-- #endif -->
41
+ <view v-if="showLoading && loading" class="u-qrcode__loading"
42
+ :style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
43
+ <up-loading-icon vertical :text="loadingText" textSize="14px"></up-loading-icon>
44
+ </view>
45
+ </view>
22
46
 
23
- </view>
47
+ </view>
24
48
  </template>
25
49
 
26
50
  <script>
@@ -28,272 +52,379 @@ import QRCode from "./qrcode.js"
28
52
  // #ifdef APP-NVUE
29
53
  // https://github.com/dcloudio/NvueCanvasDemo/blob/master/README.md
30
54
  import {
31
- enable,
32
- WeexBridge
55
+ enable,
56
+ WeexBridge
33
57
  } from '../../libs/util/gcanvas/index.js';
34
58
  // #endif
35
59
  let qrcode
36
60
  export default {
37
- name: "u-qrcode",
38
- props: {
39
- cid: {
40
- type: String,
41
- default: 'u-qrcode-canvas' + Math.random().toString()
42
- },
43
- size: {
44
- type: Number,
45
- default: 200
46
- },
47
- unit: {
48
- type: String,
49
- default: 'px'
50
- },
51
- show: {
52
- type: Boolean,
53
- default: true
54
- },
55
- val: {
56
- type: String,
57
- default: ''
58
- },
59
- background: {
60
- type: String,
61
- default: '#ffffff'
62
- },
63
- foreground: {
64
- type: String,
65
- default: '#000000'
66
- },
67
- pdground: {
68
- type: String,
69
- default: '#000000'
70
- },
71
- icon: {
72
- type: String,
73
- default: ''
74
- },
75
- iconSize: {
76
- type: Number,
77
- default: 40
78
- },
79
- lv: {
80
- type: Number,
81
- default: 3
82
- },
83
- onval: {
84
- type: Boolean,
85
- default: true
86
- },
87
- loadMake: {
88
- type: Boolean,
89
- default: true
90
- },
91
- usingComponents: {
92
- type: Boolean,
93
- default: true
94
- },
95
- showLoading: {
96
- type: Boolean,
97
- default: true
98
- },
99
- loadingText: {
100
- type: String,
101
- default: '生成中'
102
- },
103
- allowPreview: {
104
- type: Boolean,
105
- default: false
106
- },
107
- },
108
- emits: ['result', 'longpress'],
109
- data() {
110
- return {
111
- loading: false,
112
- result: '',
113
- popupShow: false,
114
- list: [
115
- {
116
- name: '保存二维码',
117
- }
118
- ],
119
- ganvas: null,
120
- context: '',
121
- canvasObj: {}
122
- }
123
- },
124
- mounted(){
125
- // #ifdef APP-NVUE
126
- /*获取元素引用*/
127
- this.ganvas = this.$refs["gcanvess"]
128
- /*通过元素引用获取canvas对象*/
129
- this.canvasObj = enable(this.ganvas, {
130
- bridge: WeexBridge
131
- })
132
- /*获取绘图所需的上下文,目前不支持3d*/
133
- this.context = this.canvasObj.getContext('2d')
134
- // #endif
61
+ name: "u-qrcode",
62
+ props: {
63
+ cid: {
64
+ type: String,
65
+ default: () => `u-qrcode-canvas${Math.floor(Math.random() * 1000000)}`
66
+ },
67
+ size: {
68
+ type: Number,
69
+ default: 200
70
+ },
71
+ unit: {
72
+ type: String,
73
+ default: 'px'
74
+ },
75
+ show: {
76
+ type: Boolean,
77
+ default: true
78
+ },
79
+ val: {
80
+ type: String,
81
+ default: ''
82
+ },
83
+ background: {
84
+ type: String,
85
+ default: '#ffffff'
86
+ },
87
+ foreground: {
88
+ type: String,
89
+ default: '#000000'
90
+ },
91
+ pdground: {
92
+ type: String,
93
+ default: '#000000'
94
+ },
95
+ icon: {
96
+ type: String,
97
+ default: ''
98
+ },
99
+ iconSize: {
100
+ type: Number,
101
+ default: 40
102
+ },
103
+ lv: {
104
+ type: Number,
105
+ default: 3
106
+ },
107
+ onval: {
108
+ type: Boolean,
109
+ default: true
110
+ },
111
+ loadMake: {
112
+ type: Boolean,
113
+ default: true
114
+ },
115
+ usingComponents: {
116
+ type: Boolean,
117
+ default: true
118
+ },
119
+ showLoading: {
120
+ type: Boolean,
121
+ default: true
122
+ },
123
+ loadingText: {
124
+ type: String,
125
+ default: '生成中'
126
+ },
127
+ allowPreview: {
128
+ type: Boolean,
129
+ default: false
130
+ },
131
+ // 是否使用根节点宽高
132
+ useRootHeightAndWidth: {
133
+ type: Boolean,
134
+ default: () => false
135
+ },
136
+ },
137
+ emits: ['result', 'longpressCallback'],
138
+ data() {
139
+ return {
140
+ loading: false,
141
+ result: '',
142
+ popupShow: false,
143
+ list: [
144
+ {
145
+ name: '保存二维码',
146
+ }
147
+ ],
148
+ rootId: `rootId${Number(Math.random() * 100).toFixed(0)}`,
149
+ ganvas: null,
150
+ context: '',
151
+ canvasObj: {},
152
+ sizeLocal: this.size,
153
+ ctx: null, // ctx 在new Qrcode 时js文件内部设置
154
+ canvas: null, // ctx 在new Qrcode 时js文件内部设置
155
+ }
156
+ },
157
+ async mounted(){
158
+ // 如果使用根节点的宽高 则 重新设置 size
159
+ if(this.useRootHeightAndWidth){
160
+ await this.setNewSize()
161
+ }
162
+
163
+ // #ifdef APP-NVUE
164
+ /*获取元素引用*/
165
+ this.ganvas = this.$refs["gcanvess"]
166
+ /*通过元素引用获取canvas对象*/
167
+ this.canvasObj = enable(this.ganvas, {
168
+ bridge: WeexBridge
169
+ })
170
+ /*获取绘图所需的上下文,目前不支持3d*/
171
+ this.context = this.canvasObj.getContext('2d')
172
+ // #endif
135
173
 
136
- if (this.loadMake) {
137
- if (!this._empty(this.val)) {
138
- setTimeout(() => {
174
+ if (this.loadMake) {
175
+ if (!this._empty(this.val)) {
176
+ setTimeout(() => {
139
177
  setTimeout(()=>{
140
178
  this._makeCode()
141
179
  })
142
- }, 0);
143
- }
144
- }
145
- },
146
- methods: {
147
- _makeCode() {
148
- let that = this
149
- if (!this._empty(this.val)) {
150
- // #ifndef APP-NVUE
151
- this.loading = true
152
- // #endif
153
- qrcode = new QRCode({
154
- context: that, // 上下文环境
155
- canvasId: that.cid, // canvas-id
156
- nvueContext: that.context,
157
- usingComponents: that.usingComponents, // 是否是自定义组件
158
- showLoading: false, // 是否显示loading
159
- loadingText: that.loadingText, // loading文字
160
- text: that.val, // 生成内容
161
- size: that.size, // 二维码大小
162
- background: that.background, // 背景色
163
- foreground: that.foreground, // 前景色
164
- pdground: that.pdground, // 定位角点颜色
165
- correctLevel: that.lv, // 容错级别
166
- image: that.icon, // 二维码图标
167
- imageSize: that.iconSize,// 二维码图标大小
168
- that,
169
- cbResult: function (res) { // 生成二维码的回调
170
- that._result(res)
171
- },
172
- });
173
- } else {
174
- uni.showToast({
175
- title: '二维码内容不能为空',
176
- icon: 'none',
177
- duration: 2000
178
- });
179
- }
180
- },
181
- _clearCode() {
182
- this._result('')
183
- qrcode.clear()
184
- },
185
- _saveCode() {
186
- let that = this;
187
- if (this.result != "") {
188
- uni.saveImageToPhotosAlbum({
189
- filePath: that.result,
190
- success: function () {
191
- uni.showToast({
192
- title: '二维码保存成功',
193
- icon: 'success',
194
- duration: 2000
195
- });
196
- }
197
- });
198
- }
199
- },
200
- preview(e) {
201
- // 预览图片
202
- // console.log(this.result)
203
- if (this.allowPreview) {
204
- uni.previewImage({
205
- urls: [this.result],
206
- longPressActions: {
207
- itemList: ['保存二维码图片'],
208
- success: function(data) {
209
- // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
210
- switch (data.tapIndex) {
211
- case 0:
212
- that._saveCode();
213
- break;
214
- }
215
- },
216
- fail: function(err) {
217
- console.log(err.errMsg);
218
- }
219
- }
220
- });
221
- }
222
- this.$emit('preview', {
223
- url: this.result
224
- }, e)
225
- },
226
- longpress() {
227
- this.$emit('longpress', this.result)
228
- },
229
- selectClick(index) {
230
- switch (index) {
231
- case 0:
232
- alert('保存二维码')
233
- this._saveCode();
234
- break;
235
- }
236
- },
237
- _result(res) {
238
- this.loading = false;
239
- this.result = res;
240
- this.$emit('result', res);
241
- },
242
- _empty(v) {
243
- let tp = typeof v,
244
- rt = false;
245
- if (tp == "number" && String(v) == "") {
246
- rt = true
247
- } else if (tp == "undefined") {
248
- rt = true
249
- } else if (tp == "object") {
250
- if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) rt = true
251
- } else if (tp == "string") {
252
- if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") rt = true
253
- } else if (tp == "function") {
254
- rt = false
255
- }
256
- return rt
257
- },
258
- },
259
- watch: {
260
- size: function (n, o) {
261
- if (n != o && !this._empty(n)) {
262
- this.cSize = n
263
- if (!this._empty(this.val)) {
264
- setTimeout(() => {
265
- this._makeCode()
266
- }, 100);
267
- }
268
- }
269
- },
270
- val: function (n, o) {
271
- if (this.onval) {
272
- if (n != o && !this._empty(n)) {
273
- setTimeout(() => {
274
- this._makeCode()
275
- }, 0);
276
- }
277
- }
278
- }
279
- },
280
- computed: {
281
- }
180
+ }, 0);
181
+ }
182
+ }
183
+ },
184
+ methods: {
185
+ _makeCode() {
186
+ let that = this
187
+ if (!this._empty(this.val)) {
188
+ // #ifndef APP-NVUE
189
+ this.loading = true
190
+ // #endif
191
+ qrcode = new QRCode({
192
+ context: that, // 上下文环境
193
+ canvasId: that.cid, // canvas-id
194
+ nvueContext: that.context,
195
+ usingComponents: that.usingComponents, // 是否是自定义组件
196
+ showLoading: false, // 是否显示loading
197
+ loadingText: that.loadingText, // loading文字
198
+ text: that.val, // 生成内容
199
+ size: that.sizeLocal, // 二维码大小
200
+ background: that.background, // 背景色
201
+ foreground: that.foreground, // 前景色
202
+ pdground: that.pdground, // 定位角点颜色
203
+ correctLevel: that.lv, // 容错级别
204
+ image: that.icon, // 二维码图标
205
+ imageSize: that.iconSize,// 二维码图标大小
206
+ cbResult: function (res) { // 生成二维码的回调
207
+ that._result(res)
208
+ },
209
+ });
210
+ } else {
211
+ uni.showToast({
212
+ title: '二维码内容不能为空',
213
+ icon: 'none',
214
+ duration: 2000
215
+ });
216
+ }
217
+ },
218
+ _clearCode() {
219
+ this._result('')
220
+ qrcode.clear()
221
+ },
222
+ _saveCode() {
223
+ let that = this;
224
+ if (this.result != "") {
225
+ uni.saveImageToPhotosAlbum({
226
+ filePath: that.result,
227
+ success: function () {
228
+ uni.showToast({
229
+ title: '二维码保存成功',
230
+ icon: 'success',
231
+ duration: 2000
232
+ });
233
+ }
234
+ });
235
+ }
236
+ },
237
+ preview(e) {
238
+ // 预览图片
239
+ // console.log(this.result)
240
+ if (this.allowPreview) {
241
+ uni.previewImage({
242
+ urls: [this.result],
243
+ longPressActions: {
244
+ itemList: ['保存二维码图片'],
245
+ success: function(data) {
246
+ // console.log('选中了第' + (data.tapIndex + 1) + '个按钮,第' + (data.index + 1) + '张图片');
247
+ switch (data.tapIndex) {
248
+ case 0:
249
+ that._saveCode();
250
+ break;
251
+ }
252
+ },
253
+ fail: function(err) {
254
+ console.log(err.errMsg);
255
+ }
256
+ }
257
+ });
258
+ }
259
+ this.$emit('preview', {
260
+ url: this.result
261
+ }, e)
262
+ },
263
+ async longpress() {
264
+ if (this.context) {
265
+ this.ctx.toTempFilePath(
266
+ 0,
267
+ 0,
268
+ this.sizeLocal,
269
+ this.sizeLocal,
270
+ this.sizeLocal,
271
+ this.sizeLocal,
272
+ "",
273
+ 1,
274
+ res => {
275
+ this.$emit('longpressCallback', res.tempFilePath)
276
+ }
277
+ );
278
+ }
279
+ else {
280
+
281
+ // #ifdef MP-TOUTIAO || H5
282
+ this.$emit('longpressCallback', this.ctx.canvas.toDataURL("image/png", 1));
283
+ // #endif
284
+
285
+ // #ifdef APP-PLUS
286
+ uni.canvasToTempFilePath(
287
+ {
288
+ canvasId: this.cid,
289
+ success :res => {
290
+ this.$emit('longpressCallback', res.tempFilePath)
291
+ },
292
+ fail: err =>{
293
+ }
294
+ },
295
+ this)
296
+ // #endif
297
+
298
+ // #ifndef MP-TOUTIAO || H5 || APP-PLUS
299
+ const canvas = await this.getNode(this.cId,true);
300
+ uni.canvasToTempFilePath(
301
+ {
302
+ canvas,
303
+ success :res => {
304
+ this.$emit('longpressCallback', res.tempFilePath)
305
+ },
306
+ fail: err =>{
307
+ }
308
+ },
309
+ this)
310
+ // #endif
311
+
312
+ }
313
+
314
+ },
315
+
316
+ /**
317
+ * 使用根节点宽高 设置新的size
318
+ * @return {Promise<void>}
319
+ */
320
+ async setNewSize(){
321
+ const rootNode = await this.getNode(this.rootId,false);
322
+ const { width , height } = rootNode;
323
+ // 将最短的设置为二维码 的size
324
+ if(width > height){
325
+ this.sizeLocal = height
326
+ }
327
+ else{
328
+ this.sizeLocal = width
329
+ }
330
+ },
331
+
332
+ /**
333
+ * 获取节点
334
+ * @param id 节点id
335
+ * @param isCanvas 是否为Canvas节点
336
+ * @return {Promise<unknown>}
337
+ */
338
+ async getNode(id,isCanvas){
339
+ return new Promise((resolve, reject)=>{
340
+ try {
341
+ const query = uni.createSelectorQuery().in(this);
342
+ query.select(`#${id}`)
343
+ .fields({ node: true, size: true })
344
+ .exec((res) => {
345
+ if(isCanvas){
346
+ resolve(res[0].node)
347
+ }
348
+ else{
349
+ resolve(res[0])
350
+ }
351
+
352
+ })
353
+ }
354
+ catch (e) {
355
+ console.error("获取节点失败",e)
356
+ }
357
+ })
358
+ },
359
+
360
+ selectClick(index) {
361
+ switch (index) {
362
+ case 0:
363
+ alert('保存二维码')
364
+ this._saveCode();
365
+ break;
366
+ }
367
+ },
368
+ _result(res) {
369
+ this.loading = false;
370
+ this.result = res;
371
+ this.$emit('result', res);
372
+ },
373
+ _empty(v) {
374
+ let tp = typeof v,
375
+ rt = false;
376
+ if (tp == "number" && String(v) == "") {
377
+ rt = true
378
+ } else if (tp == "undefined") {
379
+ rt = true
380
+ } else if (tp == "object") {
381
+ if (JSON.stringify(v) == "{}" || JSON.stringify(v) == "[]" || v == null) rt = true
382
+ } else if (tp == "string") {
383
+ if (v == "" || v == "undefined" || v == "null" || v == "{}" || v == "[]") rt = true
384
+ } else if (tp == "function") {
385
+ rt = false
386
+ }
387
+ return rt
388
+ },
389
+ },
390
+ watch: {
391
+ size: function (n, o) {
392
+ if (n != o && !this._empty(n)) {
393
+ this.cSize = n
394
+ if (!this._empty(this.val)) {
395
+ setTimeout(() => {
396
+ this._makeCode()
397
+ }, 100);
398
+ }
399
+ }
400
+ },
401
+ val: function (n, o) {
402
+ if (this.onval) {
403
+ if (n != o && !this._empty(n)) {
404
+ setTimeout(() => {
405
+ this._makeCode()
406
+ }, 0);
407
+ }
408
+ }
409
+ }
410
+ },
411
+ computed: {
412
+ }
282
413
  }
283
414
  </script>
284
415
  <style lang="scss" scoped>
285
416
  .u-qrcode {
286
- &__loading {
287
- display: flex;
288
- justify-content: center;
289
- align-items: center;
290
- background-color: #f7f7f7;
291
- position: absolute;
292
- top: 0;
293
- bottom: 0;
294
- left: 0;
295
- right: 0;
296
- }
417
+ &__loading {
418
+ display: flex;
419
+ justify-content: center;
420
+ align-items: center;
421
+ background-color: #f7f7f7;
422
+ position: absolute;
423
+ top: 0;
424
+ bottom: 0;
425
+ left: 0;
426
+ right: 0;
427
+ }
297
428
 
298
429
  /* #ifdef MP-TOUTIAO */
299
430
  /**字节小程序在编译时会出现一个 [hidde]:{ display: none !important; } 这个样式
@@ -304,15 +435,15 @@ export default {
304
435
  }
305
436
  /* #endif */
306
437
 
307
- &__content {
308
- position: relative;
438
+ &__content {
439
+ position: relative;
309
440
 
310
- &__canvas {
311
- position: fixed;
312
- top: -99999rpx;
313
- left: -99999rpx;
314
- z-index: -99999;
315
- }
316
- }
441
+ &__canvas {
442
+ position: fixed;
443
+ top: -99999rpx;
444
+ left: -99999rpx;
445
+ z-index: -99999;
446
+ }
447
+ }
317
448
  }
318
449
  </style>