@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.
- package/package.json +1 -1
- package/src/main.js +7 -7
- package/template-mobile-vant-cli/.env +3 -0
- package/template-mobile-vant-cli/.env.development +4 -6
- package/template-mobile-vant-cli/.env.pro +16 -7
- package/template-mobile-vant-cli/.env.production +21 -9
- package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
- package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
- package/template-mobile-vant-cli/config/default/network.ts +10 -0
- package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
- package/template-mobile-vant-cli/config/default/theme.ts +3 -0
- package/template-mobile-vant-cli/config/index.ts +11 -0
- package/template-mobile-vant-cli/eslint.config.js +10 -2
- package/template-mobile-vant-cli/index.html +22 -21
- package/template-mobile-vant-cli/{build → internal/vite-config/generate}/generateModifyVars.ts +1 -1
- package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
- package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
- package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
- package/template-mobile-vant-cli/{build → internal/vite-config/vite}/optimizer.ts +9 -1
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
- package/template-mobile-vant-cli/{build → internal/vite-config/vite}/plugin/autoImport.ts +7 -3
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
- package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
- package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
- package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
- package/template-mobile-vant-cli/mock/index.ts +55 -0
- package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
- package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
- package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
- package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
- package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
- package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
- package/template-mobile-vant-cli/package.json +51 -34
- package/template-mobile-vant-cli/public/css/default.css +54 -0
- package/template-mobile-vant-cli/src/App.vue +6 -2
- package/template-mobile-vant-cli/src/assets/logo.png +0 -0
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -1
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +108 -16
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +5 -2
- package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
- package/template-mobile-vant-cli/src/core/gx-design/index.ts +1 -1
- package/template-mobile-vant-cli/src/core/index.ts +0 -7
- package/template-mobile-vant-cli/src/design/color.less +1 -0
- package/template-mobile-vant-cli/src/design/config.less +5 -0
- package/template-mobile-vant-cli/src/design/index.less +1 -1
- package/template-mobile-vant-cli/src/design/mixin.less +65 -0
- package/template-mobile-vant-cli/src/design/reset.less +16 -132
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +7 -9
- package/template-mobile-vant-cli/src/layout/{BasicLayout.vue → BasicLayout/index.vue} +3 -1
- package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
- package/template-mobile-vant-cli/src/main.ts +16 -9
- package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
- package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
- package/template-mobile-vant-cli/src/pages/{home.vue → Home/index.vue} +5 -5
- package/template-mobile-vant-cli/src/pages/user/login/index.vue +74 -0
- package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
- package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
- package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
- package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
- package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
- package/template-mobile-vant-cli/src/router/index.ts +21 -15
- package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
- package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
- package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
- package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
- package/template-mobile-vant-cli/src/store/index.ts +4 -1
- package/template-mobile-vant-cli/src/store/modules/global.ts +6 -13
- package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
- package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
- package/template-mobile-vant-cli/src/utils/crypto/index.ts +3 -4
- package/template-mobile-vant-cli/src/utils/env.ts +2 -2
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +12 -6
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +9 -11
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +5 -5
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +18 -2
- package/template-mobile-vant-cli/src/utils/request/index.ts +36 -23
- package/template-mobile-vant-cli/src/utils/storage.ts +49 -32
- package/template-mobile-vant-cli/src/utils/validate.ts +31 -36
- package/template-mobile-vant-cli/tsconfig.json +17 -9
- package/template-mobile-vant-cli/types/auto-imports.d.ts +18 -2
- package/template-mobile-vant-cli/types/components.d.ts +2 -7
- package/template-mobile-vant-cli/types/config.d.ts +56 -0
- package/template-mobile-vant-cli/types/global.d.ts +62 -21
- package/template-mobile-vant-cli/types/mock.d.ts +34 -0
- package/template-mobile-vant-cli/types/module.d.ts +33 -0
- package/template-mobile-vant-cli/types/response.d.ts +3 -1
- package/template-mobile-vant-cli/types/system.d.ts +58 -0
- package/template-mobile-vant-cli/types/vant-import.d.ts +16 -5
- package/template-mobile-vant-cli/unocss.config.ts +120 -66
- package/template-mobile-vant-cli/vite.config.ts +78 -81
- package/template-mobile-vant-cli/build/cdn.ts +0 -5
- package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
- package/template-mobile-vant-cli/build/plugin/index.ts +0 -42
- package/template-mobile-vant-cli/build/plugin/mock.ts +0 -14
- package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +0 -88
- package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +0 -271
- package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +0 -69
- package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +0 -48
- package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +0 -48
- package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
- package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
- package/template-mobile-vant-cli/mock/utils.ts +0 -9
- package/template-mobile-vant-cli/postcss.config.cjs +0 -8
- package/template-mobile-vant-cli/prettier.config.cjs +0 -18
- package/template-mobile-vant-cli/public/js/flexible.js +0 -44
- package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
- package/template-mobile-vant-cli/src/design/vant.less +0 -2
- package/template-mobile-vant-cli/src/global.less +0 -1
- package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
- package/template-mobile-vant-cli/src/router/routes.ts +0 -20
- package/template-mobile-vant-cli/src/router/typings.ts +0 -8
- package/template-mobile-vant-cli/src/settings/index.ts +0 -10
- package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
- package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
- package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
- /package/template-mobile-vant-cli/{mock/datasSource/api/index.ts → src/design/vant/index.less} +0 -0
@@ -1,25 +1,31 @@
|
|
1
1
|
import type { App } from 'vue'
|
2
2
|
import type { RouteRecordRaw } from 'vue-router'
|
3
|
-
import {
|
4
|
-
import
|
5
|
-
import
|
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
|
-
|
9
|
-
history: createWebHashHistory(),
|
10
|
-
routes: constantRoutes as unknown as RouteRecordRaw[]
|
11
|
-
})
|
7
|
+
const { routerMode } = defaultSettings.system
|
12
8
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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 {
|
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
|
-
|
11
|
+
disabledScrollTop: boolean;
|
13
12
|
}
|
14
13
|
|
15
|
-
type GlobalStateKey = keyof GlobalState
|
16
|
-
|
17
14
|
export const useStoreGlobal = defineStore('global', () => {
|
18
|
-
const state =
|
19
|
-
|
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
|
-
...
|
28
|
-
|
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('
|
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
|
-
* @
|
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(
|
8
|
-
|
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
|
-
|
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
|
103
|
-
let conf
|
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 (
|
123
|
-
|
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 {
|
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 {
|
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 = (
|
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
|
}
|