uview-plus 3.1.40 → 3.1.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.
- package/changelog.md +7 -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 +11 -11
- package/components/u-code/u-code.vue +3 -3
- package/components/u-collapse-item/u-collapse-item.vue +1 -1
- package/components/u-index-list/u-index-list.vue +4 -4
- package/components/u-input/u-input.vue +1 -0
- 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 +24 -5
- package/components/u-textarea/u-textarea.vue +2 -0
- package/package.json +1 -1
package/changelog.md
CHANGED
|
@@ -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
|
},
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
@tap="clickHandler">
|
|
5
5
|
<view class="u-cell__body" :class="[ center && 'u-cell--center', size === 'large' && 'u-cell__body--large']">
|
|
6
6
|
<view class="u-cell__body__content">
|
|
7
|
-
<view class="u-cell__left-icon-wrap">
|
|
8
|
-
<slot name="icon">
|
|
9
|
-
<u-icon v-if="icon" :name="icon"
|
|
10
|
-
:custom-style="iconStyle"
|
|
11
|
-
:size="size === 'large' ? 22 : 18"></u-icon>
|
|
7
|
+
<view class="u-cell__left-icon-wrap" v-if="$slots.icon || icon">
|
|
8
|
+
<slot name="icon" v-if="$slots.icon">
|
|
12
9
|
</slot>
|
|
10
|
+
<u-icon v-else :name="icon"
|
|
11
|
+
:custom-style="iconStyle"
|
|
12
|
+
:size="size === 'large' ? 22 : 18"></u-icon>
|
|
13
13
|
</view>
|
|
14
14
|
<view class="u-cell__title">
|
|
15
15
|
<slot name="title">
|
|
@@ -27,12 +27,12 @@
|
|
|
27
27
|
:class="[disabled && 'u-cell--disabled', size === 'large' && 'u-cell__value--large']"
|
|
28
28
|
v-if="!$u.test.empty(value)">{{ value }}</text>
|
|
29
29
|
</slot>
|
|
30
|
-
<view class="u-cell__right-icon-wrap"
|
|
30
|
+
<view class="u-cell__right-icon-wrap" v-if="$slots['right-icon'] || isLink"
|
|
31
31
|
:class="[`u-cell__right-icon-wrap--${arrowDirection}`]">
|
|
32
|
-
<slot name="right-icon">
|
|
33
|
-
<u-icon v-if="isLink" :name="rightIcon" :custom-style="rightIconStyle" :color="disabled ? '#c8c9cc' : 'info'"
|
|
34
|
-
:size="size === 'large' ? 18 : 16"></u-icon>
|
|
32
|
+
<slot name="right-icon" v-if="$slots['right-icon']">
|
|
35
33
|
</slot>
|
|
34
|
+
<u-icon v-else :name="rightIcon" :custom-style="rightIconStyle" :color="disabled ? '#c8c9cc' : 'info'"
|
|
35
|
+
:size="size === 'large' ? 18 : 16"></u-icon>
|
|
36
36
|
</view>
|
|
37
37
|
</view>
|
|
38
38
|
<u-line v-if="border"></u-line>
|
|
@@ -145,7 +145,7 @@
|
|
|
145
145
|
&__content {
|
|
146
146
|
@include flex(row);
|
|
147
147
|
align-items: center;
|
|
148
|
-
flex: 1;
|
|
148
|
+
flex: 1 0 1;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
151
|
&--large {
|
|
@@ -207,10 +207,10 @@
|
|
|
207
207
|
|
|
208
208
|
&__value {
|
|
209
209
|
text-align: right;
|
|
210
|
+
margin-left: auto;
|
|
210
211
|
font-size: $u-cell-value-font-size;
|
|
211
212
|
line-height: $u-cell-line-height;
|
|
212
213
|
color: $u-cell-value-color;
|
|
213
|
-
|
|
214
214
|
&--large {
|
|
215
215
|
font-size: $u-cell-value-font-size-large;
|
|
216
216
|
}
|
|
@@ -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) {
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
:arrowDirection="expanded ? 'up' : 'down'"
|
|
13
13
|
:disabled="disabled"
|
|
14
14
|
>
|
|
15
|
-
<!-- #ifndef MP-WEIXIN -->
|
|
15
|
+
<!-- #ifndef MP-WEIXIN || MP-ALIPAY -->
|
|
16
16
|
<!-- 微信小程序不支持,因为微信中不支持 <slot name="title" slot="title" />的写法 -->
|
|
17
17
|
<template #title>
|
|
18
18
|
<slot name="title"></slot>
|
|
@@ -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"
|
|
@@ -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__button");
|
|
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 -->
|
|
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 || H5 -->
|
|
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 || H5
|
|
73
|
+
import other from './other.js';
|
|
74
|
+
// #endif
|
|
59
75
|
/**
|
|
60
76
|
* SwipeActionItem 滑动单元格子组件
|
|
61
77
|
* @description 该组件一般用于左滑唤出操作菜单的场景,用的最多的是左滑删除操作
|
|
@@ -81,7 +97,7 @@
|
|
|
81
97
|
mixins: [mpMixin, mixin, props, nvue, touch],
|
|
82
98
|
// #endif
|
|
83
99
|
// #ifdef APP-VUE || MP-WEIXIN || H5 || MP-QQ
|
|
84
|
-
mixins: [mpMixin, mixin, props, touch, wxs],
|
|
100
|
+
mixins: [mpMixin, mixin, props, touch, wxs, other],
|
|
85
101
|
// #endif
|
|
86
102
|
data() {
|
|
87
103
|
return {
|
|
@@ -93,13 +109,16 @@
|
|
|
93
109
|
},
|
|
94
110
|
// 当前状态,open-打开,close-关闭
|
|
95
111
|
status: 'close',
|
|
112
|
+
sliderStyle: {}
|
|
96
113
|
}
|
|
97
114
|
},
|
|
98
115
|
watch: {
|
|
99
116
|
// 由于wxs无法直接读取外部的值,需要在外部值变化时,重新执行赋值逻辑
|
|
117
|
+
// #ifndef APP-NVUE
|
|
100
118
|
wxsInit(newValue, oldValue) {
|
|
101
119
|
this.queryRect()
|
|
102
120
|
}
|
|
121
|
+
// #endif
|
|
103
122
|
},
|
|
104
123
|
computed: {
|
|
105
124
|
wxsInit() {
|
|
@@ -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
|
|