@gx-design-vue/create-gx-cli 0.1.15 → 0.1.17
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 +22 -9
- 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 -0
- package/template-mobile-vant-cli/.env.development +0 -19
- package/template-mobile-vant-cli/.env.pro +0 -19
- package/template-mobile-vant-cli/.env.production +0 -19
- 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/build/cdn.ts +0 -5
- package/template-mobile-vant-cli/build/generateModifyVars.ts +0 -7
- package/template-mobile-vant-cli/build/optimizer.ts +0 -18
- package/template-mobile-vant-cli/build/plugin/autoImport.ts +0 -24
- 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/eslint.config.js +0 -49
- package/template-mobile-vant-cli/index.html +0 -24
- package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
- package/template-mobile-vant-cli/mock/datasSource/api/index.ts +0 -0
- package/template-mobile-vant-cli/mock/utils.ts +0 -9
- package/template-mobile-vant-cli/package.json +0 -57
- 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/favicon.ico +0 -0
- package/template-mobile-vant-cli/public/js/flexible.js +0 -44
- package/template-mobile-vant-cli/src/App.vue +0 -5
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +0 -29
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +0 -115
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +0 -14
- package/template-mobile-vant-cli/src/core/gx-design/index.ts +0 -7
- package/template-mobile-vant-cli/src/core/index.ts +0 -12
- package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
- package/template-mobile-vant-cli/src/design/config.less +0 -0
- package/template-mobile-vant-cli/src/design/index.less +0 -3
- package/template-mobile-vant-cli/src/design/reset.less +0 -155
- package/template-mobile-vant-cli/src/design/root.less +0 -3
- 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/hooks/web/index.ts +0 -5
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +0 -58
- package/template-mobile-vant-cli/src/layout/BasicLayout.vue +0 -16
- package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
- package/template-mobile-vant-cli/src/main.ts +0 -27
- package/template-mobile-vant-cli/src/pages/home.vue +0 -71
- package/template-mobile-vant-cli/src/router/index.ts +0 -25
- 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/services/index.ts +0 -31
- package/template-mobile-vant-cli/src/settings/index.ts +0 -10
- package/template-mobile-vant-cli/src/store/index.ts +0 -17
- package/template-mobile-vant-cli/src/store/modules/global.ts +0 -30
- package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
- package/template-mobile-vant-cli/src/utils/crypto/index.ts +0 -57
- package/template-mobile-vant-cli/src/utils/env.ts +0 -50
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +0 -14
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +0 -139
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +0 -69
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +0 -9
- package/template-mobile-vant-cli/src/utils/request/index.ts +0 -142
- package/template-mobile-vant-cli/src/utils/request/typings.ts +0 -171
- package/template-mobile-vant-cli/src/utils/storage.ts +0 -198
- package/template-mobile-vant-cli/src/utils/util.ts +0 -27
- package/template-mobile-vant-cli/src/utils/validate.ts +0 -216
- package/template-mobile-vant-cli/tsconfig.json +0 -42
- package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
- package/template-mobile-vant-cli/types/auto-imports.d.ts +0 -64
- package/template-mobile-vant-cli/types/components.d.ts +0 -12
- package/template-mobile-vant-cli/types/global.d.ts +0 -39
- package/template-mobile-vant-cli/types/module.d.ts +0 -20
- package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
- package/template-mobile-vant-cli/types/response.d.ts +0 -15
- package/template-mobile-vant-cli/types/vant-import.d.ts +0 -13
- package/template-mobile-vant-cli/unocss.config.ts +0 -101
- package/template-mobile-vant-cli/vite.config.ts +0 -145
- 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,139 +0,0 @@
|
|
1
|
-
import type { AxiosError } from 'axios'
|
2
|
-
import axios from 'axios'
|
3
|
-
import { cloneDeep } from 'lodash-es'
|
4
|
-
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
|
-
import { AxiosCanceler } from './axiosCancel'
|
9
|
-
|
10
|
-
export const getPendingUrl = (config: GAxiosOptions) => config.cancelKey || [ config.method, config.url ].join(
|
11
|
-
'&')
|
12
|
-
|
13
|
-
/**
|
14
|
-
* @Author gx12358
|
15
|
-
* @DateTime 2023/1/6
|
16
|
-
* @lastTime 2023/1/6
|
17
|
-
* @description 重新定义axios
|
18
|
-
*/
|
19
|
-
export class GAxios {
|
20
|
-
private axiosInstance: GAxiosInstance
|
21
|
-
private readonly options: GAxiosOptions
|
22
|
-
|
23
|
-
constructor(options: GAxiosOptions) {
|
24
|
-
this.options = options
|
25
|
-
this.axiosInstance = axios.create(options) as GAxiosInstance
|
26
|
-
this.setupInterceptors()
|
27
|
-
}
|
28
|
-
|
29
|
-
/**
|
30
|
-
* @description: Interceptor configuration 拦截器配置
|
31
|
-
*/
|
32
|
-
private setupInterceptors() {
|
33
|
-
const {
|
34
|
-
requestInterceptors,
|
35
|
-
requestInterceptorsCatch,
|
36
|
-
responseInterceptors,
|
37
|
-
responseInterceptorsCatch
|
38
|
-
} = this.options
|
39
|
-
|
40
|
-
const axiosCanceler = new AxiosCanceler(this.options.ignoreCancelToken)
|
41
|
-
|
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
|
-
}
|
52
|
-
if (requestInterceptors && isFunction(requestInterceptors)) {
|
53
|
-
config = requestInterceptors(config)
|
54
|
-
}
|
55
|
-
return config
|
56
|
-
}, undefined)
|
57
|
-
|
58
|
-
// Request interceptor error capture
|
59
|
-
requestInterceptorsCatch && isFunction(requestInterceptorsCatch) && this.axiosInstance.interceptors.request.use(
|
60
|
-
undefined,
|
61
|
-
requestInterceptorsCatch
|
62
|
-
)
|
63
|
-
|
64
|
-
// Response result interceptor processing
|
65
|
-
this.axiosInstance.interceptors.response.use((res: GAxiosResponse) => {
|
66
|
-
res && axiosCanceler.removePending(res.config)
|
67
|
-
if (responseInterceptors && isFunction(responseInterceptors)) {
|
68
|
-
return responseInterceptors(res)
|
69
|
-
}
|
70
|
-
return res
|
71
|
-
}, undefined)
|
72
|
-
|
73
|
-
// Response result interceptor error capture
|
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
|
-
)
|
82
|
-
}
|
83
|
-
|
84
|
-
// support form-data
|
85
|
-
supportFormData(config: GAxiosOptions) {
|
86
|
-
const headers = config.headers || this.options.headers
|
87
|
-
const contentType = headers?.['Content-Type'] || headers?.['content-type']
|
88
|
-
|
89
|
-
if (contentType !== ContentTypeEnum.FORM_URLENCODED || !Reflect.has(
|
90
|
-
config,
|
91
|
-
'data'
|
92
|
-
) || config.method?.toUpperCase() === RequestEnum.GET) {
|
93
|
-
return config
|
94
|
-
}
|
95
|
-
|
96
|
-
return {
|
97
|
-
...config,
|
98
|
-
data: qs.stringify(config.data, { arrayFormat: 'brackets' })
|
99
|
-
}
|
100
|
-
}
|
101
|
-
|
102
|
-
request<T = ResponseResult | boolean>(config: GAxiosOptions): Promise<T> {
|
103
|
-
let conf: GAxiosOptions = cloneDeep(config)
|
104
|
-
|
105
|
-
const opt: GAxiosOptions = Object.assign({}, this.options, conf)
|
106
|
-
|
107
|
-
const { beforeRequestHook, requestCatchHook, transformResponseHook } = opt
|
108
|
-
if (beforeRequestHook && isFunction(beforeRequestHook)) {
|
109
|
-
conf = beforeRequestHook(opt)
|
110
|
-
}
|
111
|
-
|
112
|
-
conf = this.supportFormData(opt)
|
113
|
-
|
114
|
-
return new Promise((resolve) => {
|
115
|
-
this.axiosInstance
|
116
|
-
.request<any, GAxiosResponse>(conf)
|
117
|
-
.then((res: GAxiosResponse) => {
|
118
|
-
if (transformResponseHook && isFunction(transformResponseHook)) {
|
119
|
-
try {
|
120
|
-
const ret = transformResponseHook(res, config)
|
121
|
-
resolve(ret)
|
122
|
-
} catch (err) {
|
123
|
-
resolve(false as any)
|
124
|
-
return
|
125
|
-
}
|
126
|
-
return
|
127
|
-
}
|
128
|
-
resolve(res as unknown as Promise<T>)
|
129
|
-
})
|
130
|
-
.catch((e: Error | AxiosError) => {
|
131
|
-
if (requestCatchHook && isFunction(requestCatchHook)) {
|
132
|
-
resolve(requestCatchHook(e) as any)
|
133
|
-
return
|
134
|
-
}
|
135
|
-
resolve(false as any)
|
136
|
-
})
|
137
|
-
})
|
138
|
-
}
|
139
|
-
}
|
@@ -1,69 +0,0 @@
|
|
1
|
-
import type { Canceler } from 'axios'
|
2
|
-
import axios from 'axios'
|
3
|
-
import { isFunction } from '@gx-design-vue/pro-utils'
|
4
|
-
import type { GAxiosOptions } from './typings'
|
5
|
-
|
6
|
-
export const getPendingUrl = (
|
7
|
-
config: GAxiosOptions,
|
8
|
-
key?: string
|
9
|
-
) => key || config.cancelKey || [ config.method, config.url ].join('&')
|
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
|
-
|
21
|
-
/**
|
22
|
-
* Add request
|
23
|
-
* @param {Object} config
|
24
|
-
*/
|
25
|
-
addPending(config: GAxiosOptions) {
|
26
|
-
!this.ignoreCancelToken && this.removePending(config)
|
27
|
-
|
28
|
-
const url = getPendingUrl(config)
|
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
|
-
})
|
35
|
-
}
|
36
|
-
|
37
|
-
/**
|
38
|
-
* @description: Clear all pending
|
39
|
-
*/
|
40
|
-
removeAllPending() {
|
41
|
-
this.pendingMap.forEach((cancel) => {
|
42
|
-
cancel && isFunction(cancel) && cancel()
|
43
|
-
})
|
44
|
-
this.pendingMap.clear()
|
45
|
-
}
|
46
|
-
|
47
|
-
/**
|
48
|
-
* Removal request
|
49
|
-
* @param {Object} config
|
50
|
-
*/
|
51
|
-
removePending(config: GAxiosOptions, key?: string) {
|
52
|
-
const url = getPendingUrl(config, key)
|
53
|
-
|
54
|
-
if (this.pendingMap.has(url)) {
|
55
|
-
// If there is a current request identifier in pending,
|
56
|
-
// the current request needs to be cancelled and removed
|
57
|
-
const cancel = this.pendingMap.get(url)
|
58
|
-
cancel && cancel(url)
|
59
|
-
this.pendingMap.delete(url)
|
60
|
-
}
|
61
|
-
}
|
62
|
-
|
63
|
-
/**
|
64
|
-
* @description: reset
|
65
|
-
*/
|
66
|
-
reset(): void {
|
67
|
-
this.pendingMap = new Map<string, Canceler>()
|
68
|
-
}
|
69
|
-
}
|
@@ -1,142 +0,0 @@
|
|
1
|
-
import { showFailToast } from 'vant'
|
2
|
-
import settings from '@/settings'
|
3
|
-
import { useStoreGlobal } from '@/store'
|
4
|
-
import { isDev } from '@/utils/env'
|
5
|
-
import { tansParams } from '@/utils/util'
|
6
|
-
import { checkURL } from '@/utils/validate'
|
7
|
-
import { isBoolean } from '@gx-design-vue/pro-utils'
|
8
|
-
import { GAxios } from './XHR'
|
9
|
-
import type { GAxiosOptions, XhtInstance } from './typings'
|
10
|
-
import { RequestEnum } from './typings'
|
11
|
-
import { handleCode } from './checkStatus'
|
12
|
-
|
13
|
-
const { requestPrefix, successCode, requestTimeout, tokenName, contentType } = settings
|
14
|
-
|
15
|
-
const xhtInstance: XhtInstance = {
|
16
|
-
/**
|
17
|
-
* @description: 处理响应数据。如果数据不是预期格式,可直接抛出错误
|
18
|
-
*/
|
19
|
-
transformResponseHook: (res, options) => {
|
20
|
-
const { customize, isReturnNativeResponse } = options
|
21
|
-
// 是否返回原生响应头 比如:需要获取响应头时使用该属性
|
22
|
-
if (isReturnNativeResponse) {
|
23
|
-
return res
|
24
|
-
}
|
25
|
-
// 不进行任何处理,直接返回
|
26
|
-
// 用于页面代码可能需要直接获取code,data,message这些信息时开启
|
27
|
-
if (customize) {
|
28
|
-
return res.data
|
29
|
-
}
|
30
|
-
// 错误的时候返回
|
31
|
-
|
32
|
-
const { data }: { data: ResponseResult } = res
|
33
|
-
if (!data) {
|
34
|
-
throw new Error('请求出错,请稍候重试')
|
35
|
-
}
|
36
|
-
// 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
|
37
|
-
const { code, msg = '', message = '' } = data
|
38
|
-
|
39
|
-
const codeVerificationArray = successCode
|
40
|
-
|
41
|
-
// 这里逻辑可以根据项目进行修改
|
42
|
-
const hasSuccess = codeVerificationArray.includes(code)
|
43
|
-
if (hasSuccess) {
|
44
|
-
return data
|
45
|
-
}
|
46
|
-
|
47
|
-
// 在此处根据自己项目的实际情况对不同的code执行不同的操作
|
48
|
-
// 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
|
49
|
-
handleCode(code, message || msg)
|
50
|
-
|
51
|
-
return Promise.resolve(false)
|
52
|
-
},
|
53
|
-
|
54
|
-
// 请求之前处理config
|
55
|
-
beforeRequestHook: (config) => {
|
56
|
-
// get请求映射params参数
|
57
|
-
if (config.method?.toUpperCase() === RequestEnum.GET && config.params) {
|
58
|
-
let url = config.url + '?' + tansParams(config.params)
|
59
|
-
url = url.slice(0, -1)
|
60
|
-
config.params = {}
|
61
|
-
config.url = url
|
62
|
-
}
|
63
|
-
|
64
|
-
if (!checkURL(config.url)) {
|
65
|
-
if (config.isMock) {
|
66
|
-
config.url = `/mock-server${config.url}`
|
67
|
-
} else {
|
68
|
-
config.url = `${import.meta.env.VITE_BASE_URL}${isDev ? requestPrefix || '' : ''}${config.url}`
|
69
|
-
}
|
70
|
-
}
|
71
|
-
|
72
|
-
return config
|
73
|
-
},
|
74
|
-
|
75
|
-
/**
|
76
|
-
* @description: 请求拦截器处理
|
77
|
-
*/
|
78
|
-
requestInterceptors: (config) => {
|
79
|
-
const global = useStoreGlobal()
|
80
|
-
const carryToken = isBoolean(config.carryToken) ? config.carryToken : true
|
81
|
-
if (global.token && carryToken)
|
82
|
-
config.headers[tokenName] = global.token
|
83
|
-
return config
|
84
|
-
},
|
85
|
-
|
86
|
-
/**
|
87
|
-
* @description: 响应拦截器处理
|
88
|
-
*/
|
89
|
-
responseInterceptors: (res) => {
|
90
|
-
return res
|
91
|
-
},
|
92
|
-
|
93
|
-
/**
|
94
|
-
* @description: 响应错误处理
|
95
|
-
*/
|
96
|
-
responseInterceptorsCatch: (error: any) => {
|
97
|
-
const { response } = error
|
98
|
-
let errorMessage = error.message || ''
|
99
|
-
if (error.response && error.response.data) {
|
100
|
-
const { status } = response
|
101
|
-
handleCode(status, errorMessage)
|
102
|
-
return Promise.resolve(false)
|
103
|
-
} else {
|
104
|
-
if (errorMessage === 'Network Error') {
|
105
|
-
errorMessage = '后端接口连接异常'
|
106
|
-
}
|
107
|
-
if (errorMessage.includes('timeout')) {
|
108
|
-
errorMessage = '后端接口请求超时'
|
109
|
-
}
|
110
|
-
if (errorMessage.includes('Request failed with status code')) {
|
111
|
-
const code = errorMessage.substr(errorMessage.length - 3)
|
112
|
-
errorMessage = '后端接口' + code || '' + '异常'
|
113
|
-
}
|
114
|
-
showFailToast({ message: errorMessage || '服务器出错!' })
|
115
|
-
return Promise.resolve(false)
|
116
|
-
}
|
117
|
-
},
|
118
|
-
/**
|
119
|
-
* @description: 处理响应错误数据
|
120
|
-
*/
|
121
|
-
requestCatchHook: () => false
|
122
|
-
}
|
123
|
-
|
124
|
-
function createXhr(opt?: Partial<GAxiosOptions>) {
|
125
|
-
return new GAxios({
|
126
|
-
method: 'get',
|
127
|
-
timeout: requestTimeout,
|
128
|
-
headers: {
|
129
|
-
'Content-Type': contentType
|
130
|
-
},
|
131
|
-
// 忽略重复请求
|
132
|
-
ignoreCancelToken: true,
|
133
|
-
// 是否携带token
|
134
|
-
carryToken: true,
|
135
|
-
...xhtInstance,
|
136
|
-
...opt
|
137
|
-
})
|
138
|
-
}
|
139
|
-
|
140
|
-
const request: <T = any, R = undefined>(opt?: GAxiosOptions) => Promise<ResponseResult<T, R>> = opt => createXhr().request(opt)
|
141
|
-
|
142
|
-
export default request
|
@@ -1,171 +0,0 @@
|
|
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
|
-
}
|
23
|
-
|
24
|
-
export interface XhtInstance {
|
25
|
-
/**
|
26
|
-
* @Author gx12358
|
27
|
-
* @DateTime 2023/1/6
|
28
|
-
* @lastTime 2023/1/6
|
29
|
-
* @description 请求之前处理config
|
30
|
-
*/
|
31
|
-
beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
|
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
|
-
|
41
|
-
/**
|
42
|
-
* @description: 处理响应数据
|
43
|
-
*/
|
44
|
-
transformResponseHook?: (res: GAxiosResponse, options: Partial<GAxiosOptions>) => any;
|
45
|
-
|
46
|
-
/**
|
47
|
-
* @description: 请求失败处理
|
48
|
-
*/
|
49
|
-
requestCatchHook?: (e: Error) => boolean;
|
50
|
-
|
51
|
-
/**
|
52
|
-
* @description: 请求之前的拦截器
|
53
|
-
*/
|
54
|
-
requestInterceptors?: (config: GAxiosOptions) => GAxiosOptions;
|
55
|
-
|
56
|
-
/**
|
57
|
-
* @description: 请求之后的拦截器
|
58
|
-
*/
|
59
|
-
responseInterceptors?: (res: GAxiosResponse) => GAxiosResponse;
|
60
|
-
|
61
|
-
/**
|
62
|
-
* @description: 请求之前的拦截器错误处理
|
63
|
-
*/
|
64
|
-
requestInterceptorsCatch?: (error: AxiosError) => void;
|
65
|
-
|
66
|
-
/**
|
67
|
-
* @description: 请求之后的拦截器错误处理
|
68
|
-
*/
|
69
|
-
responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: AxiosError) => void;
|
70
|
-
}
|
71
|
-
|
72
|
-
export interface GAxiosOptions extends Omit<AxiosRequestConfig, 'headers' | 'method'> {
|
73
|
-
headers?: Record<string, any>;
|
74
|
-
method: Method;
|
75
|
-
isMock?: boolean; // 是否是mock
|
76
|
-
retry?: boolean; // 是否是重试接口
|
77
|
-
isReturnNativeResponse?: boolean; // 直接返回response,不作任何处理(包含响应值等基本信息)
|
78
|
-
customize?: boolean; // 直接返回response.data(接口返回值),错误不做统一提示
|
79
|
-
carryToken?: boolean; // 是否携带token
|
80
|
-
prefix?: string; // 接口自定义前缀
|
81
|
-
ignoreCancelToken?: boolean; // 忽略重复请求
|
82
|
-
cancelKey?: string; // 取消请求key(用来需要请求)
|
83
|
-
/**
|
84
|
-
* @Author gx12358
|
85
|
-
* @DateTime 2023/1/6
|
86
|
-
* @lastTime 2023/1/6
|
87
|
-
* @description 请求之前处理config
|
88
|
-
*/
|
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'];
|
98
|
-
|
99
|
-
/**
|
100
|
-
* @description: 处理响应数据
|
101
|
-
*/
|
102
|
-
transformResponseHook?: XhtInstance['transformResponseHook'];
|
103
|
-
|
104
|
-
/**
|
105
|
-
* @description: 请求失败处理
|
106
|
-
*/
|
107
|
-
requestCatchHook?: XhtInstance['requestCatchHook'];
|
108
|
-
|
109
|
-
/**
|
110
|
-
* @description: 请求之前的拦截器
|
111
|
-
*/
|
112
|
-
requestInterceptors?: XhtInstance['requestInterceptors'];
|
113
|
-
|
114
|
-
/**
|
115
|
-
* @description: 请求之后的拦截器
|
116
|
-
*/
|
117
|
-
responseInterceptors?: XhtInstance['responseInterceptors'];
|
118
|
-
|
119
|
-
/**
|
120
|
-
* @description: 请求之前的拦截器错误处理
|
121
|
-
*/
|
122
|
-
requestInterceptorsCatch?: XhtInstance['requestInterceptorsCatch'];
|
123
|
-
|
124
|
-
/**
|
125
|
-
* @description: 请求之后的拦截器错误处理
|
126
|
-
*/
|
127
|
-
responseInterceptorsCatch?: XhtInstance['responseInterceptorsCatch'];
|
128
|
-
}
|
129
|
-
|
130
|
-
export interface GAxiosInstance extends Omit<AxiosInstance, 'interceptors'> {
|
131
|
-
(config: GAxiosOptions): AxiosPromise<ResponseResult>;
|
132
|
-
|
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
|
-
}
|
151
|
-
}
|
152
|
-
|
153
|
-
/**
|
154
|
-
* @description: request method
|
155
|
-
*/
|
156
|
-
export enum RequestEnum {
|
157
|
-
GET = 'GET',
|
158
|
-
POST = 'POST',
|
159
|
-
PUT = 'PUT',
|
160
|
-
DELETE = 'DELETE',
|
161
|
-
}
|
162
|
-
|
163
|
-
/**
|
164
|
-
* @description: contentType
|
165
|
-
*/
|
166
|
-
export enum ContentTypeEnum {
|
167
|
-
// json
|
168
|
-
JSON = 'application/json;charset=UTF-8',
|
169
|
-
// form-data qs
|
170
|
-
FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
|
171
|
-
}
|