@a2simcode/ui 0.0.82 → 0.0.83
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/dist/simcode-ui.es.js +3 -1
- package/dist/simcode-ui.umd.js +1 -1
- package/dist/stats.html +1 -1
- package/docs/components/meta/buttons.ts +1 -1
- package/docs/components/meta/comp.ts +12 -0
- package/docs/components/meta/page.ts +2 -23
- package/docs/components/meta/tabs.ts +10 -0
- package/docs/components/page.md +15 -0
- package/docs/examples/page/dept-user-management.vue +211 -0
- package/package.json +1 -1
|
@@ -59,6 +59,18 @@ export default {
|
|
|
59
59
|
"description": "获取表格提供的方法",
|
|
60
60
|
"type": "func",
|
|
61
61
|
"default": "undefined"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"name": "colNum",
|
|
65
|
+
"description": "列索引",
|
|
66
|
+
"type": "number",
|
|
67
|
+
"default": "undefined"
|
|
68
|
+
},
|
|
69
|
+
{
|
|
70
|
+
"name": "rowNum",
|
|
71
|
+
"description": "行索引",
|
|
72
|
+
"type": "number",
|
|
73
|
+
"default": "undefined"
|
|
62
74
|
}
|
|
63
75
|
],
|
|
64
76
|
"events": [
|
|
@@ -3,7 +3,7 @@ export default {
|
|
|
3
3
|
{
|
|
4
4
|
"name": "schema",
|
|
5
5
|
"description": "模版",
|
|
6
|
-
"type": "
|
|
6
|
+
"type": "SchemaConfig[]",
|
|
7
7
|
"default": "() => []"
|
|
8
8
|
},
|
|
9
9
|
{
|
|
@@ -42,26 +42,5 @@ export default {
|
|
|
42
42
|
"type": "() => void"
|
|
43
43
|
}
|
|
44
44
|
],
|
|
45
|
-
"types": [
|
|
46
|
-
{
|
|
47
|
-
"name": "PageSchemaConfig",
|
|
48
|
-
"properties": [
|
|
49
|
-
{
|
|
50
|
-
"name": "id",
|
|
51
|
-
"type": "string",
|
|
52
|
-
"description": "id"
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"name": "type",
|
|
56
|
-
"type": "string",
|
|
57
|
-
"description": "类型"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
"name": "children",
|
|
61
|
-
"type": "PageSchemaConfig[]",
|
|
62
|
-
"description": "子集"
|
|
63
|
-
}
|
|
64
|
-
]
|
|
65
|
-
}
|
|
66
|
-
]
|
|
45
|
+
"types": []
|
|
67
46
|
}
|
|
@@ -45,6 +45,11 @@ export default {
|
|
|
45
45
|
"name": "beforeLeave",
|
|
46
46
|
"description": "切换标签之前的钩子,若返回 false 或者返回 Promise 且被 reject,则阻止切换",
|
|
47
47
|
"type": "TSFunctionType"
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
"name": "isFill",
|
|
51
|
+
"description": "是否充满容器",
|
|
52
|
+
"type": "boolean"
|
|
48
53
|
}
|
|
49
54
|
],
|
|
50
55
|
"events": [
|
|
@@ -129,6 +134,11 @@ export default {
|
|
|
129
134
|
"name": "beforeLeave",
|
|
130
135
|
"type": "(\n activeName: string | number,\n oldActiveName: string | number\n ) => boolean | Promise<boolean>",
|
|
131
136
|
"description": "切换标签之前的钩子,若返回 false 或者返回 Promise 且被 reject,则阻止切换"
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
"name": "isFill",
|
|
140
|
+
"type": "boolean",
|
|
141
|
+
"description": "是否充满容器"
|
|
132
142
|
}
|
|
133
143
|
]
|
|
134
144
|
}
|
package/docs/components/page.md
CHANGED
|
@@ -54,6 +54,19 @@
|
|
|
54
54
|
</template>
|
|
55
55
|
</Demo>
|
|
56
56
|
|
|
57
|
+
## 部门-用户联动示例
|
|
58
|
+
|
|
59
|
+
参考业务项目中常见的“左侧列表 / 右侧列表”的联动写法:点击左侧部门,触发 `onSelect` 更新筛选条件,并通过 `j-page.call('userTable','resetData')` 刷新右侧分页表格。
|
|
60
|
+
|
|
61
|
+
<Demo :source-code="pageDeptUserManagementCode">
|
|
62
|
+
<template #source>
|
|
63
|
+
<page-dept-user-management />
|
|
64
|
+
</template>
|
|
65
|
+
<template #description>
|
|
66
|
+
左侧使用 `j-table-panel`(不分页)展示部门;右侧使用 `j-table-panel`(分页)展示用户,并提供“全部用户 / 刷新”等常用按钮。
|
|
67
|
+
</template>
|
|
68
|
+
</Demo>
|
|
69
|
+
|
|
57
70
|
## API
|
|
58
71
|
|
|
59
72
|
<ApiTable :data="pageApi" componentName="page" />
|
|
@@ -63,10 +76,12 @@ import PageBasic from '../examples/page/basic.vue'
|
|
|
63
76
|
import PageInit from '../examples/page/init.vue'
|
|
64
77
|
import PageLog from '../examples/page/log.vue'
|
|
65
78
|
import PageUserManagement from '../examples/page/user-management.vue'
|
|
79
|
+
import PageDeptUserManagement from '../examples/page/dept-user-management.vue'
|
|
66
80
|
import pageApi from './meta/page'
|
|
67
81
|
|
|
68
82
|
import pageBasicCode from '../examples/page/basic.vue?raw'
|
|
69
83
|
import pageInitCode from '../examples/page/init.vue?raw'
|
|
70
84
|
import pageLogCode from '../examples/page/log.vue?raw'
|
|
71
85
|
import pageUserManagementCode from '../examples/page/user-management.vue?raw'
|
|
86
|
+
import pageDeptUserManagementCode from '../examples/page/dept-user-management.vue?raw'
|
|
72
87
|
</script>
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="j-block" style="height: 600px">
|
|
3
|
+
<j-page ref="pageRef" :noPadding="true" :schema="schema" />
|
|
4
|
+
</div>
|
|
5
|
+
</template>
|
|
6
|
+
|
|
7
|
+
<script setup lang="ts">
|
|
8
|
+
import type { TableColumnCompConfig } from '@a2simcode/ui'
|
|
9
|
+
|
|
10
|
+
import { ref } from 'vue'
|
|
11
|
+
import { ElMessage } from 'element-plus'
|
|
12
|
+
|
|
13
|
+
interface DeptRecord {
|
|
14
|
+
j_Id: string
|
|
15
|
+
j_Name: string
|
|
16
|
+
j_Code: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface UserRecord {
|
|
20
|
+
j_Id: number
|
|
21
|
+
j_DeptId: string
|
|
22
|
+
j_Account: string
|
|
23
|
+
j_Name: string
|
|
24
|
+
j_EnabledMark: 0 | 1
|
|
25
|
+
j_CreateDate: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const randomFrom = <T,>(arr: T[]) => arr[Math.floor(Math.random() * arr.length)]
|
|
29
|
+
|
|
30
|
+
const createDepts = (count: number): DeptRecord[] => {
|
|
31
|
+
const names = [
|
|
32
|
+
'研发中心',
|
|
33
|
+
'产品中心',
|
|
34
|
+
'市场部',
|
|
35
|
+
'销售部',
|
|
36
|
+
'财务部',
|
|
37
|
+
'人力资源部',
|
|
38
|
+
'运维部',
|
|
39
|
+
'客服部',
|
|
40
|
+
]
|
|
41
|
+
return Array.from({ length: count }).map((_, i) => {
|
|
42
|
+
const id = String(i + 1)
|
|
43
|
+
return {
|
|
44
|
+
j_Id: id,
|
|
45
|
+
j_Name: `${randomFrom(names)}-${String(i + 1).padStart(2, '0')}`,
|
|
46
|
+
j_Code: `D${String(i + 1).padStart(3, '0')}`,
|
|
47
|
+
}
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const createUsers = (count: number, deptIds: string[]): UserRecord[] => {
|
|
52
|
+
const names = ['张三', '李四', '王五', '赵六', '孙七', '周八', '吴九', '郑十']
|
|
53
|
+
const now = Date.now()
|
|
54
|
+
return Array.from({ length: count }).map((_, i) => {
|
|
55
|
+
const id = i + 1
|
|
56
|
+
const createTime = new Date(now - Math.floor(Math.random() * 30 * 24 * 60 * 60 * 1000))
|
|
57
|
+
return {
|
|
58
|
+
j_Id: id,
|
|
59
|
+
j_DeptId: randomFrom(deptIds),
|
|
60
|
+
j_Account: `user_${String(id).padStart(3, '0')}`,
|
|
61
|
+
j_Name: randomFrom(names),
|
|
62
|
+
j_EnabledMark: Math.random() > 0.2 ? 1 : 0,
|
|
63
|
+
j_CreateDate: createTime.toISOString(),
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const selectedDeptId = ref<string>('')
|
|
69
|
+
|
|
70
|
+
const depts = ref<DeptRecord[]>(createDepts(12))
|
|
71
|
+
const users = ref<UserRecord[]>(
|
|
72
|
+
createUsers(
|
|
73
|
+
86,
|
|
74
|
+
depts.value.map((d) => d.j_Id)
|
|
75
|
+
)
|
|
76
|
+
)
|
|
77
|
+
|
|
78
|
+
const api = {
|
|
79
|
+
getDepts: async (params: Record<string, any>) => {
|
|
80
|
+
const keyword = String(params?.keyword?.value || '').trim()
|
|
81
|
+
let list = [...depts.value]
|
|
82
|
+
if (keyword) {
|
|
83
|
+
list = list.filter((d) => d.j_Name.includes(keyword) || d.j_Code.includes(keyword))
|
|
84
|
+
}
|
|
85
|
+
return list
|
|
86
|
+
},
|
|
87
|
+
getUsers: async (params: Record<string, any>) => {
|
|
88
|
+
const keyword = String(params?.keyword?.value || '').trim()
|
|
89
|
+
const { pagination } = params || {}
|
|
90
|
+
const { rows = 10, page = 1 } = pagination || {}
|
|
91
|
+
|
|
92
|
+
let list = [...users.value]
|
|
93
|
+
if (selectedDeptId.value) {
|
|
94
|
+
list = list.filter((u) => u.j_DeptId === selectedDeptId.value)
|
|
95
|
+
}
|
|
96
|
+
if (keyword) {
|
|
97
|
+
list = list.filter((u) => u.j_Name.includes(keyword) || u.j_Account.includes(keyword))
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const start = (page - 1) * rows
|
|
101
|
+
const end = start + rows
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
rows: list.slice(start, end),
|
|
105
|
+
records: list.length,
|
|
106
|
+
}
|
|
107
|
+
},
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const pageRef = ref()
|
|
111
|
+
|
|
112
|
+
const refreshUsers = (reset = false) => {
|
|
113
|
+
pageRef.value?.call('userTable', reset ? 'resetData' : 'refreshData')
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
const deptColumns = [
|
|
117
|
+
{ id: 'j_Name', config: { label: '部门', width: 160, filter: { isSearchKeyword: true } } },
|
|
118
|
+
{ id: 'j_Code', config: { label: '编码', width: 90, filter: { isSearchKeyword: true } } },
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
const userColumnsConfig: Record<string, TableColumnCompConfig> = {
|
|
122
|
+
j_Name: { width: 120, filter: { isSearchKeyword: true } },
|
|
123
|
+
j_Account: { width: 140, filter: { isSearchKeyword: true } },
|
|
124
|
+
j_DeptId: { width: 90, align: 'center' },
|
|
125
|
+
j_EnabledMark: {
|
|
126
|
+
type: 'j-switch',
|
|
127
|
+
activeValue: 1,
|
|
128
|
+
inactiveValue: 0,
|
|
129
|
+
width: 72,
|
|
130
|
+
align: 'center',
|
|
131
|
+
change: async () => {
|
|
132
|
+
ElMessage.success('更新成功')
|
|
133
|
+
},
|
|
134
|
+
},
|
|
135
|
+
j_CreateDate: { type: 'dateTime', width: 168 },
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const userColumns = [
|
|
139
|
+
{ id: 'j_Name', label: '姓名' },
|
|
140
|
+
{ id: 'j_Account', label: '账号' },
|
|
141
|
+
{ id: 'j_DeptId', label: '部门ID' },
|
|
142
|
+
{ id: 'j_EnabledMark', label: '有效' },
|
|
143
|
+
{ id: 'j_CreateDate', label: '创建时间' },
|
|
144
|
+
].map((item) => {
|
|
145
|
+
const cfg = userColumnsConfig[item.id] || {}
|
|
146
|
+
return {
|
|
147
|
+
id: item.id,
|
|
148
|
+
type: cfg.type || '',
|
|
149
|
+
config: { ...cfg, label: item.label },
|
|
150
|
+
}
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
const userButtons = [
|
|
154
|
+
{
|
|
155
|
+
id: 'allUsers',
|
|
156
|
+
label: '全部用户',
|
|
157
|
+
click: () => {
|
|
158
|
+
selectedDeptId.value = ''
|
|
159
|
+
pageRef.value?.call('deptTable', 'clearSelection')
|
|
160
|
+
refreshUsers(true)
|
|
161
|
+
},
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: 'refresh',
|
|
165
|
+
label: '刷新',
|
|
166
|
+
config: { icon: 'mdi:refresh' },
|
|
167
|
+
click: () => refreshUsers(),
|
|
168
|
+
},
|
|
169
|
+
]
|
|
170
|
+
|
|
171
|
+
const schema = ref([
|
|
172
|
+
{
|
|
173
|
+
type: 'j-layout',
|
|
174
|
+
config: {
|
|
175
|
+
left: 320,
|
|
176
|
+
},
|
|
177
|
+
children: [
|
|
178
|
+
{
|
|
179
|
+
id: 'deptTable',
|
|
180
|
+
type: 'j-table-panel',
|
|
181
|
+
slot: 'left',
|
|
182
|
+
config: {
|
|
183
|
+
columns: deptColumns,
|
|
184
|
+
rowKey: 'j_Id',
|
|
185
|
+
isPage: false,
|
|
186
|
+
highlightMode: 'row',
|
|
187
|
+
loadData: async (params: Record<string, any>) => api.getDepts(params),
|
|
188
|
+
onSelect: (selections: DeptRecord[]) => {
|
|
189
|
+
const nextId = selections?.[0]?.j_Id || ''
|
|
190
|
+
if (nextId === selectedDeptId.value) return
|
|
191
|
+
selectedDeptId.value = nextId
|
|
192
|
+
refreshUsers(true)
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
id: 'userTable',
|
|
198
|
+
type: 'j-table-panel',
|
|
199
|
+
config: {
|
|
200
|
+
columns: userColumns,
|
|
201
|
+
buttons: userButtons,
|
|
202
|
+
rowKey: 'j_Id',
|
|
203
|
+
isPage: true,
|
|
204
|
+
sort: 'j_CreateDate DESC',
|
|
205
|
+
loadData: async (params: Record<string, any>) => api.getUsers(params),
|
|
206
|
+
},
|
|
207
|
+
},
|
|
208
|
+
],
|
|
209
|
+
},
|
|
210
|
+
])
|
|
211
|
+
</script>
|