Эх сурвалжийг харах

feat:优化登录、退出功能。admin页面限制租户账号登录

韩帛霖 1 жил өмнө
parent
commit
6b01b13812

+ 1 - 0
zkqy-admin/src/main/java/com/zkqy/web/controller/system/SysLoginController.java

@@ -136,6 +136,7 @@ public class SysLoginController {
      */
     @PostMapping("/loginAdmin")
     public AjaxResult loginadmin(@Valid @RequestBody LoginBody loginBody, BindingResult bindingResult) {
+        if (!loginBody.getUsername().equals("admin")) return AjaxResult.warn("禁止登录!");
         if (bindingResult.hasErrors()) {
             return AjaxResult.error(bindingResult.getFieldError().getDefaultMessage());
         }

+ 1 - 1
zkqy-system/src/main/resources/mapper/system/SysUserMapper.xml

@@ -257,7 +257,7 @@
     <select id="checkUserNameUnique" parameterType="String" resultMap="SysUserResult">
         select user_id, user_name
         from sys_user
-        where user_name = #{userName}
+        where  user_name = #{userName}
           and del_flag = '0' limit 1
     </select>
 

+ 27 - 17
zkqy-ui/src/layout/index.vue

@@ -5,7 +5,7 @@
       <el-row>
         <el-col :span="12">
           <div class="logo-title">
-            <img :src="logo" alt="" class="imgg" />
+            <img :src="logo" alt="" class="imgg"/>
             <span class="title">{{ title }}</span>
             <!-- <img src="../assets/images/comlo.png" alt="" class="imgg" /> -->
           </div>
@@ -16,7 +16,7 @@
             trigger="click"
           >
             <div class="avatar-wrapper">
-              <img :src="avatar" class="user-avatar" />
+              <img :src="avatar" class="user-avatar"/>
               <span style="">
                 <button class="jianbiase">{{ username || "默认用户" }}</button>
               </span>
@@ -60,11 +60,11 @@
       >
         <div :class="{ 'fixed-header': fixedHeader }">
           <!-- <navbar /> -->
-          <tags-view v-if="needTagsView" />
+          <tags-view v-if="needTagsView"/>
         </div>
-        <app-main />
+        <app-main/>
         <right-panel>
-          <settings />
+          <settings/>
         </right-panel>
       </div>
     </div>
@@ -72,15 +72,16 @@
 </template>
 
 <script>
-import { mapGetters } from "vuex";
+import {mapGetters} from "vuex";
 import RightPanel from "@/components/RightPanel";
-import { AppMain, Navbar, Settings, Sidebar, TagsView } from "./components";
+import {AppMain, Navbar, Settings, Sidebar, TagsView} from "./components";
 import ResizeMixin from "./mixin/ResizeHandler";
-import { mapState } from "vuex";
+import {mapState} from "vuex";
 import variables from "@/assets/styles/variables.scss";
 import meclogo1 from "@/assets/images/mec-logo1.svg";
 import mecLogoLogin from "@/assets/images/mec-logo-login.svg";
 import comp from "@/assets/images/comp.svg";
+
 export default {
   name: "Layout",
   components: {
@@ -142,15 +143,17 @@ export default {
         type: "warning",
       })
         .then(() => {
-          let tenantCode = this.tenantInfo.tenantCode;
-          this.$store.dispatch("LogOut").then(() => {
-            this.$router.push({path: "/login", query: {tenantCode: tenantCode}});
-          });
+          // let tenantCode = this.tenantInfo.tenantCode;
+          this.$store.dispatch("LogOut");
+          //   .then(() => {
+          //   this.$router.push({path: "/login", query: {tenantCode: tenantCode}});
+          // });
         })
-        .catch(() => {});
+        .catch(() => {
+        });
     },
     handleClickOutside() {
-      this.$store.dispatch("app/closeSideBar", { withoutAnimation: false });
+      this.$store.dispatch("app/closeSideBar", {withoutAnimation: false});
     },
     getlogo() {
       let logo = sessionStorage.getItem("logo");
@@ -175,6 +178,7 @@ export default {
 <style lang="scss" scoped>
 @import "~@/assets/styles/mixin.scss";
 @import "~@/assets/styles/variables.scss";
+
 .combarr {
   /* height: 100vh !important; */
   /* overflow: scroll; */
@@ -183,9 +187,11 @@ export default {
 .avatar-wrapper {
   white-space: nowrap;
 }
+
 .el-dropdown-menu {
   z-index: 10000 !important;
 }
+
 .sidebar-container {
   background-color: #222653 !important;
 }
@@ -212,9 +218,9 @@ export default {
   height: 37px;
   /* height: 25px; */
   background: linear-gradient(
-    128.13deg,
-    rgba(82, 79, 255, 1) 0%,
-    rgba(255, 74, 74, 1) 100%
+      128.13deg,
+      rgba(82, 79, 255, 1) 0%,
+      rgba(255, 74, 74, 1) 100%
   );
   box-shadow: 0px 4px 16px rgba(179, 192, 231, 1);
   border-radius: 27px;
@@ -227,6 +233,7 @@ export default {
   padding: 0px 20px 0px 25px;
   box-sizing: border-box;
 }
+
 .user-avatar {
   cursor: pointer;
   width: 50px;
@@ -254,6 +261,7 @@ export default {
 #dropdown-menu-1780 {
   z-index: 1000000;
 }
+
 .imgg {
   // width: 553px;
   width: 270px;
@@ -263,10 +271,12 @@ export default {
   margin-bottom: 8px;
   /* margin-left: 50px; */
 }
+
 .logo-title {
   width: 100%;
   display: flex;
   align-items: center;
+
   .title {
     flex: 1;
     margin-left: 5px;

+ 8 - 2
zkqy-ui/src/store/modules/user.js

@@ -118,6 +118,14 @@ const user = {
     LogOut({commit, state}) {
       return new Promise((resolve, reject) => {
         logout(state.token).then(() => {
+          if (state.userId == 1) {  // 如果当前用户是admin的话
+            location.href = "/login"
+          } else {
+            location.href = state.tenant.tenantToolLoginUrl
+          }
+        }).catch(error => {
+          reject(error)
+        }).finally(() => {
           commit('SET_TOKEN', '')
           commit('SET_ROLES', [])
           commit('SET_PERMISSIONS', [])
@@ -125,8 +133,6 @@ const user = {
           removeToken()
           localStorage.clear();
           resolve()
-        }).catch(error => {
-          reject(error)
         })
       })
     },

+ 62 - 60
zkqy-ui/src/utils/request.js

@@ -1,15 +1,15 @@
 import axios from 'axios'
-import { Notification, MessageBox, Message, Loading } from 'element-ui'
+import {Notification, MessageBox, Message, Loading} from 'element-ui'
 import store from '@/store'
-import { getToken } from '@/utils/auth'
+import {getToken} from '@/utils/auth'
 import errorCode from '@/utils/errorCode'
-import { tansParams, blobValidate } from "@/utils/zkqy";
+import {tansParams, blobValidate} from "@/utils/zkqy";
 import cache from '@/plugins/cache'
-import { saveAs } from 'file-saver'
+import {saveAs} from 'file-saver'
 
 let downloadLoadingInstance;
 // 是否显示重新登录
-export let isRelogin = { show: false };
+export let isRelogin = {show: false};
 
 
 axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
@@ -68,71 +68,73 @@ service.interceptors.request.use(config => {
 
 // 响应拦截器
 service.interceptors.response.use(res => {
-  // 未设置状态码则默认成功状态
-  const code = res.data.code || 200;
-  // 获取错误信息
-  const msg = errorCode[code] || res.data.msg || errorCode['default']
-  // 二进制数据则直接返回
-  if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
-    return res.data
-  }
-  if (code === 401) {
-    if (!isRelogin.show) {
-      isRelogin.show = true;
-      MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
+    // 未设置状态码则默认成功状态
+    const code = res.data.code || 200;
+    // 获取错误信息
+    const msg = errorCode[code] || res.data.msg || errorCode['default']
+    // 二进制数据则直接返回
+    if (res.request.responseType === 'blob' || res.request.responseType === 'arraybuffer') {
+      return res.data
+    }
+    if (code === 401) {
+      if (!isRelogin.show) {
+        isRelogin.show = true;
+        MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
+          confirmButtonText: '重新登录',
+          cancelButtonText: '取消',
+          type: 'warning'
+        }).then(() => {
+          isRelogin.show = false;
+          store.dispatch('LogOut')
+          //   .then(() => {
+          //   location.href = '/index';
+          // })
+        }).catch(() => {
+          isRelogin.show = false;
+        });
+      }
+      return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
+    } else if (code === 500) {
+      console.log(msg);
+      let resUrl = res.config.url;
+      if (resUrl == '/login') {
+        Message({message: msg, type: 'error'})
+        return Promise.reject(new Error(msg))
+      } else {
+        return Promise.resolve()
+      }
+      // Message({ message: msg, type: 'error' })
+      // return Promise.reject(new Error(msg))
+      // return Promise.resolve()
+    } else if (code === 601) {
+      Message({message: msg, type: 'warning'})
+      return Promise.reject('error')
+    } else if (code == 602) {
+      if (store.state.user.name == 'admin') return
+      MessageBox.confirm('数据源信息异常!请您联系管理员或尝试重新登录系统。', '系统提示', {
         confirmButtonText: '重新登录',
         cancelButtonText: '取消',
         type: 'warning'
       }).then(() => {
         isRelogin.show = false;
-        store.dispatch('LogOut').then(() => {
-          location.href = '/index';
-        })
+        store.dispatch('LogOut');
+        //   .then(() => {
+        //   location.href = '/index';
+        // })
       }).catch(() => {
         isRelogin.show = false;
       });
-    }
-    return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
-  } else if (code === 500) {
-    console.log(msg);
-    let resUrl = res.config.url;
-    if (resUrl == '/login') {
-      Message({ message: msg, type: 'error' })
-      return Promise.reject(new Error(msg))
+      return Promise.reject('数据源信息异常!请您联系管理员或尝试重新登录系统。')
+    } else if (code !== 200) {
+      Notification.error({title: msg})
+      return Promise.reject('error')
     } else {
-      return Promise.resolve()
+      return res.data
     }
-    // Message({ message: msg, type: 'error' })
-    // return Promise.reject(new Error(msg))
-    // return Promise.resolve()
-  } else if (code === 601) {
-    Message({ message: msg, type: 'warning' })
-    return Promise.reject('error')
-  } else if (code == 602) {
-    if (store.state.user.name == 'admin') return
-    MessageBox.confirm('数据源信息异常!请您联系管理员或尝试重新登录系统。', '系统提示', {
-      confirmButtonText: '重新登录',
-      cancelButtonText: '取消',
-      type: 'warning'
-    }).then(() => {
-      isRelogin.show = false;
-      store.dispatch('LogOut').then(() => {
-        location.href = '/index';
-      })
-    }).catch(() => {
-      isRelogin.show = false;
-    });
-    return Promise.reject('数据源信息异常!请您联系管理员或尝试重新登录系统。')
-  } else if (code !== 200) {
-    Notification.error({ title: msg })
-    return Promise.reject('error')
-  } else {
-    return res.data
-  }
-},
+  },
   error => {
     console.log('err' + error)
-    let { message } = error;
+    let {message} = error;
     if (message == "Network Error") {
       message = "后端接口连接异常";
     } else if (message.includes("timeout")) {
@@ -140,7 +142,7 @@ service.interceptors.response.use(res => {
     } else if (message.includes("Request failed with status code")) {
       message = "系统接口" + message.substr(message.length - 3) + "异常";
     }
-    Message({ message: message, type: 'error', duration: 5 * 1000 })
+    Message({message: message, type: 'error', duration: 5 * 1000})
     return Promise.reject(error)
   }
 )
@@ -156,7 +158,7 @@ export function download(url, params, filename, config) {
     transformRequest: [(params) => {
       return tansParams(params)
     }],
-    headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
+    headers: {'Content-Type': 'application/x-www-form-urlencoded'},
     responseType: 'blob',
     ...config
   }).then(async (data) => {