@gx-design-vue/create-gx-cli 0.1.14 → 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.
Files changed (124) hide show
  1. package/package.json +1 -1
  2. package/src/cli.js +7 -4
  3. package/src/main.js +7 -7
  4. package/template-mobile-vant-cli/.env +3 -0
  5. package/template-mobile-vant-cli/.env.development +4 -6
  6. package/template-mobile-vant-cli/.env.pro +16 -7
  7. package/template-mobile-vant-cli/.env.production +21 -9
  8. package/template-mobile-vant-cli/commitlint.config.cjs +32 -0
  9. package/template-mobile-vant-cli/config/default/defaultSettings.ts +70 -0
  10. package/template-mobile-vant-cli/config/default/network.ts +10 -0
  11. package/template-mobile-vant-cli/config/default/proxy.ts +50 -0
  12. package/template-mobile-vant-cli/config/default/theme.ts +3 -0
  13. package/template-mobile-vant-cli/config/index.ts +11 -0
  14. package/template-mobile-vant-cli/eslint.config.js +10 -2
  15. package/template-mobile-vant-cli/index.html +22 -21
  16. package/template-mobile-vant-cli/{build → internal/vite-config/generate}/generateModifyVars.ts +1 -1
  17. package/template-mobile-vant-cli/internal/vite-config/rollupOptions/index.ts +22 -0
  18. package/template-mobile-vant-cli/internal/vite-config/util/hash.ts +17 -0
  19. package/template-mobile-vant-cli/internal/vite-config/util/index.ts +132 -0
  20. package/template-mobile-vant-cli/internal/vite-config/vite/cdn.ts +65 -0
  21. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/optimizer.ts +9 -1
  22. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/appConfig.ts +91 -0
  23. package/template-mobile-vant-cli/{build → internal/vite-config/vite}/plugin/autoImport.ts +7 -3
  24. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/compress.ts +31 -0
  25. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/html.ts +32 -0
  26. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/index.ts +74 -0
  27. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/visualizer.ts +14 -0
  28. package/template-mobile-vant-cli/internal/vite-config/vite/plugin/viteNotice.ts +40 -0
  29. package/template-mobile-vant-cli/mock/config/permissions.ts +15 -0
  30. package/template-mobile-vant-cli/mock/config/user/id.ts +5 -0
  31. package/template-mobile-vant-cli/mock/config/user/index.ts +96 -0
  32. package/template-mobile-vant-cli/mock/index.ts +55 -0
  33. package/template-mobile-vant-cli/mock/routers/table/index.fake.ts +22 -0
  34. package/template-mobile-vant-cli/mock/routers/user/account.fake.ts +52 -0
  35. package/template-mobile-vant-cli/mock/routers/user/index.fake.ts +46 -0
  36. package/template-mobile-vant-cli/mock/utils/crypto.ts +21 -0
  37. package/template-mobile-vant-cli/mock/utils/table.ts +96 -0
  38. package/template-mobile-vant-cli/mock/utils/util.ts +91 -0
  39. package/template-mobile-vant-cli/package.json +51 -34
  40. package/template-mobile-vant-cli/public/css/default.css +54 -0
  41. package/template-mobile-vant-cli/src/App.vue +6 -2
  42. package/template-mobile-vant-cli/src/assets/logo.png +0 -0
  43. package/template-mobile-vant-cli/src/components/PageContainer/ProSkeleton.tsx +1 -1
  44. package/template-mobile-vant-cli/src/components/PageContainer/index.tsx +108 -16
  45. package/template-mobile-vant-cli/src/components/PageContainer/style.module.less +5 -2
  46. package/template-mobile-vant-cli/src/components/TabsMenu/index.vue +45 -0
  47. package/template-mobile-vant-cli/src/core/gx-design/index.ts +1 -1
  48. package/template-mobile-vant-cli/src/core/index.ts +0 -7
  49. package/template-mobile-vant-cli/src/design/color.less +1 -0
  50. package/template-mobile-vant-cli/src/design/config.less +5 -0
  51. package/template-mobile-vant-cli/src/design/index.less +1 -1
  52. package/template-mobile-vant-cli/src/design/mixin.less +65 -0
  53. package/template-mobile-vant-cli/src/design/reset.less +16 -132
  54. package/template-mobile-vant-cli/src/hooks/web/usePageLoading.ts +7 -9
  55. package/template-mobile-vant-cli/src/layout/{BasicLayout.vue → BasicLayout/index.vue} +3 -1
  56. package/template-mobile-vant-cli/src/layout/BasicLayout/style.less +3 -0
  57. package/template-mobile-vant-cli/src/layout/UserLayout/index.vue +18 -0
  58. package/template-mobile-vant-cli/src/layout/UserLayout/style.module.less +36 -0
  59. package/template-mobile-vant-cli/src/main.ts +16 -9
  60. package/template-mobile-vant-cli/src/pages/Account/details.vue +13 -0
  61. package/template-mobile-vant-cli/src/pages/Account/index.vue +102 -0
  62. package/template-mobile-vant-cli/src/pages/{home.vue → Home/index.vue} +5 -5
  63. package/template-mobile-vant-cli/src/pages/user/login/index.vue +74 -0
  64. package/template-mobile-vant-cli/src/plugins/dayjs/index.ts +3 -0
  65. package/template-mobile-vant-cli/src/plugins/index.ts +2 -0
  66. package/template-mobile-vant-cli/src/router/guard/index.ts +18 -0
  67. package/template-mobile-vant-cli/src/router/guard/permissions.ts +41 -0
  68. package/template-mobile-vant-cli/src/router/guard/stateGuard.ts +10 -0
  69. package/template-mobile-vant-cli/src/router/index.ts +21 -15
  70. package/template-mobile-vant-cli/src/router/routes/index.ts +46 -0
  71. package/template-mobile-vant-cli/src/router/routes/modules/dataSource.ts +32 -0
  72. package/template-mobile-vant-cli/src/services/userCenter/account.ts +42 -0
  73. package/template-mobile-vant-cli/src/services/userCenter/index.ts +28 -0
  74. package/template-mobile-vant-cli/src/store/index.ts +4 -1
  75. package/template-mobile-vant-cli/src/store/modules/global.ts +6 -13
  76. package/template-mobile-vant-cli/src/store/modules/user.ts +107 -0
  77. package/template-mobile-vant-cli/src/utils/accessToken.ts +97 -0
  78. package/template-mobile-vant-cli/src/utils/crypto/index.ts +3 -4
  79. package/template-mobile-vant-cli/src/utils/env.ts +2 -2
  80. package/template-mobile-vant-cli/src/utils/pageTitle.ts +12 -6
  81. package/template-mobile-vant-cli/src/utils/request/XHR.ts +9 -11
  82. package/template-mobile-vant-cli/src/utils/request/axiosCancel.ts +5 -5
  83. package/template-mobile-vant-cli/src/utils/request/checkStatus.ts +18 -2
  84. package/template-mobile-vant-cli/src/utils/request/index.ts +36 -23
  85. package/template-mobile-vant-cli/src/utils/storage.ts +49 -32
  86. package/template-mobile-vant-cli/src/utils/validate.ts +31 -36
  87. package/template-mobile-vant-cli/tsconfig.json +17 -9
  88. package/template-mobile-vant-cli/types/auto-imports.d.ts +18 -2
  89. package/template-mobile-vant-cli/types/components.d.ts +2 -7
  90. package/template-mobile-vant-cli/types/config.d.ts +56 -0
  91. package/template-mobile-vant-cli/types/global.d.ts +62 -21
  92. package/template-mobile-vant-cli/types/mock.d.ts +34 -0
  93. package/template-mobile-vant-cli/types/module.d.ts +33 -0
  94. package/template-mobile-vant-cli/types/response.d.ts +3 -1
  95. package/template-mobile-vant-cli/types/system.d.ts +58 -0
  96. package/template-mobile-vant-cli/types/vant-import.d.ts +16 -5
  97. package/template-mobile-vant-cli/unocss.config.ts +120 -66
  98. package/template-mobile-vant-cli/vite.config.ts +78 -81
  99. package/template-mobile-vant-cli/build/cdn.ts +0 -5
  100. package/template-mobile-vant-cli/build/plugin/html.ts +0 -26
  101. package/template-mobile-vant-cli/build/plugin/index.ts +0 -42
  102. package/template-mobile-vant-cli/build/plugin/mock.ts +0 -14
  103. package/template-mobile-vant-cli/build/plugin/viteMock/client.ts +0 -88
  104. package/template-mobile-vant-cli/build/plugin/viteMock/createMockServer.ts +0 -271
  105. package/template-mobile-vant-cli/build/plugin/viteMock/index.ts +0 -69
  106. package/template-mobile-vant-cli/build/plugin/viteMock/types.ts +0 -48
  107. package/template-mobile-vant-cli/build/plugin/viteMock/utils.ts +0 -48
  108. package/template-mobile-vant-cli/build/script/postBuild.ts +0 -14
  109. package/template-mobile-vant-cli/mock/_createProductionServer.ts +0 -19
  110. package/template-mobile-vant-cli/mock/utils.ts +0 -9
  111. package/template-mobile-vant-cli/postcss.config.cjs +0 -8
  112. package/template-mobile-vant-cli/prettier.config.cjs +0 -18
  113. package/template-mobile-vant-cli/public/js/flexible.js +0 -44
  114. package/template-mobile-vant-cli/src/core/vant-design/index.ts +0 -4
  115. package/template-mobile-vant-cli/src/design/vant.less +0 -2
  116. package/template-mobile-vant-cli/src/global.less +0 -1
  117. package/template-mobile-vant-cli/src/layout/basicLayout.less +0 -11
  118. package/template-mobile-vant-cli/src/router/routes.ts +0 -20
  119. package/template-mobile-vant-cli/src/router/typings.ts +0 -8
  120. package/template-mobile-vant-cli/src/settings/index.ts +0 -10
  121. package/template-mobile-vant-cli/src/utils/crypto/base64.ts +0 -101
  122. package/template-mobile-vant-cli/types/ant-design-import.d.ts +0 -13
  123. package/template-mobile-vant-cli/types/plugins-auto-import.d.ts +0 -14
  124. /package/template-mobile-vant-cli/{mock/datasSource/api/index.ts → src/design/vant/index.less} +0 -0
@@ -0,0 +1,65 @@
1
+ import fs from 'node:fs'
2
+ import path from 'node:path'
3
+ import { defaultSettings } from '../../../config'
4
+
5
+ const { cdn } = defaultSettings
6
+
7
+ const { modules = [], url = '' } = cdn
8
+
9
+ function getModuleVersion(name: string): string {
10
+ const pwd = process.cwd()
11
+ const pkgFile = path.join(pwd, 'node_modules', name, 'package.json')
12
+ if (fs.existsSync(pkgFile)) {
13
+ const pkgJson = JSON.parse(fs.readFileSync(pkgFile, 'utf8'))
14
+ return pkgJson.version
15
+ }
16
+
17
+ return ''
18
+ }
19
+
20
+ function isFullPath(path: string) {
21
+ return path.startsWith('http:') || path.startsWith('https:') || path.startsWith('//')
22
+ }
23
+
24
+ function renderUrl(data: CdnModuleList & {
25
+ version: string
26
+ }) {
27
+ const { path } = data
28
+ if (isFullPath(path))
29
+ return path
30
+ return url.replace(/\{name\}/g, data.name)
31
+ .replace(/\{version\}/g, data.version)
32
+ .replace(/\{path\}/g, path)
33
+ }
34
+
35
+ function getCdnModuleFiles() {
36
+ return modules.map((m) => {
37
+ const version = getModuleVersion(m.name)
38
+ if (!version) {
39
+ throw new Error(`modules: ${m.name} package.json file does not exist`)
40
+ }
41
+
42
+ let css = m.css || [] as string[]
43
+ if (!Array.isArray(css) && css) {
44
+ css = [ css ]
45
+ }
46
+
47
+ return {
48
+ js: renderUrl({
49
+ ...m,
50
+ version
51
+ }),
52
+ css
53
+ }
54
+ })
55
+ }
56
+
57
+ export function getExternalMap() {
58
+ const externalMap = {}
59
+ modules.forEach((v) => {
60
+ externalMap[v.name] = v.globalName
61
+ })
62
+ return externalMap
63
+ }
64
+
65
+ export default getCdnModuleFiles()
@@ -4,13 +4,21 @@ const vendorLibs: { match: string[]; output: string }[] = [
4
4
  {
5
5
  match: ['vant'],
6
6
  output: 'vant',
7
+ },
8
+ {
9
+ match: ['crypto-js'],
10
+ output: 'crypto-js',
11
+ },
12
+ {
13
+ match: ['lodash-es'],
14
+ output: 'lodash-es',
7
15
  }
8
16
  ]
9
17
 
10
18
  export const configManualChunk: GetManualChunk = (id: string) => {
11
19
  if (/[\\/]node_modules[\\/]/.test(id)) {
12
20
  const matchItem = vendorLibs.find((item) => {
13
- const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig')
21
+ const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'gi')
14
22
  return reg.test(id)
15
23
  })
16
24
  return matchItem ? matchItem.output : null
@@ -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 { VantResolver } from 'unplugin-vue-components/resolvers'
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/plugins-auto-import.d.ts'
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,5 @@
1
+ import { getArraryList } from '../../utils/util'
2
+
3
+ export default getArraryList(4, index => ({
4
+ id: index + 1
5
+ }))
@@ -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
+ ])