浏览代码

新增 超级管理员权限

wzg 2 年之前
父节点
当前提交
40c51a57fa
共有 5 个文件被更改,包括 111 次插入13 次删除
  1. 1 1
      src/apis/config.js
  2. 5 0
      src/apis/fetch.js
  3. 28 6
      src/layout/Header.vue
  4. 37 0
      src/store/index.js
  5. 40 6
      src/views/index/Login.vue

+ 1 - 1
src/apis/config.js

@@ -18,7 +18,7 @@ export const $http = async function (url, data) {
     url: baseurl + url,
     data: {
       ...data,
-      loginAccountId: localStorage.loginAccountId,
+      loginAccountId: store.state.loginAccountId,
     },
     withCredentials: true,
   });

+ 5 - 0
src/apis/fetch.js

@@ -160,4 +160,9 @@ export default {
   getShippingNoticeList(data) {
     return $http("/maritime/notice/getFileList", data);
   },
+
+  //获取船务公司下拉
+  getShippingCompanySelect(data) {
+    return $http("/shippingCompany/select", data);
+  },
 };

+ 28 - 6
src/layout/Header.vue

@@ -3,9 +3,23 @@
     <div class="left">
       <!-- <img class="first" src="../assets/three.png" alt="" /> -->
       <div class="shu"></div>
-      <div class="cf fs20">
+      <div class="cf fs20 mr30">
         欢迎来到 {{ shippingCompany }} 智慧远程海事管理系统
       </div>
+      <el-select
+        @change="selectCompany"
+        v-model="store.state.currentCompany"
+        value-key="key"
+        style="width: 240px; text-align: center"
+        v-if="store.state.isSuperuser == 1"
+      >
+        <el-option
+          v-for="item in store.state.companySelect"
+          :key="item.key"
+          :label="item.value"
+          :value="item"
+        />
+      </el-select>
       <!-- <img class="logo" src="../assets/white-logo.png" alt="" />
       <div class="ml20" style="color: #fff; font-size: 18px">
         version:{{ timelineData[0]?.version }}
@@ -106,11 +120,9 @@ const v = db.collection("huihenduo_versions");
 const __ = db.command;
 let userName = localStorage.staffName;
 function quit() {
-  localStorage.removeItem("loginAccountId");
-  localStorage.removeItem("loginName");
-  localStorage.removeItem("loginPhone");
-  localStorage.removeItem("shippingCompany");
-  localStorage.removeItem("shippingId");
+  localStorage.clear();
+  store.state.isSuperuser = 0;
+  store.state.currentCompany = "";
   store.commit("changeLogin", false);
   router.push({ path: "/login" });
 }
@@ -172,6 +184,9 @@ onMounted(() => {
   // cloudLogin();
   shippingCompany.value = localStorage.shippingCompany;
   loginName.value = localStorage.loginName;
+  if (localStorage.isSuperuser == 1 && store.state.companySelect.length == 0) {
+    store.dispatch("getShippingCompanySelect", localStorage.manageId);
+  }
 });
 let timelineData = ref([]);
 async function cloudLogin() {
@@ -191,6 +206,13 @@ async function getAbledVersions() {
 }
 
 const size = 20;
+
+function selectCompany(e) {
+  localStorage.loginAccountId = e.key;
+  store.state.loginAccountId = e.key;
+  localStorage.currentCompany = JSON.stringify(e);
+  router.go(0);
+}
 </script>
 <style scoped>
 .header {

+ 37 - 0
src/store/index.js

@@ -1,4 +1,6 @@
 import { createStore } from "vuex";
+import router from "../router";
+import api from "../apis/fetch";
 
 console.log(import.meta.env.VITE_PROJECT_ENV);
 let baseurl = import.meta.env.VITE_BASEURL;
@@ -18,6 +20,10 @@ const store = createStore({
     updateCertsUrl,
     versions: [],
     keepAliveList: ["shipList", "shipOwnerList"],
+    loginAccountId: localStorage.loginAccountId,
+    companySelect: [],
+    isSuperuser: localStorage.isSuperuser,
+    currentCompany: JSON.parse(localStorage.currentCompany || "{}"),
   },
   mutations: {
     changefirstTitle(state, text) {
@@ -49,6 +55,37 @@ const store = createStore({
     clearAlive(state, data) {
       state.keepAliveList = [];
     },
+    login(state, data) {
+      console.log(data);
+      Object.keys(data).forEach((key) => {
+        if (data.isSuperuser == 1 && key == "loginAccountId") {
+        } else {
+          localStorage.setItem(key, data[key]);
+        }
+      });
+      if (data.isSuperuser == 1) {
+        state.manageId = data.loginAccountId;
+        localStorage.manageId = data.loginAccountId;
+        state.isSuperuser = 1;
+      } else {
+        state.loginAccountId = data.loginAccountId;
+      }
+      state.isLogin = true;
+
+      router.replace({ path: "/index" });
+    },
+  },
+  actions: {
+    async getShippingCompanySelect(state, manageId) {
+      let { data } = await api.getShippingCompanySelect({
+        manageId,
+      });
+      if (data.status == 0) {
+        store.state.companySelect = data.result;
+      } else {
+        store.state.companySelect = [];
+      }
+    },
   },
 });
 

+ 40 - 6
src/views/index/Login.vue

@@ -48,7 +48,27 @@
         </div>
       </div>
     </div>
-
+    <el-dialog
+      title="请选择公司"
+      width="500"
+      v-model="comoanyModalVisable"
+      :show-close="false"
+      :close-on-click-modal="false"
+    >
+      <el-select
+        @change="selectCompany"
+        style="display: block; margin: 0 auto; width: 80%"
+        v-model="store.state.currentCompany"
+        placeholder="请选择"
+      >
+        <el-option
+          v-for="item in store.state.companySelect"
+          :key="item.key"
+          :label="item.value"
+          :value="item"
+        />
+      </el-select>
+    </el-dialog>
     <div @click="goBeian" class="copyright">
       Copyright © 2022 汇很多(江苏)科技有限公司 苏ICP备2022023253号-1 号
     </div>
@@ -80,6 +100,8 @@ const rules = ref({
 function check() {
   // form.value.validate((valid) => {});
 }
+let comoanyModalVisable = ref(false);
+let cache = ref({});
 async function login() {
   // let {data} = await cloudConfig.doc("18ed09686196068205eeb77612d641c6").get();
   // let { version } = data[0];
@@ -99,12 +121,17 @@ async function login() {
           message: data.msg,
           type: "success",
         });
-        Object.keys(data.result).forEach((key) => {
-          localStorage.setItem(key, data.result[key]);
-        });
 
-        store.commit("changeLogin", true);
-        router.replace({ path: "/index" });
+        if (data.result.isSuperuser == 1) {
+          comoanyModalVisable.value = true;
+          cache.value = data.result;
+          store.dispatch(
+            "getShippingCompanySelect",
+            data.result.loginAccountId
+          );
+        } else {
+          store.commit("login", data.result);
+        }
       } else {
         ElNotification.error({
           title: "错误",
@@ -119,6 +146,13 @@ async function login() {
   });
 }
 
+function selectCompany(e) {
+  localStorage.loginAccountId = e.key;
+  localStorage.currentCompany = JSON.stringify(e);
+  store.state.loginAccountId = e.key;
+  store.commit("login", cache.value);
+}
+
 function goBeian() {
   window.open("https://beian.miit.gov.cn/");
 }