@vtj/materials 0.10.1-alpha.0 → 0.10.1-alpha.2
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/dist/assets/antdv/index.umd.js +2 -2
- package/dist/assets/charts/index.umd.js +2 -2
- package/dist/assets/element/index.umd.js +2 -2
- package/dist/assets/ui/index.umd.js +2 -2
- package/dist/assets/uni-h5/index.umd.js +3 -3
- package/dist/assets/uni-ui/index.umd.js +7 -0
- package/dist/assets/vant/index.umd.js +2 -2
- package/dist/deps/@vtj/charts/index.umd.js +2 -2
- package/dist/deps/@vtj/icons/index.umd.js +2 -2
- package/dist/deps/@vtj/ui/index.umd.js +2 -2
- package/dist/deps/@vtj/uni/index.umd.js +3 -3
- package/dist/deps/@vtj/utils/index.umd.js +2 -2
- package/dist/deps/mockjs/mock-min.js +10 -0
- package/dist/deps/uni-ui/index.umd.js +1 -0
- package/dist/deps/uni-ui/style.css +1 -0
- package/package.json +9 -6
- package/src/env.d.ts +7 -0
- package/src/uni-h5/components/index.ts +43 -2
- package/src/uni-ui/components/badge.ts +73 -0
- package/src/uni-ui/components/index.ts +30 -0
- package/src/uni-ui/index.ts +213 -0
- package/src/uni-ui/lib/uni-datetime-picker/calendar-item.vue +177 -0
- package/src/uni-ui/lib/uni-datetime-picker/calendar.vue +947 -0
- package/src/uni-ui/lib/uni-datetime-picker/i18n/en.json +22 -0
- package/src/uni-ui/lib/uni-datetime-picker/i18n/index.js +8 -0
- package/src/uni-ui/lib/uni-datetime-picker/i18n/zh-Hans.json +22 -0
- package/src/uni-ui/lib/uni-datetime-picker/i18n/zh-Hant.json +22 -0
- package/src/uni-ui/lib/uni-datetime-picker/time-picker.vue +940 -0
- package/src/uni-ui/lib/uni-datetime-picker/uni-datetime-picker.vue +1232 -0
- package/src/uni-ui/lib/uni-datetime-picker/util.js +421 -0
- package/src/uni-ui/lib/uni-forms/uni-forms.vue +416 -0
- package/src/uni-ui/lib/uni-forms/utils.js +293 -0
- package/src/uni-ui/lib/uni-forms/validate.js +486 -0
- package/src/uni-ui/lib/uni-popup/i18n/en.json +7 -0
- package/src/uni-ui/lib/uni-popup/i18n/index.js +8 -0
- package/src/uni-ui/lib/uni-popup/i18n/zh-Hans.json +7 -0
- package/src/uni-ui/lib/uni-popup/i18n/zh-Hant.json +7 -0
- package/src/uni-ui/lib/uni-popup/keypress.js +45 -0
- package/src/uni-ui/lib/uni-popup/popup.js +26 -0
- package/src/uni-ui/lib/uni-popup/uni-popup.uvue +90 -0
- package/src/uni-ui/lib/uni-popup/uni-popup.vue +552 -0
- package/src/uni-ui/lib/uni-swipe-action-item/bindingx.js +302 -0
- package/src/uni-ui/lib/uni-swipe-action-item/isPC.js +12 -0
- package/src/uni-ui/lib/uni-swipe-action-item/mpalipay.js +195 -0
- package/src/uni-ui/lib/uni-swipe-action-item/mpother.js +260 -0
- package/src/uni-ui/lib/uni-swipe-action-item/mpwxs.js +84 -0
- package/src/uni-ui/lib/uni-swipe-action-item/render.js +270 -0
- package/src/uni-ui/lib/uni-swipe-action-item/uni-swipe-action-item.vue +494 -0
- package/src/uni-ui/lib/uni-swipe-action-item/wx.wxs +341 -0
- package/src/uni-ui/lib/uni-th/filter-dropdown.vue +511 -0
- package/src/uni-ui/lib/uni-th/uni-th.vue +295 -0
- package/src/uni-ui/lib/uni-tr/table-checkbox.vue +179 -0
- package/src/uni-ui/lib/uni-tr/uni-tr.vue +184 -0
- package/src/uni-ui/lib/uni.scss +76 -0
- package/src/uni-ui/polyfill.ts +41 -0
- package/src/version.ts +2 -2
@@ -0,0 +1,260 @@
|
|
1
|
+
let otherMixins = {}
|
2
|
+
|
3
|
+
// #ifndef APP-PLUS|| MP-WEIXIN || H5
|
4
|
+
const MIN_DISTANCE = 10;
|
5
|
+
otherMixins = {
|
6
|
+
data() {
|
7
|
+
// TODO 随机生生元素ID,解决百度小程序获取同一个元素位置信息的bug
|
8
|
+
const elClass = `Uni_${Math.ceil(Math.random() * 10e5).toString(36)}`
|
9
|
+
return {
|
10
|
+
uniShow: false,
|
11
|
+
left: 0,
|
12
|
+
buttonShow: 'none',
|
13
|
+
ani: false,
|
14
|
+
moveLeft: '',
|
15
|
+
elClass
|
16
|
+
}
|
17
|
+
},
|
18
|
+
watch: {
|
19
|
+
show(newVal) {
|
20
|
+
if (this.autoClose) return
|
21
|
+
this.openState(newVal)
|
22
|
+
},
|
23
|
+
left() {
|
24
|
+
this.moveLeft = `translateX(${this.left}px)`
|
25
|
+
},
|
26
|
+
buttonShow(newVal) {
|
27
|
+
if (this.autoClose) return
|
28
|
+
this.openState(newVal)
|
29
|
+
},
|
30
|
+
leftOptions() {
|
31
|
+
this.init()
|
32
|
+
},
|
33
|
+
rightOptions() {
|
34
|
+
this.init()
|
35
|
+
}
|
36
|
+
},
|
37
|
+
mounted() {
|
38
|
+
this.swipeaction = this.getSwipeAction()
|
39
|
+
if (this.swipeaction && Array.isArray(this.swipeaction.children)) {
|
40
|
+
this.swipeaction.children.push(this)
|
41
|
+
}
|
42
|
+
this.init()
|
43
|
+
},
|
44
|
+
methods: {
|
45
|
+
init() {
|
46
|
+
clearTimeout(this.timer)
|
47
|
+
this.timer = setTimeout(() => {
|
48
|
+
this.getSelectorQuery()
|
49
|
+
}, 100)
|
50
|
+
// 移动距离
|
51
|
+
this.left = 0
|
52
|
+
this.x = 0
|
53
|
+
},
|
54
|
+
|
55
|
+
closeSwipe(e) {
|
56
|
+
if (this.autoClose && this.swipeaction) {
|
57
|
+
this.swipeaction.closeOther(this)
|
58
|
+
}
|
59
|
+
},
|
60
|
+
appTouchStart(e) {
|
61
|
+
const {
|
62
|
+
clientX
|
63
|
+
} = e.changedTouches[0]
|
64
|
+
this.clientX = clientX
|
65
|
+
this.timestamp = new Date().getTime()
|
66
|
+
},
|
67
|
+
appTouchEnd(e, index, item, position) {
|
68
|
+
const {
|
69
|
+
clientX
|
70
|
+
} = e.changedTouches[0]
|
71
|
+
// fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
|
72
|
+
let diff = Math.abs(this.clientX - clientX)
|
73
|
+
let time = (new Date().getTime()) - this.timestamp
|
74
|
+
if (diff < 40 && time < 300) {
|
75
|
+
this.$emit('click', {
|
76
|
+
content: item,
|
77
|
+
index,
|
78
|
+
position
|
79
|
+
})
|
80
|
+
}
|
81
|
+
},
|
82
|
+
touchstart(e) {
|
83
|
+
if (this.disabled) return
|
84
|
+
this.ani = false
|
85
|
+
this.x = this.left || 0
|
86
|
+
this.stopTouchStart(e)
|
87
|
+
this.autoClose && this.closeSwipe()
|
88
|
+
},
|
89
|
+
touchmove(e) {
|
90
|
+
if (this.disabled) return
|
91
|
+
// 是否可以滑动页面
|
92
|
+
this.stopTouchMove(e);
|
93
|
+
if (this.direction !== 'horizontal') {
|
94
|
+
return;
|
95
|
+
}
|
96
|
+
this.move(this.x + this.deltaX)
|
97
|
+
return false
|
98
|
+
},
|
99
|
+
touchend() {
|
100
|
+
if (this.disabled) return
|
101
|
+
this.moveDirection(this.left)
|
102
|
+
},
|
103
|
+
/**
|
104
|
+
* 设置移动距离
|
105
|
+
* @param {Object} value
|
106
|
+
*/
|
107
|
+
move(value) {
|
108
|
+
value = value || 0
|
109
|
+
const leftWidth = this.leftWidth
|
110
|
+
const rightWidth = this.rightWidth
|
111
|
+
// 获取可滑动范围
|
112
|
+
this.left = this.range(value, -rightWidth, leftWidth);
|
113
|
+
},
|
114
|
+
|
115
|
+
/**
|
116
|
+
* 获取范围
|
117
|
+
* @param {Object} num
|
118
|
+
* @param {Object} min
|
119
|
+
* @param {Object} max
|
120
|
+
*/
|
121
|
+
range(num, min, max) {
|
122
|
+
return Math.min(Math.max(num, min), max);
|
123
|
+
},
|
124
|
+
/**
|
125
|
+
* 移动方向判断
|
126
|
+
* @param {Object} left
|
127
|
+
* @param {Object} value
|
128
|
+
*/
|
129
|
+
moveDirection(left) {
|
130
|
+
const threshold = this.threshold
|
131
|
+
const isopen = this.isopen || 'none'
|
132
|
+
const leftWidth = this.leftWidth
|
133
|
+
const rightWidth = this.rightWidth
|
134
|
+
if (this.deltaX === 0) {
|
135
|
+
this.openState('none')
|
136
|
+
return
|
137
|
+
}
|
138
|
+
if ((isopen === 'none' && rightWidth > 0 && -left > threshold) || (isopen !== 'none' && rightWidth >
|
139
|
+
0 && rightWidth +
|
140
|
+
left < threshold)) {
|
141
|
+
// right
|
142
|
+
this.openState('right')
|
143
|
+
} else if ((isopen === 'none' && leftWidth > 0 && left > threshold) || (isopen !== 'none' && leftWidth >
|
144
|
+
0 &&
|
145
|
+
leftWidth - left < threshold)) {
|
146
|
+
// left
|
147
|
+
this.openState('left')
|
148
|
+
} else {
|
149
|
+
// default
|
150
|
+
this.openState('none')
|
151
|
+
}
|
152
|
+
},
|
153
|
+
|
154
|
+
/**
|
155
|
+
* 开启状态
|
156
|
+
* @param {Boolean} type
|
157
|
+
*/
|
158
|
+
openState(type) {
|
159
|
+
const leftWidth = this.leftWidth
|
160
|
+
const rightWidth = this.rightWidth
|
161
|
+
let left = ''
|
162
|
+
this.isopen = this.isopen ? this.isopen : 'none'
|
163
|
+
switch (type) {
|
164
|
+
case "left":
|
165
|
+
left = leftWidth
|
166
|
+
break
|
167
|
+
case "right":
|
168
|
+
left = -rightWidth
|
169
|
+
break
|
170
|
+
default:
|
171
|
+
left = 0
|
172
|
+
}
|
173
|
+
|
174
|
+
|
175
|
+
if (this.isopen !== type) {
|
176
|
+
this.throttle = true
|
177
|
+
this.$emit('change', type)
|
178
|
+
}
|
179
|
+
|
180
|
+
this.isopen = type
|
181
|
+
// 添加动画类
|
182
|
+
this.ani = true
|
183
|
+
this.$nextTick(() => {
|
184
|
+
this.move(left)
|
185
|
+
})
|
186
|
+
// 设置最终移动位置,理论上只要进入到这个函数,肯定是要打开的
|
187
|
+
},
|
188
|
+
close() {
|
189
|
+
this.openState('none')
|
190
|
+
},
|
191
|
+
getDirection(x, y) {
|
192
|
+
if (x > y && x > MIN_DISTANCE) {
|
193
|
+
return 'horizontal';
|
194
|
+
}
|
195
|
+
if (y > x && y > MIN_DISTANCE) {
|
196
|
+
return 'vertical';
|
197
|
+
}
|
198
|
+
return '';
|
199
|
+
},
|
200
|
+
|
201
|
+
/**
|
202
|
+
* 重置滑动状态
|
203
|
+
* @param {Object} event
|
204
|
+
*/
|
205
|
+
resetTouchStatus() {
|
206
|
+
this.direction = '';
|
207
|
+
this.deltaX = 0;
|
208
|
+
this.deltaY = 0;
|
209
|
+
this.offsetX = 0;
|
210
|
+
this.offsetY = 0;
|
211
|
+
},
|
212
|
+
|
213
|
+
/**
|
214
|
+
* 设置滑动开始位置
|
215
|
+
* @param {Object} event
|
216
|
+
*/
|
217
|
+
stopTouchStart(event) {
|
218
|
+
this.resetTouchStatus();
|
219
|
+
const touch = event.touches[0];
|
220
|
+
this.startX = touch.clientX;
|
221
|
+
this.startY = touch.clientY;
|
222
|
+
},
|
223
|
+
|
224
|
+
/**
|
225
|
+
* 滑动中,是否禁止打开
|
226
|
+
* @param {Object} event
|
227
|
+
*/
|
228
|
+
stopTouchMove(event) {
|
229
|
+
const touch = event.touches[0];
|
230
|
+
this.deltaX = touch.clientX - this.startX;
|
231
|
+
this.deltaY = touch.clientY - this.startY;
|
232
|
+
this.offsetX = Math.abs(this.deltaX);
|
233
|
+
this.offsetY = Math.abs(this.deltaY);
|
234
|
+
this.direction = this.direction || this.getDirection(this.offsetX, this.offsetY);
|
235
|
+
},
|
236
|
+
|
237
|
+
getSelectorQuery() {
|
238
|
+
const views = uni.createSelectorQuery().in(this)
|
239
|
+
views
|
240
|
+
.selectAll('.' + this.elClass)
|
241
|
+
.boundingClientRect(data => {
|
242
|
+
if (data.length === 0) return
|
243
|
+
let show = 'none'
|
244
|
+
if (this.autoClose) {
|
245
|
+
show = 'none'
|
246
|
+
} else {
|
247
|
+
show = this.show
|
248
|
+
}
|
249
|
+
this.leftWidth = data[0].width || 0
|
250
|
+
this.rightWidth = data[1].width || 0
|
251
|
+
this.buttonShow = show
|
252
|
+
})
|
253
|
+
.exec()
|
254
|
+
}
|
255
|
+
}
|
256
|
+
}
|
257
|
+
|
258
|
+
// #endif
|
259
|
+
|
260
|
+
export default otherMixins
|
@@ -0,0 +1,84 @@
|
|
1
|
+
let mpMixins = {}
|
2
|
+
let is_pc = null
|
3
|
+
// #ifdef H5
|
4
|
+
import {
|
5
|
+
isPC
|
6
|
+
} from "./isPC"
|
7
|
+
is_pc = isPC()
|
8
|
+
// #endif
|
9
|
+
// #ifdef APP-VUE|| MP-WEIXIN || H5
|
10
|
+
|
11
|
+
mpMixins = {
|
12
|
+
data() {
|
13
|
+
return {
|
14
|
+
is_show: 'none'
|
15
|
+
}
|
16
|
+
},
|
17
|
+
watch: {
|
18
|
+
show(newVal) {
|
19
|
+
this.is_show = this.show
|
20
|
+
}
|
21
|
+
},
|
22
|
+
created() {
|
23
|
+
this.swipeaction = this.getSwipeAction()
|
24
|
+
if (this.swipeaction && Array.isArray(this.swipeaction.children)) {
|
25
|
+
this.swipeaction.children.push(this)
|
26
|
+
}
|
27
|
+
},
|
28
|
+
mounted() {
|
29
|
+
this.is_show = this.show
|
30
|
+
},
|
31
|
+
methods: {
|
32
|
+
// wxs 中调用
|
33
|
+
closeSwipe(e) {
|
34
|
+
if (this.autoClose && this.swipeaction) {
|
35
|
+
this.swipeaction.closeOther(this)
|
36
|
+
}
|
37
|
+
},
|
38
|
+
|
39
|
+
change(e) {
|
40
|
+
this.$emit('change', e.open)
|
41
|
+
if (this.is_show !== e.open) {
|
42
|
+
this.is_show = e.open
|
43
|
+
}
|
44
|
+
},
|
45
|
+
|
46
|
+
appTouchStart(e) {
|
47
|
+
if (is_pc) return
|
48
|
+
const {
|
49
|
+
clientX
|
50
|
+
} = e.changedTouches[0]
|
51
|
+
this.clientX = clientX
|
52
|
+
this.timestamp = new Date().getTime()
|
53
|
+
},
|
54
|
+
appTouchEnd(e, index, item, position) {
|
55
|
+
if (is_pc) return
|
56
|
+
const {
|
57
|
+
clientX
|
58
|
+
} = e.changedTouches[0]
|
59
|
+
// fixed by xxxx 模拟点击事件,解决 ios 13 点击区域错位的问题
|
60
|
+
let diff = Math.abs(this.clientX - clientX)
|
61
|
+
let time = (new Date().getTime()) - this.timestamp
|
62
|
+
if (diff < 40 && time < 300) {
|
63
|
+
this.$emit('click', {
|
64
|
+
content: item,
|
65
|
+
index,
|
66
|
+
position
|
67
|
+
})
|
68
|
+
}
|
69
|
+
},
|
70
|
+
onClickForPC(index, item, position) {
|
71
|
+
if (!is_pc) return
|
72
|
+
// #ifdef H5
|
73
|
+
this.$emit('click', {
|
74
|
+
content: item,
|
75
|
+
index,
|
76
|
+
position
|
77
|
+
})
|
78
|
+
// #endif
|
79
|
+
}
|
80
|
+
}
|
81
|
+
}
|
82
|
+
|
83
|
+
// #endif
|
84
|
+
export default mpMixins
|
@@ -0,0 +1,270 @@
|
|
1
|
+
const MIN_DISTANCE = 10;
|
2
|
+
export default {
|
3
|
+
showWatch(newVal, oldVal, ownerInstance, instance, self) {
|
4
|
+
var state = self.state
|
5
|
+
var $el = ownerInstance.$el || ownerInstance.$vm && ownerInstance.$vm.$el
|
6
|
+
if (!$el) return
|
7
|
+
this.getDom(instance, ownerInstance, self)
|
8
|
+
if (newVal && newVal !== 'none') {
|
9
|
+
this.openState(newVal, instance, ownerInstance, self)
|
10
|
+
return
|
11
|
+
}
|
12
|
+
|
13
|
+
if (state.left) {
|
14
|
+
this.openState('none', instance, ownerInstance, self)
|
15
|
+
}
|
16
|
+
this.resetTouchStatus(instance, self)
|
17
|
+
},
|
18
|
+
|
19
|
+
/**
|
20
|
+
* 开始触摸操作
|
21
|
+
* @param {Object} e
|
22
|
+
* @param {Object} ins
|
23
|
+
*/
|
24
|
+
touchstart(e, ownerInstance, self) {
|
25
|
+
let instance = e.instance;
|
26
|
+
let disabled = instance.getDataset().disabled
|
27
|
+
let state = self.state;
|
28
|
+
this.getDom(instance, ownerInstance, self)
|
29
|
+
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
|
30
|
+
disabled = this.getDisabledType(disabled)
|
31
|
+
if (disabled) return
|
32
|
+
// 开始触摸时移除动画类
|
33
|
+
instance.requestAnimationFrame(function() {
|
34
|
+
instance.removeClass('ani');
|
35
|
+
ownerInstance.callMethod('closeSwipe');
|
36
|
+
})
|
37
|
+
|
38
|
+
// 记录上次的位置
|
39
|
+
state.x = state.left || 0
|
40
|
+
// 计算滑动开始位置
|
41
|
+
this.stopTouchStart(e, ownerInstance, self)
|
42
|
+
},
|
43
|
+
|
44
|
+
/**
|
45
|
+
* 开始滑动操作
|
46
|
+
* @param {Object} e
|
47
|
+
* @param {Object} ownerInstance
|
48
|
+
*/
|
49
|
+
touchmove(e, ownerInstance, self) {
|
50
|
+
let instance = e.instance;
|
51
|
+
// 删除之后已经那不到实例了
|
52
|
+
if (!instance) return;
|
53
|
+
let disabled = instance.getDataset().disabled
|
54
|
+
let state = self.state
|
55
|
+
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
|
56
|
+
disabled = this.getDisabledType(disabled)
|
57
|
+
if (disabled) return
|
58
|
+
// 是否可以滑动页面
|
59
|
+
this.stopTouchMove(e, self);
|
60
|
+
if (state.direction !== 'horizontal') {
|
61
|
+
return;
|
62
|
+
}
|
63
|
+
if (e.preventDefault) {
|
64
|
+
// 阻止页面滚动
|
65
|
+
e.preventDefault()
|
66
|
+
}
|
67
|
+
let x = state.x + state.deltaX
|
68
|
+
this.move(x, instance, ownerInstance, self)
|
69
|
+
},
|
70
|
+
|
71
|
+
/**
|
72
|
+
* 结束触摸操作
|
73
|
+
* @param {Object} e
|
74
|
+
* @param {Object} ownerInstance
|
75
|
+
*/
|
76
|
+
touchend(e, ownerInstance, self) {
|
77
|
+
let instance = e.instance;
|
78
|
+
let disabled = instance.getDataset().disabled
|
79
|
+
let state = self.state
|
80
|
+
// fix by mehaotian, TODO 兼容 app-vue 获取dataset为字符串 , h5 获取 为 undefined 的问题,待框架修复
|
81
|
+
disabled = this.getDisabledType(disabled)
|
82
|
+
|
83
|
+
if (disabled) return
|
84
|
+
// 滑动过程中触摸结束,通过阙值判断是开启还是关闭
|
85
|
+
// fixed by mehaotian 定时器解决点击按钮,touchend 触发比 click 事件时机早的问题 ,主要是 ios13
|
86
|
+
this.moveDirection(state.left, instance, ownerInstance, self)
|
87
|
+
|
88
|
+
},
|
89
|
+
|
90
|
+
/**
|
91
|
+
* 设置移动距离
|
92
|
+
* @param {Object} value
|
93
|
+
* @param {Object} instance
|
94
|
+
* @param {Object} ownerInstance
|
95
|
+
*/
|
96
|
+
move(value, instance, ownerInstance, self) {
|
97
|
+
value = value || 0
|
98
|
+
let state = self.state
|
99
|
+
let leftWidth = state.leftWidth
|
100
|
+
let rightWidth = state.rightWidth
|
101
|
+
// 获取可滑动范围
|
102
|
+
state.left = this.range(value, -rightWidth, leftWidth);
|
103
|
+
instance.requestAnimationFrame(function() {
|
104
|
+
instance.setStyle({
|
105
|
+
transform: 'translateX(' + state.left + 'px)',
|
106
|
+
'-webkit-transform': 'translateX(' + state.left + 'px)'
|
107
|
+
})
|
108
|
+
})
|
109
|
+
|
110
|
+
},
|
111
|
+
|
112
|
+
/**
|
113
|
+
* 获取元素信息
|
114
|
+
* @param {Object} instance
|
115
|
+
* @param {Object} ownerInstance
|
116
|
+
*/
|
117
|
+
getDom(instance, ownerInstance, self) {
|
118
|
+
var state = self.state
|
119
|
+
var $el = ownerInstance.$el || ownerInstance.$vm && ownerInstance.$vm.$el
|
120
|
+
var leftDom = $el.querySelector('.button-group--left')
|
121
|
+
var rightDom = $el.querySelector('.button-group--right')
|
122
|
+
|
123
|
+
state.leftWidth = leftDom.offsetWidth || 0
|
124
|
+
state.rightWidth = rightDom.offsetWidth || 0
|
125
|
+
state.threshold = instance.getDataset().threshold
|
126
|
+
},
|
127
|
+
|
128
|
+
getDisabledType(value) {
|
129
|
+
return (typeof(value) === 'string' ? JSON.parse(value) : value) || false;
|
130
|
+
},
|
131
|
+
|
132
|
+
/**
|
133
|
+
* 获取范围
|
134
|
+
* @param {Object} num
|
135
|
+
* @param {Object} min
|
136
|
+
* @param {Object} max
|
137
|
+
*/
|
138
|
+
range(num, min, max) {
|
139
|
+
return Math.min(Math.max(num, min), max);
|
140
|
+
},
|
141
|
+
|
142
|
+
|
143
|
+
/**
|
144
|
+
* 移动方向判断
|
145
|
+
* @param {Object} left
|
146
|
+
* @param {Object} value
|
147
|
+
* @param {Object} ownerInstance
|
148
|
+
* @param {Object} ins
|
149
|
+
*/
|
150
|
+
moveDirection(left, ins, ownerInstance, self) {
|
151
|
+
var state = self.state
|
152
|
+
var threshold = state.threshold
|
153
|
+
var position = state.position
|
154
|
+
var isopen = state.isopen || 'none'
|
155
|
+
var leftWidth = state.leftWidth
|
156
|
+
var rightWidth = state.rightWidth
|
157
|
+
if (state.deltaX === 0) {
|
158
|
+
this.openState('none', ins, ownerInstance, self)
|
159
|
+
return
|
160
|
+
}
|
161
|
+
if ((isopen === 'none' && rightWidth > 0 && -left > threshold) || (isopen !== 'none' && rightWidth > 0 &&
|
162
|
+
rightWidth +
|
163
|
+
left < threshold)) {
|
164
|
+
// right
|
165
|
+
this.openState('right', ins, ownerInstance, self)
|
166
|
+
} else if ((isopen === 'none' && leftWidth > 0 && left > threshold) || (isopen !== 'none' && leftWidth > 0 &&
|
167
|
+
leftWidth - left < threshold)) {
|
168
|
+
// left
|
169
|
+
this.openState('left', ins, ownerInstance, self)
|
170
|
+
} else {
|
171
|
+
// default
|
172
|
+
this.openState('none', ins, ownerInstance, self)
|
173
|
+
}
|
174
|
+
},
|
175
|
+
|
176
|
+
|
177
|
+
/**
|
178
|
+
* 开启状态
|
179
|
+
* @param {Boolean} type
|
180
|
+
* @param {Object} ins
|
181
|
+
* @param {Object} ownerInstance
|
182
|
+
*/
|
183
|
+
openState(type, ins, ownerInstance, self) {
|
184
|
+
let state = self.state
|
185
|
+
let leftWidth = state.leftWidth
|
186
|
+
let rightWidth = state.rightWidth
|
187
|
+
let left = ''
|
188
|
+
state.isopen = state.isopen ? state.isopen : 'none'
|
189
|
+
switch (type) {
|
190
|
+
case "left":
|
191
|
+
left = leftWidth
|
192
|
+
break
|
193
|
+
case "right":
|
194
|
+
left = -rightWidth
|
195
|
+
break
|
196
|
+
default:
|
197
|
+
left = 0
|
198
|
+
}
|
199
|
+
|
200
|
+
// && !state.throttle
|
201
|
+
|
202
|
+
if (state.isopen !== type) {
|
203
|
+
state.throttle = true
|
204
|
+
ownerInstance.callMethod('change', {
|
205
|
+
open: type
|
206
|
+
})
|
207
|
+
|
208
|
+
}
|
209
|
+
|
210
|
+
state.isopen = type
|
211
|
+
// 添加动画类
|
212
|
+
ins.requestAnimationFrame(() => {
|
213
|
+
ins.addClass('ani');
|
214
|
+
this.move(left, ins, ownerInstance, self)
|
215
|
+
})
|
216
|
+
},
|
217
|
+
|
218
|
+
|
219
|
+
getDirection(x, y) {
|
220
|
+
if (x > y && x > MIN_DISTANCE) {
|
221
|
+
return 'horizontal';
|
222
|
+
}
|
223
|
+
if (y > x && y > MIN_DISTANCE) {
|
224
|
+
return 'vertical';
|
225
|
+
}
|
226
|
+
return '';
|
227
|
+
},
|
228
|
+
|
229
|
+
/**
|
230
|
+
* 重置滑动状态
|
231
|
+
* @param {Object} event
|
232
|
+
*/
|
233
|
+
resetTouchStatus(instance, self) {
|
234
|
+
let state = self.state;
|
235
|
+
state.direction = '';
|
236
|
+
state.deltaX = 0;
|
237
|
+
state.deltaY = 0;
|
238
|
+
state.offsetX = 0;
|
239
|
+
state.offsetY = 0;
|
240
|
+
},
|
241
|
+
|
242
|
+
/**
|
243
|
+
* 设置滑动开始位置
|
244
|
+
* @param {Object} event
|
245
|
+
*/
|
246
|
+
stopTouchStart(event, ownerInstance, self) {
|
247
|
+
let instance = event.instance;
|
248
|
+
let state = self.state
|
249
|
+
this.resetTouchStatus(instance, self);
|
250
|
+
var touch = event.touches[0];
|
251
|
+
state.startX = touch.clientX;
|
252
|
+
state.startY = touch.clientY;
|
253
|
+
},
|
254
|
+
|
255
|
+
/**
|
256
|
+
* 滑动中,是否禁止打开
|
257
|
+
* @param {Object} event
|
258
|
+
*/
|
259
|
+
stopTouchMove(event, self) {
|
260
|
+
let instance = event.instance;
|
261
|
+
let state = self.state;
|
262
|
+
let touch = event.touches[0];
|
263
|
+
|
264
|
+
state.deltaX = touch.clientX - state.startX;
|
265
|
+
state.deltaY = touch.clientY - state.startY;
|
266
|
+
state.offsetY = Math.abs(state.deltaY);
|
267
|
+
state.offsetX = Math.abs(state.deltaX);
|
268
|
+
state.direction = state.direction || this.getDirection(state.offsetX, state.offsetY);
|
269
|
+
}
|
270
|
+
}
|