@gx-design-vue/create-gx-cli 0.1.12 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (184) hide show
  1. package/bin/create-gx-cli +3 -2
  2. package/package.json +4 -4
  3. package/src/cli.js +9 -7
  4. package/src/git.js +8 -5
  5. package/src/main.js +29 -16
  6. package/template-mobile-vant-cli/package.json +5 -5
  7. package/template-gx-design-thin/.editorconfig +0 -19
  8. package/template-gx-design-thin/.env +0 -4
  9. package/template-gx-design-thin/.env.development +0 -15
  10. package/template-gx-design-thin/.env.production +0 -28
  11. package/template-gx-design-thin/.eslintignore +0 -16
  12. package/template-gx-design-thin/.prettierignore +0 -9
  13. package/template-gx-design-thin/LICENSE +0 -21
  14. package/template-gx-design-thin/README.md +0 -112
  15. package/template-gx-design-thin/build/constant.ts +0 -1
  16. package/template-gx-design-thin/build/generate/generateModifyVars.ts +0 -14
  17. package/template-gx-design-thin/build/rollupOptions/index.ts +0 -22
  18. package/template-gx-design-thin/build/util/hash.ts +0 -17
  19. package/template-gx-design-thin/build/util/index.ts +0 -131
  20. package/template-gx-design-thin/build/vite/cdn.ts +0 -63
  21. package/template-gx-design-thin/build/vite/optimizer.ts +0 -26
  22. package/template-gx-design-thin/build/vite/plugin/appConfig.ts +0 -91
  23. package/template-gx-design-thin/build/vite/plugin/autoImport.ts +0 -26
  24. package/template-gx-design-thin/build/vite/plugin/compress.ts +0 -31
  25. package/template-gx-design-thin/build/vite/plugin/html.ts +0 -39
  26. package/template-gx-design-thin/build/vite/plugin/index.ts +0 -75
  27. package/template-gx-design-thin/build/vite/plugin/mock.ts +0 -14
  28. package/template-gx-design-thin/build/vite/plugin/pwa.ts +0 -31
  29. package/template-gx-design-thin/build/vite/plugin/visualizer.ts +0 -14
  30. package/template-gx-design-thin/build/vite/plugin/viteMock/client.ts +0 -88
  31. package/template-gx-design-thin/build/vite/plugin/viteMock/createMockServer.ts +0 -271
  32. package/template-gx-design-thin/build/vite/plugin/viteMock/index.ts +0 -69
  33. package/template-gx-design-thin/build/vite/plugin/viteMock/types.ts +0 -48
  34. package/template-gx-design-thin/build/vite/plugin/viteMock/utils.ts +0 -48
  35. package/template-gx-design-thin/build/vite/plugin/viteNotice.ts +0 -40
  36. package/template-gx-design-thin/commitlint.config.cjs +0 -32
  37. package/template-gx-design-thin/config/default/defaultSettings.ts +0 -78
  38. package/template-gx-design-thin/config/default/network.ts +0 -10
  39. package/template-gx-design-thin/config/default/proxy.ts +0 -47
  40. package/template-gx-design-thin/config/default/theme.ts +0 -3
  41. package/template-gx-design-thin/config/index.ts +0 -11
  42. package/template-gx-design-thin/eslint.config.js +0 -51
  43. package/template-gx-design-thin/index.html +0 -42
  44. package/template-gx-design-thin/mock/_createProductionServer.ts +0 -19
  45. package/template-gx-design-thin/mock/_util.ts +0 -33
  46. package/template-gx-design-thin/mock/config/menu.ts +0 -21
  47. package/template-gx-design-thin/mock/config/user.ts +0 -123
  48. package/template-gx-design-thin/mock/datasSource/system/menu.ts +0 -10
  49. package/template-gx-design-thin/mock/datasSource/user/account.ts +0 -30
  50. package/template-gx-design-thin/mock/datasSource/user/index.ts +0 -47
  51. package/template-gx-design-thin/mock/util/crypto.ts +0 -23
  52. package/template-gx-design-thin/mock/util/table.ts +0 -92
  53. package/template-gx-design-thin/mock/util/utils.ts +0 -73
  54. package/template-gx-design-thin/package.json +0 -129
  55. package/template-gx-design-thin/pnpm-lock.yaml +0 -12575
  56. package/template-gx-design-thin/prettier.config.cjs +0 -18
  57. package/template-gx-design-thin/public/resource/css/index.css +0 -119
  58. package/template-gx-design-thin/public/resource/css/normalize.css +0 -396
  59. package/template-gx-design-thin/public/resource/img/favicon.ico +0 -0
  60. package/template-gx-design-thin/public/resource/img/logo.png +0 -0
  61. package/template-gx-design-thin/public/resource/img/pro_icon.svg +0 -1
  62. package/template-gx-design-thin/public/resource/img/pwa-192x192.png +0 -0
  63. package/template-gx-design-thin/public/resource/img/pwa-512x512.png +0 -0
  64. package/template-gx-design-thin/src/App.vue +0 -42
  65. package/template-gx-design-thin/src/assets/error_images/403.png +0 -0
  66. package/template-gx-design-thin/src/assets/error_images/404.png +0 -0
  67. package/template-gx-design-thin/src/assets/error_images/cloud.png +0 -0
  68. package/template-gx-design-thin/src/assets/login_images/login_background.svg +0 -1
  69. package/template-gx-design-thin/src/assets/logo.png +0 -0
  70. package/template-gx-design-thin/src/assets/menu_font/iconfont.css +0 -94
  71. package/template-gx-design-thin/src/assets/menu_font/iconfont.eot +0 -0
  72. package/template-gx-design-thin/src/assets/menu_font/iconfont.js +0 -1
  73. package/template-gx-design-thin/src/assets/menu_font/iconfont.json +0 -142
  74. package/template-gx-design-thin/src/assets/menu_font/iconfont.svg +0 -1
  75. package/template-gx-design-thin/src/assets/menu_font/iconfont.ttf +0 -0
  76. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff +0 -0
  77. package/template-gx-design-thin/src/assets/menu_font/iconfont.woff2 +0 -0
  78. package/template-gx-design-thin/src/assets/menu_font/index.less +0 -94
  79. package/template-gx-design-thin/src/assets/public_icon/iconfont.css +0 -42
  80. package/template-gx-design-thin/src/assets/public_icon/iconfont.eot +0 -0
  81. package/template-gx-design-thin/src/assets/public_icon/iconfont.js +0 -1
  82. package/template-gx-design-thin/src/assets/public_icon/iconfont.json +0 -51
  83. package/template-gx-design-thin/src/assets/public_icon/iconfont.svg +0 -1
  84. package/template-gx-design-thin/src/assets/public_icon/iconfont.ttf +0 -0
  85. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff +0 -0
  86. package/template-gx-design-thin/src/assets/public_icon/iconfont.woff2 +0 -0
  87. package/template-gx-design-thin/src/assets/public_icon/index.less +0 -42
  88. package/template-gx-design-thin/src/assets/public_images/nodata.svg +0 -1
  89. package/template-gx-design-thin/src/common/global.ts +0 -4
  90. package/template-gx-design-thin/src/components/GDesign/Result/index.tsx +0 -144
  91. package/template-gx-design-thin/src/components/GDesign/Result/style.less +0 -140
  92. package/template-gx-design-thin/src/components/GDesign/utils/index.ts +0 -7
  93. package/template-gx-design-thin/src/components/GlobalLayout/Confirm/index.ts +0 -21
  94. package/template-gx-design-thin/src/components/GlobalLayout/Empty/index.vue +0 -18
  95. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/index.tsx +0 -126
  96. package/template-gx-design-thin/src/components/GlobalLayout/RightContent/style.ts +0 -77
  97. package/template-gx-design-thin/src/components/GlobalLayout/Spin/index.tsx +0 -30
  98. package/template-gx-design-thin/src/components/PageLoading/index.tsx +0 -51
  99. package/template-gx-design-thin/src/components/index.ts +0 -6
  100. package/template-gx-design-thin/src/core/ant-design/index.ts +0 -10
  101. package/template-gx-design-thin/src/core/gx-admin-design/index.ts +0 -6
  102. package/template-gx-design-thin/src/core/gx-design/index.ts +0 -6
  103. package/template-gx-design-thin/src/core/gx-pro-design/index.ts +0 -8
  104. package/template-gx-design-thin/src/core/index.ts +0 -84
  105. package/template-gx-design-thin/src/design/ant-design/index.less +0 -4
  106. package/template-gx-design-thin/src/design/ant-design/layout.less +0 -22
  107. package/template-gx-design-thin/src/design/ant-design/menu.less +0 -48
  108. package/template-gx-design-thin/src/design/ant-design/spin.less +0 -23
  109. package/template-gx-design-thin/src/design/ant-design/tooltip.less +0 -7
  110. package/template-gx-design-thin/src/design/color.less +0 -1
  111. package/template-gx-design-thin/src/design/config.less +0 -5
  112. package/template-gx-design-thin/src/design/imageEditor.less +0 -180
  113. package/template-gx-design-thin/src/design/index.less +0 -95
  114. package/template-gx-design-thin/src/design/mixin.less +0 -65
  115. package/template-gx-design-thin/src/design/normalize.less +0 -391
  116. package/template-gx-design-thin/src/design/root.less +0 -3
  117. package/template-gx-design-thin/src/hooks/core/index.ts +0 -3
  118. package/template-gx-design-thin/src/hooks/core/useRequest/index.ts +0 -118
  119. package/template-gx-design-thin/src/hooks/event/index.ts +0 -3
  120. package/template-gx-design-thin/src/hooks/event/useClipboard.ts +0 -15
  121. package/template-gx-design-thin/src/hooks/web/index.ts +0 -5
  122. package/template-gx-design-thin/src/hooks/web/useThemeStyle.ts +0 -16
  123. package/template-gx-design-thin/src/layout/BasicLayout.vue +0 -123
  124. package/template-gx-design-thin/src/layout/BlankLayout.vue +0 -5
  125. package/template-gx-design-thin/src/layout/ContentView.vue +0 -50
  126. package/template-gx-design-thin/src/layout/IframeView.vue +0 -1
  127. package/template-gx-design-thin/src/layout/UserLayout.vue +0 -7
  128. package/template-gx-design-thin/src/main.ts +0 -34
  129. package/template-gx-design-thin/src/plugins/index.ts +0 -2
  130. package/template-gx-design-thin/src/router/guard/index.ts +0 -83
  131. package/template-gx-design-thin/src/router/guard/permissions.ts +0 -70
  132. package/template-gx-design-thin/src/router/guard/stateGuard.ts +0 -10
  133. package/template-gx-design-thin/src/router/helper/routeHelper.ts +0 -223
  134. package/template-gx-design-thin/src/router/helper/utils.ts +0 -19
  135. package/template-gx-design-thin/src/router/index.ts +0 -31
  136. package/template-gx-design-thin/src/router/routes/index.ts +0 -86
  137. package/template-gx-design-thin/src/router/routes/modules/dataSource.ts +0 -12
  138. package/template-gx-design-thin/src/services/common/index.ts +0 -11
  139. package/template-gx-design-thin/src/services/systemCenter/index.ts +0 -1
  140. package/template-gx-design-thin/src/services/systemCenter/menu.ts +0 -9
  141. package/template-gx-design-thin/src/services/userCenter/account.ts +0 -42
  142. package/template-gx-design-thin/src/services/userCenter/index.ts +0 -28
  143. package/template-gx-design-thin/src/store/index.ts +0 -32
  144. package/template-gx-design-thin/src/store/modules/dict.ts +0 -28
  145. package/template-gx-design-thin/src/store/modules/global.ts +0 -42
  146. package/template-gx-design-thin/src/store/modules/permission.ts +0 -19
  147. package/template-gx-design-thin/src/store/modules/routes.ts +0 -113
  148. package/template-gx-design-thin/src/store/modules/tabsRouter.ts +0 -76
  149. package/template-gx-design-thin/src/store/modules/user.ts +0 -136
  150. package/template-gx-design-thin/src/utils/accessToken.ts +0 -80
  151. package/template-gx-design-thin/src/utils/crypto/base64.ts +0 -101
  152. package/template-gx-design-thin/src/utils/crypto/index.ts +0 -57
  153. package/template-gx-design-thin/src/utils/env.ts +0 -50
  154. package/template-gx-design-thin/src/utils/fetchFile.ts +0 -81
  155. package/template-gx-design-thin/src/utils/index.ts +0 -123
  156. package/template-gx-design-thin/src/utils/pageTitle.ts +0 -20
  157. package/template-gx-design-thin/src/utils/request/XHR.ts +0 -139
  158. package/template-gx-design-thin/src/utils/request/axiosCancel.ts +0 -69
  159. package/template-gx-design-thin/src/utils/request/checkStatus.ts +0 -25
  160. package/template-gx-design-thin/src/utils/request/index.ts +0 -144
  161. package/template-gx-design-thin/src/utils/request/typings.ts +0 -171
  162. package/template-gx-design-thin/src/utils/storage.ts +0 -199
  163. package/template-gx-design-thin/src/utils/uploadFile.ts +0 -27
  164. package/template-gx-design-thin/src/utils/util.ts +0 -198
  165. package/template-gx-design-thin/src/utils/validate.ts +0 -216
  166. package/template-gx-design-thin/src/views/Iframe/index.vue +0 -76
  167. package/template-gx-design-thin/src/views/Page/one.vue +0 -13
  168. package/template-gx-design-thin/src/views/Page/two.vue +0 -13
  169. package/template-gx-design-thin/src/views/exception/403/index.vue +0 -7
  170. package/template-gx-design-thin/src/views/exception/404/index.vue +0 -9
  171. package/template-gx-design-thin/src/views/user/login/index.vue +0 -109
  172. package/template-gx-design-thin/src/views/user/login/style.less +0 -38
  173. package/template-gx-design-thin/tsconfig.json +0 -46
  174. package/template-gx-design-thin/types/ant-design-import.d.ts +0 -99
  175. package/template-gx-design-thin/types/auto-imports.d.ts +0 -81
  176. package/template-gx-design-thin/types/components.d.ts +0 -24
  177. package/template-gx-design-thin/types/config.d.ts +0 -44
  178. package/template-gx-design-thin/types/global.d.ts +0 -97
  179. package/template-gx-design-thin/types/mock.d.ts +0 -16
  180. package/template-gx-design-thin/types/module.d.ts +0 -20
  181. package/template-gx-design-thin/types/response.d.ts +0 -15
  182. package/template-gx-design-thin/unocss.config.ts +0 -101
  183. package/template-gx-design-thin/vite.config.ts +0 -120
  184. package/template-gx-design-thin/yarn.lock +0 -9492
@@ -1,57 +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 CryptoProJS from 'crypto-js'
6
- import { isJSONStr } from '@/utils/validate'
7
- import { isArray, isObject } from '@gx-design-vue/pro-utils'
8
-
9
- const key = '1234123412ABCDEF' // 十六位十六进制数作为密钥
10
-
11
- /**
12
- * 登录密码加密
13
- * @param password
14
- * @returns {string}
15
- */
16
- export const encodePassword = (password: string) => {
17
- const key = CryptoProJS.enc.Utf8.parse('8QONwyJtHesysWpM')
18
- const passwordENC = CryptoProJS.AES.encrypt(password, key, {
19
- mode: CryptoProJS.mode.ECB,
20
- padding: CryptoProJS.pad.Pkcs7
21
- })
22
- const encodePW = passwordENC.ciphertext.toString()
23
- return encodePW
24
- }
25
-
26
- // 加密方法
27
- export function Encrypt(word) {
28
- let str: string | object = word
29
- if (isObject(word) || isArray(word)) {
30
- str = JSON.stringify(word)
31
- }
32
- const keyHex = CryptoJS.enc.Utf8.parse(key)
33
- const ivHex = CryptoJS.enc.Utf8.parse(key)
34
- const encrypted = CryptoJS.DES.encrypt(str, keyHex, {
35
- iv: ivHex,
36
- mode: CryptoJS.mode.CBC,
37
- padding: CryptoJS.pad.Pkcs7
38
- })
39
- return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
40
- }
41
-
42
- // 解密方法
43
- export function Decrypt(word) {
44
- const keyHex = CryptoJS.enc.Utf8.parse(key)
45
- const ivHex = CryptoJS.enc.Utf8.parse(key)
46
- const decrypted = CryptoJS.DES.decrypt({
47
- ciphertext: CryptoJS.enc.Base64.parse(word)
48
- }, keyHex, {
49
- iv: ivHex,
50
- mode: CryptoJS.mode.CBC,
51
- padding: CryptoJS.pad.Pkcs7
52
- })
53
- const decryptedStr = decrypted.toString(CryptoJS.enc.Utf8)
54
- return isJSONStr(decryptedStr.toString())
55
- ? JSON.parse(decryptedStr.toString())
56
- : decryptedStr.toString()
57
- }
@@ -1,50 +0,0 @@
1
- /**
2
- * @Author gx12358
3
- * @DateTime 2022/4/1
4
- * @lastTime 2022/4/1
5
- * @description 环境:本地开发环境
6
- */
7
- export function isDev(): boolean {
8
- return typeViteEnv('VITE_APP_ENV') === 'dev'
9
- }
10
-
11
- /**
12
- * @Author gx12358
13
- * @DateTime 2022/4/1
14
- * @lastTime 2022/4/1
15
- * @description 环境:正式
16
- */
17
- export function isPro(): boolean {
18
- return typeViteEnv('VITE_USE_MODE') === 'pro'
19
- }
20
-
21
- /**
22
- * @Author gx12358
23
- * @DateTime 2022/4/1
24
- * @lastTime 2022/4/1
25
- * @description 环境:非本地开发环境
26
- */
27
- export function isBuild(): boolean {
28
- return typeViteEnv('VITE_NODE_ENV') === 'production'
29
- }
30
-
31
- /**
32
- * @Author gx12358
33
- * @DateTime 2022/4/1
34
- * @lastTime 2022/4/1
35
- * @description 当前联调环境
36
- */
37
- export function currentMode() {
38
- return typeViteEnv('VITE_USE_MODE')
39
- }
40
-
41
- export function typeViteEnv<T extends keyof ViteEnv>(key: T): ViteEnv[T] | undefined {
42
- let value: any = (import.meta as any).env[key]
43
-
44
- if (value && typeof value === 'string') {
45
- value = value.replace(/\\n/g, '\n') as ViteEnv[T]
46
- value = value === 'true' ? true : value === 'false' ? false : value
47
- }
48
-
49
- return value
50
- }
@@ -1,81 +0,0 @@
1
- import type { Method } from 'axios'
2
- import { message } from 'ant-design-vue'
3
- import { defaultSettings } from '@gx-config'
4
- import { tansParams } from '@/utils/util'
5
- import { typeViteEnv } from '@/utils/env'
6
-
7
- const { tokenName } = defaultSettings
8
-
9
- export interface DownLoadRequestConfig<D = any> {
10
- url: string;
11
- method?: Method | string;
12
- headers?: HeadersInit;
13
- data?: D;
14
- params?: any;
15
- name?: string; // 下载的名称
16
- direct?: boolean; // 是否直接使用url进行请求
17
- read?: boolean; // 返回下载地址,不下载
18
- showTip?: boolean; // 展示下载中字样
19
- }
20
-
21
- export default async function fetchFile(options: DownLoadRequestConfig): Promise<boolean | string> {
22
- const user = useStoreUser()
23
- if (options.showTip) {
24
- message.loading({
25
- content: `下载中,请耐心等待。。。。`,
26
- key: 'updatable',
27
- duration: 0
28
- })
29
- }
30
- const opations: RequestInit = {
31
- method: options.method,
32
- headers: {
33
- 'Content-Type': 'application/json',
34
- ...options.headers
35
- }
36
- }
37
- if (!options.direct)
38
- options.url = `${typeViteEnv('VITE_BASE_URL')}${options.url}`
39
- if (user.accessToken && !options.direct)
40
- opations.headers[tokenName] = `${user.accessToken}`
41
- if (options.params) {
42
- let url = options.url + '?' + tansParams(options.params)
43
- url = url.slice(0, -1)
44
- options.url = url
45
- }
46
- if (options.method === 'post' && options.data) {
47
- opations.body = JSON.stringify(options.data)
48
- }
49
- const response = await fetch(options.url, opations)
50
- const fileName = options.name
51
- ? options.name
52
- : response.headers.get('content-disposition')
53
- ? response.headers.get('content-disposition').split(';')[1].split('=')[1]
54
- : ''
55
- const blobResponse = await response.blob()
56
- if (blobResponse) {
57
- const a = window.document.createElement('a')
58
- const downUrl = window.URL.createObjectURL(blobResponse)
59
- if (options.read)
60
- return downUrl
61
- a.href = downUrl
62
- a.download = `${decodeURI(fileName)}`
63
- a.click()
64
- if (options.showTip) {
65
- message.success({
66
- content: `下载成功`,
67
- key: 'updatable'
68
- })
69
- }
70
- window.URL.revokeObjectURL(downUrl)
71
- return true
72
- } else {
73
- if (options.showTip) {
74
- message.success({
75
- content: `下载失败`,
76
- key: 'updatable'
77
- })
78
- }
79
- return false
80
- }
81
- }
@@ -1,123 +0,0 @@
1
- import PropTypes from 'ant-design-vue/es/_util/vue-types'
2
-
3
- export { PropTypes }
4
-
5
- /**
6
- * @author gx12358 2539306317@qq.com
7
- * @description 将url请求参数转为json格式
8
- * @param url
9
- * @returns {{}|any}
10
- */
11
- export function paramObj(url) {
12
- const search = url.split('?')[1]
13
- if (!search) {
14
- return {}
15
- }
16
- return JSON.parse(`{"${decodeURIComponent(search)
17
- .replace(/"/g, '\\"')
18
- .replace(/&/g, '","')
19
- .replace(/=/g, '":"')
20
- .replace(/\+/g, ' ')}"}`)
21
- }
22
-
23
- /**
24
- * @author gx12358 2539306317@qq.com
25
- * @description 父子关系的数组转换成树形结构数据
26
- * @param data
27
- * @returns {*}
28
- */
29
- export function translateDataToTree(data) {
30
- const parent = data.filter(
31
- value => value.parentId === 'undefined' || value.parentId == null
32
- )
33
- const children = data.filter(
34
- value => value.parentId !== 'undefined' && value.parentId != null
35
- )
36
- const translator = (parent, children) => {
37
- parent.forEach((parent) => {
38
- children.forEach((current, index) => {
39
- if (current.parentId === parent.id) {
40
- const temp = JSON.parse(JSON.stringify(children))
41
- temp.splice(index, 1)
42
- translator([ current ], temp)
43
- typeof parent.children !== 'undefined'
44
- ? parent.children.push(current)
45
- : (parent.children = [ current ])
46
- }
47
- })
48
- })
49
- }
50
- translator(parent, children)
51
- return parent
52
- }
53
-
54
- /**
55
- * @author gx12358 2539306317@qq.com
56
- * @description 树形结构数据转换成父子关系的数组
57
- * @param data
58
- * @returns {[]}
59
- */
60
- export function translateTreeToData(data) {
61
- const result: any[] = []
62
- data.forEach((item) => {
63
- const loop = (data) => {
64
- result.push({
65
- id: data.id,
66
- name: data.name,
67
- parentId: data.parentId
68
- })
69
- const child = data.children
70
- if (child) {
71
- for (let i = 0; i < child.length; i++) {
72
- loop(child[i])
73
- }
74
- }
75
- }
76
- loop(item)
77
- })
78
- return result
79
- }
80
-
81
- /**
82
- * @author gx12358 2539306317@qq.com
83
- * @description 10位时间戳转换
84
- * @param time
85
- * @returns {string}
86
- */
87
- export function tenBitTimestamp(time) {
88
- const date = new Date(time * 1000)
89
- const y = date.getFullYear()
90
- let m: any = date.getMonth() + 1
91
- m = m < 10 ? '' + m : m
92
- let d: any = date.getDate()
93
- d = d < 10 ? '' + d : d
94
- let h: any = date.getHours()
95
- h = h < 10 ? '0' + h : h
96
- let minute: any = date.getMinutes()
97
- let second: any = date.getSeconds()
98
- minute = minute < 10 ? '0' + minute : minute
99
- second = second < 10 ? '0' + second : second
100
- return y + '年' + m + '月' + d + '日 ' + h + ':' + minute + ':' + second // 组合
101
- }
102
-
103
- /**
104
- * @author gx12358 2539306317@qq.com
105
- * @description 13位时间戳转换
106
- * @param time
107
- * @returns {string}
108
- */
109
- export function thirteenBitTimestamp(time) {
110
- const date = new Date(time / 1)
111
- const y = date.getFullYear()
112
- let m: any = date.getMonth() + 1
113
- m = m < 10 ? '' + m : m
114
- let d: any = date.getDate()
115
- d = d < 10 ? '' + d : d
116
- let h: any = date.getHours()
117
- h = h < 10 ? '0' + h : h
118
- let minute: any = date.getMinutes()
119
- let second: any = date.getSeconds()
120
- minute = minute < 10 ? '0' + minute : minute
121
- second = second < 10 ? '0' + second : second
122
- return y + '年' + m + '月' + d + '日 ' + h + ':' + minute + ':' + second // 组合
123
- }
@@ -1,20 +0,0 @@
1
- import { defaultSettings } from '@gx-config'
2
-
3
- const { title, titleReverse, titleSeparator } = defaultSettings
4
-
5
- /**
6
- * @author gx12358 2539306317@qq.com
7
- * @description 设置标题
8
- * @param pageTitle
9
- * @returns {string}
10
- */
11
- export default function getPageTitle(pageTitle: string) {
12
- let newTitles: string[] = []
13
- if (pageTitle)
14
- newTitles.push(pageTitle)
15
- if (title)
16
- newTitles.push(title)
17
- if (titleReverse)
18
- newTitles = newTitles.reverse()
19
- return newTitles.join(titleSeparator)
20
- }
@@ -1,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,25 +0,0 @@
1
- import { useStoreUser } from '@/store'
2
- import { message } from 'ant-design-vue'
3
- import { router } from '@/router'
4
-
5
- /**
6
- * @author gx12358 2539306317@qq.com
7
- * @description 处理code异常
8
- * @param {*} code
9
- * @param {*} msg
10
- */
11
- export const handleCode = (code: number, msg: string) => {
12
- const user = useStoreUser()
13
- switch (code) {
14
- case 401:
15
- user.resetPermissions()
16
- router.push({ path: '/user/login' })
17
- break
18
- case 403:
19
- router.push({ path: '/exception/403' })
20
- break
21
- default:
22
- message.error(msg || '后端接口异常')
23
- break
24
- }
25
- }