From 374cc92a79eaf05693a68289a971a27600fc5cfd Mon Sep 17 00:00:00 2001 From: CoderKK Date: Tue, 26 Aug 2025 10:05:18 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fix(code-generator):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E8=A1=A8=E5=89=8D=E7=BC=80=E5=8E=BB=E9=99=A4=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在去除表前缀时,使用 slice 方法替代 trimStart 和 trim 方法 - 修复了之前使用 _.trimStart 或 _.trim 导致的命名错误问题 --- .../form/code-generator-table-config-form-basic.vue | 4 ++-- .../form/code-generator-table-config-form-basic.vue | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/smart-admin-web-javascript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue b/smart-admin-web-javascript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue index 6438ed2f..8cc3da2f 100644 --- a/smart-admin-web-javascript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue +++ b/smart-admin-web-javascript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue @@ -182,7 +182,7 @@ //命名 let removePrefixTableName = tableInfo.tableName; if (_.startsWith(tableInfo.tableName, tablePrefix.value)) { - removePrefixTableName = _.trimStart(removePrefixTableName, tablePrefix.value); + removePrefixTableName = removePrefixTableName.slice(tablePrefix.value.length); } formData.moduleName = basic && basic.moduleName ? basic.moduleName : removePrefixTableName; formData.moduleName = convertUpperCamel(formData.moduleName); @@ -205,7 +205,7 @@ function onChangeTablePrefix(e) { let removePrefixTableName = tableInfo.tableName; if (_.startsWith(tableInfo.tableName, tablePrefix.value)) { - removePrefixTableName = _.trim(removePrefixTableName, tablePrefix.value); + removePrefixTableName = tableInfo.tableName.slice(tablePrefix.value.length); } formData.moduleName = convertUpperCamel(removePrefixTableName); } diff --git a/smart-admin-web-typescript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue b/smart-admin-web-typescript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue index e2443103..c9ff0ea7 100644 --- a/smart-admin-web-typescript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue +++ b/smart-admin-web-typescript/src/views/support/code-generator/components/form/code-generator-table-config-form-basic.vue @@ -182,7 +182,7 @@ //命名 let removePrefixTableName = tableInfo.tableName; if (_.startsWith(tableInfo.tableName, tablePrefix.value)) { - removePrefixTableName = _.trimStart(removePrefixTableName, tablePrefix.value); + removePrefixTableName = removePrefixTableName.slice(tablePrefix.value.length); } formData.moduleName = basic && basic.moduleName ? basic.moduleName : removePrefixTableName; formData.moduleName = convertUpperCamel(formData.moduleName); @@ -205,7 +205,7 @@ function onChangeTablePrefix(e) { let removePrefixTableName = tableInfo.tableName; if (_.startsWith(tableInfo.tableName, tablePrefix.value)) { - removePrefixTableName = _.trim(removePrefixTableName, tablePrefix.value); + removePrefixTableName = tableInfo.tableName.slice(tablePrefix.value.length); } formData.moduleName = convertUpperCamel(removePrefixTableName); } From 885ad2118404e34791e7e24bd4e7e8983eab0891 Mon Sep 17 00:00:00 2001 From: yusg Date: Wed, 28 Jan 2026 11:26:01 +0800 Subject: [PATCH 2/2] fix: optimize env config and support dynamic proxy target --- smart-admin-web-javascript/.env.development | 3 +- smart-admin-web-javascript/.env.localhost | 3 +- smart-admin-web-javascript/.env.pre | 2 +- smart-admin-web-javascript/.env.production | 2 +- smart-admin-web-javascript/.env.test | 2 +- smart-admin-web-javascript/vite.config.js | 148 ++++++++++---------- 6 files changed, 82 insertions(+), 78 deletions(-) diff --git a/smart-admin-web-javascript/.env.development b/smart-admin-web-javascript/.env.development index 7ae8066c..89039b49 100644 --- a/smart-admin-web-javascript/.env.development +++ b/smart-admin-web-javascript/.env.development @@ -1,3 +1,4 @@ NODE_ENV=development VITE_APP_TITLE='SmartAdmin 开发环境(Dev)' -VITE_APP_API_URL='http://127.0.0.1:1024' \ No newline at end of file +VITE_APP_API_URL='/api' +VITE_PROXY_TARGET='http://127.0.0.1:1024' diff --git a/smart-admin-web-javascript/.env.localhost b/smart-admin-web-javascript/.env.localhost index 36943904..5281d99f 100644 --- a/smart-admin-web-javascript/.env.localhost +++ b/smart-admin-web-javascript/.env.localhost @@ -1,3 +1,4 @@ NODE_ENV=development VITE_APP_TITLE='SmartAdmin 本地环境(Local)' -VITE_APP_API_URL='http://127.0.0.1:1024' +VITE_APP_API_URL='/api' +VITE_PROXY_TARGET='http://127.0.0.1:1024' diff --git a/smart-admin-web-javascript/.env.pre b/smart-admin-web-javascript/.env.pre index 98cda31c..738b06c9 100644 --- a/smart-admin-web-javascript/.env.pre +++ b/smart-admin-web-javascript/.env.pre @@ -1,3 +1,3 @@ NODE_ENV=production VITE_APP_TITLE='SmartAdmin 预发布环境(Pre)' -VITE_APP_API_URL='https://preview.smartadmin.vip/smart-admin-api' \ No newline at end of file +VITE_APP_API_URL='/smart-admin-api' diff --git a/smart-admin-web-javascript/.env.production b/smart-admin-web-javascript/.env.production index 9230d6d6..22b1c087 100644 --- a/smart-admin-web-javascript/.env.production +++ b/smart-admin-web-javascript/.env.production @@ -1,3 +1,3 @@ NODE_ENV=production VITE_APP_TITLE='SmartAdmin V3.X' -VITE_APP_API_URL='https://preview.smartadmin.vip/smart-admin-api' \ No newline at end of file +VITE_APP_API_URL='/smart-admin-api' diff --git a/smart-admin-web-javascript/.env.test b/smart-admin-web-javascript/.env.test index 66243b33..b5c1b071 100644 --- a/smart-admin-web-javascript/.env.test +++ b/smart-admin-web-javascript/.env.test @@ -1,3 +1,3 @@ NODE_ENV=production VITE_APP_TITLE='SmartAdmin 测试环境(Test)' -VITE_APP_API_URL='http://127.0.0.1:1024' +VITE_APP_API_URL='/smart-admin-api' diff --git a/smart-admin-web-javascript/vite.config.js b/smart-admin-web-javascript/vite.config.js index cb985b40..b8995ac2 100644 --- a/smart-admin-web-javascript/vite.config.js +++ b/smart-admin-web-javascript/vite.config.js @@ -9,91 +9,93 @@ */ import { resolve } from 'path'; import vue from '@vitejs/plugin-vue'; +import { loadEnv } from 'vite'; import customVariables from '/@/theme/custom-variables.js'; const pathResolve = (dir) => { return resolve(__dirname, '.', dir); }; -export default { - base: process.env.NODE_ENV === 'production' ? '/' : '/', - root: process.cwd(), - resolve: { - alias: [ - // 国际化替换 - { - find: 'vue-i18n', - replacement: 'vue-i18n/dist/vue-i18n.cjs.js', - }, - // 绝对路径重命名:/@/xxxx => src/xxxx - { - find: /\/@\//, - replacement: pathResolve('src') + '/', - }, - { - find: /^~/, - replacement: '', - }, - ], - }, - server: { - host: '0.0.0.0', - port: 8081, +export default ({ mode }) => { + const env = loadEnv(mode, process.cwd()); + return { + base: process.env.NODE_ENV === 'production' ? '/' : '/', + root: process.cwd(), + resolve: { + alias: [ + // 国际化替换 + { + find: 'vue-i18n', + replacement: 'vue-i18n/dist/vue-i18n.cjs.js', + }, + // 绝对路径重命名:/@/xxxx => src/xxxx + { + find: /\/@\//, + replacement: pathResolve('src') + '/', + }, + { + find: /^~/, + replacement: '', + }, + ], + }, server: { + host: '0.0.0.0', + port: 8081, proxy: { // 代理路径 - '/': { - target: 'http://127.0.0.1:1024/', // 目标服务器地址 + '/api': { + target: env.VITE_PROXY_TARGET, // 目标服务器地址 changeOrigin: true, // 是否修改请求头中的 Origin 字段 - rewrite: (path) => path, // 重写路径 - }, - }, - } - }, - plugins: [vue()], - optimizeDeps: { - include: ['ant-design-vue/es/locale/zh_CN', 'dayjs/locale/zh-cn', 'ant-design-vue/es/locale/en_US'], - exclude: ['vue-demi'], - }, - build: { - // 清除console和debugger - terserOptions: { - compress: { - drop_console: true, - drop_debugger: true, - }, - }, - rollupOptions: { - output: { - //配置这个是让不同类型文件放在不同文件夹,不会显得太乱 - chunkFileNames: 'js/[name]-[hash].js', - entryFileNames: 'js/[name]-[hash].js', - assetFileNames: '[ext]/[name]-[hash].[ext]', - manualChunks(id) { - //静态资源分拆打包 - if (id.includes('node_modules')) { - return id.toString().split('node_modules/')[1].split('/')[0].toString(); - } + rewrite: (path) => path.replace(/^\/api/, ''), // 重写路径 }, }, }, - target: 'esnext', - outDir: 'dist', // 指定输出路径 - assetsDir: 'assets', // 指定生成静态文件目录 - assetsInlineLimit: '4096', // 小于此阈值的导入或引用资源将内联为 base64 编码 - chunkSizeWarningLimit: 500, // chunk 大小警告的限制 - minify: 'terser', // 混淆器,terser构建后文件体积更小 - emptyOutDir: true, //打包前先清空原有打包文件 - }, - css: { - preprocessorOptions: { - less: { - modifyVars: customVariables, - javascriptEnabled: true, + plugins: [vue()], + optimizeDeps: { + include: ['ant-design-vue/es/locale/zh_CN', 'dayjs/locale/zh-cn', 'ant-design-vue/es/locale/en_US'], + exclude: ['vue-demi'], + }, + build: { + // 清除console和debugger + terserOptions: { + compress: { + drop_console: true, + drop_debugger: true, + }, + }, + rollupOptions: { + output: { + //配置这个是让不同类型文件放在不同文件夹,不会显得太乱 + chunkFileNames: 'js/[name]-[hash].js', + entryFileNames: 'js/[name]-[hash].js', + assetFileNames: '[ext]/[name]-[hash].[ext]', + manualChunks(id) { + //静态资源分拆打包 + if (id.includes('node_modules')) { + return id.toString().split('node_modules/')[1].split('/')[0].toString(); + } + }, + }, + }, + target: 'esnext', + outDir: 'dist', // 指定输出路径 + assetsDir: 'assets', // 指定生成静态文件目录 + assetsInlineLimit: '4096', // 小于此阈值的导入或引用资源将内联为 base64 编码 + chunkSizeWarningLimit: 500, // chunk 大小警告的限制 + minify: 'terser', // 混淆器,terser构建后文件体积更小 + emptyOutDir: true, //打包前先清空原有打包文件 + }, + css: { + preprocessorOptions: { + less: { + modifyVars: customVariables, + javascriptEnabled: true, + }, }, }, - }, - define: { - __INTLIFY_PROD_DEVTOOLS__: false, - 'process.env': process.env, - }, + define: { + __INTLIFY_PROD_DEVTOOLS__: false, + 'process.env': process.env, + }, + }; };