stellar-ui-v2 1.35.3
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/common/css/common.scss +61 -0
- package/components/ste-animate/README.md +117 -0
- package/components/ste-animate/animate.scss +247 -0
- package/components/ste-animate/ste-animate.vue +200 -0
- package/components/ste-badge/README.md +171 -0
- package/components/ste-badge/ste-badge.vue +238 -0
- package/components/ste-barcode/README.md +36 -0
- package/components/ste-barcode/encode2.js +317 -0
- package/components/ste-barcode/ste-barcode.vue +213 -0
- package/components/ste-button/README.md +129 -0
- package/components/ste-button/ste-button.vue +345 -0
- package/components/ste-calendar/README.md +304 -0
- package/components/ste-calendar/self-date.js +119 -0
- package/components/ste-calendar/ste-calendar.vue +578 -0
- package/components/ste-checkbox/README.md +297 -0
- package/components/ste-checkbox/ste-checkbox.vue +305 -0
- package/components/ste-checkbox-group/ste-checkbox-group.vue +133 -0
- package/components/ste-code-input/README.md +67 -0
- package/components/ste-code-input/ste-code-input.vue +302 -0
- package/components/ste-date-picker/README.md +135 -0
- package/components/ste-date-picker/ste-date-picker.vue +407 -0
- package/components/ste-drag/README.md +103 -0
- package/components/ste-drag/ste-drag.vue +203 -0
- package/components/ste-dropdown-menu/README.md +358 -0
- package/components/ste-dropdown-menu/ste-dropdown-menu.vue +405 -0
- package/components/ste-dropdown-menu-item/ste-dropdown-menu-item.vue +176 -0
- package/components/ste-icon/README.md +90 -0
- package/components/ste-icon/iconfont.css +8 -0
- package/components/ste-icon/ste-icon.vue +147 -0
- package/components/ste-image/README.md +154 -0
- package/components/ste-image/ste-image.vue +218 -0
- package/components/ste-index-item/ste-index-item.vue +96 -0
- package/components/ste-index-list/README.md +153 -0
- package/components/ste-index-list/ste-index-list.vue +128 -0
- package/components/ste-input/README.md +146 -0
- package/components/ste-input/ste-input.vue +480 -0
- package/components/ste-loading/README.md +81 -0
- package/components/ste-loading/ste-loading.vue +166 -0
- package/components/ste-media-preview/README.md +243 -0
- package/components/ste-media-preview/TouchScaleing.js +102 -0
- package/components/ste-media-preview/ste-media-preview.vue +267 -0
- package/components/ste-message-box/README.md +217 -0
- package/components/ste-message-box/ste-message-box.js +72 -0
- package/components/ste-message-box/ste-message-box.vue +380 -0
- package/components/ste-notice-bar/README.md +129 -0
- package/components/ste-notice-bar/ste-notice-bar.vue +331 -0
- package/components/ste-number-keyboard/README.md +246 -0
- package/components/ste-number-keyboard/keyboard.vue +140 -0
- package/components/ste-number-keyboard/ste-number-keyboard.vue +240 -0
- package/components/ste-picker/ste-picker.vue +258 -0
- package/components/ste-popup/README.md +148 -0
- package/components/ste-popup/ste-popup.vue +337 -0
- package/components/ste-price/README.md +129 -0
- package/components/ste-price/ste-price.vue +258 -0
- package/components/ste-progress/README.md +87 -0
- package/components/ste-progress/ste-progress.vue +200 -0
- package/components/ste-qrcode/README.md +50 -0
- package/components/ste-qrcode/ste-qrcode.vue +164 -0
- package/components/ste-qrcode/uqrcode.js +34 -0
- package/components/ste-radio/README.md +286 -0
- package/components/ste-radio/ste-radio.vue +293 -0
- package/components/ste-radio-group/ste-radio-group.vue +128 -0
- package/components/ste-rate/README.md +115 -0
- package/components/ste-rate/ste-rate.vue +202 -0
- package/components/ste-read-more/README.md +111 -0
- package/components/ste-read-more/ste-read-more.vue +133 -0
- package/components/ste-rich-text/README.md +31 -0
- package/components/ste-rich-text/ste-rich-text.vue +70 -0
- package/components/ste-scroll-to/README.md +68 -0
- package/components/ste-scroll-to/mixin.js +173 -0
- package/components/ste-scroll-to/ste-scroll-to.vue +45 -0
- package/components/ste-scroll-to-item/ste-scroll-to-item.vue +25 -0
- package/components/ste-search/README.md +262 -0
- package/components/ste-search/ste-search.vue +547 -0
- package/components/ste-select/README.md +434 -0
- package/components/ste-select/datapager.vue +62 -0
- package/components/ste-select/datetime.vue +106 -0
- package/components/ste-select/defaultDate.js +142 -0
- package/components/ste-select/ste-select.vue +843 -0
- package/components/ste-signature/README.md +105 -0
- package/components/ste-signature/ste-signature.vue +220 -0
- package/components/ste-slider/README.md +165 -0
- package/components/ste-slider/ste-slider.vue +544 -0
- package/components/ste-step/ste-step.vue +264 -0
- package/components/ste-stepper/README.md +170 -0
- package/components/ste-stepper/ste-stepper.vue +373 -0
- package/components/ste-steps/README.md +132 -0
- package/components/ste-steps/ste-steps.vue +65 -0
- package/components/ste-sticky/README.md +52 -0
- package/components/ste-sticky/ste-sticky.vue +127 -0
- package/components/ste-swipe-action/README.md +197 -0
- package/components/ste-swipe-action/ste-swipe-action.vue +303 -0
- package/components/ste-swipe-action-group/ste-swipe-action-group.vue +104 -0
- package/components/ste-swiper/README.md +173 -0
- package/components/ste-swiper/ste-swiper.vue +462 -0
- package/components/ste-swiper-item/ste-swiper-item.vue +41 -0
- package/components/ste-switch/README.md +110 -0
- package/components/ste-switch/ste-switch.vue +144 -0
- package/components/ste-tab/ste-tab.vue +87 -0
- package/components/ste-table/README.md +785 -0
- package/components/ste-table/common.js +8 -0
- package/components/ste-table/ste-table.vue +666 -0
- package/components/ste-table/utils.js +20 -0
- package/components/ste-table-column/checkbox-icon.vue +65 -0
- package/components/ste-table-column/common.scss +65 -0
- package/components/ste-table-column/radio-icon.vue +110 -0
- package/components/ste-table-column/ste-table-column.vue +255 -0
- package/components/ste-table-column/sub-table.vue +116 -0
- package/components/ste-table-column/table-popover.vue +204 -0
- package/components/ste-table-column/var.scss +1 -0
- package/components/ste-tabs/README.md +475 -0
- package/components/ste-tabs/props.js +212 -0
- package/components/ste-tabs/ste-tabs.vue +758 -0
- package/components/ste-text/README.md +66 -0
- package/components/ste-text/ste-text.vue +72 -0
- package/components/ste-toast/README.md +243 -0
- package/components/ste-toast/ste-toast.js +69 -0
- package/components/ste-toast/ste-toast.vue +231 -0
- package/components/ste-touch-swipe/README.md +104 -0
- package/components/ste-touch-swipe/TouchEvent.js +72 -0
- package/components/ste-touch-swipe/ste-touch-swipe.vue +327 -0
- package/components/ste-touch-swipe-item/ste-touch-swipe-item.vue +33 -0
- package/components/ste-tour/README.md +194 -0
- package/components/ste-tour/ste-tour.vue +355 -0
- package/components/ste-tree/README.md +240 -0
- package/components/ste-tree/ste-tree.vue +350 -0
- package/components/ste-upload/README.md +276 -0
- package/components/ste-upload/ReadFile.js +229 -0
- package/components/ste-upload/ste-upload.vue +526 -0
- package/components/ste-video/README.md +60 -0
- package/components/ste-video/props.js +149 -0
- package/components/ste-video/ste-video.vue +647 -0
- package/config/color.js +22 -0
- package/index.js +2 -0
- package/package.json +19 -0
- package/utils/Color.js +66 -0
- package/utils/System.js +110 -0
- package/utils/dayjs.min.js +1 -0
- package/utils/mixin.js +67 -0
- package/utils/store.js +7 -0
- package/utils/utils.js +604 -0
|
@@ -0,0 +1,462 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ste-swiper-root" :style="[cmpRootStyle, { opacity: initializing ? 0 : 1 }]">
|
|
3
|
+
<view
|
|
4
|
+
class="swipe-content"
|
|
5
|
+
@mousedown="onTouchstart"
|
|
6
|
+
@mousemove="onTouchmove"
|
|
7
|
+
@mouseup="onTouchend"
|
|
8
|
+
@mouseleave="onTouchend"
|
|
9
|
+
@touchstart="onTouchstart"
|
|
10
|
+
@touchmove.stop="onTouchmove"
|
|
11
|
+
@touchend="onTouchend"
|
|
12
|
+
@touchcancel="onTouchend"
|
|
13
|
+
>
|
|
14
|
+
<view class="swipe-content-view" :style="[cmpBoxStyle, cmpBoxTransform]">
|
|
15
|
+
<slot></slot>
|
|
16
|
+
</view>
|
|
17
|
+
</view>
|
|
18
|
+
<view class="ste-swiper-dots" v-if="indicatorDots">
|
|
19
|
+
<view
|
|
20
|
+
class="swiper-dots-item"
|
|
21
|
+
v-for="(m, index) in children"
|
|
22
|
+
:key="index"
|
|
23
|
+
:class="{
|
|
24
|
+
active:
|
|
25
|
+
dataIndex === index ||
|
|
26
|
+
(index === 0 && dataIndex >= children.length) ||
|
|
27
|
+
(index === children.length && dataIndex === -1),
|
|
28
|
+
}"
|
|
29
|
+
/>
|
|
30
|
+
</view>
|
|
31
|
+
</view>
|
|
32
|
+
</template>
|
|
33
|
+
|
|
34
|
+
<script>
|
|
35
|
+
import utils from '../../utils/utils';
|
|
36
|
+
import TouchEvent from '../ste-touch-swipe/TouchEvent.js';
|
|
37
|
+
import { parentMixin } from '../../utils/mixin.js';
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* ste-swiper 轮播
|
|
41
|
+
* @description 轮播组件
|
|
42
|
+
* @tutorial https://stellar-ui.intecloud.com.cn/pc/index/index?name=ste-swiper
|
|
43
|
+
* @property {Number} current 当前显示所在滑块的 index
|
|
44
|
+
* @property {String} direction 滑动方向 "horizontal" | "vertical"
|
|
45
|
+
* @value horizontal 水平(默认,必须固定宽度)
|
|
46
|
+
* @value vertical 纵向(必须固定高度)
|
|
47
|
+
* @property {Boolean} disabled 是否禁用
|
|
48
|
+
* @property {Number | String} width 宽度,默认值100%
|
|
49
|
+
* @property {Number | String} height 高度,默认值100%
|
|
50
|
+
* @property {Number} duration 切换动画时常
|
|
51
|
+
* @property {Number} swipeThreshold 滑动灵敏度(0-1之间的小数,数值越小越灵敏)
|
|
52
|
+
* @property {Boolean} indicatorDots 是否显示面板指示点
|
|
53
|
+
* @property {String} indicatorColor 指示点颜色,默认rgba(0,0,0,0.3)
|
|
54
|
+
* @property {String} indicatorActiveColor 当前选中的指示点颜色,默认#000000
|
|
55
|
+
* @property {Boolean} autoplay 是否自动切换
|
|
56
|
+
* @property {Number} interval 自动切换时间间隔,默认3000
|
|
57
|
+
* @property {Boolean} circular 是否采用衔接滑动,即播放到末尾后重新回到开头
|
|
58
|
+
* @property {Number | String} previousMargin 前边距,可用于露出前一项的一小部分
|
|
59
|
+
* @property {Number | String} nextMargin 后边距,可用于露出后一项的一小部分
|
|
60
|
+
* @event {(index:number)=>void} change 切换事件
|
|
61
|
+
*/
|
|
62
|
+
export default {
|
|
63
|
+
group: '导航组件',
|
|
64
|
+
title: 'Swiper 轮播组件',
|
|
65
|
+
name: 'ste-swiper',
|
|
66
|
+
mixins: [parentMixin('ste-swiper')],
|
|
67
|
+
props: {
|
|
68
|
+
// 当前所在滑块的 index
|
|
69
|
+
current: {
|
|
70
|
+
type: [Number, null],
|
|
71
|
+
default: () => 0,
|
|
72
|
+
},
|
|
73
|
+
// 滑动方向 "horizontal" | "vertical"
|
|
74
|
+
direction: {
|
|
75
|
+
type: [String, null],
|
|
76
|
+
default: () => 'horizontal',
|
|
77
|
+
},
|
|
78
|
+
disabled: {
|
|
79
|
+
type: [Boolean, null],
|
|
80
|
+
default: () => false,
|
|
81
|
+
},
|
|
82
|
+
width: {
|
|
83
|
+
type: [Number, String, null],
|
|
84
|
+
default: () => null,
|
|
85
|
+
},
|
|
86
|
+
height: {
|
|
87
|
+
type: [Number, String, null],
|
|
88
|
+
default: () => null,
|
|
89
|
+
},
|
|
90
|
+
duration: {
|
|
91
|
+
type: [Number, null],
|
|
92
|
+
default: () => 300,
|
|
93
|
+
},
|
|
94
|
+
swipeThreshold: {
|
|
95
|
+
type: [Number, null],
|
|
96
|
+
default: () => 0.35,
|
|
97
|
+
},
|
|
98
|
+
indicatorDots: {
|
|
99
|
+
type: [Boolean, null],
|
|
100
|
+
default: () => false,
|
|
101
|
+
},
|
|
102
|
+
indicatorColor: {
|
|
103
|
+
type: [String, null],
|
|
104
|
+
default: () => '#fff',
|
|
105
|
+
},
|
|
106
|
+
indicatorActiveColor: {
|
|
107
|
+
type: [String, null],
|
|
108
|
+
default: () => '#fff',
|
|
109
|
+
},
|
|
110
|
+
autoplay: {
|
|
111
|
+
type: [Boolean, null],
|
|
112
|
+
default: () => false,
|
|
113
|
+
},
|
|
114
|
+
interval: {
|
|
115
|
+
type: [Number, null],
|
|
116
|
+
default: () => 3000,
|
|
117
|
+
},
|
|
118
|
+
circular: {
|
|
119
|
+
type: [Boolean, null],
|
|
120
|
+
default: () => false,
|
|
121
|
+
},
|
|
122
|
+
previousMargin: {
|
|
123
|
+
type: [Number, String, null],
|
|
124
|
+
default: () => 0,
|
|
125
|
+
},
|
|
126
|
+
nextMargin: {
|
|
127
|
+
type: [Number, String, null],
|
|
128
|
+
default: () => 0,
|
|
129
|
+
},
|
|
130
|
+
},
|
|
131
|
+
data() {
|
|
132
|
+
return {
|
|
133
|
+
initializing: true,
|
|
134
|
+
moveing: false,
|
|
135
|
+
reseting: false,
|
|
136
|
+
dataIndex: 0,
|
|
137
|
+
touch: new TouchEvent(),
|
|
138
|
+
boxWidth: null,
|
|
139
|
+
boxHeight: null,
|
|
140
|
+
translateX: 0,
|
|
141
|
+
translateY: 0,
|
|
142
|
+
childrenTimeout: null, // 子元素更新定时器
|
|
143
|
+
durationTimeout: null, // 滑动动画时长定时器
|
|
144
|
+
autoplayTimeout: null, // 自动切换定时器
|
|
145
|
+
source: 'autoplay',
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
computed: {
|
|
149
|
+
cmpDuration() {
|
|
150
|
+
return this.autoplay && this.duration >= this.interval ? this.interval : this.duration;
|
|
151
|
+
},
|
|
152
|
+
cmpRootStyle() {
|
|
153
|
+
let width = this.direction === 'horizontal' ? '100%' : 'auto';
|
|
154
|
+
let height = this.direction === 'vertical' ? '100%' : 'auto';
|
|
155
|
+
if (this.width) width = utils.formatPx(this.width);
|
|
156
|
+
|
|
157
|
+
if (this.height) height = utils.formatPx(this.height);
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
'--swiper-width': width,
|
|
161
|
+
'--swiper-height': height,
|
|
162
|
+
'--swiper-indicator-color': this.indicatorColor,
|
|
163
|
+
'--swiper-indicator-active-color': this.indicatorActiveColor,
|
|
164
|
+
'--swiper-root-padding':
|
|
165
|
+
this.direction === 'horizontal'
|
|
166
|
+
? `0 ${utils.formatPx(this.nextMargin)} 0 ${utils.formatPx(this.previousMargin)}`
|
|
167
|
+
: `${utils.formatPx(this.previousMargin)} 0 ${utils.formatPx(this.nextMargin)} 0`,
|
|
168
|
+
};
|
|
169
|
+
},
|
|
170
|
+
cmpBoxStyle() {
|
|
171
|
+
let style = {};
|
|
172
|
+
if (this.direction === 'horizontal') {
|
|
173
|
+
style.gridTemplateColumns = `repeat(${this.children.length || 'auto-fill'}, 100%)`;
|
|
174
|
+
} else if (this.direction === 'vertical') {
|
|
175
|
+
style.gridTemplateRows = `repeat(${this.children.length || 'auto-fill'}, 100%)`;
|
|
176
|
+
}
|
|
177
|
+
return style;
|
|
178
|
+
},
|
|
179
|
+
cmpBoxTransform() {
|
|
180
|
+
let transform = '';
|
|
181
|
+
if (this.direction === 'horizontal') {
|
|
182
|
+
transform = `translateX(${this.translateX}px)`;
|
|
183
|
+
} else if (this.direction === 'vertical') {
|
|
184
|
+
transform = `translateY(${this.translateY}px)`;
|
|
185
|
+
}
|
|
186
|
+
const duration = this.initializing || this.moveing || this.reseting ? 'inherit' : `${this.cmpDuration}ms`;
|
|
187
|
+
return { transform, transitionDuration: duration };
|
|
188
|
+
},
|
|
189
|
+
cmpStartComponent() {
|
|
190
|
+
return this.children[0];
|
|
191
|
+
},
|
|
192
|
+
cmpEndComponent() {
|
|
193
|
+
return this.children[this.children.length - 1];
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
watch: {
|
|
197
|
+
current: {
|
|
198
|
+
handler(v) {
|
|
199
|
+
if (!this.children.length) {
|
|
200
|
+
this.dataIndex = v;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
this.dataIndex = v < 0 ? 0 : v >= this.children.length ? this.children.length - 1 : v;
|
|
204
|
+
},
|
|
205
|
+
immediate: true,
|
|
206
|
+
},
|
|
207
|
+
dataIndex: {
|
|
208
|
+
handler() {
|
|
209
|
+
if (!this.children.length) return;
|
|
210
|
+
this.$nextTick(async () => {
|
|
211
|
+
await this.getBoxSize();
|
|
212
|
+
this.setTransform();
|
|
213
|
+
});
|
|
214
|
+
},
|
|
215
|
+
immediate: true,
|
|
216
|
+
},
|
|
217
|
+
children: {
|
|
218
|
+
handler(v) {
|
|
219
|
+
if (!v || !v.length) return;
|
|
220
|
+
this.$nextTick(() => {
|
|
221
|
+
this.init();
|
|
222
|
+
});
|
|
223
|
+
},
|
|
224
|
+
immediate: true,
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
mounted() {
|
|
228
|
+
this.init();
|
|
229
|
+
},
|
|
230
|
+
beforeDestroy() {
|
|
231
|
+
clearTimeout(this.childrenTimeout);
|
|
232
|
+
clearTimeout(this.durationTimeout);
|
|
233
|
+
clearInterval(this.autoplayTimeout);
|
|
234
|
+
},
|
|
235
|
+
methods: {
|
|
236
|
+
init() {
|
|
237
|
+
clearTimeout(this.childrenTimeout);
|
|
238
|
+
this.childrenTimeout = setTimeout(async () => {
|
|
239
|
+
await this.getBoxSize();
|
|
240
|
+
this.setTransform();
|
|
241
|
+
this.resetBoundary();
|
|
242
|
+
this.setAutoplay();
|
|
243
|
+
|
|
244
|
+
setTimeout(() => {
|
|
245
|
+
this.initializing = false;
|
|
246
|
+
}, 25);
|
|
247
|
+
}, 25);
|
|
248
|
+
},
|
|
249
|
+
isMover(moveX = 0, moveY = 0) {
|
|
250
|
+
if (this.children.length < 2) return;
|
|
251
|
+
if (this.circular) return true;
|
|
252
|
+
if (
|
|
253
|
+
this.direction === 'horizontal' &&
|
|
254
|
+
((this.dataIndex === 0 && moveX > 0) || (this.dataIndex === this.children.length - 1 && moveX < 0))
|
|
255
|
+
) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
if (
|
|
259
|
+
this.direction === 'vertical' &&
|
|
260
|
+
((this.dataIndex === 0 && moveY > 0) || (this.dataIndex === this.children.length - 1 && moveY < 0))
|
|
261
|
+
) {
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
return true;
|
|
265
|
+
},
|
|
266
|
+
async getBoxSize() {
|
|
267
|
+
if (this.boxWidth > 0 && this.boxHeight > 0) return;
|
|
268
|
+
const boxEl = await utils.querySelector('.swipe-content-view', this);
|
|
269
|
+
this.boxWidth = boxEl.width;
|
|
270
|
+
this.boxHeight = boxEl.height;
|
|
271
|
+
},
|
|
272
|
+
setTransform(moveX = 0, moveY = 0) {
|
|
273
|
+
if (this.children?.length < 2) return;
|
|
274
|
+
const bool = this.isMover(moveX, moveY);
|
|
275
|
+
if (!bool) return;
|
|
276
|
+
if (this.direction === 'horizontal') {
|
|
277
|
+
if (Math.abs(moveX) < Math.abs(moveY)) return;
|
|
278
|
+
const translateX = -this.dataIndex * this.boxWidth + moveX;
|
|
279
|
+
if (moveX !== 0 && Math.abs(this.translateX - translateX) < 3) return;
|
|
280
|
+
this.translateX = translateX;
|
|
281
|
+
this.setBoundary(moveX);
|
|
282
|
+
} else if (this.direction === 'vertical') {
|
|
283
|
+
if (Math.abs(moveX) > Math.abs(moveY)) return;
|
|
284
|
+
const translateY = -this.dataIndex * this.boxHeight + moveY;
|
|
285
|
+
if (moveY !== 0 && Math.abs(this.translateY - translateY) < 3) return;
|
|
286
|
+
this.translateY = translateY;
|
|
287
|
+
this.setBoundary(0, moveY);
|
|
288
|
+
}
|
|
289
|
+
},
|
|
290
|
+
async onTouchstart(e) {
|
|
291
|
+
if (this.disabled) return;
|
|
292
|
+
if (this.children?.length < 2) return;
|
|
293
|
+
this.moveing = true;
|
|
294
|
+
await this.getBoxSize();
|
|
295
|
+
clearInterval(this.autoplayTimeout);
|
|
296
|
+
this.resetBoundary();
|
|
297
|
+
this.touch.touchStart(e);
|
|
298
|
+
},
|
|
299
|
+
onTouchmove(e) {
|
|
300
|
+
if (this.disabled) return;
|
|
301
|
+
if (this.children?.length < 2) return;
|
|
302
|
+
const res = this.touch.touchMove(e);
|
|
303
|
+
if (!res) return;
|
|
304
|
+
this.moveing = true;
|
|
305
|
+
let { moveX, moveY } = res;
|
|
306
|
+
this.setTransform(moveX, moveY);
|
|
307
|
+
},
|
|
308
|
+
onTouchend(e) {
|
|
309
|
+
this.moveing = false;
|
|
310
|
+
clearTimeout(this.durationTimeout);
|
|
311
|
+
this.durationTimeout = setTimeout(() => {
|
|
312
|
+
this.setAutoplay();
|
|
313
|
+
this.resetBoundary();
|
|
314
|
+
}, this.cmpDuration);
|
|
315
|
+
|
|
316
|
+
if (this.disabled) return;
|
|
317
|
+
const { moveX, moveY } = this.touch.touchEnd(e);
|
|
318
|
+
if (this.direction === 'horizontal' && !moveX) return;
|
|
319
|
+
else if (this.direction === 'vertical' && !moveY) return;
|
|
320
|
+
const bool = this.isMover(moveX, moveY);
|
|
321
|
+
if (!bool) return;
|
|
322
|
+
|
|
323
|
+
let index = this.dataIndex;
|
|
324
|
+
if (this.direction === 'horizontal' && Math.abs(moveX) > this.boxWidth * this.swipeThreshold) {
|
|
325
|
+
index = moveX > 0 ? index - 1 : index + 1;
|
|
326
|
+
} else if (this.direction === 'vertical' && Math.abs(moveY) > this.boxHeight * this.swipeThreshold) {
|
|
327
|
+
index = moveY > 0 ? index - 1 : index + 1;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (this.dataIndex === index) {
|
|
331
|
+
this.setTransform();
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
this.source = 'touch';
|
|
335
|
+
this.dataIndex = index;
|
|
336
|
+
if (index < 0 || index >= this.children.length) return;
|
|
337
|
+
this.$emit('change', index, this.source);
|
|
338
|
+
},
|
|
339
|
+
setAutoplay() {
|
|
340
|
+
clearInterval(this.autoplayTimeout);
|
|
341
|
+
this.autoplayTimeout = setInterval(() => {
|
|
342
|
+
if (!this.autoplay || this.children?.length < 2) {
|
|
343
|
+
clearInterval(this.autoplayTimeout);
|
|
344
|
+
return;
|
|
345
|
+
}
|
|
346
|
+
let next = this.dataIndex + 1 <= this.children.length - 1 ? this.dataIndex + 1 : 0;
|
|
347
|
+
if (this.circular) {
|
|
348
|
+
next = this.dataIndex + 1;
|
|
349
|
+
}
|
|
350
|
+
this.setBoundary(-1, -1);
|
|
351
|
+
this.source = 'autoplay';
|
|
352
|
+
this.dataIndex = next;
|
|
353
|
+
if (next >= 0 && next <= this.children.length - 1) this.$emit('change', next, this.source);
|
|
354
|
+
clearTimeout(this.durationTimeout);
|
|
355
|
+
this.durationTimeout = setTimeout(() => {
|
|
356
|
+
this.resetBoundary();
|
|
357
|
+
}, this.cmpDuration - 20);
|
|
358
|
+
}, this.interval);
|
|
359
|
+
},
|
|
360
|
+
setBoundary(moveX = 0, moveY = 0) {
|
|
361
|
+
if (!this.circular) return;
|
|
362
|
+
if (this.children?.length < 2) return;
|
|
363
|
+
const startComponent = this.cmpStartComponent;
|
|
364
|
+
const endComponent = this.cmpEndComponent;
|
|
365
|
+
const length = this.children.length;
|
|
366
|
+
const width = this.boxWidth;
|
|
367
|
+
const height = this.boxHeight;
|
|
368
|
+
if (this.dataIndex <= 0) {
|
|
369
|
+
startComponent.setTransform({});
|
|
370
|
+
if (this.direction === 'horizontal' && moveX > 0) {
|
|
371
|
+
endComponent.setTransform({ x: -length * width });
|
|
372
|
+
} else if (this.direction === 'vertical' && moveY > 0) {
|
|
373
|
+
endComponent.setTransform({ y: -length * height });
|
|
374
|
+
}
|
|
375
|
+
} else if (this.dataIndex >= length - 1) {
|
|
376
|
+
endComponent.setTransform({});
|
|
377
|
+
if (this.direction === 'horizontal' && moveX < 0) {
|
|
378
|
+
startComponent.setTransform({ x: length * width });
|
|
379
|
+
} else if (this.direction === 'vertical' && moveY < 0) {
|
|
380
|
+
startComponent.setTransform({ y: length * height });
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
resetBoundary() {
|
|
385
|
+
this.reseting = true;
|
|
386
|
+
setTimeout(() => {
|
|
387
|
+
let change = false;
|
|
388
|
+
if (this.dataIndex === -1) {
|
|
389
|
+
this.dataIndex = this.children.length - 1;
|
|
390
|
+
change = true;
|
|
391
|
+
} else if (this.dataIndex === this.children.length) {
|
|
392
|
+
this.dataIndex = 0;
|
|
393
|
+
change = true;
|
|
394
|
+
}
|
|
395
|
+
if (change) {
|
|
396
|
+
this.$emit('change', this.dataIndex, this.source);
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
const length = this.children.length;
|
|
400
|
+
this.children.forEach((component, index) => {
|
|
401
|
+
let x = 0,
|
|
402
|
+
y = 0;
|
|
403
|
+
if (this.circular) {
|
|
404
|
+
if (index === length - 1 && this.dataIndex === 0 && length > 2) {
|
|
405
|
+
x = this.direction === 'horizontal' ? -length * this.boxWidth : 0;
|
|
406
|
+
y = this.direction === 'vertical' ? -length * this.boxHeight : 0;
|
|
407
|
+
} else if (index === 0 && this.dataIndex === length - 1 && length > 2) {
|
|
408
|
+
x = this.direction === 'horizontal' ? length * this.boxWidth : 0;
|
|
409
|
+
y = this.direction === 'vertical' ? length * this.boxHeight : 0;
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
component?.setTransform({ x, y });
|
|
413
|
+
});
|
|
414
|
+
setTimeout(() => {
|
|
415
|
+
this.reseting = false;
|
|
416
|
+
}, 50);
|
|
417
|
+
}, 50);
|
|
418
|
+
},
|
|
419
|
+
},
|
|
420
|
+
};
|
|
421
|
+
</script>
|
|
422
|
+
|
|
423
|
+
<style lang="scss" scoped>
|
|
424
|
+
.ste-swiper-root {
|
|
425
|
+
width: var(--swiper-width);
|
|
426
|
+
height: var(--swiper-height);
|
|
427
|
+
overflow: hidden;
|
|
428
|
+
padding: var(--swiper-root-padding);
|
|
429
|
+
position: relative;
|
|
430
|
+
.swipe-content {
|
|
431
|
+
width: var(--swiper-width);
|
|
432
|
+
height: var(--swiper-height);
|
|
433
|
+
.swipe-content-view {
|
|
434
|
+
width: var(--swiper-width);
|
|
435
|
+
height: var(--swiper-height);
|
|
436
|
+
display: grid;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
.ste-swiper-dots {
|
|
440
|
+
position: absolute;
|
|
441
|
+
bottom: 18rpx;
|
|
442
|
+
z-index: 1;
|
|
443
|
+
left: 50%;
|
|
444
|
+
transform: translateX(-50%);
|
|
445
|
+
display: flex;
|
|
446
|
+
align-items: center;
|
|
447
|
+
.swiper-dots-item {
|
|
448
|
+
width: 8rpx;
|
|
449
|
+
height: 8rpx;
|
|
450
|
+
border-radius: 6rpx;
|
|
451
|
+
background-color: var(--swiper-indicator-color);
|
|
452
|
+
&.active {
|
|
453
|
+
width: 24rpx;
|
|
454
|
+
background-color: var(--swiper-indicator-active-color);
|
|
455
|
+
}
|
|
456
|
+
& + .swiper-dots-item {
|
|
457
|
+
margin-left: 8rpx;
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
</style>
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<view class="ste-swiper-item-root" :style="[cmpStyle]">
|
|
3
|
+
<slot></slot>
|
|
4
|
+
</view>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script>
|
|
8
|
+
import { childMixin } from '../../utils/mixin.js';
|
|
9
|
+
export default {
|
|
10
|
+
name: 'ste-swiper-item',
|
|
11
|
+
mixins: [childMixin('ste-swiper')],
|
|
12
|
+
data() {
|
|
13
|
+
return {
|
|
14
|
+
transformX: 0,
|
|
15
|
+
transformY: 0,
|
|
16
|
+
transformZ: 0,
|
|
17
|
+
};
|
|
18
|
+
},
|
|
19
|
+
computed: {
|
|
20
|
+
cmpStyle() {
|
|
21
|
+
return {
|
|
22
|
+
transform: `translate3d(${this.transformX}px,${this.transformY}px,${this.transformZ}px)`,
|
|
23
|
+
};
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
methods: {
|
|
27
|
+
setTransform({ x = 0, y = 0, z = 0 }) {
|
|
28
|
+
if (this.transformX !== x) this.transformX = x;
|
|
29
|
+
if (this.transformY !== y) this.transformY = y;
|
|
30
|
+
if (this.transformZ !== z) this.transformZ = z;
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
</script>
|
|
35
|
+
|
|
36
|
+
<style>
|
|
37
|
+
.ste-swiper-item-root {
|
|
38
|
+
width: 100%;
|
|
39
|
+
height: 100%;
|
|
40
|
+
}
|
|
41
|
+
</style>
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# Switch 开关
|
|
2
|
+
|
|
3
|
+
表示两种相互对立的状态间的切换,多用于触发「开/关」。
|
|
4
|
+
|
|
5
|
+
---$
|
|
6
|
+
|
|
7
|
+
### 代码演示
|
|
8
|
+
JavaScript后面的演示代码中涉及到的变量和方法都使用本javasaript代码
|
|
9
|
+
```javascript
|
|
10
|
+
export default {
|
|
11
|
+
data() {
|
|
12
|
+
return {
|
|
13
|
+
value1: false,
|
|
14
|
+
value2: true,
|
|
15
|
+
value3: false,
|
|
16
|
+
value4: false,
|
|
17
|
+
value5: false,
|
|
18
|
+
value6: false,
|
|
19
|
+
value7: false,
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
methods: {
|
|
23
|
+
click1(value) {
|
|
24
|
+
this.showToast({
|
|
25
|
+
icon: 'none',
|
|
26
|
+
title: `点击:${value} 开关的值`,
|
|
27
|
+
});
|
|
28
|
+
},
|
|
29
|
+
click2(value, allowStop, resolve) {
|
|
30
|
+
this.showToast({
|
|
31
|
+
icon: 'none',
|
|
32
|
+
title: `点击:${value} 开关的值`,
|
|
33
|
+
});
|
|
34
|
+
// 阻止change事件
|
|
35
|
+
allowStop();
|
|
36
|
+
},
|
|
37
|
+
change(value) {
|
|
38
|
+
setTimeout(() => {
|
|
39
|
+
this.showToast({
|
|
40
|
+
icon: 'none',
|
|
41
|
+
title: `改变:${value} 开关的值`,
|
|
42
|
+
});
|
|
43
|
+
}, 1000);
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
#### 基础用法
|
|
50
|
+
通过`value`属性,双向绑定,绑定开关的选中状态,`true` 表示开,`false` 表示关。
|
|
51
|
+
```
|
|
52
|
+
<ste-switch v-model="value1"></ste-switch>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
#### 只读
|
|
56
|
+
通过`readonly `属性,设置只读,不可切换,样式不置灰 默认`false`。
|
|
57
|
+
```
|
|
58
|
+
<ste-switch v-model="value2" readonly></ste-switch>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
#### 禁用
|
|
62
|
+
通过`disabled`属性,设置禁用,不可切换,样式置灰,默认`false`。
|
|
63
|
+
```
|
|
64
|
+
<ste-switch v-model="value2" disabled></ste-switch>
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
#### 自定义大小
|
|
68
|
+
通过 `size` 属性自定义开关的大小,默认`52`。
|
|
69
|
+
```
|
|
70
|
+
<ste-switch v-model="value3" size="100"></ste-switch>
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
#### 自定义颜色
|
|
74
|
+
通过 `activeColor` 属性自定义开关的激活颜色,默认`#0090FF`。
|
|
75
|
+
通过 `inactiveColor` 属性自定义开关的激活颜色,默认`#bbbbbb`。
|
|
76
|
+
```
|
|
77
|
+
<ste-switch v-model="value4" activeColor="#13CE66" inactiveColor="#FF4949"></ste-switch>
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
#### 加载状态
|
|
81
|
+
通过 `loading` 属性设置开关为加载状态,加载状态下开关不可点击,默认`false`。
|
|
82
|
+
```
|
|
83
|
+
<ste-switch v-model="value2" loading></ste-switch>
|
|
84
|
+
<ste-switch v-model="value5" loading></ste-switch>
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---$
|
|
88
|
+
### API
|
|
89
|
+
#### 组件属性(Props)
|
|
90
|
+
|
|
91
|
+
| 参数 | 说明 | 类型 | 默认值 | 可选值 | 支持版本 |
|
|
92
|
+
| --- | --- | --- | --- | --- | --- |
|
|
93
|
+
| `value` | 开关状态(支持`v-model`双向绑定) | `Boolean` | `false` | - | - |
|
|
94
|
+
| `disabled` | 是否禁用 | `Boolean` | `false` | - | - |
|
|
95
|
+
| `readonly` | 只读(不置灰) | `Boolean` | `false` | - | - |
|
|
96
|
+
| `size` | 开关大小,单位`rpx` | `Number/String` | `52` | - | - |
|
|
97
|
+
| `activeColor` | 激活时颜色 | `String` | `#0090FF` | - | - |
|
|
98
|
+
| `inactiveColor` | 未激活颜色 | `String` | `#bbbbbb` | - | - |
|
|
99
|
+
| `loading` | 加载中 | `Boolean` | `false` | - | - |
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
#### Events
|
|
103
|
+
|事件名 |说明 |事件参数 |支持版本 |
|
|
104
|
+
|--- |--- |--- |--- |
|
|
105
|
+
| `click` |点击开关时触发的事件(可拦截change事件) |`value`:当前的绑定值,`allowStop`:允许阻止后续的事件触发,:`resolve`:后续的事件执行 | - |
|
|
106
|
+
| `change` |当绑定值变化时触发的事件 |`value`:改变后的绑定值 | - |
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
---$
|
|
110
|
+
{{qinpengfei}}
|