@gx-design-vue/create-gx-cli 0.1.15 → 0.1.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/main.js +7 -7
- package/template-mobile-vant-cli/.env +3 -0
- package/template-mobile-vant-cli/.env.development +4 -6
- package/template-mobile-vant-cli/.env.pro +16 -7
- package/template-mobile-vant-cli/.env.production +21 -9
- package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
- package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
- package/template-mobile-vant-cli/config/default/network.ts +10 -0
- package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
- package/template-mobile-vant-cli/config/default/theme.ts +3 -0
- package/template-mobile-vant-cli/config/index.ts +11 -0
- package/template-mobile-vant-cli/eslint.config.js +10 -2
- package/template-mobile-vant-cli/index.html +22 -21
- package/template-mobile-vant-cli/{build → internal/vite-config/generate}/generateModifyVars.ts +1 -1
- package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
- package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
- package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
- package/template-mobile-vant-cli/{build → internal/vite-config/vite}/optimizer.ts +9 -1
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
- package/template-mobile-vant-cli/{build → internal/vite-config/vite}/plugin/autoImport.ts +7 -3
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
- package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
- package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
- package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
- package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
- package/template-mobile-vant-cli/mock/index.ts +55 -0
- package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
- package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
- package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
- package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
- package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
- package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
- package/template-mobile-vant-cli/package.json +51 -34
- package/template-mobile-vant-cli/public/css/default.css +54 -0
- package/template-mobile-vant-cli/src/App.vue +6 -2
- package/template-mobile-vant-cli/src/assets/logo.png +0 -0
- package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -1
- package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +108 -16
- package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +5 -2
- package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
- package/template-mobile-vant-cli/src/core/gx-design/index.ts +1 -1
- package/template-mobile-vant-cli/src/core/index.ts +0 -7
- package/template-mobile-vant-cli/src/design/color.less +1 -0
- package/template-mobile-vant-cli/src/design/config.less +5 -0
- package/template-mobile-vant-cli/src/design/index.less +1 -1
- package/template-mobile-vant-cli/src/design/mixin.less +65 -0
- package/template-mobile-vant-cli/src/design/reset.less +16 -132
- package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +7 -9
- package/template-mobile-vant-cli/src/layout/{BasicLayout.vue → BasicLayout/index.vue} +3 -1
- package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
- package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
- package/template-mobile-vant-cli/src/main.ts +16 -9
- package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
- package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
- package/template-mobile-vant-cli/src/pages/{home.vue → Home/index.vue} +5 -5
- package/template-mobile-vant-cli/src/pages/user/login/index.vue +74 -0
- package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
- package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
- package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
- package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
- package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
- package/template-mobile-vant-cli/src/router/index.ts +21 -15
- package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
- package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
- package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
- package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
- package/template-mobile-vant-cli/src/store/index.ts +4 -1
- package/template-mobile-vant-cli/src/store/modules/global.ts +6 -13
- package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
- package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
- package/template-mobile-vant-cli/src/utils/crypto/index.ts +3 -4
- package/template-mobile-vant-cli/src/utils/env.ts +2 -2
- package/template-mobile-vant-cli/src/utils/pageTitle.ts +12 -6
- package/template-mobile-vant-cli/src/utils/request/XHR.ts +9 -11
- package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +5 -5
- package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +18 -2
- package/template-mobile-vant-cli/src/utils/request/index.ts +36 -23
- package/template-mobile-vant-cli/src/utils/storage.ts +49 -32
- package/template-mobile-vant-cli/src/utils/validate.ts +31 -36
- package/template-mobile-vant-cli/tsconfig.json +17 -9
- package/template-mobile-vant-cli/types/auto-imports.d.ts +18 -2
- package/template-mobile-vant-cli/types/components.d.ts +2 -7
- package/template-mobile-vant-cli/types/config.d.ts +56 -0
- package/template-mobile-vant-cli/types/global.d.ts +62 -21
- package/template-mobile-vant-cli/types/mock.d.ts +34 -0
- package/template-mobile-vant-cli/types/module.d.ts +33 -0
- package/template-mobile-vant-cli/types/response.d.ts +3 -1
- package/template-mobile-vant-cli/types/system.d.ts +58 -0
- package/template-mobile-vant-cli/types/vant-import.d.ts +16 -5
- package/template-mobile-vant-cli/unocss.config.ts +120 -66
- package/template-mobile-vant-cli/vite.config.ts +78 -81
- package/template-mobile-vant-cli/build/cdn.ts +0 -5
- package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
- package/template-mobile-vant-cli/build/plugin/index.ts +0 -42
- package/template-mobile-vant-cli/build/plugin/mock.ts +0 -14
- package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +0 -88
- package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +0 -271
- package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +0 -69
- package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +0 -48
- package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +0 -48
- package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
- package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
- package/template-mobile-vant-cli/mock/utils.ts +0 -9
- package/template-mobile-vant-cli/postcss.config.cjs +0 -8
- package/template-mobile-vant-cli/prettier.config.cjs +0 -18
- package/template-mobile-vant-cli/public/js/flexible.js +0 -44
- package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
- package/template-mobile-vant-cli/src/design/vant.less +0 -2
- package/template-mobile-vant-cli/src/global.less +0 -1
- package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
- package/template-mobile-vant-cli/src/router/routes.ts +0 -20
- package/template-mobile-vant-cli/src/router/typings.ts +0 -8
- package/template-mobile-vant-cli/src/settings/index.ts +0 -10
- package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
- package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
- package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
- /package/template-mobile-vant-cli/{mock/datasSource/api/index.ts → src/design/vant/index.less} +0 -0
@@ -0,0 +1,91 @@
|
|
1
|
+
import type { PluginOption } from 'vite'
|
2
|
+
import colors from 'picocolors'
|
3
|
+
import { readPackageJSON } from 'pkg-types'
|
4
|
+
|
5
|
+
import { getEnvConfig, rootPath } from '../../util'
|
6
|
+
import { createContentHash, strToHex } from '../../util/hash'
|
7
|
+
|
8
|
+
const GLOBAL_CONFIG_FILE_NAME = '_app.config.js'
|
9
|
+
const PLUGIN_NAME = 'app-config'
|
10
|
+
|
11
|
+
async function createAppConfigPlugin({
|
12
|
+
isBuild
|
13
|
+
}: {
|
14
|
+
isBuild: boolean;
|
15
|
+
}): Promise<PluginOption> {
|
16
|
+
let publicPath: string
|
17
|
+
let source: string
|
18
|
+
if (!isBuild) {
|
19
|
+
return {
|
20
|
+
name: PLUGIN_NAME
|
21
|
+
}
|
22
|
+
}
|
23
|
+
const { version = '' } = await readPackageJSON(rootPath)
|
24
|
+
|
25
|
+
return {
|
26
|
+
name: PLUGIN_NAME,
|
27
|
+
async configResolved(_config) {
|
28
|
+
const appTitle = _config?.env?.VITE_GLOB_APP_TITLE ?? ''
|
29
|
+
publicPath = _config.base
|
30
|
+
source = await getConfigSource(appTitle)
|
31
|
+
},
|
32
|
+
async transformIndexHtml(html) {
|
33
|
+
publicPath = publicPath.endsWith('/') ? publicPath : `${publicPath}/`
|
34
|
+
|
35
|
+
const appConfigSrc = `${
|
36
|
+
publicPath || '/'
|
37
|
+
}${GLOBAL_CONFIG_FILE_NAME}?v=${version}-${createContentHash(source)}`
|
38
|
+
|
39
|
+
return {
|
40
|
+
html,
|
41
|
+
tags: [
|
42
|
+
{
|
43
|
+
tag: 'script',
|
44
|
+
attrs: {
|
45
|
+
src: appConfigSrc
|
46
|
+
}
|
47
|
+
}
|
48
|
+
]
|
49
|
+
}
|
50
|
+
},
|
51
|
+
async generateBundle() {
|
52
|
+
try {
|
53
|
+
this.emitFile({
|
54
|
+
type: 'asset',
|
55
|
+
fileName: GLOBAL_CONFIG_FILE_NAME,
|
56
|
+
source
|
57
|
+
})
|
58
|
+
} catch (error) {
|
59
|
+
console.log(
|
60
|
+
colors.red(`configuration file configuration file failed to package:\n${error}`)
|
61
|
+
)
|
62
|
+
}
|
63
|
+
}
|
64
|
+
}
|
65
|
+
}
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Get the configuration file variable name
|
69
|
+
* @param env
|
70
|
+
*/
|
71
|
+
const getVariableName = (title: string) => {
|
72
|
+
return `__PRODUCTION__${strToHex(title) || '__APP'}__CONF__`.toUpperCase().replace(/\s/g, '')
|
73
|
+
}
|
74
|
+
|
75
|
+
async function getConfigSource(appTitle: string) {
|
76
|
+
const config = await getEnvConfig()
|
77
|
+
const variableName = getVariableName(appTitle)
|
78
|
+
const windowVariable = `window.${variableName}`
|
79
|
+
// Ensure that the variable will not be modified
|
80
|
+
let source = `${windowVariable}=${JSON.stringify(config)};`
|
81
|
+
source += `
|
82
|
+
Object.freeze(${windowVariable});
|
83
|
+
Object.defineProperty(window, "${variableName}", {
|
84
|
+
configurable: false,
|
85
|
+
writable: false,
|
86
|
+
});
|
87
|
+
`.replace(/\s/g, '')
|
88
|
+
return source
|
89
|
+
}
|
90
|
+
|
91
|
+
export { createAppConfigPlugin }
|
@@ -1,10 +1,14 @@
|
|
1
|
+
import { VantResolver } from '@vant/auto-import-resolver'
|
1
2
|
import autoImport from 'unplugin-auto-import/vite'
|
2
3
|
import Components from 'unplugin-vue-components/vite'
|
3
|
-
import {
|
4
|
+
import { defaultSettings } from '../../../../config'
|
4
5
|
|
5
6
|
const importsModules = [ 'vue', 'vue-router' ] as any
|
6
7
|
|
8
|
+
const { modules = [], use } = defaultSettings.cdn
|
9
|
+
|
7
10
|
export function createAutoImport() {
|
11
|
+
const useCdnModules = use && modules.some(el => importsModules.includes(el.name))
|
8
12
|
return [
|
9
13
|
autoImport({
|
10
14
|
include: [
|
@@ -12,13 +16,13 @@ export function createAutoImport() {
|
|
12
16
|
/\.vue$/, /\.vue\?vue/, // .vue
|
13
17
|
/\.md$/ // .md
|
14
18
|
],
|
15
|
-
imports: importsModules,
|
19
|
+
imports: useCdnModules ? [] : importsModules,
|
16
20
|
dts: 'types/auto-imports.d.ts',
|
17
21
|
dirs: [ 'src/store' ]
|
18
22
|
}),
|
19
23
|
Components({
|
20
24
|
resolvers: [ VantResolver() ],
|
21
|
-
dts: 'types/
|
25
|
+
dts: 'types/vant-import.d.ts'
|
22
26
|
})
|
23
27
|
]
|
24
28
|
}
|
@@ -0,0 +1,31 @@
|
|
1
|
+
import type { Plugin } from 'vite'
|
2
|
+
|
3
|
+
import compressPlugin from 'vite-plugin-compression'
|
4
|
+
|
5
|
+
export function configCompressPlugin(
|
6
|
+
compress: 'gzip' | 'brotli' | 'none',
|
7
|
+
deleteOriginFile = false
|
8
|
+
): Plugin | Plugin[] {
|
9
|
+
const compressList = compress.split(',')
|
10
|
+
|
11
|
+
const plugins: Plugin[] = []
|
12
|
+
|
13
|
+
if (compressList.includes('gzip')) {
|
14
|
+
plugins.push(
|
15
|
+
compressPlugin({
|
16
|
+
ext: '.gz',
|
17
|
+
deleteOriginFile
|
18
|
+
})
|
19
|
+
)
|
20
|
+
}
|
21
|
+
if (compressList.includes('brotli')) {
|
22
|
+
plugins.push(
|
23
|
+
compressPlugin({
|
24
|
+
ext: '.br',
|
25
|
+
algorithm: 'brotliCompress',
|
26
|
+
deleteOriginFile
|
27
|
+
})
|
28
|
+
)
|
29
|
+
}
|
30
|
+
return plugins
|
31
|
+
}
|
@@ -0,0 +1,32 @@
|
|
1
|
+
import type { PluginOption } from 'vite'
|
2
|
+
import { createHtmlPlugin } from 'vite-plugin-html'
|
3
|
+
|
4
|
+
import { defaultSettings } from '../../../../config'
|
5
|
+
import cdnModules from '../cdn'
|
6
|
+
|
7
|
+
const { cdn, system } = defaultSettings
|
8
|
+
|
9
|
+
const startLoadingCss = system.appInit.loading ? [ '/css/default.css' ] : []
|
10
|
+
|
11
|
+
export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
|
12
|
+
const htmlPlugin: PluginOption[] = createHtmlPlugin({
|
13
|
+
minify: isBuild,
|
14
|
+
inject: {
|
15
|
+
// Inject data into ejs template
|
16
|
+
data: {
|
17
|
+
VUE_APP_TITLE: system.title,
|
18
|
+
injectVlogScript: env.VITE_USE_V_CONSOLE
|
19
|
+
? `<script src="https://unpkg.com/vconsole@latest/dist/vconsole.min.js"></script><script>var vConsole = new window.VConsole();</script>`
|
20
|
+
: '',
|
21
|
+
injectAppContent: system.appInit.loading
|
22
|
+
? `<div class="gx-toast-loading"><div class="gx-toast-loading-cont"><span class="gx-toast-svg"><svg class="van-loading__circular" viewBox="25 25 50 50"><circle cx="50" cy="50" r="20" fill="none"></circle></svg></span><span class="gx-toast-svg-text">${system.appInit.loading?.text}</span></div></div>`
|
23
|
+
: '',
|
24
|
+
injectScript: cdn.use && isBuild ? cdnModules.map(e => e.js).filter(el => el) : [],
|
25
|
+
injectLink: cdn.use && isBuild
|
26
|
+
? cdnModules.map(e => e.css).filter(el => el).concat(startLoadingCss as string[])
|
27
|
+
: startLoadingCss
|
28
|
+
}
|
29
|
+
}
|
30
|
+
})
|
31
|
+
return htmlPlugin
|
32
|
+
}
|
@@ -0,0 +1,74 @@
|
|
1
|
+
import type { PluginOption } from 'vite'
|
2
|
+
|
3
|
+
import legacy from '@vitejs/plugin-legacy'
|
4
|
+
import vue from '@vitejs/plugin-vue'
|
5
|
+
import vueJsx from '@vitejs/plugin-vue-jsx'
|
6
|
+
import Unocss from 'unocss/vite'
|
7
|
+
import TurboConsole from 'unplugin-turbo-console/vite'
|
8
|
+
// @ts-ignore
|
9
|
+
import { vitePluginFakeServer } from 'vite-plugin-fake-server'
|
10
|
+
|
11
|
+
import { createAppConfigPlugin } from './appConfig'
|
12
|
+
import { createAutoImport } from './autoImport'
|
13
|
+
import { configCompressPlugin } from './compress'
|
14
|
+
import { configHtmlPlugin } from './html'
|
15
|
+
import { configVisualizerConfig } from './visualizer'
|
16
|
+
import viteNotice from './viteNotice'
|
17
|
+
|
18
|
+
export async function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
|
19
|
+
const {
|
20
|
+
VITE_APP_ENV,
|
21
|
+
VITE_USE_MOCK,
|
22
|
+
VITE_LEGACY,
|
23
|
+
VITE_BUILD_COMPRESS,
|
24
|
+
VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE
|
25
|
+
} = viteEnv
|
26
|
+
|
27
|
+
const isDev = VITE_APP_ENV === 'dev'
|
28
|
+
|
29
|
+
const vitePlugins: PluginOption[] = [
|
30
|
+
// have to
|
31
|
+
vue(),
|
32
|
+
// have to
|
33
|
+
vueJsx()
|
34
|
+
]
|
35
|
+
|
36
|
+
// vite-plugin-app-info
|
37
|
+
vitePlugins.push(await createAppConfigPlugin({ isBuild }))
|
38
|
+
// vite-plugin-windicss
|
39
|
+
vitePlugins.push(Unocss())
|
40
|
+
|
41
|
+
// unplugin-turbo-console
|
42
|
+
isDev && vitePlugins.push(TurboConsole())
|
43
|
+
// @vitejs/plugin-legacy
|
44
|
+
VITE_LEGACY && isBuild && vitePlugins.push(legacy({
|
45
|
+
// 设置目标浏览器,browserslist 配置语法
|
46
|
+
targets: ['Android >= 7', 'chrome < 60', 'edge < 15'],
|
47
|
+
}))
|
48
|
+
// vite-plugin-html
|
49
|
+
vitePlugins.push(configHtmlPlugin(viteEnv, isBuild))
|
50
|
+
// vite-plugin-build-info
|
51
|
+
vitePlugins.push(await viteNotice())
|
52
|
+
// vite-plugin-mock
|
53
|
+
const useMock = isDev || VITE_USE_MOCK
|
54
|
+
useMock && vitePlugins.push(vitePluginFakeServer({
|
55
|
+
include: 'mock/routers',
|
56
|
+
enableProd: VITE_USE_MOCK
|
57
|
+
}),)
|
58
|
+
|
59
|
+
// rollup-plugin-visualizer
|
60
|
+
vitePlugins.push(configVisualizerConfig())
|
61
|
+
|
62
|
+
// unplugin-auto-import/vite
|
63
|
+
vitePlugins.push(createAutoImport())
|
64
|
+
|
65
|
+
// The following plugins only work in the production environment
|
66
|
+
if (isBuild) {
|
67
|
+
// rollup-plugin-gzip
|
68
|
+
vitePlugins.push(
|
69
|
+
configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE)
|
70
|
+
)
|
71
|
+
}
|
72
|
+
|
73
|
+
return vitePlugins
|
74
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
import { visualizer } from 'rollup-plugin-visualizer'
|
2
|
+
import { isReportMode } from '../../util'
|
3
|
+
|
4
|
+
export function configVisualizerConfig() {
|
5
|
+
if (isReportMode()) {
|
6
|
+
return visualizer({
|
7
|
+
filename: './node_modules/.cache/visualizer/stats.html',
|
8
|
+
open: true,
|
9
|
+
gzipSize: true,
|
10
|
+
brotliSize: true
|
11
|
+
}) as Plugin
|
12
|
+
}
|
13
|
+
return []
|
14
|
+
}
|
@@ -0,0 +1,40 @@
|
|
1
|
+
import type { Plugin } from 'vite'
|
2
|
+
import chalk from 'chalk'
|
3
|
+
import { readPackageJSON } from 'pkg-types'
|
4
|
+
import { defaultSettings } from '../../../../config'
|
5
|
+
import { getPackageSize, getRootPath, rootPath } from '../../util'
|
6
|
+
|
7
|
+
const { build } = defaultSettings
|
8
|
+
|
9
|
+
export default async function viteNotice(): Promise<Plugin> {
|
10
|
+
let config: { command: string }
|
11
|
+
const { name = '' } = await readPackageJSON(rootPath)
|
12
|
+
|
13
|
+
return {
|
14
|
+
name: 'vite:notice',
|
15
|
+
configResolved(resolvedConfig) {
|
16
|
+
config = resolvedConfig
|
17
|
+
},
|
18
|
+
buildStart() {
|
19
|
+
console.log(
|
20
|
+
chalk.bold(
|
21
|
+
chalk.green(
|
22
|
+
`👏Welcome to use ${chalk.blue(
|
23
|
+
'[gx-design-pro]'
|
24
|
+
)}, If you feel good, remember to click on the link below to give a star https://github.com/gx12358/vue3-antd-admin`
|
25
|
+
)
|
26
|
+
)
|
27
|
+
)
|
28
|
+
},
|
29
|
+
closeBundle() {
|
30
|
+
if (config.command === 'build') {
|
31
|
+
getPackageSize({
|
32
|
+
folder: getRootPath(build.outputDir),
|
33
|
+
callBack: (size: string) => {
|
34
|
+
console.log(chalk.bold(chalk.green(`✨ ${chalk.blue(`[${name}]`)} all build successfully, Total files ${size}`)))
|
35
|
+
}
|
36
|
+
})
|
37
|
+
}
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
@@ -0,0 +1,15 @@
|
|
1
|
+
export const permissions = {
|
2
|
+
'1': [ '*:*:*' ],
|
3
|
+
'2': [
|
4
|
+
'proTable:button:add',
|
5
|
+
'proTable:button:1',
|
6
|
+
'proTable:button:2',
|
7
|
+
'proTable:button:3'
|
8
|
+
],
|
9
|
+
'3': [
|
10
|
+
'proTable:button:1',
|
11
|
+
'proTable:button:2',
|
12
|
+
'proTable:button:3'
|
13
|
+
],
|
14
|
+
'4': [],
|
15
|
+
}
|
@@ -0,0 +1,96 @@
|
|
1
|
+
import Mockjs from 'mockjs'
|
2
|
+
import { permissions } from '../permissions'
|
3
|
+
import { handleRandomImage, getMobile } from '../../utils/util'
|
4
|
+
import userIds from './id'
|
5
|
+
|
6
|
+
const admin = [ 1, 2 ]
|
7
|
+
|
8
|
+
export interface RolesInfo {
|
9
|
+
roleId: number;
|
10
|
+
roleKey: string;
|
11
|
+
roleName: string;
|
12
|
+
status: string;
|
13
|
+
}
|
14
|
+
|
15
|
+
export interface UserList {
|
16
|
+
id: number;
|
17
|
+
name: string;
|
18
|
+
}
|
19
|
+
|
20
|
+
export const accessTokens = {
|
21
|
+
gx12358: 'gx-accessToken',
|
22
|
+
admin: 'admin-accessToken',
|
23
|
+
editor: 'editor-accessToken',
|
24
|
+
no_editor: 'test-accessToken'
|
25
|
+
}
|
26
|
+
|
27
|
+
export const accounts = {
|
28
|
+
admin: 'gx.design',
|
29
|
+
gx12358: 'aa123456',
|
30
|
+
editor: 'gx.design',
|
31
|
+
no_editor: 'gx.design'
|
32
|
+
}
|
33
|
+
|
34
|
+
export const rolesInfo: RolesInfo[] = [
|
35
|
+
{
|
36
|
+
roleId: 1,
|
37
|
+
roleKey: 'gx-admin',
|
38
|
+
roleName: 'gx12358-超级管理员',
|
39
|
+
status: '0'
|
40
|
+
},
|
41
|
+
{
|
42
|
+
roleId: 2,
|
43
|
+
roleKey: 'admin',
|
44
|
+
roleName: '超级管理员',
|
45
|
+
status: '0'
|
46
|
+
},
|
47
|
+
{
|
48
|
+
roleId: 3,
|
49
|
+
roleKey: 'editor',
|
50
|
+
roleName: '编辑人员',
|
51
|
+
status: '0'
|
52
|
+
}
|
53
|
+
]
|
54
|
+
|
55
|
+
export const tokenAccount = {
|
56
|
+
'1': accessTokens.gx12358,
|
57
|
+
'2': accessTokens.admin,
|
58
|
+
'3': accessTokens.editor,
|
59
|
+
'4': accessTokens.no_editor
|
60
|
+
}
|
61
|
+
|
62
|
+
const rolesInfoAccount = {
|
63
|
+
'1': rolesInfo.filter(item => [ 1 ].includes(item.roleId)),
|
64
|
+
'2': rolesInfo.filter(item => [ 2 ].includes(item.roleId)),
|
65
|
+
'3': rolesInfo.filter(item => [ 3 ].includes(item.roleId)),
|
66
|
+
'4': rolesInfo.filter(item => [ 3 ].includes(item.roleId))
|
67
|
+
}
|
68
|
+
|
69
|
+
export const defaultUser = (id = 2) => ({
|
70
|
+
permissions: permissions[String(id)],
|
71
|
+
roles: rolesInfoAccount[String(id)].map(item => item.roleKey),
|
72
|
+
user: {
|
73
|
+
userId: Number(id),
|
74
|
+
admin: admin.includes(Number(id)),
|
75
|
+
roles: rolesInfoAccount[String(id)],
|
76
|
+
roleIds: rolesInfoAccount[String(id)].map(item => item.roleId),
|
77
|
+
nickName: Mockjs.Random.name(),
|
78
|
+
avatar: handleRandomImage(100, 100),
|
79
|
+
address: Mockjs.Random.city(),
|
80
|
+
email: 'gx12358@gmail.com',
|
81
|
+
phonenumber: getMobile(),
|
82
|
+
remark: Mockjs.Random.paragraph(1),
|
83
|
+
tags: Array.from({ length: Mockjs.Random.integer(4, 8) }).map(_ => Mockjs.Random.word(1)).join(),
|
84
|
+
userName: Object.keys(accessTokens).find(el => tokenAccount[String(id)] === accessTokens[el])
|
85
|
+
} as Partial<UserDetails>
|
86
|
+
})
|
87
|
+
|
88
|
+
export const otherAccountList: UserList[] = [ '付小小', '曲丽丽', '林东东', '周星星', '吴加好', '朱偏右', '鱼酱', '乐哥', '谭小仪', '仲尼' ]
|
89
|
+
.map((name, key) => {
|
90
|
+
return {
|
91
|
+
id: key + 1,
|
92
|
+
name
|
93
|
+
}
|
94
|
+
})
|
95
|
+
|
96
|
+
export const userList: UserInfo[] = userIds.map(item => defaultUser(item.id)) as unknown as UserInfo[]
|
@@ -0,0 +1,55 @@
|
|
1
|
+
import { defaultSettings } from '@gx-config'
|
2
|
+
import { isArray, isBoolean, isFunction } from '@gx-design-vue/pro-utils'
|
3
|
+
import { omit } from 'lodash-es'
|
4
|
+
// @ts-ignore
|
5
|
+
import { defineFakeRoute } from 'vite-plugin-fake-server/client'
|
6
|
+
import { checkBackDataFun, getToken } from './utils/util'
|
7
|
+
|
8
|
+
const { mock } = defaultSettings
|
9
|
+
|
10
|
+
export interface MockResponse {
|
11
|
+
body: any;
|
12
|
+
query: any;
|
13
|
+
headers: RequestHeater
|
14
|
+
}
|
15
|
+
|
16
|
+
export type MockResponseCallback =
|
17
|
+
| ((response: MockResponse, token?: string) => any)
|
18
|
+
| string | number | Recordable | any[] | null
|
19
|
+
|
20
|
+
export type MockConfig = FakeRouteConfig & {
|
21
|
+
merageRoot?: boolean;
|
22
|
+
carryToken?: boolean;
|
23
|
+
callback: MockResponseCallback;
|
24
|
+
}
|
25
|
+
|
26
|
+
function getRequestData(callback: MockResponseCallback, request: MockResponse, token?: string) {
|
27
|
+
if (isFunction(callback)) {
|
28
|
+
return callback?.(request, token)
|
29
|
+
}
|
30
|
+
|
31
|
+
return callback
|
32
|
+
}
|
33
|
+
|
34
|
+
function getMockRouteConfig(config: MockConfig) {
|
35
|
+
const carryToken = isBoolean(config.carryToken) ? config.carryToken : true
|
36
|
+
return {
|
37
|
+
...omit(config, 'callback'),
|
38
|
+
url: `${mock.prefix}${config.url}`,
|
39
|
+
response: (request: MockResponse) => {
|
40
|
+
if (carryToken) {
|
41
|
+
const token = getToken(request.headers)
|
42
|
+
return checkBackDataFun(getRequestData(config.callback, request, token) || {}, token || '', config.merageRoot)
|
43
|
+
}
|
44
|
+
return getRequestData(config.callback, request)
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
export function createMockRoute(router: MockConfig | MockConfig[]) {
|
50
|
+
const fakeRoute = isArray(router)
|
51
|
+
? router.map(item => getMockRouteConfig(item))
|
52
|
+
: getMockRouteConfig(router)
|
53
|
+
|
54
|
+
return defineFakeRoute(fakeRoute)
|
55
|
+
}
|
@@ -0,0 +1,22 @@
|
|
1
|
+
import type { ListSearchParams } from '../../utils/table'
|
2
|
+
import Mockjs from 'mockjs'
|
3
|
+
import { createMockRoute } from '../../../mock'
|
4
|
+
import { handlePageList, initContent } from '../../utils/table'
|
5
|
+
|
6
|
+
const dataSource = initContent<TableRecord<any>>(120, () => ({
|
7
|
+
title: Mockjs.Random.ctitle(),
|
8
|
+
}))
|
9
|
+
|
10
|
+
export default createMockRoute({
|
11
|
+
url: '/table/list',
|
12
|
+
method: 'post',
|
13
|
+
timeout: 200,
|
14
|
+
callback: ({ body }) => {
|
15
|
+
const { pageNum = 1, pageSize = 10 }: ListSearchParams = body
|
16
|
+
|
17
|
+
return {
|
18
|
+
list: handlePageList(dataSource, { pageNum, pageSize }),
|
19
|
+
totalCount: dataSource.length
|
20
|
+
}
|
21
|
+
}
|
22
|
+
})
|
@@ -0,0 +1,52 @@
|
|
1
|
+
import dayjs from 'dayjs'
|
2
|
+
import { cloneDeep } from 'lodash-es'
|
3
|
+
import { createMockRoute } from '../../../mock'
|
4
|
+
import { otherAccountList, userList } from '../../config/user'
|
5
|
+
import { tokenByUserInfo } from '../../utils/util'
|
6
|
+
|
7
|
+
export default createMockRoute([
|
8
|
+
{
|
9
|
+
url: '/user/queryUserDetail',
|
10
|
+
method: 'get',
|
11
|
+
merageRoot: true,
|
12
|
+
callback: (_, token) => {
|
13
|
+
if (token) {
|
14
|
+
const tokenUserInfo = tokenByUserInfo(token)
|
15
|
+
if (tokenUserInfo && tokenUserInfo?.userId) {
|
16
|
+
const userInfo = userList.find(item => item.user.userId === tokenUserInfo?.userId)
|
17
|
+
if (userInfo) {
|
18
|
+
userInfo.user.loginDate = dayjs().format('YYYY-MM-DD HH:mm:ss')
|
19
|
+
return userInfo
|
20
|
+
}
|
21
|
+
}
|
22
|
+
}
|
23
|
+
|
24
|
+
return {
|
25
|
+
code: 500,
|
26
|
+
message: '用户信息获取失败'
|
27
|
+
}
|
28
|
+
}
|
29
|
+
},
|
30
|
+
{
|
31
|
+
url: '/user/account/update',
|
32
|
+
method: 'post',
|
33
|
+
timeout: 200,
|
34
|
+
callback: () => null
|
35
|
+
},
|
36
|
+
{
|
37
|
+
url: '/user/account/list',
|
38
|
+
method: 'get',
|
39
|
+
timeout: 200,
|
40
|
+
callback: () => cloneDeep(otherAccountList)
|
41
|
+
},
|
42
|
+
{
|
43
|
+
url: '/user/account/count',
|
44
|
+
method: 'get',
|
45
|
+
timeout: 200,
|
46
|
+
callback: () => ({
|
47
|
+
articles: 50,
|
48
|
+
applications: 40,
|
49
|
+
projects: 60
|
50
|
+
})
|
51
|
+
}
|
52
|
+
])
|
@@ -0,0 +1,46 @@
|
|
1
|
+
import { createMockRoute } from '../../../mock'
|
2
|
+
import { accessTokens, accounts } from '../../config/user'
|
3
|
+
import { createrToken } from '../../utils/util'
|
4
|
+
|
5
|
+
export default createMockRoute([
|
6
|
+
{
|
7
|
+
url: '/user/login',
|
8
|
+
method: 'post',
|
9
|
+
carryToken: false,
|
10
|
+
callback: ({ body }) => {
|
11
|
+
const { userName, password } = body
|
12
|
+
const accessToken = accessTokens[userName]
|
13
|
+
if (accounts[userName] !== password || !accessToken) {
|
14
|
+
return {
|
15
|
+
code: 500,
|
16
|
+
msg: '帐户或密码不正确。'
|
17
|
+
}
|
18
|
+
}
|
19
|
+
return {
|
20
|
+
code: 200,
|
21
|
+
msg: 'success',
|
22
|
+
data: {
|
23
|
+
token: createrToken(accessToken),
|
24
|
+
expiresIn: 720
|
25
|
+
}
|
26
|
+
}
|
27
|
+
}
|
28
|
+
},
|
29
|
+
{
|
30
|
+
url: '/user/register',
|
31
|
+
method: 'post',
|
32
|
+
carryToken: false,
|
33
|
+
callback: () => {
|
34
|
+
return {
|
35
|
+
code: 200,
|
36
|
+
msg: '模拟注册成功'
|
37
|
+
}
|
38
|
+
}
|
39
|
+
},
|
40
|
+
{
|
41
|
+
url: '/user/logout',
|
42
|
+
method: 'get',
|
43
|
+
timeout: 200,
|
44
|
+
callback: null
|
45
|
+
}
|
46
|
+
])
|
@@ -0,0 +1,21 @@
|
|
1
|
+
import { Base64, isArray, isJSONStr, isObject } from '@gx-design-vue/pro-utils'
|
2
|
+
|
3
|
+
const cryptoBase64 = new Base64()
|
4
|
+
|
5
|
+
// 加密方法
|
6
|
+
export function Encrypt(word: string | object) {
|
7
|
+
let str: string
|
8
|
+
if (isObject(word) || isArray(word)) {
|
9
|
+
str = JSON.stringify(word)
|
10
|
+
} else {
|
11
|
+
str = word as string
|
12
|
+
}
|
13
|
+
|
14
|
+
return cryptoBase64.encode(str as string)
|
15
|
+
}
|
16
|
+
|
17
|
+
// 解密方法
|
18
|
+
export function Decrypt(word: string) {
|
19
|
+
const decryptedStr = cryptoBase64.decode(word)
|
20
|
+
return isJSONStr(decryptedStr) ? JSON.parse(decryptedStr) : decryptedStr
|
21
|
+
}
|