@fox-js/phone-skills 4.0.1-0
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/README.md +30 -0
- package/foxui/SKILL.md +442 -0
- package/foxui/references/fox-action-sheet/doc.md +74 -0
- package/foxui/references/fox-actionsheet-item/doc.md +499 -0
- package/foxui/references/fox-animate/doc.md +66 -0
- package/foxui/references/fox-audio/doc.md +76 -0
- package/foxui/references/fox-avatar/doc.md +70 -0
- package/foxui/references/fox-back-top/doc.md +69 -0
- package/foxui/references/fox-badge/doc.md +72 -0
- package/foxui/references/fox-barrage/doc.md +116 -0
- package/foxui/references/fox-button/doc.md +203 -0
- package/foxui/references/fox-calendar/doc.md +346 -0
- package/foxui/references/fox-calendar-item/doc.md +331 -0
- package/foxui/references/fox-cascader/doc.md +78 -0
- package/foxui/references/fox-cascader-item/doc.md +710 -0
- package/foxui/references/fox-cell/doc.md +74 -0
- package/foxui/references/fox-checkbox-item/doc.md +387 -0
- package/foxui/references/fox-circle-progress/doc.md +65 -0
- package/foxui/references/fox-collapse/doc.md +71 -0
- package/foxui/references/fox-count-down/doc.md +78 -0
- package/foxui/references/fox-count-up/doc.md +178 -0
- package/foxui/references/fox-date-item/doc.md +437 -0
- package/foxui/references/fox-date-picker/doc.md +438 -0
- package/foxui/references/fox-dialog/doc.md +242 -0
- package/foxui/references/fox-divider/doc.md +149 -0
- package/foxui/references/fox-domain-provider/doc.md +93 -0
- package/foxui/references/fox-drag/doc.md +64 -0
- package/foxui/references/fox-dropdown/doc.md +138 -0
- package/foxui/references/fox-elevator/doc.md +66 -0
- package/foxui/references/fox-ellipsis/doc.md +69 -0
- package/foxui/references/fox-empty/doc.md +67 -0
- package/foxui/references/fox-fixed-nav/doc.md +72 -0
- package/foxui/references/fox-floating-button/doc.md +142 -0
- package/foxui/references/fox-grid/doc.md +69 -0
- package/foxui/references/fox-group/doc.md +295 -0
- package/foxui/references/fox-icon/doc.md +65 -0
- package/foxui/references/fox-image/doc.md +75 -0
- package/foxui/references/fox-image-preview/doc.md +79 -0
- package/foxui/references/fox-indicator/doc.md +70 -0
- package/foxui/references/fox-infinite-loading/doc.md +74 -0
- package/foxui/references/fox-input-item/doc.md +210 -0
- package/foxui/references/fox-input-number/doc.md +199 -0
- package/foxui/references/fox-input-number-item/doc.md +213 -0
- package/foxui/references/fox-item/doc.md +207 -0
- package/foxui/references/fox-layout/doc.md +273 -0
- package/foxui/references/fox-link-item/doc.md +158 -0
- package/foxui/references/fox-list/doc.md +71 -0
- package/foxui/references/fox-mapping/doc.md +251 -0
- package/foxui/references/fox-menu/doc.md +425 -0
- package/foxui/references/fox-message-box/doc.md +200 -0
- package/foxui/references/fox-money-item/doc.md +174 -0
- package/foxui/references/fox-more-button/doc.md +208 -0
- package/foxui/references/fox-navbar/doc.md +75 -0
- package/foxui/references/fox-notice-bar/doc.md +71 -0
- package/foxui/references/fox-notify/doc.md +72 -0
- package/foxui/references/fox-number-keyboard/doc.md +77 -0
- package/foxui/references/fox-over-lay/doc.md +70 -0
- package/foxui/references/fox-page/doc.md +76 -0
- package/foxui/references/fox-pagination/doc.md +73 -0
- package/foxui/references/fox-picker/doc.md +668 -0
- package/foxui/references/fox-picker-item/doc.md +389 -0
- package/foxui/references/fox-popover/doc.md +70 -0
- package/foxui/references/fox-popover-dialog/doc.md +113 -0
- package/foxui/references/fox-popup/doc.md +88 -0
- package/foxui/references/fox-price/doc.md +67 -0
- package/foxui/references/fox-progress/doc.md +74 -0
- package/foxui/references/fox-pull-refresh/doc.md +77 -0
- package/foxui/references/fox-radio-item/doc.md +384 -0
- package/foxui/references/fox-range/doc.md +65 -0
- package/foxui/references/fox-rate/doc.md +141 -0
- package/foxui/references/fox-rate-item/doc.md +137 -0
- package/foxui/references/fox-rolling-provider/doc.md +87 -0
- package/foxui/references/fox-search-bar/doc.md +91 -0
- package/foxui/references/fox-short-password/doc.md +78 -0
- package/foxui/references/fox-side-nav-bar/doc.md +68 -0
- package/foxui/references/fox-signature/doc.md +202 -0
- package/foxui/references/fox-skeleton/doc.md +73 -0
- package/foxui/references/fox-steps/doc.md +162 -0
- package/foxui/references/fox-steps-bar/doc.md +610 -0
- package/foxui/references/fox-sticky/doc.md +68 -0
- package/foxui/references/fox-swipe/doc.md +176 -0
- package/foxui/references/fox-swiper/doc.md +254 -0
- package/foxui/references/fox-switch/doc.md +162 -0
- package/foxui/references/fox-switch-item/doc.md +190 -0
- package/foxui/references/fox-tabbar/doc.md +63 -0
- package/foxui/references/fox-table/doc.md +640 -0
- package/foxui/references/fox-tabs/doc.md +67 -0
- package/foxui/references/fox-tabs-bar/doc.md +533 -0
- package/foxui/references/fox-tag/doc.md +213 -0
- package/foxui/references/fox-text/doc.md +84 -0
- package/foxui/references/fox-textarea-item/doc.md +106 -0
- package/foxui/references/fox-toast/doc.md +149 -0
- package/foxui/references/fox-tour/doc.md +89 -0
- package/foxui/references/fox-trend-arrow/doc.md +72 -0
- package/foxui/references/fox-uploader/doc.md +96 -0
- package/foxui/references/fox-video/doc.md +245 -0
- package/foxui/references/fox-water-mark/doc.md +81 -0
- package/package.json +21 -0
|
@@ -0,0 +1,710 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
* @Author: 江成
|
|
3
|
+
* @Date: 2026-04-27 00:37:28
|
|
4
|
+
* @LastEditors: 江成
|
|
5
|
+
* @LastEditTime: 2026-05-12 22:33:21
|
|
6
|
+
-->
|
|
7
|
+
---
|
|
8
|
+
title: CascaderItem 组件使用规范
|
|
9
|
+
impact: HIGH
|
|
10
|
+
type: capability
|
|
11
|
+
description: 级联选择器,用于多层级数据的选择,典型场景为省市区选择.
|
|
12
|
+
tags: [foxui, fox-cascader-item, FoxCascaderItem]
|
|
13
|
+
version: "4.0.0"
|
|
14
|
+
author: jiangcheng
|
|
15
|
+
related: ["fox-js","fox-group","fox-item","fox-input-text","fox-cascader"]
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
# CascaderItem 组件使用规范
|
|
19
|
+
|
|
20
|
+
## 1. 核心职责 (Core Responsibility)
|
|
21
|
+
CascaderItem 是 foxui 中用于 **级联选择器,用于多层级数据的选择,典型场景为省市区选择.** 的标准组件。
|
|
22
|
+
- **基于**: NutUI `nut-cascader-item` 进行了二次封装 (若为纯自研组件则填 "自定义开发")
|
|
23
|
+
- **核心增强**: 基于 NutUI 组件二次封装、内置必填校验标识、支持 v-model 双向绑定、支持标签位置自定义、支持占位符提示、支持禁用/只读状态、内置多级提示信息、适配 H5 与小程序多端、支持插槽扩展自定义内容、支持主题定制
|
|
24
|
+
- **适用场景**: 级联选择器,用于多层级数据的选择,典型场景为省市区选择.
|
|
25
|
+
|
|
26
|
+
> 💡 **关键原则**: 在所有 级联选择器,用于多层级数据的选择,典型场景为省市区选择. 中,**必须**优先使用此组件,禁止直接使用原生 NutUI 组件。
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## 2. 关键 API 说明 (Key API)
|
|
31
|
+
|
|
32
|
+
### 2.1 Props 属性
|
|
33
|
+
|
|
34
|
+
| 属性名 | 类型 | 必填 | 默认值 | 说明 |
|
|
35
|
+
| :--- | :--- | :---: | :---: | :--- |
|
|
36
|
+
| `v-model` | 选中值,双向绑定 | Array | - |
|
|
37
|
+
| `source` | 级联数据 | Array,Function,String | - |
|
|
38
|
+
| `lazy` | 是否开启动态加载 | Boolean | - |
|
|
39
|
+
| `lazy-load` | 动态加载回调,开启动态加载时生效 | Function | - |
|
|
40
|
+
| `value-key` | 自定义options结构中value的字段 | String | - |
|
|
41
|
+
| `text-key` | 自定义options结构中text的字段 | String | - |
|
|
42
|
+
| `children-key` | 自定义options结构中children的字段 | String | - |
|
|
43
|
+
| `convert-config` | 当options为可转换为树形结构的扁平结构时,配置转换规则 | Object | - |
|
|
44
|
+
| `title` | 标题 | String | '' |
|
|
45
|
+
| `show-all-levels` | 是否显示完整的路径 | Boolean | true |
|
|
46
|
+
| `separator` | 分割符 | String | / |
|
|
47
|
+
| `close-icon-position` | 取消按钮位置,继承 Popup 组件 | String | "top-right" |
|
|
48
|
+
| `close-icon` | 自定义关闭按钮,继承 Popup 组件 | String | "close" |
|
|
49
|
+
| `closeable` | 是否显示关闭按钮,继承 Popup 组件 | Boolean | true |
|
|
50
|
+
| `label` | 标签 | String | - |
|
|
51
|
+
| `label-width` | 标签宽度 | String | - |
|
|
52
|
+
| `label-position` | 标签位置可选值left,right,top | String | - |
|
|
53
|
+
| `is-required` | 左侧号是否展示 | Boolean | false |
|
|
54
|
+
| `disabled` | 是否禁用 | Boolean | false |
|
|
55
|
+
| `readonly` | 是否只读 | Boolean | false |
|
|
56
|
+
| `error-tip` | 错误提示 | String | - |
|
|
57
|
+
| `error-icon` | 错误提示图标 | String | - |
|
|
58
|
+
| `warn-tip` | 警告提示 | String | - |
|
|
59
|
+
| `warn-icon` | 警告提示图标 | String | - |
|
|
60
|
+
| `info-tip` | 提示 | String | - |
|
|
61
|
+
| `info-icon` | 提示图标 | String | - |
|
|
62
|
+
|
|
63
|
+
### 2.2 Events 事件
|
|
64
|
+
|
|
65
|
+
| 事件名 | 类型 | 说明 |
|
|
66
|
+
| :--- | :--- | :--- |
|
|
67
|
+
| `change` | 选中值改变时触发 | value, pathNodes |
|
|
68
|
+
| `pathChange` | 选中项改变时触发 | pathNodes |
|
|
69
|
+
| `change` | 输入内容时触发 | val ,event |
|
|
70
|
+
| `focus` | 聚焦时触发 | val ,event |
|
|
71
|
+
| `blur` | 失焦时触发 | val ,event |
|
|
72
|
+
| `clear` | 点击清空时触发 | val |
|
|
73
|
+
|
|
74
|
+
### 2.3 Methods 方法
|
|
75
|
+
|
|
76
|
+
| 方法名 | 参数 | 说明 |
|
|
77
|
+
| :--- | :--- | :--- |
|
|
78
|
+
无
|
|
79
|
+
|
|
80
|
+
### 2.4 Slots 插槽
|
|
81
|
+
|
|
82
|
+
| 插槽名 | 说明 |
|
|
83
|
+
| :--- | :--- |
|
|
84
|
+
| `default` | label内容 |
|
|
85
|
+
|
|
86
|
+
## 3. 例子 (Examples)
|
|
87
|
+
|
|
88
|
+
## 代码演示
|
|
89
|
+
### 基础用法
|
|
90
|
+
`source`数组数据源和设置禁用或只读属性
|
|
91
|
+
```html
|
|
92
|
+
<fox-group v-if="true" title="基础用法">
|
|
93
|
+
<fox-cascader-item
|
|
94
|
+
v-model="demo1.value"
|
|
95
|
+
:source="demo1.source"
|
|
96
|
+
title="请选择地址"
|
|
97
|
+
placeholder="请选择地址"
|
|
98
|
+
@change="events.change"
|
|
99
|
+
@path-change="events.pathChange"
|
|
100
|
+
>选择地址</fox-cascader-item
|
|
101
|
+
>
|
|
102
|
+
<fox-cascader-item
|
|
103
|
+
readonly
|
|
104
|
+
v-model="demo1.value2"
|
|
105
|
+
:source="demo1.source"
|
|
106
|
+
title="请选择地址"
|
|
107
|
+
placeholder="请选择地址"
|
|
108
|
+
@change="events.change"
|
|
109
|
+
@path-change="events.pathChange"
|
|
110
|
+
>只读</fox-cascader-item
|
|
111
|
+
>
|
|
112
|
+
<fox-cascader-item
|
|
113
|
+
disabled
|
|
114
|
+
v-model="demo1.value3"
|
|
115
|
+
:source="demo1.source"
|
|
116
|
+
title="请选择地址"
|
|
117
|
+
placeholder="请选择地址"
|
|
118
|
+
@change="events.change"
|
|
119
|
+
@path-change="events.pathChange"
|
|
120
|
+
>禁用</fox-cascader-item
|
|
121
|
+
>
|
|
122
|
+
<fox-cascader-item
|
|
123
|
+
v-model="demo1.value3"
|
|
124
|
+
:source="demo1.source"
|
|
125
|
+
title="请选择地址"
|
|
126
|
+
placeholder="请选择地址"
|
|
127
|
+
:show-all-levels="false"
|
|
128
|
+
>显示最后一级</fox-cascader-item
|
|
129
|
+
>
|
|
130
|
+
</fox-group>
|
|
131
|
+
```
|
|
132
|
+
```javascript
|
|
133
|
+
setup() {
|
|
134
|
+
// 基础用法
|
|
135
|
+
const demo1 = reactive({
|
|
136
|
+
value: [],
|
|
137
|
+
value2: ['广东', '广州', '黄埔区'],
|
|
138
|
+
value3: ['福建', '福州', '台江区'],
|
|
139
|
+
value4:'',
|
|
140
|
+
source: [
|
|
141
|
+
{
|
|
142
|
+
value: '广东',
|
|
143
|
+
text: '广东',
|
|
144
|
+
children: [
|
|
145
|
+
{
|
|
146
|
+
value: '广州',
|
|
147
|
+
text: '广州',
|
|
148
|
+
disabled: true,
|
|
149
|
+
children: [
|
|
150
|
+
{ value: '黄埔区', text: '黄埔区' },
|
|
151
|
+
{ value: '南沙', text: '南沙' }
|
|
152
|
+
]
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
value: '佛山',
|
|
156
|
+
text: '佛山',
|
|
157
|
+
children: [
|
|
158
|
+
{ value: '禅城区', text: '禅城区' },
|
|
159
|
+
{ value: '南海区', text: '南海区' }
|
|
160
|
+
]
|
|
161
|
+
}
|
|
162
|
+
]
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
value: '浙江',
|
|
166
|
+
text: '浙江',
|
|
167
|
+
children: [
|
|
168
|
+
{
|
|
169
|
+
value: '杭州',
|
|
170
|
+
text: '杭州',
|
|
171
|
+
disabled: true,
|
|
172
|
+
children: [
|
|
173
|
+
{ value: '西湖区', text: '西湖区' },
|
|
174
|
+
{ value: '余杭区', text: '余杭区' }
|
|
175
|
+
]
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
value: '温州',
|
|
179
|
+
text: '温州',
|
|
180
|
+
children: [
|
|
181
|
+
{ value: '鹿城区', text: '鹿城区' },
|
|
182
|
+
{ value: '瓯海区', text: '瓯海区' }
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
]
|
|
186
|
+
},
|
|
187
|
+
{
|
|
188
|
+
value: '湖南',
|
|
189
|
+
text: '湖南',
|
|
190
|
+
disabled: true
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
value: '福建',
|
|
194
|
+
text: '福建',
|
|
195
|
+
children: [
|
|
196
|
+
{
|
|
197
|
+
value: '福州',
|
|
198
|
+
text: '福州',
|
|
199
|
+
children: [
|
|
200
|
+
{ value: '鼓楼区', text: '鼓楼区' },
|
|
201
|
+
{ value: '台江区', text: '台江区' }
|
|
202
|
+
]
|
|
203
|
+
}
|
|
204
|
+
]
|
|
205
|
+
}
|
|
206
|
+
]
|
|
207
|
+
})
|
|
208
|
+
watch(
|
|
209
|
+
() => demo1.value,
|
|
210
|
+
newVal => {
|
|
211
|
+
console.info('watch demo1 value', newVal)
|
|
212
|
+
newVal.forEach(item => {
|
|
213
|
+
console.info(item)
|
|
214
|
+
})
|
|
215
|
+
}
|
|
216
|
+
)
|
|
217
|
+
const events = {
|
|
218
|
+
change(...args: any) {
|
|
219
|
+
console.log('change', ...args);
|
|
220
|
+
},
|
|
221
|
+
pathChange(...args: any) {
|
|
222
|
+
console.log('pathChange', ...args);
|
|
223
|
+
},
|
|
224
|
+
};
|
|
225
|
+
return { demo1, events };
|
|
226
|
+
}
|
|
227
|
+
```
|
|
228
|
+
### 自定义属性名称
|
|
229
|
+
可通过`textKey`、`valueKey`、`childrenKey`指定属性名。
|
|
230
|
+
```html
|
|
231
|
+
<fox-group>
|
|
232
|
+
<fox-item label="选择地址">
|
|
233
|
+
<input
|
|
234
|
+
class="fox-input-text"
|
|
235
|
+
@click="state.visible = true"
|
|
236
|
+
:value="state.value"
|
|
237
|
+
readonly
|
|
238
|
+
placeholder="请选择地址"
|
|
239
|
+
type="text"
|
|
240
|
+
/>
|
|
241
|
+
<fox-cascader
|
|
242
|
+
title="地址选择"
|
|
243
|
+
v-model:visible="state.visible"
|
|
244
|
+
v-model="state.value"
|
|
245
|
+
label-key="text"
|
|
246
|
+
@change="events.change"
|
|
247
|
+
@path-change="events.pathChange"
|
|
248
|
+
value-key="text"
|
|
249
|
+
children-key="items"
|
|
250
|
+
:options="state.options"
|
|
251
|
+
></fox-cascader>
|
|
252
|
+
</fox-item>
|
|
253
|
+
</fox-group>
|
|
254
|
+
```
|
|
255
|
+
```ts
|
|
256
|
+
setup() {
|
|
257
|
+
const state = reactive({
|
|
258
|
+
visible: false,
|
|
259
|
+
value: ['浙江', '杭州', '西湖区'],
|
|
260
|
+
options: [
|
|
261
|
+
{
|
|
262
|
+
text: '浙江',
|
|
263
|
+
items: [
|
|
264
|
+
{
|
|
265
|
+
text: '杭州',
|
|
266
|
+
disabled: true,
|
|
267
|
+
items: [{ text: '西湖区' }, { text: '余杭区' }]
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
text: '温州',
|
|
271
|
+
items: [{ text: '鹿城区' }, { text: '瓯海区' }]
|
|
272
|
+
}
|
|
273
|
+
]
|
|
274
|
+
},
|
|
275
|
+
{
|
|
276
|
+
text: '福建',
|
|
277
|
+
items: [
|
|
278
|
+
{
|
|
279
|
+
text: '福州',
|
|
280
|
+
items: [{ text: '鼓楼区' }, { text: '台江区' }]
|
|
281
|
+
}
|
|
282
|
+
]
|
|
283
|
+
}
|
|
284
|
+
]
|
|
285
|
+
});
|
|
286
|
+
const events = {
|
|
287
|
+
change(...args: any) {
|
|
288
|
+
console.log('change', ...args)
|
|
289
|
+
},
|
|
290
|
+
pathChange(...args: any) {
|
|
291
|
+
console.log('pathChange', ...args)
|
|
292
|
+
},
|
|
293
|
+
};
|
|
294
|
+
return { demo1, events }
|
|
295
|
+
}
|
|
296
|
+
```
|
|
297
|
+
### 返回类型
|
|
298
|
+
通过设置value-type(返回类型),让v-model指向选中项中的text、value或json对象
|
|
299
|
+
级联选项的
|
|
300
|
+
```html
|
|
301
|
+
<fox-group v-if="true" title="返回类型">
|
|
302
|
+
<fox-cascader-item
|
|
303
|
+
v-model="demo2.value"
|
|
304
|
+
:source="demo2.source"
|
|
305
|
+
title="请选择地址"
|
|
306
|
+
placeholder="请选择地址"
|
|
307
|
+
@change="events.change"
|
|
308
|
+
@path-change="events.pathChange"
|
|
309
|
+
>value</fox-cascader-item
|
|
310
|
+
>
|
|
311
|
+
<fox-cascader-item
|
|
312
|
+
value-type="text"
|
|
313
|
+
v-model="demo2.value2"
|
|
314
|
+
:source="demo2.source"
|
|
315
|
+
title="请选择地址"
|
|
316
|
+
placeholder="请选择地址"
|
|
317
|
+
@change="events.change"
|
|
318
|
+
@path-change="events.pathChange"
|
|
319
|
+
>text</fox-cascader-item
|
|
320
|
+
>
|
|
321
|
+
<fox-cascader-item
|
|
322
|
+
value-type="item"
|
|
323
|
+
v-model="demo2.value3"
|
|
324
|
+
:source="demo2.source"
|
|
325
|
+
title="请选择地址"
|
|
326
|
+
placeholder="请选择地址"
|
|
327
|
+
@change="events.change"
|
|
328
|
+
@path-change="events.pathChange"
|
|
329
|
+
>item</fox-cascader-item
|
|
330
|
+
>
|
|
331
|
+
</fox-group>
|
|
332
|
+
```
|
|
333
|
+
```ts
|
|
334
|
+
setup() {
|
|
335
|
+
// 返回类型
|
|
336
|
+
const demo2 = reactive({
|
|
337
|
+
value: ['01', '0102', '010201'],
|
|
338
|
+
value2: [],
|
|
339
|
+
value3: [
|
|
340
|
+
{ value: '03', text: '福建' },
|
|
341
|
+
{ value: '0301', text: '福州' },
|
|
342
|
+
{ value: '030102', text: '台江区' }
|
|
343
|
+
],
|
|
344
|
+
source: [
|
|
345
|
+
{
|
|
346
|
+
value: '01',
|
|
347
|
+
text: '浙江',
|
|
348
|
+
children: [
|
|
349
|
+
{
|
|
350
|
+
value: '0101',
|
|
351
|
+
text: '杭州',
|
|
352
|
+
disabled: true,
|
|
353
|
+
children: [
|
|
354
|
+
{ value: '010101', text: '西湖区' },
|
|
355
|
+
{ value: '010102', text: '余杭区' }
|
|
356
|
+
]
|
|
357
|
+
},
|
|
358
|
+
{
|
|
359
|
+
value: '0102',
|
|
360
|
+
text: '温州',
|
|
361
|
+
children: [
|
|
362
|
+
{ value: '010201', text: '鹿城区' },
|
|
363
|
+
{ value: '010201', text: '瓯海区' }
|
|
364
|
+
]
|
|
365
|
+
}
|
|
366
|
+
]
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
value: '02',
|
|
370
|
+
text: '湖南',
|
|
371
|
+
disabled: true
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
value: '03',
|
|
375
|
+
text: '福建',
|
|
376
|
+
children: [
|
|
377
|
+
{
|
|
378
|
+
value: '0301',
|
|
379
|
+
text: '福州',
|
|
380
|
+
children: [
|
|
381
|
+
{ value: '030101', text: '鼓楼区' },
|
|
382
|
+
{ value: '030102', text: '台江区' }
|
|
383
|
+
]
|
|
384
|
+
}
|
|
385
|
+
]
|
|
386
|
+
}
|
|
387
|
+
]
|
|
388
|
+
})
|
|
389
|
+
watch(
|
|
390
|
+
() => demo2.value,
|
|
391
|
+
val => {
|
|
392
|
+
console.info('demo value1', val)
|
|
393
|
+
}
|
|
394
|
+
)
|
|
395
|
+
watch(
|
|
396
|
+
() => demo2.value2,
|
|
397
|
+
val => {
|
|
398
|
+
console.info('demo value2', val)
|
|
399
|
+
}
|
|
400
|
+
)
|
|
401
|
+
watch(
|
|
402
|
+
() => demo2.value3,
|
|
403
|
+
val => {
|
|
404
|
+
console.info('demo value3', val)
|
|
405
|
+
}
|
|
406
|
+
)
|
|
407
|
+
|
|
408
|
+
const events = {
|
|
409
|
+
change(...args: any) {
|
|
410
|
+
console.log('change', ...args)
|
|
411
|
+
},
|
|
412
|
+
pathChange(...args: any) {
|
|
413
|
+
console.log('pathChange', ...args)
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
return { demo2, events }
|
|
418
|
+
}
|
|
419
|
+
```
|
|
420
|
+
### 数据源
|
|
421
|
+
组件的数据源有几种类型
|
|
422
|
+
* 数组
|
|
423
|
+
* 函数
|
|
424
|
+
* 服务API
|
|
425
|
+
```html
|
|
426
|
+
<fox-group v-if="true" title="数据源">
|
|
427
|
+
<fox-cascader-item
|
|
428
|
+
v-model="demo3.value"
|
|
429
|
+
:source="demo3.list"
|
|
430
|
+
title="请选择地址"
|
|
431
|
+
placeholder="请选择地址"
|
|
432
|
+
@change="events.change"
|
|
433
|
+
@path-change="events.pathChange"
|
|
434
|
+
>数组</fox-cascader-item
|
|
435
|
+
>
|
|
436
|
+
<fox-cascader-item
|
|
437
|
+
v-model="demo3.value2"
|
|
438
|
+
:source="demo3.func"
|
|
439
|
+
title="请选择地址"
|
|
440
|
+
placeholder="请选择地址"
|
|
441
|
+
@change="events.change"
|
|
442
|
+
@path-change="events.pathChange"
|
|
443
|
+
>函数</fox-cascader-item
|
|
444
|
+
>
|
|
445
|
+
<fox-cascader-item
|
|
446
|
+
v-model="demo3.value3"
|
|
447
|
+
:source="demo3.path"
|
|
448
|
+
title="请选择地址"
|
|
449
|
+
placeholder="请选择地址"
|
|
450
|
+
@change="events.change"
|
|
451
|
+
@path-change="events.pathChange"
|
|
452
|
+
>服务API</fox-cascader-item
|
|
453
|
+
>
|
|
454
|
+
</fox-group>
|
|
455
|
+
```
|
|
456
|
+
```ts
|
|
457
|
+
setup() {
|
|
458
|
+
// 数据源
|
|
459
|
+
const demo3 = reactive({
|
|
460
|
+
value: [],
|
|
461
|
+
value2: [],
|
|
462
|
+
value3: ['01', '0101', '010101'],
|
|
463
|
+
list: [
|
|
464
|
+
{
|
|
465
|
+
value: '浙江',
|
|
466
|
+
text: '浙江',
|
|
467
|
+
children: [
|
|
468
|
+
{
|
|
469
|
+
value: '杭州',
|
|
470
|
+
text: '杭州',
|
|
471
|
+
disabled: true,
|
|
472
|
+
children: [
|
|
473
|
+
{ value: '西湖区', text: '西湖区' },
|
|
474
|
+
{ value: '余杭区', text: '余杭区' }
|
|
475
|
+
]
|
|
476
|
+
},
|
|
477
|
+
{
|
|
478
|
+
value: '温州',
|
|
479
|
+
text: '温州',
|
|
480
|
+
children: [
|
|
481
|
+
{ value: '鹿城区', text: '鹿城区' },
|
|
482
|
+
{ value: '瓯海区', text: '瓯海区' }
|
|
483
|
+
]
|
|
484
|
+
}
|
|
485
|
+
]
|
|
486
|
+
},
|
|
487
|
+
{
|
|
488
|
+
value: '湖南',
|
|
489
|
+
text: '湖南',
|
|
490
|
+
disabled: true
|
|
491
|
+
},
|
|
492
|
+
{
|
|
493
|
+
value: '福建',
|
|
494
|
+
text: '福建',
|
|
495
|
+
children: [
|
|
496
|
+
{
|
|
497
|
+
value: '福州',
|
|
498
|
+
text: '福州',
|
|
499
|
+
children: [
|
|
500
|
+
{ value: '鼓楼区', text: '鼓楼区' },
|
|
501
|
+
{ value: '台江区', text: '台江区' }
|
|
502
|
+
]
|
|
503
|
+
}
|
|
504
|
+
]
|
|
505
|
+
}
|
|
506
|
+
],
|
|
507
|
+
func: () => {
|
|
508
|
+
return [
|
|
509
|
+
{
|
|
510
|
+
value: '广东',
|
|
511
|
+
text: '广东',
|
|
512
|
+
children: [
|
|
513
|
+
{
|
|
514
|
+
value: '广州',
|
|
515
|
+
text: '广州',
|
|
516
|
+
disabled: true,
|
|
517
|
+
children: [
|
|
518
|
+
{ value: '黄埔区', text: '黄埔区' },
|
|
519
|
+
{ value: '南沙', text: '南沙' }
|
|
520
|
+
]
|
|
521
|
+
},
|
|
522
|
+
{
|
|
523
|
+
value: '佛山',
|
|
524
|
+
text: '佛山',
|
|
525
|
+
children: [
|
|
526
|
+
{ value: '禅城区', text: '禅城区' },
|
|
527
|
+
{ value: '南海区', text: '南海区' }
|
|
528
|
+
]
|
|
529
|
+
}
|
|
530
|
+
]
|
|
531
|
+
},
|
|
532
|
+
{
|
|
533
|
+
value: '福建',
|
|
534
|
+
text: '福建',
|
|
535
|
+
children: [
|
|
536
|
+
{
|
|
537
|
+
value: '福州',
|
|
538
|
+
text: '福州',
|
|
539
|
+
children: [
|
|
540
|
+
{ value: '鼓楼区', text: '鼓楼区' },
|
|
541
|
+
{ value: '台江区', text: '台江区' }
|
|
542
|
+
]
|
|
543
|
+
}
|
|
544
|
+
]
|
|
545
|
+
}
|
|
546
|
+
]
|
|
547
|
+
},
|
|
548
|
+
path: '/DD/cascader'
|
|
549
|
+
})
|
|
550
|
+
|
|
551
|
+
const events = {
|
|
552
|
+
change(...args: any) {
|
|
553
|
+
console.log('change', ...args)
|
|
554
|
+
},
|
|
555
|
+
pathChange(...args: any) {
|
|
556
|
+
console.log('pathChange', ...args)
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return { demo3, events }
|
|
560
|
+
}
|
|
561
|
+
```
|
|
562
|
+
### 异构结构
|
|
563
|
+
默认的选项item的数据结构如下
|
|
564
|
+
```ts
|
|
565
|
+
export type CascaderOption = {
|
|
566
|
+
text?: string
|
|
567
|
+
value?: number | string
|
|
568
|
+
children?: CascaderOption[]
|
|
569
|
+
}
|
|
570
|
+
```
|
|
571
|
+
如果item的数据结构和默认的有差异,这需要通过
|
|
572
|
+
* text-key
|
|
573
|
+
* value-key
|
|
574
|
+
* children-key
|
|
575
|
+
三个属性重新指定对应的key
|
|
576
|
+
```html
|
|
577
|
+
<fox-group v-if="true" title="异构结构">
|
|
578
|
+
<fox-cascader-item
|
|
579
|
+
v-model="demo4.value"
|
|
580
|
+
:source="demo4.source"
|
|
581
|
+
title="地址选择"
|
|
582
|
+
text-key="name"
|
|
583
|
+
value-key="id"
|
|
584
|
+
children-key="items"
|
|
585
|
+
@change="events.change"
|
|
586
|
+
@path-change="events.pathChange"
|
|
587
|
+
>选择地址</fox-cascader-item
|
|
588
|
+
>
|
|
589
|
+
</fox-group>
|
|
590
|
+
```
|
|
591
|
+
```ts
|
|
592
|
+
setup() {
|
|
593
|
+
// 自定义属性名称
|
|
594
|
+
const demo4 = reactive({
|
|
595
|
+
value: ['01', '0101', '010101'],
|
|
596
|
+
source: [
|
|
597
|
+
{
|
|
598
|
+
id: '01',
|
|
599
|
+
name: '中国',
|
|
600
|
+
items: [
|
|
601
|
+
{
|
|
602
|
+
id: '0101',
|
|
603
|
+
name: '广东',
|
|
604
|
+
items: [
|
|
605
|
+
{ id: '010101', name: '广州' },
|
|
606
|
+
{ id: '010102', name: '佛山' },
|
|
607
|
+
{ id: '010103', name: '茂名' }
|
|
608
|
+
]
|
|
609
|
+
},
|
|
610
|
+
{
|
|
611
|
+
id: '0201',
|
|
612
|
+
name: '江苏',
|
|
613
|
+
items: [
|
|
614
|
+
{ id: '020101', name: '南京' },
|
|
615
|
+
{ id: '020102', name: '苏州' }
|
|
616
|
+
]
|
|
617
|
+
}
|
|
618
|
+
]
|
|
619
|
+
},
|
|
620
|
+
{
|
|
621
|
+
id: '02',
|
|
622
|
+
name: '欧洲',
|
|
623
|
+
items: [
|
|
624
|
+
{
|
|
625
|
+
id: '0201',
|
|
626
|
+
name: '法国',
|
|
627
|
+
items: [
|
|
628
|
+
{ id: '020101', name: '巴黎' },
|
|
629
|
+
{ id: '020102', name: '凡尔赛' }
|
|
630
|
+
]
|
|
631
|
+
}
|
|
632
|
+
]
|
|
633
|
+
}
|
|
634
|
+
]
|
|
635
|
+
})
|
|
636
|
+
|
|
637
|
+
const events = {
|
|
638
|
+
change(...args: any) {
|
|
639
|
+
console.log('change', ...args)
|
|
640
|
+
},
|
|
641
|
+
pathChange(...args: any) {
|
|
642
|
+
console.log('pathChange', ...args)
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
return { deme4, events }
|
|
646
|
+
}
|
|
647
|
+
```
|
|
648
|
+
### 动态加载
|
|
649
|
+
使用`lazy`标识是否需要动态获取数据,此时不传`options`代表所有数据都需要通过`lazyLoad`加载,首次加载通过`root`属性区分,当遇到非叶子节点时会调用`lazyLoad`方法,参数为当前节点和`resolve`方法,注意`resolve`方法必须调用,不传子节点时会被当做叶子节点处理。
|
|
650
|
+
```html
|
|
651
|
+
<fox-group v-if="true" title="动态加载">
|
|
652
|
+
<fox-cascader-item
|
|
653
|
+
title="地址选择"
|
|
654
|
+
v-model="demo5.value"
|
|
655
|
+
@change="events.change"
|
|
656
|
+
@path-change="events.pathChange"
|
|
657
|
+
lazy
|
|
658
|
+
:lazy-load="demo5.lazyLoad"
|
|
659
|
+
>地址选择</fox-cascader-item
|
|
660
|
+
>
|
|
661
|
+
</fox-group>
|
|
662
|
+
```
|
|
663
|
+
```ts
|
|
664
|
+
setup() {
|
|
665
|
+
// 动态加载
|
|
666
|
+
const demo5 = reactive({
|
|
667
|
+
value: ['A0', 'A12', 'A23', 'A32'],
|
|
668
|
+
lazyLoad(node: any, resolve: (children: any) => void) {
|
|
669
|
+
setTimeout(() => {
|
|
670
|
+
// root表示第一层数据
|
|
671
|
+
if (node.root) {
|
|
672
|
+
resolve([
|
|
673
|
+
{ value: 'A0', text: 'A0' },
|
|
674
|
+
{ value: 'B0', text: 'B0' },
|
|
675
|
+
{ value: 'C0', text: 'C0' }
|
|
676
|
+
])
|
|
677
|
+
} else {
|
|
678
|
+
const { value, level } = node
|
|
679
|
+
const text = value.substring(0, 1)
|
|
680
|
+
const value1 = `${text}${level + 1}1`
|
|
681
|
+
const value2 = `${text}${level + 1}2`
|
|
682
|
+
const value3 = `${text}${level + 1}3`
|
|
683
|
+
resolve([
|
|
684
|
+
{ value: value1, text: value1, leaf: level >= 6 },
|
|
685
|
+
{ value: value2, text: value2, leaf: level >= 6 },
|
|
686
|
+
{ value: value3, text: value3, leaf: level >= 6 }
|
|
687
|
+
])
|
|
688
|
+
}
|
|
689
|
+
}, 2000)
|
|
690
|
+
}
|
|
691
|
+
})
|
|
692
|
+
const events = {
|
|
693
|
+
change(...args: any) {
|
|
694
|
+
console.log('change', ...args)
|
|
695
|
+
},
|
|
696
|
+
pathChange(...args: any) {
|
|
697
|
+
console.log('pathChange', ...args)
|
|
698
|
+
}
|
|
699
|
+
}
|
|
700
|
+
return { demo5, events };
|
|
701
|
+
}
|
|
702
|
+
```
|
|
703
|
+
|
|
704
|
+
## 4. 相关组件 (Related Components)
|
|
705
|
+
- **fox-js**: 与 CascaderItem 配合使用的相关组件
|
|
706
|
+
- **fox-group**: 与 CascaderItem 配合使用的相关组件
|
|
707
|
+
- **fox-item**: 与 CascaderItem 配合使用的相关组件
|
|
708
|
+
- **fox-input-text**: 与 CascaderItem 配合使用的相关组件
|
|
709
|
+
- **fox-cascader**: 与 CascaderItem 配合使用的相关组件
|
|
710
|
+
|