@gx-design-vue/create-gx-cli 0.1.2 → 0.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/package.json +1 -1
  2. package/src/main.js +9 -3
  3. package/template-mobile-vant-cli/.editorconfig +0 -19
  4. package/template-mobile-vant-cli/.env.development +0 -19
  5. package/template-mobile-vant-cli/.env.pro +0 -19
  6. package/template-mobile-vant-cli/.env.production +0 -19
  7. package/template-mobile-vant-cli/.eslintignore +0 -16
  8. package/template-mobile-vant-cli/.eslintrc.js +0 -64
  9. package/template-mobile-vant-cli/.prettierignore +0 -9
  10. package/template-mobile-vant-cli/.stylelintignore +0 -3
  11. package/template-mobile-vant-cli/build/cdn.ts +0 -5
  12. package/template-mobile-vant-cli/build/generateModifyVars.ts +0 -7
  13. package/template-mobile-vant-cli/build/optimizer.ts +0 -18
  14. package/template-mobile-vant-cli/build/plugin/autoImport.ts +0 -26
  15. package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
  16. package/template-mobile-vant-cli/build/plugin/index.ts +0 -50
  17. package/template-mobile-vant-cli/build/plugin/mock.ts +0 -20
  18. package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
  19. package/template-mobile-vant-cli/index.html +0 -24
  20. package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
  21. package/template-mobile-vant-cli/mock/api/index.ts +0 -66
  22. package/template-mobile-vant-cli/mock/utils.ts +0 -9
  23. package/template-mobile-vant-cli/package.json +0 -64
  24. package/template-mobile-vant-cli/postcss.config.js +0 -8
  25. package/template-mobile-vant-cli/prettier.config.js +0 -18
  26. package/template-mobile-vant-cli/public/favicon.ico +0 -0
  27. package/template-mobile-vant-cli/public/js/flexible.js +0 -44
  28. package/template-mobile-vant-cli/src/App.vue +0 -5
  29. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +0 -30
  30. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +0 -114
  31. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +0 -14
  32. package/template-mobile-vant-cli/src/core/gx-design/index.ts +0 -7
  33. package/template-mobile-vant-cli/src/core/index.ts +0 -12
  34. package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
  35. package/template-mobile-vant-cli/src/design/config.less +0 -0
  36. package/template-mobile-vant-cli/src/design/index.less +0 -3
  37. package/template-mobile-vant-cli/src/design/reset.less +0 -155
  38. package/template-mobile-vant-cli/src/design/root.less +0 -3
  39. package/template-mobile-vant-cli/src/design/vant.less +0 -2
  40. package/template-mobile-vant-cli/src/global.less +0 -1
  41. package/template-mobile-vant-cli/src/hooks/web/index.ts +0 -5
  42. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +0 -55
  43. package/template-mobile-vant-cli/src/layout/BasicLayout.vue +0 -16
  44. package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
  45. package/template-mobile-vant-cli/src/main.ts +0 -27
  46. package/template-mobile-vant-cli/src/pages/home.vue +0 -71
  47. package/template-mobile-vant-cli/src/router/index.ts +0 -24
  48. package/template-mobile-vant-cli/src/router/routes.ts +0 -20
  49. package/template-mobile-vant-cli/src/router/typings.ts +0 -8
  50. package/template-mobile-vant-cli/src/services/index.ts +0 -31
  51. package/template-mobile-vant-cli/src/settings/index.ts +0 -10
  52. package/template-mobile-vant-cli/src/store/index.ts +0 -17
  53. package/template-mobile-vant-cli/src/store/modules/global.ts +0 -30
  54. package/template-mobile-vant-cli/src/utils/cryptoJS.ts +0 -39
  55. package/template-mobile-vant-cli/src/utils/env.ts +0 -52
  56. package/template-mobile-vant-cli/src/utils/pageTitle.ts +0 -12
  57. package/template-mobile-vant-cli/src/utils/request/XHR.ts +0 -131
  58. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +0 -60
  59. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +0 -11
  60. package/template-mobile-vant-cli/src/utils/request/index.ts +0 -143
  61. package/template-mobile-vant-cli/src/utils/request/typings.ts +0 -114
  62. package/template-mobile-vant-cli/src/utils/storage.ts +0 -191
  63. package/template-mobile-vant-cli/src/utils/util.ts +0 -32
  64. package/template-mobile-vant-cli/src/utils/validate.ts +0 -28
  65. package/template-mobile-vant-cli/stylelint.config.js +0 -106
  66. package/template-mobile-vant-cli/tsconfig.json +0 -43
  67. package/template-mobile-vant-cli/types/auto-imports.d.ts +0 -61
  68. package/template-mobile-vant-cli/types/components.d.ts +0 -15
  69. package/template-mobile-vant-cli/types/global.d.ts +0 -36
  70. package/template-mobile-vant-cli/types/gx-components.d.ts +0 -13
  71. package/template-mobile-vant-cli/types/module.d.ts +0 -7
  72. package/template-mobile-vant-cli/types/response.d.ts +0 -12
  73. package/template-mobile-vant-cli/vite.config.ts +0 -113
  74. package/template-mobile-vant-html/css/global.css +0 -293
  75. package/template-mobile-vant-html/css/global.css.map +0 -1
  76. package/template-mobile-vant-html/css/global.less +0 -293
  77. package/template-mobile-vant-html/css/index.css +0 -20
  78. package/template-mobile-vant-html/css/index.css.map +0 -1
  79. package/template-mobile-vant-html/css/index.less +0 -21
  80. package/template-mobile-vant-html/image/disconnected.svg +0 -60
  81. package/template-mobile-vant-html/image/empty.svg +0 -52
  82. package/template-mobile-vant-html/image/error.svg +0 -53
  83. package/template-mobile-vant-html/image/loading.svg +0 -1
  84. package/template-mobile-vant-html/index.html +0 -91
  85. package/template-mobile-vant-html/js/index.js +0 -29
  86. package/template-mobile-vant-html/js/plugin/day.min.js +0 -1
  87. package/template-mobile-vant-html/js/plugin/fastclick.js +0 -730
  88. package/template-mobile-vant-html/js/plugin/jquery.min.js +0 -2
  89. package/template-mobile-vant-html/js/plugin/rem.js +0 -28
  90. package/template-mobile-vant-html/js/utils/appUtil.js +0 -70
  91. package/template-mobile-vant-html/js/utils/config.js +0 -3
  92. package/template-mobile-vant-html/js/utils/request.js +0 -61
  93. package/template-mobile-vant-html/js/utils/utils.js +0 -65
  94. package/template-mobile-vant-html/js/utils/validate.js +0 -292
@@ -1,30 +0,0 @@
1
- import { reactive, toRefs } from 'vue'
2
- import { defineStore } from 'pinia'
3
- import { deepCopy } from '@/utils/util'
4
-
5
- /**
6
- * @Author gx12358
7
- * @DateTime 2022/1/11
8
- * @lastTime 2022/1/11
9
- * @description store-global 全局属性
10
- */
11
- export interface GlobalState {
12
- token?: string; // app token
13
- }
14
-
15
- type GlobalStateKey = keyof GlobalState
16
-
17
- export const useStoreGlobal = defineStore('global', () => {
18
- const state = reactive<GlobalState>({
19
- token: ''
20
- })
21
-
22
- const setGlobalData: (params: Partial<Record<GlobalStateKey, GlobalState[GlobalStateKey]>>) => void = (params) => {
23
- Object.assign(state, deepCopy(params))
24
- }
25
-
26
- return {
27
- ...toRefs(state),
28
- setGlobalData
29
- }
30
- })
@@ -1,39 +0,0 @@
1
- import 'crypto-js/enc-utf8'
2
- import 'crypto-js/tripledes'
3
- import 'crypto-js/sha1'
4
- import * as CryptoJS from 'crypto-js/core'
5
- import { isJSONStr } from '@/utils/validate'
6
- import { isObject, isArray } from '@gx-design-vue/pro-utils'
7
-
8
- const key = '1234123412ABCDEF' //十六位十六进制数作为密钥
9
-
10
- //加密方法
11
- export function Encrypt(word) {
12
- let str: string | object = word
13
- if (isObject(word) || isArray(word)) {
14
- str = JSON.stringify(word)
15
- }
16
- const keyHex = CryptoJS.enc.Utf8.parse(key)
17
- const ivHex = CryptoJS.enc.Utf8.parse(key)
18
- const encrypted = CryptoJS.DES.encrypt(str, keyHex, {
19
- iv: ivHex,
20
- mode: CryptoJS.mode.CBC,
21
- padding: CryptoJS.pad.Pkcs7
22
- })
23
- return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
24
- }
25
-
26
- //解密方法
27
- export function Decrypt(word) {
28
- const keyHex = CryptoJS.enc.Utf8.parse(key)
29
- const ivHex = CryptoJS.enc.Utf8.parse(key)
30
- const decrypted = CryptoJS.DES.decrypt({
31
- ciphertext: CryptoJS.enc.Base64.parse(word)
32
- }, keyHex, {
33
- iv: ivHex,
34
- mode: CryptoJS.mode.CBC,
35
- padding: CryptoJS.pad.Pkcs7
36
- })
37
- const decryptedStr = decrypted.toString(CryptoJS.enc.Utf8)
38
- return isJSONStr(decryptedStr.toString()) ? JSON.parse(decryptedStr.toString()) : decryptedStr.toString()
39
- }
@@ -1,52 +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
- const DEV = typeViteEnv('VITE_USE_MODE') === 'development'
9
- return DEV
10
- }
11
-
12
- /**
13
- * @Author gx12358
14
- * @DateTime 2022/4/1
15
- * @lastTime 2022/4/1
16
- * @description 环境:测试
17
- */
18
- export function isTest(): boolean {
19
- const PRO = typeViteEnv('VITE_USE_MODE') === 'test'
20
- return PRO
21
- }
22
-
23
- /**
24
- * @Author gx12358
25
- * @DateTime 2022/4/1
26
- * @lastTime 2022/4/1
27
- * @description 环境:正式
28
- */
29
- export function isPro(): boolean {
30
- return typeViteEnv('VITE_USE_MODE') === 'production'
31
- }
32
-
33
- /**
34
- * @Author gx12358
35
- * @DateTime 2022/4/1
36
- * @lastTime 2022/4/1
37
- * @description 环境:测试、正式
38
- */
39
- export function isBuild(): boolean {
40
- return typeViteEnv('VITE_USE_MODE') !== 'development'
41
- }
42
-
43
- export function typeViteEnv(key: ViteEnvKey) {
44
- let value = import.meta.env[key]
45
- if (value) {
46
- value = (value as string).replace(/\\n/g, '\n')
47
-
48
- value = value === 'true' ? true : value === 'false' ? false : value
49
- }
50
-
51
- return value
52
- }
@@ -1,12 +0,0 @@
1
- /**
2
- * @author gx12358 2539306317@qq.com
3
- * @description 设置标题
4
- * @param pageTitle
5
- * @returns {string}
6
- */
7
- export default function getPageTitle(title: string, pageTitle: string) {
8
- let newTitles: any = []
9
- if (pageTitle) newTitles.push(pageTitle)
10
- if (title) newTitles.push(title)
11
- return newTitles.join('-')
12
- }
@@ -1,131 +0,0 @@
1
- import type { AxiosResponse, AxiosError } from 'axios'
2
- import axios from 'axios'
3
- import { deepCopy } from '@/utils/util'
4
- import qs from 'qs'
5
- import { isFunction } from '@gx-design-vue/pro-utils'
6
- import type { GAxiosInstance, GAxiosOptions } from './typings'
7
- import { ContentTypeEnum, RequestEnum } from './typings'
8
- import { AxiosCanceler } from './axiosCancel'
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)
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()
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
45
-
46
- !ignoreCancel && axiosCanceler.addPending(config)
47
- if (requestInterceptors && isFunction(requestInterceptors)) {
48
- config = requestInterceptors(config)
49
- }
50
- return config
51
- }, undefined)
52
-
53
- // Request interceptor error capture
54
- requestInterceptorsCatch &&
55
- isFunction(requestInterceptorsCatch) &&
56
- this.axiosInstance.interceptors.request.use(undefined, requestInterceptorsCatch)
57
-
58
- // Response result interceptor processing
59
- this.axiosInstance.interceptors.response.use((res: AxiosResponse) => {
60
- res && axiosCanceler.removePending(res.config)
61
- if (responseInterceptors && isFunction(responseInterceptors)) {
62
- return responseInterceptors(res)
63
- }
64
- return res
65
- }, undefined)
66
-
67
- // Response result interceptor error capture
68
- responseInterceptorsCatch &&
69
- isFunction(responseInterceptorsCatch) &&
70
- this.axiosInstance.interceptors.response.use(undefined, (error) => {
71
- return responseInterceptorsCatch(this.axiosInstance, error)
72
- })
73
- }
74
-
75
- // support form-data
76
- supportFormData(config: GAxiosOptions) {
77
- const headers = config.headers || this.options.headers
78
- const contentType = headers?.['Content-Type'] || headers?.['content-type']
79
-
80
- if (
81
- contentType !== ContentTypeEnum.FORM_URLENCODED ||
82
- !Reflect.has(config, 'data') ||
83
- config.method?.toUpperCase() === RequestEnum.GET
84
- ) {
85
- return config
86
- }
87
-
88
- return {
89
- ...config,
90
- data: qs.stringify(config.data, { arrayFormat: 'brackets' })
91
- }
92
- }
93
-
94
- request<T = ResponseResult | boolean>(config: GAxiosOptions): Promise<T> {
95
- let conf: GAxiosOptions = deepCopy(config)
96
-
97
- const opt: GAxiosOptions = Object.assign({}, this.options, conf)
98
-
99
- const { beforeRequestHook, requestCatchHook, transformResponseHook } = opt
100
- if (beforeRequestHook && isFunction(beforeRequestHook)) {
101
- conf = beforeRequestHook(opt)
102
- }
103
-
104
- conf = this.supportFormData(opt)
105
-
106
- return new Promise((resolve) => {
107
- this.axiosInstance
108
- .request<any, AxiosResponse>(conf)
109
- .then((res: AxiosResponse) => {
110
- if (transformResponseHook && isFunction(transformResponseHook)) {
111
- try {
112
- const ret = transformResponseHook(res, config)
113
- resolve(ret)
114
- } catch (err) {
115
- resolve(false as any)
116
- return
117
- }
118
- return
119
- }
120
- resolve(res as unknown as Promise<T>)
121
- })
122
- .catch((e: Error | AxiosError) => {
123
- if (requestCatchHook && isFunction(requestCatchHook)) {
124
- resolve(requestCatchHook(e) as any)
125
- return
126
- }
127
- resolve(false as any)
128
- })
129
- })
130
- }
131
- }
@@ -1,60 +0,0 @@
1
- import type { AxiosRequestConfig, Canceler } from 'axios'
2
- import axios from 'axios'
3
- import { isFunction } from '@gx-design-vue/pro-utils'
4
-
5
- // Used to store the identification and cancellation function of each request
6
- let pendingMap = new Map<string, Canceler>()
7
-
8
- export const getPendingUrl = (config: AxiosRequestConfig) => [ config.method, config.url ].join('&')
9
-
10
- export class AxiosCanceler {
11
- /**
12
- * Add request
13
- * @param {Object} config
14
- */
15
- addPending(config: AxiosRequestConfig) {
16
- this.removePending(config)
17
- const url = getPendingUrl(config)
18
- config.cancelToken =
19
- config.cancelToken ||
20
- new axios.CancelToken((cancel) => {
21
- if (!pendingMap.has(url)) {
22
- // If there is no current request in pending, add it
23
- pendingMap.set(url, cancel)
24
- }
25
- })
26
- }
27
-
28
- /**
29
- * @description: Clear all pending
30
- */
31
- removeAllPending() {
32
- pendingMap.forEach((cancel) => {
33
- cancel && isFunction(cancel) && cancel()
34
- })
35
- pendingMap.clear()
36
- }
37
-
38
- /**
39
- * Removal request
40
- * @param {Object} config
41
- */
42
- removePending(config: AxiosRequestConfig) {
43
- const url = getPendingUrl(config)
44
-
45
- if (pendingMap.has(url)) {
46
- // If there is a current request identifier in pending,
47
- // the current request needs to be cancelled and removed
48
- const cancel = pendingMap.get(url)
49
- cancel && cancel(url)
50
- pendingMap.delete(url)
51
- }
52
- }
53
-
54
- /**
55
- * @description: reset
56
- */
57
- reset(): void {
58
- pendingMap = new Map<string, Canceler>()
59
- }
60
- }
@@ -1,11 +0,0 @@
1
- import { showFailToast } from 'vant'
2
-
3
- /**
4
- * @author gx12358 2539306317@qq.com
5
- * @description 处理code异常
6
- * @param {*} code
7
- * @param {*} msg
8
- */
9
- export const handleCode = (code: number, msg: string) => {
10
- // 这里处理不同状态
11
- }
@@ -1,143 +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 { XhtInstance } from './typings'
10
- import { RequestEnum } from './typings'
11
- import type { GAxiosOptions } from './typings'
12
- import { handleCode } from './checkStatus'
13
-
14
- const { requestPrefix, successCode, requestTimeout, tokenName, contentType } = settings
15
-
16
- const xhtInstance: XhtInstance = {
17
- /**
18
- * @description: 处理响应数据。如果数据不是预期格式,可直接抛出错误
19
- */
20
- transformResponseHook: (res, options) => {
21
- const { customize, isReturnNativeResponse } = options
22
- // 是否返回原生响应头 比如:需要获取响应头时使用该属性
23
- if (isReturnNativeResponse) {
24
- return res
25
- }
26
- // 不进行任何处理,直接返回
27
- // 用于页面代码可能需要直接获取code,data,message这些信息时开启
28
- if (customize) {
29
- return res.data
30
- }
31
- // 错误的时候返回
32
-
33
- const { data }: { data: ResponseResult } = res
34
- if (!data) {
35
- throw new Error('请求出错,请稍候重试')
36
- }
37
- // 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
38
- const { code, msg = '', message = '' } = data
39
-
40
- const codeVerificationArray = successCode
41
-
42
- // 这里逻辑可以根据项目进行修改
43
- const hasSuccess = codeVerificationArray.includes(code)
44
- if (hasSuccess) {
45
- return data
46
- }
47
-
48
- // 在此处根据自己项目的实际情况对不同的code执行不同的操作
49
- // 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
50
- handleCode(code, message || msg)
51
-
52
- return Promise.resolve(false)
53
- },
54
-
55
- // 请求之前处理config
56
- beforeRequestHook: (config) => {
57
- // get请求映射params参数
58
- if (config.method?.toUpperCase() === RequestEnum.GET && config.params) {
59
- let url = config.url + '?' + tansParams(config.params)
60
- url = url.slice(0, -1)
61
- config.params = {}
62
- config.url = url
63
- }
64
-
65
- if (!checkURL(config.url)) {
66
- if (config.isMock) {
67
- config.url = `/mock-server${config.url}`
68
- } else {
69
- config.url = `${import.meta.env.VITE_BASE_URL}${isDev ? requestPrefix || '' : ''}${config.url}`
70
- }
71
- }
72
-
73
- return config
74
- },
75
-
76
- /**
77
- * @description: 请求拦截器处理
78
- */
79
- requestInterceptors: (config) => {
80
- const global = useStoreGlobal()
81
- const carryToken = isBoolean(config.carryToken) ? config.carryToken : true
82
- if (global.token && carryToken)
83
- config.headers[tokenName] = global.token
84
- return config
85
- },
86
-
87
- /**
88
- * @description: 响应拦截器处理
89
- */
90
- responseInterceptors: (res) => {
91
- return res
92
- },
93
-
94
- /**
95
- * @description: 响应错误处理
96
- */
97
- responseInterceptorsCatch: (error: any) => {
98
- const { response } = error
99
- let errorMessage = error.message || ''
100
- if (error.response && error.response.data) {
101
- const { status } = response
102
- handleCode(status, errorMessage)
103
- return Promise.resolve(false)
104
- } else {
105
- if (errorMessage === 'Network Error') {
106
- errorMessage = '后端接口连接异常'
107
- }
108
- if (errorMessage.includes('timeout')) {
109
- errorMessage = '后端接口请求超时'
110
- }
111
- if (errorMessage.includes('Request failed with status code')) {
112
- const code = errorMessage.substr(errorMessage.length - 3)
113
- errorMessage = '后端接口' + code || '' + '异常'
114
- }
115
- showFailToast({ message: errorMessage || '服务器出错!' })
116
- return Promise.resolve(false)
117
- }
118
- },
119
- /**
120
- * @description: 处理响应错误数据
121
- */
122
- requestCatchHook: () => false
123
- }
124
-
125
- function createXhr(opt ?: Partial<GAxiosOptions>) {
126
- return new GAxios({
127
- method: 'get',
128
- timeout: requestTimeout,
129
- headers: {
130
- 'Content-Type': contentType
131
- },
132
- // 忽略重复请求
133
- ignoreCancelToken: true,
134
- // 是否携带token
135
- carryToken: true,
136
- ...xhtInstance,
137
- ...opt
138
- })
139
- }
140
-
141
- const request: (opt?: GAxiosOptions) => Promise<ResponseResult> = (opt) => createXhr().request(opt)
142
-
143
- export default request
@@ -1,114 +0,0 @@
1
- import type { AxiosRequestConfig, AxiosResponse, Axios, AxiosPromise } from 'axios'
2
-
3
- export type XhtInstance = {
4
- /**
5
- * @Author gx12358
6
- * @DateTime 2023/1/6
7
- * @lastTime 2023/1/6
8
- * @description 请求之前处理config
9
- */
10
- beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
11
-
12
- /**
13
- * @description: 处理响应数据
14
- */
15
- transformResponseHook?: (res: AxiosResponse, options: GAxiosOptions) => any;
16
-
17
- /**
18
- * @description: 请求失败处理
19
- */
20
- requestCatchHook?: (e: Error) => boolean;
21
-
22
- /**
23
- * @description: 请求之前的拦截器
24
- */
25
- requestInterceptors?: (config: GAxiosOptions) => GAxiosOptions;
26
-
27
- /**
28
- * @description: 请求之后的拦截器
29
- */
30
- responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
31
-
32
- /**
33
- * @description: 请求之前的拦截器错误处理
34
- */
35
- requestInterceptorsCatch?: (error: Error) => void;
36
-
37
- /**
38
- * @description: 请求之后的拦截器错误处理
39
- */
40
- responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: Error) => void;
41
- }
42
-
43
- export interface GAxiosOptions extends AxiosRequestConfig {
44
- headers?: RecordType;
45
- isMock?: boolean; // 是否是mock
46
- isReturnNativeResponse?: boolean; // 直接返回response,不作任何处理(包含响应值等基本信息)
47
- customize?: boolean; // 直接返回response.data(接口返回值),错误不做统一提示
48
- carryToken?: boolean; // 是否携带token
49
- ignoreCancelToken?: boolean; // 忽略重复请求
50
- /**
51
- * @Author gx12358
52
- * @DateTime 2023/1/6
53
- * @lastTime 2023/1/6
54
- * @description 请求之前处理config
55
- */
56
- beforeRequestHook?: (config: GAxiosOptions) => GAxiosOptions;
57
-
58
- /**
59
- * @description: 处理响应数据
60
- */
61
- transformResponseHook?: (res: AxiosResponse, options: GAxiosOptions) => any;
62
-
63
- /**
64
- * @description: 请求失败处理
65
- */
66
- requestCatchHook?: (e: Error) => boolean;
67
-
68
- /**
69
- * @description: 请求之前的拦截器
70
- */
71
- requestInterceptors?: (config: GAxiosOptions) => GAxiosOptions;
72
-
73
- /**
74
- * @description: 请求之后的拦截器
75
- */
76
- responseInterceptors?: (res: AxiosResponse) => AxiosResponse;
77
-
78
- /**
79
- * @description: 请求之前的拦截器错误处理
80
- */
81
- requestInterceptorsCatch?: (error: Error) => void;
82
-
83
- /**
84
- * @description: 请求之后的拦截器错误处理
85
- */
86
- responseInterceptorsCatch?: (axiosInstance: GAxiosInstance, error: Error) => void;
87
- }
88
-
89
- export interface GAxiosInstance extends Axios {
90
- (config: GAxiosOptions): AxiosPromise<ResponseResult>;
91
-
92
- (url: string, config?: GAxiosOptions): AxiosPromise<ResponseResult>;
93
- }
94
-
95
- /**
96
- * @description: request method
97
- */
98
- export enum RequestEnum {
99
- GET = 'GET',
100
- POST = 'POST',
101
- PUT = 'PUT',
102
- DELETE = 'DELETE',
103
- }
104
-
105
- /**
106
- * @description: contentType
107
- */
108
- export enum ContentTypeEnum {
109
- // json
110
- JSON = 'application/json;charset=UTF-8',
111
- // form-data qs
112
- FORM_URLENCODED = 'application/x-www-form-urlencoded;charset=UTF-8',
113
- }
114
-