@gx-design-vue/create-gx-cli 0.1.14 → 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 (124) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +7 -4
  3. package/src/main.js +7 -7
  4. package/template-mobile-vant-cli/.env +3 -0
  5. package/template-mobile-vant-cli/.env.development +4 -6
  6. package/template-mobile-vant-cli/.env.pro +16 -7
  7. package/template-mobile-vant-cli/.env.production +21 -9
  8. package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
  9. package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
  10. package/template-mobile-vant-cli/config/default/network.ts +10 -0
  11. package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
  12. package/template-mobile-vant-cli/config/default/theme.ts +3 -0
  13. package/template-mobile-vant-cli/config/index.ts +11 -0
  14. package/template-mobile-vant-cli/eslint.config.js +10 -2
  15. package/template-mobile-vant-cli/index.html +22 -21
  16. package/template-mobile-vant-cli/{build → internal/vite-config/generate}/generateModifyVars.ts +1 -1
  17. package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
  18. package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
  19. package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
  20. package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
  21. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/optimizer.ts +9 -1
  22. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
  23. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/plugin/autoImport.ts +7 -3
  24. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
  25. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
  26. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
  27. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
  28. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
  29. package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
  30. package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
  31. package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
  32. package/template-mobile-vant-cli/mock/index.ts +55 -0
  33. package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
  34. package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
  35. package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
  36. package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
  37. package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
  38. package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
  39. package/template-mobile-vant-cli/package.json +51 -34
  40. package/template-mobile-vant-cli/public/css/default.css +54 -0
  41. package/template-mobile-vant-cli/src/App.vue +6 -2
  42. package/template-mobile-vant-cli/src/assets/logo.png +0 -0
  43. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -1
  44. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +108 -16
  45. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +5 -2
  46. package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
  47. package/template-mobile-vant-cli/src/core/gx-design/index.ts +1 -1
  48. package/template-mobile-vant-cli/src/core/index.ts +0 -7
  49. package/template-mobile-vant-cli/src/design/color.less +1 -0
  50. package/template-mobile-vant-cli/src/design/config.less +5 -0
  51. package/template-mobile-vant-cli/src/design/index.less +1 -1
  52. package/template-mobile-vant-cli/src/design/mixin.less +65 -0
  53. package/template-mobile-vant-cli/src/design/reset.less +16 -132
  54. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +7 -9
  55. package/template-mobile-vant-cli/src/layout/{BasicLayout.vue → BasicLayout/index.vue} +3 -1
  56. package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
  57. package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
  58. package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
  59. package/template-mobile-vant-cli/src/main.ts +16 -9
  60. package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
  61. package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
  62. package/template-mobile-vant-cli/src/pages/{home.vue → Home/index.vue} +5 -5
  63. package/template-mobile-vant-cli/src/pages/user/login/index.vue +74 -0
  64. package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
  65. package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
  66. package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
  67. package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
  68. package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
  69. package/template-mobile-vant-cli/src/router/index.ts +21 -15
  70. package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
  71. package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
  72. package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
  73. package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
  74. package/template-mobile-vant-cli/src/store/index.ts +4 -1
  75. package/template-mobile-vant-cli/src/store/modules/global.ts +6 -13
  76. package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
  77. package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
  78. package/template-mobile-vant-cli/src/utils/crypto/index.ts +3 -4
  79. package/template-mobile-vant-cli/src/utils/env.ts +2 -2
  80. package/template-mobile-vant-cli/src/utils/pageTitle.ts +12 -6
  81. package/template-mobile-vant-cli/src/utils/request/XHR.ts +9 -11
  82. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +5 -5
  83. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +18 -2
  84. package/template-mobile-vant-cli/src/utils/request/index.ts +36 -23
  85. package/template-mobile-vant-cli/src/utils/storage.ts +49 -32
  86. package/template-mobile-vant-cli/src/utils/validate.ts +31 -36
  87. package/template-mobile-vant-cli/tsconfig.json +17 -9
  88. package/template-mobile-vant-cli/types/auto-imports.d.ts +18 -2
  89. package/template-mobile-vant-cli/types/components.d.ts +2 -7
  90. package/template-mobile-vant-cli/types/config.d.ts +56 -0
  91. package/template-mobile-vant-cli/types/global.d.ts +62 -21
  92. package/template-mobile-vant-cli/types/mock.d.ts +34 -0
  93. package/template-mobile-vant-cli/types/module.d.ts +33 -0
  94. package/template-mobile-vant-cli/types/response.d.ts +3 -1
  95. package/template-mobile-vant-cli/types/system.d.ts +58 -0
  96. package/template-mobile-vant-cli/types/vant-import.d.ts +16 -5
  97. package/template-mobile-vant-cli/unocss.config.ts +120 -66
  98. package/template-mobile-vant-cli/vite.config.ts +78 -81
  99. package/template-mobile-vant-cli/build/cdn.ts +0 -5
  100. package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
  101. package/template-mobile-vant-cli/build/plugin/index.ts +0 -42
  102. package/template-mobile-vant-cli/build/plugin/mock.ts +0 -14
  103. package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +0 -88
  104. package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +0 -271
  105. package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +0 -69
  106. package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +0 -48
  107. package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +0 -48
  108. package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
  109. package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
  110. package/template-mobile-vant-cli/mock/utils.ts +0 -9
  111. package/template-mobile-vant-cli/postcss.config.cjs +0 -8
  112. package/template-mobile-vant-cli/prettier.config.cjs +0 -18
  113. package/template-mobile-vant-cli/public/js/flexible.js +0 -44
  114. package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
  115. package/template-mobile-vant-cli/src/design/vant.less +0 -2
  116. package/template-mobile-vant-cli/src/global.less +0 -1
  117. package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
  118. package/template-mobile-vant-cli/src/router/routes.ts +0 -20
  119. package/template-mobile-vant-cli/src/router/typings.ts +0 -8
  120. package/template-mobile-vant-cli/src/settings/index.ts +0 -10
  121. package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
  122. package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
  123. package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
  124. /package/template-mobile-vant-cli/{mock/datasSource/api/index.ts → src/design/vant/index.less} +0 -0
@@ -0,0 +1,74 @@
1
+ <script setup lang="ts">
2
+ import { reactive } from 'vue'
3
+
4
+ interface UserState {
5
+ userName: string
6
+ password: string
7
+ }
8
+
9
+ const { user } = useStore()
10
+ const router = useRouter()
11
+
12
+ const loading = ref(false)
13
+
14
+ const userForm = reactive<UserState>({
15
+ userName: 'admin',
16
+ password: 'gx.design'
17
+ })
18
+
19
+ const userRules = reactive({
20
+ userName: [ { required: true, message: '用户名是必填项!' } ],
21
+ password: [ { required: true, message: '密码是必填项!' } ]
22
+ })
23
+
24
+ const handleSubmit = async () => {
25
+ const response = await user.userLogin(toRaw(userForm))
26
+ if (response) {
27
+ router.push({ path: '/' })
28
+ }
29
+ }
30
+ </script>
31
+
32
+ <template>
33
+ <div class="h-100vh w-full flex flex-col items-center pt-150">
34
+ <img class="h-40" src="@/assets/logo.png" alt="logo">
35
+ <div class="mt-50 w-75%">
36
+ <van-form validate-trigger="onSubmit">
37
+ <div class="overflow-hidden rounded-3xl">
38
+ <van-field
39
+ v-model="userForm.userName"
40
+ :rules="userRules.userName"
41
+ name="userName"
42
+ placeholder="用户名: admin"
43
+ />
44
+ </div>
45
+
46
+ <div class="mt-24 overflow-hidden rounded-3xl">
47
+ <van-field
48
+ v-model="userForm.password"
49
+ type="password"
50
+ :rules="userRules.password"
51
+ name="password"
52
+ placeholder="密码: gx.design"
53
+ />
54
+ </div>
55
+
56
+ <div class="mt-24">
57
+ <van-button
58
+ :loading="loading"
59
+ type="primary"
60
+ native-type="submit"
61
+ round
62
+ block
63
+ @click="handleSubmit"
64
+ >
65
+ 登录
66
+ </van-button>
67
+ </div>
68
+ </van-form>
69
+ </div>
70
+ </div>
71
+ </template>
72
+
73
+ <style scoped lang="less">
74
+ </style>
@@ -0,0 +1,3 @@
1
+ import dayjs from 'dayjs'
2
+
3
+ dayjs.locale('zh-cn')
@@ -0,0 +1,2 @@
1
+ // 加载插件
2
+ import.meta.glob('./**/*.ts', { eager: true })
@@ -0,0 +1,18 @@
1
+ import type { MenuDataItem } from '@gx-design-vue/pro-layout'
2
+ import type { Router } from 'vue-router'
3
+ import getPageTitle from '@/utils/pageTitle'
4
+ import { createPermissionGuard } from './permissions'
5
+ import { createStateGuard } from './stateGuard'
6
+
7
+ export function setupRouterGuard(router: Router) {
8
+ createPageGuard(router)
9
+ createPermissionGuard(router)
10
+ createStateGuard(router)
11
+ }
12
+
13
+ export function createPageGuard(router: Router) {
14
+ router.afterEach((to) => {
15
+ const { meta } = to as MenuDataItem
16
+ document.title = getPageTitle(meta?.title || '')
17
+ })
18
+ }
@@ -0,0 +1,41 @@
1
+ import type { Router } from 'vue-router'
2
+ import { defaultSettings } from '@gx-config'
3
+
4
+ const { loginInterception, routesWhiteList } = defaultSettings.system
5
+
6
+ export function createPermissionGuard(router: Router) {
7
+ const userStore = useStoreUser()
8
+
9
+ router.beforeEach(async (to, _, next) => {
10
+ if (loginInterception) {
11
+ const token = userStore.accessToken
12
+ if (routesWhiteList.includes(to.path)) {
13
+ if (token) {
14
+ next({ path: '/', replace: true })
15
+ }
16
+ next()
17
+ return
18
+ }
19
+ if (!token) {
20
+ userStore.resetPermissions()
21
+ next({ path: '/user/login', replace: true })
22
+ return
23
+ }
24
+
25
+ const hasUserId = userStore.userInfo.userId
26
+
27
+ if (hasUserId) {
28
+ next()
29
+ return
30
+ }
31
+
32
+ const status = await userStore.checkUserPremission()
33
+ if (status !== 1) {
34
+ userStore.resetPermissions()
35
+ next({ path: '/user/login', replace: true })
36
+ return
37
+ }
38
+ }
39
+ next()
40
+ })
41
+ }
@@ -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
  }