@gx-design-vue/create-gx-cli 0.1.10 → 0.1.11
Sign up to get free protection for your applications and to get access to all the features.
- package/package.json +2 -1
- package/template-gx-design-thin/.editorconfig +19 -0
- package/template-gx-design-thin/.env +4 -0
- package/template-gx-design-thin/.env.development +15 -0
- package/template-gx-design-thin/.env.production +28 -0
- package/template-gx-design-thin/.eslintignore +16 -0
- package/template-gx-design-thin/.prettierignore +9 -0
- package/template-gx-design-thin/LICENSE +21 -0
- package/template-gx-design-thin/README.md +112 -0
- package/template-gx-design-thin/build/constant.ts +1 -0
- package/template-gx-design-thin/build/generate/generateModifyVars.ts +14 -0
- package/template-gx-design-thin/build/rollupOptions/index.ts +22 -0
- package/template-gx-design-thin/build/util/hash.ts +17 -0
- package/template-gx-design-thin/build/util/index.ts +131 -0
- package/template-gx-design-thin/build/vite/cdn.ts +63 -0
- package/template-gx-design-thin/build/vite/optimizer.ts +26 -0
- package/template-gx-design-thin/build/vite/plugin/appConfig.ts +91 -0
- package/template-gx-design-thin/build/vite/plugin/autoImport.ts +26 -0
- package/template-gx-design-thin/build/vite/plugin/compress.ts +31 -0
- package/template-gx-design-thin/build/vite/plugin/html.ts +39 -0
- package/template-gx-design-thin/build/vite/plugin/index.ts +75 -0
- package/template-gx-design-thin/build/vite/plugin/mock.ts +14 -0
- package/template-gx-design-thin/build/vite/plugin/pwa.ts +31 -0
- package/template-gx-design-thin/build/vite/plugin/visualizer.ts +14 -0
- package/template-gx-design-thin/build/vite/plugin/viteMock/client.ts +88 -0
- package/template-gx-design-thin/build/vite/plugin/viteMock/createMockServer.ts +271 -0
- package/template-gx-design-thin/build/vite/plugin/viteMock/index.ts +69 -0
- package/template-gx-design-thin/build/vite/plugin/viteMock/types.ts +48 -0
- package/template-gx-design-thin/build/vite/plugin/viteMock/utils.ts +48 -0
- package/template-gx-design-thin/build/vite/plugin/viteNotice.ts +40 -0
- package/template-gx-design-thin/commitlint.config.cjs +32 -0
- package/template-gx-design-thin/config/default/defaultSettings.ts +78 -0
- package/template-gx-design-thin/config/default/network.ts +10 -0
- package/template-gx-design-thin/config/default/proxy.ts +47 -0
- package/template-gx-design-thin/config/default/theme.ts +3 -0
- package/template-gx-design-thin/config/index.ts +11 -0
- package/template-gx-design-thin/eslint.config.js +51 -0
- package/template-gx-design-thin/index.html +42 -0
- package/template-gx-design-thin/mock/_createProductionServer.ts +19 -0
- package/template-gx-design-thin/mock/_util.ts +33 -0
- package/template-gx-design-thin/mock/config/menu.ts +21 -0
- package/template-gx-design-thin/mock/config/user.ts +123 -0
- package/template-gx-design-thin/mock/datasSource/system/menu.ts +10 -0
- package/template-gx-design-thin/mock/datasSource/user/account.ts +30 -0
- package/template-gx-design-thin/mock/datasSource/user/index.ts +47 -0
- package/template-gx-design-thin/mock/util/crypto.ts +23 -0
- package/template-gx-design-thin/mock/util/table.ts +92 -0
- package/template-gx-design-thin/mock/util/utils.ts +73 -0
- package/template-gx-design-thin/package.json +129 -0
- package/template-gx-design-thin/pnpm-lock.yaml +12575 -0
- package/template-gx-design-thin/prettier.config.cjs +18 -0
- package/template-gx-design-thin/public/resource/css/index.css +119 -0
- package/template-gx-design-thin/public/resource/css/normalize.css +396 -0
- package/template-gx-design-thin/public/resource/img/favicon.ico +0 -0
- package/template-gx-design-thin/public/resource/img/logo.png +0 -0
- package/template-gx-design-thin/public/resource/img/pro_icon.svg +1 -0
- package/template-gx-design-thin/public/resource/img/pwa-192x192.png +0 -0
- package/template-gx-design-thin/public/resource/img/pwa-512x512.png +0 -0
- package/template-gx-design-thin/src/App.vue +42 -0
- package/template-gx-design-thin/src/assets/error_images/403.png +0 -0
- package/template-gx-design-thin/src/assets/error_images/404.png +0 -0
- package/template-gx-design-thin/src/assets/error_images/cloud.png +0 -0
- package/template-gx-design-thin/src/assets/login_images/login_background.svg +1 -0
- package/template-gx-design-thin/src/assets/logo.png +0 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.css +94 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.eot +0 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.js +1 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.json +142 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.svg +1 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.ttf +0 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.woff +0 -0
- package/template-gx-design-thin/src/assets/menu_font/iconfont.woff2 +0 -0
- package/template-gx-design-thin/src/assets/menu_font/index.less +94 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.css +42 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.eot +0 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.js +1 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.json +51 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.svg +1 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.ttf +0 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.woff +0 -0
- package/template-gx-design-thin/src/assets/public_icon/iconfont.woff2 +0 -0
- package/template-gx-design-thin/src/assets/public_icon/index.less +42 -0
- package/template-gx-design-thin/src/assets/public_images/nodata.svg +1 -0
- package/template-gx-design-thin/src/common/global.ts +4 -0
- package/template-gx-design-thin/src/components/GDesign/Result/index.tsx +144 -0
- package/template-gx-design-thin/src/components/GDesign/Result/style.less +140 -0
- package/template-gx-design-thin/src/components/GDesign/utils/index.ts +7 -0
- package/template-gx-design-thin/src/components/GlobalLayout/Confirm/index.ts +21 -0
- package/template-gx-design-thin/src/components/GlobalLayout/Empty/index.vue +18 -0
- package/template-gx-design-thin/src/components/GlobalLayout/RightContent/index.tsx +126 -0
- package/template-gx-design-thin/src/components/GlobalLayout/RightContent/style.ts +77 -0
- package/template-gx-design-thin/src/components/GlobalLayout/Spin/index.tsx +30 -0
- package/template-gx-design-thin/src/components/PageLoading/index.tsx +51 -0
- package/template-gx-design-thin/src/components/index.ts +6 -0
- package/template-gx-design-thin/src/core/ant-design/index.ts +10 -0
- package/template-gx-design-thin/src/core/gx-admin-design/index.ts +6 -0
- package/template-gx-design-thin/src/core/gx-design/index.ts +6 -0
- package/template-gx-design-thin/src/core/gx-pro-design/index.ts +8 -0
- package/template-gx-design-thin/src/core/index.ts +84 -0
- package/template-gx-design-thin/src/design/ant-design/index.less +4 -0
- package/template-gx-design-thin/src/design/ant-design/layout.less +22 -0
- package/template-gx-design-thin/src/design/ant-design/menu.less +48 -0
- package/template-gx-design-thin/src/design/ant-design/spin.less +23 -0
- package/template-gx-design-thin/src/design/ant-design/tooltip.less +7 -0
- package/template-gx-design-thin/src/design/color.less +1 -0
- package/template-gx-design-thin/src/design/config.less +5 -0
- package/template-gx-design-thin/src/design/imageEditor.less +180 -0
- package/template-gx-design-thin/src/design/index.less +95 -0
- package/template-gx-design-thin/src/design/mixin.less +65 -0
- package/template-gx-design-thin/src/design/normalize.less +391 -0
- package/template-gx-design-thin/src/design/root.less +3 -0
- package/template-gx-design-thin/src/hooks/core/index.ts +3 -0
- package/template-gx-design-thin/src/hooks/core/useRequest/index.ts +118 -0
- package/template-gx-design-thin/src/hooks/event/index.ts +3 -0
- package/template-gx-design-thin/src/hooks/event/useClipboard.ts +15 -0
- package/template-gx-design-thin/src/hooks/web/index.ts +5 -0
- package/template-gx-design-thin/src/hooks/web/useThemeStyle.ts +16 -0
- package/template-gx-design-thin/src/layout/BasicLayout.vue +123 -0
- package/template-gx-design-thin/src/layout/BlankLayout.vue +5 -0
- package/template-gx-design-thin/src/layout/ContentView.vue +50 -0
- package/template-gx-design-thin/src/layout/IframeView.vue +1 -0
- package/template-gx-design-thin/src/layout/UserLayout.vue +7 -0
- package/template-gx-design-thin/src/main.ts +34 -0
- package/template-gx-design-thin/src/plugins/index.ts +2 -0
- package/template-gx-design-thin/src/router/guard/index.ts +83 -0
- package/template-gx-design-thin/src/router/guard/permissions.ts +70 -0
- package/template-gx-design-thin/src/router/guard/stateGuard.ts +10 -0
- package/template-gx-design-thin/src/router/helper/routeHelper.ts +231 -0
- package/template-gx-design-thin/src/router/helper/utils.ts +19 -0
- package/template-gx-design-thin/src/router/index.ts +31 -0
- package/template-gx-design-thin/src/router/routes/index.ts +86 -0
- package/template-gx-design-thin/src/router/routes/modules/dataSource.ts +12 -0
- package/template-gx-design-thin/src/services/common/index.ts +11 -0
- package/template-gx-design-thin/src/services/systemCenter/index.ts +1 -0
- package/template-gx-design-thin/src/services/systemCenter/menu.ts +9 -0
- package/template-gx-design-thin/src/services/userCenter/account.ts +42 -0
- package/template-gx-design-thin/src/services/userCenter/index.ts +28 -0
- package/template-gx-design-thin/src/store/index.ts +32 -0
- package/template-gx-design-thin/src/store/modules/dict.ts +28 -0
- package/template-gx-design-thin/src/store/modules/global.ts +42 -0
- package/template-gx-design-thin/src/store/modules/permission.ts +19 -0
- package/template-gx-design-thin/src/store/modules/routes.ts +113 -0
- package/template-gx-design-thin/src/store/modules/tabsRouter.ts +76 -0
- package/template-gx-design-thin/src/store/modules/user.ts +136 -0
- package/template-gx-design-thin/src/utils/accessToken.ts +80 -0
- package/template-gx-design-thin/src/utils/crypto/base64.ts +101 -0
- package/template-gx-design-thin/src/utils/crypto/index.ts +57 -0
- package/template-gx-design-thin/src/utils/env.ts +50 -0
- package/template-gx-design-thin/src/utils/fetchFile.ts +81 -0
- package/template-gx-design-thin/src/utils/index.ts +123 -0
- package/template-gx-design-thin/src/utils/pageTitle.ts +20 -0
- package/template-gx-design-thin/src/utils/request/XHR.ts +139 -0
- package/template-gx-design-thin/src/utils/request/axiosCancel.ts +69 -0
- package/template-gx-design-thin/src/utils/request/checkStatus.ts +25 -0
- package/template-gx-design-thin/src/utils/request/index.ts +144 -0
- package/template-gx-design-thin/src/utils/request/typings.ts +171 -0
- package/template-gx-design-thin/src/utils/storage.ts +199 -0
- package/template-gx-design-thin/src/utils/uploadFile.ts +27 -0
- package/template-gx-design-thin/src/utils/util.ts +198 -0
- package/template-gx-design-thin/src/utils/validate.ts +216 -0
- package/template-gx-design-thin/src/views/Iframe/index.vue +76 -0
- package/template-gx-design-thin/src/views/Page/one.vue +13 -0
- package/template-gx-design-thin/src/views/Page/two.vue +13 -0
- package/template-gx-design-thin/src/views/exception/403/index.vue +7 -0
- package/template-gx-design-thin/src/views/exception/404/index.vue +9 -0
- package/template-gx-design-thin/src/views/user/login/index.vue +109 -0
- package/template-gx-design-thin/src/views/user/login/style.less +38 -0
- package/template-gx-design-thin/tsconfig.json +46 -0
- package/template-gx-design-thin/types/ant-design-import.d.ts +99 -0
- package/template-gx-design-thin/types/auto-imports.d.ts +81 -0
- package/template-gx-design-thin/types/components.d.ts +24 -0
- package/template-gx-design-thin/types/config.d.ts +44 -0
- package/template-gx-design-thin/types/global.d.ts +97 -0
- package/template-gx-design-thin/types/mock.d.ts +16 -0
- package/template-gx-design-thin/types/module.d.ts +20 -0
- package/template-gx-design-thin/types/response.d.ts +15 -0
- package/template-gx-design-thin/unocss.config.ts +101 -0
- package/template-gx-design-thin/vite.config.ts +120 -0
- package/template-gx-design-thin/yarn.lock +9492 -0
@@ -0,0 +1,57 @@
|
|
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
|
+
}
|
@@ -0,0 +1,50 @@
|
|
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
|
+
}
|
@@ -0,0 +1,81 @@
|
|
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
|
+
}
|
@@ -0,0 +1,123 @@
|
|
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
|
+
}
|
@@ -0,0 +1,20 @@
|
|
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
|
+
}
|
@@ -0,0 +1,139 @@
|
|
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
|
+
}
|
@@ -0,0 +1,69 @@
|
|
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
|
+
}
|
@@ -0,0 +1,25 @@
|
|
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
|
+
}
|