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,240 @@
1
+ # Tree 树形控件
2
+ - 树形控件
3
+
4
+ ---$
5
+
6
+ ## 使用示例
7
+ - 以下示例中,但凡使用到`options`属性的,都使用以下数据
8
+ ```json
9
+ [
10
+ {
11
+ title: '标题1',
12
+ value: '1',
13
+ children: [
14
+ {
15
+ title: '标题1-1',
16
+ value: '1-1',
17
+ children: [
18
+ { title: '标题-1-1', value: '1-1-1' },
19
+ { title: '标题1-1-2', value: '1-1-2' },
20
+ ],
21
+ },
22
+ {
23
+ title: '标题1-2',
24
+ value: '1-2',
25
+ children: [
26
+ { title: '标题1-2-1', value: '1-2-1' },
27
+ {
28
+ title: '标题1-2-2',
29
+ value: '1-2-2',
30
+ children: [{ title: '标题1-2-2-1', value: '1-2-2-1' }],
31
+ },
32
+ ],
33
+ },
34
+ ],
35
+ },
36
+ {
37
+ title: '标题2',
38
+ value: '2',
39
+ children: [{ title: '标题2-1', value: '2-1' }],
40
+ },
41
+ ]
42
+
43
+ ```
44
+
45
+
46
+ ### 基础用法
47
+ - 属性`options`用于设置折叠面板的选项,类型为树形结构
48
+ - 对象属性
49
+ - `title`:标题展示文本,(可通过`titleKey`指定)
50
+ - `value`:唯一标识,(可通过`valueKey`指定)
51
+ - `children`:子节点数组,(可通过`childrenKey`指定)
52
+ - `hasChildren`:是否有`children`,懒加载没有`children`属性时,需要将该属性设置为`true`
53
+
54
+ - 事件`open`用于监听打开节点
55
+ - 事件`close`用于监听关闭节点
56
+ ```html
57
+ <template>
58
+ <ste-tree :options="options" @open="onOpen" @close="onClose"></ste-tree>
59
+ </template>
60
+ <script>
61
+ export default {
62
+ methods: {
63
+ onOpen(node) {
64
+ uni.showToast({ title: `打开节点:${node.title}`, icon: 'none' });
65
+ },
66
+ onClose(node) {
67
+ uni.showToast({ title: `关闭节点:${node.title}`, icon: 'none' });
68
+ },
69
+ },
70
+ };
71
+ </script>
72
+ ```
73
+ ### 默认展开节点,打开/关闭指定节点
74
+
75
+ - 属性`openNodes`用于设置默认展开的节点,默认展开的节点数组(数组内容为节点value值,请在组件加载前设置,加载后若要展开请调用open方法)
76
+ - 方法`open`用于打开指定节点
77
+ - 方法`close`用于关闭指定节点
78
+ ```html
79
+ <template>
80
+ <ste-tree ref="accordion" :options="options" :openNodes="['1-2-2']"></ste-tree>
81
+ <ste-button @click="openNode" mode="100">打开标题2</ste-button>
82
+ <ste-button @click="closeNode" mode="100">关闭标题2</ste-button>
83
+ </template>
84
+ <script>
85
+ export default {
86
+ methods: {
87
+ openNode() {
88
+ this.$refs.accordion.open('2');
89
+ },
90
+ closeNode() {
91
+ this.$refs.accordion.close('2');
92
+ },
93
+ },
94
+ };
95
+ </script>
96
+ ```
97
+ ### 节点搜索
98
+
99
+ - 属性`searchTitle`用于搜索节点
100
+ - 也可以使用方法`search(keyword)`进行搜索
101
+
102
+ ```html
103
+ <template>
104
+ <ste-input placeholder="请输入标题内容" v-model="searchTitle"></ste-input>
105
+ <ste-tree :options="options" :searchTitle="searchTitle"></ste-tree>
106
+ </template>
107
+ <script>
108
+ export default {
109
+ data(){
110
+ return {
111
+ searchTitle: '',
112
+ }
113
+ }
114
+ };
115
+ </script>
116
+ ```
117
+ ### 非手风琴模式(展开时不关闭兄弟节点)
118
+
119
+ - 属性`accordion`用于设置是否为手风琴模式,默认为`true`
120
+
121
+ ```html
122
+ <template>
123
+ <ste-tree :options="options" :accordion="false"></ste-tree>
124
+ </template>
125
+ ```
126
+
127
+ ### 懒加载
128
+
129
+ - `options`中对象没有子集`children`时,将属性`hasChildren`设置为`true`可展示`open`按钮
130
+ - 事件`beforeOpen`用于监听用户点击`open`时,打开指定节点前触发
131
+ - 参数一:当前`node`对象
132
+ - 参数二:`suspend`函数,用于等待后续操作
133
+ - 参数三:`next`函数,继续执行后续代码,可接收一个对象数组,该数组会替换当前节点的`children`
134
+ - 参数四:`stop`函数,阻止后续代码执行
135
+
136
+ ```html
137
+ <template>
138
+ <ste-tree :options="lazyLoadOptions" @beforeOpen="beforeOpen"></ste-tree>
139
+ </template>
140
+ <script>
141
+ export default {
142
+ data(){
143
+ return{
144
+ lazyLoadOptions: [
145
+ { title: '标题1', value: '1', hasChildren: true },
146
+ { title: '标题2', value: '2', hasChildren: true },
147
+ ],
148
+ }
149
+ },
150
+ methods: {
151
+ beforeOpen(node, suspend, next, stop) {
152
+ // 开启等待
153
+ suspend();
154
+ setTimeout(() => {
155
+ // 继续后续操作,并将结果传递给next
156
+ next([
157
+ { title: `${node.title}-1`, value: `${node.value}-1` },
158
+ { title: `${node.title}-2`, value: `${node.value}-2`, hasChildren: true },
159
+ ]);
160
+ }, 2000);
161
+ },
162
+ }
163
+ }
164
+ </script>
165
+ ```
166
+
167
+ ### 自定义内容
168
+
169
+ - 插槽`default`用于自定义节点标题
170
+ - 插槽`open`用于自定义节点展开按钮图标,大小不得超过30rpx
171
+ - 插槽`loading`用于自定义懒加载动画
172
+ ```html
173
+ <template>
174
+ <ste-tree :options="options">
175
+ <template v-slot="{ node, depth }">
176
+ <view class="item-title">
177
+ <image
178
+ v-if="depth === 0"
179
+ class="title-image"
180
+ src="https://image.whzb.com/chain/StellarUI/component-icons/ste-tree.png"
181
+ ></image>
182
+ <image
183
+ v-if="depth === 1"
184
+ class="title-image"
185
+ src="https://image.whzb.com/chain/StellarUI/component-icons/ste-tree-children.png"
186
+ ></image>
187
+ <view class="item-text">{{ node.title }}</view>
188
+ </view>
189
+ </template>
190
+ <template v-slot:open="{ open }">
191
+ <view class="slef-open-icon">
192
+ {{ open ? '-' : '+' }}
193
+ </view>
194
+ </template>
195
+ </ste-tree>
196
+ </template>
197
+ <script>
198
+ ```
199
+
200
+
201
+ ---$
202
+ ### API
203
+ #### Props
204
+ 背景之外的颜色属性只支持`16进制`、`RGB`、`RGBA`格式
205
+ | 属性名 | 说明 | 类型 | 默认值 | 可选值 | 支持版本 |
206
+ | ----- | ----- | ----- | ----- | ----- | ----- |
207
+ | `options` | 树形结构数组(`Node`结构见基础用法详情 ),若组件渲染完成后修此属性,请手动调用`init`方法 | `Array<Node>` | `[]` | - | - |
208
+ | `valueKey` | 节点的值字段名 | `String` | `"value"` | - | - |
209
+ | `titleKey` | 节点的标题字段名 | `String` | `"title"` | - | - |
210
+ | `childrenKey` | 节点的子节点字段名 | `String` | `"children"`| - | - |
211
+ | `accordion` | 是否手风琴模式 | `Boolean` | `true` | - | - |
212
+ | `childrenPadding` | 子节点缩进,单位rpx | `Number`,`String` | `40` | - | - |
213
+ | `openNodes` | 默认展开的节点数组 | `Array<String/Number>`| `[]` | - | - |
214
+
215
+
216
+ #### Method
217
+
218
+ | 方法名 | 说明 | 方法参数 | 支持版本 |
219
+ | --- | --- | --- | --- |
220
+ | `init` | 初始化方法,若`options`改变时页面没有更新,可调用此方法重现渲染 | - | - |
221
+ | `open` | 打开指定节点 | `value` | - |
222
+ | `close` | 关闭指定节点 | `value` | - |
223
+ | `search`| 节点搜索 | `title` | - |
224
+
225
+
226
+
227
+ #### Events
228
+
229
+ | 事件名 | 说明 | 事件参数 | 支持版本 |
230
+ | --- | --- | --- | --- |
231
+ | `click` | 点击节点时触发 | `node` | - |
232
+ | `open` | 打开节点时触发 | `node` | - |
233
+ | `close` | 关闭节点时触发 | `node` | - |
234
+ | `beforeOpen`| 打开节点前触发 | 见`懒加载`示例详细说明 | - |
235
+
236
+
237
+
238
+
239
+ ---$
240
+ {{xuyajun}}
@@ -0,0 +1,350 @@
1
+ <template>
2
+ <view class="ste-tree-root">
3
+ <view
4
+ v-for="(node, index) in viewList"
5
+ :key="node[valueKey]"
6
+ class="tree-item"
7
+ :class="{ open: node.open, children: node.hasChildren }"
8
+ >
9
+ <view class="tree-item-content" :style="{ paddingLeft: `${node.depth * cmpPaddingLeft}px` }">
10
+ <view class="tree-item-head" @click="onClick(node)">
11
+ <view class="tree-item-right">
12
+ <slot :node="node" :depth="node.depth">
13
+ <view class="tree-item-title">{{ node[titleKey] }}</view>
14
+ </slot>
15
+ </view>
16
+ <view class="tree-item-open" v-if="node.hasChildren" @click="onOpen(node)">
17
+ <slot name="open" :open="node.open">
18
+ <view class="open-icon">
19
+ <ste-icon code="&#xe678;" size="30" />
20
+ </view>
21
+ </slot>
22
+ </view>
23
+ </view>
24
+ </view>
25
+
26
+ <view class="tree-item-loading" v-if="node.loading">
27
+ <slot name="loading">
28
+ <ste-loading size="30" />
29
+ </slot>
30
+ </view>
31
+ </view>
32
+ </view>
33
+ </template>
34
+
35
+ <script>
36
+ import utils from '../../utils/utils.js';
37
+
38
+ /**
39
+ * ste-tree 树形控件
40
+ * @description 树形控件组件
41
+ * @tutorial https://stellar-ui.intecloud.com.cn/pc/index/index?name=ste-tree
42
+ * @property {Array} options 节点数组(支持树形结构)
43
+ * @property {String} valueKey 节点的值字段名(默认:value)
44
+ * @property {String} titleKey 节点的标题字段名(默认:title)
45
+ * @property {String} childrenKey 节点的子节点字段名(默认:children)
46
+ * @property {Boolean} accordion 是否手风琴模式(默认:true)
47
+ * @property {Number | String} childrenPadding 子节点缩进,单位RPX(默认:40)
48
+ * @property {Array} openNodes 默认展开的节点数组(数组内容为节点value值,请在组件加载前设置,加载后若要展开请调用open方法)
49
+ * @event {Function} click 点击节点触发,参数为当前节点对象
50
+ * @event {Function} open 打开节点时触发,参数为当前节点对象
51
+ * @event {Function} close 关闭节点时触发,参数为当前节点对象
52
+ * @event {Function} beforeOpen 打开节点前触发,第一个参数为当前节点对象(第二个参数为suspend函数,用于等待后续操作)(第三个参数为next函数,继续执行后续代码,可接收一个对象数组,该数组会替换当前节点的children)(第四个参数为stop,阻止后续代码执行)
53
+ */
54
+
55
+ export default {
56
+ group: '展示组件',
57
+ title: 'Tree 树形控件',
58
+ name: 'ste-tree',
59
+ props: {
60
+ options: { type: [Array, null], default: () => [] },
61
+ valueKey: { type: [String, null], default: () => 'value' },
62
+ titleKey: { type: [String, null], default: () => 'title' },
63
+ childrenKey: { type: [String, null], default: () => 'children' },
64
+ accordion: { type: [Boolean, null], default: () => true },
65
+ childrenPadding: { type: [Number, String, null], default: () => 40 },
66
+ openNodes: { type: [Array, null], default: () => [] },
67
+ searchTitle: { type: [String, null], default: () => '' },
68
+ },
69
+ data() {
70
+ return {
71
+ dataOptions: [], // 全部数据
72
+ viewOptions: [], // 渲染数据
73
+ viewList: [], // 渲染列表
74
+ dataSearchTitle: '',
75
+
76
+ searchTime: null,
77
+ };
78
+ },
79
+ computed: {
80
+ cmpPaddingLeft() {
81
+ return utils.formatPx(this.childrenPadding, 'num');
82
+ },
83
+ },
84
+ watch: {
85
+ options: {
86
+ handler() {
87
+ this.init();
88
+ },
89
+ immediate: true,
90
+ },
91
+ searchTitle: {
92
+ handler(v) {
93
+ this.dataSearchTitle = v;
94
+ },
95
+ immediate: true,
96
+ },
97
+ dataSearchTitle: {
98
+ handler(v) {
99
+ this.onSearch(v);
100
+ },
101
+ immediate: true,
102
+ },
103
+ },
104
+ methods: {
105
+ init() {
106
+ this.dataOptions = this.formatTree(this.options);
107
+ this.viewOptions = this.dataOptions;
108
+ if (this.openNodes?.length) this.openNodes.forEach((v) => this.open(v));
109
+ else this.rende();
110
+ },
111
+ async open(value) {
112
+ const node = this.findNode(this.viewOptions, value);
113
+ if (!node) return;
114
+ if (!this.dataSearchTitle) {
115
+ await this.beforeOpen(node);
116
+ }
117
+ this.setNodeOpen(node[this.valueKey], true);
118
+ if (node.parentNode !== '__root__') {
119
+ const getParents = (_node) => {
120
+ const parents = [];
121
+ const parent = this.findNode(this.viewOptions, _node.parentNode);
122
+ if (parent) {
123
+ parents.push(parent);
124
+ if (parent.parentNode !== '__root__') {
125
+ parents.push(...getParents(parent));
126
+ }
127
+ }
128
+ return parents;
129
+ };
130
+ const parents = getParents(node);
131
+ parents.forEach((parent) => {
132
+ if (parent.open) return;
133
+ this.setNodeOpen(parent[this.valueKey], true);
134
+ });
135
+ }
136
+
137
+ this.rende();
138
+ },
139
+ close(value) {
140
+ this.closeNode(value);
141
+ },
142
+ search(title) {
143
+ this.dataSearchTitle = title;
144
+ },
145
+
146
+ formatTree(tree, parentNode, depth) {
147
+ return utils.formatTree(
148
+ tree,
149
+ this.valueKey,
150
+ this.childrenKey,
151
+ (node) => {
152
+ return { open: false, loading: false, hasChildren: !!node[this.childrenKey]?.length };
153
+ },
154
+ parentNode,
155
+ depth
156
+ );
157
+ },
158
+ rende() {
159
+ this.$nextTick(() => {
160
+ if (!this.viewOptions?.length) {
161
+ this.viewList = [];
162
+ return;
163
+ }
164
+ this.viewList = utils.flattenTree(this.viewOptions, this.childrenKey, (node) => node.open);
165
+ });
166
+ },
167
+
168
+ onClick(node) {
169
+ this.$emit('click', node);
170
+ },
171
+ onOpen(node) {
172
+ if (node.open) this.closeNode(node[this.valueKey]);
173
+ else this.openNode(node);
174
+ },
175
+
176
+ onSearch(title) {
177
+ clearTimeout(this.searchTime);
178
+
179
+ this.searchTime = setTimeout(() => {
180
+ if (!title) {
181
+ if (this.viewOptions !== this.dataOptions) {
182
+ this.viewOptions = this.dataOptions;
183
+ }
184
+ this.rende();
185
+ return;
186
+ }
187
+ this.viewOptions = utils.filterTree(
188
+ this.dataOptions,
189
+ (node) => node[this.titleKey]?.indexOf(title) !== -1,
190
+ this.valueKey,
191
+ this.childrenKey
192
+ );
193
+ this.rende();
194
+ }, 500);
195
+ },
196
+ async beforeOpen(node, suspend, next, stop) {
197
+ let is_next = true;
198
+ const beforeOpen = new Promise((resolve, reject) => {
199
+ this.$emit(
200
+ 'beforeOpen',
201
+ node,
202
+ typeof suspend === 'function'
203
+ ? suspend
204
+ : () => {
205
+ is_next = false;
206
+ this.$set(node, 'loading', true);
207
+ },
208
+ (children = []) => {
209
+ const _children = this.formatTree(children, node[this.valueKey], node.depth + 1);
210
+
211
+ typeof next === 'function' ? next(_children) : resolve(_children);
212
+ },
213
+ typeof stop === 'function' ? stop : () => reject()
214
+ );
215
+ });
216
+ if (!is_next) {
217
+ try {
218
+ const children = await beforeOpen;
219
+ this.$set(node, this.childrenKey, children);
220
+ this.$set(node, 'loading', false);
221
+ } catch (e) {
222
+ // TODO handle the exception
223
+ this.$set(node, 'loading', false);
224
+ throw e;
225
+ }
226
+ }
227
+ },
228
+
229
+ async openNode(node) {
230
+ try {
231
+ await this.open(node[this.valueKey]);
232
+ this.$emit('open', node);
233
+ this.rende();
234
+ } catch (e) {
235
+ //TODO handle the exception
236
+ }
237
+ },
238
+ closeNode(value) {
239
+ const node = this.setNodeOpen(value, false);
240
+ this.$emit('close', node);
241
+ this.rende();
242
+ },
243
+
244
+ findNode(tree, value) {
245
+ return utils.findTreeNode(tree, value, this.valueKey, this.childrenKey);
246
+ },
247
+ // 关闭打开的兄弟节点
248
+ closeSibling(node) {
249
+ const sibling = this.viewList.filter(
250
+ (s) => s.open && s.parentNode === node.parentNode && s[this.valueKey] !== node[this.valueKey]
251
+ );
252
+ sibling.forEach((s) => this.setNodeOpen(s[this.valueKey], false));
253
+ },
254
+ setNodeOpen(nodeValue, open) {
255
+ // 修改渲染状态
256
+ const node = this.findNode(this.viewOptions, nodeValue);
257
+ if (open && this.accordion) {
258
+ this.closeSibling(node);
259
+ }
260
+ if (this.dataOptions !== this.viewOptions) {
261
+ // 同步到数据中
262
+ const _node = this.findNode(this.dataOptions, nodeValue);
263
+ _node.open = open;
264
+ }
265
+ node.open = open;
266
+ return node;
267
+ },
268
+ },
269
+ };
270
+ </script>
271
+
272
+ <style lang="scss" scoped>
273
+ .ste-tree-root {
274
+ width: 100%;
275
+ background-color: #fff;
276
+ .tree-item {
277
+ width: 100%;
278
+
279
+ &.open {
280
+ & > .tree-item-content {
281
+ .tree-item-head {
282
+ box-shadow: 0px 4rpx 10rpx 2rpx rgba(0, 0, 0, 0.04);
283
+ .tree-item-open .open-icon {
284
+ transform: rotate(180deg);
285
+ }
286
+ }
287
+ }
288
+ & > .tree-children {
289
+ display: block;
290
+ margin: 8rpx 0;
291
+ }
292
+ }
293
+
294
+ &.children {
295
+ .tree-item-content {
296
+ .tree-item-head {
297
+ margin-bottom: 8rpx;
298
+ .tree-item-right {
299
+ width: calc(100% - 70rpx);
300
+ }
301
+ .tree-item-open {
302
+ width: 70rpx;
303
+ height: 60rpx;
304
+ line-height: 30rpx;
305
+ padding: 15rpx 20rpx;
306
+ line-height: 30rpx;
307
+ }
308
+ }
309
+ }
310
+ }
311
+
312
+ .tree-item-content {
313
+ width: 100%;
314
+ .tree-item-head {
315
+ width: 100%;
316
+ display: flex;
317
+ align-items: center;
318
+ justify-content: space-between;
319
+ font-family: PingFang SC, PingFang SC;
320
+ font-weight: 500;
321
+ font-size: 28rpx;
322
+ color: #000000;
323
+
324
+ .tree-item-right {
325
+ width: 100%;
326
+
327
+ .tree-item-title {
328
+ width: 100%;
329
+ height: 80rpx;
330
+ line-height: 80rpx;
331
+ padding-left: 20rpx;
332
+ }
333
+ }
334
+ }
335
+ }
336
+ .tree-item-loading {
337
+ width: 100%;
338
+ height: 80rpx;
339
+ display: flex;
340
+ justify-content: center;
341
+ align-items: center;
342
+ }
343
+ .tree-children {
344
+ display: none;
345
+ width: 100%;
346
+ padding-left: 40rpx;
347
+ }
348
+ }
349
+ }
350
+ </style>