zhangwei
1 天以前 309b5a2eb4a99f20b2dcceca41c7ed1275bcc6ae
src/views/login/index.vue
@@ -30,7 +30,7 @@
// import darkIcon from "@/assets/svg/dark.svg?component";
import Lock from "~icons/ri/lock-fill";
import User from "~icons/ri/user-3-fill";
import { captcha, phoneNumberCode, exRole } from "@/api/register/index.ts";
import { captcha, phoneNumberCode, exRole } from "@/api/register/index";
defineOptions({
  name: "Login"
@@ -50,11 +50,8 @@
// 获取验证码
const getCaptcha = async () => {
  // if (!state.captchaEnabled) return;
  state.ruleForm.code = "";
  const res = await captcha();
  console.log(res);
  state.captchaImage = "data:text/html;base64," + res.result?.img;
  state.expirySeconds = res.result?.expirySeconds;
  state.ruleForm.codeId = res.result?.id;
@@ -66,9 +63,8 @@
    nickName: "",
    phone: "",
    phoneVCode: "",
    // tenantId: props.tenantInfo.id,
    code: "",
    codeId: 0,
    codeId: "",
    email: "",
    exRoleCode: ""
  },
@@ -110,7 +106,8 @@
  hideTenantForLogin: false,
  expirySeconds: 60, // 验证码过期时间
  phoneSeconds: 0, // 手机验证码倒计时
  roleList: []
  roleList: [],
  nowRole: {}
});
// 验证码过期计时器
let timer: any = null;
@@ -119,7 +116,7 @@
// 页面初始化
onMounted(async () => {
  // 若URL带有Token参数(第三方登录)
  const accessToken = route.query.token;
  // if (accessToken) await saveTokenAndInitRoutes(accessToken);
  // watch(
  //   () => themeConfig.value.isLoaded,
@@ -132,8 +129,16 @@
  // 获取验证码
  getCaptcha();
  exRole().then(res => {
    state.roleList = res.result;
    const role = route.query;
    if (role.code) {
      state.nowRole = role;
    } else {
      state.nowRole = state.roleList[0];
    }
    state.ruleForm.exRoleCode = state.nowRole.code;
  });
  // 注册验证码过期计时器
  // if (state.captchaEnabled) {
@@ -159,24 +164,33 @@
  if (!formEl) return;
  await formEl.validate(valid => {
    if (valid) {
      let obj = {
        phone: state.ruleForm.phone,
        code: state.ruleForm.phoneVCode,
        exRuleCode: state.ruleForm.exRoleCode
      };
      loading.value = true;
      useUserStoreHook()
        .loginByUsername({
          phone: state.ruleForm.phone,
          code: state.ruleForm.phoneVCode,
          exRuleCode: state.ruleForm.exRoleCode
        })
        .loginByUsername(obj)
        .then(res => {
          if (res.code == 200) {
            // 获取后端路由
            return initRouter().then(() => {
              disabled.value = true;
              router
                .replace("index")
                .then(() => {
                  message("登录成功", { type: "success" });
                })
                .finally(() => (disabled.value = false));
              console.log(res, "=-=-=-=", res.result.exRoles[0].hasFlsh);
              if (!res.result.exRoles[0].hasFlsh) {
                disabled.value = true;
                router
                  .replace({
                    name: "RegisterNav",
                    query: { code: res.result.exRoles[0].code }
                  })
                  .then(() => {
                    message("登录成功", { type: "success" });
                  })
                  .finally(() => (disabled.value = false));
              } else {
                router.replace("welcome");
              }
            });
          } else {
            message(res?.message || "登录失败", { type: "error" });
@@ -224,16 +238,16 @@
      <img width="400px" :src="logo1" class="logo1" />
    </div>
    <!-- <img :src="bg" class="wave" /> -->
    <div class="flex-c absolute right-5 top-3">
      <!-- 主题 -->
      <el-switch
    <!-- <div class="flex-c absolute right-5 top-3"> -->
    <!-- 主题 -->
    <!-- <el-switch
        v-model="dataTheme"
        inline-prompt
        :active-icon="dayIcon"
        :inactive-icon="darkIcon"
        @change="dataThemeChange"
      />
    </div>
    </div> -->
    <div class="login-container">
      <div class="img">
        <!-- <component :is="toRaw(illustration)" /> -->
@@ -242,7 +256,7 @@
        <div class="login-form">
          <!-- <avatar class="avatar" /> -->
          <Motion>
            <h2 class="outline-hidden">{{ title }}</h2>
            <h2 class="logintitle">{{ state.nowRole.name }}登录</h2>
          </Motion>
          <el-form
@@ -251,7 +265,7 @@
            :rules="loginRules"
            size="large"
          >
            <Motion :delay="150">
            <!-- <Motion :delay="150">
              <el-form-item prop="exRoleCode">
                <el-radio-group v-model="state.ruleForm.exRoleCode">
                  <el-radio
@@ -262,7 +276,7 @@
                  >
                </el-radio-group>
              </el-form-item>
            </Motion>
            </Motion> -->
            <Motion :delay="100">
              <el-form-item
                :rules="[
@@ -382,4 +396,44 @@
#suffix-span {
  cursor: pointer;
}
.login-content-code {
  display: flex;
  align-items: center;
  justify-content: space-around;
  position: relative;
  .login-content-code-img {
    width: 100%;
    height: 40px;
    line-height: 40px;
    background-color: #ffffff;
    // /* border: 1px solid rgb(220, 223, 230); */
    cursor: pointer;
    transition: all ease 0.2s;
    border-radius: 4px;
    user-select: none;
    &:hover {
      border-color: #c0c4cc;
      transition: all ease 0.2s;
    }
  }
}
.login-content-code-expired {
  @extend .login-content-code;
  &::before {
    content: "验证码已过期";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border-radius: 4px;
    background-color: rgba(0, 0, 0, 0.5);
    color: #ffffff;
    text-align: center;
    line-height: 40px;
  }
}
</style>