@wg-song/bare 0.1.0 → 0.1.2

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.
@@ -0,0 +1,87 @@
1
+ <script setup lang="ts">
2
+ import { ref } from 'vue'
3
+ import { PageShell, TableRead, confirm } from '@wg-song/bare'
4
+ import type {
5
+ FormField,
6
+ PageShellProps,
7
+ ActionItem,
8
+ TableColumn,
9
+ } from '@wg-song/bare'
10
+
11
+ const searchSchemas: FormField[] = [
12
+ { field: 'userName', label: '用户名', component: 'input' },
13
+ { field: 'phone', label: '手机号', component: 'input' },
14
+ ]
15
+
16
+ const columns: TableColumn[] = [
17
+ { field: 'userName', title: '用户名' },
18
+ { field: 'realName', title: '真实姓名' },
19
+ { field: 'phone', title: '手机号' },
20
+ {
21
+ field: 'status',
22
+ title: '状态',
23
+ component: 'tag',
24
+ tagColor: ({ value }) => (value === 1 ? 'success' : 'default'),
25
+ },
26
+ { field: 'createTime', title: '创建时间' },
27
+ ]
28
+
29
+ const allRows = Array.from({ length: 28 }).map((_, i) => ({
30
+ id: i + 1,
31
+ userName: `user_${i + 1}`,
32
+ realName: `用户 ${i + 1}`,
33
+ phone: `1380000${String(i + 1).padStart(4, '0')}`,
34
+ status: i % 4 === 0 ? 0 : 1,
35
+ createTime: '2024-01-01 10:00:00',
36
+ }))
37
+
38
+ const toolbarActions: ActionItem[] = [
39
+ { label: '新增', type: 'primary', onClick: () => alert('打开新增弹窗') },
40
+ ]
41
+
42
+ const loader: PageShellProps['loader'] = async ({ params, page, pageSize }) => {
43
+ await new Promise((resolve) => setTimeout(resolve, 300))
44
+ const filtered = allRows.filter((r) => {
45
+ if (params.userName && !r.userName.includes(String(params.userName))) return false
46
+ if (params.phone && !r.phone.includes(String(params.phone))) return false
47
+ return true
48
+ })
49
+ const start = (page - 1) * pageSize
50
+ return {
51
+ list: filtered.slice(start, start + pageSize),
52
+ total: filtered.length,
53
+ }
54
+ }
55
+
56
+ function rowActions(row: any): ActionItem[] {
57
+ return [
58
+ { label: '编辑', onClick: () => console.log('编辑', row) },
59
+ {
60
+ label: '删除',
61
+ danger: true,
62
+ onClick: async () => {
63
+ const ok = await confirm('确认删除该用户?')
64
+ if (!ok) return
65
+ // 业务侧调用删除 API
66
+ },
67
+ },
68
+ ]
69
+ }
70
+ </script>
71
+
72
+ <template>
73
+ <PageShell
74
+ :search-schemas="searchSchemas"
75
+ :loader="loader"
76
+ :toolbar-actions="toolbarActions"
77
+ >
78
+ <template #default="{ data, loading }">
79
+ <TableRead
80
+ :data="data"
81
+ :columns="columns"
82
+ :loading="loading"
83
+ :get-row-actions="rowActions"
84
+ />
85
+ </template>
86
+ </PageShell>
87
+ </template>