uview-plus 3.8.86 → 3.8.108
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/changelog.md +173 -3
- package/components/u-action-sheet/u-action-sheet.vue +21 -2
- package/components/u-barcode/u-barcode.vue +0 -2
- package/components/u-button/u-button.vue +2 -5
- package/components/u-canvas/u-canvas.vue +430 -77
- package/components/u-cell/u-cell.vue +8 -0
- package/components/u-datetime-picker/u-datetime-picker.vue +53 -4
- package/components/u-dragsort/u-dragsort.vue +55 -31
- package/components/u-icon/u-icon.vue +12 -3
- package/components/u-icon/util.js +81 -10
- package/components/u-index-item/u-index-item.vue +1 -1
- package/components/u-index-list/u-index-list.vue +1 -1
- package/components/u-novel-reader/content-normalizer.js +80 -0
- package/components/u-novel-reader/layout-engine.js +225 -0
- package/components/u-novel-reader/measure-adapter.js +69 -0
- package/components/u-novel-reader/novelReader.js +35 -0
- package/components/u-novel-reader/persistence.js +144 -0
- package/components/u-novel-reader/props.js +100 -0
- package/components/u-novel-reader/reader-catalog.vue +234 -0
- package/components/u-novel-reader/reader-content.vue +226 -0
- package/components/u-novel-reader/reader-core.js +151 -0
- package/components/u-novel-reader/reader-settings.vue +325 -0
- package/components/u-novel-reader/reader-toolbar.vue +313 -0
- package/components/u-novel-reader/theme-vars.scss +49 -0
- package/components/u-novel-reader/u-novel-reader.vue +836 -0
- package/components/u-poster/u-poster.vue +272 -222
- package/components/u-qrcode/qrcode.js +56 -49
- package/components/u-qrcode/u-qrcode.vue +159 -88
- package/components/u-scroll-list/scrollWxs.wxs +1 -1
- package/components/u-slider/u-slider.vue +1 -1
- package/components/u-swipe-action-item/index.wxs +43 -25
- package/components/u-swipe-action-item/nvue.js +9 -0
- package/components/u-swipe-action-item/other.js +32 -21
- package/components/u-swipe-action-item/props.js +5 -0
- package/components/u-swipe-action-item/swipeActionItem.js +1 -0
- package/components/u-swipe-action-item/u-swipe-action-item.vue +28 -4
- package/components/u-switch/u-switch.vue +1 -1
- package/components/u-tabbar/u-tabbar.vue +2 -1
- package/components/u-tabbar-item/u-tabbar-item.vue +64 -21
- package/components/u-tabs/u-tabs.vue +11 -8
- package/components/u-tabs-pro/u-tabs-pro.vue +212 -0
- package/components/u-text/text.js +1 -1
- package/components/u-text/u-text.vue +18 -6
- package/components/u-upload/u-upload.vue +1 -1
- package/components/u-waterfall/u-waterfall.vue +118 -65
- package/libs/config/config.js +1 -1
- package/libs/config/props.js +1 -0
- package/libs/function/index.js +66 -0
- package/libs/mixin/mixin.js +4 -50
- package/libs/root/index.js +78 -5
- package/libs/root/page.js +7 -7
- package/libs/root/root.js +73 -3
- package/libs/util/app-nvue-webview-canvas.js +486 -0
- package/libs/util/gcanvas/bridge/bridge-weex.js +0 -2
- package/libs/util/gcanvas/index.js +3 -3
- package/package.json +2 -2
- package/types/comps/swipeActionItem.d.ts +13 -0
- package/types/comps/tabs.d.ts +2 -1
- package/types/comps/text.d.ts +1 -1
- package/types/func.d.ts +23 -0
- package/types/index.d.ts +1 -0
|
@@ -1164,60 +1164,67 @@ let QRCode = {};
|
|
|
1164
1164
|
}
|
|
1165
1165
|
}
|
|
1166
1166
|
}
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
});
|
|
1203
|
-
}
|
|
1204
|
-
}, options.text.length + 100);
|
|
1205
|
-
};
|
|
1167
|
+
// canvas2 绘制是自动的不需要手动绘制
|
|
1168
|
+
if(options.isNvue || isApp){
|
|
1169
|
+
let exportStarted = false;
|
|
1170
|
+
const reportFailure = function(error) {
|
|
1171
|
+
uni.hideLoading();
|
|
1172
|
+
if (options.cbResult) {
|
|
1173
|
+
options.cbResult(error instanceof Error ? error : new Error(String(error || '绘制失败')))
|
|
1174
|
+
}
|
|
1175
|
+
};
|
|
1176
|
+
const exportCode = async function() {
|
|
1177
|
+
if (exportStarted) return;
|
|
1178
|
+
exportStarted = true;
|
|
1179
|
+
try {
|
|
1180
|
+
if (!options.canvasHost || typeof options.canvasHost.toTempFilePath !== 'function') {
|
|
1181
|
+
throw new Error('无法获取二维码画布导出方法');
|
|
1182
|
+
}
|
|
1183
|
+
const res = await options.canvasHost.toTempFilePath({
|
|
1184
|
+
width: options.width || options.size,
|
|
1185
|
+
height: options.height || options.size,
|
|
1186
|
+
quality: Number(1)
|
|
1187
|
+
});
|
|
1188
|
+
const tempFilePath = res && (res.tempFilePath || res.apFilePath);
|
|
1189
|
+
if (empty(tempFilePath)) {
|
|
1190
|
+
throw new Error('二维码导出未返回文件路径');
|
|
1191
|
+
}
|
|
1192
|
+
if (options.cbResult) {
|
|
1193
|
+
options.cbResult(tempFilePath)
|
|
1194
|
+
}
|
|
1195
|
+
uni.hideLoading();
|
|
1196
|
+
} catch (error) {
|
|
1197
|
+
reportFailure(error);
|
|
1198
|
+
}
|
|
1199
|
+
};
|
|
1200
|
+
try {
|
|
1201
|
+
let drawResult;
|
|
1206
1202
|
if (options.canvasHost && typeof options.canvasHost.draw === 'function') {
|
|
1207
|
-
options.canvasHost.draw(true, exportCode);
|
|
1203
|
+
drawResult = options.canvasHost.draw(true, exportCode);
|
|
1208
1204
|
} else if (ctx && typeof ctx.draw === 'function') {
|
|
1209
|
-
ctx.draw(true, exportCode);
|
|
1205
|
+
drawResult = ctx.draw(true, exportCode);
|
|
1210
1206
|
} else {
|
|
1211
1207
|
exportCode();
|
|
1212
1208
|
}
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
}
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
|
|
1220
|
-
|
|
1209
|
+
if (drawResult && typeof drawResult.then === 'function') {
|
|
1210
|
+
drawResult.then(exportCode, reportFailure);
|
|
1211
|
+
}
|
|
1212
|
+
} catch (error) {
|
|
1213
|
+
reportFailure(error);
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
else{
|
|
1217
|
+
setTimeout(function() {
|
|
1218
|
+
options.cbResult("")
|
|
1219
|
+
}, options.usingComponents ? 100 : 200);
|
|
1220
|
+
}
|
|
1221
|
+
}
|
|
1222
|
+
createCanvas(this.options).catch(function(error) {
|
|
1223
|
+
uni.hideLoading();
|
|
1224
|
+
if (opt.cbResult) {
|
|
1225
|
+
opt.cbResult(error instanceof Error ? error : new Error(String(error || '二维码绘制失败')))
|
|
1226
|
+
}
|
|
1227
|
+
});
|
|
1221
1228
|
// 空判定
|
|
1222
1229
|
let empty = function (v) {
|
|
1223
1230
|
let tp = typeof v,
|
|
@@ -6,7 +6,11 @@
|
|
|
6
6
|
height: useRootHeightAndWidth ? '100%' : 'auto',
|
|
7
7
|
}"
|
|
8
8
|
@longpress="longpress">
|
|
9
|
-
<view
|
|
9
|
+
<view
|
|
10
|
+
class="u-qrcode__content"
|
|
11
|
+
:style="{ width: sizeLocal + unit, height: sizeLocal + unit }"
|
|
12
|
+
@click="preview">
|
|
13
|
+
<!-- #ifdef APP-NVUE -->
|
|
10
14
|
<up-canvas
|
|
11
15
|
ref="qrcodeCanvas"
|
|
12
16
|
class="u-qrcode__canvas"
|
|
@@ -16,6 +20,18 @@
|
|
|
16
20
|
:unit="unit"
|
|
17
21
|
bg-color="transparent"
|
|
18
22
|
:style="{ width: sizeLocal + unit, height: sizeLocal + unit }" />
|
|
23
|
+
<!-- #endif -->
|
|
24
|
+
<!-- #ifndef APP-NVUE -->
|
|
25
|
+
<up-canvas
|
|
26
|
+
ref="qrcodeCanvas"
|
|
27
|
+
class="u-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 -->
|
|
19
35
|
<view v-if="showLoading && loading" class="u-qrcode__loading"
|
|
20
36
|
:style="{ width: sizeLocal + unit, height: sizeLocal + unit }">
|
|
21
37
|
<up-loading-icon vertical :text="loadingText" textSize="14px"></up-loading-icon>
|
|
@@ -27,7 +43,6 @@
|
|
|
27
43
|
|
|
28
44
|
<script>
|
|
29
45
|
import QRCode from "./qrcode.js"
|
|
30
|
-
let qrcode
|
|
31
46
|
export default {
|
|
32
47
|
name: "u-qrcode",
|
|
33
48
|
props: {
|
|
@@ -130,6 +145,9 @@ export default {
|
|
|
130
145
|
canvasHost: null
|
|
131
146
|
}
|
|
132
147
|
},
|
|
148
|
+
created() {
|
|
149
|
+
this._qrcode = null
|
|
150
|
+
},
|
|
133
151
|
async mounted(){
|
|
134
152
|
// 如果使用根节点的宽高 则 重新设置 size
|
|
135
153
|
if(this.useRootHeightAndWidth){
|
|
@@ -144,7 +162,9 @@ export default {
|
|
|
144
162
|
if (!this._empty(this.val)) {
|
|
145
163
|
setTimeout(() => {
|
|
146
164
|
setTimeout(()=>{
|
|
147
|
-
this._makeCode()
|
|
165
|
+
this._makeCode().catch(error => {
|
|
166
|
+
console.error('二维码生成失败', error)
|
|
167
|
+
})
|
|
148
168
|
})
|
|
149
169
|
}, 0);
|
|
150
170
|
}
|
|
@@ -153,49 +173,60 @@ export default {
|
|
|
153
173
|
methods: {
|
|
154
174
|
async _makeCode() {
|
|
155
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
|
+
}
|
|
156
184
|
if (!this.ctx) {
|
|
157
185
|
await this.initCanvas(true)
|
|
158
186
|
}
|
|
159
|
-
if (!this.ctx)
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
})
|
|
194
|
-
|
|
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
|
+
})
|
|
195
226
|
},
|
|
196
227
|
_clearCode() {
|
|
197
228
|
this._result('')
|
|
198
|
-
if (
|
|
229
|
+
if (this._qrcode) this._qrcode.clear()
|
|
199
230
|
},
|
|
200
231
|
_saveCode() {
|
|
201
232
|
let that = this;
|
|
@@ -256,24 +287,27 @@ export default {
|
|
|
256
287
|
url: this.result
|
|
257
288
|
}, e)
|
|
258
289
|
},
|
|
259
|
-
async toTempFilePath({success, fail}) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
|
|
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
|
|
266
310
|
}
|
|
267
|
-
this.canvasHost.toTempFilePath({
|
|
268
|
-
width: this.sizeLocal,
|
|
269
|
-
height: this.sizeLocal,
|
|
270
|
-
destWidth: this.sizeLocal,
|
|
271
|
-
destHeight: this.sizeLocal,
|
|
272
|
-
success,
|
|
273
|
-
fail
|
|
274
|
-
}).catch(err => {
|
|
275
|
-
if (fail) fail(err)
|
|
276
|
-
})
|
|
277
311
|
},
|
|
278
312
|
async longpress() {
|
|
279
313
|
this.toTempFilePath({
|
|
@@ -322,26 +356,48 @@ export default {
|
|
|
322
356
|
await this.$nextTick()
|
|
323
357
|
const canvasRef = this.$refs.qrcodeCanvas
|
|
324
358
|
if (!canvasRef) return false
|
|
325
|
-
await canvasRef.initCanvas(force)
|
|
359
|
+
const initialized = await canvasRef.initCanvas(force)
|
|
360
|
+
if (!initialized) {
|
|
361
|
+
this.canvasHost = null
|
|
362
|
+
this.ctx = null
|
|
363
|
+
return false
|
|
364
|
+
}
|
|
326
365
|
this.canvasHost = canvasRef
|
|
327
366
|
this.ctx = canvasRef.getRawContext()
|
|
328
367
|
return !!this.ctx
|
|
368
|
+
},
|
|
369
|
+
async refreshCanvas(force = false) {
|
|
370
|
+
await this.$nextTick()
|
|
371
|
+
return this.initCanvas(force)
|
|
329
372
|
},
|
|
330
373
|
getUPCanvasContext() {
|
|
331
374
|
return this.canvasHost ? this.canvasHost.getRawContext() : null
|
|
332
375
|
},
|
|
333
|
-
|
|
334
|
-
|
|
376
|
+
async drawImage(url, x, y, w, h) {
|
|
377
|
+
try {
|
|
335
378
|
if (!this.canvasHost) {
|
|
336
|
-
await this.initCanvas(true)
|
|
379
|
+
const initialized = await this.initCanvas(true)
|
|
380
|
+
if (!initialized) {
|
|
381
|
+
throw new Error('无法初始化二维码画布')
|
|
382
|
+
}
|
|
337
383
|
}
|
|
338
|
-
if (this.canvasHost) {
|
|
339
|
-
|
|
384
|
+
if (!this.canvasHost || !this.ctx) {
|
|
385
|
+
throw new Error('无法获取二维码画布实例')
|
|
340
386
|
}
|
|
341
|
-
|
|
342
|
-
|
|
387
|
+
await this.canvasHost.drawImage(url, x, y, w, h)
|
|
388
|
+
} catch (error) {
|
|
389
|
+
console.error('drawImage绘制出错', error)
|
|
390
|
+
throw error
|
|
343
391
|
}
|
|
344
|
-
},
|
|
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
|
+
},
|
|
345
401
|
|
|
346
402
|
selectClick(index) {
|
|
347
403
|
switch (index) {
|
|
@@ -374,33 +430,48 @@ export default {
|
|
|
374
430
|
},
|
|
375
431
|
},
|
|
376
432
|
watch: {
|
|
377
|
-
size: function (n, o) {
|
|
378
|
-
if (n != o && !this._empty(n)) {
|
|
379
|
-
this.
|
|
380
|
-
if (
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
}
|
|
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
|
+
}
|
|
396
467
|
},
|
|
397
468
|
computed: {
|
|
398
469
|
}
|
|
399
470
|
}
|
|
400
471
|
</script>
|
|
401
|
-
<style lang="scss" scoped>
|
|
402
|
-
.u-qrcode {
|
|
403
|
-
&__loading {
|
|
472
|
+
<style lang="scss" scoped>
|
|
473
|
+
.u-qrcode {
|
|
474
|
+
&__loading {
|
|
404
475
|
display: flex;
|
|
405
476
|
justify-content: center;
|
|
406
477
|
align-items: center;
|
|
@@ -17,7 +17,7 @@ function scroll(event, ownerInstance) {
|
|
|
17
17
|
setBarStyle(ownerInstance, x)
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
// 由于webview
|
|
20
|
+
// 由于webview的问题,无法保证scroll-view在滑动过程中,一直触发scroll事件,会导致
|
|
21
21
|
// 无法监听到某些滚动值,当在首尾临界值无法监听到时,这是致命的,因为错失这些值会导致滑块无法回到起点和终点
|
|
22
22
|
// 所以这里需要对临界值做监听并处理
|
|
23
23
|
function scrolltolower(event, ownerInstance) {
|
|
@@ -40,11 +40,12 @@ function touchmove(event, ownerInstance) {
|
|
|
40
40
|
if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > state.threshold) {
|
|
41
41
|
event.preventDefault && event.preventDefault()
|
|
42
42
|
event.stopPropagation && event.stopPropagation()
|
|
43
|
-
}
|
|
44
|
-
// 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
|
|
45
|
-
if (Math.abs(moveX) < Math.abs(moveY)) return
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
}
|
|
44
|
+
// 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
|
|
45
|
+
if (Math.abs(moveX) < Math.abs(moveY)) return
|
|
46
|
+
ownerInstance.callMethod('setScrolling', true)
|
|
47
|
+
|
|
48
|
+
// 限制右滑的距离,不允许内容部分往右偏移,右滑会导致X轴偏移值大于0,以此做判断
|
|
48
49
|
// 此处不能直接return,因为滑动过程中会缺失某些关键点坐标,会导致错乱,最好的办法就是
|
|
49
50
|
// 在超出后,设置为0
|
|
50
51
|
if (state.status === 'open') {
|
|
@@ -68,11 +69,16 @@ function touchmove(event, ownerInstance) {
|
|
|
68
69
|
function touchend(event, ownerInstance) {
|
|
69
70
|
// 触发事件的组件的ComponentDescriptor实例
|
|
70
71
|
var instance = event.instance
|
|
71
|
-
// wxs内的局部变量快照
|
|
72
|
-
var state = instance.getState()
|
|
73
|
-
if (!state.moving || state.disabled)
|
|
74
|
-
|
|
75
|
-
|
|
72
|
+
// wxs内的局部变量快照
|
|
73
|
+
var state = instance.getState()
|
|
74
|
+
if (!state.moving || state.disabled) {
|
|
75
|
+
ownerInstance.callMethod('setScrolling', false)
|
|
76
|
+
return
|
|
77
|
+
}
|
|
78
|
+
state.moving = false
|
|
79
|
+
ownerInstance.callMethod('setScrolling', false)
|
|
80
|
+
var touches = event.changedTouches ? event.changedTouches[0] : {}
|
|
81
|
+
var pageX = touches.pageX
|
|
76
82
|
var pageY = touches.pageY
|
|
77
83
|
var moveX = pageX - state.startX
|
|
78
84
|
if (state.status === 'open') {
|
|
@@ -98,11 +104,21 @@ function touchend(event, ownerInstance) {
|
|
|
98
104
|
} else {
|
|
99
105
|
openSwipeAction(instance, ownerInstance)
|
|
100
106
|
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
//
|
|
105
|
-
function
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 触摸取消
|
|
111
|
+
function touchcancel(event, ownerInstance) {
|
|
112
|
+
var instance = event.instance
|
|
113
|
+
var state = instance.getState()
|
|
114
|
+
if (state) {
|
|
115
|
+
state.moving = false
|
|
116
|
+
}
|
|
117
|
+
ownerInstance.callMethod('setScrolling', false)
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// 获取过渡时间
|
|
121
|
+
function getDuration(value) {
|
|
106
122
|
if (value.toString().indexOf('s') >= 0) return value
|
|
107
123
|
return value > 30 ? value + 'ms' : value + 's'
|
|
108
124
|
}
|
|
@@ -157,10 +173,11 @@ function setStatus(status, instance, ownerInstance) {
|
|
|
157
173
|
}
|
|
158
174
|
|
|
159
175
|
// 一次性收起滑动菜单
|
|
160
|
-
function closeSwipeAction(instance, ownerInstance) {
|
|
161
|
-
var state = instance.getState()
|
|
162
|
-
|
|
163
|
-
|
|
176
|
+
function closeSwipeAction(instance, ownerInstance) {
|
|
177
|
+
var state = instance.getState()
|
|
178
|
+
ownerInstance.callMethod('setScrolling', false)
|
|
179
|
+
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
180
|
+
var buttons = ownerInstance.selectAllComponents('.u-swipe-action-item__right__button')
|
|
164
181
|
var len = buttons.length
|
|
165
182
|
// 处理duration单位问题
|
|
166
183
|
var duration = getDuration(state.duration)
|
|
@@ -226,9 +243,10 @@ function sizeChange(newValue, oldValue, ownerInstance, instance) {
|
|
|
226
243
|
}
|
|
227
244
|
|
|
228
245
|
module.exports = {
|
|
229
|
-
touchstart: touchstart,
|
|
230
|
-
touchmove: touchmove,
|
|
231
|
-
touchend: touchend,
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
246
|
+
touchstart: touchstart,
|
|
247
|
+
touchmove: touchmove,
|
|
248
|
+
touchend: touchend,
|
|
249
|
+
touchcancel: touchcancel,
|
|
250
|
+
sizeChange: sizeChange,
|
|
251
|
+
statusChange: statusChange
|
|
252
|
+
}
|
|
@@ -43,6 +43,7 @@ export default {
|
|
|
43
43
|
},
|
|
44
44
|
// 关闭单元格,用于打开一个,自动关闭其他单元格的场景
|
|
45
45
|
closeHandler() {
|
|
46
|
+
this.setScrolling(false)
|
|
46
47
|
if(this.status === 'open') {
|
|
47
48
|
// 如果在打开状态下,进行点击的话,直接关闭单元格
|
|
48
49
|
return this.moveCellByAnimation('close') && this.unbindBindingX()
|
|
@@ -55,6 +56,7 @@ export default {
|
|
|
55
56
|
// 尝试关闭其他打开的单元格
|
|
56
57
|
this.parent && this.parent.closeOther(this)
|
|
57
58
|
if(this.status === 'open') {
|
|
59
|
+
this.setScrolling(false)
|
|
58
60
|
// 如果在打开状态下,进行点击的话,直接关闭单元格
|
|
59
61
|
return this.moveCellByAnimation('close') && this.unbindBindingX()
|
|
60
62
|
}
|
|
@@ -63,9 +65,11 @@ export default {
|
|
|
63
65
|
onTouchstart(e) {
|
|
64
66
|
// 如果当前正在移动中,或者disabled状态,则返回
|
|
65
67
|
if(this.moving || this.disabled) {
|
|
68
|
+
this.setScrolling(false)
|
|
66
69
|
return this.unbindBindingX()
|
|
67
70
|
}
|
|
68
71
|
if(this.status === 'open') {
|
|
72
|
+
this.setScrolling(false)
|
|
69
73
|
// 如果在打开状态下,进行点击的话,直接关闭单元格
|
|
70
74
|
return this.moveCellByAnimation('close') && this.unbindBindingX()
|
|
71
75
|
}
|
|
@@ -73,6 +77,7 @@ export default {
|
|
|
73
77
|
e?.stopPropagation && e.stopPropagation()
|
|
74
78
|
e?.preventDefault && e.preventDefault()
|
|
75
79
|
this.moving = true
|
|
80
|
+
this.setScrolling(true)
|
|
76
81
|
// 获取元素ref
|
|
77
82
|
const content = this.getContentRef()
|
|
78
83
|
let expression = `min(max(${-this.buttonsWidth}, x), 0)`
|
|
@@ -92,6 +97,7 @@ export default {
|
|
|
92
97
|
}, (res) => {
|
|
93
98
|
this.moving = false
|
|
94
99
|
if (res.state === 'end' || res.state === 'exit') {
|
|
100
|
+
this.setScrolling(false)
|
|
95
101
|
const deltaX = res.deltaX
|
|
96
102
|
if(deltaX <= -this.buttonsWidth || deltaX >= 0) {
|
|
97
103
|
// 如果触摸滑动的过程中,大于单元格的总宽度,或者大于0,意味着已经动过滑动达到了打开或者关闭的状态
|
|
@@ -114,6 +120,7 @@ export default {
|
|
|
114
120
|
},
|
|
115
121
|
// 释放bindingX
|
|
116
122
|
unbindBindingX() {
|
|
123
|
+
this.setScrolling(false)
|
|
117
124
|
// 释放上一次的资源
|
|
118
125
|
if (this?.panEvent?.token != 0) {
|
|
119
126
|
bindingX.unbind({
|
|
@@ -159,6 +166,7 @@ export default {
|
|
|
159
166
|
timingFunction: 'ease-in-out'
|
|
160
167
|
}, () => {
|
|
161
168
|
this.moving = false
|
|
169
|
+
this.setScrolling(false)
|
|
162
170
|
this.status = status
|
|
163
171
|
this.unbindBindingX()
|
|
164
172
|
})
|
|
@@ -168,6 +176,7 @@ export default {
|
|
|
168
176
|
return this.$refs['u-swipe-action-item__content'].ref
|
|
169
177
|
},
|
|
170
178
|
beforeUnmount() {
|
|
179
|
+
this.setScrolling(false)
|
|
171
180
|
this.unbindBindingX()
|
|
172
181
|
}
|
|
173
182
|
}
|