create-librex 1.0.2 → 1.0.4

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.2",
3
+ "version": "1.0.4",
4
4
  "description": "LibreX — 积木式后台管理框架项目脚手架",
5
5
  "type": "module",
6
6
  "bin": {
@@ -0,0 +1,31 @@
1
+ import { definePageConfig, useContext } from 'librex'
2
+
3
+ export default definePageConfig({
4
+ title: '仪表盘',
5
+ path: '/dashboard',
6
+ icon: 'LayoutDashboard',
7
+ navOrder: 1,
8
+
9
+ builtinBricks: ['LStatsBar', 'LSearchBar', 'LDataTable', 'LRowActionBar'],
10
+
11
+ setup({ setTableColumns, setTableData, setStats, setStatsLabels }) {
12
+ const store = useContext()
13
+
14
+ setStats({ total: 12800, primary: 5632, junior: 23, senior: 7145 })
15
+ setStatsLabels({ total: '访问量', primary: '订单量', junior: '待处理', senior: '已完成' })
16
+
17
+ setTableColumns([
18
+ { key: 'id', label: 'ID', sortable: true, width: 60 },
19
+ { key: 'name', label: '项目名称', sortable: true },
20
+ { key: 'progress', label: '进度', sortable: true },
21
+ { key: 'status', label: '状态', sortable: true },
22
+ ])
23
+
24
+ setTableData([
25
+ { id: 1, name: 'LibreX 框架', progress: '85%', status: '进行中' },
26
+ { id: 2, name: '用户中心', progress: '100%', status: '已完成' },
27
+ { id: 3, name: '数据分析', progress: '30%', status: '规划中' },
28
+ { id: 4, name: '消息推送', progress: '60%', status: '开发中' },
29
+ ])
30
+ },
31
+ })
@@ -11,8 +11,10 @@
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
- min-height: 100vh; padding: 40px;
17
+ width: 100%; height: 100%;
16
18
  background: var(--color-bg-viewport, #f0f2f5);
17
19
  color: var(--color-text-primary, #333);
18
20
  }
@@ -0,0 +1,47 @@
1
+ import { definePageConfig, useContext, useConfirm } from 'librex'
2
+
3
+ export default definePageConfig({
4
+ title: '用户管理',
5
+ path: '/users',
6
+ icon: 'Users',
7
+ navOrder: 2,
8
+
9
+ builtinBricks: ['LSearchBar', 'LDataTable', 'LRowActionBar', 'LBatchActionBar'],
10
+
11
+ setup({ setTableColumns, setTableData, setPageHooks }) {
12
+ const store = useContext()
13
+ const confirmStore = useConfirm()
14
+
15
+ setTableColumns([
16
+ { key: 'id', label: 'ID', sortable: true, width: 60 },
17
+ { key: 'username', label: '用户名', sortable: true },
18
+ { key: 'role', label: '角色', sortable: true },
19
+ { key: 'email', label: '邮箱' },
20
+ { key: 'createdAt', label: '创建时间', sortable: true },
21
+ ])
22
+
23
+ setTableData([
24
+ { id: 1, username: 'admin', role: '管理员', email: 'admin@librex.dev', createdAt: '2025-01-15' },
25
+ { id: 2, username: 'zhangsan', role: '编辑者', email: 'zhangsan@librex.dev', createdAt: '2025-03-20' },
26
+ { id: 3, username: 'lisi', role: '观察者', email: 'lisi@librex.dev', createdAt: '2025-04-10' },
27
+ { id: 4, username: 'wangwu', role: '编辑者', email: 'wangwu@librex.dev', createdAt: '2025-05-08' },
28
+ { id: 5, username: 'zhaoliu', role: '观察者', email: 'zhaoliu@librex.dev', createdAt: '2025-06-01' },
29
+ ])
30
+
31
+ setPageHooks({
32
+ onDelete: async (row) => {
33
+ const confirmed = await confirmStore.confirmDelete([row.id as number])
34
+ if (!confirmed) return
35
+ store.setTableData((store.tableData as any[]).filter((r: any) => r.id !== row.id))
36
+ store.pushNotification({ type: 'success', title: `已删除 ${row.username}` })
37
+ },
38
+ onBatchDelete: async (ids) => {
39
+ const confirmed = await confirmStore.confirmDelete(ids)
40
+ if (!confirmed) return
41
+ store.removeRows(ids)
42
+ store.clearSelection()
43
+ store.pushNotification({ type: 'success', title: `已删除 ${ids.length} 条` })
44
+ },
45
+ })
46
+ },
47
+ })
@@ -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 },
@@ -22,29 +22,38 @@ export const useUserStore = defineStore('user', () => {
22
22
  async function login(credentials: { username: string; password: string }): Promise<boolean> {
23
23
  loading.value = true
24
24
  try {
25
- // TODO: 替换为实际登录 API
25
+ // DEMO 账号 — 无后端时可用,替换为你的 API 后请删除
26
+ if (credentials.username === 'admin' && credentials.password === 'admin123') {
27
+ token.value = 'demo-token-librex'
28
+ currentUser.value = { id: 1, name: 'Admin', role: 'admin' }
29
+ localStorage.setItem(TOKEN_KEY, token.value)
30
+ localStorage.setItem(USER_KEY, JSON.stringify(currentUser.value))
31
+ loading.value = false
32
+ return true
33
+ }
34
+
35
+ // 实际 API 登录
26
36
  const res = await fetch('/api/admin/login', {
27
37
  method: 'POST',
28
38
  headers: { 'Content-Type': 'application/json' },
29
39
  body: JSON.stringify({ account: credentials.username, password: credentials.password }),
30
40
  })
31
41
  const data = await res.json()
32
- if (data.code !== 1 || !data.data) return false
42
+ if (data.code !== 1 || !data.data) { loading.value = false; return false }
33
43
 
34
44
  token.value = data.data.token || data.data.session_id
35
45
  localStorage.setItem(TOKEN_KEY, token.value || '')
36
46
 
37
- // 获取用户信息
38
47
  const user = await fetchUserInfo()
39
48
  if (user) {
40
49
  currentUser.value = user
41
50
  localStorage.setItem(USER_KEY, JSON.stringify(user))
42
51
  }
52
+ loading.value = false
43
53
  return true
44
54
  } catch {
45
- return false
46
- } finally {
47
55
  loading.value = false
56
+ return false
48
57
  }
49
58
  }
50
59