@gx-design-vue/create-gx-cli 0.1.16 → 0.1.18
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/dist/index.js +62 -0
- package/index.js +3 -0
- package/package.json +24 -14
- package/bin/create-gx-cli +0 -5
- package/src/cli.js +0 -115
- package/src/git.js +0 -81
- package/src/main.js +0 -190
- package/template-mobile-vant-cli/.editorconfig +0 -19
- package/template-mobile-vant-cli/.env +0 -3
- package/template-mobile-vant-cli/.env.development +0 -17
- package/template-mobile-vant-cli/.env.pro +0 -28
- package/template-mobile-vant-cli/.env.production +0 -31
- package/template-mobile-vant-cli/.eslintignore +0 -15
- package/template-mobile-vant-cli/.prettierignore +0 -9
- package/template-mobile-vant-cli/README.md +0 -1
- package/template-mobile-vant-cli/commitlint.config.cjs +0 -32
- package/template-mobile-vant-cli/config/default/defaultSettings.ts +0 -70
- package/template-mobile-vant-cli/config/default/network.ts +0 -10
- package/template-mobile-vant-cli/config/default/proxy.ts +0 -50
- package/template-mobile-vant-cli/config/default/theme.ts +0 -3
- package/template-mobile-vant-cli/config/index.ts +0 -11
- package/template-mobile-vant-cli/eslint.config.js +0 -57
- package/template-mobile-vant-cli/index.html +0 -25
- package/template-mobile-vant-cli/internal/vite-config/generate/generateModifyVars.ts +0 -7
- package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +0 -22
- package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +0 -17
- package/template-mobile-vant-cli/internal/vite-config/util/index.ts +0 -132
- package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +0 -65
- package/template-mobile-vant-cli/internal/vite-config/vite/optimizer.ts +0 -26
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +0 -91
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/autoImport.ts +0 -28
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +0 -31
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +0 -32
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +0 -74
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +0 -14
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +0 -40
- package/template-mobile-vant-cli/mock/config/permissions.ts +0 -15
- package/template-mobile-vant-cli/mock/config/user/id.ts +0 -5
- package/template-mobile-vant-cli/mock/config/user/index.ts +0 -96
- package/template-mobile-vant-cli/mock/index.ts +0 -55
- package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +0 -22
- package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +0 -52
- package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +0 -46
- package/template-mobile-vant-cli/mock/utils/crypto.ts +0 -21
- package/template-mobile-vant-cli/mock/utils/table.ts +0 -96
- package/template-mobile-vant-cli/mock/utils/util.ts +0 -91
- package/template-mobile-vant-cli/package.json +0 -74
- package/template-mobile-vant-cli/public/css/default.css +0 -54
- package/template-mobile-vant-cli/public/favicon.ico +0 -0
- package/template-mobile-vant-cli/src/App.vue +0 -9
- package/template-mobile-vant-cli/src/assets/logo.png +0 -0
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +0 -29
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +0 -207
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +0 -17
- package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +0 -45
- package/template-mobile-vant-cli/src/core/gx-design/index.ts +0 -7
- package/template-mobile-vant-cli/src/core/index.ts +0 -5
- package/template-mobile-vant-cli/src/design/color.less +0 -1
- package/template-mobile-vant-cli/src/design/config.less +0 -5
- package/template-mobile-vant-cli/src/design/index.less +0 -3
- package/template-mobile-vant-cli/src/design/mixin.less +0 -65
- package/template-mobile-vant-cli/src/design/reset.less +0 -39
- package/template-mobile-vant-cli/src/design/root.less +0 -3
- package/template-mobile-vant-cli/src/design/vant/index.less +0 -0
- package/template-mobile-vant-cli/src/hooks/web/index.ts +0 -5
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +0 -56
- package/template-mobile-vant-cli/src/layout/BasicLayout/index.vue +0 -18
- package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +0 -3
- package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +0 -18
- package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +0 -36
- package/template-mobile-vant-cli/src/main.ts +0 -34
- package/template-mobile-vant-cli/src/pages/Account/details.vue +0 -13
- package/template-mobile-vant-cli/src/pages/Account/index.vue +0 -102
- package/template-mobile-vant-cli/src/pages/Home/index.vue +0 -71
- package/template-mobile-vant-cli/src/pages/user/login/index.vue +0 -74
- package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +0 -3
- package/template-mobile-vant-cli/src/plugins/index.ts +0 -2
- package/template-mobile-vant-cli/src/router/guard/index.ts +0 -18
- package/template-mobile-vant-cli/src/router/guard/permissions.ts +0 -41
- package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +0 -10
- package/template-mobile-vant-cli/src/router/index.ts +0 -31
- package/template-mobile-vant-cli/src/router/routes/index.ts +0 -46
- package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +0 -32
- package/template-mobile-vant-cli/src/services/index.ts +0 -31
- package/template-mobile-vant-cli/src/services/userCenter/account.ts +0 -42
- package/template-mobile-vant-cli/src/services/userCenter/index.ts +0 -28
- package/template-mobile-vant-cli/src/store/index.ts +0 -20
- package/template-mobile-vant-cli/src/store/modules/global.ts +0 -23
- package/template-mobile-vant-cli/src/store/modules/user.ts +0 -107
- package/template-mobile-vant-cli/src/utils/accessToken.ts +0 -97
- package/template-mobile-vant-cli/src/utils/crypto/index.ts +0 -56
- package/template-mobile-vant-cli/src/utils/env.ts +0 -50
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +0 -20
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +0 -137
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +0 -69
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +0 -25
- package/template-mobile-vant-cli/src/utils/request/index.ts +0 -155
- package/template-mobile-vant-cli/src/utils/request/typings.ts +0 -171
- package/template-mobile-vant-cli/src/utils/storage.ts +0 -215
- package/template-mobile-vant-cli/src/utils/util.ts +0 -27
- package/template-mobile-vant-cli/src/utils/validate.ts +0 -211
- package/template-mobile-vant-cli/tsconfig.json +0 -50
- package/template-mobile-vant-cli/types/auto-imports.d.ts +0 -80
- package/template-mobile-vant-cli/types/components.d.ts +0 -7
- package/template-mobile-vant-cli/types/config.d.ts +0 -56
- package/template-mobile-vant-cli/types/global.d.ts +0 -80
- package/template-mobile-vant-cli/types/mock.d.ts +0 -34
- package/template-mobile-vant-cli/types/module.d.ts +0 -53
- package/template-mobile-vant-cli/types/response.d.ts +0 -17
- package/template-mobile-vant-cli/types/system.d.ts +0 -58
- package/template-mobile-vant-cli/types/vant-import.d.ts +0 -24
- package/template-mobile-vant-cli/unocss.config.ts +0 -155
- package/template-mobile-vant-cli/vite.config.ts +0 -142
- package/template-mobile-vant-html/README.md +0 -4
- package/template-mobile-vant-html/css/global.css +0 -293
- package/template-mobile-vant-html/css/global.css.map +0 -1
- package/template-mobile-vant-html/css/global.less +0 -293
- package/template-mobile-vant-html/css/index.css +0 -20
- package/template-mobile-vant-html/css/index.css.map +0 -1
- package/template-mobile-vant-html/css/index.less +0 -21
- package/template-mobile-vant-html/image/disconnected.svg +0 -60
- package/template-mobile-vant-html/image/empty.svg +0 -52
- package/template-mobile-vant-html/image/error.svg +0 -53
- package/template-mobile-vant-html/image/loading.svg +0 -1
- package/template-mobile-vant-html/index.html +0 -91
- package/template-mobile-vant-html/js/index.js +0 -29
- package/template-mobile-vant-html/js/plugin/day.min.js +0 -1
- package/template-mobile-vant-html/js/plugin/fastclick.js +0 -730
- package/template-mobile-vant-html/js/plugin/jquery.min.js +0 -2
- package/template-mobile-vant-html/js/plugin/rem.js +0 -28
- package/template-mobile-vant-html/js/utils/appUtil.js +0 -70
- package/template-mobile-vant-html/js/utils/config.js +0 -3
- package/template-mobile-vant-html/js/utils/request.js +0 -61
- package/template-mobile-vant-html/js/utils/utils.js +0 -65
- package/template-mobile-vant-html/js/utils/validate.js +0 -292
@@ -1,46 +0,0 @@
|
|
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
|
-
]
|
@@ -1,32 +0,0 @@
|
|
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[]
|
@@ -1,31 +0,0 @@
|
|
1
|
-
import request from '@/utils/request'
|
2
|
-
|
3
|
-
// get 请求
|
4
|
-
export function getMock(params) {
|
5
|
-
return request({
|
6
|
-
url: '/get/mock',
|
7
|
-
method: 'get',
|
8
|
-
isMock: true,
|
9
|
-
params
|
10
|
-
})
|
11
|
-
}
|
12
|
-
|
13
|
-
// post 请求
|
14
|
-
export function postMock(data) {
|
15
|
-
return request({
|
16
|
-
url: '/post/mock',
|
17
|
-
method: 'post',
|
18
|
-
isMock: true,
|
19
|
-
data
|
20
|
-
})
|
21
|
-
}
|
22
|
-
|
23
|
-
// formData 请求
|
24
|
-
export function formDataMock(data) {
|
25
|
-
return request({
|
26
|
-
url: '/formData/mock',
|
27
|
-
method: 'post',
|
28
|
-
isMock: true,
|
29
|
-
data
|
30
|
-
})
|
31
|
-
}
|
@@ -1,42 +0,0 @@
|
|
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
|
-
}
|
@@ -1,28 +0,0 @@
|
|
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,20 +0,0 @@
|
|
1
|
-
import type { App } from 'vue'
|
2
|
-
import { createPinia } from 'pinia'
|
3
|
-
import { useStoreGlobal } from './modules/global'
|
4
|
-
import { useStoreUser } from './modules/user'
|
5
|
-
|
6
|
-
export {
|
7
|
-
useStoreGlobal,
|
8
|
-
useStoreUser,
|
9
|
-
}
|
10
|
-
|
11
|
-
export function useStore() {
|
12
|
-
return {
|
13
|
-
user: useStoreUser(),
|
14
|
-
global: useStoreGlobal()
|
15
|
-
}
|
16
|
-
}
|
17
|
-
|
18
|
-
export function setupStore(app: App<Element>) {
|
19
|
-
app.use(createPinia())
|
20
|
-
}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
import { useReactiveState } from '@gx-design-vue/pro-hooks'
|
2
|
-
import { defineStore } from 'pinia'
|
3
|
-
|
4
|
-
/**
|
5
|
-
* @Author gx12358
|
6
|
-
* @DateTime 2022/1/11
|
7
|
-
* @lastTime 2022/1/11
|
8
|
-
* @description store-global 全局属性
|
9
|
-
*/
|
10
|
-
export interface GlobalState {
|
11
|
-
disabledScrollTop: boolean;
|
12
|
-
}
|
13
|
-
|
14
|
-
export const useStoreGlobal = defineStore('global', () => {
|
15
|
-
const [ state, setValue ] = useReactiveState<GlobalState>({
|
16
|
-
disabledScrollTop: false
|
17
|
-
})
|
18
|
-
|
19
|
-
return {
|
20
|
-
...state,
|
21
|
-
setValue
|
22
|
-
}
|
23
|
-
})
|
@@ -1,107 +0,0 @@
|
|
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
|
-
})
|
@@ -1,97 +0,0 @@
|
|
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,56 +0,0 @@
|
|
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'
|
4
|
-
import 'crypto-js/enc-utf8'
|
5
|
-
import 'crypto-js/tripledes'
|
6
|
-
import 'crypto-js/sha1'
|
7
|
-
|
8
|
-
const key = '1234123412ABCDEF' // 十六位十六进制数作为密钥
|
9
|
-
|
10
|
-
/**
|
11
|
-
* 登录密码加密
|
12
|
-
* @param password
|
13
|
-
* @returns {string}
|
14
|
-
*/
|
15
|
-
export const encodePassword = (password: string) => {
|
16
|
-
const key = CryptoProJS.enc.Utf8.parse('8QONwyJtHesysWpM')
|
17
|
-
const passwordENC = CryptoProJS.AES.encrypt(password, key, {
|
18
|
-
mode: CryptoProJS.mode.ECB,
|
19
|
-
padding: CryptoProJS.pad.Pkcs7
|
20
|
-
})
|
21
|
-
const encodePW = passwordENC.ciphertext.toString()
|
22
|
-
return encodePW
|
23
|
-
}
|
24
|
-
|
25
|
-
// 加密方法
|
26
|
-
export function Encrypt(word) {
|
27
|
-
let str: string | object = word
|
28
|
-
if (isObject(word) || isArray(word)) {
|
29
|
-
str = JSON.stringify(word)
|
30
|
-
}
|
31
|
-
const keyHex = CryptoJS.enc.Utf8.parse(key)
|
32
|
-
const ivHex = CryptoJS.enc.Utf8.parse(key)
|
33
|
-
const encrypted = CryptoJS.DES.encrypt(str, keyHex, {
|
34
|
-
iv: ivHex,
|
35
|
-
mode: CryptoJS.mode.CBC,
|
36
|
-
padding: CryptoJS.pad.Pkcs7
|
37
|
-
})
|
38
|
-
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
|
39
|
-
}
|
40
|
-
|
41
|
-
// 解密方法
|
42
|
-
export function Decrypt(word) {
|
43
|
-
const keyHex = CryptoJS.enc.Utf8.parse(key)
|
44
|
-
const ivHex = CryptoJS.enc.Utf8.parse(key)
|
45
|
-
const decrypted = CryptoJS.DES.decrypt({
|
46
|
-
ciphertext: CryptoJS.enc.Base64.parse(word)
|
47
|
-
}, keyHex, {
|
48
|
-
iv: ivHex,
|
49
|
-
mode: CryptoJS.mode.CBC,
|
50
|
-
padding: CryptoJS.pad.Pkcs7
|
51
|
-
})
|
52
|
-
const decryptedStr = decrypted.toString(CryptoJS.enc.Utf8)
|
53
|
-
return isJSONStr(decryptedStr.toString())
|
54
|
-
? JSON.parse(decryptedStr.toString())
|
55
|
-
: decryptedStr.toString()
|
56
|
-
}
|
@@ -1,50 +0,0 @@
|
|
1
|
-
/**
|
2
|
-
* @Author gx12358
|
3
|
-
* @DateTime 2022/4/1
|
4
|
-
* @lastTime 2022/4/1
|
5
|
-
* @description 环境:本地开发环境
|
6
|
-
*/
|
7
|
-
export function isDev(): boolean {
|
8
|
-
return typeViteEnv('VITE_APP_ENV') === 'dev'
|
9
|
-
}
|
10
|
-
|
11
|
-
/**
|
12
|
-
* @Author gx12358
|
13
|
-
* @DateTime 2022/4/1
|
14
|
-
* @lastTime 2022/4/1
|
15
|
-
* @description 环境:正式
|
16
|
-
*/
|
17
|
-
export function isPro(): boolean {
|
18
|
-
return typeViteEnv('VITE_USE_MODE') === 'pro'
|
19
|
-
}
|
20
|
-
|
21
|
-
/**
|
22
|
-
* @Author gx12358
|
23
|
-
* @DateTime 2022/4/1
|
24
|
-
* @lastTime 2022/4/1
|
25
|
-
* @description 环境:非开发环境
|
26
|
-
*/
|
27
|
-
export function isBuild(): boolean {
|
28
|
-
return typeViteEnv('VITE_APP_ENV') !== 'dev'
|
29
|
-
}
|
30
|
-
|
31
|
-
/**
|
32
|
-
* @Author gx12358
|
33
|
-
* @DateTime 2022/4/1
|
34
|
-
* @lastTime 2022/4/1
|
35
|
-
* @description 当前联调环境
|
36
|
-
*/
|
37
|
-
export function currentMode() {
|
38
|
-
return typeViteEnv('VITE_USE_MODE')
|
39
|
-
}
|
40
|
-
|
41
|
-
export function typeViteEnv<T extends keyof ViteEnv>(key: T): ViteEnv[T] | undefined {
|
42
|
-
let value: any = (import.meta as any).env[key]
|
43
|
-
|
44
|
-
if (value && typeof value === 'string') {
|
45
|
-
value = value.replace(/\\n/g, '\n') as ViteEnv[T]
|
46
|
-
value = value === 'true' ? true : value === 'false' ? false : value
|
47
|
-
}
|
48
|
-
|
49
|
-
return value
|
50
|
-
}
|
@@ -1,20 +0,0 @@
|
|
1
|
-
import { defaultSettings } from '@gx-config'
|
2
|
-
|
3
|
-
const { title, titleReverse, titleSeparator } = defaultSettings.system
|
4
|
-
|
5
|
-
/**
|
6
|
-
* @Author gx12358
|
7
|
-
* @DateTime 2024/9/20
|
8
|
-
* @lastTime 2024/9/20
|
9
|
-
* @description 设置标题
|
10
|
-
*/
|
11
|
-
export default function getPageTitle(pageTitle: string) {
|
12
|
-
let newTitles: string[] = []
|
13
|
-
if (pageTitle)
|
14
|
-
newTitles.push(pageTitle)
|
15
|
-
if (title)
|
16
|
-
newTitles.push(title)
|
17
|
-
if (titleReverse)
|
18
|
-
newTitles = newTitles.reverse()
|
19
|
-
return newTitles.join(titleSeparator)
|
20
|
-
}
|
@@ -1,137 +0,0 @@
|
|
1
|
-
import type { AxiosError } from 'axios'
|
2
|
-
import type { GAxiosInstance, GAxiosOptions, GAxiosResponse } from './typings'
|
3
|
-
import { isFunction } from '@gx-design-vue/pro-utils'
|
4
|
-
import axios from 'axios'
|
5
|
-
import { cloneDeep } from 'lodash-es'
|
6
|
-
import qs from 'qs'
|
7
|
-
import { AxiosCanceler } from './axiosCancel'
|
8
|
-
import { ContentTypeEnum, RequestEnum } from './typings'
|
9
|
-
|
10
|
-
/**
|
11
|
-
* @Author gx12358
|
12
|
-
* @DateTime 2023/1/6
|
13
|
-
* @lastTime 2023/1/6
|
14
|
-
* @description 重新定义axios
|
15
|
-
*/
|
16
|
-
export class GAxios {
|
17
|
-
private axiosInstance: GAxiosInstance
|
18
|
-
private readonly options: GAxiosOptions
|
19
|
-
|
20
|
-
constructor(options: GAxiosOptions) {
|
21
|
-
this.options = options
|
22
|
-
this.axiosInstance = axios.create(options) as GAxiosInstance
|
23
|
-
this.setupInterceptors()
|
24
|
-
}
|
25
|
-
|
26
|
-
/**
|
27
|
-
* @description: Interceptor configuration 拦截器配置
|
28
|
-
*/
|
29
|
-
private setupInterceptors() {
|
30
|
-
const {
|
31
|
-
requestInterceptors,
|
32
|
-
requestInterceptorsCatch,
|
33
|
-
responseInterceptors,
|
34
|
-
responseInterceptorsCatch
|
35
|
-
} = this.options
|
36
|
-
|
37
|
-
const axiosCanceler = new AxiosCanceler(this.options.ignoreCancelToken)
|
38
|
-
|
39
|
-
this.axiosInstance.interceptors.request.use<GAxiosOptions>((config) => {
|
40
|
-
const { cancelCallBackHook } = config
|
41
|
-
axiosCanceler.addPending(config)
|
42
|
-
if (cancelCallBackHook) {
|
43
|
-
cancelCallBackHook({
|
44
|
-
reset: axiosCanceler.reset,
|
45
|
-
cancel: (key?: string) => axiosCanceler.removePending(config, key),
|
46
|
-
cancelAll: axiosCanceler.removeAllPending
|
47
|
-
})
|
48
|
-
}
|
49
|
-
if (requestInterceptors && isFunction(requestInterceptors)) {
|
50
|
-
config = requestInterceptors(config)
|
51
|
-
}
|
52
|
-
return config
|
53
|
-
}, undefined)
|
54
|
-
|
55
|
-
// Request interceptor error capture
|
56
|
-
requestInterceptorsCatch && isFunction(requestInterceptorsCatch) && this.axiosInstance.interceptors.request.use(
|
57
|
-
undefined,
|
58
|
-
requestInterceptorsCatch
|
59
|
-
)
|
60
|
-
|
61
|
-
// Response result interceptor processing
|
62
|
-
this.axiosInstance.interceptors.response.use((res: GAxiosResponse) => {
|
63
|
-
res && axiosCanceler.removePending(res.config)
|
64
|
-
if (responseInterceptors && isFunction(responseInterceptors)) {
|
65
|
-
return responseInterceptors(res)
|
66
|
-
}
|
67
|
-
return res
|
68
|
-
}, undefined)
|
69
|
-
|
70
|
-
// Response result interceptor error capture
|
71
|
-
responseInterceptorsCatch && isFunction(responseInterceptorsCatch) && this.axiosInstance.interceptors.response.use(
|
72
|
-
undefined,
|
73
|
-
(error) => {
|
74
|
-
axiosCanceler.removePending(error.config)
|
75
|
-
|
76
|
-
return responseInterceptorsCatch(this.axiosInstance, error)
|
77
|
-
}
|
78
|
-
)
|
79
|
-
}
|
80
|
-
|
81
|
-
// support form-data
|
82
|
-
supportFormData(config: GAxiosOptions) {
|
83
|
-
const headers = config.headers || this.options.headers
|
84
|
-
const contentType = headers?.['Content-Type'] || headers?.['content-type']
|
85
|
-
|
86
|
-
if (contentType !== ContentTypeEnum.FORM_URLENCODED || !Reflect.has(
|
87
|
-
config,
|
88
|
-
'data'
|
89
|
-
) || config.method?.toUpperCase() === RequestEnum.GET) {
|
90
|
-
return config
|
91
|
-
}
|
92
|
-
|
93
|
-
return {
|
94
|
-
...config,
|
95
|
-
data: qs.stringify(config.data, { arrayFormat: 'brackets' })
|
96
|
-
}
|
97
|
-
}
|
98
|
-
|
99
|
-
request<T = ResponseResult | boolean>(config?: GAxiosOptions): Promise<T> {
|
100
|
-
let conf = cloneDeep(config || {} as GAxiosOptions)
|
101
|
-
|
102
|
-
const opt: GAxiosOptions = Object.assign({}, this.options, conf)
|
103
|
-
|
104
|
-
const { beforeRequestHook, requestCatchHook, transformResponseHook } = opt
|
105
|
-
if (beforeRequestHook && isFunction(beforeRequestHook)) {
|
106
|
-
conf = beforeRequestHook(opt)
|
107
|
-
}
|
108
|
-
|
109
|
-
conf = this.supportFormData(opt)
|
110
|
-
|
111
|
-
return new Promise((resolve) => {
|
112
|
-
this.axiosInstance
|
113
|
-
.request<any, GAxiosResponse>(conf)
|
114
|
-
.then((res: GAxiosResponse) => {
|
115
|
-
if (transformResponseHook && isFunction(transformResponseHook)) {
|
116
|
-
try {
|
117
|
-
const ret = transformResponseHook(res, config || {})
|
118
|
-
resolve(ret)
|
119
|
-
} catch (error) {
|
120
|
-
console.error('request-error', error)
|
121
|
-
resolve(false as unknown as Promise<T>)
|
122
|
-
return
|
123
|
-
}
|
124
|
-
return
|
125
|
-
}
|
126
|
-
resolve(res as unknown as Promise<T>)
|
127
|
-
})
|
128
|
-
.catch((e: Error | AxiosError) => {
|
129
|
-
if (requestCatchHook && isFunction(requestCatchHook)) {
|
130
|
-
resolve(requestCatchHook(e) as any)
|
131
|
-
return
|
132
|
-
}
|
133
|
-
resolve(false as any)
|
134
|
-
})
|
135
|
-
})
|
136
|
-
}
|
137
|
-
}
|