祖安之光
9 天以前 b609f77709c4646daf155341475ae14fc0c7943d
src/views/components/loginForm.vue
@@ -46,13 +46,9 @@
              <img :src="codeUrl" @click="getCode" class="login-code-img"/>
            </div>
          </el-form-item>
    <!--      <el-radio-group v-model="loginForm.role" class="mb5">-->
    <!--        <el-radio :label="0" size="large">监管部门</el-radio>-->
    <!--        <el-radio :label="1" size="large">机构管理员</el-radio>-->
    <!--      </el-radio-group>-->
          <div style="display: flex;justify-content: space-between;align-items: center;margin-bottom: 25px">
            <div class="btn-cont">
              <button class="login-btn" @click.prevent="handleLogin">
              <button class="login-btn" @click.prevent="handleLogin" v-preReClick>
                <span v-if="!loading">登 录</span>
                <span v-else>登 录 中...</span>
              </button>
@@ -63,8 +59,12 @@
          </div>
        </el-form>
        <div class="other-btns">
          <el-button link type="primary" style="color: #fff" @click="openApply()">专家申请</el-button>
          <el-button link type="primary" style="color: #fff" @click="openCheck">专家评定进度查询</el-button>
          <el-button link type="primary" style="color: #fff" @click="openApply()" v-preReClick>专家申请</el-button>
          <el-button link type="primary" style="color: #fff" @click="openCheck" v-preReClick>专家评定进度查询</el-button>
        </div>
        <div style="margin-top: 10px;display: flex;align-items: center">
          <img :src="info" style="width: 20px;height: auto;margin-right: 6px"/>
          <el-button link type="primary" style="color: yellow;text-decoration: underline;font-size: 18px" @click="openFile()" v-preReClick>2025年第三方评定工作的通知</el-button>
        </div>
      </div>
    </el-col>
@@ -74,16 +74,20 @@
</template>
<script setup>
import {onMounted, ref, watch, defineAsyncComponent, nextTick} from "vue"
import {onMounted, ref, watch, defineAsyncComponent, nextTick, computed} from "vue"
import { getCodeImg } from "@/api/login";
import {getSettings} from "@/api/backManage/evaluate";
import info from '@/assets/icons/info.png'
import Cookies from "js-cookie";
import { encrypt, decrypt } from "@/utils/jsencrypt";
import useUserStore from '@/store/modules/user'
import { Register } from "@/layout/components";
import { Base64 } from 'js-base64'
import menu from "@/layout/components/Sidebar/menu";
import ExpertForm from "../safetyReview/expertManage/applyRecords/components/expertForm";
import usePermissionStore from '@/store/modules/permission'
import {ElMessage} from "element-plus";
const permissionStore = usePermissionStore()
const sidebarRouters =  computed(() => permissionStore.sidebarRouters);
const userStore = useUserStore()
const route = useRoute();
const router = useRouter();
@@ -93,8 +97,7 @@
  username: "",
  password: "",
  code: "",
  uuid: "",
  role: 0
  uuid: ""
});
const loginRules = {
@@ -108,12 +111,13 @@
const regRef = ref(null)
// 验证码开关
const captchaEnabled = ref(true);
const applyStatus = ref('1')
// 注册开关
const isRegister = ref(true);
const redirect = ref(undefined);
onMounted(()=>{
  Cookies.remove("userState");
})
const openRegist = ()=>{
@@ -124,18 +128,32 @@
    redirect.value = newRoute.query && newRoute.query.redirect;
}, { immediate: true });
const sidebarRouters = ref([])
const openFile =()=>{
  window.open('noticeFile.pdf', '_blank')
}
const expertFormRef = ref()
const openApply = () => {
  // expertFormRef.value.openApply(type, value)
  const routePath = '/fillForm';
  const resolvedRoute = router.resolve(routePath);
  const fullPath = resolvedRoute.href
  window.open(fullPath, '_blank');
const getApplyStatus = async ()=>{
  const res = await getSettings()
  if(res.code == 200){
    return res.data
  }else{
    ElMessage.warning(res.msg)
    return '0'
  }
}
const openApply = async () => {
  const status = await getApplyStatus();
  if(status == '1'){
    const routePath = '/fillForm';
    const resolvedRoute = router.resolve(routePath);
    const fullPath = resolvedRoute.href
    window.open(fullPath, '_blank');
  }else{
    ElMessage.warning('抱歉,专家申请暂未开启,请联系相关人员进行处理')
  }
}
@@ -154,7 +172,8 @@
      // 勾选了需要记住密码设置在 cookie 中设置记住用户名和密码
      // if (loginForm.value.rememberMe) {
        Cookies.set("username", loginForm.value.username, { expires: 30 });
        Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 });
        Cookies.set("password", loginForm.value.password, { expires: 30 });
        // Cookies.set("password", encrypt(loginForm.value.password), { expires: 30 });
      //   Cookies.set("rememberMe", loginForm.value.rememberMe, { expires: 30 });
      // } else {
        // 否则移除
@@ -166,48 +185,19 @@
      // loginForm.value.password = Base64.encode(loginForm.value.password)
        const param = {
            username: loginForm.value.username,
            password: Base64.encode(loginForm.value.password),
            password: loginForm.value.password,
            code: loginForm.value.code,
            uuid: loginForm.value.uuid,
            identity: loginForm.value.role
        }
      userStore.login(param).then(() => {
        // const query = route.query;
        // const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
        //   if (cur !== "redirect") {
        //     acc[cur] = query[cur];
        //   }
        //   return acc;
        // }, {});
        const userInfo = JSON.parse(Cookies.get('userInfo'))
          if(userInfo.identity === 0 ) {
              //监管用户
              sidebarRouters.value =  menu.adminMenu
              Cookies.set('routers',JSON.stringify(sidebarRouters.value))
          }else if(userInfo.identity === 1) {
            const userState = JSON.parse(Cookies.get('userState'))
            console.log("userState",userState)
              //机构用户
              //未审核状态不显示菜单
              if(userState !==2 ){
                sidebarRouters.value = menu.noMenu
                Cookies.set('routers',JSON.stringify(sidebarRouters.value))
              }else {
                sidebarRouters.value =  menu.agencyMenu
                Cookies.set('routers',JSON.stringify(sidebarRouters.value))
              }
        const query = route.query;
        const otherQueryParams = Object.keys(query).reduce((acc, cur) => {
          if (cur !== "redirect") {
            acc[cur] = query[cur];
          }
          let path = ""
          if(sidebarRouters.value[0].children && sidebarRouters.value[0].children.length > 0){
              path = sidebarRouters.value[0].path + '/'+ sidebarRouters.value[0].children[0].path
          }else {
              path = sidebarRouters.value[0].path
          }
        router.push({
            path: path
        })
        // router.push({ path: redirect.value || "/", query: otherQueryParams });
          return acc;
        }, {});
        router.push({ path: redirect.value || "/", query: otherQueryParams });
      }).catch(() => {
        loading.value = false;
        // 重新获取验证码
@@ -221,22 +211,22 @@
function getCode() {
  getCodeImg().then(res => {
    captchaEnabled.value = res.data.captchaEnabled === undefined ? true : res.captchaEnabled
    captchaEnabled.value = res.captchaEnabled === undefined ? true : res.captchaEnabled
    if (captchaEnabled.value) {
      codeUrl.value = "data:image/gif;base64," + res.data.image
      loginForm.value.uuid = res.data.uuid
      codeUrl.value = "data:image/gif;base64," + res.img
      loginForm.value.uuid = res.uuid
    }
  });
}
// function getCookie() {
//   const username = Cookies.get("username")
//   const password = Cookies.get("password")
//   loginForm.value = {
//     username: username === undefined ? loginForm.value.username : username,
//     password: password === undefined ? loginForm.value.password : decrypt(password),
//   };
// }
function getCookie() {
  const username = Cookies.get("username")
  const password = Cookies.get("password")
  loginForm.value = {
    username: username === undefined ? loginForm.value.username : username,
    password: password === undefined ? loginForm.value.password : decrypt(password),
  };
}
getCode();
// getCookie();