2 Commits c6d739e468 ... f46012b30d

Author SHA1 Message Date
  armg f46012b30d 1.优化登录 4 days ago
  armg 779e1fd3d3 判断登录 4 days ago

+ 2 - 2
src/main.ts

@@ -50,10 +50,10 @@ Vue.component('el-collapse', ElCollapse);
 Vue.component('el-collapse-item', ElCollapseItem);
 Vue.component('el-collapse-item', ElCollapseItem);
 Vue.component('el-image', ElImage);
 Vue.component('el-image', ElImage);
 // 引入并初始化 vConsole(仅在非生产环境启用,避免线上暴露调试工具)
 // 引入并初始化 vConsole(仅在非生产环境启用,避免线上暴露调试工具)
-// if (process.env.NODE_ENV !== 'production') {
+if (process.env.NODE_ENV !== 'production') {
   const VConsole = require('vconsole')
   const VConsole = require('vconsole')
   new VConsole() // 初始化后,移动端页面会出现 vConsole 悬浮按钮
   new VConsole() // 初始化后,移动端页面会出现 vConsole 悬浮按钮
-// }
+}
 import {
 import {
   Swipe,
   Swipe,
   SwipeItem,
   SwipeItem,

+ 12 - 5
src/router/index.ts

@@ -41,7 +41,8 @@ const router = new VueRouter({
         //设计页
         //设计页
         {
         {
           path: "/AIDesign/design",
           path: "/AIDesign/design",
-          component: () => import("../views/AIDesign/design.vue")
+          component: () => import("../views/AIDesign/design.vue"),
+          meta: { requiresAuth: true } // 标记需要登录的页面
         },
         },
         //结果页
         //结果页
         {
         {
@@ -52,22 +53,26 @@ const router = new VueRouter({
         //历史页
         //历史页
         {
         {
           path: "/AIDesign/history",
           path: "/AIDesign/history",
-          component: () => import("../views/AIDesign/history.vue")
+          component: () => import("../views/AIDesign/history.vue"),
+          meta: { requiresAuth: true } // 标记需要登录的页面
         },
         },
         //内墙-设计页
         //内墙-设计页
         {
         {
           path: "/AIDesign/insideDesign",
           path: "/AIDesign/insideDesign",
-          component: () => import("../views/AIDesign/insideDesign.vue")
+          component: () => import("../views/AIDesign/insideDesign.vue"),
+          meta: { requiresAuth: true } // 标记需要登录的页面
         },
         },
         //一键诊断-生成页
         //一键诊断-生成页
         {
         {
           path: "/AIDesign/diagnose",
           path: "/AIDesign/diagnose",
-          component: () => import("../views/AIDesign/diagnose.vue")
+          component: () => import("../views/AIDesign/diagnose.vue"),
+          meta: { requiresAuth: true } // 标记需要登录的页面
         },
         },
         //一键诊断-历史页
         //一键诊断-历史页
         {
         {
           path: "/AIDesign/diagnoseHistory",
           path: "/AIDesign/diagnoseHistory",
-          component: () => import("../views/AIDesign/diagnoseHistory.vue")
+          component: () => import("../views/AIDesign/diagnoseHistory.vue"),
+          meta: { requiresAuth: true } // 标记需要登录的页面
         },
         },
         //一键诊断-结果页
         //一键诊断-结果页
         {
         {
@@ -81,6 +86,7 @@ const router = new VueRouter({
 });
 });
 // 全局前置守卫:只对需要登录的页面进行登录校验
 // 全局前置守卫:只对需要登录的页面进行登录校验
 router.beforeEach((to, from, next) => {
 router.beforeEach((to, from, next) => {
+  // console.log("-------页面链接=", window.location.href)
   if (!to.meta || (to.meta && !to.meta.requiresAuth)) {
   if (!to.meta || (to.meta && !to.meta.requiresAuth)) {
     next();
     next();
     return;
     return;
@@ -96,6 +102,7 @@ router.beforeEach((to, from, next) => {
     if (code) {
     if (code) {
       doWecomLogin(code)
       doWecomLogin(code)
         .then(() => {
         .then(() => {
+          next();
           console.log(`登录成功,即将进入 ${to.path}`);
           console.log(`登录成功,即将进入 ${to.path}`);
         })
         })
         .catch(() => {
         .catch(() => {

+ 8 - 6
src/utils/requestAI.js

@@ -36,7 +36,7 @@ service.interceptors.request.use(config => {
 
 
 // 响应拦截器
 // 响应拦截器
 service.interceptors.response.use(res => {
 service.interceptors.response.use(res => {
-    const code = res.data.code || 200;
+    const code = res.data.StatusCode || 200;
     const msg = errorCode[code] || res.data.msg || errorCode['default']
     const msg = errorCode[code] || res.data.msg || errorCode['default']
     if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
     if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
         return res.data
         return res.data
@@ -46,16 +46,18 @@ service.interceptors.response.use(res => {
     } else if (code === 500) {
     } else if (code === 500) {
         Toast(msg);
         Toast(msg);
         return Promise.reject(new Error(msg))
         return Promise.reject(new Error(msg))
-    } else if (code !== 200 && code !== 204) {
-        Toast(msg);
-        return Promise.reject('error')
     } else if (code === 420) {
     } else if (code === 420) {
         window.localStorage.clear();
         window.localStorage.clear();
         let url, appid, agentid;
         let url, appid, agentid;
-        url = encodeURIComponent(process.env.VUE_APP_AUTHURL);
+        // url = encodeURIComponent(process.env.VUE_APP_AUTHURL);
+        url = encodeURIComponent(window.location.href);
         appid = process.env.VUE_APP_APPID;
         appid = process.env.VUE_APP_APPID;
         agentid = process.env.VUE_APP_AGENTID;
         agentid = process.env.VUE_APP_AGENTID;
-        window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${url}&response_type=code&scope=snsapi_base&state=&agentid=${agentid}#wechat_redirect&t=${new Date().getTime()}`;
+        // console.log("--url=",url)
+        window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${url}&response_type=code&scope=snsapi_base&state=&agentid=${agentid}&&t=${new Date().getTime()}#wechat_redirect`;
+    } else if (code !== 200 && code !== 204) {
+        Toast(msg);
+        return Promise.reject('error')
     } else {
     } else {
         return res.data
         return res.data
     }
     }

+ 5 - 4
src/utils/wecomLogin.ts

@@ -60,7 +60,6 @@ export const initGuidInfo = (): void => {
         // 无缓存-存储
         // 无缓存-存储
         window.localStorage.setItem('guidInfo', JSON.stringify(newGuidInfo));
         window.localStorage.setItem('guidInfo', JSON.stringify(newGuidInfo));
     }
     }
-    console.log("guidInfo=", window.localStorage.getItem('guidInfo'))
 };
 };
 /**
 /**
  * 企业微信登录核心流程(获取 code → 兑换 AIToken)
  * 企业微信登录核心流程(获取 code → 兑换 AIToken)
@@ -91,8 +90,9 @@ export const doWecomLogin = async (code: string): Promise<void> => {
             // 登录成功:存储 AIToken
             // 登录成功:存储 AIToken
             window.localStorage.setItem('AIToken', res.Data.token);
             window.localStorage.setItem('AIToken', res.Data.token);
             isLogging = false;
             isLogging = false;
+            // console.log("router.currentRoute.fullPath=",router.currentRoute.fullPath)
             // 重新跳转目标页面(此时登录状态已满足)
             // 重新跳转目标页面(此时登录状态已满足)
-            router.push(router.currentRoute.fullPath);
+            // router.push(router.currentRoute.fullPath);
         } else if (res.StatusCode === 403) {
         } else if (res.StatusCode === 403) {
             // 无权限 → 跳错误页
             // 无权限 → 跳错误页
             isLogging = false;
             isLogging = false;
@@ -124,9 +124,10 @@ export const getGuid = () => {
 }
 }
 export const getQyCode = () => {
 export const getQyCode = () => {
     let url, appid, agentid;
     let url, appid, agentid;
-    url = encodeURIComponent(process.env.VUE_APP_AUTHURL);
+    // url = encodeURIComponent(process.env.VUE_APP_AUTHURL);
+    url = encodeURIComponent(window.location.href);
     appid = process.env.VUE_APP_APPID;
     appid = process.env.VUE_APP_APPID;
     agentid = process.env.VUE_APP_AGENTID;
     agentid = process.env.VUE_APP_AGENTID;
-    
+
     window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${url}&response_type=code&scope=snsapi_base&state=&agentid=${agentid}&t=${new Date().getTime()}#wechat_redirect`;
     window.location.href = `https://open.weixin.qq.com/connect/oauth2/authorize?appid=${appid}&redirect_uri=${url}&response_type=code&scope=snsapi_base&state=&agentid=${agentid}&t=${new Date().getTime()}#wechat_redirect`;
 }
 }

+ 6 - 2
src/views/AIDesign/design.vue

@@ -1042,11 +1042,15 @@ export default class extends Vue {
           this.GetEntityData(this.$route.query.F_id);
           this.GetEntityData(this.$route.query.F_id);
         }
         }
       } else {
       } else {
-        that.$toast(response.Info)
+        if(response.Info){
+          that.$toast(response.Info)
+        }
         console.log(response.Info);
         console.log(response.Info);
       }
       }
     }).catch((err) => {
     }).catch((err) => {
-      that.$toast(err)
+      // if(err){
+      //   that.$toast(err)
+      // }
     })
     })
   }
   }
 
 

+ 3 - 1
src/views/AIDesign/insideDesign.vue

@@ -517,7 +517,9 @@ export default class extends Vue {
       } else {
       } else {
         that.projectActionLoadingShow = false;
         that.projectActionLoadingShow = false;
         that.AIBtnDisabled = false;
         that.AIBtnDisabled = false;
-        that.$toast(response.Info);
+        if(response.Info){
+          that.$toast(response.Info);
+        }
       }
       }
     })
     })
       .catch((err) => {
       .catch((err) => {