@gx-design-vue/create-gx-cli 0.1.10 → 0.1.12

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. package/package.json +2 -1
  2. package/template-gx-design-thin/.editorconfig +19 -0
  3. package/template-gx-design-thin/.env +4 -0
  4. package/template-gx-design-thin/.env.development +15 -0
  5. package/template-gx-design-thin/.env.production +28 -0
  6. package/template-gx-design-thin/.eslintignore +16 -0
  7. package/template-gx-design-thin/.prettierignore +9 -0
  8. package/template-gx-design-thin/LICENSE +21 -0
  9. package/template-gx-design-thin/README.md +112 -0
  10. package/template-gx-design-thin/build/constant.ts +1 -0
  11. package/template-gx-design-thin/build/generate/generateModifyVars.ts +14 -0
  12. package/template-gx-design-thin/build/rollupOptions/index.ts +22 -0
  13. package/template-gx-design-thin/build/util/hash.ts +17 -0
  14. package/template-gx-design-thin/build/util/index.ts +131 -0
  15. package/template-gx-design-thin/build/vite/cdn.ts +63 -0
  16. package/template-gx-design-thin/build/vite/optimizer.ts +26 -0
  17. package/template-gx-design-thin/build/vite/plugin/appConfig.ts +91 -0
  18. package/template-gx-design-thin/build/vite/plugin/autoImport.ts +26 -0
  19. package/template-gx-design-thin/build/vite/plugin/compress.ts +31 -0
  20. package/template-gx-design-thin/build/vite/plugin/html.ts +39 -0
  21. package/template-gx-design-thin/build/vite/plugin/index.ts +75 -0
  22. package/template-gx-design-thin/build/vite/plugin/mock.ts +14 -0
  23. package/template-gx-design-thin/build/vite/plugin/pwa.ts +31 -0
  24. package/template-gx-design-thin/build/vite/plugin/visualizer.ts +14 -0
  25. package/template-gx-design-thin/build/vite/plugin/viteMock/client.ts +88 -0
  26. package/template-gx-design-thin/build/vite/plugin/viteMock/createMockServer.ts +271 -0
  27. package/template-gx-design-thin/build/vite/plugin/viteMock/index.ts +69 -0
  28. package/template-gx-design-thin/build/vite/plugin/viteMock/types.ts +48 -0
  29. package/template-gx-design-thin/build/vite/plugin/viteMock/utils.ts +48 -0
  30. package/template-gx-design-thin/build/vite/plugin/viteNotice.ts +40 -0
  31. package/template-gx-design-thin/commitlint.config.cjs +32 -0
  32. package/template-gx-design-thin/config/default/defaultSettings.ts +78 -0
  33. package/template-gx-design-thin/config/default/network.ts +10 -0
  34. package/template-gx-design-thin/config/default/proxy.ts +47 -0
  35. package/template-gx-design-thin/config/default/theme.ts +3 -0
  36. package/template-gx-design-thin/config/index.ts +11 -0
  37. package/template-gx-design-thin/eslint.config.js +51 -0
  38. package/template-gx-design-thin/index.html +42 -0
  39. package/template-gx-design-thin/mock/_createProductionServer.ts +19 -0
  40. package/template-gx-design-thin/mock/_util.ts +33 -0
  41. package/template-gx-design-thin/mock/config/menu.ts +21 -0
  42. package/template-gx-design-thin/mock/config/user.ts +123 -0
  43. package/template-gx-design-thin/mock/datasSource/system/menu.ts +10 -0
  44. package/template-gx-design-thin/mock/datasSource/user/account.ts +30 -0
  45. package/template-gx-design-thin/mock/datasSource/user/index.ts +47 -0
  46. package/template-gx-design-thin/mock/util/crypto.ts +23 -0
  47. package/template-gx-design-thin/mock/util/table.ts +92 -0
  48. package/template-gx-design-thin/mock/util/utils.ts +73 -0
  49. package/template-gx-design-thin/package.json +129 -0
  50. package/template-gx-design-thin/pnpm-lock.yaml +12575 -0
  51. package/template-gx-design-thin/prettier.config.cjs +18 -0
  52. package/template-gx-design-thin/public/resource/css/index.css +119 -0
  53. package/template-gx-design-thin/public/resource/css/normalize.css +396 -0
  54. package/template-gx-design-thin/public/resource/img/favicon.ico +0 -0
  55. package/template-gx-design-thin/public/resource/img/logo.png +0 -0
  56. package/template-gx-design-thin/public/resource/img/pro_icon.svg +1 -0
  57. package/template-gx-design-thin/public/resource/img/pwa-192x192.png +0 -0
  58. package/template-gx-design-thin/public/resource/img/pwa-512x512.png +0 -0
  59. package/template-gx-design-thin/src/App.vue +42 -0
  60. package/template-gx-design-thin/src/assets/error_images/403.png +0 -0
  61. package/template-gx-design-thin/src/assets/error_images/404.png +0 -0
  62. package/template-gx-design-thin/src/assets/error_images/cloud.png +0 -0
  63. package/template-gx-design-thin/src/assets/login_images/login_background.svg +1 -0
  64. package/template-gx-design-thin/src/assets/logo.png +0 -0
  65. package/template-gx-design-thin/src/assets/menu_font/iconfont.css +94 -0
  66. package/template-gx-design-thin/src/assets/menu_font/iconfont.eot +0 -0
  67. package/template-gx-design-thin/src/assets/menu_font/iconfont.js +1 -0
  68. package/template-gx-design-thin/src/assets/menu_font/iconfont.json +142 -0
  69. package/template-gx-design-thin/src/assets/menu_font/iconfont.svg +1 -0
  70. package/template-gx-design-thin/src/assets/menu_font/iconfont.ttf +0 -0
  71. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff +0 -0
  72. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff2 +0 -0
  73. package/template-gx-design-thin/src/assets/menu_font/index.less +94 -0
  74. package/template-gx-design-thin/src/assets/public_icon/iconfont.css +42 -0
  75. package/template-gx-design-thin/src/assets/public_icon/iconfont.eot +0 -0
  76. package/template-gx-design-thin/src/assets/public_icon/iconfont.js +1 -0
  77. package/template-gx-design-thin/src/assets/public_icon/iconfont.json +51 -0
  78. package/template-gx-design-thin/src/assets/public_icon/iconfont.svg +1 -0
  79. package/template-gx-design-thin/src/assets/public_icon/iconfont.ttf +0 -0
  80. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff +0 -0
  81. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff2 +0 -0
  82. package/template-gx-design-thin/src/assets/public_icon/index.less +42 -0
  83. package/template-gx-design-thin/src/assets/public_images/nodata.svg +1 -0
  84. package/template-gx-design-thin/src/common/global.ts +4 -0
  85. package/template-gx-design-thin/src/components/GDesign/Result/index.tsx +144 -0
  86. package/template-gx-design-thin/src/components/GDesign/Result/style.less +140 -0
  87. package/template-gx-design-thin/src/components/GDesign/utils/index.ts +7 -0
  88. package/template-gx-design-thin/src/components/GlobalLayout/Confirm/index.ts +21 -0
  89. package/template-gx-design-thin/src/components/GlobalLayout/Empty/index.vue +18 -0
  90. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/index.tsx +126 -0
  91. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/style.ts +77 -0
  92. package/template-gx-design-thin/src/components/GlobalLayout/Spin/index.tsx +30 -0
  93. package/template-gx-design-thin/src/components/PageLoading/index.tsx +51 -0
  94. package/template-gx-design-thin/src/components/index.ts +6 -0
  95. package/template-gx-design-thin/src/core/ant-design/index.ts +10 -0
  96. package/template-gx-design-thin/src/core/gx-admin-design/index.ts +6 -0
  97. package/template-gx-design-thin/src/core/gx-design/index.ts +6 -0
  98. package/template-gx-design-thin/src/core/gx-pro-design/index.ts +8 -0
  99. package/template-gx-design-thin/src/core/index.ts +84 -0
  100. package/template-gx-design-thin/src/design/ant-design/index.less +4 -0
  101. package/template-gx-design-thin/src/design/ant-design/layout.less +22 -0
  102. package/template-gx-design-thin/src/design/ant-design/menu.less +48 -0
  103. package/template-gx-design-thin/src/design/ant-design/spin.less +23 -0
  104. package/template-gx-design-thin/src/design/ant-design/tooltip.less +7 -0
  105. package/template-gx-design-thin/src/design/color.less +1 -0
  106. package/template-gx-design-thin/src/design/config.less +5 -0
  107. package/template-gx-design-thin/src/design/imageEditor.less +180 -0
  108. package/template-gx-design-thin/src/design/index.less +95 -0
  109. package/template-gx-design-thin/src/design/mixin.less +65 -0
  110. package/template-gx-design-thin/src/design/normalize.less +391 -0
  111. package/template-gx-design-thin/src/design/root.less +3 -0
  112. package/template-gx-design-thin/src/hooks/core/index.ts +3 -0
  113. package/template-gx-design-thin/src/hooks/core/useRequest/index.ts +118 -0
  114. package/template-gx-design-thin/src/hooks/event/index.ts +3 -0
  115. package/template-gx-design-thin/src/hooks/event/useClipboard.ts +15 -0
  116. package/template-gx-design-thin/src/hooks/web/index.ts +5 -0
  117. package/template-gx-design-thin/src/hooks/web/useThemeStyle.ts +16 -0
  118. package/template-gx-design-thin/src/layout/BasicLayout.vue +123 -0
  119. package/template-gx-design-thin/src/layout/BlankLayout.vue +5 -0
  120. package/template-gx-design-thin/src/layout/ContentView.vue +50 -0
  121. package/template-gx-design-thin/src/layout/IframeView.vue +1 -0
  122. package/template-gx-design-thin/src/layout/UserLayout.vue +7 -0
  123. package/template-gx-design-thin/src/main.ts +34 -0
  124. package/template-gx-design-thin/src/plugins/index.ts +2 -0
  125. package/template-gx-design-thin/src/router/guard/index.ts +83 -0
  126. package/template-gx-design-thin/src/router/guard/permissions.ts +70 -0
  127. package/template-gx-design-thin/src/router/guard/stateGuard.ts +10 -0
  128. package/template-gx-design-thin/src/router/helper/routeHelper.ts +223 -0
  129. package/template-gx-design-thin/src/router/helper/utils.ts +19 -0
  130. package/template-gx-design-thin/src/router/index.ts +31 -0
  131. package/template-gx-design-thin/src/router/routes/index.ts +86 -0
  132. package/template-gx-design-thin/src/router/routes/modules/dataSource.ts +12 -0
  133. package/template-gx-design-thin/src/services/common/index.ts +11 -0
  134. package/template-gx-design-thin/src/services/systemCenter/index.ts +1 -0
  135. package/template-gx-design-thin/src/services/systemCenter/menu.ts +9 -0
  136. package/template-gx-design-thin/src/services/userCenter/account.ts +42 -0
  137. package/template-gx-design-thin/src/services/userCenter/index.ts +28 -0
  138. package/template-gx-design-thin/src/store/index.ts +32 -0
  139. package/template-gx-design-thin/src/store/modules/dict.ts +28 -0
  140. package/template-gx-design-thin/src/store/modules/global.ts +42 -0
  141. package/template-gx-design-thin/src/store/modules/permission.ts +19 -0
  142. package/template-gx-design-thin/src/store/modules/routes.ts +113 -0
  143. package/template-gx-design-thin/src/store/modules/tabsRouter.ts +76 -0
  144. package/template-gx-design-thin/src/store/modules/user.ts +136 -0
  145. package/template-gx-design-thin/src/utils/accessToken.ts +80 -0
  146. package/template-gx-design-thin/src/utils/crypto/base64.ts +101 -0
  147. package/template-gx-design-thin/src/utils/crypto/index.ts +57 -0
  148. package/template-gx-design-thin/src/utils/env.ts +50 -0
  149. package/template-gx-design-thin/src/utils/fetchFile.ts +81 -0
  150. package/template-gx-design-thin/src/utils/index.ts +123 -0
  151. package/template-gx-design-thin/src/utils/pageTitle.ts +20 -0
  152. package/template-gx-design-thin/src/utils/request/XHR.ts +139 -0
  153. package/template-gx-design-thin/src/utils/request/axiosCancel.ts +69 -0
  154. package/template-gx-design-thin/src/utils/request/checkStatus.ts +25 -0
  155. package/template-gx-design-thin/src/utils/request/index.ts +144 -0
  156. package/template-gx-design-thin/src/utils/request/typings.ts +171 -0
  157. package/template-gx-design-thin/src/utils/storage.ts +199 -0
  158. package/template-gx-design-thin/src/utils/uploadFile.ts +27 -0
  159. package/template-gx-design-thin/src/utils/util.ts +198 -0
  160. package/template-gx-design-thin/src/utils/validate.ts +216 -0
  161. package/template-gx-design-thin/src/views/Iframe/index.vue +76 -0
  162. package/template-gx-design-thin/src/views/Page/one.vue +13 -0
  163. package/template-gx-design-thin/src/views/Page/two.vue +13 -0
  164. package/template-gx-design-thin/src/views/exception/403/index.vue +7 -0
  165. package/template-gx-design-thin/src/views/exception/404/index.vue +9 -0
  166. package/template-gx-design-thin/src/views/user/login/index.vue +109 -0
  167. package/template-gx-design-thin/src/views/user/login/style.less +38 -0
  168. package/template-gx-design-thin/tsconfig.json +46 -0
  169. package/template-gx-design-thin/types/ant-design-import.d.ts +99 -0
  170. package/template-gx-design-thin/types/auto-imports.d.ts +81 -0
  171. package/template-gx-design-thin/types/components.d.ts +24 -0
  172. package/template-gx-design-thin/types/config.d.ts +44 -0
  173. package/template-gx-design-thin/types/global.d.ts +97 -0
  174. package/template-gx-design-thin/types/mock.d.ts +16 -0
  175. package/template-gx-design-thin/types/module.d.ts +20 -0
  176. package/template-gx-design-thin/types/response.d.ts +15 -0
  177. package/template-gx-design-thin/unocss.config.ts +101 -0
  178. package/template-gx-design-thin/vite.config.ts +120 -0
  179. package/template-gx-design-thin/yarn.lock +9492 -0
@@ -0,0 +1,42 @@
1
+ import request from '@/utils/request'
2
+
3
+ export function getUserInfo() {
4
+ return request({
5
+ url: '/user/queryUserDetail',
6
+ method: 'get',
7
+ isMock: true
8
+ })
9
+ }
10
+
11
+ export function getUserList() {
12
+ return request({
13
+ url: '/user/account/list',
14
+ method: 'get',
15
+ isMock: true
16
+ })
17
+ }
18
+
19
+ export function getAccountGroupList() {
20
+ return request({
21
+ url: '/user/account/group',
22
+ method: 'get',
23
+ isMock: true
24
+ })
25
+ }
26
+
27
+ export function getAccountCount() {
28
+ return request({
29
+ url: '/user/account/count',
30
+ method: 'get',
31
+ isMock: true
32
+ })
33
+ }
34
+
35
+ export function updateUserDetails(data) {
36
+ return request({
37
+ url: '/user/account/update',
38
+ method: 'post',
39
+ data,
40
+ isMock: true
41
+ })
42
+ }
@@ -0,0 +1,28 @@
1
+ import request from '@/utils/request'
2
+
3
+ export * from './account'
4
+
5
+ export function login(data) {
6
+ return request({
7
+ url: '/user/login',
8
+ method: 'post',
9
+ data,
10
+ isMock: true
11
+ })
12
+ }
13
+
14
+ export function logout() {
15
+ return request({
16
+ url: '/user/logout',
17
+ method: 'get',
18
+ isMock: true
19
+ })
20
+ }
21
+
22
+ export function register() {
23
+ return request({
24
+ url: '/user/register',
25
+ method: 'post',
26
+ isMock: true
27
+ })
28
+ }
@@ -0,0 +1,32 @@
1
+ import type { App } from 'vue'
2
+ import { createPinia } from 'pinia'
3
+ import { useStoreGlobal } from './modules/global'
4
+ import { useStoreDict } from './modules/dict'
5
+ import { useStoreUser } from './modules/user'
6
+ import { useStoreRoutes } from './modules/routes'
7
+ import { useStorePermission } from './modules/permission'
8
+ import { useStoreTabsRouter } from './modules/tabsRouter'
9
+
10
+ export {
11
+ useStoreGlobal,
12
+ useStoreDict,
13
+ useStoreUser,
14
+ useStoreRoutes,
15
+ useStorePermission,
16
+ useStoreTabsRouter
17
+ }
18
+
19
+ export function useStore() {
20
+ return {
21
+ user: useStoreUser(),
22
+ dict: useStoreDict(),
23
+ global: useStoreGlobal(),
24
+ routes: useStoreRoutes(),
25
+ permission: useStorePermission(),
26
+ tabsRouter: useStoreTabsRouter()
27
+ }
28
+ }
29
+
30
+ export function setupStore(app: App<Element>) {
31
+ app.use(createPinia())
32
+ }
@@ -0,0 +1,28 @@
1
+ import { reactive, toRefs } from 'vue'
2
+ import { defineStore } from 'pinia'
3
+ import type { DictRecord, DictType } from '@gx-mock/config/dict'
4
+
5
+ /**
6
+ * @Author gx12358
7
+ * @DateTime 2022/1/11
8
+ * @lastTime 2022/1/11
9
+ * @description store-dict 数字字典
10
+ */
11
+ export interface DictState {
12
+ data: Partial<Record<DictType, DictRecord[]>>;
13
+ }
14
+
15
+ export const useStoreDict = defineStore('dict', () => {
16
+ const state = reactive<DictState>({
17
+ data: {}
18
+ })
19
+
20
+ const setDictData = (type, value) => {
21
+ state.data[type] = value
22
+ }
23
+
24
+ return {
25
+ ...toRefs(state),
26
+ setDictData
27
+ }
28
+ })
@@ -0,0 +1,42 @@
1
+ import { reactive } from 'vue'
2
+ import { defineStore } from 'pinia'
3
+ import type { ThemeConfig } from '@gx-design-vue/pro-provider'
4
+ import { themeConfig as proThemeConfig } from '@gx-design-vue/pro-provider'
5
+ import type { BasicLayoutProps } from '@gx-design-vue/pro-layout'
6
+ import { handleThemeConfig } from '@gx-design-vue/pro-layout'
7
+ import { defaultSettings, theme } from '@gx-config'
8
+ import logo from '@/assets/logo.png'
9
+
10
+ const layoutThemeConfig = {
11
+ ...proThemeConfig,
12
+ title: defaultSettings.title
13
+ } as ThemeConfig
14
+
15
+ /**
16
+ * @Author gx12358
17
+ * @DateTime 2022/1/11
18
+ * @lastTime 2022/1/11
19
+ * @description store-global 全局属性
20
+ */
21
+ export interface GlobalState {
22
+ globalLayout: BasicLayoutProps;
23
+ keepAlive: boolean;
24
+ showProgressBar: boolean;
25
+ disabledScrollTop: boolean;
26
+ }
27
+
28
+ export const useStoreGlobal = defineStore('global', () => {
29
+ const state = reactive<GlobalState>({
30
+ keepAlive: true,
31
+ showProgressBar: true,
32
+ disabledScrollTop: false,
33
+ globalLayout: {
34
+ logo,
35
+ ...handleThemeConfig({ ...layoutThemeConfig, primaryColor: theme.colorPrimary })
36
+ }
37
+ })
38
+
39
+ return {
40
+ ...toRefs(state)
41
+ }
42
+ })
@@ -0,0 +1,19 @@
1
+ import { reactive, toRefs } from 'vue'
2
+ import { defineStore } from 'pinia'
3
+
4
+ export const useStorePermission = defineStore('permission', () => {
5
+ const state = reactive({
6
+ admin: false,
7
+ role: [],
8
+ ability: []
9
+ })
10
+
11
+ const changeValue = (type: string, value: any) => {
12
+ state[type] = value
13
+ }
14
+
15
+ return {
16
+ ...toRefs(state),
17
+ changeValue
18
+ }
19
+ })
@@ -0,0 +1,113 @@
1
+ import { reactive, toRefs } from 'vue'
2
+ import { defineStore } from 'pinia'
3
+ import type { AppRouteModule, MenuDataItem } from '@gx-design-vue/pro-layout'
4
+ import { asyncRoutes, localRoutes } from '@/router/routes'
5
+ import { getMenuList } from '@/services/systemCenter'
6
+ import { generator, getRootMenu } from '@/router/helper/routeHelper'
7
+ import { getFirstLastChild } from '@/router/helper/utils'
8
+ import { getLevelData } from '@gx-design-vue/pro-utils'
9
+
10
+ /**
11
+ * @Author gx12358
12
+ * @DateTime 2022/1/11
13
+ * @lastTime 2022/1/11
14
+ * @description store-routes 路由
15
+ */
16
+ export interface RoutesState {
17
+ routes: AppRouteModule[];
18
+ routerLoadList: string[];
19
+ meunLoading: boolean;
20
+ routerLoading: boolean;
21
+ }
22
+
23
+ type RouteStateKey = keyof RoutesState
24
+
25
+ export const useStoreRoutes = defineStore('routes', () => {
26
+ const state = reactive<RoutesState>({
27
+ routes: [],
28
+ routerLoadList: [],
29
+ meunLoading: false,
30
+ routerLoading: false
31
+ })
32
+
33
+ /**
34
+ * @Author gx12358
35
+ * @DateTime 2022/1/11
36
+ * @lastTime 2022/1/11
37
+ * @description intelligence(前端静态路由)模式设置路由
38
+ */
39
+ const setRoutes = () => {
40
+ state.routes = localRoutes
41
+ return [ ...localRoutes ]
42
+ }
43
+
44
+ /**
45
+ * @Author gx12358
46
+ * @DateTime 2022/1/11
47
+ * @lastTime 2022/1/11
48
+ * @description all(后端动态路由)
49
+ */
50
+ const setAllRoutes = async () => {
51
+ let routes: AppRouteModule[] = []
52
+ state.meunLoading = true
53
+ const response: ResponseResult<MenuDataItem[]> = await getMenuList()
54
+ if (response && (response?.data)?.length) {
55
+ const notFoundRouter: AppRouteModule = {
56
+ path: '/:path(.*)*',
57
+ redirect: '/exception/404',
58
+ hidden: true
59
+ }
60
+ const rootMenu = getRootMenu(response?.data || [])
61
+ const asyncRouteList = generator(rootMenu)
62
+ asyncRouteList[0].children = [ ...(asyncRouteList[0]?.children || []), ...asyncRoutes ]
63
+ const haveHomePage = getLevelData(asyncRouteList[0].children)
64
+ .find(item => item.meta ? item.meta.homePage === 1 : false)
65
+ asyncRouteList[0].redirect = haveHomePage ? haveHomePage.path : getFirstLastChild(asyncRouteList[0].children)
66
+ asyncRouteList.push(notFoundRouter)
67
+ routes = [ ...asyncRouteList ]
68
+ }
69
+ state.routes = routes
70
+ state.meunLoading = false
71
+ return routes
72
+ }
73
+
74
+ /**
75
+ * @Author gx12358
76
+ * @DateTime 2022/1/11
77
+ * @lastTime 2022/1/11
78
+ * @description 重置路由
79
+ */
80
+ const resetRoute = () => {
81
+ state.routes = []
82
+ state.routerLoadList = []
83
+ }
84
+
85
+ /**
86
+ * @Author gx12358
87
+ * @DateTime 2022/1/11
88
+ * @lastTime 2022/1/11
89
+ * @description 添加路由记录
90
+ */
91
+ const addRouterLoadList = (path) => {
92
+ state.routerLoadList.push(path)
93
+ }
94
+
95
+ /**
96
+ * @Author gx12358
97
+ * @DateTime 2022/1/11
98
+ * @lastTime 2022/1/11
99
+ * @description 修改state状态
100
+ */
101
+ const setRouteState: (params: Partial<Record<RouteStateKey, RoutesState[RouteStateKey]>>) => void = (params) => {
102
+ Object.assign(state, params)
103
+ }
104
+
105
+ return {
106
+ ...toRefs(state),
107
+ setRoutes,
108
+ setAllRoutes,
109
+ resetRoute,
110
+ addRouterLoadList,
111
+ setRouteState
112
+ }
113
+ })
@@ -0,0 +1,76 @@
1
+ import { reactive, toRefs } from 'vue'
2
+ import { defineStore } from 'pinia'
3
+
4
+ export interface TabsRouterState {
5
+ visitedRoutes: Recordable[];
6
+ }
7
+
8
+ export const useStoreTabsRouter = defineStore('tabsRouter', () => {
9
+ const state = reactive({
10
+ visitedRoutes: []
11
+ } as TabsRouterState)
12
+
13
+ const addVisitedRoute = (route) => {
14
+ const target = state.visitedRoutes.find(item => item.path === route.path)
15
+ if (target) {
16
+ if (route.fullPath !== target.fullPath)
17
+ Object.assign(target, route)
18
+ return
19
+ }
20
+ if (route.tagFixed) {
21
+ state.visitedRoutes.unshift(Object.assign({}, route))
22
+ } else {
23
+ state.visitedRoutes.push(Object.assign({}, route))
24
+ }
25
+ }
26
+
27
+ const delVisitedRoute = (route) => {
28
+ state.visitedRoutes.forEach((item, index) => {
29
+ if (item.path === route.path)
30
+ state.visitedRoutes.splice(index, 1)
31
+ })
32
+ }
33
+
34
+ const delOthersVisitedRoutes = (route) => {
35
+ state.visitedRoutes = state.visitedRoutes.filter(
36
+ item => item.meta.tagFixed || item.path === route.path
37
+ )
38
+ }
39
+
40
+ const delLeftVisitedRoutes = (route) => {
41
+ let index = state.visitedRoutes.length
42
+ state.visitedRoutes = state.visitedRoutes.filter((item) => {
43
+ if (item.name === route.name)
44
+ index = state.visitedRoutes.indexOf(item)
45
+ return item.meta.tagFixed || index <= state.visitedRoutes.indexOf(item)
46
+ })
47
+ }
48
+
49
+ const delRightVisitedRoutes = (route) => {
50
+ let index = state.visitedRoutes.length
51
+ state.visitedRoutes = state.visitedRoutes.filter((item) => {
52
+ if (item.name === route.name)
53
+ index = state.visitedRoutes.indexOf(item)
54
+ return item.meta.tagFixed || index >= state.visitedRoutes.indexOf(item)
55
+ })
56
+ }
57
+
58
+ const delAllVisitedRoutes = () => {
59
+ state.visitedRoutes = state.visitedRoutes.filter(item => item.meta.tagFixed)
60
+ }
61
+
62
+ const blankingTabs = () => {
63
+ state.visitedRoutes = []
64
+ }
65
+
66
+ return {
67
+ ...toRefs(state),
68
+ blankingTabs,
69
+ addVisitedRoute,
70
+ delVisitedRoute,
71
+ delOthersVisitedRoutes,
72
+ delLeftVisitedRoutes,
73
+ delRightVisitedRoutes,
74
+ delAllVisitedRoutes
75
+ }
76
+ })
@@ -0,0 +1,136 @@
1
+ import { reactive, toRefs } from 'vue'
2
+ import { defineStore } from 'pinia'
3
+ import { notification } from 'ant-design-vue'
4
+ import { defaultSettings } from '@gx-config'
5
+ import type { UserDetails, UserInfo } from '@gx-mock/config/user'
6
+ import { defaultUser } from '@gx-mock/config/user'
7
+ import { getUserInfo, login, logout } from '@/services/userCenter'
8
+ import { getAccessToken, removeAccessToken, setAccessToken } from '@/utils/accessToken'
9
+ import { timeFix } from '@/utils/util'
10
+ import { useStoreRoutes } from './routes'
11
+ import { useStorePermission } from './permission'
12
+ import { useStoreTabsRouter } from './tabsRouter'
13
+ import { isObject } from '@gx-design-vue/pro-utils'
14
+ import { cloneDeep } from 'lodash-es'
15
+
16
+ const { tokenName, loginInterception } = defaultSettings
17
+
18
+ export interface UserState {
19
+ accessToken: string;
20
+ userInfo: UserDetails;
21
+ }
22
+
23
+ type UserStateKey = keyof UserState
24
+
25
+ export const useStoreUser = defineStore('user', () => {
26
+ const routes = useStoreRoutes()
27
+ const auth = useStorePermission()
28
+ const tabsRouter = useStoreTabsRouter()
29
+
30
+ const state = reactive<UserState>({
31
+ accessToken: getAccessToken(),
32
+ userInfo: {} as UserDetails
33
+ })
34
+
35
+ const userDetails = computed<UserDetails>(() => state.userInfo)
36
+
37
+ const setState: (params: Partial<Record<UserStateKey, UserState[UserStateKey]>>) => void = (params) => {
38
+ Object.assign(state, params)
39
+ }
40
+
41
+ /**
42
+ * @Author gx12358
43
+ * @DateTime 2022/1/11
44
+ * @lastTime 2022/1/11
45
+ * @description 登录拦截放行时,设置虚拟角色
46
+ */
47
+ const setVirtualUserInfo = () => {
48
+ auth.changeValue('admin', true)
49
+ auth.changeValue('role', defaultUser.roles)
50
+ auth.changeValue('ability', defaultUser.permissions)
51
+ setState({
52
+ userInfo: defaultUser.user as UserDetails
53
+ })
54
+ }
55
+
56
+ /**
57
+ * @Author gx12358
58
+ * @DateTime 2022/1/11
59
+ * @lastTime 2022/1/11
60
+ * @description 登录
61
+ */
62
+ const userLogin = async (params): Promise<boolean> => {
63
+ const response: ResponseResult<{ expiresIn: number; }> = await login(params)
64
+ const accessToken = response?.data?.[tokenName]
65
+ if (accessToken) {
66
+ const expiresIn = response?.data?.expiresIn
67
+ state.accessToken = accessToken
68
+ setAccessToken(accessToken, expiresIn ? expiresIn * 60 * 1000 : 0)
69
+ return true
70
+ }
71
+ return false
72
+ }
73
+
74
+ const updateUserInfo = async () => {
75
+ const response: ResponseResult<UserInfo> = await getUserInfo()
76
+ const { user, roles, permissions } = response?.data || {} as UserInfo
77
+ if (response && user && isObject(user)) {
78
+ if (user.userName && roles && Array.isArray(roles)) {
79
+ auth.changeValue('role', roles)
80
+ auth.changeValue('ability', permissions)
81
+
82
+ setState({
83
+ userInfo: cloneDeep(user)
84
+ })
85
+ notification.success({
86
+ message: `欢迎登录${state.userInfo?.userName}`,
87
+ description: `${timeFix()}!`
88
+ })
89
+ }
90
+ }
91
+ }
92
+
93
+ /**
94
+ * @Author gx12358
95
+ * @DateTime 2022/1/11
96
+ * @lastTime 2022/1/11
97
+ * @description 获取用户信息
98
+ */
99
+ const checkUserPremission = async () => {
100
+ if (loginInterception)
101
+ await updateUserInfo()
102
+ else setVirtualUserInfo()
103
+ return Object.keys(state.userInfo).length
104
+ }
105
+
106
+ const resetPermissions = () => {
107
+ state.accessToken = ''
108
+ removeAccessToken()
109
+ auth.changeValue('admin', false)
110
+ auth.changeValue('role', [])
111
+ auth.changeValue('ability', [])
112
+ routes.resetRoute()
113
+ tabsRouter.blankingTabs()
114
+ }
115
+
116
+ /**
117
+ * @Author gx12358
118
+ * @DateTime 2022/5/15
119
+ * @lastTime 2022/5/15
120
+ * @description 用户退出登录
121
+ */
122
+ const userLogut = async () => {
123
+ await logout()
124
+ resetPermissions()
125
+ }
126
+
127
+ return {
128
+ ...toRefs(state),
129
+ userDetails,
130
+ userLogin,
131
+ userLogut,
132
+ setState,
133
+ resetPermissions,
134
+ checkUserPremission
135
+ }
136
+ })
@@ -0,0 +1,80 @@
1
+ import { defaultSettings } from '@gx-config'
2
+ import {
3
+ delCookie,
4
+ getStorage,
5
+ removeStorage,
6
+ setCookie,
7
+ setStorage
8
+ } from '@/utils/storage'
9
+
10
+ const { storage, tokenTableName } = defaultSettings
11
+
12
+ /**
13
+ * @Author gx12358
14
+ * @DateTime 2021/12/27
15
+ * @lastTime 2021/12/27
16
+ * @description 获取accessToken
17
+ */
18
+ export function getAccessToken() {
19
+ return getStorage({ key: tokenTableName, type: storage || 'localStorage' })
20
+ }
21
+
22
+ /**
23
+ * @author gx12358 2539306317@qq.com
24
+ * @description 存储accessToken
25
+ * @param accessToken
26
+ * @returns {void|*}
27
+ */
28
+ export function setAccessToken(accessToken: string, expired?: number) {
29
+ if (storage) {
30
+ if (storage === 'localStorage') {
31
+ return setStorage({
32
+ key: tokenTableName,
33
+ value: accessToken,
34
+ expired
35
+ })
36
+ } else if (storage === 'sessionStorage') {
37
+ return setStorage({
38
+ key: tokenTableName,
39
+ value: accessToken,
40
+ expired,
41
+ type: 'session'
42
+ })
43
+ } else if (storage === 'cookie') {
44
+ return setCookie(tokenTableName, accessToken, expired)
45
+ } else {
46
+ return setStorage({
47
+ key: tokenTableName,
48
+ value: accessToken,
49
+ expired
50
+ })
51
+ }
52
+ } else {
53
+ return setStorage({
54
+ key: tokenTableName,
55
+ value: accessToken,
56
+ expired
57
+ })
58
+ }
59
+ }
60
+
61
+ /**
62
+ * @author gx12358 2539306317@qq.com
63
+ * @description 移除accessToken
64
+ * @returns {void|Promise<void>}
65
+ */
66
+ export function removeAccessToken() {
67
+ if (storage) {
68
+ if (storage === 'localStorage') {
69
+ return removeStorage(tokenTableName)
70
+ } else if (storage === 'sessionStorage') {
71
+ return removeStorage(tokenTableName, 'session')
72
+ } else if (storage === 'cookie') {
73
+ return delCookie(tokenTableName)
74
+ } else {
75
+ return removeStorage(tokenTableName)
76
+ }
77
+ } else {
78
+ return removeStorage(tokenTableName)
79
+ }
80
+ }
@@ -0,0 +1,101 @@
1
+ export default class Base64 {
2
+ _keyStr: string
3
+
4
+ constructor() {
5
+ this._keyStr = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='
6
+ }
7
+
8
+ _utf8_encode(string: string) {
9
+ string = string.replace(/\r\n/g, '\n')
10
+ let utftext = ''
11
+ for (let n = 0; n < string.length; n++) {
12
+ const c = string.charCodeAt(n)
13
+ if (c < 128) {
14
+ utftext += String.fromCharCode(c)
15
+ } else if ((c > 127) && (c < 2048)) {
16
+ utftext += String.fromCharCode((c >> 6) | 192)
17
+ utftext += String.fromCharCode((c & 63) | 128)
18
+ } else {
19
+ utftext += String.fromCharCode((c >> 12) | 224)
20
+ utftext += String.fromCharCode(((c >> 6) & 63) | 128)
21
+ utftext += String.fromCharCode((c & 63) | 128)
22
+ }
23
+ }
24
+ return utftext
25
+ }
26
+
27
+ _utf8_decode(utftext: string) {
28
+ let string = ''
29
+ let i = 0
30
+ let c = 0
31
+ let c1 = 0
32
+ let c2 = 0
33
+ while (i < utftext.length) {
34
+ c = utftext.charCodeAt(i)
35
+ if (c < 128) {
36
+ string += String.fromCharCode(c)
37
+ i++
38
+ } else if ((c > 191) && (c < 224)) {
39
+ c1 = utftext.charCodeAt(i + 1)
40
+ string += String.fromCharCode(((c & 31) << 6) | (c1 & 63))
41
+ i += 2
42
+ } else {
43
+ c1 = utftext.charCodeAt(i + 1)
44
+ c2 = utftext.charCodeAt(i + 2)
45
+ string += String.fromCharCode(((c & 15) << 12) | ((c1 & 63) << 6) | (c2 & 63))
46
+ i += 3
47
+ }
48
+ }
49
+ return string
50
+ }
51
+
52
+ encode(input: string) {
53
+ let output = ''
54
+ let chr1, chr2, chr3, enc1, enc2, enc3, enc4
55
+ let i = 0
56
+ input = this._utf8_encode(input)
57
+ while (i < input.length) {
58
+ chr1 = input.charCodeAt(i++)
59
+ chr2 = input.charCodeAt(i++)
60
+ chr3 = input.charCodeAt(i++)
61
+ enc1 = chr1 >> 2
62
+ enc2 = ((chr1 & 3) << 4) | (chr2 >> 4)
63
+ enc3 = ((chr2 & 15) << 2) | (chr3 >> 6)
64
+ enc4 = chr3 & 63
65
+ if (Number.isNaN(chr2)) {
66
+ enc3 = enc4 = 64
67
+ } else if (Number.isNaN(chr3)) {
68
+ enc4 = 64
69
+ }
70
+ output = output + this._keyStr.charAt(enc1) + this._keyStr.charAt(enc2) + this._keyStr.charAt(
71
+ enc3) + this._keyStr.charAt(enc4)
72
+ }
73
+ return output
74
+ }
75
+
76
+ decode(input: string) {
77
+ let output = ''
78
+ let chr1, chr2, chr3
79
+ let enc1, enc2, enc3, enc4
80
+ let i = 0
81
+ input = input.replace(/[^A-Za-z0-9+/=]/g, '')
82
+ while (i < input.length) {
83
+ enc1 = this._keyStr.indexOf(input.charAt(i++))
84
+ enc2 = this._keyStr.indexOf(input.charAt(i++))
85
+ enc3 = this._keyStr.indexOf(input.charAt(i++))
86
+ enc4 = this._keyStr.indexOf(input.charAt(i++))
87
+ chr1 = (enc1 << 2) | (enc2 >> 4)
88
+ chr2 = ((enc2 & 15) << 4) | (enc3 >> 2)
89
+ chr3 = ((enc3 & 3) << 6) | enc4
90
+ output = output + String.fromCharCode(chr1)
91
+ if (enc3 !== 64) {
92
+ output = output + String.fromCharCode(chr2)
93
+ }
94
+ if (enc4 !== 64) {
95
+ output = output + String.fromCharCode(chr3)
96
+ }
97
+ }
98
+ output = this._utf8_decode(output)
99
+ return output
100
+ }
101
+ }