Skip to content

Commit 42b1900

Browse files
committed
fix(uni-ui):swipe-action 新增bindxing
1 parent 58b1987 commit 42b1900

5 files changed

Lines changed: 276 additions & 21 deletions

File tree

‎components/uni-list/uni-list.vue‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,9 @@
5252
background-color: #ffffff;
5353
position: relative;
5454
flex-direction: column;
55-
/* border-bottom-color: $uni-border-color;
56-
*/
57-
/* border-bottom-style: solid;
58-
*/
59-
/* border-bottom-width: 1px;
60-
*/
55+
/* border-bottom-color: $uni-border-color; */
56+
/* border-bottom-style: solid; */
57+
/* border-bottom-width: 1px; */
6158
}
6259
6360
/* #ifndef APP-NVUE */
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
const BindingX = weex.requireModule('bindingx');
2+
const dom = weex.requireModule('dom');
3+
const animation = weex.requireModule('animation');
4+
5+
export default {
6+
data() {
7+
return {
8+
right: 0,
9+
button: [],
10+
preventGesture: false
11+
}
12+
},
13+
mounted() {
14+
this.boxSelector = this.getEl(this.$refs['selector-box-hock']);
15+
this.selector = this.getEl(this.$refs['selector-content-hock']);
16+
this.buttonSelector = this.getEl(this.$refs['selector-button-hock']);
17+
this.position = {}
18+
this.x = 0
19+
setTimeout(() => {
20+
this.getSelectorQuery()
21+
}, 200)
22+
},
23+
beforeDestoy() {
24+
BindingX.unbind({
25+
token: this.timing.token,
26+
eventType: 'timing'
27+
})
28+
BindingX.unbind({
29+
token: this.pan.token,
30+
eventType: 'pan'
31+
})
32+
},
33+
watch: {
34+
show(newVal) {
35+
if (!this.position || JSON.stringify(this.position) === '{}') return;
36+
if (this.autoClose) return
37+
if (this.isInAnimation) return
38+
if (newVal) {
39+
this.open()
40+
} else {
41+
this.close()
42+
}
43+
},
44+
},
45+
methods: {
46+
onClick(index, item) {
47+
this.$emit('click', {
48+
content: item,
49+
index
50+
})
51+
},
52+
touchstart(e) {
53+
if (this.isInAnimation) return
54+
if (this.stop) return
55+
this.stop = true
56+
let endWidth = this.right
57+
let boxStep = `(x+${this.x})`
58+
let pageX = `${boxStep}> ${-endWidth} && ${boxStep} < 0?${boxStep}:(x+${this.x} < 0? ${-endWidth}:0)`
59+
60+
let props = [{
61+
element: this.selector,
62+
property: 'transform.translateX',
63+
expression: pageX
64+
}]
65+
66+
let left = 0
67+
for (let i = 0; i < this.options.length; i++) {
68+
let buttonSelectors = this.getEl(this.$refs['button-hock'][i]);
69+
if (this.button.length === 0 || !this.button[i] || !this.button[i].width) return
70+
let moveMix = endWidth - left
71+
left += this.button[i].width
72+
let step = `(${this.x}+x)/${endWidth}`
73+
let moveX = `(${step}) * ${moveMix}`
74+
let pageButtonX = `${moveX}&& (x+${this.x} > ${-endWidth})?${moveX}:${-moveMix}`
75+
props.push({
76+
element: buttonSelectors,
77+
property: 'transform.translateX',
78+
expression: pageButtonX
79+
})
80+
}
81+
82+
this.eventpan = this._bind(this.boxSelector, props, 'pan', (e) => {
83+
if (e.state === 'end') {
84+
this.x = e.deltaX + this.x;
85+
if (this.x < -endWidth) {
86+
this.x = -endWidth
87+
}
88+
if (this.x > 0) {
89+
this.x = 0
90+
}
91+
this.stop = false
92+
this.bindTiming();
93+
}
94+
})
95+
},
96+
touchend(e) {
97+
this.$nextTick(() => {
98+
if (this.isopen && !this.isDrag && !this.isInAnimation) {
99+
this.close()
100+
}
101+
})
102+
},
103+
bindTiming() {
104+
if (this.isopen) {
105+
this.move(this.x, -this.right)
106+
} else {
107+
this.move(this.x, -40)
108+
}
109+
},
110+
move(left, value) {
111+
if (left >= value) {
112+
this.close()
113+
} else {
114+
this.open()
115+
}
116+
},
117+
/**
118+
* 开启swipe
119+
*/
120+
open() {
121+
this.animation(true)
122+
},
123+
/**
124+
* 关闭swipe
125+
*/
126+
close() {
127+
this.animation(false)
128+
},
129+
/**
130+
* 开启关闭动画
131+
* @param {Object} type
132+
*/
133+
animation(type) {
134+
this.isDrag = true
135+
let endWidth = this.right
136+
let time = 200
137+
this.isInAnimation = true;
138+
139+
let exit = `t>${time}`;
140+
let translate_x_expression = `easeOutExpo(t,${this.x},${type?(-endWidth-this.x):(-this.x)},${time})`
141+
let props = [{
142+
element: this.selector,
143+
property: 'transform.translateX',
144+
expression: translate_x_expression
145+
}]
146+
147+
let left = 0
148+
for (let i = 0; i < this.options.length; i++) {
149+
let buttonSelectors = this.getEl(this.$refs['button-hock'][i]);
150+
if (this.button.length === 0 || !this.button[i] || !this.button[i].width) return
151+
let moveMix = endWidth - left
152+
left += this.button[i].width
153+
let step = `${this.x}/${endWidth}`
154+
let moveX = `(${step}) * ${moveMix}`
155+
let pageButtonX = `easeOutExpo(t,${moveX},${type ? -moveMix + '-' + moveX: 0 + '-' + moveX},${time})`
156+
props.push({
157+
element: buttonSelectors,
158+
property: 'transform.translateX',
159+
expression: pageButtonX
160+
})
161+
}
162+
163+
this.timing = BindingX.bind({
164+
eventType: 'timing',
165+
exitExpression: exit,
166+
props: props
167+
}, (e) => {
168+
if (e.state === 'end' || e.state === 'exit') {
169+
this.x = type ? -endWidth : 0
170+
this.isInAnimation = false;
171+
this.isopen = type
172+
this.isDrag = false
173+
this.$emit('change', type)
174+
}
175+
});
176+
},
177+
/**
178+
* 绑定 BindingX
179+
* @param {Object} anchor
180+
* @param {Object} props
181+
* @param {Object} fn
182+
*/
183+
_bind(anchor, props, eventType, fn) {
184+
return BindingX.bind({
185+
anchor,
186+
eventType,
187+
props
188+
}, (e) => {
189+
typeof(fn) === 'function' && fn(e)
190+
});
191+
},
192+
/**
193+
* 获取ref
194+
* @param {Object} el
195+
*/
196+
getEl(el) {
197+
return el.ref
198+
},
199+
/**
200+
* 获取节点信息
201+
*/
202+
getSelectorQuery() {
203+
dom.getComponentRect(this.$refs['selector-content-hock'], (data) => {
204+
if (this.position.content) return
205+
this.position.content = data.size
206+
})
207+
for (let i = 0; i < this.options.length; i++) {
208+
dom.getComponentRect(this.$refs['button-hock'][i], (data) => {
209+
if (!this.button) {
210+
this.button = []
211+
}
212+
if (this.options.length === this.button.length) return
213+
this.button.push(data.size)
214+
this.right += data.size.width
215+
if (this.autoClose) return
216+
if (this.show) {
217+
this.open()
218+
}
219+
})
220+
}
221+
}
222+
}
223+
}

‎components/uni-swipe-action/uni-swipe-action.vue‎

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<template>
22
<view class="uni-swipe">
3-
<!-- #ifndef APP-VUE|| MP-WEIXIN||H5 -->
3+
<!-- #ifndef APP-PLUS || MP-WEIXIN || H5 -->
44
<view class="uni-swipe_content">
55
<view ref="selector-button-hock" class="uni-swipe_button-group selector-query-hock move-hock">
66
<view v-for="(item,index) in options" :data-button="btn" :key="index" :style="{
@@ -32,21 +32,47 @@
3232
</view>
3333
</view>
3434
<!-- #endif -->
35+
<!-- #ifdef APP-NVUE -->
36+
<view ref="selector-box-hock" class="uni-swipe_content" @horizontalpan="touchstart" @touchend="touchend">
37+
<view ref="selector-button-hock" class="uni-swipe_button-group selector-query-hock move-hock" :style="{width:right+'px'}">
38+
<view ref="button-hock" v-for="(item,index) in options" :key="index" :style="{
39+
backgroundColor: item.style && item.style.backgroundColor ? item.style.backgroundColor : '#C7C6CD',
40+
fontSize: item.style && item.style.fontSize ? item.style.fontSize : '16px',left: right+'px'
41+
}" class="uni-swipe_button " @click.stop="onClick(index,item)"><text class="uni-swipe_button-text" :style="{color: item.style && item.style.color ? item.style.color : '#FFFFFF',}">{{ item.text }}</text></view>
42+
</view>
43+
<view ref='selector-content-hock' class="uni-swipe_move-box selector-query-hock">
44+
<view class="uni-swipe_box">
45+
<slot />
46+
</view>
47+
</view>
48+
49+
</view>
50+
<!-- #endif -->
3551

3652
</view>
3753
</template>
3854
<script src="./index.wxs" module="swipe" lang="wxs"></script>
3955
<script>
56+
// #ifndef APP-PLUS|| MP-WEIXIN || H5
4057
import mixins from './mpother'
58+
// #endif
59+
// #ifdef APP-VUE|| MP-WEIXIN||H5
4160
import mp from './mp'
42-
61+
// #endif
62+
// #ifdef APP-NVUE
63+
import bindingx from './bindingx.js'
64+
// #endif
4365
export default {
4466
// #ifdef APP-VUE|| MP-WEIXIN||H5
4567
mixins: [mp],
4668
// #endif
47-
// #ifndef APP-VUE|| MP-WEIXIN||H5
69+
// #ifdef APP-NVUE
70+
mixins: [bindingx],
71+
// #endif
72+
// #ifndef APP-PLUS|| MP-WEIXIN || H5
4873
mixins: [mixins],
4974
// #endif
75+
5076
props: {
5177
/**
5278
* 按钮内容
@@ -92,7 +118,7 @@
92118
}
93119
94120
.uni-swipe_move-box {
95-
/* #ifndef APP-NUVE */
121+
/* #ifndef APP-NVUE */
96122
display: flex;
97123
/* #endif */
98124
position: relative;
@@ -119,15 +145,21 @@
119145
bottom: 0;
120146
z-index: 0;
121147
/* #endif */
122-
/* #ifndef APP-NUVE */
148+
/* #ifndef APP-NVUE */
123149
display: flex;
124150
flex-shrink: 0;
125151
/* #endif */
126152
flex-direction: row;
127153
}
128154
129155
.uni-swipe_button {
130-
/* #ifndef APP-NUVE */
156+
/* #ifdef APP-NVUE */
157+
position: absolute;
158+
left: 0;
159+
top: 0;
160+
bottom: 0;
161+
/* #endif */
162+
/* #ifndef APP-NVUE */
131163
display: flex;
132164
/* #endif */
133165
flex-direction: row;

pages/extUI/swipe-action/swipe-action.vue renamed to pages/extUI/swipe-action/swipe-action.nvue

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<template>
22
<view>
33
<uni-section title="基本用法" type="line"></uni-section>
4-
<uni-swipe-action :options="options2" @click="bindClick">
4+
<uni-swipe-action :options="options1" @click="bindClick">
55
<text class="cont">SwipeAction 基础使用场景</text>
66
</uni-swipe-action>
77
<uni-section title="禁止滑动" type="line"></uni-section>
@@ -15,18 +15,18 @@
1515
<uni-swipe-action :options="options2" :show="isOpened" :auto-close="false" @change="change">
1616
<text class="cont">使用变量控制SwipeAction的开启状态</text>
1717
</uni-swipe-action>
18-
<uni-section title="与 List 组件一起使用" type="line"></uni-section>
19-
<uni-list>
18+
<uni-section title="swipe-action 列表" type="line"></uni-section>
19+
<view>
2020
<uni-swipe-action :options="options1">
21-
<uni-list-item :show-arrow="false" title="item1" />
21+
<text class="cont">item1</text>
2222
</uni-swipe-action>
2323
<uni-swipe-action :options="options2">
24-
<uni-list-item :show-arrow="false" title="item2" />
24+
<text class="cont">item2</text>
2525
</uni-swipe-action>
2626
<uni-swipe-action :options="options3">
27-
<uni-list-item :show-arrow="false" title="item3" />
27+
<text class="cont">item3</text>
2828
</uni-swipe-action>
29-
</uni-list>
29+
</view>
3030
</view>
3131
</template>
3232

@@ -192,23 +192,26 @@
192192
background-color: #4ca2ff;
193193
}
194194

195-
196195
.cont {
197196
height: 45px;
198197
line-height: 45px;
199198
padding: 0 15px;
200199
position: relative;
201200
background-color: #fff;
202201
font-size: 15px;
202+
border-bottom-color: #F5F5F5;
203+
border-bottom-width: 1px;
204+
border-bottom-style: solid;
203205
}
204206

205207
.example-body {
206-
/* #ifndef APP-NUVE */
208+
/* #ifndef APP-NVUE */
207209
display: flex;
208210
/* #endif */
209211
flex-direction: row;
210212
justify-content: center;
211213
padding: 10px 0;
214+
background-color: #fff;
212215
}
213216

214217
.button {

0 commit comments

Comments
 (0)