Browse Source

新增租户切换

wangtao 1 month ago
parent
commit
b92f54bdb2

+ 5 - 1
src/pages/business/zhaf/xunJian/plan/components/report.vue

@@ -236,6 +236,7 @@ function AbnormalReport(){
  * @结束巡检
  */
 function endInspection() {
+
   errorApi()
   .Insert(
     {
@@ -246,7 +247,10 @@ function endInspection() {
       "deviceId": proxy.$settingStore.deviceList.deviceId,
       "planId": xunJianStore.planId
     }
-  )
+  ).then(() => {
+    proxy.$modal.msg("结束巡检成功");
+    uni.navigateBack();
+  })
   .catch((err) => {
     proxy.$modal.msg(err);
   });

+ 141 - 34
src/pages/index.vue

@@ -1,9 +1,12 @@
 <template>
   <u-navbar :autoBack="false" :placeholder="true" :safeAreaInsetTop="true" :bgColor="proxy.$settingStore.themeColor.color">
     <template #left>
-      <view class="u-navbar__content__left__item">
+      <view class="u-navbar__content__left__item" v-if="tenantIdList.length == 1">
         <view class="u-navbar__content__left__item__title">应用中心</view>
       </view>
+      <view  v-if="tenantIdList.length > 1 && accountState">
+        <image class="unit-change" src="@/static/images/index/unitChange.png" @click="showLeftStateClick()" ></image>
+      </view>
     </template>
     <template #center>
       <view class="u-navbar__content__left__item"> </view>
@@ -77,19 +80,17 @@
       </view>
     </template>
   </oa-scroll>
-  <uni-drawer ref="showLeft" mode="left" :width="320" @change="change($event,'showLeft')">
-    <!-- <view class="close">
-      <button @click="closeDrawer('showLeft')"><text class="word-btn-white">X</text></button>
-    </view> -->
-    <text>切换企业</text>
+  <uni-drawer ref="showLeft" mode="left"   style="height:calc(100vh - 44px);width:90%;margin-top:44px;">
     <view class="unit">
-      <view class="list">
-        <u-radio-group v-model="tenantIdChange" @change="changeTenantId">
-          <u-radio :activeColor="proxy.$settingStore.themeColor.color" :name="item.id" :label="item.tenantName" v-for="(item, index) in tenantIdList" :key="index"></u-radio>
-        </u-radio-group>
+      <view class="unit-title">切换企业</view>
+      <view :class="item.id == useStore.tenantId ? 'active' : ''" class="list"  v-for="(item, index) in tenantIdList" :key="index" @click="changeTenantId(item.id)">
+        <image class="list-image" src="@/static/images/index/unit-active.png" v-if="item.id == useStore.tenantId" ></image>
+        <image class="list-image" src="@/static/images/index/unit.png" v-if="item.id != useStore.tenantId" ></image>
+        <text class="list-name">{{ item.tenantName }}</text>
+        <image class="list-right" src="@/static/images/index/right.png" v-if="item.id == useStore.tenantId"></image>
+        <text class="list-state">默认企业</text>
       </view>
     </view>
-
   </uni-drawer>
   <oa-tabbar :tabbarValue="0" :tabbarList="proxy.$constData.homeTabbar"></oa-tabbar>
 </template>
@@ -101,8 +102,9 @@ import { ref, onMounted, inject, shallowRef, reactive, getCurrentInstance, toRef
 /*----------------------------------接口引入-----------------------------------*/
 import { scan_push, getHomePageData, getFunctionalModuleStatistics, getAppRouters, qrCodeSend, getMobileBanner } from "@/api/index";
 /*----------------------------------组件引入-----------------------------------*/
+import config from "@/config";
 /*----------------------------------store引入-----------------------------------*/
-import { useStores } from "@/store/modules/index";
+import { useStores, commonStores } from "@/store/modules/index";
 /*----------------------------------公共方法引入-----------------------------------*/
 import * as jwx from "@/utils/jssdk.js"; //引入js sdk的封装
 import { getToken, setToken, removeToken } from "@/utils/auth";
@@ -112,9 +114,11 @@ import { decrypt } from "@/plugins/jsencrypt";
 /*----------------------------------公共变量-----------------------------------*/
 const { proxy } = getCurrentInstance();
 const useStore = useStores();
+const commonStore = commonStores();
 /*----------------------------------变量声明-----------------------------------*/
-const touchStartX = ref(0); // 触摸开始X轴坐标
-const showLeft = ref(false); // 左侧菜单显示状态
+const accountState = ref(false); // 有效账号状态(用于企业切换)
+const showLeft = ref(false); // 左侧菜单
+const showLeftState = ref(false); // 左侧菜单显示状态
 const tenantIdChange = ref(""); // 切换租户ID
 const tenantIdList = ref([]); // 租户ID列表
 const state = reactive({
@@ -129,48 +133,90 @@ const state = reactive({
   recentlyUsed: [],
 });
 const { dialogFlag } = toRefs(state);
-
-function touchStart(e){
-  touchStartX.value = e.touches[0].clientX;
-}
-// 触摸结束时触发此函数
-function touchEnd(e) {
-    // 计算触摸结束时与开始时的坐标差值
-    let deltaX = e.changedTouches[0].clientX - touchStartX.value;
-    if(deltaX > 100){
-      showDrawer()
-    }
+/**
+ * @企业弹框切换
+ */
+function showLeftStateClick(){
+  showLeftState.value = !showLeftState.value;
+  if(showLeftState.value){
+    showDrawer()
+  }else{
+    closeDrawer()
+  }
 }
 // 单位打开窗口
 function showDrawer() {
-  // showLeft.value.open()
+  showLeft.value.open()
 }
 // 单位关闭窗口
-function 	closeDrawer(e) {
+function closeDrawer(e) {
   showLeft.value.close()
 }
 //获取企业列表
 function getTenantList(id){
   getTenantByUser(id).then((res) => {
     tenantIdList.value = res.data
+    if(storage.get("account")?.userName && storage.get("account")?.passWord){
+      accountState.value = true;
+    }
   })
 }
-function changeTenantId(){
-  if(useStore.userName && useStore.password){
-    
-  }
+/**
+ * @企业切换
+ */
+function changeTenantId(id){
+  
+  storage.set("tenantId",id)
+  var info = JSON.parse(JSON.stringify({
+    userName:storage.get("account")?.userName,
+    passWord:storage.get("account")?.passWord,
+    tenantId:id,
+  }))
+  useStore.LogOut().then(() => {
+    //#ifdef APP-PLUS
+      uni.navigateTo({
+        url: "/pages/index",
+      });
+    //#endif
+    //#ifndef APP-PLUS
+    //#endif
+      if (localStorage.getItem("type")) {
+          wx.miniProgram.navigateTo({
+              appId: 'wxf5ad8734295d43f8',
+              url: '/pages/login?type=logout'
+          })
+      } else {
+        useStore.Login(
+          {
+            username: decrypt(info.userName),
+            password: decrypt(info.passWord),
+            tenantId: id,
+            method:"switch",
+            cids: proxy.$settingStore.pushClientId || undefined,
+            type: proxy.$common.isWechatMp() ? "wx" : "app",
+            openId: proxy.$common.isWechatMp() ? localStorage.getItem("wxOpenId") : undefined,
+          }
+        ).then(() => {
+          // /** 获取用户信息 */
+          useStore.SET_STORAGE_OBJECT_KEYS({"tenantId":id})
+          proxy.$modal.closeLoading();
+          useStore.GetInfo().then((res) => {
+            proxy.$settingStore.initThemeColor(storageSystem.get("themeColor")); //初始化默认主题
+            init()
+            closeDrawer()
+          });
+        });
+      }
+  });
 }
 /**
  * @初始化
  */
 async function init(options) {
-  setTimeout(()=>{
     if(useStore?.userId){
       tenantIdChange.value = useStore.tenantId; //切换租户ID
-      console.log("切换租户ID", useStore)
       getTenantList(useStore.userId); //调用获取企业列表方法
     }
-  },2000)
   //#ifdef H5
   await useStore.GetWxOpenId(2, options); //调用获取微信公众号openId
   //#endif
@@ -490,4 +536,65 @@ onShow(() => {
     }
   }
 }
+.unit-change{
+  width:18px;
+  height:18px;
+  position:fixed;
+  top:12px;
+  left:12px;
+}
+.unit{
+  width:100vw !important;
+  height:100%;
+  background: #0D2E59;
+  position:fixed;
+  top:0px;
+  left:0%;
+  &-title{
+    margin:15px 0 10px 10px;
+    color:#fff;
+  }
+  .list{
+    margin-top:10px;
+    padding:10px;
+    position:relative;
+    width:90%;
+    &-image{
+      width:29px;
+      height:29px;
+      vertical-align:middle;
+      margin-right:10px;
+    }
+    &-name{
+      vertical-align:middle;
+      color:#fff;
+      width:60%;
+      display:inline-block;
+      white-space: nowrap; /* 防止文本换行 */
+      overflow: hidden; /* 隐藏超出容器的文本 */
+      text-overflow: ellipsis; /* 显示省略号以代表被隐藏的文本 */
+    }
+    &-right{
+      position:absolute;
+      top:38%;
+      right:30%;
+      width:16px;
+      height:11px;
+      vertical-align:middle;
+    }
+    &-state{
+      position:absolute;
+      right:20px;
+      top:16px;
+      font-size:12px;
+      color:#2A98FF;
+    }
+    &-state.active{
+      color:#999;
+    }
+  }
+  .list.active{
+    background:#193B61;
+  }
+}
 </style>

BIN
src/static/images/banner/banner01.jpg


BIN
src/static/images/banner/banner02.jpg


BIN
src/static/images/banner/banner03.jpg


BIN
src/static/images/index/right.png


BIN
src/static/images/index/unit-active.png


BIN
src/static/images/index/unit.png


BIN
src/static/images/index/unitChange.png


+ 3 - 3
src/store/modules/user.js

@@ -28,7 +28,7 @@ const useStores = defineStore("useStores", {
     roles: storage.get("roles"),//用户权限
     permissions: storage.get("permissions"),
     userName: "",//用户名
-    password: "",//密码
+    passWord: "",//密码
 
     loginTitle: storage.get("loginTitle"),
     loginBottomTitle: storage.get("loginBottomTitle"),
@@ -53,8 +53,7 @@ const useStores = defineStore("useStores", {
             this.SET_TOKEN(res.data.access_token)
             setToken(res.data.access_token);
             this.codeTime = 0
-            this.userName = encrypt(data.username)
-            this.password = encrypt(data.password)
+            storage.set("account",{ userName:encrypt(data.username),passWord:encrypt(data.password) })
             resolve(res);
             resolve();
           })
@@ -379,6 +378,7 @@ const useStores = defineStore("useStores", {
       storage.set("permissions", permissions);
     },
     SET_STORAGE_OBJECT_KEYS(LIST) {
+      console.log(LIST,111)
       Object.keys(LIST).forEach(function (key) {
         storage.set(key, LIST[key]);
         useStores()[key] = LIST[key];