xto-fronted 0.4.6 → 0.4.8

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.
Files changed (160) hide show
  1. package/.env.development +7 -7
  2. package/.env.production +7 -7
  3. package/dist/assets/403-AFBQifUI.js +1 -0
  4. package/dist/assets/403-BHEXXbt2.css +1 -0
  5. package/dist/assets/404-Ct_A1n7S.css +1 -0
  6. package/dist/assets/404-WFvpcD2_.js +1 -0
  7. package/dist/assets/_plugin-vue_export-helper-DlAUqK2U.js +1 -0
  8. package/dist/assets/index-1juADvYN.js +2 -0
  9. package/dist/assets/index-B-sX4Ru0.js +1 -0
  10. package/dist/assets/index-BMcziU5a.css +1 -0
  11. package/dist/assets/index-BRR97dc6.js +1 -0
  12. package/dist/assets/index-BZA0ksjx.css +1 -0
  13. package/dist/assets/index-BpV_8nl0.js +1 -0
  14. package/dist/assets/index-BvzhR4zp.js +1 -0
  15. package/dist/assets/index-CUh_s55Z.css +1 -0
  16. package/dist/assets/index-CVjdnIgR.css +1 -0
  17. package/dist/assets/index-CYq57-zj.js +1 -0
  18. package/dist/assets/index-CkL3sVAQ.js +2 -0
  19. package/dist/assets/index-CtrKVYJb.css +1 -0
  20. package/dist/assets/index-Cz2P_bsS.js +1 -0
  21. package/dist/assets/index-D9wlAuR_.js +1 -0
  22. package/dist/assets/index-DawJb02s.css +1 -0
  23. package/dist/assets/index-DfFR6NLf.js +1 -0
  24. package/dist/assets/index-DwVgMO8e.js +1 -0
  25. package/dist/assets/index-GDP-IkXE.css +1 -0
  26. package/dist/assets/index-Iaz1ZzPC.js +2 -0
  27. package/dist/assets/index-PfV8pzQz.css +1 -0
  28. package/dist/assets/index-Swfu6yvD.css +1 -0
  29. package/dist/assets/index-Te8_PRgJ.js +1 -0
  30. package/dist/assets/index-WyZ91RLx.css +1 -0
  31. package/dist/assets/index-tFYRoFdE.js +1 -0
  32. package/dist/assets/vendor-42ANG6Sg.js +6 -0
  33. package/dist/assets/vite-Dw-pgLOX.js +1 -0
  34. package/dist/assets/vue-vendor-Br-l7wbK.js +29 -0
  35. package/dist/assets/xto-base-C-IBqjVs.js +1 -0
  36. package/dist/assets/xto-base-C6eqMPdO.css +1 -0
  37. package/dist/assets/xto-business--V1F5Gwb.css +1 -0
  38. package/dist/assets/xto-core-DZK7Cyg0.js +1 -0
  39. package/dist/assets/xto-data-BFpiDgJi.js +1 -0
  40. package/dist/assets/xto-data-CnAQAQH2.css +1 -0
  41. package/dist/assets/xto-feedback-B7ipsTfz.js +1 -0
  42. package/dist/assets/xto-feedback-DBwJzoTj.css +1 -0
  43. package/dist/assets/xto-form-CrsyAjyr.css +1 -0
  44. package/dist/assets/xto-form-NRjKKNcY.js +1 -0
  45. package/dist/assets/xto-layout-BqU8RuWL.css +1 -0
  46. package/dist/assets/xto-navigation-BiSaXPfr.js +1 -0
  47. package/dist/assets/xto-navigation-C1cnSL2E.css +1 -0
  48. package/dist/assets/xto-navigation-CBPg4dCc.css +1 -0
  49. package/dist/assets/xto-navigation-CKabFu9d.js +1 -0
  50. package/dist/index-54irhCHL.js +1830 -0
  51. package/dist/{index-15Bu0M8D.js → index-BzRf1eoJ.js} +1 -1
  52. package/dist/{index-BO2Zf9u6.js → index-DH4aoCZb.js} +1 -1
  53. package/dist/{index-BBqvHkzE.js → index-Kqa7iZ9E.js} +1 -1
  54. package/dist/{index-BQqo0ZIb.js → index-pxkZlvBw.js} +1 -1
  55. package/dist/index.es.js +1 -1
  56. package/dist/index.html +28 -0
  57. package/dist/index.umd.js +1 -1
  58. package/dist/style.css +1 -1
  59. package/package.json +85 -86
  60. package/src/api/auth.ts +25 -25
  61. package/src/api/system.ts +66 -66
  62. package/src/assets/styles/_dark.scss +406 -406
  63. package/src/components/Layout/Header.vue +973 -973
  64. package/src/components/Layout/Sidebar.vue +273 -212
  65. package/src/components/Layout/index.vue +443 -63
  66. package/src/composables/useApp.ts +61 -61
  67. package/src/composables/useAuth.ts +16 -16
  68. package/src/directives/permission.ts +27 -27
  69. package/src/env.d.ts +18 -18
  70. package/src/index.ts +47 -47
  71. package/src/router/dynamicRoutes.ts +162 -162
  72. package/src/router/guards.ts +128 -128
  73. package/src/router/index.ts +79 -79
  74. package/src/stores/auth.ts +65 -65
  75. package/src/stores/menu.ts +48 -48
  76. package/src/stores/user.ts +50 -50
  77. package/src/types/api.d.ts +80 -80
  78. package/src/utils/auth.ts +99 -99
  79. package/src/utils/config.ts +80 -80
  80. package/src/utils/permission.ts +32 -32
  81. package/src/utils/request.ts +124 -124
  82. package/src/views/login/index.vue +194 -188
  83. package/vite.config.ts +135 -135
  84. package/dist/index-B3PLzNB0.js +0 -345
  85. package/dist/index-B6DTsC6l.js +0 -1715
  86. package/dist/index-B7etKk33.js +0 -372
  87. package/dist/index-B7mpL6Zf.js +0 -475
  88. package/dist/index-BC2PGkkJ.js +0 -1644
  89. package/dist/index-BGgbfcmf.js +0 -475
  90. package/dist/index-BGmUwemj.js +0 -372
  91. package/dist/index-BQFfQj5Q.js +0 -142
  92. package/dist/index-BkRneTya.js +0 -142
  93. package/dist/index-BlRrngsc.js +0 -475
  94. package/dist/index-BmVvM7sm.js +0 -345
  95. package/dist/index-Bn4ThpX9.js +0 -142
  96. package/dist/index-BwfjwDKr.js +0 -1477
  97. package/dist/index-BxIL2hrt.js +0 -475
  98. package/dist/index-C-3fhbN2.js +0 -1644
  99. package/dist/index-C0VN9nFF.js +0 -142
  100. package/dist/index-C0xyGOsz.js +0 -475
  101. package/dist/index-C3c8NAZq.js +0 -1477
  102. package/dist/index-C42VtP71.js +0 -142
  103. package/dist/index-C6Nm0r9k.js +0 -475
  104. package/dist/index-C6w0-8xN.js +0 -1648
  105. package/dist/index-CD364XjV.js +0 -142
  106. package/dist/index-CHww99-i.js +0 -345
  107. package/dist/index-CIgWYERJ.js +0 -1644
  108. package/dist/index-CTs6DTuQ.js +0 -345
  109. package/dist/index-CWRs4WMN.js +0 -372
  110. package/dist/index-Cb-SxHJp.js +0 -345
  111. package/dist/index-CeCysOnl.js +0 -345
  112. package/dist/index-Cg1UpC8D.js +0 -1644
  113. package/dist/index-Cgkqpyx2.js +0 -345
  114. package/dist/index-CiuDEfo-.js +0 -142
  115. package/dist/index-CmQfZC8r.js +0 -372
  116. package/dist/index-CmkjhpX_.js +0 -475
  117. package/dist/index-CpxpXTQX.js +0 -1462
  118. package/dist/index-CqXFk_ET.js +0 -345
  119. package/dist/index-Cqix1YLE.js +0 -1697
  120. package/dist/index-CtvB5J9E.js +0 -372
  121. package/dist/index-Cu3Z2-PY.js +0 -345
  122. package/dist/index-CvDxK7Ab.js +0 -372
  123. package/dist/index-D-FER0vJ.js +0 -372
  124. package/dist/index-D2fQ8TK8.js +0 -475
  125. package/dist/index-D3xVcFvg.js +0 -372
  126. package/dist/index-D4crnrO6.js +0 -142
  127. package/dist/index-D7EzwTM5.js +0 -372
  128. package/dist/index-D7TZamyY.js +0 -1664
  129. package/dist/index-D88fiqXR.js +0 -475
  130. package/dist/index-DEbpF-M4.js +0 -1457
  131. package/dist/index-DFXuyPge.js +0 -1627
  132. package/dist/index-DLgimJYb.js +0 -1667
  133. package/dist/index-DPEVEyik.js +0 -475
  134. package/dist/index-DWy_UGhI.js +0 -345
  135. package/dist/index-DYVtddfw.js +0 -142
  136. package/dist/index-DYnXaqYf.js +0 -142
  137. package/dist/index-DcvRPHuy.js +0 -372
  138. package/dist/index-DdC1uV2v.js +0 -1700
  139. package/dist/index-Dga14ZN7.js +0 -1774
  140. package/dist/index-Dk2V44uP.js +0 -372
  141. package/dist/index-DnJ481u1.js +0 -475
  142. package/dist/index-Do1CBqg8.js +0 -345
  143. package/dist/index-DqQRSPeF.js +0 -345
  144. package/dist/index-Jb4VMHIS.js +0 -142
  145. package/dist/index-MC3wWjNt.js +0 -475
  146. package/dist/index-MG0JePmx.js +0 -142
  147. package/dist/index-PRFGBLWt.js +0 -475
  148. package/dist/index-QgkT42dc.js +0 -372
  149. package/dist/index-TrLCW5xL.js +0 -372
  150. package/dist/index-YDlNLFVk.js +0 -142
  151. package/dist/index-ZAJgA3XD.js +0 -475
  152. package/dist/index-a_ilWAvi.js +0 -345
  153. package/dist/index-bi1TMGid.js +0 -372
  154. package/dist/index-fyarVCog.js +0 -475
  155. package/dist/index-mnTZtPFa.js +0 -345
  156. package/dist/index-orZCyV6I.js +0 -345
  157. package/dist/index-p3TbK44c.js +0 -142
  158. package/dist/index-sRwZYbZ4.js +0 -372
  159. package/dist/index-wATqKEcF.js +0 -142
  160. package/dist/setup.d.ts +0 -17
@@ -1,129 +1,129 @@
1
- /**
2
- * 路由守卫设置
3
- */
4
-
5
- import type { Router } from 'vue-router'
6
- import { getToken } from '@/utils/auth'
7
- import { useUserStore } from '@/stores/user'
8
- import { useMenuStore } from '@/stores/menu'
9
- import { useAppStore } from '@/stores/app'
10
- import { getUserInfo } from '@/api/auth'
11
- import { getMenuTree } from '@/api/system'
12
-
13
- // 白名单路由
14
- const defaultWhiteList = ['/login', '/404', '/403']
15
-
16
- interface RouterGuardOptions {
17
- // 白名单路由
18
- whiteList?: string[]
19
- // 登录页路径
20
- loginPath?: string
21
- // 首页路径
22
- homePath?: string
23
- // 应用ID
24
- appId?: string
25
- // 获取用户信息的回调(可选,默认调用 API)
26
- fetchUserInfo?: () => Promise<any>
27
- // 获取菜单的回调(可选,默认调用 API)
28
- fetchMenu?: () => Promise<any>
29
- // 登录成功后的回调
30
- onLoginSuccess?: () => void
31
- }
32
-
33
- /**
34
- * 设置路由守卫
35
- * @param router 路由实例
36
- * @param options 配置选项
37
- */
38
- export function setupRouterGuards(router: Router, options: RouterGuardOptions = {}) {
39
- const whiteList = options.whiteList || defaultWhiteList
40
- const loginPath = options.loginPath || '/login'
41
- const homePath = options.homePath || '/'
42
-
43
- router.beforeEach(async (to, _from, next) => {
44
- const appStore = useAppStore()
45
- const userStore = useUserStore()
46
- const menuStore = useMenuStore()
47
-
48
- // 初始化主题
49
- appStore.initTheme()
50
-
51
- // 检查是否有 token
52
- const token = getToken()
53
-
54
- if (token) {
55
- // 已登录
56
- if (to.path === loginPath) {
57
- // 已登录访问登录页,跳转到首页
58
- next({ path: homePath })
59
- } else {
60
- // 检查是否已获取用户信息
61
- if (userStore.isLoggedIn) {
62
- // 已有用户信息,直接放行
63
- // 添加缓存页面
64
- if (to.name && to.meta.keepAlive) {
65
- appStore.addCachedView(to.name as string)
66
- }
67
- next()
68
- } else {
69
- // 尝试获取用户信息
70
- try {
71
- // 获取用户信息
72
- if (options.fetchUserInfo) {
73
- const userInfo = await options.fetchUserInfo()
74
- userStore.setUserInfo(userInfo)
75
- } else {
76
- const userInfo = await getUserInfo()
77
- userStore.setUserInfo(userInfo)
78
- }
79
-
80
- // 获取菜单
81
- if (options.fetchMenu) {
82
- const menuList = await options.fetchMenu()
83
- menuStore.setMenuList(menuList)
84
- } else {
85
- const menuList = await getMenuTree(options.appId)
86
- menuStore.setMenuList(menuList)
87
- }
88
-
89
- // 登录成功回调
90
- if (options.onLoginSuccess) {
91
- options.onLoginSuccess()
92
- }
93
-
94
- // 添加缓存页面
95
- if (to.name && to.meta.keepAlive) {
96
- appStore.addCachedView(to.name as string)
97
- }
98
-
99
- // 重新导航到目标路由,确保动态路由已添加
100
- next({ ...to, replace: true })
101
- } catch (error) {
102
- // 获取用户信息失败,清除 token 并跳转到登录页
103
- console.error('获取用户信息失败:', error)
104
- userStore.clearUserInfo()
105
- menuStore.clearMenu()
106
- // 清除 token
107
- localStorage.removeItem('token')
108
- localStorage.removeItem('token_type')
109
- localStorage.removeItem('refresh_token')
110
- next({ path: loginPath, query: { redirect: to.fullPath } })
111
- }
112
- }
113
- }
114
- } else {
115
- // 未登录
116
- if (whiteList.includes(to.path)) {
117
- // 在白名单中,直接放行
118
- next()
119
- } else {
120
- // 不在白名单中,跳转到登录页
121
- next({ path: loginPath, query: { redirect: to.fullPath } })
122
- }
123
- }
124
- })
125
-
126
- router.afterEach(() => {
127
- // 可以在这里添加进度条结束等
128
- })
1
+ /**
2
+ * 路由守卫设置
3
+ */
4
+
5
+ import type { Router } from 'vue-router'
6
+ import { getToken } from '@/utils/auth'
7
+ import { useUserStore } from '@/stores/user'
8
+ import { useMenuStore } from '@/stores/menu'
9
+ import { useAppStore } from '@/stores/app'
10
+ import { getUserInfo } from '@/api/auth'
11
+ import { getMenuTree } from '@/api/system'
12
+
13
+ // 白名单路由
14
+ const defaultWhiteList = ['/login', '/404', '/403']
15
+
16
+ interface RouterGuardOptions {
17
+ // 白名单路由
18
+ whiteList?: string[]
19
+ // 登录页路径
20
+ loginPath?: string
21
+ // 首页路径
22
+ homePath?: string
23
+ // 应用ID
24
+ appId?: string
25
+ // 获取用户信息的回调(可选,默认调用 API)
26
+ fetchUserInfo?: () => Promise<any>
27
+ // 获取菜单的回调(可选,默认调用 API)
28
+ fetchMenu?: () => Promise<any>
29
+ // 登录成功后的回调
30
+ onLoginSuccess?: () => void
31
+ }
32
+
33
+ /**
34
+ * 设置路由守卫
35
+ * @param router 路由实例
36
+ * @param options 配置选项
37
+ */
38
+ export function setupRouterGuards(router: Router, options: RouterGuardOptions = {}) {
39
+ const whiteList = options.whiteList || defaultWhiteList
40
+ const loginPath = options.loginPath || '/login'
41
+ const homePath = options.homePath || '/'
42
+
43
+ router.beforeEach(async (to, _from, next) => {
44
+ const appStore = useAppStore()
45
+ const userStore = useUserStore()
46
+ const menuStore = useMenuStore()
47
+
48
+ // 初始化主题
49
+ appStore.initTheme()
50
+
51
+ // 检查是否有 token
52
+ const token = getToken()
53
+
54
+ if (token) {
55
+ // 已登录
56
+ if (to.path === loginPath) {
57
+ // 已登录访问登录页,跳转到首页
58
+ next({ path: homePath })
59
+ } else {
60
+ // 检查是否已获取用户信息
61
+ if (userStore.isLoggedIn) {
62
+ // 已有用户信息,直接放行
63
+ // 添加缓存页面
64
+ if (to.name && to.meta.keepAlive) {
65
+ appStore.addCachedView(to.name as string)
66
+ }
67
+ next()
68
+ } else {
69
+ // 尝试获取用户信息
70
+ try {
71
+ // 获取用户信息
72
+ if (options.fetchUserInfo) {
73
+ const userInfo = await options.fetchUserInfo()
74
+ userStore.setUserInfo(userInfo)
75
+ } else {
76
+ const userInfo = await getUserInfo()
77
+ userStore.setUserInfo(userInfo)
78
+ }
79
+
80
+ // 获取菜单
81
+ if (options.fetchMenu) {
82
+ const menuList = await options.fetchMenu()
83
+ menuStore.setMenuList(menuList)
84
+ } else {
85
+ const menuList = await getMenuTree(options.appId)
86
+ menuStore.setMenuList(menuList)
87
+ }
88
+
89
+ // 登录成功回调
90
+ if (options.onLoginSuccess) {
91
+ options.onLoginSuccess()
92
+ }
93
+
94
+ // 添加缓存页面
95
+ if (to.name && to.meta.keepAlive) {
96
+ appStore.addCachedView(to.name as string)
97
+ }
98
+
99
+ // 重新导航到目标路由,确保动态路由已添加
100
+ next({ ...to, replace: true })
101
+ } catch (error) {
102
+ // 获取用户信息失败,清除 token 并跳转到登录页
103
+ console.error('获取用户信息失败:', error)
104
+ userStore.clearUserInfo()
105
+ menuStore.clearMenu()
106
+ // 清除 token
107
+ localStorage.removeItem('token')
108
+ localStorage.removeItem('token_type')
109
+ localStorage.removeItem('refresh_token')
110
+ next({ path: loginPath, query: { redirect: to.fullPath } })
111
+ }
112
+ }
113
+ }
114
+ } else {
115
+ // 未登录
116
+ if (whiteList.includes(to.path)) {
117
+ // 在白名单中,直接放行
118
+ next()
119
+ } else {
120
+ // 不在白名单中,跳转到登录页
121
+ next({ path: loginPath, query: { redirect: to.fullPath } })
122
+ }
123
+ }
124
+ })
125
+
126
+ router.afterEach(() => {
127
+ // 可以在这里添加进度条结束等
128
+ })
129
129
  }
@@ -1,80 +1,80 @@
1
- /**
2
- * 路由配置
3
- */
4
-
5
- import { createRouter, createWebHistory } from 'vue-router'
6
- import { staticRoutes, errorRoute } from './staticRoutes'
7
- import { layoutRoute } from './dynamicRoutes'
8
- import { hasToken } from '@/utils/auth'
9
- import { getAppId } from '@/utils/config'
10
- import { useUserStore } from '@/stores/user'
11
- import { useMenuStore } from '@/stores/menu'
12
- import { useAppStore } from '@/stores/app'
13
- import { mockMenuData } from './dynamicRoutes'
14
-
15
- const router = createRouter({
16
- history: createWebHistory(),
17
- routes: [...staticRoutes, layoutRoute, errorRoute],
18
- scrollBehavior: () => ({ left: 0, top: 0 })
19
- })
20
-
21
- // 白名单路由
22
- const whiteList = ['/login', '/404', '/403']
23
-
24
- // 路由守卫
25
- router.beforeEach(async (to, _from, next) => {
26
- const appStore = useAppStore()
27
-
28
- // 初始化主题
29
- appStore.initTheme()
30
-
31
- // 已登录
32
- if (hasToken()) {
33
- if (to.path === '/login') {
34
- // 已登录,跳转到首页
35
- next({ path: '/' })
36
- } else {
37
- // 设置用户信息(如果未设置)
38
- const userStore = useUserStore()
39
- if (!userStore.isLoggedIn) {
40
- userStore.setUserInfo({
41
- appId: getAppId(),
42
- userId: '1',
43
- userName: '管理员',
44
- departmentName: '技术部',
45
- email: 'admin@example.com',
46
- mobilePhone: '13800138000',
47
- positionName: '管理员',
48
- avatar: ''
49
- })
50
-
51
- // 设置菜单
52
- const menuStore = useMenuStore()
53
- menuStore.setMenuList(mockMenuData)
54
- }
55
-
56
- // 添加缓存页面
57
- if (to.name && to.meta.keepAlive) {
58
- appStore.addCachedView(to.name as string)
59
- }
60
- next()
61
- }
62
- } else {
63
- // 未登录
64
- if (whiteList.includes(to.path)) {
65
- next()
66
- } else {
67
- next('/login')
68
- }
69
- }
70
- })
71
-
72
- export function resetRouter() {
73
- const newRouter = createRouter({
74
- history: createWebHistory(),
75
- routes: [...staticRoutes, layoutRoute, errorRoute]
76
- })
77
- ;(router as any).matcher = (newRouter as any).matcher
78
- }
79
-
1
+ /**
2
+ * 路由配置
3
+ */
4
+
5
+ import { createRouter, createWebHistory } from 'vue-router'
6
+ import { staticRoutes, errorRoute } from './staticRoutes'
7
+ import { layoutRoute } from './dynamicRoutes'
8
+ import { hasToken } from '@/utils/auth'
9
+ import { getAppId } from '@/utils/config'
10
+ import { useUserStore } from '@/stores/user'
11
+ import { useMenuStore } from '@/stores/menu'
12
+ import { useAppStore } from '@/stores/app'
13
+ import { mockMenuData } from './dynamicRoutes'
14
+
15
+ const router = createRouter({
16
+ history: createWebHistory(),
17
+ routes: [...staticRoutes, layoutRoute, errorRoute],
18
+ scrollBehavior: () => ({ left: 0, top: 0 })
19
+ })
20
+
21
+ // 白名单路由
22
+ const whiteList = ['/login', '/404', '/403']
23
+
24
+ // 路由守卫
25
+ router.beforeEach(async (to, _from, next) => {
26
+ const appStore = useAppStore()
27
+
28
+ // 初始化主题
29
+ appStore.initTheme()
30
+
31
+ // 已登录
32
+ if (hasToken()) {
33
+ if (to.path === '/login') {
34
+ // 已登录,跳转到首页
35
+ next({ path: '/' })
36
+ } else {
37
+ // 设置用户信息(如果未设置)
38
+ const userStore = useUserStore()
39
+ if (!userStore.isLoggedIn) {
40
+ userStore.setUserInfo({
41
+ appId: getAppId(),
42
+ userId: '1',
43
+ userName: '管理员',
44
+ departmentName: '技术部',
45
+ email: 'admin@example.com',
46
+ mobilePhone: '13800138000',
47
+ positionName: '管理员',
48
+ avatar: ''
49
+ })
50
+
51
+ // 设置菜单
52
+ const menuStore = useMenuStore()
53
+ menuStore.setMenuList(mockMenuData)
54
+ }
55
+
56
+ // 添加缓存页面
57
+ if (to.name && to.meta.keepAlive) {
58
+ appStore.addCachedView(to.name as string)
59
+ }
60
+ next()
61
+ }
62
+ } else {
63
+ // 未登录
64
+ if (whiteList.includes(to.path)) {
65
+ next()
66
+ } else {
67
+ next('/login')
68
+ }
69
+ }
70
+ })
71
+
72
+ export function resetRouter() {
73
+ const newRouter = createRouter({
74
+ history: createWebHistory(),
75
+ routes: [...staticRoutes, layoutRoute, errorRoute]
76
+ })
77
+ ;(router as any).matcher = (newRouter as any).matcher
78
+ }
79
+
80
80
  export default router
@@ -1,66 +1,66 @@
1
- /**
2
- * 认证状态
3
- */
4
-
5
- import { defineStore } from 'pinia'
6
- import { ref, computed } from 'vue'
7
- import { getToken, clearToken, setTokenInfo, hasToken, type TokenInfo } from '@/utils/auth'
8
-
9
- export const useAuthStore = defineStore('auth', () => {
10
- // 状态
11
- const token = ref<string | null>(getToken())
12
- const isLoggedIn = computed(() => hasToken())
13
-
14
- // 应用配置
15
- const baseUrl = ref<string>('')
16
- const appId = ref<string>('')
17
- const clientId = ref<string>('')
18
- const loginPath = ref<string>('/login')
19
-
20
- // 设置 token(参考 tineco-ui)
21
- const login = (tokenInfo: TokenInfo) => {
22
- token.value = tokenInfo.access_token
23
- setTokenInfo(tokenInfo)
24
- }
25
-
26
- // 登出
27
- const logout = () => {
28
- token.value = null
29
- clearToken()
30
- }
31
-
32
- // 设置 API 基础路径
33
- const setBaseUrl = (url: string) => {
34
- baseUrl.value = url
35
- }
36
-
37
- // 设置应用 ID
38
- const setAppId = (id: string) => {
39
- appId.value = id
40
- }
41
-
42
- // 设置客户端 ID
43
- const setClientId = (id: string) => {
44
- clientId.value = id
45
- }
46
-
47
- // 设置登录页路径
48
- const setLoginPath = (path: string) => {
49
- loginPath.value = path
50
- }
51
-
52
- return {
53
- token,
54
- isLoggedIn,
55
- baseUrl,
56
- appId,
57
- clientId,
58
- loginPath,
59
- login,
60
- logout,
61
- setBaseUrl,
62
- setAppId,
63
- setClientId,
64
- setLoginPath
65
- }
1
+ /**
2
+ * 认证状态
3
+ */
4
+
5
+ import { defineStore } from 'pinia'
6
+ import { ref, computed } from 'vue'
7
+ import { getToken, clearToken, setTokenInfo, hasToken, type TokenInfo } from '@/utils/auth'
8
+
9
+ export const useAuthStore = defineStore('auth', () => {
10
+ // 状态
11
+ const token = ref<string | null>(getToken())
12
+ const isLoggedIn = computed(() => hasToken())
13
+
14
+ // 应用配置
15
+ const baseUrl = ref<string>('')
16
+ const appId = ref<string>('')
17
+ const clientId = ref<string>('')
18
+ const loginPath = ref<string>('/login')
19
+
20
+ // 设置 token(参考 tineco-ui)
21
+ const login = (tokenInfo: TokenInfo) => {
22
+ token.value = tokenInfo.access_token
23
+ setTokenInfo(tokenInfo)
24
+ }
25
+
26
+ // 登出
27
+ const logout = () => {
28
+ token.value = null
29
+ clearToken()
30
+ }
31
+
32
+ // 设置 API 基础路径
33
+ const setBaseUrl = (url: string) => {
34
+ baseUrl.value = url
35
+ }
36
+
37
+ // 设置应用 ID
38
+ const setAppId = (id: string) => {
39
+ appId.value = id
40
+ }
41
+
42
+ // 设置客户端 ID
43
+ const setClientId = (id: string) => {
44
+ clientId.value = id
45
+ }
46
+
47
+ // 设置登录页路径
48
+ const setLoginPath = (path: string) => {
49
+ loginPath.value = path
50
+ }
51
+
52
+ return {
53
+ token,
54
+ isLoggedIn,
55
+ baseUrl,
56
+ appId,
57
+ clientId,
58
+ loginPath,
59
+ login,
60
+ logout,
61
+ setBaseUrl,
62
+ setAppId,
63
+ setClientId,
64
+ setLoginPath
65
+ }
66
66
  })
@@ -1,49 +1,49 @@
1
- /**
2
- * 菜单状态
3
- */
4
-
5
- import { defineStore } from 'pinia'
6
- import { ref, computed } from 'vue'
7
- import type { MenuItem } from '@/types/api'
8
- import { local } from '@/utils/storage'
9
-
10
- const MENU_LIST_KEY = 'menu_list'
11
-
12
- // 首页菜单(参考 tineco-ui)
13
- const indexMenu: MenuItem = {
14
- menuCode: 'home',
15
- menuName: '首页',
16
- menuUrl: '/dashboard',
17
- icon: 'home',
18
- closable: false,
19
- isDefault: false,
20
- isOut: false
21
- }
22
-
23
- export const useMenuStore = defineStore('menu', () => {
24
- // 状态
25
- const menuList = ref<MenuItem[]>(local.get<MenuItem[]>(MENU_LIST_KEY) || [])
26
-
27
- // 计算属性
28
- const hasMenu = computed(() => menuList.value.length > 0)
29
-
30
- // 设置菜单
31
- const setMenuList = (menus: MenuItem[]) => {
32
- // 添加首页菜单到开头
33
- menuList.value = [indexMenu, ...menus]
34
- local.set(MENU_LIST_KEY, menuList.value)
35
- }
36
-
37
- // 清除菜单
38
- const clearMenu = () => {
39
- menuList.value = []
40
- local.remove(MENU_LIST_KEY)
41
- }
42
-
43
- return {
44
- menuList,
45
- hasMenu,
46
- setMenuList,
47
- clearMenu
48
- }
1
+ /**
2
+ * 菜单状态
3
+ */
4
+
5
+ import { defineStore } from 'pinia'
6
+ import { ref, computed } from 'vue'
7
+ import type { MenuItem } from '@/types/api'
8
+ import { local } from '@/utils/storage'
9
+
10
+ const MENU_LIST_KEY = 'menu_list'
11
+
12
+ // 首页菜单(参考 tineco-ui)
13
+ const indexMenu: MenuItem = {
14
+ menuCode: 'home',
15
+ menuName: '首页',
16
+ menuUrl: '/dashboard',
17
+ icon: 'home',
18
+ closable: false,
19
+ isDefault: false,
20
+ isOut: false
21
+ }
22
+
23
+ export const useMenuStore = defineStore('menu', () => {
24
+ // 状态
25
+ const menuList = ref<MenuItem[]>(local.get<MenuItem[]>(MENU_LIST_KEY) || [])
26
+
27
+ // 计算属性
28
+ const hasMenu = computed(() => menuList.value.length > 0)
29
+
30
+ // 设置菜单
31
+ const setMenuList = (menus: MenuItem[]) => {
32
+ // 添加首页菜单到开头
33
+ menuList.value = [indexMenu, ...menus]
34
+ local.set(MENU_LIST_KEY, menuList.value)
35
+ }
36
+
37
+ // 清除菜单
38
+ const clearMenu = () => {
39
+ menuList.value = []
40
+ local.remove(MENU_LIST_KEY)
41
+ }
42
+
43
+ return {
44
+ menuList,
45
+ hasMenu,
46
+ setMenuList,
47
+ clearMenu
48
+ }
49
49
  })