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.
Files changed (141) hide show
  1. package/common/css/common.scss +61 -0
  2. package/components/ste-animate/README.md +117 -0
  3. package/components/ste-animate/animate.scss +247 -0
  4. package/components/ste-animate/ste-animate.vue +200 -0
  5. package/components/ste-badge/README.md +171 -0
  6. package/components/ste-badge/ste-badge.vue +238 -0
  7. package/components/ste-barcode/README.md +36 -0
  8. package/components/ste-barcode/encode2.js +317 -0
  9. package/components/ste-barcode/ste-barcode.vue +213 -0
  10. package/components/ste-button/README.md +129 -0
  11. package/components/ste-button/ste-button.vue +345 -0
  12. package/components/ste-calendar/README.md +304 -0
  13. package/components/ste-calendar/self-date.js +119 -0
  14. package/components/ste-calendar/ste-calendar.vue +578 -0
  15. package/components/ste-checkbox/README.md +297 -0
  16. package/components/ste-checkbox/ste-checkbox.vue +305 -0
  17. package/components/ste-checkbox-group/ste-checkbox-group.vue +133 -0
  18. package/components/ste-code-input/README.md +67 -0
  19. package/components/ste-code-input/ste-code-input.vue +302 -0
  20. package/components/ste-date-picker/README.md +135 -0
  21. package/components/ste-date-picker/ste-date-picker.vue +407 -0
  22. package/components/ste-drag/README.md +103 -0
  23. package/components/ste-drag/ste-drag.vue +203 -0
  24. package/components/ste-dropdown-menu/README.md +358 -0
  25. package/components/ste-dropdown-menu/ste-dropdown-menu.vue +405 -0
  26. package/components/ste-dropdown-menu-item/ste-dropdown-menu-item.vue +176 -0
  27. package/components/ste-icon/README.md +90 -0
  28. package/components/ste-icon/iconfont.css +8 -0
  29. package/components/ste-icon/ste-icon.vue +147 -0
  30. package/components/ste-image/README.md +154 -0
  31. package/components/ste-image/ste-image.vue +218 -0
  32. package/components/ste-index-item/ste-index-item.vue +96 -0
  33. package/components/ste-index-list/README.md +153 -0
  34. package/components/ste-index-list/ste-index-list.vue +128 -0
  35. package/components/ste-input/README.md +146 -0
  36. package/components/ste-input/ste-input.vue +480 -0
  37. package/components/ste-loading/README.md +81 -0
  38. package/components/ste-loading/ste-loading.vue +166 -0
  39. package/components/ste-media-preview/README.md +243 -0
  40. package/components/ste-media-preview/TouchScaleing.js +102 -0
  41. package/components/ste-media-preview/ste-media-preview.vue +267 -0
  42. package/components/ste-message-box/README.md +217 -0
  43. package/components/ste-message-box/ste-message-box.js +72 -0
  44. package/components/ste-message-box/ste-message-box.vue +380 -0
  45. package/components/ste-notice-bar/README.md +129 -0
  46. package/components/ste-notice-bar/ste-notice-bar.vue +331 -0
  47. package/components/ste-number-keyboard/README.md +246 -0
  48. package/components/ste-number-keyboard/keyboard.vue +140 -0
  49. package/components/ste-number-keyboard/ste-number-keyboard.vue +240 -0
  50. package/components/ste-picker/ste-picker.vue +258 -0
  51. package/components/ste-popup/README.md +148 -0
  52. package/components/ste-popup/ste-popup.vue +337 -0
  53. package/components/ste-price/README.md +129 -0
  54. package/components/ste-price/ste-price.vue +258 -0
  55. package/components/ste-progress/README.md +87 -0
  56. package/components/ste-progress/ste-progress.vue +200 -0
  57. package/components/ste-qrcode/README.md +50 -0
  58. package/components/ste-qrcode/ste-qrcode.vue +164 -0
  59. package/components/ste-qrcode/uqrcode.js +34 -0
  60. package/components/ste-radio/README.md +286 -0
  61. package/components/ste-radio/ste-radio.vue +293 -0
  62. package/components/ste-radio-group/ste-radio-group.vue +128 -0
  63. package/components/ste-rate/README.md +115 -0
  64. package/components/ste-rate/ste-rate.vue +202 -0
  65. package/components/ste-read-more/README.md +111 -0
  66. package/components/ste-read-more/ste-read-more.vue +133 -0
  67. package/components/ste-rich-text/README.md +31 -0
  68. package/components/ste-rich-text/ste-rich-text.vue +70 -0
  69. package/components/ste-scroll-to/README.md +68 -0
  70. package/components/ste-scroll-to/mixin.js +173 -0
  71. package/components/ste-scroll-to/ste-scroll-to.vue +45 -0
  72. package/components/ste-scroll-to-item/ste-scroll-to-item.vue +25 -0
  73. package/components/ste-search/README.md +262 -0
  74. package/components/ste-search/ste-search.vue +547 -0
  75. package/components/ste-select/README.md +434 -0
  76. package/components/ste-select/datapager.vue +62 -0
  77. package/components/ste-select/datetime.vue +106 -0
  78. package/components/ste-select/defaultDate.js +142 -0
  79. package/components/ste-select/ste-select.vue +843 -0
  80. package/components/ste-signature/README.md +105 -0
  81. package/components/ste-signature/ste-signature.vue +220 -0
  82. package/components/ste-slider/README.md +165 -0
  83. package/components/ste-slider/ste-slider.vue +544 -0
  84. package/components/ste-step/ste-step.vue +264 -0
  85. package/components/ste-stepper/README.md +170 -0
  86. package/components/ste-stepper/ste-stepper.vue +373 -0
  87. package/components/ste-steps/README.md +132 -0
  88. package/components/ste-steps/ste-steps.vue +65 -0
  89. package/components/ste-sticky/README.md +52 -0
  90. package/components/ste-sticky/ste-sticky.vue +127 -0
  91. package/components/ste-swipe-action/README.md +197 -0
  92. package/components/ste-swipe-action/ste-swipe-action.vue +303 -0
  93. package/components/ste-swipe-action-group/ste-swipe-action-group.vue +104 -0
  94. package/components/ste-swiper/README.md +173 -0
  95. package/components/ste-swiper/ste-swiper.vue +462 -0
  96. package/components/ste-swiper-item/ste-swiper-item.vue +41 -0
  97. package/components/ste-switch/README.md +110 -0
  98. package/components/ste-switch/ste-switch.vue +144 -0
  99. package/components/ste-tab/ste-tab.vue +87 -0
  100. package/components/ste-table/README.md +785 -0
  101. package/components/ste-table/common.js +8 -0
  102. package/components/ste-table/ste-table.vue +666 -0
  103. package/components/ste-table/utils.js +20 -0
  104. package/components/ste-table-column/checkbox-icon.vue +65 -0
  105. package/components/ste-table-column/common.scss +65 -0
  106. package/components/ste-table-column/radio-icon.vue +110 -0
  107. package/components/ste-table-column/ste-table-column.vue +255 -0
  108. package/components/ste-table-column/sub-table.vue +116 -0
  109. package/components/ste-table-column/table-popover.vue +204 -0
  110. package/components/ste-table-column/var.scss +1 -0
  111. package/components/ste-tabs/README.md +475 -0
  112. package/components/ste-tabs/props.js +212 -0
  113. package/components/ste-tabs/ste-tabs.vue +758 -0
  114. package/components/ste-text/README.md +66 -0
  115. package/components/ste-text/ste-text.vue +72 -0
  116. package/components/ste-toast/README.md +243 -0
  117. package/components/ste-toast/ste-toast.js +69 -0
  118. package/components/ste-toast/ste-toast.vue +231 -0
  119. package/components/ste-touch-swipe/README.md +104 -0
  120. package/components/ste-touch-swipe/TouchEvent.js +72 -0
  121. package/components/ste-touch-swipe/ste-touch-swipe.vue +327 -0
  122. package/components/ste-touch-swipe-item/ste-touch-swipe-item.vue +33 -0
  123. package/components/ste-tour/README.md +194 -0
  124. package/components/ste-tour/ste-tour.vue +355 -0
  125. package/components/ste-tree/README.md +240 -0
  126. package/components/ste-tree/ste-tree.vue +350 -0
  127. package/components/ste-upload/README.md +276 -0
  128. package/components/ste-upload/ReadFile.js +229 -0
  129. package/components/ste-upload/ste-upload.vue +526 -0
  130. package/components/ste-video/README.md +60 -0
  131. package/components/ste-video/props.js +149 -0
  132. package/components/ste-video/ste-video.vue +647 -0
  133. package/config/color.js +22 -0
  134. package/index.js +2 -0
  135. package/package.json +19 -0
  136. package/utils/Color.js +66 -0
  137. package/utils/System.js +110 -0
  138. package/utils/dayjs.min.js +1 -0
  139. package/utils/mixin.js +67 -0
  140. package/utils/store.js +7 -0
  141. package/utils/utils.js +604 -0
@@ -0,0 +1,127 @@
1
+ <template>
2
+ <view class="ste-sticky" :id="elId" :style="[cmpRootStyle]">
3
+ <slot />
4
+ </view>
5
+ </template>
6
+
7
+ <script>
8
+ import utils from '../../utils/utils';
9
+ /**
10
+ * sticky 吸顶
11
+ * @description 该组件与CSS中position: sticky属性实现的效果一致,当组件达到预设的到顶部距离时, 就会固定在指定位置,组件位置大于预设的顶部距离时,会重新按照正常的布局排列。
12
+ * @tutorial https://stellar-ui.intecloud.com.cn/pc/index/index?name=ste-sticky
13
+ * @property {String | Number} offsetTop 吸顶时与顶部的距离,单位rpx(默认 0 )
14
+ * @property {String | Number} customNavHeight 航栏的高度(没有导航栏时,请设置为0)
15
+ * @property {Boolean} disabled 是否开启吸顶功能 (默认 false )
16
+ * @property {String} background 组件背景,默认#fff
17
+ * @property {String | Number} zIndex 吸顶时的z-index值
18
+ * @event {Function} fixed 组件吸顶时触发
19
+ * @event {Function} unfixed 组件取消吸顶时触发
20
+ * @example <ste-sticky offsetTop="200"><view>塞下秋来风景异,衡阳雁去无留意</view></ste-sticky>
21
+ */
22
+ export default {
23
+ name: 'ste-sticky',
24
+ group: '基础组件',
25
+ title: 'Sticky 吸顶',
26
+ props: {
27
+ // 吸顶容器到顶部某个距离的时候,进行吸顶
28
+ offsetTop: {
29
+ type: [String, Number, null],
30
+ default: 0,
31
+ },
32
+ // 导航栏的高度(如果没有导航栏请设置为0)
33
+ customNavHeight: {
34
+ type: [String, Number, null],
35
+ default: () => null,
36
+ },
37
+ // 是否禁用吸顶功能
38
+ disabled: {
39
+ type: [Boolean, null],
40
+ default: () => false,
41
+ },
42
+ // 吸顶区域的背景
43
+ background: {
44
+ type: [String, null],
45
+ default: () => '#fff',
46
+ },
47
+ // z-index值
48
+ zIndex: {
49
+ type: [String, Number, null],
50
+ default: () => 98,
51
+ },
52
+ },
53
+ data() {
54
+ return {
55
+ elId: utils.guid(),
56
+ };
57
+ },
58
+ computed: {
59
+ cmpRootStyle() {
60
+ const style = {
61
+ ...utils.bg2style(this.background),
62
+ };
63
+ if (!this.disabled) {
64
+ style.position = 'sticky';
65
+ style.zIndex = this.zIndex;
66
+ style.top = utils.formatPx(this.offsetTop);
67
+ }
68
+ return style;
69
+ },
70
+ relativeToViewportTop() {
71
+ let customNavHeight = 0;
72
+ if (this.customNavHeight === null) {
73
+ // #ifdef H5
74
+ customNavHeight = 44;
75
+ // #endif
76
+ // #ifndef H5
77
+ customNavHeight = utils.System.getNavbarBottom();
78
+ // #endif
79
+ } else {
80
+ customNavHeight = utils.formatPx(this.customNavHeight, 'num');
81
+ }
82
+ return customNavHeight + utils.formatPx(this.offsetTop, 'num');
83
+ },
84
+ },
85
+ mounted() {
86
+ if (this.disabled) return;
87
+ setTimeout(() => {
88
+ this.observeContent();
89
+ }, 20);
90
+ },
91
+ methods: {
92
+ observeContent() {
93
+ // 先断掉之前的观察
94
+ this.disconnectObserver('contentObserver');
95
+ const contentObserver = uni.createIntersectionObserver(this, {
96
+ thresholds: [0.8, 1],
97
+ });
98
+ // 到屏幕顶部的高度时触发
99
+ contentObserver.relativeToViewport({ top: -(this.relativeToViewportTop + 1) });
100
+ // 绑定观察的元素
101
+ contentObserver.observe(`#${this.elId}`, (res) => {
102
+ this.setFixed(res.boundingClientRect.top);
103
+ });
104
+ this.contentObserver = contentObserver;
105
+ },
106
+ setFixed(top) {
107
+ const bool = top <= this.relativeToViewportTop;
108
+ // 判断是否处于吸顶条件范围
109
+ if (bool) this.$emit('fixed');
110
+ else this.$emit('unfixed');
111
+ },
112
+ disconnectObserver(observerName) {
113
+ const observer = this[observerName];
114
+ observer && observer.disconnect();
115
+ },
116
+ },
117
+ destroyed() {
118
+ this.disconnectObserver();
119
+ },
120
+ };
121
+ </script>
122
+
123
+ <style lang="scss" scoped>
124
+ .ste-sticky {
125
+ width: 100%;
126
+ }
127
+ </style>
@@ -0,0 +1,197 @@
1
+ # SwipeAction 滑动单元格
2
+ - 该组件一般用于左滑唤出操作菜单的场景,用的最多的是左滑删除操作。
3
+ - 如果把该组件通过v-for用于左滑删除的列表,请保证循环的:key是一个唯一值,可以用数据的id或者title替代。 不能是数组循环的index,否则删除的时候,可能会出现数据错乱
4
+
5
+ ---$
6
+
7
+ ### 代码演示
8
+ - 演示代码中公用css样式
9
+ ```css
10
+ .content-view {
11
+ height: 90rpx;
12
+ border-bottom: 1px solid #fff;
13
+ background-color: #f5f5f5;
14
+ }
15
+ .test-btn {
16
+ background-color: #dd524d;
17
+ color: #fff;
18
+ line-height: 90rpx;
19
+ text-align: center;
20
+ width: 100rpx;
21
+ height: 100%;
22
+ }
23
+ ```
24
+
25
+ #### 基础用法
26
+ - 插槽`default`为单元格内容区域
27
+ - 插槽`right`为单元格右侧内容区域
28
+ ```html
29
+ <ste-swipe-action>
30
+ <view class="content-view">内容区域</view>
31
+ <template v-slot:right>
32
+ <div class="test-btn">删除</div>
33
+ </template>
34
+ </ste-swipe-action>
35
+ ```
36
+ #### 调用方法打开或关闭
37
+ - 方法`open`可打开单元格
38
+ - 参数为需要打开的方向(默认同mode)
39
+ - 方法`close`可关闭单元格
40
+ ```html
41
+ <ste-swipe-action ref="swipe">
42
+ <view class="content-view">内容区域</view>
43
+ <template v-slot:right>
44
+ <div class="test-btn">删除</div>
45
+ </template>
46
+ </ste-swipe-action>
47
+ <ste-button mode="200" @click="openSwipe">打开</ste-button>
48
+ <ste-button mode="200" @click="closeSwipe">关闭</ste-button>
49
+ <script>
50
+ export default {
51
+ methods:{
52
+ openSwipe() {
53
+ this.$refs.swipe.open();
54
+ },
55
+ closeSwipe() {
56
+ this.$refs.swipe.close();
57
+ },
58
+ }
59
+ }
60
+ </script>
61
+ ```
62
+ #### 滑动方向、开关按钮
63
+ - 属性`mode`可以设置滑动方向,默认为`right`,可选值为`left`、`all`
64
+ - 属性`leftIcon`和`rightIcon`可以设置是否显示开关按钮
65
+ - 事件`open`可以监听单元格的打开
66
+ - 参数为打开的方向
67
+ - 事件`close`可以监听单元格的关闭
68
+
69
+ ```html
70
+ <ste-swipe-action mode="all" @open="onOpen" @close="onClose" leftIcon rightIcon>
71
+ <template v-slot:left>
72
+ <div class="test-btn">收藏</div>
73
+ </template>
74
+ <view class="content-view">内容区域</view>
75
+ <template v-slot:right>
76
+ <div class="test-btn">删除</div>
77
+ </template>
78
+ </ste-swipe-action>
79
+ <script>
80
+ export default{
81
+ methods:{
82
+ onOpen(direction) {
83
+ this.showToast({
84
+ title: `打开方向:${direction}`,
85
+ icon: 'none',
86
+ });
87
+ },
88
+ onClose() {
89
+ this.showToast({
90
+ title: '关闭',
91
+ icon: 'none',
92
+ });
93
+ },
94
+ }
95
+ }
96
+ </script>
97
+ ```
98
+ #### 单元格组
99
+ - 标签`ste-swipe-action-group`用于包裹多个单元格
100
+ - 事件`open`监听组内单元格的开启
101
+ - 第一个参数为打开的方向
102
+ - 第二个参数为打开的单元格索引
103
+ - 事件`close`监听组内单元格的关闭
104
+ - 参数为关闭的单元格索引
105
+ - 方法`open`可以用于打开指定单元格
106
+ - 参数1为需要打开的方向(默认同mode)
107
+ - 参数2为需要打开的单元格索引
108
+ - 方法`close`可以用于关闭指定单元格
109
+ - 参数为需要关闭的单元格索引
110
+ ```html
111
+ <ste-swipe-action-group @open="onOpen" @close="onClose" ref="swipeGroup">
112
+ <ste-swipe-action>
113
+ <view class="content-view">11111</view>
114
+ <template v-slot:right>
115
+ <div class="test-btn">删除</div>
116
+ </template>
117
+ </ste-swipe-action>
118
+ <ste-swipe-action>
119
+ <view class="content-view">22222</view>
120
+ <template v-slot:right>
121
+ <div class="test-btn">删除</div>
122
+ </template>
123
+ </ste-swipe-action>
124
+ </ste-swipe-action-group>
125
+ <view style="margin-top: 12rpx">
126
+ <ste-button mode="200" @click="openSwipeGroup(0)">打开第1行</ste-button>
127
+ <ste-button mode="200" @click="closeSwipeGroup(0)">关闭第1行</ste-button>
128
+ <ste-button mode="200" @click="openSwipeGroup(1)">打开第2行</ste-button>
129
+ <ste-button mode="200" @click="closeSwipeGroup(1)">关闭第2行</ste-button>
130
+ </view>
131
+
132
+ <script>
133
+ export default {
134
+ methods:{
135
+ openSwipeGroup(index) {
136
+ this.$refs.swipeGroup.open('right', index);
137
+ },
138
+ closeSwipeGroup(index) {
139
+ this.$refs.swipeGroup.close(index);
140
+ },
141
+ }
142
+ }
143
+ </script>
144
+ ```
145
+
146
+ ---$
147
+ ### API
148
+ #### SwipeAction Props
149
+
150
+ | 属性名 | 说明 | 类型 | 默认值 | 可选值 | 支持版本 |
151
+ | ----- | ----- | ----- | ----- | ----- | ----- |
152
+ | `mode` | 模式 | `String` | `right` | `right`:右侧滑动<br/>`left`:左侧滑动<br/>`all`:左右滑动 | - |
153
+ | `disabled` | 禁用 | `Boolean` | `false` | - | - |
154
+ | `swipeThreshold`| 灵敏度(0-1之间的小数,数值越小灵敏度越高) | `Number` | `0.35` | - | - |
155
+ | `duration` | 动画时长,单位ms | `Number`,`String` | `300` | - | - |
156
+ | `leftIcon` | 是否显示左侧图标 | `Boolean` | `false` | - | - |
157
+ | `rightIcon` | 是否显示右侧图标 | `Boolean` | `false` | - | - |
158
+
159
+ #### SwipeAction Method
160
+ |方法名 |说明 |方法参数 |支持版本 |
161
+ | --- | --- | --- | --- |
162
+ | `open` | 打开滑块,参数为方向 | `left`/`right`:需要打开的方向,默认同`mode` | - |
163
+ | `close` | 关闭滑块 | - | - |
164
+
165
+ #### SwipeAction Events
166
+ |事件名 |说明 |事件参数 |支持版本 |
167
+ | --- | --- | --- | --- |
168
+ | `open` | 打开滑块时触发,参数为方向 | `left`/`right`:打开的方向 | - |
169
+ | `close` | 关闭滑块时触发 | - | - |
170
+
171
+ #### SwipeActionGroup Props
172
+
173
+ | 属性名 | 说明 | 类型 | 默认值 | 可选值 | 支持版本 |
174
+ | ----- | ----- | ----- | ----- | ----- | ----- |
175
+ | `mode` | 模式 | `String` | `right` | `right`:右侧滑动<br/>`left`:左侧滑动<br/>`all`:左右滑动 | - |
176
+ | `autoClose` | 是否自动关闭其他swipe | `Boolean` | `true` | - | - |
177
+ | `disabled` | 禁用 | `Boolean` | `false` | - | - |
178
+ | `swipeThreshold`| 灵敏度(0-1之间的小数,数值越小灵敏度越高) | `Number` | `0.35` | - | - |
179
+ | `duration` | 动画时长,单位ms | `Number`,`String` | `300` | - | - |
180
+ | `leftIcon` | 是否显示左侧图标 | `Boolean` | `false` | - | - |
181
+ | `rightIcon` | 是否显示右侧图标 | `Boolean` | `false` | - | - |
182
+
183
+ #### SwipeActionGroup Method
184
+ | 方法名 | 说明 | 方法参数 | 支持版本 |
185
+ | --- | --- | --- | --- |
186
+ | `open` | 打开滑块 | `left`/`right`:需要打开的方向,默认同`mode`,<br/>`index`:需要打开的下标 | - |
187
+ | `close` | 关闭滑块 | `index` | - |
188
+
189
+ #### SwipeActionGroup Events
190
+ | 事件名 | 说明 | 事件参数 | 支持版本 |
191
+ | --- | --- | --- | --- |
192
+ | `open` | 打开滑块时触发 | `left`/`right`:打开的方向,`index`:打开的下标 | - |
193
+ | `close` | 关闭滑块时触发 | - | - |
194
+
195
+
196
+ ---$
197
+ {{xuyajun}}
@@ -0,0 +1,303 @@
1
+ <template>
2
+ <view class="ste-swipe-action-root">
3
+ <view class="swipe-action-view" :style="[cmpTransform]">
4
+ <view class="swipe-action-left-icon" v-if="cmpLeftIcon" @click="iconOpen('left')">
5
+ <view class="swipe-icon" :class="{ active: dataTranslateX > 0 }">
6
+ <ste-icon code="&#xe674;" size="30rpx" />
7
+ </view>
8
+ </view>
9
+ <view class="swipe-action-right-icon" v-if="cmpRightIcon" @click="iconOpen('right')">
10
+ <view class="swipe-icon" :class="{ active: dataTranslateX < 0 }">
11
+ <ste-icon code="&#xe673;" size="30rpx" />
12
+ </view>
13
+ </view>
14
+ <view
15
+ @mousedown="onTouchstart"
16
+ @mousemove="onTouchmove"
17
+ @mouseup="onTouchend"
18
+ @mouseleave="onTouchend"
19
+ @touchstart="onTouchstart"
20
+ @touchmove="onTouchmove"
21
+ @touchend="onTouchend"
22
+ @touchcancel="onTouchend"
23
+ >
24
+ <view class="swipe-action-left">
25
+ <slot name="left"></slot>
26
+ </view>
27
+ <view class="swipe-action-content">
28
+ <slot></slot>
29
+ </view>
30
+ <view class="swipe-action-right">
31
+ <slot name="right"></slot>
32
+ </view>
33
+ </view>
34
+ </view>
35
+ </view>
36
+ </template>
37
+
38
+ <script>
39
+ import utils from '../../utils/utils.js';
40
+ import { childMixin } from '../../utils/mixin.js';
41
+ import TouchEvent from '../ste-touch-swipe/TouchEvent.js';
42
+ /**
43
+ * SwipeAction 滑动单元格
44
+ * @description 滑动单元格
45
+ * @tutorial https://stellar-ui.intecloud.com.cn/pc/index/index?name=ste-swipe-action
46
+ * @property {String} mode 模式
47
+ * @value right 右侧滑动
48
+ * @value left 左侧滑动
49
+ * @value all 左右滑动
50
+ * @property {Boolean} disabled 禁用
51
+ * @property {String | Number} swipeThreshold 灵敏度(0-1之间的小数,数值越小灵敏度越高)
52
+ * @property {String | Number} duration 动画时长,单位ms(默认300)
53
+ * @property {Boolean} leftIcon 是否显示左侧图标(默认false)
54
+ * @property {Boolean} rightIcon 是否显示右侧图标(默认false)
55
+ * @event {Function} open 打开滑块时触发,参数为方向('left'|'right')
56
+ * @event {Function} close 关闭滑块时触发
57
+ */
58
+ export default {
59
+ group: '展示组件',
60
+ title: 'SwipeAction 滑动单元格',
61
+ name: 'ste-swipe-action',
62
+ mixins: [childMixin('ste-swipe-action-group')],
63
+ props: {
64
+ mode: {
65
+ type: [String, null],
66
+ default: () => null,
67
+ },
68
+ disabled: {
69
+ type: [Boolean, null],
70
+ default: () => null,
71
+ },
72
+ swipeThreshold: {
73
+ type: [Number, String, null],
74
+ default: () => null,
75
+ },
76
+ duration: {
77
+ type: [Number, String, null],
78
+ default: () => null,
79
+ },
80
+ leftIcon: {
81
+ type: [Boolean, null],
82
+ default: () => null,
83
+ },
84
+ rightIcon: {
85
+ type: [Boolean, null],
86
+ default: () => null,
87
+ },
88
+ },
89
+ data() {
90
+ return {
91
+ touch: new TouchEvent(),
92
+ moveing: false,
93
+ translateX: 0,
94
+ dataTranslateX: 0,
95
+ leftWidth: 0,
96
+ rightWidth: 0,
97
+ changeCallback: null,
98
+ };
99
+ },
100
+ computed: {
101
+ cmpMode() {
102
+ return this.mode || this.parent?.mode || 'right';
103
+ },
104
+ cmpLeft() {
105
+ return ['all', 'left'].indexOf(this.cmpMode) !== -1;
106
+ },
107
+ cmpRight() {
108
+ return ['all', 'right'].indexOf(this.cmpMode) !== -1;
109
+ },
110
+ cmpDisabled() {
111
+ return this.disabled !== null ? this.disabled : this.parent?.disabled;
112
+ },
113
+ cmpSwipeThreshold() {
114
+ return this.swipeThreshold || this.parent?.swipeThreshold || 0.35;
115
+ },
116
+ cmpDuration() {
117
+ return this.duration || this.parent?.duration || 300;
118
+ },
119
+ cmpLeftIcon() {
120
+ return this.leftIcon !== null ? this.leftIcon : this.parent?.leftIcon;
121
+ },
122
+ cmpRightIcon() {
123
+ return this.rightIcon !== null ? this.rightIcon : this.parent?.rightIcon;
124
+ },
125
+ cmpTransform() {
126
+ return {
127
+ transform: `translateX(${this.translateX}px)`,
128
+ transitionDuration: this.moveing ? 0 : `${this.cmpDuration}ms`,
129
+ };
130
+ },
131
+ },
132
+ mounted() {},
133
+ methods: {
134
+ /**
135
+ * 打开侧滑
136
+ * @param {'right'|'left'} 打开哪一端,默认同mode属性
137
+ */
138
+ open(direction = this.cmpMode) {
139
+ setTimeout(async () => {
140
+ if (direction === 'left') {
141
+ const l = await utils.querySelector('.swipe-action-left', this);
142
+ if (!l) return;
143
+ this.setTransform(l.width);
144
+ } else {
145
+ const r = await utils.querySelector('.swipe-action-right', this);
146
+ if (!r) return;
147
+ this.setTransform(-r.width);
148
+ }
149
+ }, 30);
150
+ },
151
+ close() {
152
+ this.setTransform(0);
153
+ },
154
+ iconOpen(direction) {
155
+ if (this.cmpDisabled) return;
156
+ if (this.dataTranslateX) this.close();
157
+ else this.open(direction);
158
+ },
159
+ setTransform(moveX) {
160
+ this.translateX = moveX;
161
+ if (this.dataTranslateX === moveX) return;
162
+ this.dataTranslateX = moveX;
163
+ if (this.changeCallback) this.changeCallback(moveX);
164
+ if (moveX === 0) this.$emit('close');
165
+ else this.$emit('open', moveX > 0 ? 'left' : 'right');
166
+ },
167
+ async onTouchstart(e) {
168
+ if (this.cmpDisabled) return;
169
+ this.moveing = true;
170
+ this.touch.touchStart(e);
171
+ if (this.cmpLeft) {
172
+ const l = await utils.querySelector('.swipe-action-left', this);
173
+ if (l?.width) this.leftWidth = l.width;
174
+ } else {
175
+ this.leftWidth = 0;
176
+ }
177
+ if (this.cmpRight) {
178
+ const r = await utils.querySelector('.swipe-action-right', this);
179
+ if (r?.width) this.rightWidth = r.width;
180
+ } else {
181
+ this.rightWidth = 0;
182
+ }
183
+ },
184
+ onTouchmove(e) {
185
+ if (this.cmpDisabled) return;
186
+ const d = this.touch.touchMove(e);
187
+ if (!d) return;
188
+ let x = this.dataTranslateX + d.moveX;
189
+ if (this.dataTranslateX > 0 && x < 0) {
190
+ // 左侧按钮显示的时候,不能直接滑动到右侧按钮
191
+ x = 0;
192
+ } else if (this.dataTranslateX < 0 && x > 0) {
193
+ // 右侧按钮显示的时候,不能直接滑动到左侧按钮
194
+ x = 0;
195
+ } else if (!this.cmpLeft && x > 0) {
196
+ // 没有左侧按钮时,不能滑动到左侧
197
+ x = 0;
198
+ } else if (this.cmpLeft && x > this.leftWidth) {
199
+ // 左侧按钮显示时,左侧滑动距离不能超过按钮宽度
200
+ x = this.leftWidth;
201
+ } else if (!this.cmpRight && x < 0) {
202
+ // 没有右侧按钮时,不能滑动到右侧
203
+ x = 0;
204
+ } else if (this.cmpRight && x < -this.rightWidth) {
205
+ // 右侧按钮显示时,右侧滑动距离不能超过按钮宽度
206
+ x = -this.rightWidth;
207
+ }
208
+ this.translateX = x;
209
+ },
210
+ onTouchend(e) {
211
+ this.moveing = false;
212
+ if (this.cmpDisabled) return;
213
+ const { moveX } = this.touch.touchEnd(e);
214
+ let x = this.dataTranslateX;
215
+ if (x === 0) {
216
+ if (moveX > 0 && this.cmpLeft && moveX > this.leftWidth * this.cmpSwipeThreshold) {
217
+ x = this.leftWidth;
218
+ } else if (moveX < 0 && this.cmpRight && Math.abs(moveX) > this.rightWidth * this.cmpSwipeThreshold) {
219
+ x = -this.rightWidth;
220
+ }
221
+ } else if (x > 0 && moveX < 0 && Math.abs(moveX) > this.leftWidth * this.cmpSwipeThreshold) {
222
+ x = 0;
223
+ } else if (x < 0 && moveX > 0 && moveX > this.rightWidth * this.cmpSwipeThreshold) {
224
+ x = 0;
225
+ }
226
+ setTimeout(() => {
227
+ this.setTransform(x);
228
+ }, 10);
229
+ },
230
+ onchange(callback) {
231
+ this.changeCallback = callback;
232
+ },
233
+ },
234
+ };
235
+ </script>
236
+
237
+ <style lang="scss" scoped>
238
+ .ste-swipe-action-root {
239
+ width: 100%;
240
+ position: relative;
241
+ overflow: hidden;
242
+
243
+ .swipe-action-left-icon,
244
+ .swipe-action-right-icon {
245
+ width: 30rpx;
246
+ height: 60rpx;
247
+ position: absolute;
248
+ top: 50%;
249
+ z-index: 10;
250
+ transform: translateY(-50%);
251
+ overflow: hidden;
252
+ box-shadow: 0 0 10rpx rgba(0, 0, 0, 0.1);
253
+ background-color: #fff;
254
+ display: flex;
255
+ align-items: center;
256
+ justify-content: center;
257
+ .swipe-icon {
258
+ width: 30rpx;
259
+ height: 30rpx;
260
+ display: flex;
261
+ align-items: center;
262
+ justify-content: center;
263
+ transition: 300ms;
264
+ &.active {
265
+ transform: rotate(180deg);
266
+ }
267
+ }
268
+ }
269
+ .swipe-action-left-icon {
270
+ left: 0;
271
+ border-radius: 0 30rpx 30rpx 0;
272
+ }
273
+ .swipe-action-right-icon {
274
+ right: 0;
275
+ border-radius: 30rpx 0 0 30rpx;
276
+ }
277
+ .swipe-action-view {
278
+ width: 100%;
279
+ position: relative;
280
+ .swipe-action-left {
281
+ position: absolute;
282
+ top: 0;
283
+ bottom: 0;
284
+ left: 0;
285
+ z-index: 2;
286
+ transform: translateX(-100%);
287
+ }
288
+ .swipe-action-content {
289
+ position: relative;
290
+ width: 100%;
291
+ z-index: 5;
292
+ }
293
+ .swipe-action-right {
294
+ position: absolute;
295
+ top: 0;
296
+ bottom: 0;
297
+ right: 0;
298
+ z-index: 2;
299
+ transform: translateX(100%);
300
+ }
301
+ }
302
+ }
303
+ </style>