uview-plus 3.3.6 → 3.3.8
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 +58 -0
- package/components/u-action-sheet/props.js +6 -1
- package/components/u-action-sheet/u-action-sheet.vue +4 -5
- package/components/u-cell/u-cell.vue +20 -1
- package/components/u-checkbox/u-checkbox.vue +29 -19
- package/components/u-code/u-code.vue +0 -5
- package/components/u-collapse-item/props.js +6 -1
- package/components/u-collapse-item/u-collapse-item.vue +5 -3
- package/components/u-count-down/u-count-down.vue +0 -5
- package/components/u-dropdown/u-dropdown.vue +1 -1
- package/components/u-form-item/u-form-item.vue +1 -1
- package/components/u-grid-item/u-grid-item.vue +0 -5
- package/components/u-index-list/props.js +6 -1
- package/components/u-index-list/u-index-list.vue +168 -42
- package/components/u-lazy-load/u-lazy-load.vue +10 -3
- package/components/u-loading-icon/u-loading-icon.vue +2 -0
- package/components/u-modal/u-modal.vue +6 -3
- package/components/u-notify/u-notify.vue +0 -5
- package/components/u-number-box/u-number-box.vue +1 -0
- package/components/u-parse/node/node.vue +9 -1
- package/components/u-parse/u-parse.vue +1 -7
- package/components/u-picker/u-picker.vue +1 -0
- package/components/u-popup/u-popup.vue +3 -1
- package/components/u-row-notice/u-row-notice.vue +1 -8
- package/components/u-scroll-list/nvue.js +1 -1
- package/components/u-scroll-list/u-scroll-list.vue +5 -2
- package/components/u-slider/props.js +45 -19
- package/components/u-slider/u-slider.vue +414 -7
- package/components/u-sticky/u-sticky.vue +0 -5
- package/components/u-swipe-action-item/nvue.js +0 -5
- package/components/u-tabbar-item/u-tabbar-item.vue +3 -0
- package/components/u-tabs/u-tabs.vue +21 -4
- package/components/u-toast/u-toast.vue +10 -10
- package/components/u-upload/u-upload.vue +9 -4
- package/components/u-upload/utils.js +10 -4
- package/components/u-waterfall/u-waterfall.vue +11 -5
- package/libs/config/props/actionSheet.js +2 -1
- package/libs/config/props/collapseItem.js +2 -1
- package/libs/config/props/indexList.js +2 -1
- package/libs/config/props/slider.js +3 -1
- package/libs/css/common.scss +1 -1
- package/libs/css/flex.scss +3 -0
- package/libs/mixin/mixin.js +23 -8
- package/package.json +1 -1
- package/types/index.d.ts +154 -29
- package/components/u-slider/nvue - /345/211/257/346/234/254.js" +0 -180
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { defineMixin } from '../../libs/vue'
|
|
2
2
|
import defProps from '../../libs/config/props.js'
|
|
3
|
+
|
|
3
4
|
export const props = defineMixin({
|
|
4
5
|
props: {
|
|
5
6
|
// 最小可选值
|
|
@@ -17,20 +18,30 @@ export const props = defineMixin({
|
|
|
17
18
|
type: [Number, String],
|
|
18
19
|
default: () => defProps.slider.step
|
|
19
20
|
},
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
21
|
+
// #ifdef VUE3
|
|
22
|
+
// 当前取值
|
|
23
|
+
modelValue: {
|
|
24
|
+
type: [String, Number],
|
|
25
|
+
default: () => defProps.slider.value
|
|
26
|
+
},
|
|
27
|
+
// #endif
|
|
28
|
+
// #ifdef VUE2
|
|
29
|
+
// 当前取值
|
|
30
|
+
value: {
|
|
31
|
+
type: [String, Number],
|
|
32
|
+
default: () => defProps.slider.value
|
|
33
|
+
},
|
|
34
|
+
// #endif
|
|
35
|
+
// 是否区间模式
|
|
36
|
+
isRange: {
|
|
37
|
+
type: Boolean,
|
|
38
|
+
default: false
|
|
39
|
+
},
|
|
40
|
+
// 双滑块时值
|
|
41
|
+
rangeValue: {
|
|
42
|
+
type: [Array],
|
|
43
|
+
default: [0, 0]
|
|
44
|
+
},
|
|
34
45
|
// 滑块右侧已选择部分的背景色
|
|
35
46
|
activeColor: {
|
|
36
47
|
type: String,
|
|
@@ -51,15 +62,30 @@ export const props = defineMixin({
|
|
|
51
62
|
type: String,
|
|
52
63
|
default: () => defProps.slider.blockColor
|
|
53
64
|
},
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
// 用户对滑块的自定义颜色
|
|
66
|
+
blockStyle: {
|
|
67
|
+
type: Object,
|
|
68
|
+
default: () => defProps.slider.blockStyle
|
|
69
|
+
},
|
|
70
|
+
// 禁用状态
|
|
71
|
+
disabled: {
|
|
72
|
+
type: Boolean,
|
|
73
|
+
default: () => defProps.slider.disabled
|
|
74
|
+
},
|
|
59
75
|
// 是否显示当前的选择值
|
|
60
76
|
showValue: {
|
|
61
77
|
type: Boolean,
|
|
62
78
|
default: () => defProps.slider.showValue
|
|
79
|
+
},
|
|
80
|
+
// 是否渲染uni-app框架内置组件
|
|
81
|
+
useNative: {
|
|
82
|
+
type: Boolean,
|
|
83
|
+
default: () => defProps.slider.useNative
|
|
84
|
+
},
|
|
85
|
+
// 滑块高度
|
|
86
|
+
height: {
|
|
87
|
+
type: String,
|
|
88
|
+
default: () => defProps.slider.height
|
|
63
89
|
}
|
|
64
90
|
}
|
|
65
91
|
})
|
|
@@ -3,7 +3,84 @@
|
|
|
3
3
|
class="u-slider"
|
|
4
4
|
:style="[addStyle(customStyle)]"
|
|
5
5
|
>
|
|
6
|
+
<template v-if="!useNative || isRange">
|
|
7
|
+
<view ref="u-slider-inner" class="u-slider-inner" @click="onClick"
|
|
8
|
+
@onTouchStart="onTouchStart2($event, 1)" @touchmove="onTouchMove2($event, 1)"
|
|
9
|
+
@touchend="onTouchEnd2($event, 1)" @touchcancel="onTouchEnd2($event, 1)"
|
|
10
|
+
:class="[disabled ? 'u-slider--disabled' : '']" :style="{
|
|
11
|
+
height: (isRange && showValue) ? (getPx(blockSize) + 24) + 'px' : (getPx(blockSize)) + 'px',
|
|
12
|
+
}"
|
|
13
|
+
>
|
|
14
|
+
<view ref="u-slider__base"
|
|
15
|
+
class="u-slider__base"
|
|
16
|
+
:style="[
|
|
17
|
+
{
|
|
18
|
+
height: height,
|
|
19
|
+
backgroundColor: inactiveColor
|
|
20
|
+
}
|
|
21
|
+
]"
|
|
22
|
+
>
|
|
23
|
+
</view>
|
|
24
|
+
<view
|
|
25
|
+
class="u-slider__gap"
|
|
26
|
+
:style="[
|
|
27
|
+
barStyle,
|
|
28
|
+
{
|
|
29
|
+
height: height,
|
|
30
|
+
marginTop: '-' + height,
|
|
31
|
+
backgroundColor: activeColor
|
|
32
|
+
}
|
|
33
|
+
]"
|
|
34
|
+
>
|
|
35
|
+
</view>
|
|
36
|
+
<view v-if="isRange"
|
|
37
|
+
class="u-slider__gap u-slider__gap-0"
|
|
38
|
+
:style="[
|
|
39
|
+
barStyle0,
|
|
40
|
+
{
|
|
41
|
+
height: height,
|
|
42
|
+
marginTop: '-' + height,
|
|
43
|
+
backgroundColor: inactiveColor
|
|
44
|
+
}
|
|
45
|
+
]"
|
|
46
|
+
>
|
|
47
|
+
</view>
|
|
48
|
+
<text v-if="isRange && showValue"
|
|
49
|
+
class="u-slider__show-range-value" :style="{left: (getPx(barStyle0.width) + getPx(blockSize)/2) + 'px'}">
|
|
50
|
+
{{ this.rangeValue[0] }}
|
|
51
|
+
</text>
|
|
52
|
+
<text v-if="isRange && showValue"
|
|
53
|
+
class="u-slider__show-range-value" :style="{left: (getPx(barStyle.width) + getPx(blockSize)/2) + 'px'}">
|
|
54
|
+
{{ this.rangeValue[1] }}
|
|
55
|
+
</text>
|
|
56
|
+
<template v-if="isRange">
|
|
57
|
+
<view class="u-slider__button-wrap u-slider__button-wrap-0" @touchstart="onTouchStart($event, 0)"
|
|
58
|
+
@touchmove="onTouchMove($event, 0)" @touchend="onTouchEnd($event, 0)"
|
|
59
|
+
@touchcancel="onTouchEnd($event, 0)" :style="{left: (getPx(barStyle0.width) + getPx(blockSize)/2) + 'px'}">
|
|
60
|
+
<slot v-if="$slots.default || $slots.$default"/>
|
|
61
|
+
<view v-else class="u-slider__button" :style="[blockStyle, {
|
|
62
|
+
height: getPx(blockSize, true),
|
|
63
|
+
width: getPx(blockSize, true),
|
|
64
|
+
backgroundColor: blockColor
|
|
65
|
+
}]"></view>
|
|
66
|
+
</view>
|
|
67
|
+
</template>
|
|
68
|
+
<view class="u-slider__button-wrap" @touchstart="onTouchStart"
|
|
69
|
+
@touchmove="onTouchMove" @touchend="onTouchEnd"
|
|
70
|
+
@touchcancel="onTouchEnd" :style="{left: (getPx(barStyle.width) + getPx(blockSize)/2) + 'px'}">
|
|
71
|
+
<slot v-if="$slots.default || $slots.$default"/>
|
|
72
|
+
<view v-else class="u-slider__button" :style="[blockStyle, {
|
|
73
|
+
height: getPx(blockSize, true),
|
|
74
|
+
width: getPx(blockSize, true),
|
|
75
|
+
backgroundColor: blockColor
|
|
76
|
+
}]"></view>
|
|
77
|
+
</view>
|
|
78
|
+
</view>
|
|
79
|
+
<view class="u-slider__show-value" v-if="showValue && !isRange">{{ modelValue }}</view>
|
|
80
|
+
</template>
|
|
6
81
|
<slider
|
|
82
|
+
class="u-slider__native"
|
|
83
|
+
v-else
|
|
7
84
|
:min="min"
|
|
8
85
|
:max="max"
|
|
9
86
|
:step="step"
|
|
@@ -24,15 +101,105 @@
|
|
|
24
101
|
import { props } from './props';
|
|
25
102
|
import { mpMixin } from '../../libs/mixin/mpMixin';
|
|
26
103
|
import { mixin } from '../../libs/mixin/mixin';
|
|
27
|
-
import { addStyle, getPx } from '../../libs/function/index.js';
|
|
104
|
+
import { addStyle, getPx, sleep } from '../../libs/function/index.js';
|
|
105
|
+
// #ifdef APP-NVUE
|
|
106
|
+
const dom = uni.requireNativePlugin('dom')
|
|
107
|
+
// #endif
|
|
108
|
+
/**
|
|
109
|
+
* slider 滑块选择器
|
|
110
|
+
* @tutorial https://uview-plus.jiangruyi.com/components/slider.html
|
|
111
|
+
* @property {Number | String} value 滑块默认值(默认0)
|
|
112
|
+
* @property {Number | String} min 最小值(默认0)
|
|
113
|
+
* @property {Number | String} max 最大值(默认100)
|
|
114
|
+
* @property {Number | String} step 步长(默认1)
|
|
115
|
+
* @property {Number | String} blockWidth 滑块宽度,高等于宽(30)
|
|
116
|
+
* @property {Number | String} height 滑块条高度,单位rpx(默认6)
|
|
117
|
+
* @property {String} inactiveColor 底部条背景颜色(默认#c0c4cc)
|
|
118
|
+
* @property {String} activeColor 底部选择部分的背景颜色(默认#2979ff)
|
|
119
|
+
* @property {String} blockColor 滑块颜色(默认#ffffff)
|
|
120
|
+
* @property {Object} blockStyle 给滑块自定义样式,对象形式
|
|
121
|
+
* @property {Boolean} disabled 是否禁用滑块(默认为false)
|
|
122
|
+
* @event {Function} changing 正在滑动中
|
|
123
|
+
* @event {Function} change 滑动结束
|
|
124
|
+
* @example <up-slider v-model="value" />
|
|
125
|
+
*/
|
|
28
126
|
export default {
|
|
29
|
-
name: '
|
|
127
|
+
name: 'u-slider',
|
|
30
128
|
mixins: [mpMixin, mixin, props],
|
|
31
|
-
emits: ["changing", "change", "update:modelValue"],
|
|
129
|
+
emits: ["start", "changing", "change", "update:modelValue"],
|
|
130
|
+
data() {
|
|
131
|
+
return {
|
|
132
|
+
startX: 0,
|
|
133
|
+
status: 'end',
|
|
134
|
+
newValue: 0,
|
|
135
|
+
distanceX: 0,
|
|
136
|
+
startValue0: 0,
|
|
137
|
+
startValue: 0,
|
|
138
|
+
barStyle0: {},
|
|
139
|
+
barStyle: {},
|
|
140
|
+
sliderRect: {
|
|
141
|
+
left: 0,
|
|
142
|
+
width: 0
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
},
|
|
146
|
+
watch: {
|
|
147
|
+
// #ifdef VUE3
|
|
148
|
+
modelValue(n) {
|
|
149
|
+
// 只有在非滑动状态时,才可以通过value更新滑块值,这里监听,是为了让用户触发
|
|
150
|
+
if(this.status == 'end') this.updateValue(this.modelValue, false);
|
|
151
|
+
},
|
|
152
|
+
// #endif
|
|
153
|
+
// #ifdef VUE2
|
|
154
|
+
value(n) {
|
|
155
|
+
// 只有在非滑动状态时,才可以通过value更新滑块值,这里监听,是为了让用户触发
|
|
156
|
+
if(this.status == 'end') this.updateValue(this.value, false);
|
|
157
|
+
}
|
|
158
|
+
// #endif
|
|
159
|
+
},
|
|
160
|
+
created() {
|
|
161
|
+
},
|
|
162
|
+
async mounted() {
|
|
163
|
+
// 获取滑块条的尺寸信息
|
|
164
|
+
if (!this.useNative) {
|
|
165
|
+
// #ifndef APP-NVUE
|
|
166
|
+
this.$uGetRect('.u-slider__base').then(rect => {
|
|
167
|
+
this.sliderRect = rect;
|
|
168
|
+
this.init()
|
|
169
|
+
});
|
|
170
|
+
// #endif
|
|
171
|
+
// #ifdef APP-NVUE
|
|
172
|
+
await sleep(30) // 不延迟会出现size获取都为0的问题
|
|
173
|
+
const ref = this.$refs['u-slider__base']
|
|
174
|
+
ref &&
|
|
175
|
+
dom.getComponentRect(ref, (res) => {
|
|
176
|
+
// console.log(res)
|
|
177
|
+
this.sliderRect = {
|
|
178
|
+
left: res.size.left,
|
|
179
|
+
width: res.size.width
|
|
180
|
+
};
|
|
181
|
+
this.init()
|
|
182
|
+
})
|
|
183
|
+
// #endif
|
|
184
|
+
}
|
|
185
|
+
},
|
|
32
186
|
methods: {
|
|
33
187
|
addStyle,
|
|
34
188
|
getPx,
|
|
35
|
-
|
|
189
|
+
init() {
|
|
190
|
+
if (this.isRange) {
|
|
191
|
+
this.updateValue(this.rangeValue[0], false, 0);
|
|
192
|
+
this.updateValue(this.rangeValue[1], false, 1);
|
|
193
|
+
} else {
|
|
194
|
+
// #ifdef VUE3
|
|
195
|
+
this.updateValue(this.modelValue, false);
|
|
196
|
+
// #endif
|
|
197
|
+
// #ifdef VUE2
|
|
198
|
+
this.updateValue(this.value, false);
|
|
199
|
+
// #endif
|
|
200
|
+
}
|
|
201
|
+
},
|
|
202
|
+
// native拖动过程中触发
|
|
36
203
|
changingHandler(e) {
|
|
37
204
|
const {
|
|
38
205
|
value
|
|
@@ -47,7 +214,7 @@
|
|
|
47
214
|
// 触发事件
|
|
48
215
|
this.$emit('changing', value)
|
|
49
216
|
},
|
|
50
|
-
// 滑动结束时触发
|
|
217
|
+
// native滑动结束时触发
|
|
51
218
|
changeHandler(e) {
|
|
52
219
|
const {
|
|
53
220
|
value
|
|
@@ -60,12 +227,252 @@
|
|
|
60
227
|
this.$emit("input", value);
|
|
61
228
|
// #endif
|
|
62
229
|
// 触发事件
|
|
63
|
-
this.$emit('change', value)
|
|
230
|
+
this.$emit('change', value);
|
|
231
|
+
},
|
|
232
|
+
onTouchStart(event, index = 1) {
|
|
233
|
+
if (this.disabled) return;
|
|
234
|
+
this.startX = 0;
|
|
235
|
+
// 触摸点集
|
|
236
|
+
let touches = event.touches[0];
|
|
237
|
+
// 触摸点到屏幕左边的距离
|
|
238
|
+
this.startX = touches.clientX;
|
|
239
|
+
// 此处的this.modelValue虽为props值,但是通过$emit('update:modelValue')进行了修改
|
|
240
|
+
if (this.isRange) {
|
|
241
|
+
this.startValue0 = this.format(this.rangeValue[0], 0);
|
|
242
|
+
this.startValue = this.format(this.rangeValue[1], 1);
|
|
243
|
+
} else {
|
|
244
|
+
// #ifdef VUE3
|
|
245
|
+
this.startValue = this.format(this.modelValue);
|
|
246
|
+
// #endif
|
|
247
|
+
// #ifdef VUE2
|
|
248
|
+
this.startValue = this.format(this.value);
|
|
249
|
+
// #endif
|
|
250
|
+
}
|
|
251
|
+
// 标示当前的状态为开始触摸滑动
|
|
252
|
+
this.status = 'start';
|
|
253
|
+
|
|
254
|
+
let clientX = 0;
|
|
255
|
+
// #ifndef APP-NVUE
|
|
256
|
+
clientX = touches.clientX;
|
|
257
|
+
// #endif
|
|
258
|
+
// #ifdef APP-NVUE
|
|
259
|
+
clientX = touches.screenX;
|
|
260
|
+
// #endif
|
|
261
|
+
this.distanceX = clientX - this.sliderRect.left;
|
|
262
|
+
// 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
|
|
263
|
+
// 否则造成通信阻塞,需要每改变一个step值时修改一次视图
|
|
264
|
+
this.newValue = ((this.distanceX / this.sliderRect.width) * (this.max - this.min)) + parseFloat(this.min);
|
|
265
|
+
this.status = 'moving';
|
|
266
|
+
// 发出moving事件
|
|
267
|
+
this.$emit('changing');
|
|
268
|
+
this.updateValue(this.newValue, true, index);
|
|
269
|
+
},
|
|
270
|
+
onTouchMove(event, index = 1) {
|
|
271
|
+
if (this.disabled) return;
|
|
272
|
+
// 连续触摸的过程会一直触发本方法,但只有手指触发且移动了才被认为是拖动了,才发出事件
|
|
273
|
+
// 触摸后第一次移动已经将status设置为moving状态,故触摸第二次移动不会触发本事件
|
|
274
|
+
if (this.status == 'start') this.$emit('start');
|
|
275
|
+
let touches = event.touches[0];
|
|
276
|
+
console.log('touchs', touches)
|
|
277
|
+
// 滑块的左边不一定跟屏幕左边接壤,所以需要减去最外层父元素的左边值
|
|
278
|
+
let clientX = 0;
|
|
279
|
+
// #ifndef APP-NVUE
|
|
280
|
+
clientX = touches.clientX;
|
|
281
|
+
// #endif
|
|
282
|
+
// #ifdef APP-NVUE
|
|
283
|
+
clientX = touches.screenX;
|
|
284
|
+
// #endif
|
|
285
|
+
this.distanceX = clientX - this.sliderRect.left;
|
|
286
|
+
// 获得移动距离对整个滑块的值,此为带有多位小数的值,不能用此更新视图
|
|
287
|
+
// 否则造成通信阻塞,需要每改变一个step值时修改一次视图
|
|
288
|
+
this.newValue = ((this.distanceX / this.sliderRect.width) * (this.max - this.min)) + parseFloat(this.min);
|
|
289
|
+
this.status = 'moving';
|
|
290
|
+
// 发出moving事件
|
|
291
|
+
this.$emit('changing');
|
|
292
|
+
this.updateValue(this.newValue, true, index);
|
|
293
|
+
},
|
|
294
|
+
onTouchEnd(event, index = 1) {
|
|
295
|
+
if (this.disabled) return;
|
|
296
|
+
if (this.status === 'moving') {
|
|
297
|
+
this.updateValue(this.newValue, false, index);
|
|
298
|
+
this.$emit('change');
|
|
299
|
+
}
|
|
300
|
+
this.status = 'end';
|
|
301
|
+
},
|
|
302
|
+
onTouchStart2(event, index = 1) {
|
|
303
|
+
if (!this.isRange) {
|
|
304
|
+
this.onChangeStart(event, index);
|
|
305
|
+
}
|
|
306
|
+
},
|
|
307
|
+
onTouchMove2(event, index = 1) {
|
|
308
|
+
if (!this.isRange) {
|
|
309
|
+
this.onTouchMove(event, index);
|
|
310
|
+
}
|
|
311
|
+
},
|
|
312
|
+
onTouchEnd2(event, index = 1) {
|
|
313
|
+
if (!this.isRange) {
|
|
314
|
+
this.onTouchEnd(event, index);
|
|
315
|
+
}
|
|
316
|
+
},
|
|
317
|
+
onClick(event) {
|
|
318
|
+
if (this.disabled) return;
|
|
319
|
+
// 直接点击滑块的情况,计算方式与onTouchMove方法相同
|
|
320
|
+
// console.log('click', event)
|
|
321
|
+
// #ifndef APP-NVUE
|
|
322
|
+
// nvue下暂时无法获取坐标
|
|
323
|
+
let clientX = event.detail.x - this.sliderRect.left
|
|
324
|
+
this.newValue = ((clientX / this.sliderRect.width) * (this.max - this.min)) + parseFloat(this.min);
|
|
325
|
+
this.updateValue(this.newValue, false, 1);
|
|
326
|
+
// #endif
|
|
327
|
+
},
|
|
328
|
+
updateValue(value, drag, index = 1) {
|
|
329
|
+
// 去掉小数部分,同时也是对step步进的处理
|
|
330
|
+
let valueFormat = this.format(value, index);
|
|
331
|
+
// 不允许滑动的值超过max最大值
|
|
332
|
+
if(valueFormat > this.max ) {
|
|
333
|
+
valueFormat = this.max
|
|
334
|
+
}
|
|
335
|
+
// 设置移动的距离,不能用百分比,因为NVUE不支持。
|
|
336
|
+
let width = Math.min((valueFormat - this.min) / (this.max - this.min) * this.sliderRect.width, this.sliderRect.width)
|
|
337
|
+
let barStyle = {
|
|
338
|
+
width: width + 'px'
|
|
339
|
+
};
|
|
340
|
+
// 移动期间无需过渡动画
|
|
341
|
+
if (drag == true) {
|
|
342
|
+
barStyle.transition = 'none';
|
|
343
|
+
} else {
|
|
344
|
+
// 非移动期间,删掉对过渡为空的声明,让css中的声明起效
|
|
345
|
+
delete barStyle.transition;
|
|
346
|
+
}
|
|
347
|
+
// 修改value值
|
|
348
|
+
if (this.isRange) {
|
|
349
|
+
this.rangeValue[index] = valueFormat;
|
|
350
|
+
this.$emit("update:modelValue", this.rangeValue);
|
|
351
|
+
} else {
|
|
352
|
+
// #ifdef VUE3
|
|
353
|
+
this.$emit("update:modelValue", valueFormat);
|
|
354
|
+
// #endif
|
|
355
|
+
// #ifdef VUE2
|
|
356
|
+
this.$emit("input", valueFormat);
|
|
357
|
+
// #endif
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
switch (index) {
|
|
361
|
+
case 0:
|
|
362
|
+
this.barStyle0 = {...barStyle};
|
|
363
|
+
break;
|
|
364
|
+
case 1:
|
|
365
|
+
this.barStyle = {...barStyle};
|
|
366
|
+
break;
|
|
367
|
+
default:
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
},
|
|
372
|
+
format(value, index = 1) {
|
|
373
|
+
// 将小数变成整数,为了减少对视图的更新,造成视图层与逻辑层的阻塞
|
|
374
|
+
if (this.isRange) {
|
|
375
|
+
switch (index) {
|
|
376
|
+
case 0:
|
|
377
|
+
return Math.round(
|
|
378
|
+
Math.max(this.min, Math.min(value, this.rangeValue[1] - this.step,this.max))
|
|
379
|
+
/ this.step
|
|
380
|
+
) * this.step;
|
|
381
|
+
break;
|
|
382
|
+
case 1:
|
|
383
|
+
return Math.round(
|
|
384
|
+
Math.max(this.min, this.rangeValue[0] + this.step, Math.min(value, this.max))
|
|
385
|
+
/ this.step
|
|
386
|
+
) * this.step;
|
|
387
|
+
break;
|
|
388
|
+
default:
|
|
389
|
+
break;
|
|
390
|
+
}
|
|
391
|
+
} else {
|
|
392
|
+
return Math.round(
|
|
393
|
+
Math.max(this.min, Math.min(value, this.max))
|
|
394
|
+
/ this.step
|
|
395
|
+
) * this.step;
|
|
396
|
+
}
|
|
64
397
|
}
|
|
65
|
-
}
|
|
398
|
+
}
|
|
66
399
|
}
|
|
67
400
|
</script>
|
|
68
401
|
|
|
69
402
|
<style lang="scss" scoped>
|
|
70
403
|
@import "../../libs/css/components.scss";
|
|
404
|
+
.u-slider {
|
|
405
|
+
position: relative;
|
|
406
|
+
display: flex;
|
|
407
|
+
flex-direction: row;
|
|
408
|
+
align-items: center;
|
|
409
|
+
|
|
410
|
+
&__native {
|
|
411
|
+
flex: 1;
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
&-inner {
|
|
415
|
+
flex: 1;
|
|
416
|
+
position: relative;
|
|
417
|
+
border-radius: 999px;
|
|
418
|
+
padding: 10px 18px;
|
|
419
|
+
justify-content: center;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
&__show-value {
|
|
423
|
+
margin: 10px 18px 10px 0px;
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
&__show-range-value {
|
|
427
|
+
padding-top: 2px;
|
|
428
|
+
font-size: 12px;
|
|
429
|
+
line-height: 12px;
|
|
430
|
+
position: absolute;
|
|
431
|
+
bottom: 0;
|
|
432
|
+
}
|
|
433
|
+
|
|
434
|
+
&__base {
|
|
435
|
+
background-color: #ebedf0;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/* #ifndef APP-NVUE */
|
|
439
|
+
&-inner:before {
|
|
440
|
+
position: absolute;
|
|
441
|
+
right: 0;
|
|
442
|
+
left: 0;
|
|
443
|
+
content: '';
|
|
444
|
+
top: -8px;
|
|
445
|
+
bottom: -8px;
|
|
446
|
+
z-index: -1;
|
|
447
|
+
}
|
|
448
|
+
/* #endif */
|
|
449
|
+
|
|
450
|
+
&__gap {
|
|
451
|
+
position: relative;
|
|
452
|
+
border-radius: 999px;
|
|
453
|
+
transition: width 0.2s;
|
|
454
|
+
background-color: #1989fa;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
&__button {
|
|
458
|
+
width: 24px;
|
|
459
|
+
height: 24px;
|
|
460
|
+
border-radius: 50%;
|
|
461
|
+
box-shadow: 0 1px 2px rgba(0, 0, 0, 0.5);
|
|
462
|
+
background-color: #fff;
|
|
463
|
+
transform: scale(0.9);
|
|
464
|
+
/* #ifdef H5 */
|
|
465
|
+
cursor: pointer;
|
|
466
|
+
/* #endif */
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
&__button-wrap {
|
|
470
|
+
position: absolute;
|
|
471
|
+
// transform: translate3d(50%, -50%, 0);
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
&--disabled {
|
|
475
|
+
opacity: 0.5;
|
|
476
|
+
}
|
|
477
|
+
}
|
|
71
478
|
</style>
|
|
@@ -167,12 +167,7 @@ export default {
|
|
|
167
167
|
getContentRef() {
|
|
168
168
|
return this.$refs['u-swipe-action-item__content'].ref
|
|
169
169
|
},
|
|
170
|
-
// #ifdef VUE2
|
|
171
|
-
beforeDestroy() {
|
|
172
|
-
// #endif
|
|
173
|
-
// #ifdef VUE3
|
|
174
170
|
beforeUnmount() {
|
|
175
|
-
// #endif
|
|
176
171
|
this.unbindBindingX()
|
|
177
172
|
}
|
|
178
173
|
}
|
|
@@ -20,11 +20,15 @@
|
|
|
20
20
|
v-for="(item, index) in list"
|
|
21
21
|
:key="index"
|
|
22
22
|
@tap="clickHandler(item, index)"
|
|
23
|
+
@longpress="longPressHandler(item,index)"
|
|
23
24
|
:ref="`u-tabs__wrapper__nav__item-${index}`"
|
|
24
25
|
:style="[addStyle(itemStyle), {flex: scrollable ? '' : 1}]"
|
|
25
26
|
:class="[`u-tabs__wrapper__nav__item-${index}`, item.disabled && 'u-tabs__wrapper__nav__item--disabled']"
|
|
26
27
|
>
|
|
27
|
-
<
|
|
28
|
+
<slot v-if="$slots.content" name="content" :item="item" :keyName="keyName" :index="index" />
|
|
29
|
+
<slot v-else-if="!$slots.content && ($slots.default || $slots.$default)"
|
|
30
|
+
:item="item" :keyName="keyName" :index="index" />
|
|
31
|
+
<text v-else
|
|
28
32
|
:class="[item.disabled && 'u-tabs__wrapper__nav__item__text--disabled']"
|
|
29
33
|
class="u-tabs__wrapper__nav__item__text"
|
|
30
34
|
:style="[textStyle(index)]"
|
|
@@ -99,7 +103,8 @@
|
|
|
99
103
|
* @property {String} keyName 从`list`元素对象中读取的键名(默认 'name' )
|
|
100
104
|
* @event {Function(index)} change 标签改变时触发 index: 点击了第几个tab,索引从0开始
|
|
101
105
|
* @event {Function(index)} click 点击标签时触发 index: 点击了第几个tab,索引从0开始
|
|
102
|
-
* @
|
|
106
|
+
* @event {Function(index)} longPress 长按标签时触发 index: 点击了第几个tab,索引从0开始
|
|
107
|
+
* @example <u-tabs :list="list" :is-scroll="false" :current="current" @change="change" @longPress="longPress"></u-tabs>
|
|
103
108
|
*/
|
|
104
109
|
export default {
|
|
105
110
|
name: 'u-tabs',
|
|
@@ -157,7 +162,7 @@
|
|
|
157
162
|
async mounted() {
|
|
158
163
|
this.init()
|
|
159
164
|
},
|
|
160
|
-
emits: ['click', 'change'],
|
|
165
|
+
emits: ['click', 'longPress', 'change', 'update:current'],
|
|
161
166
|
methods: {
|
|
162
167
|
addStyle,
|
|
163
168
|
addUnit,
|
|
@@ -209,11 +214,19 @@
|
|
|
209
214
|
if (item.disabled) return
|
|
210
215
|
this.innerCurrent = index
|
|
211
216
|
this.resize()
|
|
217
|
+
this.$emit('update:current', index)
|
|
212
218
|
this.$emit('change', {
|
|
213
219
|
...item,
|
|
214
220
|
index
|
|
215
221
|
}, index)
|
|
216
222
|
},
|
|
223
|
+
// 长按事件
|
|
224
|
+
longPressHandler(item, index) {
|
|
225
|
+
this.$emit('longPress', {
|
|
226
|
+
...item,
|
|
227
|
+
index
|
|
228
|
+
})
|
|
229
|
+
},
|
|
217
230
|
init() {
|
|
218
231
|
sleep().then(() => {
|
|
219
232
|
this.resize()
|
|
@@ -327,10 +340,12 @@
|
|
|
327
340
|
@include flex;
|
|
328
341
|
align-items: center;
|
|
329
342
|
justify-content: center;
|
|
343
|
+
/* #ifdef H5 */
|
|
330
344
|
cursor: pointer;
|
|
345
|
+
/* #endif */
|
|
331
346
|
|
|
332
347
|
&--disabled {
|
|
333
|
-
/* #
|
|
348
|
+
/* #ifdef H5 */
|
|
334
349
|
cursor: not-allowed;
|
|
335
350
|
/* #endif */
|
|
336
351
|
}
|
|
@@ -338,7 +353,9 @@
|
|
|
338
353
|
&__text {
|
|
339
354
|
font-size: 15px;
|
|
340
355
|
color: $u-content-color;
|
|
356
|
+
/* #ifndef APP-NVUE */
|
|
341
357
|
white-space: nowrap !important;
|
|
358
|
+
/* #endif */
|
|
342
359
|
|
|
343
360
|
&--disabled {
|
|
344
361
|
color: $u-disabled-color !important;
|