@a2simcode/ui 0.0.75 → 0.0.77
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/components/comp/index.d.ts +30 -0
- package/dist/components/comp/src/comp.vue.d.ts +30 -0
- package/dist/simcode-ui.es.js +1187 -1163
- package/dist/simcode-ui.umd.js +2 -2
- package/dist/stats.html +1 -1
- package/dist/ui.css +1 -1
- package/docs/components/meta/button.ts +99 -10
- package/docs/components/meta/buttons.ts +17 -2
- package/docs/components/meta/form.ts +10 -5
- package/docs/components/page.md +15 -0
- package/docs/examples/page/user-management.vue +313 -0
- package/docs/examples/table/editable.vue +0 -1
- package/package.json +1 -1
package/docs/components/page.md
CHANGED
|
@@ -41,6 +41,19 @@
|
|
|
41
41
|
</template>
|
|
42
42
|
</Demo>
|
|
43
43
|
|
|
44
|
+
## 用户管理页面示例
|
|
45
|
+
|
|
46
|
+
参考业务项目中的写法,展示了如何在 `j-page` 内嵌 `j-table-panel`,并完成“新增 / 编辑 / 重置密码 / 删除 / 状态开关”等常见交互。
|
|
47
|
+
|
|
48
|
+
<Demo :source-code="pageUserManagementCode">
|
|
49
|
+
<template #source>
|
|
50
|
+
<page-user-management />
|
|
51
|
+
</template>
|
|
52
|
+
<template #description>
|
|
53
|
+
示例使用 Mock 数据模拟分页接口,并通过 `openLayer` 打开表单弹窗;保存/删除后通过 `j-page.call('mainTable','refreshData')` 刷新表格。
|
|
54
|
+
</template>
|
|
55
|
+
</Demo>
|
|
56
|
+
|
|
44
57
|
## API
|
|
45
58
|
|
|
46
59
|
<ApiTable :data="pageApi" componentName="page" />
|
|
@@ -49,9 +62,11 @@
|
|
|
49
62
|
import PageBasic from '../examples/page/basic.vue'
|
|
50
63
|
import PageInit from '../examples/page/init.vue'
|
|
51
64
|
import PageLog from '../examples/page/log.vue'
|
|
65
|
+
import PageUserManagement from '../examples/page/user-management.vue'
|
|
52
66
|
import pageApi from './meta/page'
|
|
53
67
|
|
|
54
68
|
import pageBasicCode from '../examples/page/basic.vue?raw'
|
|
55
69
|
import pageInitCode from '../examples/page/init.vue?raw'
|
|
56
70
|
import pageLogCode from '../examples/page/log.vue?raw'
|
|
71
|
+
import pageUserManagementCode from '../examples/page/user-management.vue?raw'
|
|
57
72
|
</script>
|
|
@@ -0,0 +1,313 @@
|
|
|
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 { ButtonClickScope, TableColumnCompConfig } from '@a2simcode/ui'
|
|
9
|
+
|
|
10
|
+
import { ref, defineComponent, h } from 'vue'
|
|
11
|
+
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
12
|
+
|
|
13
|
+
interface UserRecord {
|
|
14
|
+
j_Id: number
|
|
15
|
+
j_Account: string
|
|
16
|
+
j_Name: string
|
|
17
|
+
j_EnabledMark: 0 | 1
|
|
18
|
+
j_CreateUserName: string
|
|
19
|
+
j_CreateDate: string
|
|
20
|
+
j_ModifyDate: string
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const randomFrom = <T,>(arr: T[]) => arr[Math.floor(Math.random() * arr.length)]
|
|
24
|
+
|
|
25
|
+
const createUsers = (count: number): UserRecord[] => {
|
|
26
|
+
const names = ['张三', '李四', '王五', '赵六', '孙七', '周八', '吴九', '郑十']
|
|
27
|
+
const creators = ['系统', '管理员', '运维', '审计']
|
|
28
|
+
const now = Date.now()
|
|
29
|
+
|
|
30
|
+
return Array.from({ length: count }).map((_, i) => {
|
|
31
|
+
const id = i + 1
|
|
32
|
+
const createTime = new Date(now - Math.floor(Math.random() * 20 * 24 * 60 * 60 * 1000))
|
|
33
|
+
const modifyTime = new Date(
|
|
34
|
+
createTime.getTime() + Math.floor(Math.random() * 5 * 24 * 60 * 60 * 1000)
|
|
35
|
+
)
|
|
36
|
+
return {
|
|
37
|
+
j_Id: id,
|
|
38
|
+
j_Account: `user_${String(id).padStart(3, '0')}`,
|
|
39
|
+
j_Name: randomFrom(names),
|
|
40
|
+
j_EnabledMark: Math.random() > 0.2 ? 1 : 0,
|
|
41
|
+
j_CreateUserName: randomFrom(creators),
|
|
42
|
+
j_CreateDate: createTime.toISOString(),
|
|
43
|
+
j_ModifyDate: modifyTime.toISOString(),
|
|
44
|
+
}
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const users = ref<UserRecord[]>(createUsers(57))
|
|
49
|
+
|
|
50
|
+
const api = {
|
|
51
|
+
getPage: async (params: Record<string, any>) => {
|
|
52
|
+
const keyword = String(params?.keyword?.value || '').trim()
|
|
53
|
+
const { pagination } = params || {}
|
|
54
|
+
const { rows = 10, page = 1 } = pagination || {}
|
|
55
|
+
|
|
56
|
+
let list = [...users.value]
|
|
57
|
+
if (keyword) {
|
|
58
|
+
list = list.filter((u) => u.j_Name.includes(keyword) || u.j_Account.includes(keyword))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const start = (page - 1) * rows
|
|
62
|
+
const end = start + rows
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
rows: list.slice(start, end),
|
|
66
|
+
records: list.length,
|
|
67
|
+
}
|
|
68
|
+
},
|
|
69
|
+
updateState: async (id: number, enabled: 0 | 1) => {
|
|
70
|
+
const target = users.value.find((u) => u.j_Id === id)
|
|
71
|
+
if (!target) return false
|
|
72
|
+
target.j_EnabledMark = enabled
|
|
73
|
+
target.j_ModifyDate = new Date().toISOString()
|
|
74
|
+
return true
|
|
75
|
+
},
|
|
76
|
+
upsert: async (data: Pick<UserRecord, 'j_Account' | 'j_Name'> & { j_Id?: number }) => {
|
|
77
|
+
const now = new Date().toISOString()
|
|
78
|
+
if (!data.j_Id) {
|
|
79
|
+
const nextId = Math.max(0, ...users.value.map((u) => u.j_Id)) + 1
|
|
80
|
+
users.value.unshift({
|
|
81
|
+
j_Id: nextId,
|
|
82
|
+
j_Account: data.j_Account,
|
|
83
|
+
j_Name: data.j_Name,
|
|
84
|
+
j_EnabledMark: 1,
|
|
85
|
+
j_CreateUserName: '管理员',
|
|
86
|
+
j_CreateDate: now,
|
|
87
|
+
j_ModifyDate: now,
|
|
88
|
+
})
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const target = users.value.find((u) => u.j_Id === data.j_Id)
|
|
93
|
+
if (!target) return false
|
|
94
|
+
target.j_Account = data.j_Account
|
|
95
|
+
target.j_Name = data.j_Name
|
|
96
|
+
target.j_ModifyDate = now
|
|
97
|
+
return true
|
|
98
|
+
},
|
|
99
|
+
resetPassword: async () => true,
|
|
100
|
+
remove: async (id: number) => {
|
|
101
|
+
const idx = users.value.findIndex((u) => u.j_Id === id)
|
|
102
|
+
if (idx < 0) return false
|
|
103
|
+
users.value.splice(idx, 1)
|
|
104
|
+
return true
|
|
105
|
+
},
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const UserFormLayer = defineComponent({
|
|
109
|
+
name: 'UserFormLayer',
|
|
110
|
+
setup(_, { expose }) {
|
|
111
|
+
const isEdit = ref(false)
|
|
112
|
+
const currentId = ref<number | undefined>(undefined)
|
|
113
|
+
const formData = ref({
|
|
114
|
+
j_Account: '',
|
|
115
|
+
j_Name: '',
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
const open = async (param: any) => {
|
|
119
|
+
isEdit.value = !!param?.isEdit
|
|
120
|
+
const record = param?.record as UserRecord | undefined
|
|
121
|
+
currentId.value = record?.j_Id
|
|
122
|
+
formData.value = {
|
|
123
|
+
j_Account: record?.j_Account || '',
|
|
124
|
+
j_Name: record?.j_Name || '',
|
|
125
|
+
}
|
|
126
|
+
return true
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
const ok = async () => {
|
|
130
|
+
const account = formData.value.j_Account.trim()
|
|
131
|
+
const name = formData.value.j_Name.trim()
|
|
132
|
+
if (!account) {
|
|
133
|
+
ElMessage.warning('请输入账号')
|
|
134
|
+
return false
|
|
135
|
+
}
|
|
136
|
+
if (!name) {
|
|
137
|
+
ElMessage.warning('请输入姓名')
|
|
138
|
+
return false
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
const res = await api.upsert({
|
|
142
|
+
j_Id: currentId.value,
|
|
143
|
+
j_Account: account,
|
|
144
|
+
j_Name: name,
|
|
145
|
+
})
|
|
146
|
+
if (!res) {
|
|
147
|
+
ElMessage.warning('保存失败')
|
|
148
|
+
}
|
|
149
|
+
return res
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
expose({ open, ok })
|
|
153
|
+
|
|
154
|
+
return () =>
|
|
155
|
+
h('div', { style: 'padding: 16px' }, [
|
|
156
|
+
h('div', { style: 'margin-bottom: 12px' }, [
|
|
157
|
+
h('div', { style: 'margin-bottom: 6px; color: var(--j-color-text-2)' }, '账号'),
|
|
158
|
+
h('input', {
|
|
159
|
+
value: formData.value.j_Account,
|
|
160
|
+
onInput: (e: any) => (formData.value.j_Account = e?.target?.value || ''),
|
|
161
|
+
placeholder: '请输入账号',
|
|
162
|
+
style:
|
|
163
|
+
'width: 100%; padding: 6px 10px; border: 1px solid var(--j-color-border); border-radius: 4px; outline: none;',
|
|
164
|
+
}),
|
|
165
|
+
]),
|
|
166
|
+
h('div', { style: 'margin-bottom: 12px' }, [
|
|
167
|
+
h('div', { style: 'margin-bottom: 6px; color: var(--j-color-text-2)' }, '姓名'),
|
|
168
|
+
h('input', {
|
|
169
|
+
value: formData.value.j_Name,
|
|
170
|
+
onInput: (e: any) => (formData.value.j_Name = e?.target?.value || ''),
|
|
171
|
+
placeholder: '请输入姓名',
|
|
172
|
+
style:
|
|
173
|
+
'width: 100%; padding: 6px 10px; border: 1px solid var(--j-color-border); border-radius: 4px; outline: none;',
|
|
174
|
+
}),
|
|
175
|
+
]),
|
|
176
|
+
h(
|
|
177
|
+
'div',
|
|
178
|
+
{ style: 'color: var(--j-color-text-3); font-size: 12px' },
|
|
179
|
+
isEdit.value ? '编辑模式:修改后点击确定保存' : '新增模式:填写后点击确定创建'
|
|
180
|
+
),
|
|
181
|
+
])
|
|
182
|
+
},
|
|
183
|
+
})
|
|
184
|
+
|
|
185
|
+
const pageRef = ref()
|
|
186
|
+
|
|
187
|
+
const refreshTable = () => {
|
|
188
|
+
pageRef.value?.call('mainTable', 'refreshData')
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const columnsConfig: Record<string, TableColumnCompConfig> = {
|
|
192
|
+
j_Name: { width: 120, filter: { isSearchKeyword: true } },
|
|
193
|
+
j_Account: { width: 140, filter: { isSearchKeyword: true } },
|
|
194
|
+
j_EnabledMark: {
|
|
195
|
+
type: 'j-switch',
|
|
196
|
+
activeValue: 1,
|
|
197
|
+
inactiveValue: 0,
|
|
198
|
+
width: 72,
|
|
199
|
+
align: 'center',
|
|
200
|
+
change: async ({ row }: { row: UserRecord }) => {
|
|
201
|
+
const res = await api.updateState(row.j_Id, row.j_EnabledMark)
|
|
202
|
+
if (res) {
|
|
203
|
+
ElMessage.success('更新成功')
|
|
204
|
+
refreshTable()
|
|
205
|
+
} else {
|
|
206
|
+
ElMessage.warning('更新失败')
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
j_CreateUserName: { filter: { isSearchKeyword: true } },
|
|
211
|
+
j_CreateDate: { type: 'dateTime', width: 168 },
|
|
212
|
+
j_ModifyDate: { type: 'dateTime', width: 168 },
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
const columns = [
|
|
216
|
+
{ id: 'j_Name', label: '姓名' },
|
|
217
|
+
{ id: 'j_Account', label: '账号' },
|
|
218
|
+
{ id: 'j_EnabledMark', label: '有效' },
|
|
219
|
+
{ id: 'j_CreateUserName', label: '创建用户' },
|
|
220
|
+
{ id: 'j_CreateDate', label: '创建时间' },
|
|
221
|
+
{ id: 'j_ModifyDate', label: '最后更新时间' },
|
|
222
|
+
].map((item) => {
|
|
223
|
+
const cfg = columnsConfig[item.id] || {}
|
|
224
|
+
return {
|
|
225
|
+
id: item.id,
|
|
226
|
+
type: cfg.type || '',
|
|
227
|
+
config: { ...cfg, label: item.label },
|
|
228
|
+
}
|
|
229
|
+
})
|
|
230
|
+
|
|
231
|
+
const buttons = [
|
|
232
|
+
{
|
|
233
|
+
id: 'add',
|
|
234
|
+
label: '新增',
|
|
235
|
+
config: { icon: 'mdi:add', type: 'primary' },
|
|
236
|
+
click: ({ openLayer }: ButtonClickScope) => {
|
|
237
|
+
openLayer({
|
|
238
|
+
title: '新增用户',
|
|
239
|
+
name: UserFormLayer,
|
|
240
|
+
width: 520,
|
|
241
|
+
height: 240,
|
|
242
|
+
param: { isEdit: false },
|
|
243
|
+
afterOk: refreshTable,
|
|
244
|
+
})
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
]
|
|
248
|
+
|
|
249
|
+
const actions = [
|
|
250
|
+
{
|
|
251
|
+
id: 'edit',
|
|
252
|
+
label: '编辑',
|
|
253
|
+
click: ({ openLayer, data }: ButtonClickScope) => {
|
|
254
|
+
openLayer({
|
|
255
|
+
title: '编辑用户',
|
|
256
|
+
name: UserFormLayer,
|
|
257
|
+
width: 520,
|
|
258
|
+
height: 240,
|
|
259
|
+
param: { isEdit: true, record: data },
|
|
260
|
+
afterOk: refreshTable,
|
|
261
|
+
})
|
|
262
|
+
},
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
id: 'resetPassword',
|
|
266
|
+
label: '重置密码',
|
|
267
|
+
click: async ({ data }: ButtonClickScope) => {
|
|
268
|
+
await ElMessageBox.confirm(`您确定重置【${data?.j_Name}】密码吗?`, '提示', {
|
|
269
|
+
type: 'warning',
|
|
270
|
+
confirmButtonText: '确定',
|
|
271
|
+
cancelButtonText: '取消',
|
|
272
|
+
})
|
|
273
|
+
const res = await api.resetPassword()
|
|
274
|
+
if (res) {
|
|
275
|
+
ElMessage.success('重置成功')
|
|
276
|
+
}
|
|
277
|
+
},
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
id: 'delete',
|
|
281
|
+
label: '删除',
|
|
282
|
+
config: { danger: true },
|
|
283
|
+
click: async ({ data }: ButtonClickScope) => {
|
|
284
|
+
await ElMessageBox.confirm(`您确定删除【${data?.j_Name}】吗?`, '提示', {
|
|
285
|
+
type: 'warning',
|
|
286
|
+
confirmButtonText: '确定',
|
|
287
|
+
cancelButtonText: '取消',
|
|
288
|
+
})
|
|
289
|
+
const res = await api.remove(data.j_Id)
|
|
290
|
+
if (res) {
|
|
291
|
+
ElMessage.success('删除成功')
|
|
292
|
+
refreshTable()
|
|
293
|
+
}
|
|
294
|
+
},
|
|
295
|
+
},
|
|
296
|
+
]
|
|
297
|
+
|
|
298
|
+
const schema = ref([
|
|
299
|
+
{
|
|
300
|
+
id: 'mainTable',
|
|
301
|
+
type: 'j-table-panel',
|
|
302
|
+
config: {
|
|
303
|
+
columns,
|
|
304
|
+
buttons,
|
|
305
|
+
actions,
|
|
306
|
+
rowKey: 'j_Id',
|
|
307
|
+
isPage: true,
|
|
308
|
+
sort: 'j_CreateDate DESC',
|
|
309
|
+
loadData: async (params: Record<string, any>) => api.getPage(params),
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
])
|
|
313
|
+
</script>
|