From fa3ac93010bea3805438ee3ab0a182bfbf7423da Mon Sep 17 00:00:00 2001
From: baoshiwei <baoshiwei@shlanbao.cn>
Date: 星期一, 27 五月 2024 16:19:31 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/master'

---
 src/views/sys/login/LoginSelect.vue |  334 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 334 insertions(+), 0 deletions(-)

diff --git a/src/views/sys/login/LoginSelect.vue b/src/views/sys/login/LoginSelect.vue
new file mode 100644
index 0000000..57ad48d
--- /dev/null
+++ b/src/views/sys/login/LoginSelect.vue
@@ -0,0 +1,334 @@
+<template>
+  <BasicModal v-bind="config" @register="registerModal" :title="currTitle" wrapClassName="loginSelectModal" v-model:visible="visible">
+    <a-form ref="formRef" :model="formState" :rules="rules" v-bind="layout" :colon="false" class="loginSelectForm">
+      <!--澶氱鎴烽�夋嫨-->
+      <a-form-item v-if="isMultiTenant" name="tenantId" :validate-status="validate_status">
+        <!--label鍐呭-->
+        <template #label>
+          <a-tooltip placement="topLeft">
+            <template #title>
+              <span>鎮ㄩ毝灞炰簬澶氱鎴凤紝璇烽�夋嫨鐧诲綍绉熸埛</span>
+            </template>
+            <a-avatar style="background-color: #87d068" :size="30"> 绉熸埛 </a-avatar>
+          </a-tooltip>
+        </template>
+        <template #extra v-if="validate_status == 'error'">
+          <span style="color: #ed6f6f">璇烽�夋嫨鐧诲綍绉熸埛</span>
+        </template>
+        <!--绉熸埛涓嬫媺鍐呭-->
+        <a-select
+          v-model:value="formState.tenantId"
+          @change="handleTenantChange"
+          placeholder="璇烽�夋嫨鐧诲綍绉熸埛"
+          :class="{ 'valid-error': validate_status == 'error' }"
+        >
+          <template v-for="tenant in tenantList" :key="tenant.id">
+            <a-select-option :value="tenant.id">{{ tenant.name }}</a-select-option>
+          </template>
+        </a-select>
+      </a-form-item>
+      <!--澶氶儴闂ㄩ�夋嫨-->
+      <a-form-item v-if="isMultiDepart" :validate-status="validate_status1" :colon="false">
+        <!--label鍐呭-->
+        <template #label>
+          <a-tooltip placement="topLeft">
+            <template #title>
+              <span>鎮ㄩ毝灞炰簬澶氶儴闂紝璇烽�夋嫨鐧诲綍閮ㄩ棬</span>
+            </template>
+            <a-avatar style="background-color: rgb(104, 208, 203)" :size="30"> 閮ㄩ棬 </a-avatar>
+          </a-tooltip>
+        </template>
+        <template #extra v-if="validate_status1 == 'error'">
+          <span style="color: #ed6f6f">璇烽�夋嫨鐧诲綍閮ㄩ棬</span>
+        </template>
+        <!--閮ㄩ棬涓嬫媺鍐呭-->
+        <a-select
+          v-model:value="formState.orgCode"
+          @change="handleDepartChange"
+          placeholder="璇烽�夋嫨鐧诲綍閮ㄩ棬"
+          :class="{ 'valid-error': validate_status1 == 'error' }"
+        >
+          <template v-for="depart in departList" :key="depart.orgCode">
+            <a-select-option :value="depart.orgCode">{{ depart.departName }}</a-select-option>
+          </template>
+        </a-select>
+      </a-form-item>
+    </a-form>
+
+    <template #footer>
+      <a-button @click="handleSubmit" type="primary">纭</a-button>
+    </template>
+  </BasicModal>
+</template>
+
+<script lang="ts">
+  import { defineComponent, ref, computed, watch, unref, reactive, UnwrapRef } from 'vue';
+  import { Avatar } from 'ant-design-vue';
+  import { BasicModal, useModalInner } from '/@/components/Modal';
+  import { useMessage } from '/@/hooks/web/useMessage';
+  import { useUserStore } from '/@/store/modules/user';
+  import { defHttp } from '/@/utils/http/axios';
+  interface FormState {
+    orgCode: string | undefined;
+    tenantId: number;
+  }
+  export default defineComponent({
+    name: 'loginSelect',
+    components: {
+      Avatar,
+      BasicModal,
+    },
+    emits: ['success', 'register'],
+    setup(props, { emit }) {
+      const userStore = useUserStore();
+      const { notification } = useMessage();
+      //绉熸埛閰嶇疆
+      const isMultiTenant = ref(false);
+      const tenantList = ref([]);
+      const validate_status = ref('');
+      //閮ㄩ棬閰嶇疆
+      const isMultiDepart = ref(false);
+      const departList = ref([]);
+      const validate_status1 = ref('');
+      //寮圭獥鏄鹃殣
+      const visible = ref(false);
+      //鐧诲綍鐢ㄦ埛
+      const username = ref('');
+      //琛ㄥ崟
+      const formRef = ref();
+      //閫夋嫨鐨勭鎴烽儴闂ㄤ俊鎭�
+      const formState: UnwrapRef<FormState> = reactive({
+        orgCode: undefined,
+        tenantId: null,
+      });
+
+      const config = {
+        maskClosable: false,
+        closable: false,
+        canFullscreen: false,
+        width: '500px',
+        minHeight: 20,
+        maxHeight: 20,
+      };
+      //寮圭獥鎿嶄綔
+      const [registerModal, { closeModal }] = useModalInner();
+
+      //褰撳墠鏍囬
+      const currTitle = computed(() => {
+        if (unref(isMultiDepart) && unref(isMultiTenant)) {
+          return '璇烽�夋嫨绉熸埛鍜岄儴闂�';
+        } else if (unref(isMultiDepart) && !unref(isMultiTenant)) {
+          return '璇烽�夋嫨閮ㄩ棬';
+        } else if (!unref(isMultiDepart) && unref(isMultiTenant)) {
+          return '璇烽�夋嫨绉熸埛';
+        }
+      });
+
+      const rules = ref({
+        tenantId: [{ required: unref(isMultiTenant), type: 'number', message: '璇烽�夋嫨绉熸埛', trigger: 'change' }],
+        orgCode: [{ required: unref(isMultiDepart), message: '璇烽�夋嫨閮ㄩ棬', trigger: 'change' }],
+      });
+
+      const layout = {
+        labelCol: { span: 4 },
+        wrapperCol: { span: 18 },
+      };
+      /**
+       * 澶勭悊閮ㄩ棬鎯呭喌
+       */
+      function bizDepart(loginResult) {
+        //濡傛灉鐧诲綍鎺ュ彛杩斿洖浜嗙敤鎴蜂笂娆$櫥褰曠鎴稩D锛屽垯涓嶉渶瑕侀噸鏂伴�夋嫨
+        if(loginResult.userInfo?.orgCode && loginResult.userInfo?.orgCode!==''){
+          isMultiDepart.value = false;
+          return;
+        }
+        
+        let multi_depart = loginResult.multi_depart;
+        console.log("loginResult::",loginResult);
+        //0:鏃犻儴闂� 1:涓�涓儴闂� 2:澶氫釜閮ㄩ棬
+        if (multi_depart == 0) {
+          notification.warn({
+            message: '鎻愮ず',
+            description: `鎮ㄥ皻鏈綊灞為儴闂�,璇风‘璁よ处鍙蜂俊鎭痐,
+            duration: 3,
+          });
+          isMultiDepart.value = false;
+        } else if (multi_depart == 2) {
+          isMultiDepart.value = true;
+          departList.value = loginResult.departs;
+        } else {
+          isMultiDepart.value = false;
+        }
+      }
+
+      /**
+       * 澶勭悊绉熸埛鎯呭喌
+       */
+      function bizTenantList(loginResult) {
+        //濡傛灉鐧诲綍鎺ュ彛杩斿洖浜嗙敤鎴蜂笂娆$櫥褰曠鎴稩D锛屽垯涓嶉渶瑕侀噸鏂伴�夋嫨
+        if(loginResult.userInfo?.loginTenantId && loginResult.userInfo?.loginTenantId!==0){
+          isMultiTenant.value = false;
+          return;
+        }
+        
+        let tenantArr = loginResult.tenantList;
+        if (Array.isArray(tenantArr)) {
+          if (tenantArr.length === 0) {
+            isMultiTenant.value = false;
+            userStore.setTenant(formState.tenantId);
+          } else if (tenantArr.length === 1) {
+            formState.tenantId = tenantArr[0].id;
+            isMultiTenant.value = false;
+            userStore.setTenant(formState.tenantId);
+          } else {
+            isMultiTenant.value = true;
+            tenantList.value = tenantArr;
+          }
+        }
+      }
+
+      /**
+       * 纭閫変腑鐨勭鎴峰拰閮ㄩ棬淇℃伅
+       */
+      function handleSubmit() {
+        if (unref(isMultiTenant) && !formState.tenantId) {
+          validate_status.value = 'error';
+          return false;
+        }
+        if (unref(isMultiDepart) && !formState.orgCode) {
+          validate_status1.value = 'error';
+          return false;
+        }
+        formRef.value
+          .validate()
+          .then(() => {
+            departResolve()
+              .then(() => {
+                userStore.setTenant(formState.tenantId);
+                emit('success');
+              })
+              .catch((e) => {
+                console.log('鐧诲綍閫夋嫨鍑虹幇闂', e);
+              })
+              .finally(() => {
+                close();
+              });
+          })
+          .catch((err) => {
+            console.log('琛ㄥ崟鏍¢獙鏈�氳繃error', err);
+          });
+      }
+      /**
+       *鍒囨崲閫夋嫨閮ㄩ棬
+       */
+      function departResolve() {
+        return new Promise((resolve, reject) => {
+          if (!unref(isMultiDepart) && !unref(isMultiTenant)) {
+            resolve();
+          } else {
+            let params = { orgCode: formState.orgCode,loginTenantId: formState.tenantId, username: unref(username) };
+            defHttp.put({ url: '/sys/selectDepart', params }).then((res) => {
+              if (res.userInfo) {
+                userStore.setUserInfo(res.userInfo);
+                resolve();
+              } else {
+                requestFailed(res);
+                userStore.logout();
+                reject();
+              }
+            });
+          }
+        });
+      }
+
+      /**
+       * 璇锋眰澶辫触澶勭悊
+       */
+      function requestFailed(err) {
+        notification.error({
+          message: '鐧诲綍澶辫触',
+          description: ((err.response || {}).data || {}).message || err.message || '璇锋眰鍑虹幇閿欒锛岃绋嶅悗鍐嶈瘯',
+          duration: 4,
+        });
+      }
+
+      /**
+       * 鍏抽棴model
+       */
+      function close() {
+        closeModal();
+        reset();
+      }
+      /**
+       * 寮圭獥鎵撳紑鍓嶅鐞�
+       */
+      async function show(loginResult) {
+        console.log("showLoginResult::", loginResult);
+        if (loginResult) {
+          username.value = userStore.username;
+          await reset();
+          await bizDepart(loginResult);
+          await bizTenantList(loginResult);
+          if (!unref(isMultiDepart) && !unref(isMultiTenant)) {
+            emit('success', userStore.getUserInfo);
+          } else {
+            visible.value = true;
+          }
+        }
+        //鐧诲綍寮圭獥瀹屾垚鍚庯紝灏嗙櫥褰曠殑鏍囪瘑璁剧疆鎴恌alse
+        loginResult.isLogin = false;
+        userStore.setLoginInfo(loginResult);
+      }
+
+      /**
+       *閲嶇疆鏁版嵁
+       */
+      function reset() {
+        tenantList.value = [];
+        validate_status.value = '';
+
+        departList.value = [];
+        validate_status1.value = '';
+      }
+
+      function handleTenantChange(e) {
+        validate_status.value = '';
+      }
+
+      function handleDepartChange(e) {
+        validate_status1.value = '';
+      }
+
+      return {
+        registerModal,
+        visible,
+        tenantList,
+        isMultiTenant,
+        validate_status,
+        isMultiDepart,
+        departList,
+        validate_status1,
+        formState,
+        rules,
+        layout,
+        formRef,
+        currTitle,
+        config,
+        handleTenantChange,
+        handleDepartChange,
+        show,
+        handleSubmit,
+      };
+    },
+  });
+</script>
+
+<style lang="less" scoped>
+  .loginSelectForm {
+    margin-bottom: -20px;
+  }
+
+  .loginSelectModal {
+    top: 10px;
+  }
+</style>

--
Gitblit v1.9.3