yangyin
2024-11-29 3c0f2cd6720032f83ab34daff947bf31f3bb96b3
src/layout/component/sidebar/components/MenuList.vue
@@ -21,14 +21,14 @@
               ><span class="user_name"> {{ userName }} </span></span
            ><span ref="toggleExitLoginBtnRef"
               ><span
                  class="ywicon text-white"
                  :class="{ 'icon-fold': !state.isShowExitLogin, 'icon-unfold': state.isShowExitLogin }"
                  class="ywifont text-white"
                  :class="{ 'ywicon-fold': !state.isShowExitLogin, 'ywicon-unfold': state.isShowExitLogin }"
                  @click="toggleShowExitLogin"
               ></span
            ></span>
         </div>
         <div class="pop_up actived" v-show="state.isShowExitLogin">
            <div class="exit" @click="logoutClick"><i class="ywicon icon-tuichu"></i> 退出登录</div>
            <div class="exit" @click="logoutClick"><i class="ywifont ywicon-tuichu"></i> 退出登录</div>
         </div>
      </div>
      <div v-else class="user_login">
@@ -37,65 +37,42 @@
         </div>
      </div>
   </div>
   <div class="pc-login" v-show="state.isShowLogin">
      <div class="login_box">
         <div class="sign_in">
            <i class="ywicon icon-guanbi closes" @click="handleClose"></i>
            <h1><span class="ml-[33px]">登录 WI 水务</span></h1>
            <el-form ref="loginFormRef" :model="state.loginForm" :rules="loginRules" class="demo-ruleForm" size="large">
               <el-form-item label="账号" prop="account">
                  <el-input v-model="state.loginForm.account" clearable />
               </el-form-item>
               <el-form-item label="密码" prop="pwd">
                  <el-input v-model="state.loginForm.pwd" type="password" autocomplete="off" clearable />
               </el-form-item>
            </el-form>
            <div class="mt-[115px]">
               <el-button type="primary" @click="onSubmit" class="set-login_btn">登录</el-button>
            </div>
         </div>
      </div>
   </div>
</template>
<script setup lang="ts">
import type { FormInstance } from 'element-plus';
import { computed, onMounted, reactive, ref, watchEffect } from 'vue';
import { PostLogin } from '/@/api/ai/user';
import router from '/@/router';
import emitter from '/@/utils/mitt';
import { isLoginStatus, isSharePage, isShowLogin } from '/@/stores/chatRoom';
import { accessSessionKey, userNameKey } from '/@/utils/request';
import { gotoRoute } from '/@/utils/route';
import { Local } from '/@/utils/storage';
const loginFormRef = ref<FormInstance>(null);
const isLoginStatus = ref(!!Local.get(accessSessionKey));
import { Local, LoginInfo } from '/@/utils/storage';
import emitter from '/@/utils/mitt';
const userName = ref('');
const firstUserCharacter = computed(() => userName.value?.[0]?.toUpperCase());
isLoginStatus.value = !!Local.get(accessSessionKey);
watchEffect(() => {
   if (!isLoginStatus.value) return;
   userName.value = Local.get(userNameKey);
});
let state = reactive({
   asideTitleList: [
      {
         id: 1,
         icon: '/static/images/wave/AsideIcon.png',
         title: '应用场景',
         routerName: 'Scenario',
      },
      {
         id: 2,
         icon: '/static/images/wave/AsideIcon.png',
         title: '帮助中心',
         // routerName:'Scenario',
      },
      {
         id: 3,
         icon: '/static/images/wave/AsideIcon.png',
         title: '个人设置',
      },
      // {
      //    id: 1,
      //    icon: '/static/images/wave/AsideIcon.png',
      //    title: '应用场景',
      //    routerName: 'AllScenario',
      // },
      // {
      //    id: 2,
      //    icon: '/static/images/wave/AsideIcon.png',
      //    title: '帮助中心',
      //    // routerName:'Scenario',
      // },
      // {
      //    id: 3,
      //    icon: '/static/images/wave/AsideIcon.png',
      //    title: '个人设置',
      // },
      {
         id: 4,
         icon: '/static/images/wave/AsideIcon.png',
@@ -103,40 +80,27 @@
         routerName: 'AboutUs',
      },
   ],
   isShowLogin: false,
   isShowExitLogin: false,
   loginForm: {
      account: '',
      pwd: '',
   },
});
const loginRules = reactive({
   account: [{ required: true, message: '请输入账号', trigger: 'blur' }],
   pwd: [{ required: true, message: '请输入密码', trigger: 'blur' }],
   loginPhoneForm: {
      phoneUser: '',
      verifyCode: '',
   },
   activeLoginName: 'accountUser',
});
const handleClick = (item) => {
   if (!item.routerName) return;
   gotoRoute({ name: item.routerName });
};
//登录
const openLoginDlg = async () => {
   state.isShowLogin = true;
};
const handleClose = () => {
   state.isShowLogin = false;
};
//登录
const onSubmit = async () => {
   const isValid = await loginFormRef.value.validate().catch(() => {});
   if (!isValid) return;
   const res = await PostLogin({
      user: state.loginForm.account,
      pass: state.loginForm.pwd,
   });
   Local.set(accessSessionKey, res.hswatersession);
   Local.set(userNameKey, state.loginForm.account);
   state.isShowLogin = false;
   isLoginStatus.value = true;
   window.location.reload();
   // 分享页不需要
   if (isSharePage.value) return;
   isShowLogin.value = true;
};
const currentRoute = router.currentRoute;
@@ -149,7 +113,7 @@
const logoutClick = () => {
   state.isShowExitLogin = false;
   isLoginStatus.value = false;
   Local.remove(accessSessionKey);
   LoginInfo.remove();
};
const toggleExitLoginBtnRef = ref<HTMLDivElement>(null);
@@ -161,14 +125,13 @@
onMounted(() => {
   emitter.on('openLoginDlg', () => {
      if (state.isShowLogin || isLoginStatus.value) return;
      if (isShowLogin.value || isLoginStatus.value) return;
      openLoginDlg();
   });
   emitter.on('logout', () => {
      logoutClick();
   });
   document.addEventListener('click', listenClickOtherExit);
});
</script>
@@ -343,6 +306,7 @@
   -ms-flex-pack: center;
   justify-content: center;
}
.pc-login {
   position: fixed;
   top: 0;
@@ -354,9 +318,9 @@
   .login_box {
      position: relative;
      width: 450px;
      height: 550px;
      margin: 15vh auto;
      .sign_in {
         padding: 39px;
         position: relative;
         width: 100%;
         height: 100%;
@@ -387,12 +351,10 @@
         h1 {
            box-sizing: content-box;
            width: 100%;
            margin-top: 25px;
            font-size: 30px;
            font-weight: 500;
            color: #1c153a;
            text-align: left !important;
            margin-bottom: 105px;
         }
         .demo-ruleForm {
            :deep(.el-input__wrapper) {
@@ -407,6 +369,9 @@
               background-color: #fff;
               border-radius: 5px;
            }
            :deep(.el-form-item--large .el-form-item__error) {
               padding: unset !important;
            }
         }
         .set-pwd {
            text-align: right;