uview-plus 3.1.41 → 3.1.45
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 +12 -0
- package/components/u-calendar/month.vue +1 -1
- package/components/u-calendar/u-calendar.vue +7 -2
- package/components/u-cell/u-cell.vue +5 -9
- package/components/u-code/u-code.vue +3 -3
- package/components/u-collapse-item/u-collapse-item.vue +6 -11
- package/components/u-index-list/u-index-list.vue +4 -4
- package/components/u-input/u-input.vue +5 -4
- package/components/u-number-box/u-number-box.vue +8 -5
- package/components/u-picker/u-picker.vue +2 -2
- package/components/u-swipe-action-item/alipay.sjs +229 -0
- package/components/u-swipe-action-item/other.js +171 -0
- package/components/u-swipe-action-item/u-swipe-action-item.vue +25 -13
- package/components/u-text/u-text.vue +2 -2
- package/components/u-textarea/u-textarea.vue +2 -0
- package/package.json +1 -1
package/changelog.md
CHANGED
|
@@ -1,3 +1,15 @@
|
|
|
1
|
+
## 3.1.45(2024-01-24)
|
|
2
|
+
fix: #262ext组件为超链接的情况下size属性不生效
|
|
3
|
+
fix: #263最新版本3.1.42中微信小程序u-swipe-action-item报错
|
|
4
|
+
fix: #224最新版本3.1.42中微信小程序u-swipe-action-item报错
|
|
5
|
+
fix: #263支持支付宝小程序
|
|
6
|
+
fix: #261u-input在直接修改v-model的绑定值时,每隔一次会无法出发change事件
|
|
7
|
+
优化折叠面板兼容微信小程序
|
|
8
|
+
## 3.1.42(2024-01-15)
|
|
9
|
+
修复u-number-box默认值0时在小程序不显示值
|
|
10
|
+
优化u-code的timer判断
|
|
11
|
+
优化支付宝小程序下textarea字数统计兼容
|
|
12
|
+
优化u-calendar
|
|
1
13
|
## 3.1.41(2023-11-18)
|
|
2
14
|
#215优化u-cell图标容器间距问题
|
|
3
15
|
## 3.1.40(2023-11-16)
|
|
@@ -199,7 +199,7 @@ export default {
|
|
|
199
199
|
this.innerFormatter = e
|
|
200
200
|
},
|
|
201
201
|
// month组件内部选择日期后,通过事件通知给父组件
|
|
202
|
-
monthSelected(e) {
|
|
202
|
+
monthSelected(e,scene ='init') {
|
|
203
203
|
this.selected = e
|
|
204
204
|
if (!this.showConfirm) {
|
|
205
205
|
// 在不需要确认按钮的情况下,如果为单选,或者范围多选且已选长度大于2,则直接进行返还
|
|
@@ -208,7 +208,12 @@ export default {
|
|
|
208
208
|
this.mode === 'single' ||
|
|
209
209
|
(this.mode === 'range' && this.selected.length >= 2)
|
|
210
210
|
) {
|
|
211
|
-
|
|
211
|
+
if( scene === 'init'){
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
if( scene === 'tap') {
|
|
215
|
+
this.$emit('confirm', this.selected)
|
|
216
|
+
}
|
|
212
217
|
}
|
|
213
218
|
}
|
|
214
219
|
},
|
|
@@ -11,11 +11,9 @@
|
|
|
11
11
|
:custom-style="iconStyle"
|
|
12
12
|
:size="size === 'large' ? 22 : 18"></u-icon>
|
|
13
13
|
</view>
|
|
14
|
-
<view class="u-cell__title">
|
|
15
|
-
|
|
16
|
-
<text v-if="title" class="u-cell__title-text" :style="[titleTextStyle]"
|
|
14
|
+
<view class="u-cell__title">
|
|
15
|
+
<text v-else class="u-cell__title-text" :style="[titleTextStyle]"
|
|
17
16
|
:class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__title-text--large']">{{ title }}</text>
|
|
18
|
-
</slot>
|
|
19
17
|
<slot name="label">
|
|
20
18
|
<text class="u-cell__label" v-if="label"
|
|
21
19
|
:class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__label--large']">{{ label }}</text>
|
|
@@ -29,10 +27,8 @@
|
|
|
29
27
|
</slot>
|
|
30
28
|
<view class="u-cell__right-icon-wrap" v-if="$slots['right-icon'] || isLink"
|
|
31
29
|
:class="[`u-cell__right-icon-wrap--${arrowDirection}`]">
|
|
32
|
-
<slot name="right-icon"
|
|
33
|
-
|
|
34
|
-
<u-icon v-else :name="rightIcon" :custom-style="rightIconStyle" :color="disabled ? '#c8c9cc' : 'info'"
|
|
35
|
-
:size="size === 'large' ? 18 : 16"></u-icon>
|
|
30
|
+
<slot name="right-icon">
|
|
31
|
+
<u-icon v-if="rightIcon" :name="rightIcon" :custom-style="rightIconStyle" :color="disabled ? '#c8c9cc' : 'info'"
|
|
36
32
|
</view>
|
|
37
33
|
</view>
|
|
38
34
|
<u-line v-if="border"></u-line>
|
|
@@ -207,10 +203,10 @@
|
|
|
207
203
|
|
|
208
204
|
&__value {
|
|
209
205
|
text-align: right;
|
|
206
|
+
margin-left: auto;
|
|
210
207
|
font-size: $u-cell-value-font-size;
|
|
211
208
|
line-height: $u-cell-line-height;
|
|
212
209
|
color: $u-cell-value-color;
|
|
213
|
-
|
|
214
210
|
&--large {
|
|
215
211
|
font-size: $u-cell-value-font-size-large;
|
|
216
212
|
}
|
|
@@ -18,11 +18,11 @@
|
|
|
18
18
|
* @property {String} endText 倒计结束的提示语,见官网说明(默认 '重新获取' )
|
|
19
19
|
* @property {Boolean} keepRunning 是否在H5刷新或各端返回再进入时继续倒计时( 默认false )
|
|
20
20
|
* @property {String} uniqueKey 为了区分多个页面,或者一个页面多个倒计时组件本地存储的继续倒计时变了
|
|
21
|
-
*
|
|
21
|
+
*
|
|
22
22
|
* @event {Function} change 倒计时期间,每秒触发一次
|
|
23
23
|
* @event {Function} start 开始倒计时触发
|
|
24
24
|
* @event {Function} end 结束倒计时触发
|
|
25
|
-
* @example <u-code ref="uCode" @change="codeChange" seconds="20"></u-code>
|
|
25
|
+
* @example <u-code ref="uCode" @change="codeChange" seconds="20"></u-code>
|
|
26
26
|
*/
|
|
27
27
|
export default {
|
|
28
28
|
name: "u-code",
|
|
@@ -104,7 +104,7 @@
|
|
|
104
104
|
},
|
|
105
105
|
// 保存时间戳,为了防止倒计时尚未结束,H5刷新或者各端的右上角返回上一页再进来
|
|
106
106
|
setTimeToStorage() {
|
|
107
|
-
if(!this.keepRunning
|
|
107
|
+
if(!this.keepRunning) return
|
|
108
108
|
// 记录当前的时间戳,为了下次进入页面,如果还在倒计时内的话,继续倒计时
|
|
109
109
|
// 倒计时尚未结束,结果大于0;倒计时已经开始,就会小于初始值,如果等于初始值,说明没有开始倒计时,无需处理
|
|
110
110
|
if(this.secNum > 0 && this.secNum <= this.seconds) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<view class="u-collapse-item">
|
|
3
3
|
<u-cell
|
|
4
|
-
:title="title"
|
|
4
|
+
:title="$slots.title ? '' : title"
|
|
5
5
|
:value="value"
|
|
6
6
|
:label="label"
|
|
7
7
|
:icon="icon"
|
|
@@ -12,21 +12,16 @@
|
|
|
12
12
|
:arrowDirection="expanded ? 'up' : 'down'"
|
|
13
13
|
:disabled="disabled"
|
|
14
14
|
>
|
|
15
|
-
<!-- #ifndef MP-WEIXIN -->
|
|
16
15
|
<!-- 微信小程序不支持,因为微信中不支持 <slot name="title" slot="title" />的写法 -->
|
|
17
|
-
<template #title>
|
|
18
|
-
<slot name="
|
|
19
|
-
</template>
|
|
20
|
-
<template #icon>
|
|
21
|
-
<slot name="icon"></slot>
|
|
16
|
+
<template #title>
|
|
17
|
+
<slot name="icon">
|
|
22
18
|
</template>
|
|
23
19
|
<template #value>
|
|
24
|
-
<slot name="value"
|
|
20
|
+
<slot name="value">
|
|
25
21
|
</template>
|
|
26
22
|
<template #right-icon>
|
|
27
|
-
<slot name="right-icon"
|
|
23
|
+
<slot name="right-icon">
|
|
28
24
|
</template>
|
|
29
|
-
<!-- #endif -->
|
|
30
25
|
</u-cell>
|
|
31
26
|
<view
|
|
32
27
|
class="u-collapse-item__content"
|
|
@@ -101,7 +96,7 @@
|
|
|
101
96
|
}
|
|
102
97
|
},
|
|
103
98
|
mounted() {
|
|
104
|
-
this.init()
|
|
99
|
+
this.init()
|
|
105
100
|
},
|
|
106
101
|
methods: {
|
|
107
102
|
// 异步获取内容,或者动态修改了内容时,需要重新初始化
|
|
@@ -48,10 +48,10 @@
|
|
|
48
48
|
class="u-index-list__letter"
|
|
49
49
|
ref="u-index-list__letter"
|
|
50
50
|
:style="{ top: $u.addUnit(letterInfo.top || 100) }"
|
|
51
|
-
@touchstart="touchStart"
|
|
52
|
-
@touchmove.
|
|
53
|
-
@touchend.
|
|
54
|
-
@touchcancel.
|
|
51
|
+
@touchstart.prevent="touchStart"
|
|
52
|
+
@touchmove.prevent="touchMove"
|
|
53
|
+
@touchend.prevent="touchEnd"
|
|
54
|
+
@touchcancel.prevent="touchEnd"
|
|
55
55
|
>
|
|
56
56
|
<view
|
|
57
57
|
class="u-index-list__letter__item"
|
|
@@ -44,6 +44,7 @@
|
|
|
44
44
|
@focus="onFocus"
|
|
45
45
|
@confirm="onConfirm"
|
|
46
46
|
@keyboardheightchange="onkeyboardheightchange"
|
|
47
|
+
@change="onInput"
|
|
47
48
|
/>
|
|
48
49
|
</view>
|
|
49
50
|
<view
|
|
@@ -147,10 +148,10 @@ export default {
|
|
|
147
148
|
// 在H5中,外部value变化后,修改input中的值,不会触发@input事件,此时手动调用值变化方法
|
|
148
149
|
if (
|
|
149
150
|
this.firstChange === false &&
|
|
150
|
-
|
|
151
|
+
this.changeFromInner === false
|
|
151
152
|
) {
|
|
152
153
|
this.valueChange();
|
|
153
|
-
}
|
|
154
|
+
} else {
|
|
154
155
|
/* #endif */
|
|
155
156
|
this.firstChange = false;
|
|
156
157
|
// 重置changeFromInner的值为false,标识下一次引起默认为外部引起的
|
|
@@ -170,7 +171,7 @@ export default {
|
|
|
170
171
|
this.changeFromInner === false
|
|
171
172
|
) {
|
|
172
173
|
this.valueChange();
|
|
173
|
-
}
|
|
174
|
+
} else {
|
|
174
175
|
/* #endif */
|
|
175
176
|
this.firstChange = false;
|
|
176
177
|
// 重置changeFromInner的值为false,标识下一次引起默认为外部引起的
|
|
@@ -254,7 +255,7 @@ export default {
|
|
|
254
255
|
this.$emit("blur", event.detail.value);
|
|
255
256
|
// H5端的blur会先于点击清除控件的点击click事件触发,导致focused
|
|
256
257
|
// 瞬间为false,从而隐藏了清除控件而无法被点击到
|
|
257
|
-
uni.$u.sleep(
|
|
258
|
+
uni.$u.sleep(150).then(() => {
|
|
258
259
|
this.focused = false;
|
|
259
260
|
});
|
|
260
261
|
// 尝试调用u-form的验证方法
|
|
@@ -136,11 +136,14 @@
|
|
|
136
136
|
// #endif
|
|
137
137
|
// #ifdef VUE3
|
|
138
138
|
// 监听v-mode的变化,重新初始化内部的值
|
|
139
|
-
modelValue
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
139
|
+
modelValue: {
|
|
140
|
+
handler: function (newV, oldV) {
|
|
141
|
+
if (newV !== this.currentValue) {
|
|
142
|
+
this.currentValue = this.format(this.modelValue)
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
immediate: true
|
|
146
|
+
}
|
|
144
147
|
// #endif
|
|
145
148
|
},
|
|
146
149
|
computed: {
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
:key="index"
|
|
31
31
|
class="u-picker__view__column"
|
|
32
32
|
>
|
|
33
|
-
<
|
|
33
|
+
<view
|
|
34
34
|
v-if="$u.test.array(item)"
|
|
35
35
|
class="u-picker__view__column__item u-line-1"
|
|
36
36
|
v-for="(item1, index1) in item"
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
lineHeight: $u.addUnit(itemHeight),
|
|
41
41
|
fontWeight: index1 === innerIndex[index] ? 'bold' : 'normal'
|
|
42
42
|
}"
|
|
43
|
-
>{{ getItemText(item1) }}</
|
|
43
|
+
>{{ getItemText(item1) }}</view>
|
|
44
44
|
</picker-view-column>
|
|
45
45
|
</picker-view>
|
|
46
46
|
<view
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 此为wxs模块,只支持APP-VUE,微信和QQ小程序以及H5平台
|
|
3
|
+
* wxs内部不支持es6语法,变量只能使用var定义,无法使用解构,箭头函数等特性
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// 开始触摸
|
|
7
|
+
function touchstart(event, ownerInstance) {
|
|
8
|
+
// 触发事件的组件的ComponentDescriptor实例
|
|
9
|
+
var instance = event.instance
|
|
10
|
+
// wxs内的局部变量快照,此快照是属于整个组件的,在touchstart和touchmove事件中都能获取到相同的结果
|
|
11
|
+
var state = instance.getState()
|
|
12
|
+
if (state.disabled) return
|
|
13
|
+
var touches = event.touches
|
|
14
|
+
// 如果进行的是多指触控,不允许进行操作
|
|
15
|
+
if (touches && touches.length > 1) return
|
|
16
|
+
// 标识当前为滑动中状态
|
|
17
|
+
state.moving = true
|
|
18
|
+
// 记录触摸开始点的坐标值
|
|
19
|
+
state.startX = touches[0].pageX
|
|
20
|
+
state.startY = touches[0].pageY
|
|
21
|
+
|
|
22
|
+
ownerInstance.callMethod('closeOther')
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// 触摸滑动
|
|
26
|
+
function touchmove(event, ownerInstance) {
|
|
27
|
+
// 触发事件的组件的ComponentDescriptor实例
|
|
28
|
+
var instance = event.instance
|
|
29
|
+
// wxs内的局部变量快照
|
|
30
|
+
var state = instance.getState()
|
|
31
|
+
if (state.disabled || !state.moving) return
|
|
32
|
+
var touches = event.touches
|
|
33
|
+
var pageX = touches[0].pageX
|
|
34
|
+
var pageY = touches[0].pageY
|
|
35
|
+
var moveX = pageX - state.startX
|
|
36
|
+
var moveY = pageY - state.startY
|
|
37
|
+
var buttonsWidth = state.buttonsWidth
|
|
38
|
+
|
|
39
|
+
// 移动的X轴距离大于Y轴距离,也即终点与起点位置连线,与X轴夹角小于45度时,禁止页面滚动
|
|
40
|
+
if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > state.threshold) {
|
|
41
|
+
event.preventDefault && event.preventDefault()
|
|
42
|
+
event.stopPropagation && event.stopPropagation()
|
|
43
|
+
}
|
|
44
|
+
// 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
|
|
45
|
+
if (Math.abs(moveX) < Math.abs(moveY)) return
|
|
46
|
+
|
|
47
|
+
// 限制右滑的距离,不允许内容部分往右偏移,右滑会导致X轴偏移值大于0,以此做判断
|
|
48
|
+
// 此处不能直接return,因为滑动过程中会缺失某些关键点坐标,会导致错乱,最好的办法就是
|
|
49
|
+
// 在超出后,设置为0
|
|
50
|
+
if (state.status === 'open') {
|
|
51
|
+
// 在开启状态下,向左滑动,需忽略
|
|
52
|
+
if (moveX < 0) moveX = 0
|
|
53
|
+
// 想要收起菜单,最大能移动的距离为按钮的总宽度
|
|
54
|
+
if (moveX > buttonsWidth) moveX = buttonsWidth
|
|
55
|
+
// 如果是已经打开了的状态,向左滑动时,移动收起菜单
|
|
56
|
+
moveSwipeAction(-buttonsWidth + moveX, instance, ownerInstance)
|
|
57
|
+
} else {
|
|
58
|
+
// 关闭状态下,右滑动需忽略
|
|
59
|
+
if (moveX > 0) moveX = 0
|
|
60
|
+
// 滑动的距离不允许超过所有按钮的总宽度,此时只能是左滑,最终设置按钮的总宽度,同时为负数
|
|
61
|
+
if (Math.abs(moveX) > buttonsWidth) moveX = -buttonsWidth
|
|
62
|
+
// 只要是在滑过程中,就不断移动单元格内容部分,从而使隐藏的菜单显示出来
|
|
63
|
+
moveSwipeAction(moveX, instance, ownerInstance)
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// 触摸结束
|
|
68
|
+
function touchend(event, ownerInstance) {
|
|
69
|
+
// 触发事件的组件的ComponentDescriptor实例
|
|
70
|
+
var instance = event.instance
|
|
71
|
+
// wxs内的局部变量快照
|
|
72
|
+
var state = instance.getState()
|
|
73
|
+
if (!state.moving || state.disabled) return
|
|
74
|
+
var touches = event.changedTouches ? event.changedTouches[0] : {}
|
|
75
|
+
var pageX = touches.pageX
|
|
76
|
+
var pageY = touches.pageY
|
|
77
|
+
var moveX = pageX - state.startX
|
|
78
|
+
if (state.status === 'open') {
|
|
79
|
+
// 在展开的状态下,继续左滑,无需操作
|
|
80
|
+
if (moveX < 0) return
|
|
81
|
+
// 在开启状态下,点击一下内容区域,moveX为0,也即没有进行移动,这时执行收起菜单逻辑
|
|
82
|
+
if (moveX === 0) {
|
|
83
|
+
return closeSwipeAction(instance, ownerInstance)
|
|
84
|
+
}
|
|
85
|
+
// 在开启状态下,滑动距离小于阈值,则默认为不关闭,同时恢复原来的打开状态
|
|
86
|
+
if (Math.abs(moveX) < state.threshold) {
|
|
87
|
+
openSwipeAction(instance, ownerInstance)
|
|
88
|
+
} else {
|
|
89
|
+
// 如果滑动距离大于阈值,则执行收起逻辑
|
|
90
|
+
closeSwipeAction(instance, ownerInstance)
|
|
91
|
+
}
|
|
92
|
+
} else {
|
|
93
|
+
// 在关闭的状态下,右滑,无需操作
|
|
94
|
+
if (moveX > 0) return
|
|
95
|
+
// 理由同上
|
|
96
|
+
if (Math.abs(moveX) < state.threshold) {
|
|
97
|
+
closeSwipeAction(instance, ownerInstance)
|
|
98
|
+
} else {
|
|
99
|
+
openSwipeAction(instance, ownerInstance)
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// 获取过渡时间
|
|
105
|
+
function getDuration(value) {
|
|
106
|
+
if (value.toString().indexOf('s') >= 0) return value
|
|
107
|
+
return value > 30 ? value + 'ms' : value + 's'
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 滑动结束时判断滑动的方向
|
|
111
|
+
function getMoveDirection(instance, ownerInstance) {
|
|
112
|
+
var state = instance.getState()
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// 移动滑动选择器内容区域,同时显示出其隐藏的菜单
|
|
116
|
+
function moveSwipeAction(moveX, instance, ownerInstance) {
|
|
117
|
+
var state = instance.getState()
|
|
118
|
+
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
119
|
+
var buttons = ownerInstance.selectAllComponents('.u-swipe-action-item__right__button')
|
|
120
|
+
|
|
121
|
+
// 设置菜单内容部分的偏移
|
|
122
|
+
instance.requestAnimationFrame(function() {
|
|
123
|
+
instance.setStyle({
|
|
124
|
+
// 设置translateX的值
|
|
125
|
+
'transition': 'none',
|
|
126
|
+
transform: 'translateX(' + moveX + 'px)',
|
|
127
|
+
'-webkit-transform': 'translateX(' + moveX + 'px)'
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// 一次性展开滑动菜单
|
|
133
|
+
function openSwipeAction(instance, ownerInstance) {
|
|
134
|
+
var state = instance.getState()
|
|
135
|
+
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
136
|
+
var buttons = ownerInstance.selectAllComponents('.u-swipe-action-item__right__button')
|
|
137
|
+
// 处理duration单位问题
|
|
138
|
+
var duration = getDuration(state.duration)
|
|
139
|
+
// 展开过程中,是向左移动,所以X的偏移应该为负值
|
|
140
|
+
var buttonsWidth = -state.buttonsWidth
|
|
141
|
+
instance.requestAnimationFrame(function() {
|
|
142
|
+
// 设置菜单主体内容
|
|
143
|
+
instance.setStyle({
|
|
144
|
+
'transition': 'transform ' + duration,
|
|
145
|
+
'transform': 'translateX(' + buttonsWidth + 'px)',
|
|
146
|
+
'-webkit-transform': 'translateX(' + buttonsWidth + 'px)',
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
setStatus('open', instance, ownerInstance)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// 标记菜单的当前状态,open-已经打开,close-已经关闭
|
|
153
|
+
function setStatus(status, instance, ownerInstance) {
|
|
154
|
+
var state = instance.getState()
|
|
155
|
+
state.status = status
|
|
156
|
+
ownerInstance.callMethod('setState', status)
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
// 一次性收起滑动菜单
|
|
160
|
+
function closeSwipeAction(instance, ownerInstance) {
|
|
161
|
+
var state = instance.getState()
|
|
162
|
+
// 获取所有按钮的实例,需要通过它去设置按钮的位移
|
|
163
|
+
var buttons = ownerInstance.selectAllComponents('.u-swipe-action-item__right__button')
|
|
164
|
+
var len = buttons.length
|
|
165
|
+
// 处理duration单位问题
|
|
166
|
+
var duration = getDuration(state.duration)
|
|
167
|
+
instance.requestAnimationFrame(function() {
|
|
168
|
+
// 设置菜单主体内容
|
|
169
|
+
instance.setStyle({
|
|
170
|
+
'transition': 'transform ' + duration,
|
|
171
|
+
'transform': 'translateX(0px)',
|
|
172
|
+
'-webkit-transform': 'translateX(0px)'
|
|
173
|
+
})
|
|
174
|
+
// 设置各个隐藏的按钮为收起的状态
|
|
175
|
+
for (var i = len - 1; i >= 0; i--) {
|
|
176
|
+
buttons[i].setStyle({
|
|
177
|
+
'transition': 'transform ' + duration,
|
|
178
|
+
'transform': 'translateX(0px)',
|
|
179
|
+
'-webkit-transform': 'translateX(0px)'
|
|
180
|
+
})
|
|
181
|
+
}
|
|
182
|
+
})
|
|
183
|
+
setStatus('close', instance, ownerInstance)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// status的状态发生变化
|
|
187
|
+
function statusChange(newValue, oldValue, ownerInstance, instance) {
|
|
188
|
+
var state = instance.getState()
|
|
189
|
+
if (state.disabled) return
|
|
190
|
+
// 打开或关闭单元格
|
|
191
|
+
if (newValue === 'close' && state.status === 'open') {
|
|
192
|
+
closeSwipeAction(instance, ownerInstance)
|
|
193
|
+
} else if(newValue === 'open' && state.status === 'close') {
|
|
194
|
+
openSwipeAction(instance, ownerInstance)
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// 菜单尺寸发生变化
|
|
199
|
+
function sizeChange(newValue, oldValue, ownerInstance, instance) {
|
|
200
|
+
// wxs内的局部变量快照
|
|
201
|
+
var state = instance.getState()
|
|
202
|
+
// 临时防止nv_disabled报错
|
|
203
|
+
if (!state || !newValue) {
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
state.disabled = newValue.disabled
|
|
207
|
+
state.duration = newValue.duration
|
|
208
|
+
state.show = newValue.show
|
|
209
|
+
state.threshold = newValue.threshold
|
|
210
|
+
state.buttons = newValue.buttons
|
|
211
|
+
|
|
212
|
+
if (state.buttons) {
|
|
213
|
+
var len = state.buttons.length
|
|
214
|
+
var buttonsWidth = 0
|
|
215
|
+
var buttons = newValue.buttons
|
|
216
|
+
for (var i = 0; i < len; i++) {
|
|
217
|
+
buttonsWidth += buttons[i].width
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
state.buttonsWidth = buttonsWidth
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
export default {
|
|
224
|
+
touchstart: touchstart,
|
|
225
|
+
touchmove: touchmove,
|
|
226
|
+
touchend: touchend,
|
|
227
|
+
sizeChange: sizeChange,
|
|
228
|
+
statusChange: statusChange
|
|
229
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
data() {
|
|
3
|
+
return {
|
|
4
|
+
state: {
|
|
5
|
+
moving: false,
|
|
6
|
+
startX: 0,
|
|
7
|
+
startY: 0,
|
|
8
|
+
buttonsWidth: 0
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
watch: {
|
|
13
|
+
status(newValue) {
|
|
14
|
+
if (this.disabled) return
|
|
15
|
+
// 打开或关闭单元格
|
|
16
|
+
if (newValue === 'close' && this.status === 'open') {
|
|
17
|
+
this.closeSwipeAction(instance, ownerInstance)
|
|
18
|
+
} else if(newValue === 'open' && this.status === 'close') {
|
|
19
|
+
this.openSwipeAction()
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
options(newVal) {
|
|
23
|
+
this.getBtnWidth()
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
mounted() {
|
|
27
|
+
this.getBtnWidth()
|
|
28
|
+
},
|
|
29
|
+
methods: {
|
|
30
|
+
clickHandler() {
|
|
31
|
+
},
|
|
32
|
+
getBtnWidth() {
|
|
33
|
+
let view = uni.createSelectorQuery().in(this).select(".u-swipe-action-item__right");
|
|
34
|
+
view.fields({
|
|
35
|
+
size: true,
|
|
36
|
+
scrollOffset: true
|
|
37
|
+
}, data => {
|
|
38
|
+
this.state.buttonsWidth = data.width
|
|
39
|
+
// console.log("得到节点信息" + JSON.stringify(data));
|
|
40
|
+
}).exec();
|
|
41
|
+
},
|
|
42
|
+
// 开始触摸
|
|
43
|
+
touchstart(event) {
|
|
44
|
+
// console.log(event)
|
|
45
|
+
// 标识当前为滑动中状态
|
|
46
|
+
this.state.moving = true
|
|
47
|
+
// 记录触摸开始点的坐标值
|
|
48
|
+
var touches = event.touches
|
|
49
|
+
this.state.startX = touches[0].pageX
|
|
50
|
+
this.state.startY = touches[0].pageY
|
|
51
|
+
|
|
52
|
+
// todo关闭其它
|
|
53
|
+
// this.$parent && this.$parent.closeOther(this)
|
|
54
|
+
},
|
|
55
|
+
touchmove(event) {
|
|
56
|
+
// console.log(event)
|
|
57
|
+
if (this.disabled || !this.state.moving) return
|
|
58
|
+
var touches = event.touches
|
|
59
|
+
var pageX = touches[0].pageX
|
|
60
|
+
var pageY = touches[0].pageY
|
|
61
|
+
var moveX = pageX - this.state.startX
|
|
62
|
+
var moveY = pageY - this.state.startY
|
|
63
|
+
|
|
64
|
+
// 移动的X轴距离大于Y轴距离,也即终点与起点位置连线,与X轴夹角小于45度时,禁止页面滚动
|
|
65
|
+
if (Math.abs(moveX) > Math.abs(moveY) || Math.abs(moveX) > this.threshold) {
|
|
66
|
+
event.preventDefault && event.preventDefault()
|
|
67
|
+
event.stopPropagation && event.stopPropagation()
|
|
68
|
+
}
|
|
69
|
+
// 如果移动的X轴距离小于Y轴距离,也即终点位置与起点位置连线,与Y轴夹角小于45度时,认为是页面上下滑动,而不是左右滑动单元格
|
|
70
|
+
if (Math.abs(moveX) < Math.abs(moveY)) return
|
|
71
|
+
|
|
72
|
+
// 限制右滑的距离,不允许内容部分往右偏移,右滑会导致X轴偏移值大于0,以此做判断
|
|
73
|
+
// 此处不能直接return,因为滑动过程中会缺失某些关键点坐标,会导致错乱,最好的办法就是
|
|
74
|
+
// 在超出后,设置为0
|
|
75
|
+
if (this.status === 'open') {
|
|
76
|
+
// 在开启状态下,向左滑动,需忽略
|
|
77
|
+
if (moveX < 0) moveX = 0
|
|
78
|
+
// 想要收起菜单,最大能移动的距离为按钮的总宽度
|
|
79
|
+
if (moveX > this.state.buttonsWidth) moveX = this.state.buttonsWidth
|
|
80
|
+
// 如果是已经打开了的状态,向左滑动时,移动收起菜单
|
|
81
|
+
this.moveSwipeAction(-this.state.buttonsWidth + moveX)
|
|
82
|
+
} else {
|
|
83
|
+
// 关闭状态下,右滑动需忽略
|
|
84
|
+
if (moveX > 0) moveX = 0
|
|
85
|
+
// 滑动的距离不允许超过所有按钮的总宽度,此时只能是左滑,最终设置按钮的总宽度,同时为负数
|
|
86
|
+
if (Math.abs(moveX) > this.state.buttonsWidth) moveX = -this.state.buttonsWidth
|
|
87
|
+
// 只要是在滑过程中,就不断移动单元格内容部分,从而使隐藏的菜单显示出来
|
|
88
|
+
this.moveSwipeAction(moveX)
|
|
89
|
+
}
|
|
90
|
+
},
|
|
91
|
+
touchend(event) {
|
|
92
|
+
// console.log(event)
|
|
93
|
+
if (!this.state.moving || this.disabled) return
|
|
94
|
+
this.state.moving = false
|
|
95
|
+
var touches = event.changedTouches ? event.changedTouches[0] : {}
|
|
96
|
+
var pageX = touches.pageX
|
|
97
|
+
var pageY = touches.pageY
|
|
98
|
+
var moveX = pageX - this.state.startX
|
|
99
|
+
if (this.status === 'open') {
|
|
100
|
+
// 在展开的状态下,继续左滑,无需操作
|
|
101
|
+
if (moveX < 0) return
|
|
102
|
+
// 在开启状态下,点击一下内容区域,moveX为0,也即没有进行移动,这时执行收起菜单逻辑
|
|
103
|
+
if (moveX === 0) {
|
|
104
|
+
return this.closeSwipeAction()
|
|
105
|
+
}
|
|
106
|
+
// 在开启状态下,滑动距离小于阈值,则默认为不关闭,同时恢复原来的打开状态
|
|
107
|
+
if (Math.abs(moveX) < this.threshold) {
|
|
108
|
+
this.openSwipeAction()
|
|
109
|
+
} else {
|
|
110
|
+
// 如果滑动距离大于阈值,则执行收起逻辑
|
|
111
|
+
this.closeSwipeAction()
|
|
112
|
+
}
|
|
113
|
+
} else {
|
|
114
|
+
// 在关闭的状态下,右滑,无需操作
|
|
115
|
+
if (moveX > 0) return
|
|
116
|
+
// 理由同上
|
|
117
|
+
if (Math.abs(moveX) < this.threshold) {
|
|
118
|
+
this.closeSwipeAction()
|
|
119
|
+
} else {
|
|
120
|
+
this.openSwipeAction()
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
},
|
|
124
|
+
// 一次性展开滑动菜单
|
|
125
|
+
openSwipeAction() {
|
|
126
|
+
// 处理duration单位问题
|
|
127
|
+
var duration = this.getDuration(this.duration)
|
|
128
|
+
// 展开过程中,是向左移动,所以X的偏移应该为负值
|
|
129
|
+
var buttonsWidth = -this.state.buttonsWidth
|
|
130
|
+
this.sliderStyle = {
|
|
131
|
+
'transition': 'transform ' + duration,
|
|
132
|
+
'transform': 'translateX(' + buttonsWidth + 'px)',
|
|
133
|
+
'-webkit-transform': 'translateX(' + buttonsWidth + 'px)',
|
|
134
|
+
}
|
|
135
|
+
this.setStatus('open')
|
|
136
|
+
},
|
|
137
|
+
// 一次性收起滑动菜单
|
|
138
|
+
closeSwipeAction() {
|
|
139
|
+
// 处理duration单位问题
|
|
140
|
+
var duration = this.getDuration(this.duration)
|
|
141
|
+
this.sliderStyle = {
|
|
142
|
+
'transition': 'transform ' + duration,
|
|
143
|
+
'transform': 'translateX(0px)',
|
|
144
|
+
'-webkit-transform': 'translateX(0px)'
|
|
145
|
+
}
|
|
146
|
+
// 设置各个隐藏的按钮为收起的状态
|
|
147
|
+
// for (var i = this.state.buttonsWidth - 1; i >= 0; i--) {
|
|
148
|
+
// buttons[i].setStyle({
|
|
149
|
+
// 'transition': 'transform ' + duration,
|
|
150
|
+
// 'transform': 'translateX(0px)',
|
|
151
|
+
// '-webkit-transform': 'translateX(0px)'
|
|
152
|
+
// })
|
|
153
|
+
// }
|
|
154
|
+
this.setStatus('close')
|
|
155
|
+
},
|
|
156
|
+
// 移动滑动选择器内容区域,同时显示出其隐藏的菜单
|
|
157
|
+
moveSwipeAction(moveX) {
|
|
158
|
+
// 设置菜单内容部分的偏移
|
|
159
|
+
this.sliderStyle = {
|
|
160
|
+
'transition': 'none',
|
|
161
|
+
transform: 'translateX(' + moveX + 'px)',
|
|
162
|
+
'-webkit-transform': 'translateX(' + moveX + 'px)'
|
|
163
|
+
}
|
|
164
|
+
},
|
|
165
|
+
// 获取过渡时间
|
|
166
|
+
getDuration(value) {
|
|
167
|
+
if (value.toString().indexOf('s') >= 0) return value
|
|
168
|
+
return value > 30 ? value + 'ms' : value + 's'
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
<template>
|
|
1
|
+
<template>
|
|
2
|
+
<!-- #ifdef MP-ALIPAY -->
|
|
3
|
+
<!-- <import-sjs from="./alipay.sjs" name="mysjs" /> -->
|
|
4
|
+
<!-- #endif -->
|
|
2
5
|
<view class="u-swipe-action-item" ref="u-swipe-action-item">
|
|
3
6
|
<view class="u-swipe-action-item__right">
|
|
4
7
|
<slot name="button">
|
|
@@ -27,13 +30,23 @@
|
|
|
27
30
|
</view>
|
|
28
31
|
</slot>
|
|
29
32
|
</view>
|
|
30
|
-
<!-- #ifdef APP-VUE || MP-WEIXIN ||
|
|
33
|
+
<!-- #ifdef APP-VUE || MP-WEIXIN || MP-QQ || H5 -->
|
|
31
34
|
<view class="u-swipe-action-item__content" @touchstart="wxs.touchstart" @touchmove="wxs.touchmove"
|
|
32
35
|
@touchend="wxs.touchend" :status="status" :change:status="wxs.statusChange" :size="size"
|
|
33
36
|
:change:size="wxs.sizeChange">
|
|
34
37
|
<slot></slot>
|
|
35
38
|
</view>
|
|
36
39
|
<!-- #endif -->
|
|
40
|
+
<!-- #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO-->
|
|
41
|
+
<view class="u-swipe-action-item__content" @click="clickHandler" @touchstart="touchstart" @touchmove="touchmove"
|
|
42
|
+
@touchend="touchend" :style="sliderStyle">
|
|
43
|
+
<slot></slot>
|
|
44
|
+
</view>
|
|
45
|
+
<!-- <view class="u-swipe-action-item__content" @touchstart="mysjs.touchstart" @touchmove="mysjs.touchmove"
|
|
46
|
+
@touchend="mysjs.touchend">
|
|
47
|
+
<slot></slot>
|
|
48
|
+
</view> -->
|
|
49
|
+
<!-- #endif -->
|
|
37
50
|
<!-- #ifdef APP-NVUE -->
|
|
38
51
|
<view class="u-swipe-action-item__content" ref="u-swipe-action-item__content" @panstart="onTouchstart"
|
|
39
52
|
@tap="clickHandler">
|
|
@@ -42,7 +55,7 @@
|
|
|
42
55
|
<!-- #endif -->
|
|
43
56
|
</view>
|
|
44
57
|
</template>
|
|
45
|
-
<!-- #ifdef APP-VUE || MP-WEIXIN ||
|
|
58
|
+
<!-- #ifdef APP-VUE || MP-WEIXIN || MP-QQ || H5 -->
|
|
46
59
|
<script src="./index.wxs" module="wxs" lang="wxs"></script>
|
|
47
60
|
<!-- #endif -->
|
|
48
61
|
<script>
|
|
@@ -53,9 +66,12 @@
|
|
|
53
66
|
// #ifdef APP-NVUE
|
|
54
67
|
import nvue from './nvue.js';
|
|
55
68
|
// #endif
|
|
56
|
-
// #ifdef APP-VUE || MP-WEIXIN ||
|
|
69
|
+
// #ifdef APP-VUE || MP-WEIXIN || MP-QQ || H5
|
|
57
70
|
import wxs from './wxs.js';
|
|
58
71
|
// #endif
|
|
72
|
+
// #ifdef MP-ALIPAY || MP-BAIDU || MP-TOUTIAO
|
|
73
|
+
import other from './other.js';
|
|
74
|
+
// #endif
|
|
59
75
|
/**
|
|
60
76
|
* SwipeActionItem 滑动单元格子组件
|
|
61
77
|
* @description 该组件一般用于左滑唤出操作菜单的场景,用的最多的是左滑删除操作
|
|
@@ -74,15 +90,8 @@
|
|
|
74
90
|
export default {
|
|
75
91
|
name: 'u-swipe-action-item',
|
|
76
92
|
emits: ['click'],
|
|
77
|
-
|
|
78
|
-
mixins: [
|
|
79
|
-
// #endif
|
|
80
|
-
// #ifdef APP-NVUE
|
|
81
|
-
mixins: [mpMixin, mixin, props, nvue, touch],
|
|
82
|
-
// #endif
|
|
83
|
-
// #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ
|
|
84
|
-
mixins: [mpMixin, mixin, props, touch, wxs],
|
|
85
|
-
// #endif
|
|
93
|
+
|
|
94
|
+
mixins: [
|
|
86
95
|
data() {
|
|
87
96
|
return {
|
|
88
97
|
// 按钮的尺寸信息
|
|
@@ -93,13 +102,16 @@
|
|
|
93
102
|
},
|
|
94
103
|
// 当前状态,open-打开,close-关闭
|
|
95
104
|
status: 'close',
|
|
105
|
+
sliderStyle: {}
|
|
96
106
|
}
|
|
97
107
|
},
|
|
98
108
|
watch: {
|
|
99
109
|
// 由于wxs无法直接读取外部的值,需要在外部值变化时,重新执行赋值逻辑
|
|
110
|
+
// #ifndef APP-NVUE
|
|
100
111
|
wxsInit(newValue, oldValue) {
|
|
101
112
|
this.queryRect()
|
|
102
113
|
}
|
|
114
|
+
// #endif
|
|
103
115
|
},
|
|
104
116
|
computed: {
|
|
105
117
|
wxsInit() {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
></u-icon>
|
|
23
23
|
</view>
|
|
24
24
|
<u-link
|
|
25
|
-
v-if="mode === 'link'"
|
|
26
|
-
:
|
|
25
|
+
v-if="mode === 'link'"
|
|
26
|
+
:style="{fontWeight: valueStyle.fontWeight, wordWrap: valueStyle.wordWrap, fontSize: valueStyle.fontSize}"
|
|
27
27
|
:href="href"
|
|
28
28
|
underLine
|
|
29
29
|
></u-link>
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
@confirm="onConfirm"
|
|
30
30
|
@keyboardheightchange="onKeyboardheightchange"
|
|
31
31
|
></textarea>
|
|
32
|
+
<!-- #ifndef MP-ALIPAY -->
|
|
32
33
|
<text
|
|
33
34
|
class="u-textarea__count"
|
|
34
35
|
:style="{
|
|
@@ -37,6 +38,7 @@
|
|
|
37
38
|
v-if="count"
|
|
38
39
|
>{{ innerValue.length }}/{{ maxlength }}</text
|
|
39
40
|
>
|
|
41
|
+
<!-- #endif -->
|
|
40
42
|
</view>
|
|
41
43
|
</template>
|
|
42
44
|
|