@gx-design-vue/create-gx-cli 0.1.15 → 0.1.16

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 (123) hide show
  1. package/package.json +1 -1
  2. package/src/main.js +7 -7
  3. package/template-mobile-vant-cli/.env +3 -0
  4. package/template-mobile-vant-cli/.env.development +4 -6
  5. package/template-mobile-vant-cli/.env.pro +16 -7
  6. package/template-mobile-vant-cli/.env.production +21 -9
  7. package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
  8. package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
  9. package/template-mobile-vant-cli/config/default/network.ts +10 -0
  10. package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
  11. package/template-mobile-vant-cli/config/default/theme.ts +3 -0
  12. package/template-mobile-vant-cli/config/index.ts +11 -0
  13. package/template-mobile-vant-cli/eslint.config.js +10 -2
  14. package/template-mobile-vant-cli/index.html +22 -21
  15. package/template-mobile-vant-cli/{build → internal/vite-config/generate}/generateModifyVars.ts +1 -1
  16. package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
  17. package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
  18. package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
  19. package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
  20. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/optimizer.ts +9 -1
  21. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
  22. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/plugin/autoImport.ts +7 -3
  23. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
  24. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
  25. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
  26. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
  27. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
  28. package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
  29. package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
  30. package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
  31. package/template-mobile-vant-cli/mock/index.ts +55 -0
  32. package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
  33. package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
  34. package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
  35. package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
  36. package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
  37. package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
  38. package/template-mobile-vant-cli/package.json +51 -34
  39. package/template-mobile-vant-cli/public/css/default.css +54 -0
  40. package/template-mobile-vant-cli/src/App.vue +6 -2
  41. package/template-mobile-vant-cli/src/assets/logo.png +0 -0
  42. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -1
  43. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +108 -16
  44. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +5 -2
  45. package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
  46. package/template-mobile-vant-cli/src/core/gx-design/index.ts +1 -1
  47. package/template-mobile-vant-cli/src/core/index.ts +0 -7
  48. package/template-mobile-vant-cli/src/design/color.less +1 -0
  49. package/template-mobile-vant-cli/src/design/config.less +5 -0
  50. package/template-mobile-vant-cli/src/design/index.less +1 -1
  51. package/template-mobile-vant-cli/src/design/mixin.less +65 -0
  52. package/template-mobile-vant-cli/src/design/reset.less +16 -132
  53. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +7 -9
  54. package/template-mobile-vant-cli/src/layout/{BasicLayout.vue → BasicLayout/index.vue} +3 -1
  55. package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
  56. package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
  57. package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
  58. package/template-mobile-vant-cli/src/main.ts +16 -9
  59. package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
  60. package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
  61. package/template-mobile-vant-cli/src/pages/{home.vue → Home/index.vue} +5 -5
  62. package/template-mobile-vant-cli/src/pages/user/login/index.vue +74 -0
  63. package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
  64. package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
  65. package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
  66. package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
  67. package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
  68. package/template-mobile-vant-cli/src/router/index.ts +21 -15
  69. package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
  70. package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
  71. package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
  72. package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
  73. package/template-mobile-vant-cli/src/store/index.ts +4 -1
  74. package/template-mobile-vant-cli/src/store/modules/global.ts +6 -13
  75. package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
  76. package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
  77. package/template-mobile-vant-cli/src/utils/crypto/index.ts +3 -4
  78. package/template-mobile-vant-cli/src/utils/env.ts +2 -2
  79. package/template-mobile-vant-cli/src/utils/pageTitle.ts +12 -6
  80. package/template-mobile-vant-cli/src/utils/request/XHR.ts +9 -11
  81. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +5 -5
  82. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +18 -2
  83. package/template-mobile-vant-cli/src/utils/request/index.ts +36 -23
  84. package/template-mobile-vant-cli/src/utils/storage.ts +49 -32
  85. package/template-mobile-vant-cli/src/utils/validate.ts +31 -36
  86. package/template-mobile-vant-cli/tsconfig.json +17 -9
  87. package/template-mobile-vant-cli/types/auto-imports.d.ts +18 -2
  88. package/template-mobile-vant-cli/types/components.d.ts +2 -7
  89. package/template-mobile-vant-cli/types/config.d.ts +56 -0
  90. package/template-mobile-vant-cli/types/global.d.ts +62 -21
  91. package/template-mobile-vant-cli/types/mock.d.ts +34 -0
  92. package/template-mobile-vant-cli/types/module.d.ts +33 -0
  93. package/template-mobile-vant-cli/types/response.d.ts +3 -1
  94. package/template-mobile-vant-cli/types/system.d.ts +58 -0
  95. package/template-mobile-vant-cli/types/vant-import.d.ts +16 -5
  96. package/template-mobile-vant-cli/unocss.config.ts +120 -66
  97. package/template-mobile-vant-cli/vite.config.ts +78 -81
  98. package/template-mobile-vant-cli/build/cdn.ts +0 -5
  99. package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
  100. package/template-mobile-vant-cli/build/plugin/index.ts +0 -42
  101. package/template-mobile-vant-cli/build/plugin/mock.ts +0 -14
  102. package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +0 -88
  103. package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +0 -271
  104. package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +0 -69
  105. package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +0 -48
  106. package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +0 -48
  107. package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
  108. package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
  109. package/template-mobile-vant-cli/mock/utils.ts +0 -9
  110. package/template-mobile-vant-cli/postcss.config.cjs +0 -8
  111. package/template-mobile-vant-cli/prettier.config.cjs +0 -18
  112. package/template-mobile-vant-cli/public/js/flexible.js +0 -44
  113. package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
  114. package/template-mobile-vant-cli/src/design/vant.less +0 -2
  115. package/template-mobile-vant-cli/src/global.less +0 -1
  116. package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
  117. package/template-mobile-vant-cli/src/router/routes.ts +0 -20
  118. package/template-mobile-vant-cli/src/router/typings.ts +0 -8
  119. package/template-mobile-vant-cli/src/settings/index.ts +0 -10
  120. package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
  121. package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
  122. package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
  123. /package/template-mobile-vant-cli/{mock/datasSource/api/index.ts → src/design/vant/index.less} +0 -0
@@ -0,0 +1,10 @@
1
+ import type { Router } from 'vue-router'
2
+
3
+ export function createStateGuard(router: Router) {
4
+ router.afterEach((to) => {
5
+ const user = useStoreUser()
6
+ if (to.path === '/user/login') {
7
+ user.resetPermissions()
8
+ }
9
+ })
10
+ }
@@ -1,25 +1,31 @@
1
1
  import type { App } from 'vue'
2
2
  import type { RouteRecordRaw } from 'vue-router'
3
- import { createRouter, createWebHashHistory } from 'vue-router'
4
- import settings from '@/settings'
5
- import getPageTitle from '@/utils/pageTitle'
6
- import { constantRoutes } from './routes'
3
+ import { defaultSettings } from '@gx-config'
4
+ import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
5
+ import { routerList } from './routes'
7
6
 
8
- export const router = createRouter({
9
- history: createWebHashHistory(),
10
- routes: constantRoutes as unknown as RouteRecordRaw[]
11
- })
7
+ const { routerMode } = defaultSettings.system
12
8
 
13
- const doRouterPermission = () => {
14
- router.afterEach((to) => {
15
- const { meta }: any = to
16
- document.title = getPageTitle(settings.title, meta.title || '')
17
- })
9
+ function handleRouterMode() {
10
+ switch (routerMode) {
11
+ case 'hash':
12
+ return createWebHashHistory()
13
+ break
14
+ case 'browser':
15
+ return createWebHistory()
16
+ break
17
+ default:
18
+ return createWebHashHistory()
19
+ break
20
+ }
18
21
  }
19
22
 
23
+ export const router = createRouter({
24
+ history: handleRouterMode(),
25
+ routes: routerList as unknown as RouteRecordRaw[]
26
+ })
27
+
20
28
  // 配置路由器
21
29
  export function setupRouter(app: App<Element>) {
22
30
  app.use(router)
23
-
24
- doRouterPermission()
25
31
  }
@@ -0,0 +1,46 @@
1
+ import BasicLayout from '@/layout/BasicLayout/index.vue'
2
+ import UserLayout from '@/layout/UserLayout/index.vue'
3
+
4
+ // import.meta.globEager() 直接引入所有的模块 Vite 独有的功能
5
+ const modules = import.meta.glob('./modules/**/*.ts', { eager: true })
6
+ const routeModuleList: AppRouteModule[] = []
7
+
8
+ // 加入到路由集合中
9
+ Object.keys(modules).forEach((key) => {
10
+ const mod = (modules[key] as any).default || {}
11
+ const modList = Array.isArray(mod) ? [ ...mod ] : [ mod ]
12
+ routeModuleList.push(...modList)
13
+ })
14
+
15
+ export const notFoundRoute: AppRouteModule = {
16
+ path: '/:path(.*)*',
17
+ name: 'NotFound',
18
+ redirect: '/'
19
+ }
20
+
21
+ // 自定义路由
22
+ export const routerList: AppRouteModule[] = [
23
+ {
24
+ path: '/user',
25
+ component: UserLayout,
26
+ name: 'UserLayout',
27
+ redirect: '/user/login',
28
+ children: [
29
+ {
30
+ path: '/user/login',
31
+ name: 'Login',
32
+ meta: {
33
+ title: '登录'
34
+ },
35
+ component: () => import('@/pages/user/login/index.vue')
36
+ }
37
+ ]
38
+ },
39
+ {
40
+ path: '/',
41
+ name: '首页',
42
+ component: BasicLayout,
43
+ children: routeModuleList
44
+ },
45
+ notFoundRoute
46
+ ]
@@ -0,0 +1,32 @@
1
+ export default [
2
+ {
3
+ path: '/',
4
+ name: 'Home',
5
+ meta: {
6
+ name: '首页',
7
+ icon: 'wap-home-o',
8
+ isMenu: true
9
+ },
10
+ component: () => import('@/pages/Home/index.vue')
11
+ },
12
+ {
13
+ path: '/account',
14
+ name: 'Account',
15
+ meta: {
16
+ name: '我的',
17
+ title: '个人中心',
18
+ icon: 'user-o',
19
+ isMenu: true
20
+ },
21
+ component: () => import('@/pages/Account/index.vue')
22
+ },
23
+ {
24
+ path: '/account/detail',
25
+ name: 'AccountDetails',
26
+ meta: {
27
+ title: '账号详情',
28
+ menuSelectKey: 'Account'
29
+ },
30
+ component: () => import('@/pages/Account/details.vue')
31
+ }
32
+ ] as AppRouteModule[]
@@ -0,0 +1,42 @@
1
+ import request from '@/utils/request'
2
+
3
+ export function getUserInfo<T, D = undefined>() {
4
+ return request<T, D>({
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<T, D>(data) {
6
+ return request<T, D>({
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
+ }
@@ -1,13 +1,16 @@
1
1
  import type { App } from 'vue'
2
2
  import { createPinia } from 'pinia'
3
3
  import { useStoreGlobal } from './modules/global'
4
+ import { useStoreUser } from './modules/user'
4
5
 
5
6
  export {
6
- useStoreGlobal
7
+ useStoreGlobal,
8
+ useStoreUser,
7
9
  }
8
10
 
9
11
  export function useStore() {
10
12
  return {
13
+ user: useStoreUser(),
11
14
  global: useStoreGlobal()
12
15
  }
13
16
  }
@@ -1,6 +1,5 @@
1
- import { reactive, toRefs } from 'vue'
1
+ import { useReactiveState } from '@gx-design-vue/pro-hooks'
2
2
  import { defineStore } from 'pinia'
3
- import { deepCopy } from '@gx-design-vue/pro-utils'
4
3
 
5
4
  /**
6
5
  * @Author gx12358
@@ -9,22 +8,16 @@ import { deepCopy } from '@gx-design-vue/pro-utils'
9
8
  * @description store-global 全局属性
10
9
  */
11
10
  export interface GlobalState {
12
- token?: string; // app token
11
+ disabledScrollTop: boolean;
13
12
  }
14
13
 
15
- type GlobalStateKey = keyof GlobalState
16
-
17
14
  export const useStoreGlobal = defineStore('global', () => {
18
- const state = reactive<GlobalState>({
19
- token: ''
15
+ const [ state, setValue ] = useReactiveState<GlobalState>({
16
+ disabledScrollTop: false
20
17
  })
21
18
 
22
- const setGlobalData: (params: Partial<Record<GlobalStateKey, GlobalState[GlobalStateKey]>>) => void = (params) => {
23
- Object.assign(state, deepCopy(params))
24
- }
25
-
26
19
  return {
27
- ...toRefs(state),
28
- setGlobalData
20
+ ...state,
21
+ setValue
29
22
  }
30
23
  })
@@ -0,0 +1,107 @@
1
+ import { getUserInfo, login, logout } from '@/services/userCenter'
2
+ import { getAccessToken, removeAccessToken, setAccessToken } from '@/utils/accessToken'
3
+ import { defaultSettings } from '@gx-config'
4
+ import { useReactiveState } from '@gx-design-vue/pro-hooks'
5
+ import { isArray, isNumber, isObject } from '@gx-design-vue/pro-utils'
6
+ import { defineStore } from 'pinia'
7
+
8
+ const { loginInterception } = defaultSettings.system
9
+
10
+ export interface UserState {
11
+ accessToken: string;
12
+ userInfo: UserDetails;
13
+ }
14
+
15
+ // 0 返回登录页 1 成功 2 返回注册页
16
+ export type CheckUserStatus = 0 | 1 | 2
17
+
18
+ export const useStoreUser = defineStore('user', () => {
19
+ const [ state, setValue ] = useReactiveState<UserState>({
20
+ accessToken: getAccessToken(),
21
+ userInfo: {} as UserDetails
22
+ }, { omitNil: false, omitEmpty: false })
23
+
24
+ /**
25
+ * @Author gx12358
26
+ * @DateTime 2022/1/11
27
+ * @lastTime 2022/1/11
28
+ * @description 登录拦截放行时,设置虚拟角色
29
+ */
30
+ const setVirtualUserInfo = (): CheckUserStatus => {
31
+ return 1
32
+ }
33
+
34
+ /**
35
+ * @Author gx12358
36
+ * @DateTime 2022/1/11
37
+ * @lastTime 2022/1/11
38
+ * @description 登录
39
+ */
40
+ const userLogin = async (params: any): Promise<boolean> => {
41
+ const response: ResponseResult<{ token: string; expiresIn: number }> = await login(params)
42
+ if (response) {
43
+ const accessToken = response.data?.token
44
+ if (accessToken) {
45
+ setValue({ accessToken })
46
+ setAccessToken(accessToken, response.data?.expiresIn ? response.data?.expiresIn * 60 * 1000 : 0)
47
+ return true
48
+ }
49
+ }
50
+
51
+ return false
52
+ }
53
+
54
+ const updateUserInfo = async (): Promise<CheckUserStatus> => {
55
+ let status: CheckUserStatus = 0
56
+ const response: ResponseResult<null, UserInfo> = await getUserInfo()
57
+ const { user, roles } = response || {} as UserInfo
58
+ if (response && user && isObject(user)) {
59
+ if (isNumber(user.userId) && roles && isArray(roles)) {
60
+ status = 1
61
+ setValue({ userInfo: { ...user } })
62
+ }
63
+ }
64
+ return status
65
+ }
66
+
67
+ /**
68
+ * @Author gx12358
69
+ * @DateTime 2022/1/11
70
+ * @lastTime 2022/1/11
71
+ * @description 获取用户信息
72
+ */
73
+ const checkUserPremission = async (): Promise<CheckUserStatus> => {
74
+ let status: CheckUserStatus = 0
75
+ if (loginInterception) {
76
+ status = await updateUserInfo()
77
+ } else {
78
+ status = setVirtualUserInfo()
79
+ }
80
+ return status
81
+ }
82
+
83
+ const resetPermissions = () => {
84
+ removeAccessToken()
85
+ setValue({ accessToken: '', userInfo: {} })
86
+ }
87
+
88
+ /**
89
+ * @Author gx12358
90
+ * @DateTime 2022/5/15
91
+ * @lastTime 2022/5/15
92
+ * @description 用户退出登录
93
+ */
94
+ const userLogut = async () => {
95
+ await logout()
96
+ resetPermissions()
97
+ }
98
+
99
+ return {
100
+ ...state,
101
+ userLogin,
102
+ userLogut,
103
+ setValue,
104
+ resetPermissions,
105
+ checkUserPremission
106
+ }
107
+ })
@@ -0,0 +1,97 @@
1
+ import {
2
+ delCookie,
3
+ getCookie,
4
+ getStorage,
5
+ removeStorage,
6
+ setCookie,
7
+ setStorage
8
+ } from '@/utils/storage'
9
+ import { defaultSettings } from '@gx-config'
10
+
11
+ const { storage, storageName } = defaultSettings.token
12
+
13
+ /**
14
+ * @Author gx12358
15
+ * @DateTime 2021/12/27
16
+ * @lastTime 2021/12/27
17
+ * @description 获取accessToken
18
+ */
19
+ export function getAccessToken() {
20
+ if (storage) {
21
+ if (storage === 'localStorage') {
22
+ return getStorage({ key: storageName, originKey: true })
23
+ } else if (storage === 'sessionStorage') {
24
+ return getStorage({ key: storageName, type: 'session', originKey: true })
25
+ } else if (storage === 'cookie') {
26
+ return getCookie(storageName)
27
+ } else {
28
+ return getStorage({ key: storageName, originKey: true })
29
+ }
30
+ } else {
31
+ return getStorage({ key: storageName, originKey: true })
32
+ }
33
+ }
34
+
35
+ /**
36
+ * @author gx12358 2539306317@qq.com
37
+ * @description 存储accessToken
38
+ * @param accessToken
39
+ * @returns {void|*}
40
+ */
41
+ export function setAccessToken(accessToken: string, expired?: number) {
42
+ if (storage) {
43
+ if (storage === 'localStorage') {
44
+ return setStorage({
45
+ key: storageName,
46
+ originKey: true,
47
+ value: accessToken,
48
+ expired
49
+ })
50
+ } else if (storage === 'sessionStorage') {
51
+ return setStorage({
52
+ key: storageName,
53
+ originKey: true,
54
+ value: accessToken,
55
+ expired,
56
+ type: 'session'
57
+ })
58
+ } else if (storage === 'cookie') {
59
+ return setCookie(storageName, accessToken, expired)
60
+ } else {
61
+ return setStorage({
62
+ key: storageName,
63
+ originKey: true,
64
+ value: accessToken,
65
+ expired
66
+ })
67
+ }
68
+ } else {
69
+ return setStorage({
70
+ key: storageName,
71
+ originKey: true,
72
+ value: accessToken,
73
+ expired
74
+ })
75
+ }
76
+ }
77
+
78
+ /**
79
+ * @author gx12358 2539306317@qq.com
80
+ * @description 移除accessToken
81
+ * @returns {void|Promise<void>}
82
+ */
83
+ export function removeAccessToken() {
84
+ if (storage) {
85
+ if (storage === 'localStorage') {
86
+ return removeStorage({ key: storageName, originKey: true })
87
+ } else if (storage === 'sessionStorage') {
88
+ return removeStorage({ key: storageName, type: 'session', originKey: true })
89
+ } else if (storage === 'cookie') {
90
+ return delCookie(storageName)
91
+ } else {
92
+ return removeStorage({ key: storageName, originKey: true })
93
+ }
94
+ } else {
95
+ return removeStorage({ key: storageName, originKey: true })
96
+ }
97
+ }
@@ -1,10 +1,9 @@
1
+ import { isArray, isJSONStr, isObject } from '@gx-design-vue/pro-utils'
2
+ import CryptoProJS from 'crypto-js'
3
+ import * as CryptoJS from 'crypto-js/core'
1
4
  import 'crypto-js/enc-utf8'
2
5
  import 'crypto-js/tripledes'
3
6
  import 'crypto-js/sha1'
4
- import * as CryptoJS from 'crypto-js/core'
5
- import CryptoProJS from 'crypto-js'
6
- import { isJSONStr } from '@/utils/validate'
7
- import { isArray, isObject } from '@gx-design-vue/pro-utils'
8
7
 
9
8
  const key = '1234123412ABCDEF' // 十六位十六进制数作为密钥
10
9
 
@@ -22,10 +22,10 @@ export function isPro(): boolean {
22
22
  * @Author gx12358
23
23
  * @DateTime 2022/4/1
24
24
  * @lastTime 2022/4/1
25
- * @description 环境:非本地开发环境
25
+ * @description 环境:非开发环境
26
26
  */
27
27
  export function isBuild(): boolean {
28
- return typeViteEnv('VITE_NODE_ENV') === 'production'
28
+ return typeViteEnv('VITE_APP_ENV') !== 'dev'
29
29
  }
30
30
 
31
31
  /**
@@ -1,14 +1,20 @@
1
+ import { defaultSettings } from '@gx-config'
2
+
3
+ const { title, titleReverse, titleSeparator } = defaultSettings.system
4
+
1
5
  /**
2
- * @author gx12358 2539306317@qq.com
6
+ * @Author gx12358
7
+ * @DateTime 2024/9/20
8
+ * @lastTime 2024/9/20
3
9
  * @description 设置标题
4
- * @param pageTitle
5
- * @returns {string}
6
10
  */
7
- export default function getPageTitle(title: string, pageTitle: string) {
8
- const newTitles: string[] = []
11
+ export default function getPageTitle(pageTitle: string) {
12
+ let newTitles: string[] = []
9
13
  if (pageTitle)
10
14
  newTitles.push(pageTitle)
11
15
  if (title)
12
16
  newTitles.push(title)
13
- return newTitles.join('-')
17
+ if (titleReverse)
18
+ newTitles = newTitles.reverse()
19
+ return newTitles.join(titleSeparator)
14
20
  }
@@ -1,14 +1,11 @@
1
1
  import type { AxiosError } from 'axios'
2
+ import type { GAxiosInstance, GAxiosOptions, GAxiosResponse } from './typings'
3
+ import { isFunction } from '@gx-design-vue/pro-utils'
2
4
  import axios from 'axios'
3
5
  import { cloneDeep } from 'lodash-es'
4
6
  import qs from 'qs'
5
- import { isFunction } from '@gx-design-vue/pro-utils'
6
- import type { GAxiosInstance, GAxiosOptions, GAxiosResponse } from './typings'
7
- import { ContentTypeEnum, RequestEnum } from './typings'
8
7
  import { AxiosCanceler } from './axiosCancel'
9
-
10
- export const getPendingUrl = (config: GAxiosOptions) => config.cancelKey || [ config.method, config.url ].join(
11
- '&')
8
+ import { ContentTypeEnum, RequestEnum } from './typings'
12
9
 
13
10
  /**
14
11
  * @Author gx12358
@@ -99,8 +96,8 @@ export class GAxios {
99
96
  }
100
97
  }
101
98
 
102
- request<T = ResponseResult | boolean>(config: GAxiosOptions): Promise<T> {
103
- let conf: GAxiosOptions = cloneDeep(config)
99
+ request<T = ResponseResult | boolean>(config?: GAxiosOptions): Promise<T> {
100
+ let conf = cloneDeep(config || {} as GAxiosOptions)
104
101
 
105
102
  const opt: GAxiosOptions = Object.assign({}, this.options, conf)
106
103
 
@@ -117,10 +114,11 @@ export class GAxios {
117
114
  .then((res: GAxiosResponse) => {
118
115
  if (transformResponseHook && isFunction(transformResponseHook)) {
119
116
  try {
120
- const ret = transformResponseHook(res, config)
117
+ const ret = transformResponseHook(res, config || {})
121
118
  resolve(ret)
122
- } catch (err) {
123
- resolve(false as any)
119
+ } catch (error) {
120
+ console.error('request-error', error)
121
+ resolve(false as unknown as Promise<T>)
124
122
  return
125
123
  }
126
124
  return
@@ -1,7 +1,7 @@
1
1
  import type { Canceler } from 'axios'
2
- import axios from 'axios'
3
- import { isFunction } from '@gx-design-vue/pro-utils'
4
2
  import type { GAxiosOptions } from './typings'
3
+ import { isFunction } from '@gx-design-vue/pro-utils'
4
+ import axios from 'axios'
5
5
 
6
6
  export const getPendingUrl = (
7
7
  config: GAxiosOptions,
@@ -15,12 +15,12 @@ export class AxiosCanceler {
15
15
  constructor(ignoreCancel?: boolean) {
16
16
  this.pendingMap = new Map<string, Canceler>()
17
17
 
18
- this.ignoreCancelToken = ignoreCancel
18
+ this.ignoreCancelToken = !!ignoreCancel
19
19
  }
20
20
 
21
21
  /**
22
22
  * Add request
23
- * @param {Object} config
23
+ * @param {object} config
24
24
  */
25
25
  addPending(config: GAxiosOptions) {
26
26
  !this.ignoreCancelToken && this.removePending(config)
@@ -46,7 +46,7 @@ export class AxiosCanceler {
46
46
 
47
47
  /**
48
48
  * Removal request
49
- * @param {Object} config
49
+ * @param {object} config
50
50
  */
51
51
  removePending(config: GAxiosOptions, key?: string) {
52
52
  const url = getPendingUrl(config, key)
@@ -1,9 +1,25 @@
1
+ import { router } from '@/router'
2
+ import { useStoreUser } from '@/store'
3
+ import { showToast } from 'vant'
4
+
1
5
  /**
2
6
  * @author gx12358 2539306317@qq.com
3
7
  * @description 处理code异常
4
8
  * @param {*} code
5
9
  * @param {*} msg
6
10
  */
7
- export const handleCode = (_code: number, _msg: string) => {
8
- // 这里处理不同状态
11
+ export const handleCode = (code: number, msg: string) => {
12
+ const user = useStoreUser()
13
+ switch (code) {
14
+ case 401:
15
+ user.resetPermissions()
16
+ router.push({ path: '/user/login' })
17
+ break
18
+ default:
19
+ showToast({
20
+ type: 'fail',
21
+ message: msg || '后端接口异常'
22
+ })
23
+ break
24
+ }
9
25
  }