@gx-design-vue/create-gx-cli 0.1.9 → 0.1.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (181) hide show
  1. package/package.json +2 -1
  2. package/src/main.js +0 -4
  3. package/template-gx-design-thin/.editorconfig +19 -0
  4. package/template-gx-design-thin/.env +4 -0
  5. package/template-gx-design-thin/.env.development +15 -0
  6. package/template-gx-design-thin/.env.production +28 -0
  7. package/template-gx-design-thin/.eslintignore +16 -0
  8. package/template-gx-design-thin/.prettierignore +9 -0
  9. package/template-gx-design-thin/LICENSE +21 -0
  10. package/template-gx-design-thin/README.md +112 -0
  11. package/template-gx-design-thin/build/constant.ts +1 -0
  12. package/template-gx-design-thin/build/generate/generateModifyVars.ts +14 -0
  13. package/template-gx-design-thin/build/rollupOptions/index.ts +22 -0
  14. package/template-gx-design-thin/build/util/hash.ts +17 -0
  15. package/template-gx-design-thin/build/util/index.ts +131 -0
  16. package/template-gx-design-thin/build/vite/cdn.ts +63 -0
  17. package/template-gx-design-thin/build/vite/optimizer.ts +26 -0
  18. package/template-gx-design-thin/build/vite/plugin/appConfig.ts +91 -0
  19. package/template-gx-design-thin/build/vite/plugin/autoImport.ts +26 -0
  20. package/template-gx-design-thin/build/vite/plugin/compress.ts +31 -0
  21. package/template-gx-design-thin/build/vite/plugin/html.ts +39 -0
  22. package/template-gx-design-thin/build/vite/plugin/index.ts +75 -0
  23. package/template-gx-design-thin/build/vite/plugin/mock.ts +14 -0
  24. package/template-gx-design-thin/build/vite/plugin/pwa.ts +31 -0
  25. package/template-gx-design-thin/build/vite/plugin/visualizer.ts +14 -0
  26. package/template-gx-design-thin/build/vite/plugin/viteMock/client.ts +88 -0
  27. package/template-gx-design-thin/build/vite/plugin/viteMock/createMockServer.ts +271 -0
  28. package/template-gx-design-thin/build/vite/plugin/viteMock/index.ts +69 -0
  29. package/template-gx-design-thin/build/vite/plugin/viteMock/types.ts +48 -0
  30. package/template-gx-design-thin/build/vite/plugin/viteMock/utils.ts +48 -0
  31. package/template-gx-design-thin/build/vite/plugin/viteNotice.ts +40 -0
  32. package/template-gx-design-thin/commitlint.config.cjs +32 -0
  33. package/template-gx-design-thin/config/default/defaultSettings.ts +78 -0
  34. package/template-gx-design-thin/config/default/network.ts +10 -0
  35. package/template-gx-design-thin/config/default/proxy.ts +47 -0
  36. package/template-gx-design-thin/config/default/theme.ts +3 -0
  37. package/template-gx-design-thin/config/index.ts +11 -0
  38. package/template-gx-design-thin/eslint.config.js +51 -0
  39. package/template-gx-design-thin/index.html +42 -0
  40. package/template-gx-design-thin/mock/_createProductionServer.ts +19 -0
  41. package/template-gx-design-thin/mock/_util.ts +33 -0
  42. package/template-gx-design-thin/mock/config/menu.ts +21 -0
  43. package/template-gx-design-thin/mock/config/user.ts +123 -0
  44. package/template-gx-design-thin/mock/datasSource/system/menu.ts +10 -0
  45. package/template-gx-design-thin/mock/datasSource/user/account.ts +30 -0
  46. package/template-gx-design-thin/mock/datasSource/user/index.ts +47 -0
  47. package/template-gx-design-thin/mock/util/crypto.ts +23 -0
  48. package/template-gx-design-thin/mock/util/table.ts +92 -0
  49. package/template-gx-design-thin/mock/util/utils.ts +73 -0
  50. package/template-gx-design-thin/package.json +129 -0
  51. package/template-gx-design-thin/pnpm-lock.yaml +12575 -0
  52. package/template-gx-design-thin/prettier.config.cjs +18 -0
  53. package/template-gx-design-thin/public/resource/css/index.css +119 -0
  54. package/template-gx-design-thin/public/resource/css/normalize.css +396 -0
  55. package/template-gx-design-thin/public/resource/img/favicon.ico +0 -0
  56. package/template-gx-design-thin/public/resource/img/logo.png +0 -0
  57. package/template-gx-design-thin/public/resource/img/pro_icon.svg +1 -0
  58. package/template-gx-design-thin/public/resource/img/pwa-192x192.png +0 -0
  59. package/template-gx-design-thin/public/resource/img/pwa-512x512.png +0 -0
  60. package/template-gx-design-thin/src/App.vue +42 -0
  61. package/template-gx-design-thin/src/assets/error_images/403.png +0 -0
  62. package/template-gx-design-thin/src/assets/error_images/404.png +0 -0
  63. package/template-gx-design-thin/src/assets/error_images/cloud.png +0 -0
  64. package/template-gx-design-thin/src/assets/login_images/login_background.svg +1 -0
  65. package/template-gx-design-thin/src/assets/logo.png +0 -0
  66. package/template-gx-design-thin/src/assets/menu_font/iconfont.css +94 -0
  67. package/template-gx-design-thin/src/assets/menu_font/iconfont.eot +0 -0
  68. package/template-gx-design-thin/src/assets/menu_font/iconfont.js +1 -0
  69. package/template-gx-design-thin/src/assets/menu_font/iconfont.json +142 -0
  70. package/template-gx-design-thin/src/assets/menu_font/iconfont.svg +1 -0
  71. package/template-gx-design-thin/src/assets/menu_font/iconfont.ttf +0 -0
  72. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff +0 -0
  73. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff2 +0 -0
  74. package/template-gx-design-thin/src/assets/menu_font/index.less +94 -0
  75. package/template-gx-design-thin/src/assets/public_icon/iconfont.css +42 -0
  76. package/template-gx-design-thin/src/assets/public_icon/iconfont.eot +0 -0
  77. package/template-gx-design-thin/src/assets/public_icon/iconfont.js +1 -0
  78. package/template-gx-design-thin/src/assets/public_icon/iconfont.json +51 -0
  79. package/template-gx-design-thin/src/assets/public_icon/iconfont.svg +1 -0
  80. package/template-gx-design-thin/src/assets/public_icon/iconfont.ttf +0 -0
  81. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff +0 -0
  82. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff2 +0 -0
  83. package/template-gx-design-thin/src/assets/public_icon/index.less +42 -0
  84. package/template-gx-design-thin/src/assets/public_images/nodata.svg +1 -0
  85. package/template-gx-design-thin/src/common/global.ts +4 -0
  86. package/template-gx-design-thin/src/components/GDesign/Result/index.tsx +144 -0
  87. package/template-gx-design-thin/src/components/GDesign/Result/style.less +140 -0
  88. package/template-gx-design-thin/src/components/GDesign/utils/index.ts +7 -0
  89. package/template-gx-design-thin/src/components/GlobalLayout/Confirm/index.ts +21 -0
  90. package/template-gx-design-thin/src/components/GlobalLayout/Empty/index.vue +18 -0
  91. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/index.tsx +126 -0
  92. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/style.ts +77 -0
  93. package/template-gx-design-thin/src/components/GlobalLayout/Spin/index.tsx +30 -0
  94. package/template-gx-design-thin/src/components/PageLoading/index.tsx +51 -0
  95. package/template-gx-design-thin/src/components/index.ts +6 -0
  96. package/template-gx-design-thin/src/core/ant-design/index.ts +10 -0
  97. package/template-gx-design-thin/src/core/gx-admin-design/index.ts +6 -0
  98. package/template-gx-design-thin/src/core/gx-design/index.ts +6 -0
  99. package/template-gx-design-thin/src/core/gx-pro-design/index.ts +8 -0
  100. package/template-gx-design-thin/src/core/index.ts +84 -0
  101. package/template-gx-design-thin/src/design/ant-design/index.less +4 -0
  102. package/template-gx-design-thin/src/design/ant-design/layout.less +22 -0
  103. package/template-gx-design-thin/src/design/ant-design/menu.less +48 -0
  104. package/template-gx-design-thin/src/design/ant-design/spin.less +23 -0
  105. package/template-gx-design-thin/src/design/ant-design/tooltip.less +7 -0
  106. package/template-gx-design-thin/src/design/color.less +1 -0
  107. package/template-gx-design-thin/src/design/config.less +5 -0
  108. package/template-gx-design-thin/src/design/imageEditor.less +180 -0
  109. package/template-gx-design-thin/src/design/index.less +95 -0
  110. package/template-gx-design-thin/src/design/mixin.less +65 -0
  111. package/template-gx-design-thin/src/design/normalize.less +391 -0
  112. package/template-gx-design-thin/src/design/root.less +3 -0
  113. package/template-gx-design-thin/src/hooks/core/index.ts +3 -0
  114. package/template-gx-design-thin/src/hooks/core/useRequest/index.ts +118 -0
  115. package/template-gx-design-thin/src/hooks/event/index.ts +3 -0
  116. package/template-gx-design-thin/src/hooks/event/useClipboard.ts +15 -0
  117. package/template-gx-design-thin/src/hooks/web/index.ts +5 -0
  118. package/template-gx-design-thin/src/hooks/web/useThemeStyle.ts +16 -0
  119. package/template-gx-design-thin/src/layout/BasicLayout.vue +123 -0
  120. package/template-gx-design-thin/src/layout/BlankLayout.vue +5 -0
  121. package/template-gx-design-thin/src/layout/ContentView.vue +50 -0
  122. package/template-gx-design-thin/src/layout/IframeView.vue +1 -0
  123. package/template-gx-design-thin/src/layout/UserLayout.vue +7 -0
  124. package/template-gx-design-thin/src/main.ts +34 -0
  125. package/template-gx-design-thin/src/plugins/index.ts +2 -0
  126. package/template-gx-design-thin/src/router/guard/index.ts +83 -0
  127. package/template-gx-design-thin/src/router/guard/permissions.ts +70 -0
  128. package/template-gx-design-thin/src/router/guard/stateGuard.ts +10 -0
  129. package/template-gx-design-thin/src/router/helper/routeHelper.ts +231 -0
  130. package/template-gx-design-thin/src/router/helper/utils.ts +19 -0
  131. package/template-gx-design-thin/src/router/index.ts +31 -0
  132. package/template-gx-design-thin/src/router/routes/index.ts +86 -0
  133. package/template-gx-design-thin/src/router/routes/modules/dataSource.ts +12 -0
  134. package/template-gx-design-thin/src/services/common/index.ts +11 -0
  135. package/template-gx-design-thin/src/services/systemCenter/index.ts +1 -0
  136. package/template-gx-design-thin/src/services/systemCenter/menu.ts +9 -0
  137. package/template-gx-design-thin/src/services/userCenter/account.ts +42 -0
  138. package/template-gx-design-thin/src/services/userCenter/index.ts +28 -0
  139. package/template-gx-design-thin/src/store/index.ts +32 -0
  140. package/template-gx-design-thin/src/store/modules/dict.ts +28 -0
  141. package/template-gx-design-thin/src/store/modules/global.ts +42 -0
  142. package/template-gx-design-thin/src/store/modules/permission.ts +19 -0
  143. package/template-gx-design-thin/src/store/modules/routes.ts +113 -0
  144. package/template-gx-design-thin/src/store/modules/tabsRouter.ts +76 -0
  145. package/template-gx-design-thin/src/store/modules/user.ts +136 -0
  146. package/template-gx-design-thin/src/utils/accessToken.ts +80 -0
  147. package/template-gx-design-thin/src/utils/crypto/base64.ts +101 -0
  148. package/template-gx-design-thin/src/utils/crypto/index.ts +57 -0
  149. package/template-gx-design-thin/src/utils/env.ts +50 -0
  150. package/template-gx-design-thin/src/utils/fetchFile.ts +81 -0
  151. package/template-gx-design-thin/src/utils/index.ts +123 -0
  152. package/template-gx-design-thin/src/utils/pageTitle.ts +20 -0
  153. package/template-gx-design-thin/src/utils/request/XHR.ts +139 -0
  154. package/template-gx-design-thin/src/utils/request/axiosCancel.ts +69 -0
  155. package/template-gx-design-thin/src/utils/request/checkStatus.ts +25 -0
  156. package/template-gx-design-thin/src/utils/request/index.ts +144 -0
  157. package/template-gx-design-thin/src/utils/request/typings.ts +171 -0
  158. package/template-gx-design-thin/src/utils/storage.ts +199 -0
  159. package/template-gx-design-thin/src/utils/uploadFile.ts +27 -0
  160. package/template-gx-design-thin/src/utils/util.ts +198 -0
  161. package/template-gx-design-thin/src/utils/validate.ts +216 -0
  162. package/template-gx-design-thin/src/views/Iframe/index.vue +76 -0
  163. package/template-gx-design-thin/src/views/Page/one.vue +13 -0
  164. package/template-gx-design-thin/src/views/Page/two.vue +13 -0
  165. package/template-gx-design-thin/src/views/exception/403/index.vue +7 -0
  166. package/template-gx-design-thin/src/views/exception/404/index.vue +9 -0
  167. package/template-gx-design-thin/src/views/user/login/index.vue +109 -0
  168. package/template-gx-design-thin/src/views/user/login/style.less +38 -0
  169. package/template-gx-design-thin/tsconfig.json +46 -0
  170. package/template-gx-design-thin/types/ant-design-import.d.ts +99 -0
  171. package/template-gx-design-thin/types/auto-imports.d.ts +81 -0
  172. package/template-gx-design-thin/types/components.d.ts +24 -0
  173. package/template-gx-design-thin/types/config.d.ts +44 -0
  174. package/template-gx-design-thin/types/global.d.ts +97 -0
  175. package/template-gx-design-thin/types/mock.d.ts +16 -0
  176. package/template-gx-design-thin/types/module.d.ts +20 -0
  177. package/template-gx-design-thin/types/response.d.ts +15 -0
  178. package/template-gx-design-thin/unocss.config.ts +101 -0
  179. package/template-gx-design-thin/vite.config.ts +120 -0
  180. package/template-gx-design-thin/yarn.lock +9492 -0
  181. package/template-mobile-vant-cli/package.json +1 -1
@@ -0,0 +1,144 @@
1
+ import { message } from 'ant-design-vue'
2
+ import { defaultSettings, network } from '@gx-config'
3
+ import { useStoreUser } from '@/store'
4
+ import { isDev, typeViteEnv } 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 { tokenName, requestPrefix, mockPrefixUrl } = defaultSettings
14
+
15
+ const { requestTimeout, successCode } = network
16
+
17
+ const xhtInstance: XhtInstance = {
18
+ /**
19
+ * @description: 处理响应数据。如果数据不是预期格式,可直接抛出错误
20
+ */
21
+ transformResponseHook: (res, options) => {
22
+ const { customize, isReturnNativeResponse } = options
23
+ // 是否返回原生响应头 比如:需要获取响应头时使用该属性
24
+ if (isReturnNativeResponse) {
25
+ return res
26
+ }
27
+ // 不进行任何处理,直接返回
28
+ // 用于页面代码可能需要直接获取code,data,message这些信息时开启
29
+ if (customize) {
30
+ return res.data
31
+ }
32
+ // 错误的时候返回
33
+
34
+ const { data }: { data: ResponseResult } = res
35
+ if (!data) {
36
+ throw new Error('请求出错,请稍候重试')
37
+ }
38
+ // 这里 code,result,message为 后台统一的字段,需要在 types.ts内修改为项目自己的接口返回格式
39
+ const { code, msg = '', message = '' } = data
40
+
41
+ const codeVerificationArray = successCode
42
+
43
+ // 这里逻辑可以根据项目进行修改
44
+ const hasSuccess = codeVerificationArray.includes(code)
45
+ if (hasSuccess) {
46
+ return data
47
+ }
48
+
49
+ // 在此处根据自己项目的实际情况对不同的code执行不同的操作
50
+ // 如果不希望中断当前请求,请return数据,否则直接抛出异常即可
51
+ handleCode(code, message || msg)
52
+
53
+ return Promise.resolve(false)
54
+ },
55
+
56
+ // 请求之前处理config
57
+ beforeRequestHook: (config) => {
58
+ // get请求映射params参数
59
+ if (config.method?.toUpperCase() === RequestEnum.GET && config.params) {
60
+ let url = config.url + '?' + tansParams(config.params)
61
+ url = url.slice(0, -1)
62
+ config.params = {}
63
+ config.url = url
64
+ }
65
+
66
+ if (!checkURL(config.url)) {
67
+ if (config.isMock) {
68
+ config.url = `${mockPrefixUrl}${config.url}`
69
+ } else {
70
+ config.url = `${typeViteEnv('VITE_BASE_URL')}${isDev ? requestPrefix || '' : ''}${config.url}`
71
+ }
72
+ }
73
+
74
+ return config
75
+ },
76
+
77
+ /**
78
+ * @description: 请求拦截器处理
79
+ */
80
+ requestInterceptors: (config) => {
81
+ const user = useStoreUser()
82
+ const carryToken = isBoolean(config.carryToken) ? config.carryToken : true
83
+ if (user.accessToken && carryToken)
84
+ config.headers[tokenName] = user.accessToken
85
+ return config
86
+ },
87
+
88
+ /**
89
+ * @description: 响应拦截器处理
90
+ */
91
+ responseInterceptors: (res) => {
92
+ return res
93
+ },
94
+
95
+ /**
96
+ * @description: 响应错误处理
97
+ */
98
+ responseInterceptorsCatch: (_, error) => {
99
+ const { response } = error
100
+ let errorMessage = error.message || ''
101
+ if (error.response && error.response.data) {
102
+ const { status } = response
103
+ handleCode(status, errorMessage)
104
+ return Promise.resolve(false)
105
+ } else {
106
+ if (errorMessage === 'Network Error') {
107
+ errorMessage = '后端接口连接异常'
108
+ }
109
+ if (errorMessage.includes('timeout')) {
110
+ errorMessage = '后端接口请求超时'
111
+ }
112
+ if (errorMessage.includes('Request failed with status code')) {
113
+ const code = errorMessage.substr(errorMessage.length - 3)
114
+ errorMessage = '后端接口' + code || '' + '异常'
115
+ }
116
+ message.error(errorMessage || `后端接口未知异常`)
117
+ return Promise.resolve(false)
118
+ }
119
+ },
120
+ /**
121
+ * @description: 处理响应错误数据
122
+ */
123
+ requestCatchHook: () => false
124
+ }
125
+
126
+ function createXhr(opt?: Partial<GAxiosOptions>) {
127
+ return new GAxios({
128
+ method: 'get',
129
+ timeout: requestTimeout,
130
+ headers: {
131
+ 'Content-Type': 'application/json;charset=UTF-8'
132
+ },
133
+ // 忽略重复请求
134
+ ignoreCancelToken: true,
135
+ // 是否携带token
136
+ carryToken: true,
137
+ ...xhtInstance,
138
+ ...opt
139
+ })
140
+ }
141
+
142
+ const request: <T = any, R = undefined>(opt?: GAxiosOptions) => Promise<ResponseResult<T, R>> = opt => createXhr().request(opt)
143
+
144
+ export default request
@@ -0,0 +1,171 @@
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
+ }
@@ -0,0 +1,199 @@
1
+ import dayjs from 'dayjs'
2
+ import { defaultSettings } from '@gx-config'
3
+ import { isPro, typeViteEnv } from '@/utils/env'
4
+ import { Decrypt, Encrypt } from '@/utils/crypto'
5
+ import { isJSONStr } from '@/utils/validate'
6
+ import { isObject } from '@gx-design-vue/pro-utils'
7
+
8
+ const { shortName } = defaultSettings
9
+
10
+ function isEncryption(status: boolean) {
11
+ return isPro() ? status : false
12
+ }
13
+
14
+ function handleStorageValue(value: string) {
15
+ if (isJSONStr(value))
16
+ return JSON.parse(value)
17
+ return value
18
+ }
19
+
20
+ /**
21
+ * @Author gx12358
22
+ * @DateTime 2019/12/3
23
+ * @lastTime 2019/12/3
24
+ * @description 设置Local-key的规则
25
+ */
26
+ export function getStorageKey(key: string, originKey?: boolean) {
27
+ const { pkg } = __APP_INFO__
28
+ return originKey ? key : `${shortName}_${pkg.version}_${typeViteEnv('VITE_APP_ENV') === 'dev'
29
+ ? 'development'
30
+ : typeViteEnv('VITE_USE_MODE')}_${key}`
31
+ }
32
+
33
+ /**
34
+ * @Author gx12358
35
+ * @DateTime 2019/12/3
36
+ * @lastTime 2019/12/3
37
+ * @description 获取Storage
38
+ */
39
+ export function getStorage({
40
+ key,
41
+ encryption = true,
42
+ type = 'localStorage',
43
+ originKey
44
+ }: { key: string, encryption?: boolean, type?: SettingConfig['storage'], originKey?: boolean }) {
45
+ const storageValue = type === 'localStorage'
46
+ ? localStorage.getItem(getStorageKey(key, originKey)) : type === 'sessionStorage'
47
+ ? sessionStorage.getItem(getStorageKey(key, originKey))
48
+ : getCookie(
49
+ getStorageKey(key, originKey))
50
+ const result: string | LocalResult = storageValue
51
+ ? isEncryption(encryption) ? Decrypt(storageValue) : handleStorageValue(storageValue) : ''
52
+ if (result && isObject(result)) {
53
+ if (result.expired) {
54
+ const expiredStatus = dayjs().diff(dayjs(result.time)) >= result.expired
55
+ if (expiredStatus) {
56
+ removeStorage(key, type)
57
+ return ''
58
+ }
59
+ }
60
+ }
61
+ return result?.['value'] || result || ''
62
+ }
63
+
64
+ /**
65
+ * @Author gx12358
66
+ * @DateTime 2019/12/3
67
+ * @lastTime 2019/12/3
68
+ * @description 设置Storage
69
+ */
70
+ export function setStorage({
71
+ key,
72
+ value,
73
+ expired,
74
+ originKey,
75
+ encryption = true,
76
+ type = 'local'
77
+ }: {
78
+ key: string;
79
+ value: any;
80
+ originKey?: boolean;
81
+ expired?: number;
82
+ encryption?: boolean;
83
+ type?: string;
84
+ }) {
85
+ const result: LocalResult = originKey ? value : {
86
+ value,
87
+ time: dayjs().format('YYYY-MM-DD HH:mm:ss'),
88
+ expired: expired || 0
89
+ }
90
+ const storageValue = isEncryption(encryption) ? Encrypt(JSON.stringify(result)) : JSON.stringify(
91
+ result)
92
+ if (type === 'local')
93
+ localStorage.setItem(getStorageKey(key, originKey), storageValue)
94
+ sessionStorage.setItem(getStorageKey(key, originKey), storageValue)
95
+ }
96
+
97
+ /**
98
+ * @Author gx12358
99
+ * @DateTime 2019/12/3
100
+ * @lastTime 2019/12/3
101
+ * @description 删除Storage
102
+ */
103
+ export function removeStorage(key: string, type = 'local', originKey?: boolean) {
104
+ if (type === 'local')
105
+ localStorage.removeItem(getStorageKey(key, originKey))
106
+ sessionStorage.removeItem(getStorageKey(key, originKey))
107
+ }
108
+
109
+ /**
110
+ * @Author gx12358
111
+ * @DateTime 2019-09-24
112
+ * @lastTime 2019-09-24
113
+ * @description 获取Cookie-name
114
+ */
115
+ function getCookies(cname: string) {
116
+ const name = `${cname}=`
117
+ const decodedCookie = decodeURIComponent(document.cookie)
118
+ const ca = decodedCookie.split(';')
119
+ for (let i = 0; i < ca.length; i += 1) {
120
+ let c = ca[i]
121
+ while (c.charAt(0) === ' ') {
122
+ c = c.substring(1)
123
+ }
124
+ if (c.indexOf(name) === 0) {
125
+ return decodeURIComponent(c.substring(name.length, c.length))
126
+ }
127
+ }
128
+ return ''
129
+ }
130
+
131
+ /**
132
+ * @Author gx12358
133
+ * @DateTime 2019-09-24
134
+ * @lastTime 2019-09-24
135
+ * @description 获取Cookiedomin
136
+ */
137
+ function GetCookieDomain() {
138
+ let host = location.hostname
139
+ 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])$/
140
+ if (ip.test(host) === true || host === 'localhost')
141
+ return host
142
+ const regex = /([^]*).*/
143
+ const match = host.match(regex)
144
+ if (typeof match !== 'undefined' && match !== null) {
145
+ const someIndex = 1
146
+ host = match[someIndex]
147
+ }
148
+ if (typeof host !== 'undefined' && host !== null) {
149
+ const strAry = host.split('.')
150
+ if (strAry.length > 1) {
151
+ host = `${strAry[strAry.length - 2]}.${strAry[strAry.length - 1]}`
152
+ }
153
+ }
154
+ return `.${host}`
155
+ }
156
+
157
+ /**
158
+ * @Author gx12358
159
+ * @DateTime 2019-09-24
160
+ * @lastTime 2019-09-24
161
+ * @description 设置Cookie
162
+ */
163
+ export function setCookie(cname: string, cvalue: string, exdays?: number) {
164
+ const d = new Date()
165
+ d.setTime(d.getTime() + (exdays || 365) * 24 * 60 * 60 * 1000)
166
+ const expires = `=${d.toUTCString()}`
167
+ document.cookie = `${cname}=${encodeURIComponent(
168
+ cvalue
169
+ )}; expires=${expires}; domain=${GetCookieDomain()}; path=/`
170
+ }
171
+
172
+ /**
173
+ * @Author gx12358
174
+ * @DateTime 2019-09-24
175
+ * @lastTime 2019-09-24
176
+ * @description 获取Cookie
177
+ */
178
+ export function getCookie(cname: string) {
179
+ const result = getCookies(cname)
180
+ if (result === '') {
181
+ return ''
182
+ }
183
+ return decodeURIComponent(result)
184
+ }
185
+
186
+ /**
187
+ * @Author gx12358
188
+ * @DateTime 2019-09-24
189
+ * @lastTime 2019-09-24
190
+ * @description 删除Cookie
191
+ */
192
+ export function delCookie(name: string) {
193
+ const exp = new Date()
194
+ exp.setTime(exp.getTime() - 1)
195
+ const cval = getCookies(name)
196
+ if (cval !== null) {
197
+ document.cookie = `${name}=; expires=Thu, 01 Jan 1970 00:00:00 UTC; domain=${GetCookieDomain()}; path=/`
198
+ }
199
+ }
@@ -0,0 +1,27 @@
1
+ import dayjs from 'dayjs'
2
+ import { getRandomNumber } from '@gx-design-vue/pro-utils'
3
+
4
+ /**
5
+ * @Author gx12358
6
+ * @DateTime 2022/4/22
7
+ * @lastTime 2022/4/22
8
+ * @description 修改文件名
9
+ */
10
+ export const createFileName = ({
11
+ file,
12
+ name
13
+ }: {
14
+ file: File | string;
15
+ name?: string;
16
+ }) => {
17
+ if (name !== 'image' && name !== 'vod')
18
+ return name
19
+ const names = file instanceof File ? file.name.split('.') : file.split('.')
20
+ const time1 = dayjs().format('YYYYMMDDHH')
21
+ const uuid = `${name || 'vod'}/creator/${time1}/${getRandomNumber().uuid(32).toLowerCase()}`
22
+ if (names.length > 1) {
23
+ return uuid + '.' + names[names.length - 1]
24
+ } else {
25
+ return uuid
26
+ }
27
+ }