浏览代码

彻底解决登录问题

彻底解决登录问题
dangyunlong 5 天之前
父节点
当前提交
072f77fe44
共有 2 个文件被更改,包括 27 次插入2 次删除
  1. 26 1
      src/permission.js
  2. 1 1
      src/views/componentGallery/imgList.vue

+ 26 - 1
src/permission.js

@@ -31,6 +31,7 @@ router.beforeEach(async (to, from, next) => {
         if (to.path === '/login') {
             //获取登录参数,是backurl还是userurl
             let loginType = getLoginType(window.location.href)
+
             if(loginType == 'userurl'){
                 //如果是userurl
                 const userurl = hashParams();
@@ -77,7 +78,31 @@ router.beforeEach(async (to, from, next) => {
                     window.location.href = backurl + '?backurl=' + backurl + '&admintoken=' + getToken()
                 }
             }
-            
+
+            //出现这种情况,说明用户使用的是管理员登录
+            if(loginType == null){
+                const userInfo = await getInfo();
+                //此时不需要返回C端
+                if(userInfo.code == 400){
+                    console.log("用户没有访问权限,将跳转到无权限页面!")
+                    if (to.path !== '/no-permission') {
+                        //到达此页面后直接清理token,避免出现用户直接从url返回login导致无限循环
+                        removeToken()
+                        //避免重复跳转
+                        next({path:'/no-permission'})
+                    } else {
+                        //已经在无权限页面,不再跳转
+                        next()
+                    }
+                    NProgress.done()
+                }else{
+                    setUseType(userInfo.data.type_id, 86400)
+                    setWebSiteId(userInfo.data.website_id, 86400)
+                    console.log("用户有访问权限,访问继续!")
+                    next()
+                }
+            }
+
         } else {
             //3.4.2 如果有token,但是没在登录页面
             const hasRoles = store.getters.roles && store.getters.roles.length > 0

+ 1 - 1
src/views/componentGallery/imgList.vue

@@ -78,7 +78,7 @@
         </div>
 
         <!-- 弹出框 start----------------------------------------------------------->
-        <el-dialog :title="dialogName" :visible.sync="dialogTableVisible" width="50%" top="8vh"
+        <el-dialog :title="dialogName" :visible.sync="dialogTableVisible" width="45%" top="8vh"
             :close-on-click-modal="false">
             <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="120px" class="demo-ruleForm">
                 <div class="dialogText">