@gx-design-vue/create-gx-cli 0.1.2 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +4 -11
- package/package.json +3 -2
- package/src/main.js +9 -3
- package/template-mobile-vant-cli/.env +0 -0
- package/template-mobile-vant-cli/.env.pro +1 -1
- package/template-mobile-vant-cli/.env.production +2 -2
- package/template-mobile-vant-cli/.eslintignore +0 -1
- package/template-mobile-vant-cli/build/plugin/autoImport.ts +8 -10
- package/template-mobile-vant-cli/build/plugin/index.ts +2 -10
- package/template-mobile-vant-cli/build/plugin/mock.ts +5 -11
- package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +88 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +271 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +69 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +48 -0
- package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +48 -0
- package/template-mobile-vant-cli/eslint.config.js +49 -0
- package/template-mobile-vant-cli/mock/_createProductionServer.ts +4 -4
- package/template-mobile-vant-cli/mock/datasSource/api/index.ts +0 -0
- package/template-mobile-vant-cli/package.json +26 -33
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -2
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +7 -6
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +1 -1
- package/template-mobile-vant-cli/src/core/vant-design/index.ts +1 -1
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +8 -5
- package/template-mobile-vant-cli/src/layout/BasicLayout.vue +3 -3
- package/template-mobile-vant-cli/src/pages/home.vue +27 -27
- package/template-mobile-vant-cli/src/router/index.ts +3 -2
- package/template-mobile-vant-cli/src/router/typings.ts +1 -1
- package/template-mobile-vant-cli/src/settings/index.ts +2 -2
- package/template-mobile-vant-cli/src/store/modules/global.ts +1 -1
- package/template-mobile-vant-cli/src/utils/crypto/base64.ts +101 -0
- package/template-mobile-vant-cli/src/utils/{cryptoJS.ts → crypto/index.ts} +23 -5
- package/template-mobile-vant-cli/src/utils/env.ts +15 -17
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +5 -3
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +38 -30
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +32 -23
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +1 -3
- package/template-mobile-vant-cli/src/utils/request/index.ts +3 -4
- package/template-mobile-vant-cli/src/utils/request/typings.ts +74 -17
- package/template-mobile-vant-cli/src/utils/storage.ts +25 -18
- package/template-mobile-vant-cli/src/utils/util.ts +0 -5
- package/template-mobile-vant-cli/src/utils/validate.ts +191 -3
- package/template-mobile-vant-cli/tsconfig.json +8 -9
- package/template-mobile-vant-cli/types/{gx-components.d.ts → ant-design-import.d.ts} +3 -3
- package/template-mobile-vant-cli/types/auto-imports.d.ts +3 -0
- package/template-mobile-vant-cli/types/components.d.ts +2 -5
- package/template-mobile-vant-cli/types/global.d.ts +7 -4
- package/template-mobile-vant-cli/types/module.d.ts +15 -2
- package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +14 -0
- package/template-mobile-vant-cli/types/response.d.ts +8 -5
- package/template-mobile-vant-cli/types/vant-import.d.ts +13 -0
- package/template-mobile-vant-cli/unocss.config.ts +101 -0
- package/template-mobile-vant-cli/vite.config.ts +43 -11
- package/template-mobile-vant-cli/.eslintrc.js +0 -64
- package/template-mobile-vant-cli/.stylelintignore +0 -3
- package/template-mobile-vant-cli/mock/api/index.ts +0 -66
- package/template-mobile-vant-cli/stylelint.config.js +0 -106
- /package/template-mobile-vant-cli/{postcss.config.js → postcss.config.cjs} +0 -0
- /package/template-mobile-vant-cli/{prettier.config.js → prettier.config.cjs} +0 -0
@@ -5,8 +5,10 @@
|
|
5
5
|
* @returns {string}
|
6
6
|
*/
|
7
7
|
export default function getPageTitle(title: string, pageTitle: string) {
|
8
|
-
|
9
|
-
if (pageTitle)
|
10
|
-
|
8
|
+
const newTitles: string[] = []
|
9
|
+
if (pageTitle)
|
10
|
+
newTitles.push(pageTitle)
|
11
|
+
if (title)
|
12
|
+
newTitles.push(title)
|
11
13
|
return newTitles.join('-')
|
12
14
|
}
|
@@ -1,12 +1,15 @@
|
|
1
|
-
import type {
|
1
|
+
import type { AxiosError } from 'axios'
|
2
2
|
import axios from 'axios'
|
3
|
-
import {
|
3
|
+
import { cloneDeep } from 'lodash-es'
|
4
4
|
import qs from 'qs'
|
5
5
|
import { isFunction } from '@gx-design-vue/pro-utils'
|
6
|
-
import type { GAxiosInstance, GAxiosOptions } from './typings'
|
6
|
+
import type { GAxiosInstance, GAxiosOptions, GAxiosResponse } from './typings'
|
7
7
|
import { ContentTypeEnum, RequestEnum } from './typings'
|
8
8
|
import { AxiosCanceler } from './axiosCancel'
|
9
9
|
|
10
|
+
export const getPendingUrl = (config: GAxiosOptions) => config.cancelKey || [ config.method, config.url ].join(
|
11
|
+
'&')
|
12
|
+
|
10
13
|
/**
|
11
14
|
* @Author gx12358
|
12
15
|
* @DateTime 2023/1/6
|
@@ -19,7 +22,7 @@ export class GAxios {
|
|
19
22
|
|
20
23
|
constructor(options: GAxiosOptions) {
|
21
24
|
this.options = options
|
22
|
-
this.axiosInstance = axios.create(options)
|
25
|
+
this.axiosInstance = axios.create(options) as GAxiosInstance
|
23
26
|
this.setupInterceptors()
|
24
27
|
}
|
25
28
|
|
@@ -34,16 +37,18 @@ export class GAxios {
|
|
34
37
|
responseInterceptorsCatch
|
35
38
|
} = this.options
|
36
39
|
|
37
|
-
const axiosCanceler = new AxiosCanceler()
|
38
|
-
|
39
|
-
this.axiosInstance.interceptors.request.use((config: GAxiosOptions) => {
|
40
|
-
const { ignoreCancelToken } = config
|
41
|
-
const ignoreCancel =
|
42
|
-
ignoreCancelToken !== undefined
|
43
|
-
? ignoreCancelToken
|
44
|
-
: this.options?.ignoreCancelToken
|
40
|
+
const axiosCanceler = new AxiosCanceler(this.options.ignoreCancelToken)
|
45
41
|
|
46
|
-
|
42
|
+
this.axiosInstance.interceptors.request.use<GAxiosOptions>((config) => {
|
43
|
+
const { cancelCallBackHook } = config
|
44
|
+
axiosCanceler.addPending(config)
|
45
|
+
if (cancelCallBackHook) {
|
46
|
+
cancelCallBackHook({
|
47
|
+
reset: axiosCanceler.reset,
|
48
|
+
cancel: (key?: string) => axiosCanceler.removePending(config, key),
|
49
|
+
cancelAll: axiosCanceler.removeAllPending
|
50
|
+
})
|
51
|
+
}
|
47
52
|
if (requestInterceptors && isFunction(requestInterceptors)) {
|
48
53
|
config = requestInterceptors(config)
|
49
54
|
}
|
@@ -51,12 +56,13 @@ export class GAxios {
|
|
51
56
|
}, undefined)
|
52
57
|
|
53
58
|
// Request interceptor error capture
|
54
|
-
requestInterceptorsCatch &&
|
55
|
-
|
56
|
-
|
59
|
+
requestInterceptorsCatch && isFunction(requestInterceptorsCatch) && this.axiosInstance.interceptors.request.use(
|
60
|
+
undefined,
|
61
|
+
requestInterceptorsCatch
|
62
|
+
)
|
57
63
|
|
58
64
|
// Response result interceptor processing
|
59
|
-
this.axiosInstance.interceptors.response.use((res:
|
65
|
+
this.axiosInstance.interceptors.response.use((res: GAxiosResponse) => {
|
60
66
|
res && axiosCanceler.removePending(res.config)
|
61
67
|
if (responseInterceptors && isFunction(responseInterceptors)) {
|
62
68
|
return responseInterceptors(res)
|
@@ -65,11 +71,14 @@ export class GAxios {
|
|
65
71
|
}, undefined)
|
66
72
|
|
67
73
|
// Response result interceptor error capture
|
68
|
-
responseInterceptorsCatch &&
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
74
|
+
responseInterceptorsCatch && isFunction(responseInterceptorsCatch) && this.axiosInstance.interceptors.response.use(
|
75
|
+
undefined,
|
76
|
+
(error) => {
|
77
|
+
axiosCanceler.removePending(error.config)
|
78
|
+
|
79
|
+
return responseInterceptorsCatch(this.axiosInstance, error)
|
80
|
+
}
|
81
|
+
)
|
73
82
|
}
|
74
83
|
|
75
84
|
// support form-data
|
@@ -77,11 +86,10 @@ export class GAxios {
|
|
77
86
|
const headers = config.headers || this.options.headers
|
78
87
|
const contentType = headers?.['Content-Type'] || headers?.['content-type']
|
79
88
|
|
80
|
-
if (
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
) {
|
89
|
+
if (contentType !== ContentTypeEnum.FORM_URLENCODED || !Reflect.has(
|
90
|
+
config,
|
91
|
+
'data'
|
92
|
+
) || config.method?.toUpperCase() === RequestEnum.GET) {
|
85
93
|
return config
|
86
94
|
}
|
87
95
|
|
@@ -92,7 +100,7 @@ export class GAxios {
|
|
92
100
|
}
|
93
101
|
|
94
102
|
request<T = ResponseResult | boolean>(config: GAxiosOptions): Promise<T> {
|
95
|
-
let conf: GAxiosOptions =
|
103
|
+
let conf: GAxiosOptions = cloneDeep(config)
|
96
104
|
|
97
105
|
const opt: GAxiosOptions = Object.assign({}, this.options, conf)
|
98
106
|
|
@@ -105,8 +113,8 @@ export class GAxios {
|
|
105
113
|
|
106
114
|
return new Promise((resolve) => {
|
107
115
|
this.axiosInstance
|
108
|
-
.request<any,
|
109
|
-
.then((res:
|
116
|
+
.request<any, GAxiosResponse>(conf)
|
117
|
+
.then((res: GAxiosResponse) => {
|
110
118
|
if (transformResponseHook && isFunction(transformResponseHook)) {
|
111
119
|
try {
|
112
120
|
const ret = transformResponseHook(res, config)
|
@@ -1,53 +1,62 @@
|
|
1
|
-
import type {
|
1
|
+
import type { Canceler } from 'axios'
|
2
2
|
import axios from 'axios'
|
3
3
|
import { isFunction } from '@gx-design-vue/pro-utils'
|
4
|
+
import type { GAxiosOptions } from './typings'
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
export const getPendingUrl = (
|
7
|
+
config: GAxiosOptions,
|
8
|
+
key?: string
|
9
|
+
) => key || config.cancelKey || [ config.method, config.url ].join('&')
|
9
10
|
|
10
11
|
export class AxiosCanceler {
|
12
|
+
ignoreCancelToken: boolean
|
13
|
+
pendingMap: Map<string, Canceler>
|
14
|
+
|
15
|
+
constructor(ignoreCancel?: boolean) {
|
16
|
+
this.pendingMap = new Map<string, Canceler>()
|
17
|
+
|
18
|
+
this.ignoreCancelToken = ignoreCancel
|
19
|
+
}
|
20
|
+
|
11
21
|
/**
|
12
22
|
* Add request
|
13
23
|
* @param {Object} config
|
14
24
|
*/
|
15
|
-
addPending(config:
|
16
|
-
this.removePending(config)
|
25
|
+
addPending(config: GAxiosOptions) {
|
26
|
+
!this.ignoreCancelToken && this.removePending(config)
|
27
|
+
|
17
28
|
const url = getPendingUrl(config)
|
18
|
-
config.cancelToken =
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
}
|
25
|
-
})
|
29
|
+
config.cancelToken = config.cancelToken || new axios.CancelToken((cancel) => {
|
30
|
+
if (!this.pendingMap.has(url)) {
|
31
|
+
// If there is no current request in pending, add it
|
32
|
+
this.pendingMap.set(url, cancel)
|
33
|
+
}
|
34
|
+
})
|
26
35
|
}
|
27
36
|
|
28
37
|
/**
|
29
38
|
* @description: Clear all pending
|
30
39
|
*/
|
31
40
|
removeAllPending() {
|
32
|
-
pendingMap.forEach((cancel) => {
|
41
|
+
this.pendingMap.forEach((cancel) => {
|
33
42
|
cancel && isFunction(cancel) && cancel()
|
34
43
|
})
|
35
|
-
pendingMap.clear()
|
44
|
+
this.pendingMap.clear()
|
36
45
|
}
|
37
46
|
|
38
47
|
/**
|
39
48
|
* Removal request
|
40
49
|
* @param {Object} config
|
41
50
|
*/
|
42
|
-
removePending(config:
|
43
|
-
const url = getPendingUrl(config)
|
51
|
+
removePending(config: GAxiosOptions, key?: string) {
|
52
|
+
const url = getPendingUrl(config, key)
|
44
53
|
|
45
|
-
if (pendingMap.has(url)) {
|
54
|
+
if (this.pendingMap.has(url)) {
|
46
55
|
// If there is a current request identifier in pending,
|
47
56
|
// the current request needs to be cancelled and removed
|
48
|
-
const cancel = pendingMap.get(url)
|
57
|
+
const cancel = this.pendingMap.get(url)
|
49
58
|
cancel && cancel(url)
|
50
|
-
pendingMap.delete(url)
|
59
|
+
this.pendingMap.delete(url)
|
51
60
|
}
|
52
61
|
}
|
53
62
|
|
@@ -55,6 +64,6 @@ export class AxiosCanceler {
|
|
55
64
|
* @description: reset
|
56
65
|
*/
|
57
66
|
reset(): void {
|
58
|
-
pendingMap = new Map<string, Canceler>()
|
67
|
+
this.pendingMap = new Map<string, Canceler>()
|
59
68
|
}
|
60
69
|
}
|
@@ -1,11 +1,9 @@
|
|
1
|
-
import { showFailToast } from 'vant'
|
2
|
-
|
3
1
|
/**
|
4
2
|
* @author gx12358 2539306317@qq.com
|
5
3
|
* @description 处理code异常
|
6
4
|
* @param {*} code
|
7
5
|
* @param {*} msg
|
8
6
|
*/
|
9
|
-
export const handleCode = (
|
7
|
+
export const handleCode = (_code: number, _msg: string) => {
|
10
8
|
// 这里处理不同状态
|
11
9
|
}
|
@@ -6,9 +6,8 @@ import { tansParams } from '@/utils/util'
|
|
6
6
|
import { checkURL } from '@/utils/validate'
|
7
7
|
import { isBoolean } from '@gx-design-vue/pro-utils'
|
8
8
|
import { GAxios } from './XHR'
|
9
|
-
import type { XhtInstance } from './typings'
|
9
|
+
import type { GAxiosOptions, XhtInstance } from './typings'
|
10
10
|
import { RequestEnum } from './typings'
|
11
|
-
import type { GAxiosOptions } from './typings'
|
12
11
|
import { handleCode } from './checkStatus'
|
13
12
|
|
14
13
|
const { requestPrefix, successCode, requestTimeout, tokenName, contentType } = settings
|
@@ -122,7 +121,7 @@ const xhtInstance: XhtInstance = {
|
|
122
121
|
requestCatchHook: () => false
|
123
122
|
}
|
124
123
|
|
125
|
-
function createXhr(opt
|
124
|
+
function createXhr(opt?: Partial<GAxiosOptions>) {
|
126
125
|
return new GAxios({
|
127
126
|
method: 'get',
|
128
127
|
timeout: requestTimeout,
|
@@ -138,6 +137,6 @@ function createXhr(opt ?: Partial<GAxiosOptions>) {
|
|
138
137
|
})
|
139
138
|
}
|
140
139
|
|
141
|
-
const request: (opt?: GAxiosOptions) => Promise<ResponseResult
|
140
|
+
const request: <T = any, R = undefined>(opt?: GAxiosOptions) => Promise<ResponseResult<T, R>> = opt => createXhr().request(opt)
|
142
141
|
|
143
142
|
export default request
|
@@ -1,6 +1,27 @@
|
|
1
|
-
import type {
|
1
|
+
import type {
|
2
|
+
AxiosError,
|
3
|
+
AxiosInstance,
|
4
|
+
AxiosInterceptorManager,
|
5
|
+
AxiosInterceptorOptions,
|
6
|
+
AxiosPromise,
|
7
|
+
AxiosRequestConfig,
|
8
|
+
AxiosResponse,
|
9
|
+
InternalAxiosRequestConfig,
|
10
|
+
Method
|
11
|
+
} from 'axios'
|
12
|
+
|
13
|
+
export interface GAxiosResponse<T = any> extends Omit<AxiosResponse, 'data' | 'config'> {
|
14
|
+
data: T;
|
15
|
+
config: Omit<GAxiosOptions, 'headers'>;
|
16
|
+
}
|
17
|
+
|
18
|
+
export interface CancelOptions {
|
19
|
+
cancel: (key?: string) => void,
|
20
|
+
cancelAll: () => void;
|
21
|
+
reset: () => void
|
22
|
+
}
|
2
23
|
|
3
|
-
export
|
24
|
+
export interface XhtInstance {
|
4
25
|
/**
|
5
26
|
* @Author gx12358
|
6
27
|
* @DateTime 2023/1/6
|
@@ -9,10 +30,18 @@ export type XhtInstance = {
|
|
9
30
|
*/
|
10
31
|
beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
|
11
32
|
|
33
|
+
/**
|
34
|
+
* @Author gx12358
|
35
|
+
* @DateTime 2023/11/3
|
36
|
+
* @lastTime 2023/11/3
|
37
|
+
* @description 请求之前返回cancel函数
|
38
|
+
*/
|
39
|
+
cancelCallBackHook?: ({ cancel, cancelAll, reset }: CancelOptions) => void;
|
40
|
+
|
12
41
|
/**
|
13
42
|
* @description: 处理响应数据
|
14
43
|
*/
|
15
|
-
transformResponseHook?: (res:
|
44
|
+
transformResponseHook?: (res: GAxiosResponse, options: Partial<GAxiosOptions>) => any;
|
16
45
|
|
17
46
|
/**
|
18
47
|
* @description: 请求失败处理
|
@@ -27,69 +56,98 @@ export type XhtInstance = {
|
|
27
56
|
/**
|
28
57
|
* @description: 请求之后的拦截器
|
29
58
|
*/
|
30
|
-
responseInterceptors?: (res:
|
59
|
+
responseInterceptors?: (res: GAxiosResponse) => GAxiosResponse;
|
31
60
|
|
32
61
|
/**
|
33
62
|
* @description: 请求之前的拦截器错误处理
|
34
63
|
*/
|
35
|
-
requestInterceptorsCatch?: (error:
|
64
|
+
requestInterceptorsCatch?: (error: AxiosError) => void;
|
36
65
|
|
37
66
|
/**
|
38
67
|
* @description: 请求之后的拦截器错误处理
|
39
68
|
*/
|
40
|
-
responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error:
|
69
|
+
responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: AxiosError) => void;
|
41
70
|
}
|
42
71
|
|
43
|
-
export interface GAxiosOptions extends AxiosRequestConfig {
|
44
|
-
headers?:
|
72
|
+
export interface GAxiosOptions extends Omit<AxiosRequestConfig, 'headers' | 'method'> {
|
73
|
+
headers?: Record<string, any>;
|
74
|
+
method: Method;
|
45
75
|
isMock?: boolean; // 是否是mock
|
76
|
+
retry?: boolean; // 是否是重试接口
|
46
77
|
isReturnNativeResponse?: boolean; // 直接返回response,不作任何处理(包含响应值等基本信息)
|
47
78
|
customize?: boolean; // 直接返回response.data(接口返回值),错误不做统一提示
|
48
79
|
carryToken?: boolean; // 是否携带token
|
80
|
+
prefix?: string; // 接口自定义前缀
|
49
81
|
ignoreCancelToken?: boolean; // 忽略重复请求
|
82
|
+
cancelKey?: string; // 取消请求key(用来需要请求)
|
50
83
|
/**
|
51
84
|
* @Author gx12358
|
52
85
|
* @DateTime 2023/1/6
|
53
86
|
* @lastTime 2023/1/6
|
54
87
|
* @description 请求之前处理config
|
55
88
|
*/
|
56
|
-
beforeRequestHook?:
|
89
|
+
beforeRequestHook?: XhtInstance['beforeRequestHook'];
|
90
|
+
|
91
|
+
/**
|
92
|
+
* @Author gx12358
|
93
|
+
* @DateTime 2023/11/3
|
94
|
+
* @lastTime 2023/11/3
|
95
|
+
* @description 请求之前返回cancel函数
|
96
|
+
*/
|
97
|
+
cancelCallBackHook?: XhtInstance['cancelCallBackHook'];
|
57
98
|
|
58
99
|
/**
|
59
100
|
* @description: 处理响应数据
|
60
101
|
*/
|
61
|
-
transformResponseHook?:
|
102
|
+
transformResponseHook?: XhtInstance['transformResponseHook'];
|
62
103
|
|
63
104
|
/**
|
64
105
|
* @description: 请求失败处理
|
65
106
|
*/
|
66
|
-
requestCatchHook?:
|
107
|
+
requestCatchHook?: XhtInstance['requestCatchHook'];
|
67
108
|
|
68
109
|
/**
|
69
110
|
* @description: 请求之前的拦截器
|
70
111
|
*/
|
71
|
-
requestInterceptors?:
|
112
|
+
requestInterceptors?: XhtInstance['requestInterceptors'];
|
72
113
|
|
73
114
|
/**
|
74
115
|
* @description: 请求之后的拦截器
|
75
116
|
*/
|
76
|
-
responseInterceptors?:
|
117
|
+
responseInterceptors?: XhtInstance['responseInterceptors'];
|
77
118
|
|
78
119
|
/**
|
79
120
|
* @description: 请求之前的拦截器错误处理
|
80
121
|
*/
|
81
|
-
requestInterceptorsCatch?:
|
122
|
+
requestInterceptorsCatch?: XhtInstance['requestInterceptorsCatch'];
|
82
123
|
|
83
124
|
/**
|
84
125
|
* @description: 请求之后的拦截器错误处理
|
85
126
|
*/
|
86
|
-
responseInterceptorsCatch?:
|
127
|
+
responseInterceptorsCatch?: XhtInstance['responseInterceptorsCatch'];
|
87
128
|
}
|
88
129
|
|
89
|
-
export interface GAxiosInstance extends
|
130
|
+
export interface GAxiosInstance extends Omit<AxiosInstance, 'interceptors'> {
|
90
131
|
(config: GAxiosOptions): AxiosPromise<ResponseResult>;
|
91
132
|
|
92
133
|
(url: string, config?: GAxiosOptions): AxiosPromise<ResponseResult>;
|
134
|
+
|
135
|
+
interceptors: {
|
136
|
+
request: Omit<AxiosInterceptorManager<InternalAxiosRequestConfig>, 'use'> & {
|
137
|
+
use<V>(
|
138
|
+
onFulfilled?: ((value: V) => V | Promise<V>) | null,
|
139
|
+
onRejected?: ((error: any) => any) | null,
|
140
|
+
options?: AxiosInterceptorOptions
|
141
|
+
): number;
|
142
|
+
};
|
143
|
+
response: Omit<AxiosInterceptorManager<AxiosResponse>, 'use'> & {
|
144
|
+
use<V>(
|
145
|
+
onFulfilled?: ((value: V) => V | Promise<V>) | null,
|
146
|
+
onRejected?: ((error: any) => any) | null,
|
147
|
+
options?: AxiosInterceptorOptions
|
148
|
+
): number;
|
149
|
+
};
|
150
|
+
}
|
93
151
|
}
|
94
152
|
|
95
153
|
/**
|
@@ -111,4 +169,3 @@ export enum ContentTypeEnum {
|
|
111
169
|
// form-data qs
|
112
170
|
FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
|
113
171
|
}
|
114
|
-
|
@@ -1,15 +1,18 @@
|
|
1
1
|
import dayjs from 'dayjs'
|
2
|
-
import { isPro } from '@/utils/env'
|
3
|
-
import { Decrypt, Encrypt } from '@/utils/
|
2
|
+
import { isPro, typeViteEnv } from '@/utils/env'
|
3
|
+
import { Decrypt, Encrypt } from '@/utils/crypto'
|
4
4
|
import { isJSONStr } from '@/utils/validate'
|
5
5
|
import { isObject } from '@gx-design-vue/pro-utils'
|
6
6
|
|
7
|
+
export type StorageKey = 'localStorage' | 'sessionStorage' | 'cookie'
|
8
|
+
|
7
9
|
function isEncryption(status: boolean) {
|
8
10
|
return isPro() ? status : false
|
9
11
|
}
|
10
12
|
|
11
13
|
function handleStorageValue(value: string) {
|
12
|
-
if (isJSONStr(value))
|
14
|
+
if (isJSONStr(value))
|
15
|
+
return JSON.parse(value)
|
13
16
|
return value
|
14
17
|
}
|
15
18
|
|
@@ -21,10 +24,9 @@ function handleStorageValue(value: string) {
|
|
21
24
|
*/
|
22
25
|
export function getStorageKey(key: string, originKey?: boolean) {
|
23
26
|
const { pkg } = __APP_INFO__
|
24
|
-
|
25
|
-
return originKey ? key : `live_${pkg.version}_${VITE_APP_ENV === 'dev'
|
27
|
+
return originKey ? key : `${pkg.name}_${pkg.version}_${typeViteEnv('VITE_APP_ENV') === 'dev'
|
26
28
|
? 'development'
|
27
|
-
: VITE_USE_MODE}_${key}`
|
29
|
+
: typeViteEnv('VITE_USE_MODE')}_${key}`
|
28
30
|
}
|
29
31
|
|
30
32
|
/**
|
@@ -36,15 +38,16 @@ export function getStorageKey(key: string, originKey?: boolean) {
|
|
36
38
|
export function getStorage({
|
37
39
|
key,
|
38
40
|
encryption = true,
|
39
|
-
type = '
|
41
|
+
type = 'localStorage',
|
40
42
|
originKey
|
41
|
-
}: { key: string, encryption?: boolean, type?:
|
42
|
-
const storageValue = type === '
|
43
|
-
localStorage.getItem(getStorageKey(key, originKey))
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
}: { key: string, encryption?: boolean, type?: StorageKey, originKey?: boolean }) {
|
44
|
+
const storageValue = type === 'localStorage'
|
45
|
+
? localStorage.getItem(getStorageKey(key, originKey)) : type === 'sessionStorage'
|
46
|
+
? sessionStorage.getItem(getStorageKey(key, originKey))
|
47
|
+
: getCookie(
|
48
|
+
getStorageKey(key, originKey))
|
49
|
+
const result: string | LocalResult = storageValue
|
50
|
+
? isEncryption(encryption) ? Decrypt(storageValue) : handleStorageValue(storageValue) : ''
|
48
51
|
if (result && isObject(result)) {
|
49
52
|
if (result.expired) {
|
50
53
|
const expiredStatus = dayjs().diff(dayjs(result.time)) >= result.expired
|
@@ -83,8 +86,10 @@ export function setStorage({
|
|
83
86
|
time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
84
87
|
expired: expired || 0
|
85
88
|
}
|
86
|
-
const storageValue = isEncryption(encryption) ? Encrypt(JSON.stringify(result)) : JSON.stringify(
|
87
|
-
|
89
|
+
const storageValue = isEncryption(encryption) ? Encrypt(JSON.stringify(result)) : JSON.stringify(
|
90
|
+
result)
|
91
|
+
if (type === 'local')
|
92
|
+
localStorage.setItem(getStorageKey(key, originKey), storageValue)
|
88
93
|
sessionStorage.setItem(getStorageKey(key, originKey), storageValue)
|
89
94
|
}
|
90
95
|
|
@@ -95,7 +100,8 @@ export function setStorage({
|
|
95
100
|
* @description 删除Storage
|
96
101
|
*/
|
97
102
|
export function removeStorage(key: string, type = 'local', originKey?: boolean) {
|
98
|
-
if (type === 'local')
|
103
|
+
if (type === 'local')
|
104
|
+
localStorage.removeItem(getStorageKey(key, originKey))
|
99
105
|
sessionStorage.removeItem(getStorageKey(key, originKey))
|
100
106
|
}
|
101
107
|
|
@@ -130,7 +136,8 @@ function getCookies(cname: string) {
|
|
130
136
|
function GetCookieDomain() {
|
131
137
|
let host = location.hostname
|
132
138
|
const ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
|
133
|
-
if (ip.test(host) === true || host === 'localhost')
|
139
|
+
if (ip.test(host) === true || host === 'localhost')
|
140
|
+
return host
|
134
141
|
const regex = /([^]*).*/
|
135
142
|
const match = host.match(regex)
|
136
143
|
if (typeof match !== 'undefined' && match !== null) {
|