diff --git a/src/api/user.ts b/src/api/user.ts index b7be5cb..f486c6f 100644 --- a/src/api/user.ts +++ b/src/api/user.ts @@ -3,6 +3,7 @@ import { baseUrlApi } from "./utils"; export type UserResult = { success: boolean; + status: number; data: { /** 头像 */ avatar: string; diff --git a/src/store/modules/user.ts b/src/store/modules/user.ts index ad7d0ca..f713277 100644 --- a/src/store/modules/user.ts +++ b/src/store/modules/user.ts @@ -66,12 +66,20 @@ export const useUserStore = defineStore({ }, /** 登入 */ async loginByUsername(data) { + console.info("```````````````````````````````````````````````"); + console.info(data); return new Promise((resolve, reject) => { getLogin(data) .then(data => { console.log("loginByUsername"); console.log(data.data); - if (data?.success) setToken(data.data); + console.log(data.status); + console.log(data); + //if (data?.success) setToken(data.data); + // if(data?.status==200) setToken(data.data); + if (data && data.status == 200) { + setToken(data.data); + } resolve(data); }) .catch(error => { diff --git a/src/views/login/index.vue b/src/views/login/index.vue index 6659925..74616c3 100644 --- a/src/views/login/index.vue +++ b/src/views/login/index.vue @@ -34,7 +34,7 @@ const { title } = useNav(); const ruleForm = reactive({ username: "admin", - password: "admin123" + password: "comcat@2019" }); const onLogin = async (formEl: FormInstance | undefined) => { @@ -45,10 +45,22 @@ const onLogin = async (formEl: FormInstance | undefined) => { useUserStoreHook() .loginByUsername({ username: ruleForm.username, - password: ruleForm.password + password: ruleForm.password, + isBackendUser: 1 }) .then(res => { - if (res.success) { + console.log(res); + console.log("res.status = " + res.status); + console.log("res.success = " + res.success); + // if (res.success) { + console.info(typeof res.status); + if (res.status) { + console.log(res.status); + } else { + console.info(res); + console.error("res.status is undefined"); + } + if (res.status === 200) { // 获取后端路由 return initRouter().then(() => { router.push(getTopMenu(true).path).then(() => { diff --git a/vite.config.ts b/vite.config.ts index f387c94..c5e2765 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -29,13 +29,41 @@ export default ({ mode }: ConfigEnv): UserConfigExport => { "/base": { target: "http://127.0.0.1:9098", changeOrigin: true, - rewrite: path => path.replace(/^\/base/, "") + rewrite: path => path.replace(/^\/base/, ""), + configure: (proxy, options) => { + // 添加调试日志 + proxy.on("proxyReq", (proxyReq, req, res) => { + console.log(res); + console.log("代理请求:", { + from: req.url, + to: options.target + proxyReq.path + }); + }); + proxy.on("proxyRes", (proxyRes, req, res) => { + console.log(res); + console.log("代理响应:", { + path: req.url, + status: proxyRes.statusCode + }); + }); + proxy.on("error", (err, req, res) => { + console.log(res); + console.log(req); + console.error("代理错误:", err); + }); + } }, // 第二个代理后端地址 "/otherApi": { target: "http://127.0.0.1:3290", changeOrigin: true, rewrite: path => path.replace(/^\/otherApi/, "") + }, + // 第三个代理后端地址 + "/biz": { + target: "http://127.0.0.1:8089", + changeOrigin: true, + rewrite: path => path.replace(/^\/biz/, "") } }, // 预热文件以提前转换和缓存结果,降低启动期间的初始页面加载时长并防止转换瀑布