create-librex 1.0.3 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "create-librex",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "LibreX — 积木式后台管理框架项目脚手架",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,32 @@
1
+ import { definePageConfig, useContext } from 'librex'
2
+
3
+ export default definePageConfig({
4
+ title: '仪表盘',
5
+ path: '/dashboard',
6
+ icon: 'layout-dashboard',
7
+ navOrder: 1,
8
+ navGroup: '📊 数据概览',
9
+
10
+ builtinBricks: ['LStatsBar', 'LSearchBar', 'LDataTable', 'LRowActionBar'],
11
+
12
+ setup({ setTableColumns, setTableData, setStats, setStatsLabels }) {
13
+ const store = useContext()
14
+
15
+ setStats({ total: 12800, primary: 5632, junior: 23, senior: 7145 })
16
+ setStatsLabels({ total: '访问量', primary: '订单量', junior: '待处理', senior: '已完成' })
17
+
18
+ setTableColumns([
19
+ { key: 'id', label: 'ID', sortable: true, width: 60 },
20
+ { key: 'name', label: '项目名称', sortable: true },
21
+ { key: 'progress', label: '进度', sortable: true },
22
+ { key: 'status', label: '状态', sortable: true },
23
+ ])
24
+
25
+ setTableData([
26
+ { id: 1, name: 'LibreX 框架', progress: '85%', status: '进行中' },
27
+ { id: 2, name: '用户中心', progress: '100%', status: '已完成' },
28
+ { id: 3, name: '数据分析', progress: '30%', status: '规划中' },
29
+ { id: 4, name: '消息推送', progress: '60%', status: '开发中' },
30
+ ])
31
+ },
32
+ })
@@ -11,6 +11,8 @@
11
11
 
12
12
  <style scoped>
13
13
  .not-found-page {
14
+ grid-area: main;
15
+ grid-column: 1 / -1;
14
16
  display: flex; align-items: center; justify-content: center;
15
17
  width: 100%; height: 100%;
16
18
  background: var(--color-bg-viewport, #f0f2f5);
@@ -0,0 +1,40 @@
1
+ import { definePageConfig } from 'librex'
2
+
3
+ /**
4
+ * 隐藏详情页 — 路径含 /:id,自动标记 hasParams=true,不出现在导航中。
5
+ *
6
+ * 从列表页跳转: router.push('/users/' + row.id)
7
+ */
8
+
9
+ export default definePageConfig({
10
+ title: '用户详情',
11
+ path: '/users/detail/:id',
12
+
13
+ // 路径有 /: → hasParams 自动 true → IconRail 不显示
14
+ // icon + navGroup 可省略,因为不在导航中出现
15
+
16
+ builtinBricks: ['LForm'],
17
+
18
+ defaultState: 'reviewing',
19
+
20
+ setup({ setFormFields, setTableData }) {
21
+ setFormFields([
22
+ { key: 'id', label: 'ID', fieldType: 'input' },
23
+ { key: 'username', label: '用户名', fieldType: 'input', required: true },
24
+ { key: 'role', label: '角色', fieldType: 'select', props: {
25
+ options: [
26
+ { label: '管理员', value: 'admin' },
27
+ { label: '编辑者', value: 'editor' },
28
+ { label: '观察者', value: 'viewer' },
29
+ ],
30
+ }},
31
+ { key: 'email', label: '邮箱', fieldType: 'input' },
32
+ { key: 'phone', label: '电话', fieldType: 'input' },
33
+ ])
34
+
35
+ // 模拟从 API 加载数据
36
+ setTableData([
37
+ { id: 1, username: 'admin', role: 'admin', email: 'admin@librex.dev', phone: '13800000001' },
38
+ ])
39
+ },
40
+ })
@@ -0,0 +1,51 @@
1
+ import { definePageConfig, useContext, useConfirm } from 'librex'
2
+
3
+ export default definePageConfig({
4
+ title: '用户管理',
5
+ path: '/users',
6
+ icon: 'users',
7
+ navOrder: 2,
8
+ navGroup: '📊 数据概览',
9
+
10
+ builtinBricks: ['LSearchBar', 'LDataTable', 'LRowActionBar', 'LBatchActionBar'],
11
+
12
+ // 行操作 — "查看"按钮跳隐藏详情页 /users/detail/:id
13
+ rowActions: [{ label: '查看', subView: 'detail' }],
14
+
15
+ setup({ setTableColumns, setTableData, setPageHooks }) {
16
+ const store = useContext()
17
+ const confirmStore = useConfirm()
18
+
19
+ setTableColumns([
20
+ { key: 'id', label: 'ID', sortable: true, width: 60 },
21
+ { key: 'username', label: '用户名', sortable: true },
22
+ { key: 'role', label: '角色', sortable: true },
23
+ { key: 'email', label: '邮箱' },
24
+ { key: 'createdAt', label: '创建时间', sortable: true },
25
+ ])
26
+
27
+ setTableData([
28
+ { id: 1, username: 'admin', role: '管理员', email: 'admin@librex.dev', createdAt: '2025-01-15' },
29
+ { id: 2, username: 'zhangsan', role: '编辑者', email: 'zhangsan@librex.dev', createdAt: '2025-03-20' },
30
+ { id: 3, username: 'lisi', role: '观察者', email: 'lisi@librex.dev', createdAt: '2025-04-10' },
31
+ { id: 4, username: 'wangwu', role: '编辑者', email: 'wangwu@librex.dev', createdAt: '2025-05-08' },
32
+ { id: 5, username: 'zhaoliu', role: '观察者', email: 'zhaoliu@librex.dev', createdAt: '2025-06-01' },
33
+ ])
34
+
35
+ setPageHooks({
36
+ onDelete: async (row) => {
37
+ const confirmed = await confirmStore.confirmDelete([row.id as number])
38
+ if (!confirmed) return
39
+ store.setTableData((store.tableData as any[]).filter((r: any) => r.id !== row.id))
40
+ store.pushNotification({ type: 'success', title: `已删除 ${row.username}` })
41
+ },
42
+ onBatchDelete: async (ids) => {
43
+ const confirmed = await confirmStore.confirmDelete(ids)
44
+ if (!confirmed) return
45
+ store.removeRows(ids)
46
+ store.clearSelection()
47
+ store.pushNotification({ type: 'success', title: `已删除 ${ids.length} 条` })
48
+ },
49
+ })
50
+ },
51
+ })
@@ -13,6 +13,7 @@ const allConfigs: PageConfig[] = brickRoutes
13
13
  .filter(Boolean) as PageConfig[]
14
14
 
15
15
  const routes: RouteRecordRaw[] = [
16
+ { path: '/', redirect: '/dashboard' },
16
17
  { path: '/login', name: 'login', component: LoginPage },
17
18
  ...brickRoutes,
18
19
  { path: '/:pathMatch(.*)*', name: 'not-found', component: NotFound },
@@ -96,10 +96,12 @@ export function vitePluginLibrex(): Plugin {
96
96
  for (const route of r) {
97
97
  const lastSlash = route.path.lastIndexOf('/')
98
98
  if (lastSlash <= 0) continue
99
- const parentPath = route.path.slice(0, lastSlash)
99
+ let parentPath = route.path.slice(0, lastSlash)
100
+ // 剥离参数段 (:id) 再匹配 — 如 /unit/detail/:id → 匹配 /unit
100
101
  const parent = r.find(rr => rr.path === parentPath)
102
+ ?? r.find(rr => rr.path === parentPath.replace(/\/[^/]*:[^/]+$/, ''))
101
103
  if (!parent) continue
102
- const groupName = parent.navGroup || `${parent.icon} ${parent.title}`
104
+ const groupName = parent.navGroup || `${parent.title}`
103
105
  if (!route.navGroup) route.navGroup = groupName
104
106
  if (!parent.navGroup) parent.navGroup = groupName
105
107
  }