diff --git a/build/index.ts b/build/index.ts index f125097..278488f 100644 --- a/build/index.ts +++ b/build/index.ts @@ -1,7 +1,7 @@ /** 处理环境变量 */ -const warpperEnv = (envConf: Recordable): ViteEnv => { +const wrapperEnv = (envConfigs: Recordable): ViteEnv => { /** 此处为默认值 */ - const ret: ViteEnv = { + const defaultEnvConfigs: ViteEnv = { VITE_PORT: 8848, VITE_PUBLIC_PATH: "", VITE_ROUTER_HISTORY: "", @@ -10,22 +10,27 @@ const warpperEnv = (envConf: Recordable): ViteEnv => { VITE_COMPRESSION: "none" }; - for (const envName of Object.keys(envConf)) { - let realName = envConf[envName].replace(/\\n/g, "\n"); - realName = - realName === "true" ? true : realName === "false" ? false : realName; + for (const configName of Object.keys(envConfigs)) { + let realConfigValue = envConfigs[configName].replace(/\\n/g, "\n"); + realConfigValue = + realConfigValue === "true" + ? true + : realConfigValue === "false" + ? false + : realConfigValue; - if (envName === "VITE_PORT") { - realName = Number(realName); + if (configName === "VITE_PORT") { + realConfigValue = Number(realConfigValue); } - ret[envName] = realName; - if (typeof realName === "string") { - process.env[envName] = realName; - } else if (typeof realName === "object") { - process.env[envName] = JSON.stringify(realName); + + defaultEnvConfigs[configName] = realConfigValue; + if (typeof realConfigValue === "string") { + process.env[configName] = realConfigValue; + } else if (typeof realConfigValue === "object") { + process.env[configName] = JSON.stringify(realConfigValue); } } - return ret; + return defaultEnvConfigs; }; -export { warpperEnv }; +export { wrapperEnv }; diff --git a/src/views/login/index.vue b/src/views/login/index.vue index d6da675..a3f4efa 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -43,7 +43,10 @@ const onLogin = async (formEl: FormInstance | undefined) => { await formEl.validate((valid, fields) => { if (valid) { useUserStoreHook() - .loginByUsername({ username: ruleForm.username, password: "admin123" }) + .loginByUsername({ + username: ruleForm.username, + password: ruleForm.password + }) .then(res => { if (res.success) { // 获取后端路由 diff --git a/vite.config.ts b/vite.config.ts index 8a7a336..7c9d798 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -1,7 +1,7 @@ import dayjs from "dayjs"; import { resolve } from "path"; import pkg from "./package.json"; -import { warpperEnv } from "./build"; +import { wrapperEnv } from "./build"; import { getPluginsList } from "./build/plugins"; import { include, exclude } from "./build/optimize"; import { UserConfigExport, ConfigEnv, loadEnv } from "vite"; @@ -28,7 +28,7 @@ const __APP_INFO__ = { export default ({ command, mode }: ConfigEnv): UserConfigExport => { const { VITE_CDN, VITE_PORT, VITE_COMPRESSION, VITE_PUBLIC_PATH } = - warpperEnv(loadEnv(mode, root)); + wrapperEnv(loadEnv(mode, root)); return { base: VITE_PUBLIC_PATH, root,