Commit 2f1fbf8e487fdae4db5c144d97f9d20e42bb1603

Authored by vben
1 parent 7658f4d6

style: add some notes

.eslintignore
@@ -20,9 +20,6 @@ lib @@ -20,9 +20,6 @@ lib
20 Dockerfile 20 Dockerfile
21 vue.config.js 21 vue.config.js
22 commit-lint.js 22 commit-lint.js
23 -/src/assets/iconfont/  
24 -/types/shims  
25 -/src/types/shims  
26 postcss.config.js 23 postcss.config.js
27 stylelint.config.js 24 stylelint.config.js
28 commitlint.config.js 25 commitlint.config.js
build/constant.ts
  1 +/**
  2 + * The name of the configuration file entered in the production environment
  3 + */
1 export const GLOB_CONFIG_FILE_NAME = '_app.config.js'; 4 export const GLOB_CONFIG_FILE_NAME = '_app.config.js';
build/getShortName.ts
  1 +/**
  2 + * Get the configuration file variable name
  3 + * @param env
  4 + */
1 export const getShortName = (env: any) => { 5 export const getShortName = (env: any) => {
2 return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__` 6 return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`
3 .toUpperCase() 7 .toUpperCase()
build/script/buildConf.ts
  1 +/**
  2 + * Generate additional configuration files when used for packaging. The file can be configured with some global variables, so that it can be changed directly externally without repackaging
  3 + */
1 import { GLOB_CONFIG_FILE_NAME } from '../constant'; 4 import { GLOB_CONFIG_FILE_NAME } from '../constant';
2 import fs, { writeFileSync } from 'fs-extra'; 5 import fs, { writeFileSync } from 'fs-extra';
3 6
4 import viteConfig from '../../vite.config'; 7 import viteConfig from '../../vite.config';
5 import { errorConsole, successConsole, getCwdPath, getEnvConfig } from '../utils'; 8 import { errorConsole, successConsole, getCwdPath, getEnvConfig } from '../utils';
6 -  
7 -const getShortName = (env: any) => {  
8 - return `__PRODUCTION__${env.VITE_GLOB_APP_SHORT_NAME || '__APP'}__CONF__`  
9 - .toUpperCase()  
10 - .replace(/\s/g, '');  
11 -}; 9 +import { getShortName } from '../getShortName';
12 10
13 function createConfig( 11 function createConfig(
14 { 12 {
@@ -20,6 +18,7 @@ function createConfig( @@ -20,6 +18,7 @@ function createConfig(
20 try { 18 try {
21 const windowConf = `window.${configName}`; 19 const windowConf = `window.${configName}`;
22 const outDir = viteConfig.outDir || 'dist'; 20 const outDir = viteConfig.outDir || 'dist';
  21 + // Ensure that the variable will not be modified
23 const configStr = `${windowConf}=${JSON.stringify(config)}; 22 const configStr = `${windowConf}=${JSON.stringify(config)};
24 23
25 Object.freeze(${windowConf}); 24 Object.freeze(${windowConf});
build/utils.ts
@@ -7,6 +7,7 @@ import chalk from 'chalk'; @@ -7,6 +7,7 @@ import chalk from 'chalk';
7 7
8 export const isFunction = (arg: unknown): arg is (...args: any[]) => any => 8 export const isFunction = (arg: unknown): arg is (...args: any[]) => any =>
9 typeof arg === 'function'; 9 typeof arg === 'function';
  10 +
10 export const isRegExp = (arg: unknown): arg is RegExp => 11 export const isRegExp = (arg: unknown): arg is RegExp =>
11 Object.prototype.toString.call(arg) === '[object RegExp]'; 12 Object.prototype.toString.call(arg) === '[object RegExp]';
12 13
@@ -43,6 +44,9 @@ export function readAllFile(root: string, reg: RegExp) { @@ -43,6 +44,9 @@ export function readAllFile(root: string, reg: RegExp) {
43 return resultArr; 44 return resultArr;
44 } 45 }
45 46
  47 +/**
  48 + * get client ip address
  49 + */
46 export function getIPAddress() { 50 export function getIPAddress() {
47 let interfaces = networkInterfaces(); 51 let interfaces = networkInterfaces();
48 for (let devName in interfaces) { 52 for (let devName in interfaces) {
@@ -67,12 +71,23 @@ export function isProdFn(): boolean { @@ -67,12 +71,23 @@ export function isProdFn(): boolean {
67 return process.env.NODE_ENV === 'production'; 71 return process.env.NODE_ENV === 'production';
68 } 72 }
69 73
  74 +/**
  75 + * Whether to generate package preview
  76 + */
70 export function isReportMode(): boolean { 77 export function isReportMode(): boolean {
71 return process.env.REPORT === 'true'; 78 return process.env.REPORT === 'true';
72 } 79 }
  80 +
  81 +/**
  82 + * Whether to generate gzip for packaging
  83 + */
73 export function isBuildGzip(): boolean { 84 export function isBuildGzip(): boolean {
74 return process.env.VITE_BUILD_GZIP === 'true'; 85 return process.env.VITE_BUILD_GZIP === 'true';
75 } 86 }
  87 +
  88 +/**
  89 + * Whether to generate package site
  90 + */
76 export function isSiteMode(): boolean { 91 export function isSiteMode(): boolean {
77 return process.env.SITE === 'true'; 92 return process.env.SITE === 'true';
78 } 93 }
@@ -89,6 +104,7 @@ export interface ViteEnv { @@ -89,6 +104,7 @@ export interface ViteEnv {
89 VITE_BUILD_GZIP: boolean; 104 VITE_BUILD_GZIP: boolean;
90 } 105 }
91 106
  107 +// Read all environment variable configuration files to process.env
92 export function loadEnv(): ViteEnv { 108 export function loadEnv(): ViteEnv {
93 const env = process.env.NODE_ENV; 109 const env = process.env.NODE_ENV;
94 const ret: any = {}; 110 const ret: any = {};
@@ -116,6 +132,11 @@ export function loadEnv(): ViteEnv { @@ -116,6 +132,11 @@ export function loadEnv(): ViteEnv {
116 return ret; 132 return ret;
117 } 133 }
118 134
  135 +/**
  136 + * Get the environment variables starting with the specified prefix
  137 + * @param match prefix
  138 + * @param confFiles ext
  139 + */
119 export function getEnvConfig(match = 'VITE_GLOB_', confFiles = ['.env', '.env.production']) { 140 export function getEnvConfig(match = 'VITE_GLOB_', confFiles = ['.env', '.env.production']) {
120 let envConfig = {}; 141 let envConfig = {};
121 confFiles.forEach((item) => { 142 confFiles.forEach((item) => {
@@ -142,18 +163,34 @@ function consoleFn(color: string, message: any) { @@ -142,18 +163,34 @@ function consoleFn(color: string, message: any) {
142 ); 163 );
143 } 164 }
144 165
  166 +/**
  167 + * warnConsole
  168 + * @param message
  169 + */
145 export function successConsole(message: any) { 170 export function successConsole(message: any) {
146 consoleFn('green', '✨ ' + message); 171 consoleFn('green', '✨ ' + message);
147 } 172 }
148 173
  174 +/**
  175 + * warnConsole
  176 + * @param message
  177 + */
149 export function errorConsole(message: any) { 178 export function errorConsole(message: any) {
150 consoleFn('red', '✨ ' + message); 179 consoleFn('red', '✨ ' + message);
151 } 180 }
152 181
  182 +/**
  183 + * warnConsole
  184 + * @param message message
  185 + */
153 export function warnConsole(message: any) { 186 export function warnConsole(message: any) {
154 consoleFn('yellow', '✨ ' + message); 187 consoleFn('yellow', '✨ ' + message);
155 } 188 }
156 189
  190 +/**
  191 + * Get user root directory
  192 + * @param dir file path
  193 + */
157 export function getCwdPath(...dir: string[]) { 194 export function getCwdPath(...dir: string[]) {
158 return path.resolve(process.cwd(), ...dir); 195 return path.resolve(process.cwd(), ...dir);
159 } 196 }
build/vite/hm.ts
1 -// 百度统计代码 用于站点部署  
2 -// 只在build:site开启 1 +// Baidu statistics code for site deployment
  2 +// Only open in build:site
3 export const hmScript = `<script> 3 export const hmScript = `<script>
4 var _hmt = _hmt || []; 4 var _hmt = _hmt || [];
5 (function() { 5 (function() {
build/vite/plugin/gzip/index.ts
1 // 修改自https://github.com/kryops/rollup-plugin-gzip 1 // 修改自https://github.com/kryops/rollup-plugin-gzip
2 // 因为rollup-plugin-gzip不支持vite 2 // 因为rollup-plugin-gzip不支持vite
3 // vite对css打包独立的。所以不能在打包的时候顺带打包css 3 // vite对css打包独立的。所以不能在打包的时候顺带打包css
  4 +// TODO rc.9会支持 configurBuild 配置项。到时候重新修改
4 5
5 import { readFile, writeFile } from 'fs'; 6 import { readFile, writeFile } from 'fs';
6 import { basename } from 'path'; 7 import { basename } from 'path';
build/vite/proxy.ts
@@ -3,6 +3,11 @@ type ProxyItem = [string, string]; @@ -3,6 +3,11 @@ type ProxyItem = [string, string];
3 type ProxyList = ProxyItem[]; 3 type ProxyList = ProxyItem[];
4 4
5 const reg = /^https:\/\//; 5 const reg = /^https:\/\//;
  6 +
  7 +/**
  8 + * Generate proxy
  9 + * @param list
  10 + */
6 export function createProxy(list: ProxyList = []) { 11 export function createProxy(list: ProxyList = []) {
7 const ret: any = {}; 12 const ret: any = {};
8 for (const [prefix, target] of list) { 13 for (const [prefix, target] of list) {
@@ -12,6 +17,7 @@ export function createProxy(list: ProxyList = []) { @@ -12,6 +17,7 @@ export function createProxy(list: ProxyList = []) {
12 target: target, 17 target: target,
13 changeOrigin: true, 18 changeOrigin: true,
14 rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''), 19 rewrite: (path: string) => path.replace(new RegExp(`^${prefix}`), ''),
  20 + // https is require secure=false
15 ...(isHttps ? { secure: false } : {}), 21 ...(isHttps ? { secure: false } : {}),
16 }; 22 };
17 } 23 }
mock/_createProductionServer.ts
@@ -3,6 +3,9 @@ import userMock from &#39;./sys/user&#39;; @@ -3,6 +3,9 @@ import userMock from &#39;./sys/user&#39;;
3 import menuMock from './sys/menu'; 3 import menuMock from './sys/menu';
4 import tableDemoMock from './demo/table-demo'; 4 import tableDemoMock from './demo/table-demo';
5 5
  6 +/**
  7 + * Used in a production environment. Need to manually import all modules
  8 + */
6 export function setupProdMockServer() { 9 export function setupProdMockServer() {
7 createProdMockServer([...userMock, ...menuMock, ...tableDemoMock]); 10 createProdMockServer([...userMock, ...menuMock, ...tableDemoMock]);
8 } 11 }
src/App.vue
@@ -23,14 +23,20 @@ @@ -23,14 +23,20 @@
23 name: 'App', 23 name: 'App',
24 components: { ConfigProvider }, 24 components: { ConfigProvider },
25 setup() { 25 setup() {
  26 + // Initialize application settings
26 useInitAppConfigStore(); 27 useInitAppConfigStore();
  28 + // Initialize network monitoring
27 useListenerNetWork(); 29 useListenerNetWork();
  30 + // Initialize breakpoint monitoring
28 createBreakpointListen(); 31 createBreakpointListen();
  32 + // Get system configuration
29 const { projectSetting } = useSetting(); 33 const { projectSetting } = useSetting();
  34 + // Get ConfigProvider configuration
30 const { transformCellText } = useConfigProvider(); 35 const { transformCellText } = useConfigProvider();
31 36
32 let lockOn = {}; 37 let lockOn = {};
33 if (projectSetting.lockTime) { 38 if (projectSetting.lockTime) {
  39 + // Monitor the mouse or keyboard time, used to recalculate the lock screen time
34 const { on } = useLockPage(); 40 const { on } = useLockPage();
35 lockOn = on; 41 lockOn = on;
36 } 42 }
src/main.ts
@@ -22,8 +22,10 @@ setupRouter(app); @@ -22,8 +22,10 @@ setupRouter(app);
22 // store 22 // store
23 setupStore(app); 23 setupStore(app);
24 24
  25 +// Directives
25 setupDirectives(app); 26 setupDirectives(app);
26 27
  28 +// error-handle
27 setupErrorHandle(app); 29 setupErrorHandle(app);
28 30
29 router.isReady().then(() => { 31 router.isReady().then(() => {
@@ -35,8 +37,10 @@ if (isDevMode()) { @@ -35,8 +37,10 @@ if (isDevMode()) {
35 window.__APP__ = app; 37 window.__APP__ = app;
36 } 38 }
37 39
  40 +// If you do not need to use the mock service in the production environment, you can comment the code
38 if (isProdMode() && isUseMock()) { 41 if (isProdMode() && isUseMock()) {
39 setupProdMockServer(); 42 setupProdMockServer();
40 } 43 }
41 44
  45 +// Used to share app instances in other modules
42 setApp(app); 46 setApp(app);
src/useApp.ts
  1 +// Application related functions
1 import type { ProjectConfig } from '/@/types/config'; 2 import type { ProjectConfig } from '/@/types/config';
2 import type { App } from 'vue'; 3 import type { App } from 'vue';
3 import { computed, ref } from 'vue'; 4 import { computed, ref } from 'vue';
src/utils/http/axios/const.ts
  1 +// 接口返回值data不能为这个,否则会判为请求失败
1 export const errorResult = '__ERROR_RESULT__'; 2 export const errorResult = '__ERROR_RESULT__';
vite.config.ts
@@ -35,79 +35,89 @@ const viteConfig: UserConfig = { @@ -35,79 +35,89 @@ const viteConfig: UserConfig = {
35 // TODO build error 35 // TODO build error
36 // entry: './public/index.html', 36 // entry: './public/index.html',
37 /** 37 /**
38 - * 端口号 38 + * port
39 * @default '3000' 39 * @default '3000'
40 */ 40 */
41 port: VITE_PORT, 41 port: VITE_PORT,
42 /** 42 /**
43 - * 服务地址  
44 * @default 'localhost' 43 * @default 'localhost'
45 */ 44 */
46 hostname: 'localhost', 45 hostname: 'localhost',
47 /** 46 /**
48 - * 运行自动打开浏览器· 47 + * Run to open the browser automatically
49 * @default 'false' 48 * @default 'false'
50 */ 49 */
51 open: false, 50 open: false,
52 /** 51 /**
53 - * 压缩代码  
54 - * boolean | 'terser' | 'esbuild' 52 + * Set to `false` to disable minification, or specify the minifier to use.
  53 + * Available options are 'terser' or 'esbuild'.
55 * @default 'terser' 54 * @default 'terser'
56 */ 55 */
57 minify: isDevFn() ? 'esbuild' : 'terser', 56 minify: isDevFn() ? 'esbuild' : 'terser',
58 /** 57 /**
59 - * 基本公共路径 58 + * Base public path when served in production.
60 * @default '/' 59 * @default '/'
61 */ 60 */
62 base: VITE_PUBLIC_PATH, 61 base: VITE_PUBLIC_PATH,
63 62
64 /** 63 /**
65 - * 打包输入路径 64 + * Directory relative from `root` where build output will be placed. If the
  65 + * directory exists, it will be removed before the build.
66 * @default 'dist' 66 * @default 'dist'
67 */ 67 */
68 outDir: 'dist', 68 outDir: 'dist',
69 /** 69 /**
70 - * @default 'false' 70 + * Whether to generate sourcemap
  71 + * @default false
71 */ 72 */
72 sourcemap: false, 73 sourcemap: false,
73 /** 74 /**
74 - * 资源输出路径 75 + * Directory relative from `outDir` where the built js/css/image assets will
  76 + * be placed.
75 * @default '_assets' 77 * @default '_assets'
76 */ 78 */
77 assetsDir: '_assets', 79 assetsDir: '_assets',
78 /** 80 /**
79 - * 静态资源小于该大小将会内联,默认4096kb  
80 - * @default '4096' 81 + * Static asset files smaller than this number (in bytes) will be inlined as
  82 + * base64 strings. Default limit is `4096` (4kb). Set to `0` to disable.
  83 + * @default 4096
81 */ 84 */
82 assetsInlineLimit: 4096, 85 assetsInlineLimit: 4096,
83 /** 86 /**
84 - * esbuild转换目标。 87 + * Transpile target for esbuild.
85 * @default 'es2020' 88 * @default 'es2020'
86 */ 89 */
87 esbuildTarget: 'es2020', 90 esbuildTarget: 'es2020',
  91 + /**
  92 + * Whether to log asset info to console
  93 + * @default false
  94 + */
88 silent: false, 95 silent: false,
89 - // 别名 96 + /**
  97 + * Import alias. The entries can either be exact request -> request mappings
  98 + * (exact, no wildcard syntax), or request path -> fs directory mappings.
  99 + * When using directory mappings, the key **must start and end with a slash**.
  100 + * ```
  101 + */
90 alias: { 102 alias: {
91 '/@/': pathResolve('src'), 103 '/@/': pathResolve('src'),
92 }, 104 },
93 - // terser配置 105 + // terser options
94 terserOptions: { 106 terserOptions: {
95 compress: { 107 compress: {
96 - // 是否删除console  
97 drop_console: VITE_DROP_CONSOLE, 108 drop_console: VITE_DROP_CONSOLE,
98 }, 109 },
99 }, 110 },
100 define: { 111 define: {
101 __VERSION__: pkg.version, 112 __VERSION__: pkg.version,
102 }, 113 },
103 - // css预处理  
104 cssPreprocessOptions: { 114 cssPreprocessOptions: {
105 less: { 115 less: {
106 modifyVars: modifyVars, 116 modifyVars: modifyVars,
107 javascriptEnabled: true, 117 javascriptEnabled: true,
108 }, 118 },
109 }, 119 },
110 - // 会使用 rollup 对 包重新编译,将编译成符合 esm 模块规范的新的包放入 node_modules/.vite_opt_cache 120 + // The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache
111 optimizeDeps: { 121 optimizeDeps: {
112 include: [ 122 include: [
113 'echarts', 123 'echarts',
@@ -118,7 +128,7 @@ const viteConfig: UserConfig = { @@ -118,7 +128,7 @@ const viteConfig: UserConfig = {
118 ], 128 ],
119 }, 129 },
120 130
121 - // 本地跨域代理 131 + // Local cross-domain proxy
122 proxy: createProxy(VITE_PROXY), 132 proxy: createProxy(VITE_PROXY),
123 plugins: createVitePlugins(viteEnv), 133 plugins: createVitePlugins(viteEnv),
124 rollupInputOptions: { 134 rollupInputOptions: {