jianghu-ui 1.0.1
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 +376 -0
- package/dist/jianghu-ui.css +2318 -0
- package/dist/jianghu-ui.js +2 -0
- package/dist/jianghu-ui.js.LICENSE.txt +1 -0
- package/package.json +56 -0
- package/src/Design.stories.mdx +195 -0
- package/src/Introduction.stories.mdx +148 -0
- package/src/components/JhAddressSelect/JhAddressSelect.md +250 -0
- package/src/components/JhAddressSelect/JhAddressSelect.stories.js +282 -0
- package/src/components/JhAddressSelect/JhAddressSelect.vue +261 -0
- package/src/components/JhCard/JhCard.md +246 -0
- package/src/components/JhCard/JhCard.stories.js +688 -0
- package/src/components/JhCard/JhCard.vue +604 -0
- package/src/components/JhCheckCard/JhCheckCard.md +245 -0
- package/src/components/JhCheckCard/JhCheckCard.stories.js +750 -0
- package/src/components/JhCheckCard/JhCheckCard.vue +476 -0
- package/src/components/JhConfirmDialog/JhConfirmDialog.md +70 -0
- package/src/components/JhConfirmDialog/JhConfirmDialog.stories.js +550 -0
- package/src/components/JhConfirmDialog/JhConfirmDialog.vue +181 -0
- package/src/components/JhDateRangePicker/JhDateRangePicker.md +56 -0
- package/src/components/JhDateRangePicker/JhDateRangePicker.stories.js +320 -0
- package/src/components/JhDateRangePicker/JhDateRangePicker.vue +307 -0
- package/src/components/JhDescriptions/JhDescriptions.md +724 -0
- package/src/components/JhDescriptions/JhDescriptions.stories.js +858 -0
- package/src/components/JhDescriptions/JhDescriptions.vue +933 -0
- package/src/components/JhDraggable/JhDraggable.md +66 -0
- package/src/components/JhDraggable/JhDraggable.stories.js +161 -0
- package/src/components/JhDraggable/JhDraggable.vue +254 -0
- package/src/components/JhDrawer/JhDrawer.md +68 -0
- package/src/components/JhDrawer/JhDrawer.stories.js +478 -0
- package/src/components/JhDrawer/JhDrawer.vue +281 -0
- package/src/components/JhDrawerForm/JhDrawerForm.md +69 -0
- package/src/components/JhDrawerForm/JhDrawerForm.stories.js +492 -0
- package/src/components/JhDrawerForm/JhDrawerForm.vue +297 -0
- package/src/components/JhEditableTable/JhEditableTable.md +507 -0
- package/src/components/JhEditableTable/JhEditableTable.stories.js +615 -0
- package/src/components/JhEditableTable/JhEditableTable.vue +685 -0
- package/src/components/JhFileInput/JhFileInput.md +56 -0
- package/src/components/JhFileInput/JhFileInput.stories.js +103 -0
- package/src/components/JhFileInput/JhFileInput.vue +253 -0
- package/src/components/JhForm/JhForm.md +676 -0
- package/src/components/JhForm/JhForm.stories.js +1375 -0
- package/src/components/JhForm/JhForm.vue +657 -0
- package/src/components/JhFormField/JhFormField.stories.js +217 -0
- package/src/components/JhFormField/JhFormField.vue +439 -0
- package/src/components/JhFormFields/JhFormFields.md +647 -0
- package/src/components/JhFormFields/JhFormFields.stories.js +922 -0
- package/src/components/JhFormFields/JhFormFields.vue +998 -0
- package/src/components/JhFormList/JhFormList.md +303 -0
- package/src/components/JhFormList/JhFormList.stories.js +661 -0
- package/src/components/JhFormList/JhFormList.vue +1127 -0
- package/src/components/JhJsonEditor/JhJsonEditor.md +54 -0
- package/src/components/JhJsonEditor/JhJsonEditor.stories.js +157 -0
- package/src/components/JhJsonEditor/JhJsonEditor.vue +178 -0
- package/src/components/JhLayout/JhLayout.md +580 -0
- package/src/components/JhLayout/JhLayout.stories.js +414 -0
- package/src/components/JhLayout/JhLayout.vue +387 -0
- package/src/components/JhList/JhList.md +441 -0
- package/src/components/JhList/JhList.stories.js +524 -0
- package/src/components/JhList/JhList.vue +571 -0
- package/src/components/JhMarkdownEditor/JhMarkdownEditor.md +56 -0
- package/src/components/JhMarkdownEditor/JhMarkdownEditor.stories.js +191 -0
- package/src/components/JhMarkdownEditor/JhMarkdownEditor.vue +188 -0
- package/src/components/JhMask/JhMask.md +62 -0
- package/src/components/JhMask/JhMask.stories.js +270 -0
- package/src/components/JhMask/JhMask.vue +123 -0
- package/src/components/JhMenu/JhMenu.md +85 -0
- package/src/components/JhMenu/JhMenu.stories.js +384 -0
- package/src/components/JhMenu/JhMenu.vue +545 -0
- package/src/components/JhModal/JhModal.md +68 -0
- package/src/components/JhModal/JhModal.stories.js +562 -0
- package/src/components/JhModal/JhModal.vue +235 -0
- package/src/components/JhModalForm/JhModalForm.md +69 -0
- package/src/components/JhModalForm/JhModalForm.stories.js +592 -0
- package/src/components/JhModalForm/JhModalForm.vue +298 -0
- package/src/components/JhPageContainer/JhPageContainer.md +409 -0
- package/src/components/JhPageContainer/JhPageContainer.stories.js +209 -0
- package/src/components/JhPageContainer/JhPageContainer.vue +72 -0
- package/src/components/JhQueryFilter/JhQueryFilter.md +77 -0
- package/src/components/JhQueryFilter/JhQueryFilter.stories.js +684 -0
- package/src/components/JhQueryFilter/JhQueryFilter.vue +429 -0
- package/src/components/JhScene/JhScene.md +64 -0
- package/src/components/JhScene/JhScene.stories.js +317 -0
- package/src/components/JhScene/JhScene.vue +376 -0
- package/src/components/JhStatisticCard/JhStatisticCard.md +363 -0
- package/src/components/JhStatisticCard/JhStatisticCard.stories.js +847 -0
- package/src/components/JhStatisticCard/JhStatisticCard.vue +459 -0
- package/src/components/JhStepsForm/JhStepsForm.md +666 -0
- package/src/components/JhStepsForm/JhStepsForm.stories.js +1224 -0
- package/src/components/JhStepsForm/JhStepsForm.vue +749 -0
- package/src/components/JhTable/JhTable.md +730 -0
- package/src/components/JhTable/JhTable.stories.js +1444 -0
- package/src/components/JhTable/JhTable.vue +2298 -0
- package/src/components/JhTableAttachment/JhTableAttachment.md +70 -0
- package/src/components/JhTableAttachment/JhTableAttachment.stories.js +198 -0
- package/src/components/JhTableAttachment/JhTableAttachment.vue +264 -0
- package/src/components/JhToast/JhToast.md +67 -0
- package/src/components/JhToast/JhToast.stories.js +386 -0
- package/src/components/JhToast/JhToast.vue +239 -0
- package/src/components/JhTreeSelect/JhTreeSelect.md +82 -0
- package/src/components/JhTreeSelect/JhTreeSelect.stories.js +391 -0
- package/src/components/JhTreeSelect/JhTreeSelect.vue +727 -0
- package/src/components/JhWaterMark/JhWaterMark.md +190 -0
- package/src/components/JhWaterMark/JhWaterMark.stories.js +675 -0
- package/src/components/JhWaterMark/JhWaterMark.vue +351 -0
- package/src/components/README.md +52 -0
- package/src/index.js +135 -0
- package/src/style/globalCSSJHV4.css +348 -0
- package/src/style/globalCSSVuetifyV4.css +637 -0
- package/src/style/storybook.css +4 -0
- package/src/tailwind.css +3 -0
- package/src/utils/vuetify.js +31 -0
|
@@ -0,0 +1,724 @@
|
|
|
1
|
+
# JhDescriptions 描述列表
|
|
2
|
+
|
|
3
|
+
基于 Ant Design ProDescriptions 设计的数据展示组件,用于展示结构化的详情信息。
|
|
4
|
+
|
|
5
|
+
## 功能特性
|
|
6
|
+
|
|
7
|
+
- 📋 **多种布局** - 支持水平、垂直、行内与简洁四种布局方式
|
|
8
|
+
- ✏️ **可编辑模式** - 支持行内编辑,快速修改数据
|
|
9
|
+
- 🎨 **丰富的 ValueType** - 内置多种数据类型格式化
|
|
10
|
+
- 📱 **响应式列数** - 支持不同屏幕尺寸自适应列数
|
|
11
|
+
- 📋 **一键复制** - 支持字段内容快速复制
|
|
12
|
+
- 🔄 **异步加载** - 支持通过 request 方法异步获取数据
|
|
13
|
+
- 🎯 **自定义渲染** - 支持自定义渲染函数和插槽
|
|
14
|
+
- 🎭 **多种尺寸** - 支持 small 和 default 两种尺寸
|
|
15
|
+
|
|
16
|
+
## 基础用法
|
|
17
|
+
|
|
18
|
+
```vue
|
|
19
|
+
<template>
|
|
20
|
+
<jh-descriptions
|
|
21
|
+
title="用户信息"
|
|
22
|
+
:columns="columns"
|
|
23
|
+
:data-source="dataSource"
|
|
24
|
+
:column="3"
|
|
25
|
+
bordered
|
|
26
|
+
/>
|
|
27
|
+
</template>
|
|
28
|
+
|
|
29
|
+
<script>
|
|
30
|
+
export default {
|
|
31
|
+
data() {
|
|
32
|
+
return {
|
|
33
|
+
columns: [
|
|
34
|
+
{
|
|
35
|
+
title: '用户名',
|
|
36
|
+
dataIndex: 'username',
|
|
37
|
+
key: 'username',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
title: '手机号',
|
|
41
|
+
dataIndex: 'phone',
|
|
42
|
+
key: 'phone',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
title: '邮箱',
|
|
46
|
+
dataIndex: 'email',
|
|
47
|
+
key: 'email',
|
|
48
|
+
},
|
|
49
|
+
],
|
|
50
|
+
dataSource: {
|
|
51
|
+
username: '张三',
|
|
52
|
+
phone: '13800138000',
|
|
53
|
+
email: 'zhangsan@example.com',
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
</script>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## 垂直布局
|
|
62
|
+
|
|
63
|
+
```vue
|
|
64
|
+
<template>
|
|
65
|
+
<jh-descriptions
|
|
66
|
+
title="产品详情"
|
|
67
|
+
layout="vertical"
|
|
68
|
+
:columns="columns"
|
|
69
|
+
:data-source="dataSource"
|
|
70
|
+
:column="3"
|
|
71
|
+
/>
|
|
72
|
+
</template>
|
|
73
|
+
|
|
74
|
+
<script>
|
|
75
|
+
export default {
|
|
76
|
+
data() {
|
|
77
|
+
return {
|
|
78
|
+
columns: [
|
|
79
|
+
{
|
|
80
|
+
title: '产品名称',
|
|
81
|
+
dataIndex: 'productName',
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
title: '产品价格',
|
|
85
|
+
dataIndex: 'price',
|
|
86
|
+
valueType: 'money',
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
title: '库存数量',
|
|
90
|
+
dataIndex: 'stock',
|
|
91
|
+
valueType: 'digit',
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
dataSource: {
|
|
95
|
+
productName: 'iPhone 15 Pro',
|
|
96
|
+
price: 7999,
|
|
97
|
+
stock: 1234,
|
|
98
|
+
},
|
|
99
|
+
};
|
|
100
|
+
},
|
|
101
|
+
};
|
|
102
|
+
</script>
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## 行内 / 简洁布局
|
|
106
|
+
|
|
107
|
+
```vue
|
|
108
|
+
<template>
|
|
109
|
+
<div class="space-y-6">
|
|
110
|
+
<jh-descriptions
|
|
111
|
+
title="行内展示(紧凑左右)"
|
|
112
|
+
layout="inline"
|
|
113
|
+
:columns="columns"
|
|
114
|
+
:data-source="dataSource"
|
|
115
|
+
:column="{ default: 3, md: 2, sm: 1 }"
|
|
116
|
+
/>
|
|
117
|
+
|
|
118
|
+
<jh-descriptions
|
|
119
|
+
title="简洁展示(上下堆叠)"
|
|
120
|
+
layout="simple"
|
|
121
|
+
:columns="columns"
|
|
122
|
+
:data-source="dataSource"
|
|
123
|
+
:column="2"
|
|
124
|
+
:bordered="false"
|
|
125
|
+
/>
|
|
126
|
+
</div>
|
|
127
|
+
</template>
|
|
128
|
+
|
|
129
|
+
<script>
|
|
130
|
+
export default {
|
|
131
|
+
data() {
|
|
132
|
+
return {
|
|
133
|
+
columns: [
|
|
134
|
+
{ title: '负责人', dataIndex: 'owner' },
|
|
135
|
+
{ title: '创建时间', dataIndex: 'createdAt', valueType: 'dateTime' },
|
|
136
|
+
{ title: '状态', dataIndex: 'status', valueType: 'option', valueEnum: { enabled: '启用', disabled: '禁用' } },
|
|
137
|
+
],
|
|
138
|
+
dataSource: {
|
|
139
|
+
owner: '陈小明',
|
|
140
|
+
createdAt: '2024-01-20 09:00:00',
|
|
141
|
+
status: 'enabled',
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
},
|
|
145
|
+
};
|
|
146
|
+
</script>
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## 可编辑模式
|
|
150
|
+
|
|
151
|
+
```vue
|
|
152
|
+
<template>
|
|
153
|
+
<jh-descriptions
|
|
154
|
+
title="个人信息"
|
|
155
|
+
:columns="columns"
|
|
156
|
+
:data-source="dataSource"
|
|
157
|
+
:editable="true"
|
|
158
|
+
@save="handleSave"
|
|
159
|
+
/>
|
|
160
|
+
</template>
|
|
161
|
+
|
|
162
|
+
<script>
|
|
163
|
+
export default {
|
|
164
|
+
data() {
|
|
165
|
+
return {
|
|
166
|
+
columns: [
|
|
167
|
+
{
|
|
168
|
+
title: '姓名',
|
|
169
|
+
dataIndex: 'name',
|
|
170
|
+
editable: true,
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
title: '年龄',
|
|
174
|
+
dataIndex: 'age',
|
|
175
|
+
valueType: 'digit',
|
|
176
|
+
editable: true,
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
title: '性别',
|
|
180
|
+
dataIndex: 'gender',
|
|
181
|
+
valueType: 'select',
|
|
182
|
+
editable: true,
|
|
183
|
+
valueEnum: {
|
|
184
|
+
male: '男',
|
|
185
|
+
female: '女',
|
|
186
|
+
},
|
|
187
|
+
},
|
|
188
|
+
],
|
|
189
|
+
dataSource: {
|
|
190
|
+
name: '李四',
|
|
191
|
+
age: 28,
|
|
192
|
+
gender: 'male',
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
},
|
|
196
|
+
methods: {
|
|
197
|
+
handleSave(data) {
|
|
198
|
+
console.log('保存数据:', data);
|
|
199
|
+
// 调用 API 保存数据
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
</script>
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
## ValueType 类型
|
|
207
|
+
|
|
208
|
+
组件支持多种内置的数据类型格式化:
|
|
209
|
+
|
|
210
|
+
```vue
|
|
211
|
+
<template>
|
|
212
|
+
<jh-descriptions
|
|
213
|
+
title="ValueType 示例"
|
|
214
|
+
:columns="columns"
|
|
215
|
+
:data-source="dataSource"
|
|
216
|
+
/>
|
|
217
|
+
</template>
|
|
218
|
+
|
|
219
|
+
<script>
|
|
220
|
+
export default {
|
|
221
|
+
data() {
|
|
222
|
+
return {
|
|
223
|
+
columns: [
|
|
224
|
+
{
|
|
225
|
+
title: '金额',
|
|
226
|
+
dataIndex: 'money',
|
|
227
|
+
valueType: 'money', // ¥ 12,345.67
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
title: '百分比',
|
|
231
|
+
dataIndex: 'percent',
|
|
232
|
+
valueType: 'percent', // 85%
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
title: '数字',
|
|
236
|
+
dataIndex: 'digit',
|
|
237
|
+
valueType: 'digit', // 1,234,567
|
|
238
|
+
},
|
|
239
|
+
{
|
|
240
|
+
title: '日期',
|
|
241
|
+
dataIndex: 'date',
|
|
242
|
+
valueType: 'date', // 2024-01-15
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
title: '日期时间',
|
|
246
|
+
dataIndex: 'dateTime',
|
|
247
|
+
valueType: 'dateTime', // 2024-01-15 14:30:00
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
title: '时间',
|
|
251
|
+
dataIndex: 'time',
|
|
252
|
+
valueType: 'time', // 14:30:00
|
|
253
|
+
},
|
|
254
|
+
{
|
|
255
|
+
title: '选项',
|
|
256
|
+
dataIndex: 'status',
|
|
257
|
+
valueType: 'option',
|
|
258
|
+
valueEnum: {
|
|
259
|
+
success: '成功',
|
|
260
|
+
error: '失败',
|
|
261
|
+
},
|
|
262
|
+
},
|
|
263
|
+
],
|
|
264
|
+
dataSource: {
|
|
265
|
+
money: 12345.67,
|
|
266
|
+
percent: 85,
|
|
267
|
+
digit: 1234567,
|
|
268
|
+
date: '2024-01-15',
|
|
269
|
+
dateTime: '2024-01-15 14:30:00',
|
|
270
|
+
time: '14:30:00',
|
|
271
|
+
status: 'success',
|
|
272
|
+
},
|
|
273
|
+
};
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
</script>
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
## 自定义渲染
|
|
280
|
+
|
|
281
|
+
### 使用 render 函数
|
|
282
|
+
|
|
283
|
+
```vue
|
|
284
|
+
<template>
|
|
285
|
+
<jh-descriptions
|
|
286
|
+
:columns="columns"
|
|
287
|
+
:data-source="dataSource"
|
|
288
|
+
/>
|
|
289
|
+
</template>
|
|
290
|
+
|
|
291
|
+
<script>
|
|
292
|
+
export default {
|
|
293
|
+
data() {
|
|
294
|
+
return {
|
|
295
|
+
columns: [
|
|
296
|
+
{
|
|
297
|
+
title: '状态',
|
|
298
|
+
dataIndex: 'status',
|
|
299
|
+
render: (value) => {
|
|
300
|
+
const statusMap = {
|
|
301
|
+
active: '<span style="color: #52c41a;">● 活跃</span>',
|
|
302
|
+
inactive: '<span style="color: #ff4d4f;">● 未激活</span>',
|
|
303
|
+
};
|
|
304
|
+
return statusMap[value] || value;
|
|
305
|
+
},
|
|
306
|
+
},
|
|
307
|
+
{
|
|
308
|
+
title: '进度',
|
|
309
|
+
dataIndex: 'progress',
|
|
310
|
+
render: (value) => {
|
|
311
|
+
const color = value >= 80 ? '#52c41a' : '#faad14';
|
|
312
|
+
return `
|
|
313
|
+
<div style="display: flex; align-items: center; gap: 8px;">
|
|
314
|
+
<div style="flex: 1; height: 8px; background: #f0f0f0; border-radius: 4px;">
|
|
315
|
+
<div style="width: ${value}%; height: 100%; background: ${color};"></div>
|
|
316
|
+
</div>
|
|
317
|
+
<span>${value}%</span>
|
|
318
|
+
</div>
|
|
319
|
+
`;
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
],
|
|
323
|
+
dataSource: {
|
|
324
|
+
status: 'active',
|
|
325
|
+
progress: 75,
|
|
326
|
+
},
|
|
327
|
+
};
|
|
328
|
+
},
|
|
329
|
+
};
|
|
330
|
+
</script>
|
|
331
|
+
```
|
|
332
|
+
|
|
333
|
+
### 使用插槽
|
|
334
|
+
|
|
335
|
+
```vue
|
|
336
|
+
<template>
|
|
337
|
+
<jh-descriptions
|
|
338
|
+
:columns="columns"
|
|
339
|
+
:data-source="dataSource"
|
|
340
|
+
>
|
|
341
|
+
<template #item-avatar="{ value }">
|
|
342
|
+
<img :src="value" alt="avatar" style="width: 48px; height: 48px; border-radius: 50%;" />
|
|
343
|
+
</template>
|
|
344
|
+
|
|
345
|
+
<template #item-tags="{ value }">
|
|
346
|
+
<div style="display: flex; gap: 8px;">
|
|
347
|
+
<span
|
|
348
|
+
v-for="tag in value"
|
|
349
|
+
:key="tag"
|
|
350
|
+
style="padding: 2px 8px; background: #f0f0f0; border-radius: 4px;"
|
|
351
|
+
>
|
|
352
|
+
{{ tag }}
|
|
353
|
+
</span>
|
|
354
|
+
</div>
|
|
355
|
+
</template>
|
|
356
|
+
</jh-descriptions>
|
|
357
|
+
</template>
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## 可复制
|
|
361
|
+
|
|
362
|
+
```vue
|
|
363
|
+
<template>
|
|
364
|
+
<jh-descriptions
|
|
365
|
+
title="API 配置"
|
|
366
|
+
:columns="columns"
|
|
367
|
+
:data-source="dataSource"
|
|
368
|
+
@copy="handleCopy"
|
|
369
|
+
/>
|
|
370
|
+
</template>
|
|
371
|
+
|
|
372
|
+
<script>
|
|
373
|
+
export default {
|
|
374
|
+
data() {
|
|
375
|
+
return {
|
|
376
|
+
columns: [
|
|
377
|
+
{
|
|
378
|
+
title: 'API Key',
|
|
379
|
+
dataIndex: 'apiKey',
|
|
380
|
+
copyable: true, // 显示复制按钮
|
|
381
|
+
},
|
|
382
|
+
{
|
|
383
|
+
title: 'Secret Key',
|
|
384
|
+
dataIndex: 'secretKey',
|
|
385
|
+
copyable: true,
|
|
386
|
+
},
|
|
387
|
+
],
|
|
388
|
+
dataSource: {
|
|
389
|
+
apiKey: 'sk_test_1234567890abcdef',
|
|
390
|
+
secretKey: 'sk_live_abcdef1234567890',
|
|
391
|
+
},
|
|
392
|
+
};
|
|
393
|
+
},
|
|
394
|
+
methods: {
|
|
395
|
+
handleCopy({ text, item }) {
|
|
396
|
+
console.log('已复制:', text);
|
|
397
|
+
this.$toast.success('复制成功');
|
|
398
|
+
},
|
|
399
|
+
},
|
|
400
|
+
};
|
|
401
|
+
</script>
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
## 异步加载数据
|
|
405
|
+
|
|
406
|
+
```vue
|
|
407
|
+
<template>
|
|
408
|
+
<jh-descriptions
|
|
409
|
+
title="文章详情"
|
|
410
|
+
:columns="columns"
|
|
411
|
+
:request="fetchArticle"
|
|
412
|
+
:params="{ id: articleId }"
|
|
413
|
+
@request-success="handleSuccess"
|
|
414
|
+
@request-error="handleError"
|
|
415
|
+
/>
|
|
416
|
+
</template>
|
|
417
|
+
|
|
418
|
+
<script>
|
|
419
|
+
export default {
|
|
420
|
+
data() {
|
|
421
|
+
return {
|
|
422
|
+
articleId: 1,
|
|
423
|
+
columns: [
|
|
424
|
+
{
|
|
425
|
+
title: '标题',
|
|
426
|
+
dataIndex: 'title',
|
|
427
|
+
},
|
|
428
|
+
{
|
|
429
|
+
title: '作者',
|
|
430
|
+
dataIndex: 'author',
|
|
431
|
+
},
|
|
432
|
+
{
|
|
433
|
+
title: '发布时间',
|
|
434
|
+
dataIndex: 'publishTime',
|
|
435
|
+
valueType: 'dateTime',
|
|
436
|
+
},
|
|
437
|
+
],
|
|
438
|
+
};
|
|
439
|
+
},
|
|
440
|
+
methods: {
|
|
441
|
+
async fetchArticle(params) {
|
|
442
|
+
const response = await fetch(`/api/articles/${params.id}`);
|
|
443
|
+
return response.json();
|
|
444
|
+
},
|
|
445
|
+
handleSuccess(data) {
|
|
446
|
+
console.log('数据加载成功:', data);
|
|
447
|
+
},
|
|
448
|
+
handleError(error) {
|
|
449
|
+
console.error('数据加载失败:', error);
|
|
450
|
+
},
|
|
451
|
+
},
|
|
452
|
+
};
|
|
453
|
+
</script>
|
|
454
|
+
```
|
|
455
|
+
|
|
456
|
+
## 响应式列数
|
|
457
|
+
|
|
458
|
+
```vue
|
|
459
|
+
<template>
|
|
460
|
+
<jh-descriptions
|
|
461
|
+
:columns="columns"
|
|
462
|
+
:data-source="dataSource"
|
|
463
|
+
:column="{
|
|
464
|
+
xs: 1,
|
|
465
|
+
sm: 2,
|
|
466
|
+
md: 3,
|
|
467
|
+
lg: 3,
|
|
468
|
+
xl: 4,
|
|
469
|
+
xxl: 4,
|
|
470
|
+
}"
|
|
471
|
+
/>
|
|
472
|
+
</template>
|
|
473
|
+
```
|
|
474
|
+
|
|
475
|
+
## API
|
|
476
|
+
|
|
477
|
+
### JhDescriptions Props
|
|
478
|
+
|
|
479
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
480
|
+
|------|------|------|--------|
|
|
481
|
+
| title | 标题 | `string` | - |
|
|
482
|
+
| tooltip | 标题提示信息 | `string` | - |
|
|
483
|
+
| columns | 列配置 | `Column[]` | `[]` |
|
|
484
|
+
| dataSource | 数据源 | `object` | `{}` |
|
|
485
|
+
| request | 请求数据的方法 | `(params) => Promise<object>` | - |
|
|
486
|
+
| params | 请求参数 | `object` | `{}` |
|
|
487
|
+
| column | 列数 | `number \| object` | `3` |
|
|
488
|
+
| layout | 布局方式 | `'horizontal' \| 'vertical'` | `'horizontal'` |
|
|
489
|
+
| bordered | 是否显示边框 | `boolean` | `true` |
|
|
490
|
+
| size | 尺寸 | `'small' \| 'default'` | `'default'` |
|
|
491
|
+
| colon | 是否显示冒号 | `boolean` | `true` |
|
|
492
|
+
| labelWidth | 标签宽度比例(仅水平布局) | `number \| string` | `'auto'` |
|
|
493
|
+
| editable | 是否可编辑 | `boolean \| object` | `false` |
|
|
494
|
+
| editText | 编辑按钮文本 | `string` | `'编辑'` |
|
|
495
|
+
| cancelText | 取消按钮文本 | `string` | `'取消'` |
|
|
496
|
+
| saveText | 保存按钮文本 | `string` | `'保存'` |
|
|
497
|
+
| emptyText | 空值占位符 | `string` | `'-'` |
|
|
498
|
+
| loading | 加载状态 | `boolean` | `false` |
|
|
499
|
+
| responsive | 响应式配置 | `boolean` | `true` |
|
|
500
|
+
|
|
501
|
+
### Column 配置
|
|
502
|
+
|
|
503
|
+
| 参数 | 说明 | 类型 | 默认值 |
|
|
504
|
+
|------|------|------|--------|
|
|
505
|
+
| title | 标题 | `string` | - |
|
|
506
|
+
| label | 标签(同 title) | `string` | - |
|
|
507
|
+
| dataIndex | 数据字段名 | `string` | - |
|
|
508
|
+
| key | 唯一标识 | `string` | - |
|
|
509
|
+
| valueType | 值类型 | `ValueType` | `'text'` |
|
|
510
|
+
| valueEnum | 值枚举(用于 option 类型) | `object` | - |
|
|
511
|
+
| span | 跨列数 | `number` | `1` |
|
|
512
|
+
| tooltip | 提示信息 | `string` | - |
|
|
513
|
+
| copyable | 是否可复制 | `boolean` | `false` |
|
|
514
|
+
| editable | 是否可编辑 | `boolean` | `true` |
|
|
515
|
+
| disabled | 是否禁用编辑 | `boolean` | `false` |
|
|
516
|
+
| readonly | 是否只读 | `boolean` | `false` |
|
|
517
|
+
| render | 自定义渲染函数 | `(value, record, item) => string` | - |
|
|
518
|
+
| fieldComponent | 编辑时的字段组件 | `string` | - |
|
|
519
|
+
| fieldProps | 字段组件属性 | `object` | - |
|
|
520
|
+
| visible | 是否可见 | `boolean \| (record) => boolean` | `true` |
|
|
521
|
+
| hideInDescriptions | 是否在描述列表中隐藏 | `boolean` | `false` |
|
|
522
|
+
| labelCol | 标签列宽(仅水平布局) | `number` | `6` |
|
|
523
|
+
|
|
524
|
+
### ValueType 类型
|
|
525
|
+
|
|
526
|
+
| 类型 | 说明 | 示例 |
|
|
527
|
+
|------|------|------|
|
|
528
|
+
| text | 文本 | 普通文本 |
|
|
529
|
+
| textarea | 多行文本 | 长文本 |
|
|
530
|
+
| digit | 数字 | 1,234,567 |
|
|
531
|
+
| money | 金额 | ¥ 12,345.67 |
|
|
532
|
+
| percent | 百分比 | 85% |
|
|
533
|
+
| date | 日期 | 2024-01-15 |
|
|
534
|
+
| dateTime | 日期时间 | 2024-01-15 14:30:00 |
|
|
535
|
+
| time | 时间 | 14:30:00 |
|
|
536
|
+
| option | 选项 | 需配合 valueEnum 使用 |
|
|
537
|
+
| select | 下拉选择 | 编辑模式下显示 |
|
|
538
|
+
| radio | 单选 | 编辑模式下显示 |
|
|
539
|
+
| checkbox | 复选框 | 编辑模式下显示 |
|
|
540
|
+
| switch | 开关 | 编辑模式下显示 |
|
|
541
|
+
|
|
542
|
+
### Events
|
|
543
|
+
|
|
544
|
+
| 事件名 | 说明 | 回调参数 |
|
|
545
|
+
|--------|------|----------|
|
|
546
|
+
| save | 保存数据 | `(data: object)` |
|
|
547
|
+
| save-success | 保存成功 | `(data: object)` |
|
|
548
|
+
| save-error | 保存失败 | `(error: Error)` |
|
|
549
|
+
| cancel | 取消编辑 | - |
|
|
550
|
+
| edit-start | 开始编辑 | - |
|
|
551
|
+
| field-change | 字段值变化 | `{ field, value, item }` |
|
|
552
|
+
| copy | 复制内容 | `{ text, item }` |
|
|
553
|
+
| request-success | 请求成功 | `(data: object)` |
|
|
554
|
+
| request-error | 请求失败 | `(error: Error)` |
|
|
555
|
+
|
|
556
|
+
### Slots
|
|
557
|
+
|
|
558
|
+
| 插槽名 | 说明 | 参数 |
|
|
559
|
+
|--------|------|------|
|
|
560
|
+
| title | 自定义标题 | - |
|
|
561
|
+
| extra | 额外内容 | - |
|
|
562
|
+
| item-{dataIndex} | 自定义字段内容 | `{ value, record, item }` |
|
|
563
|
+
|
|
564
|
+
### Methods
|
|
565
|
+
|
|
566
|
+
| 方法名 | 说明 | 参数 |
|
|
567
|
+
|--------|------|------|
|
|
568
|
+
| reload | 重新加载数据 | - |
|
|
569
|
+
|
|
570
|
+
## 响应式断点
|
|
571
|
+
|
|
572
|
+
| 断点 | 屏幕宽度 |
|
|
573
|
+
|------|----------|
|
|
574
|
+
| xs | < 576px |
|
|
575
|
+
| sm | ≥ 576px |
|
|
576
|
+
| md | ≥ 768px |
|
|
577
|
+
| lg | ≥ 992px |
|
|
578
|
+
| xl | ≥ 1200px |
|
|
579
|
+
| xxl | ≥ 1920px |
|
|
580
|
+
|
|
581
|
+
## 样式定制
|
|
582
|
+
|
|
583
|
+
组件使用 scoped 样式,可以通过以下 CSS 变量进行定制:
|
|
584
|
+
|
|
585
|
+
```css
|
|
586
|
+
.jh-descriptions {
|
|
587
|
+
/* 标签背景色 */
|
|
588
|
+
--jh-descriptions-label-bg: #fafafa;
|
|
589
|
+
|
|
590
|
+
/* 标签文字颜色 */
|
|
591
|
+
--jh-descriptions-label-color: rgba(0, 0, 0, 0.85);
|
|
592
|
+
|
|
593
|
+
/* 内容文字颜色 */
|
|
594
|
+
--jh-descriptions-content-color: rgba(0, 0, 0, 0.65);
|
|
595
|
+
|
|
596
|
+
/* 边框颜色 */
|
|
597
|
+
--jh-descriptions-border-color: #f0f0f0;
|
|
598
|
+
}
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
## 最佳实践
|
|
602
|
+
|
|
603
|
+
### 1. 合理使用 span
|
|
604
|
+
|
|
605
|
+
对于需要占据更多空间的字段,使用 `span` 属性:
|
|
606
|
+
|
|
607
|
+
```javascript
|
|
608
|
+
{
|
|
609
|
+
title: '详细地址',
|
|
610
|
+
dataIndex: 'address',
|
|
611
|
+
span: 2, // 占据 2 列的空间
|
|
612
|
+
}
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
### 2. 编辑模式的表单验证
|
|
616
|
+
|
|
617
|
+
在编辑模式下,建议配合表单验证:
|
|
618
|
+
|
|
619
|
+
```javascript
|
|
620
|
+
{
|
|
621
|
+
title: '邮箱',
|
|
622
|
+
dataIndex: 'email',
|
|
623
|
+
editable: true,
|
|
624
|
+
fieldProps: {
|
|
625
|
+
rules: [
|
|
626
|
+
{ required: true, message: '请输入邮箱' },
|
|
627
|
+
{ type: 'email', message: '邮箱格式不正确' },
|
|
628
|
+
],
|
|
629
|
+
},
|
|
630
|
+
}
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
### 3. 异步数据加载
|
|
634
|
+
|
|
635
|
+
使用 `request` 方法时,建议添加错误处理:
|
|
636
|
+
|
|
637
|
+
```vue
|
|
638
|
+
<template>
|
|
639
|
+
<jh-descriptions
|
|
640
|
+
:request="fetchData"
|
|
641
|
+
@request-error="handleError"
|
|
642
|
+
/>
|
|
643
|
+
</template>
|
|
644
|
+
|
|
645
|
+
<script>
|
|
646
|
+
export default {
|
|
647
|
+
methods: {
|
|
648
|
+
async fetchData(params) {
|
|
649
|
+
try {
|
|
650
|
+
const response = await api.getData(params);
|
|
651
|
+
return response.data;
|
|
652
|
+
} catch (error) {
|
|
653
|
+
console.error('数据加载失败:', error);
|
|
654
|
+
throw error;
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
handleError(error) {
|
|
658
|
+
this.$toast.error('数据加载失败,请稍后重试');
|
|
659
|
+
},
|
|
660
|
+
},
|
|
661
|
+
};
|
|
662
|
+
</script>
|
|
663
|
+
```
|
|
664
|
+
|
|
665
|
+
### 4. 性能优化
|
|
666
|
+
|
|
667
|
+
对于大量数据,建议使用 `hideInDescriptions` 隐藏不必要的字段:
|
|
668
|
+
|
|
669
|
+
```javascript
|
|
670
|
+
{
|
|
671
|
+
title: '内部ID',
|
|
672
|
+
dataIndex: 'internalId',
|
|
673
|
+
hideInDescriptions: true, // 不在描述列表中显示
|
|
674
|
+
}
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
## 与 ProTable 共享配置
|
|
678
|
+
|
|
679
|
+
`JhDescriptions` 和 `JhTable` 可以共享相同的 columns 配置:
|
|
680
|
+
|
|
681
|
+
```javascript
|
|
682
|
+
const columns = [
|
|
683
|
+
{
|
|
684
|
+
title: '用户名',
|
|
685
|
+
dataIndex: 'username',
|
|
686
|
+
hideInTable: false, // 在表格中显示
|
|
687
|
+
hideInDescriptions: false, // 在描述列表中显示
|
|
688
|
+
},
|
|
689
|
+
{
|
|
690
|
+
title: '创建时间',
|
|
691
|
+
dataIndex: 'createTime',
|
|
692
|
+
valueType: 'dateTime',
|
|
693
|
+
hideInTable: false,
|
|
694
|
+
hideInDescriptions: false,
|
|
695
|
+
},
|
|
696
|
+
];
|
|
697
|
+
|
|
698
|
+
// 在表格中使用
|
|
699
|
+
<jh-table :columns="columns" />
|
|
700
|
+
|
|
701
|
+
// 在描述列表中使用
|
|
702
|
+
<jh-descriptions :columns="columns" />
|
|
703
|
+
```
|
|
704
|
+
|
|
705
|
+
## 注意事项
|
|
706
|
+
|
|
707
|
+
1. `dataIndex` 或 `key` 必须提供其中之一
|
|
708
|
+
2. 使用 `render` 函数时返回的 HTML 字符串会被渲染,注意 XSS 安全
|
|
709
|
+
3. 编辑模式下,`editable: false` 的字段不可编辑
|
|
710
|
+
4. `request` 方法应该返回一个对象,而不是数组
|
|
711
|
+
5. 响应式列数配置时,至少要提供 `default` 值
|
|
712
|
+
|
|
713
|
+
## 更新日志
|
|
714
|
+
|
|
715
|
+
### v1.0.0 (2024-01-15)
|
|
716
|
+
|
|
717
|
+
- ✨ 初始版本发布
|
|
718
|
+
- ✨ 支持水平和垂直布局
|
|
719
|
+
- ✨ 支持可编辑模式
|
|
720
|
+
- ✨ 支持多种 ValueType
|
|
721
|
+
- ✨ 支持异步数据加载
|
|
722
|
+
- ✨ 支持自定义渲染
|
|
723
|
+
- ✨ 支持响应式列数
|
|
724
|
+
- ✨ 支持复制功能
|