Commit 07c18d602ec47215c0390096a3fa66b40004d041

Authored by vben
1 parent 23657547

chore: add some notes

.editorconfig
@@ -3,7 +3,7 @@ root = true @@ -3,7 +3,7 @@ root = true
3 [*] 3 [*]
4 charset=utf-8 4 charset=utf-8
5 end_of_line=lf 5 end_of_line=lf
6 -insert_final_newline=false 6 +insert_final_newline=true
7 indent_style=space 7 indent_style=space
8 indent_size=2 8 indent_size=2
9 9
.eslintignore
1 1
2 *.sh 2 *.sh
3 node_modules 3 node_modules
4 -lib  
5 *.md 4 *.md
6 -*.scss  
7 *.woff 5 *.woff
8 *.ttf 6 *.ttf
9 .vscode 7 .vscode
10 .idea 8 .idea
11 -/dist/  
12 -/mock/ 9 +dist
13 /public 10 /public
14 /docs 11 /docs
15 -.vscode 12 +.husky
16 .local 13 .local
17 /bin 14 /bin
18 -/build  
19 -/config  
20 Dockerfile 15 Dockerfile
21 -vue.config.js  
22 -commit-lint.js  
23 -postcss.config.js  
24 -stylelint.config.js  
25 -commitlint.config.js  
.eslintrc.js
@@ -23,21 +23,7 @@ module.exports = { @@ -23,21 +23,7 @@ module.exports = {
23 '@typescript-eslint/no-empty-function': 'off', 23 '@typescript-eslint/no-empty-function': 'off',
24 'vue/custom-event-name-casing': 'off', 24 'vue/custom-event-name-casing': 'off',
25 'no-use-before-define': 'off', 25 'no-use-before-define': 'off',
26 - // 'no-setting-before-define': [  
27 - // 'error',  
28 - // {  
29 - // functions: false,  
30 - // classes: true,  
31 - // },  
32 - // ],  
33 '@typescript-eslint/no-use-before-define': 'off', 26 '@typescript-eslint/no-use-before-define': 'off',
34 - // '@typescript-eslint/no-setting-before-define': [  
35 - // 'error',  
36 - // {  
37 - // functions: false,  
38 - // classes: true,  
39 - // },  
40 - // ],  
41 '@typescript-eslint/ban-ts-comment': 'off', 27 '@typescript-eslint/ban-ts-comment': 'off',
42 '@typescript-eslint/ban-types': 'off', 28 '@typescript-eslint/ban-types': 'off',
43 '@typescript-eslint/no-non-null-assertion': 'off', 29 '@typescript-eslint/no-non-null-assertion': 'off',
.husky/pre-commit
@@ -4,5 +4,9 @@ @@ -4,5 +4,9 @@
4 4
5 [ -n "$CI" ] && exit 0 5 [ -n "$CI" ] && exit 0
6 6
  7 +# Check the file name
  8 +# ! ls-lint cannot be used normally in mac pro of M1 system.
7 npm run lint:ls-lint 9 npm run lint:ls-lint
  10 +
  11 +# Format and submit code according to lintstagedrc.js configuration
8 npm run lint:lint-staged 12 npm run lint:lint-staged
build/vite/optimizer.ts
  1 +// TODO
1 import type { GetManualChunk, GetManualChunkApi } from 'rollup'; 2 import type { GetManualChunk, GetManualChunkApi } from 'rollup';
2 3
3 // 4 //
@@ -10,6 +11,7 @@ const vendorLibs: { match: string[]; output: string }[] = [ @@ -10,6 +11,7 @@ const vendorLibs: { match: string[]; output: string }[] = [
10 11
11 // @ts-ignore 12 // @ts-ignore
12 export const configManualChunk: GetManualChunk = (id: string, api: GetManualChunkApi) => { 13 export const configManualChunk: GetManualChunk = (id: string, api: GetManualChunkApi) => {
  14 + console.log(api);
13 if (/[\\/]node_modules[\\/]/.test(id)) { 15 if (/[\\/]node_modules[\\/]/.test(id)) {
14 const matchItem = vendorLibs.find((item) => { 16 const matchItem = vendorLibs.find((item) => {
15 const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig'); 17 const reg = new RegExp(`[\\/]node_modules[\\/]_?(${item.match.join('|')})(.*)`, 'ig');
build/vite/plugin/gzip.ts
  1 +/**
  2 + * Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
  3 + */
  4 +import type { Plugin } from 'vite';
  5 +
1 import gzipPlugin from 'rollup-plugin-gzip'; 6 import gzipPlugin from 'rollup-plugin-gzip';
2 import { isBuildGzip } from '../../utils'; 7 import { isBuildGzip } from '../../utils';
3 -import { Plugin } from 'vite'; 8 +
4 export function configGzipPlugin(isBuild: boolean): Plugin | Plugin[] { 9 export function configGzipPlugin(isBuild: boolean): Plugin | Plugin[] {
5 const useGzip = isBuild && isBuildGzip(); 10 const useGzip = isBuild && isBuildGzip();
6 11
build/vite/plugin/html.ts
  1 +/**
  2 + * Plugin to minimize and use ejs template syntax in index.html.
  3 + * https://github.com/anncwb/vite-plugin-html
  4 + */
1 import type { Plugin } from 'vite'; 5 import type { Plugin } from 'vite';
2 import type { ViteEnv } from '../../utils'; 6 import type { ViteEnv } from '../../utils';
  7 +
3 import html from 'vite-plugin-html'; 8 import html from 'vite-plugin-html';
4 9
5 import pkg from '../../../package.json'; 10 import pkg from '../../../package.json';
@@ -7,22 +12,27 @@ import { GLOB_CONFIG_FILE_NAME } from '../../constant'; @@ -7,22 +12,27 @@ import { GLOB_CONFIG_FILE_NAME } from '../../constant';
7 12
8 export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) { 13 export function configHtmlPlugin(env: ViteEnv, isBuild: boolean) {
9 const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env; 14 const { VITE_GLOB_APP_TITLE, VITE_PUBLIC_PATH } = env;
  15 +
10 const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`; 16 const path = VITE_PUBLIC_PATH.endsWith('/') ? VITE_PUBLIC_PATH : `${VITE_PUBLIC_PATH}/`;
11 17
  18 + const getAppConfigSrc = () => {
  19 + return `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${pkg.version}-${new Date().getTime()}`;
  20 + };
  21 +
12 const htmlPlugin: Plugin[] = html({ 22 const htmlPlugin: Plugin[] = html({
13 minify: isBuild, 23 minify: isBuild,
14 inject: { 24 inject: {
  25 + // Inject data into ejs template
15 injectData: { 26 injectData: {
16 title: VITE_GLOB_APP_TITLE, 27 title: VITE_GLOB_APP_TITLE,
17 }, 28 },
  29 + // Embed the generated app.config.js file
18 tags: isBuild 30 tags: isBuild
19 ? [ 31 ? [
20 { 32 {
21 tag: 'script', 33 tag: 'script',
22 attrs: { 34 attrs: {
23 - src: `${path || '/'}${GLOB_CONFIG_FILE_NAME}?v=${  
24 - pkg.version  
25 - }-${new Date().getTime()}`, 35 + src: getAppConfigSrc(),
26 }, 36 },
27 }, 37 },
28 ] 38 ]
build/vite/plugin/imagemin.ts
  1 +// Image resource files used to compress the output of the production environment
  2 +
1 import viteImagemin from 'vite-plugin-imagemin'; 3 import viteImagemin from 'vite-plugin-imagemin';
2 4
3 export function configImageminPlugin() { 5 export function configImageminPlugin() {
build/vite/plugin/index.ts
1 import type { Plugin } from 'vite'; 1 import type { Plugin } from 'vite';
2 2
3 import PurgeIcons from 'vite-plugin-purge-icons'; 3 import PurgeIcons from 'vite-plugin-purge-icons';
  4 +import vue from '@vitejs/plugin-vue';
  5 +import vueJsx from '@vitejs/plugin-vue-jsx';
  6 +import legacy from '@vitejs/plugin-legacy';
4 7
5 import { ViteEnv } from '../../utils'; 8 import { ViteEnv } from '../../utils';
6 import { configHtmlPlugin } from './html'; 9 import { configHtmlPlugin } from './html';
@@ -12,11 +15,18 @@ import { configVisualizerConfig } from './visualizer'; @@ -12,11 +15,18 @@ import { configVisualizerConfig } from './visualizer';
12 import { configThemePlugin } from './theme'; 15 import { configThemePlugin } from './theme';
13 import { configImageminPlugin } from './imagemin'; 16 import { configImageminPlugin } from './imagemin';
14 17
15 -// gen vite plugins  
16 export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { 18 export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
17 - const { VITE_USE_IMAGEMIN, VITE_USE_MOCK } = viteEnv; 19 + const { VITE_USE_IMAGEMIN, VITE_USE_MOCK, VITE_LEGACY } = viteEnv;
18 20
19 - const vitePlugins: (Plugin | Plugin[])[] = []; 21 + const vitePlugins: (Plugin | Plugin[])[] = [
  22 + // have to
  23 + vue(),
  24 + // have to
  25 + vueJsx(),
  26 + ];
  27 +
  28 + // @vitejs/plugin-legacy
  29 + VITE_LEGACY && isBuild && vitePlugins.push(legacy());
20 30
21 // vite-plugin-html 31 // vite-plugin-html
22 vitePlugins.push(configHtmlPlugin(viteEnv, isBuild)); 32 vitePlugins.push(configHtmlPlugin(viteEnv, isBuild));
@@ -36,6 +46,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) { @@ -36,6 +46,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
36 //vite-plugin-theme 46 //vite-plugin-theme
37 vitePlugins.push(configThemePlugin()); 47 vitePlugins.push(configThemePlugin());
38 48
  49 + // The following plugins only work in the production environment
39 if (isBuild) { 50 if (isBuild) {
40 //vite-plugin-imagemin 51 //vite-plugin-imagemin
41 VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin()); 52 VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
build/vite/plugin/mock.ts
  1 +/**
  2 + * Mock plugin for development and production.
  3 + * https://github.com/anncwb/vite-plugin-mock
  4 + */
1 import { viteMockServe } from 'vite-plugin-mock'; 5 import { viteMockServe } from 'vite-plugin-mock';
2 6
3 export function configMockPlugin(isBuild: boolean) { 7 export function configMockPlugin(isBuild: boolean) {
build/vite/plugin/pwa.ts
  1 +/**
  2 + * Zero-config PWA for Vite
  3 + * https://github.com/antfu/vite-plugin-pwa
  4 + */
  5 +
1 import { VitePWA } from 'vite-plugin-pwa'; 6 import { VitePWA } from 'vite-plugin-pwa';
2 7
3 import { ViteEnv } from '../../utils'; 8 import { ViteEnv } from '../../utils';
build/vite/plugin/styleImport.ts
  1 +/**
  2 + * Introduces component library styles on demand.
  3 + * https://github.com/anncwb/vite-plugin-style-import
  4 + */
  5 +
1 import styleImport from 'vite-plugin-style-import'; 6 import styleImport from 'vite-plugin-style-import';
2 7
3 export function configStyleImportPlugin() { 8 export function configStyleImportPlugin() {
build/vite/plugin/theme.ts
  1 +/**
  2 + * Vite plugin for website theme color switching
  3 + * https://github.com/anncwb/vite-plugin-theme
  4 + */
1 import { viteThemePlugin, mixLighten, mixDarken, tinycolor } from 'vite-plugin-theme'; 5 import { viteThemePlugin, mixLighten, mixDarken, tinycolor } from 'vite-plugin-theme';
2 import { getThemeColors, generateColors } from '../../config/themeConfig'; 6 import { getThemeColors, generateColors } from '../../config/themeConfig';
3 7
build/vite/plugin/visualizer.ts
  1 +/**
  2 + * Package file volume analysis
  3 + */
1 import visualizer from 'rollup-plugin-visualizer'; 4 import visualizer from 'rollup-plugin-visualizer';
2 import { isReportMode } from '../../utils'; 5 import { isReportMode } from '../../utils';
3 6
build/vite/proxy.ts
  1 +/**
  2 + * Used to parse the .env.development proxy configuration
  3 + */
1 import type { ServerOptions } from 'http-proxy'; 4 import type { ServerOptions } from 'http-proxy';
2 5
3 type ProxyItem = [string, string]; 6 type ProxyItem = [string, string];
mock/_util.ts
@@ -38,7 +38,7 @@ export function resultError(message = 'Request failed', { code = -1, result = nu @@ -38,7 +38,7 @@ export function resultError(message = 'Request failed', { code = -1, result = nu
38 } 38 }
39 39
40 export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]): T[] { 40 export function pagination<T = any>(pageNo: number, pageSize: number, array: T[]): T[] {
41 - let offset = (pageNo - 1) * Number(pageSize); 41 + const offset = (pageNo - 1) * Number(pageSize);
42 const ret = 42 const ret =
43 offset + Number(pageSize) >= array.length 43 offset + Number(pageSize) >= array.length
44 ? array.slice(offset, array.length) 44 ? array.slice(offset, array.length)
mock/demo/select-demo.ts
@@ -18,6 +18,7 @@ export default [ @@ -18,6 +18,7 @@ export default [
18 timeout: 4000, 18 timeout: 4000,
19 method: 'get', 19 method: 'get',
20 response: ({ query }) => { 20 response: ({ query }) => {
  21 + console.log(query);
21 return resultSuccess(demoList); 22 return resultSuccess(demoList);
22 }, 23 },
23 }, 24 },
package.json
@@ -14,8 +14,7 @@ @@ -14,8 +14,7 @@
14 "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite", 14 "clean:cache": "rimraf node_modules/.cache/ && rimraf node_modules/.vite",
15 "clean:lib": "npx rimraf node_modules", 15 "clean:lib": "npx rimraf node_modules",
16 "typecheck": "vuedx-typecheck .", 16 "typecheck": "vuedx-typecheck .",
17 - "lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" ",  
18 - "lint:eslint:fix": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix", 17 + "lint:eslint": "eslint \"{src,mock}/**/*.{vue,ts,tsx}\" --fix",
19 "lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"", 18 "lint:prettier": "prettier --write --loglevel warn \"src/**/*.{js,json,tsx,css,less,scss,vue,html,md}\"",
20 "lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/", 19 "lint:stylelint": "stylelint --fix \"**/*.{vue,less,postcss,css,scss}\" --cache --cache-location node_modules/.cache/stylelint/",
21 "lint:ls-lint": "ls-lint", 20 "lint:ls-lint": "ls-lint",
prettier.config.js
@@ -17,12 +17,4 @@ module.exports = { @@ -17,12 +17,4 @@ module.exports = {
17 htmlWhitespaceSensitivity: 'strict', 17 htmlWhitespaceSensitivity: 'strict',
18 endOfLine: 'lf', 18 endOfLine: 'lf',
19 rangeStart: 0, 19 rangeStart: 0,
20 - overrides: [  
21 - {  
22 - files: '*.md',  
23 - options: {  
24 - tabWidth: 2,  
25 - },  
26 - },  
27 - ],  
28 }; 20 };
src/components/Description/src/index.tsx
@@ -84,35 +84,36 @@ export default defineComponent({ @@ -84,35 +84,36 @@ export default defineComponent({
84 84
85 function renderItem() { 85 function renderItem() {
86 const { schema, data } = unref(getProps); 86 const { schema, data } = unref(getProps);
87 - return unref(schema).map((item) => {  
88 - const { render, field, span, show, contentMinWidth } = item;  
89 -  
90 - if (show && isFunction(show) && !show(data)) {  
91 - return null;  
92 - }  
93 -  
94 - const getContent = () => {  
95 - const _data = unref(data);  
96 - const getField = get(_data, field);  
97 - return isFunction(render) ? render(getField, _data) : getField ?? '';  
98 - };  
99 -  
100 - const width = contentMinWidth;  
101 - return (  
102 - <Descriptions.Item label={renderLabel(item)} key={field} span={span}>  
103 - {() => {  
104 - if (!contentMinWidth) {  
105 - return getContent();  
106 - }  
107 - const style: CSSProperties = {  
108 - minWidth: `${width}px`,  
109 - };  
110 - return <div style={style}>{getContent()}</div>;  
111 - }}  
112 - </Descriptions.Item>  
113 - );  
114 - })  
115 - .filter((item) => !!item); 87 + return unref(schema)
  88 + .map((item) => {
  89 + const { render, field, span, show, contentMinWidth } = item;
  90 +
  91 + if (show && isFunction(show) && !show(data)) {
  92 + return null;
  93 + }
  94 +
  95 + const getContent = () => {
  96 + const _data = unref(data);
  97 + const getField = get(_data, field);
  98 + return isFunction(render) ? render(getField, _data) : getField ?? '';
  99 + };
  100 +
  101 + const width = contentMinWidth;
  102 + return (
  103 + <Descriptions.Item label={renderLabel(item)} key={field} span={span}>
  104 + {() => {
  105 + if (!contentMinWidth) {
  106 + return getContent();
  107 + }
  108 + const style: CSSProperties = {
  109 + minWidth: `${width}px`,
  110 + };
  111 + return <div style={style}>{getContent()}</div>;
  112 + }}
  113 + </Descriptions.Item>
  114 + );
  115 + })
  116 + .filter((item) => !!item);
116 } 117 }
117 118
118 const renderDesc = () => { 119 const renderDesc = () => {
stylelint.config.js
@@ -28,7 +28,7 @@ module.exports = { @@ -28,7 +28,7 @@ module.exports = {
28 ignore: ['after-comment', 'first-nested'], 28 ignore: ['after-comment', 'first-nested'],
29 }, 29 },
30 ], 30 ],
31 - // ๆŒ‡ๅฎšๅฃฐๆ˜Žๅ—ๅ†…ๅฑžๆ€ง็š„ๅญ—ๆฏ้กบๅบ 31 + // Specify the alphabetical order of the attributes in the declaration block
32 'order/properties-order': [ 32 'order/properties-order': [
33 'position', 33 'position',
34 'top', 34 'top',
vite.config.ts
1 import type { UserConfig, ConfigEnv } from 'vite'; 1 import type { UserConfig, ConfigEnv } from 'vite';
2 -import { resolve } from 'path';  
3 -import vue from '@vitejs/plugin-vue';  
4 -import vueJsx from '@vitejs/plugin-vue-jsx';  
5 -import legacy from '@vitejs/plugin-legacy';  
6 2
7 import { loadEnv } from 'vite'; 3 import { loadEnv } from 'vite';
  4 +import { resolve } from 'path';
8 5
9 import { generateModifyVars } from './build/config/themeConfig'; 6 import { generateModifyVars } from './build/config/themeConfig';
10 import { createProxy } from './build/vite/proxy'; 7 import { createProxy } from './build/vite/proxy';
@@ -18,11 +15,14 @@ function pathResolve(dir: string) { @@ -18,11 +15,14 @@ function pathResolve(dir: string) {
18 return resolve(__dirname, '.', dir); 15 return resolve(__dirname, '.', dir);
19 } 16 }
20 17
21 -const root = process.cwd();  
22 -  
23 export default ({ command, mode }: ConfigEnv): UserConfig => { 18 export default ({ command, mode }: ConfigEnv): UserConfig => {
  19 + const root = process.cwd();
  20 +
24 const env = loadEnv(mode, root); 21 const env = loadEnv(mode, root);
  22 +
  23 + // The boolean type read by loadEnv is a string. This function can be converted to boolean type
25 const viteEnv = wrapperEnv(env); 24 const viteEnv = wrapperEnv(env);
  25 +
26 const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_LEGACY } = viteEnv; 26 const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_LEGACY } = viteEnv;
27 27
28 const isBuild = command === 'build'; 28 const isBuild = command === 'build';
@@ -32,12 +32,14 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; { @@ -32,12 +32,14 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
32 root, 32 root,
33 alias: [ 33 alias: [
34 { 34 {
  35 + // /@/xxxx => src/xxx
35 find: /^\/@\//, 36 find: /^\/@\//,
36 replacement: pathResolve('src') + '/', 37 replacement: pathResolve('src') + '/',
37 }, 38 },
38 ], 39 ],
39 server: { 40 server: {
40 port: VITE_PORT, 41 port: VITE_PORT,
  42 + // Load proxy configuration from .env
41 proxy: createProxy(VITE_PROXY), 43 proxy: createProxy(VITE_PROXY),
42 hmr: { 44 hmr: {
43 overlay: true, 45 overlay: true,
@@ -50,9 +52,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; { @@ -50,9 +52,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
50 terserOptions: { 52 terserOptions: {
51 compress: { 53 compress: {
52 keep_infinity: true, 54 keep_infinity: true,
  55 + // Used to delete console in production environment
53 drop_console: VITE_DROP_CONSOLE, 56 drop_console: VITE_DROP_CONSOLE,
54 }, 57 },
55 }, 58 },
  59 + // Turning off brotliSize display can slightly reduce packaging time
56 brotliSize: false, 60 brotliSize: false,
57 chunkSizeWarningLimit: 1200, 61 chunkSizeWarningLimit: 1200,
58 }, 62 },
@@ -68,6 +72,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; { @@ -68,6 +72,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
68 preprocessorOptions: { 72 preprocessorOptions: {
69 less: { 73 less: {
70 modifyVars: { 74 modifyVars: {
  75 + // Used for global import to avoid the need to import each style file separately
71 // reference: Avoid repeated references 76 // reference: Avoid repeated references
72 hack: `true; @import (reference) "${resolve('src/design/config.less')}";`, 77 hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
73 ...generateModifyVars(), 78 ...generateModifyVars(),
@@ -77,14 +82,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; { @@ -77,14 +82,11 @@ export default ({ command, mode }: ConfigEnv): UserConfig =&gt; {
77 }, 82 },
78 }, 83 },
79 84
80 - plugins: [  
81 - vue(),  
82 - vueJsx(),  
83 - ...(VITE_LEGACY && isBuild ? [legacy()] : []),  
84 - ...createVitePlugins(viteEnv, isBuild),  
85 - ], 85 + // The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
  86 + plugins: createVitePlugins(viteEnv, isBuild),
86 87
87 optimizeDeps: { 88 optimizeDeps: {
  89 + // @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
88 include: ['@iconify/iconify'], 90 include: ['@iconify/iconify'],
89 }, 91 },
90 }; 92 };