yangyin
2024-11-12 e30bb3208315331271a1ea8c2cd13259c30639c5
src/views/login/component/mobile.vue
@@ -24,9 +24,7 @@
         </el-col>
         <el-col :span="1"></el-col>
         <el-col :span="8">
            <el-button v-waves class="login-content-code" @click="sendSMS" :disabled="state.ruleForm.countNum > 0">{{
               state.ruleForm.countNum > 0 ? `${state.ruleForm.countNum}秒后重试` : '获取验证码'
            }}</el-button>
            <el-button v-waves class="login-content-code" @click="sendSMS" :disabled="hasSended">{{ sendCodeMsg }}</el-button>
         </el-col>
      </el-form-item>
      <el-form-item class="login-animation3">
@@ -40,10 +38,11 @@
<script setup lang="ts" name="loginMobile">
import { FormInstance, FormRules } from 'element-plus';
import { reactive, ref } from 'vue';
import { computed, reactive, ref } from 'vue';
import { PostPhoneLogin, loginVerifyMessage } from '/@/api/ai/user';
import { accessSessionKey } from '/@/utils/request';
import { Local } from '/@/utils/storage';
import { formatAxis } from '/@/utils/formatTime';
const emit = defineEmits(['login']);
// 定义变量内容
const state = reactive({
   ruleForm: {
@@ -60,6 +59,13 @@
      { required: true, message: '请输入手机号码', trigger: 'blur' },
      { pattern: /^1\d{10}$/, message: '请输入正确的手机号码', trigger: 'blur' },
   ],
});
const hasSended = computed(() => {
   return state.ruleForm.countNum !== null;
});
const sendCodeMsg = computed(() => {
   return !hasSended.value ? '获取验证码' : `${state.ruleForm.countNum} 秒后重试`;
});
function stopCount() {
   state.ruleForm.countNum = null;
@@ -96,11 +102,16 @@
      },
      {
         noAuth: true,
         loading: false,
      }
   );
   startCount();
};
const currentTime = computed(() => {
   return formatAxis(new Date());
});
const LOGIN_CLIENT = '后台管理';
// 登录
const onSignIn = async () => {
@@ -116,36 +127,9 @@
         loading: false,
      });
      Local.set(accessSessionKey, res.hswatersession);
      return
      await useUserInfo().setUserInfos({
         userName: ruleForm.value.account,
         phoneNumber: '',
         photo: profileMan,
      }); //缓存用户信息
      state.loading.signIn = true;
      if (!themeConfig.value.isRequestRoutes) {
         // 前端控制路由,2、请注意执行顺序
         const isNoPower = await initFrontEndControlRoutes();
         // console.log(isNoPower,172)
         signInSuccess(isNoPower);
      } else {
         // 模拟后端控制路由,isRequestRoutes 为 true,则开启后端控制路由
         // 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
         const isNoPower = await initBackEndControlRoutes();
         // 执行完 initBackEndControlRoutes,再执行 signInSuccess
         // console.log(isNoPower,178)
         signInSuccess(isNoPower);
      }
      // 登录校验
      // await apiSysAuthLoginPost(params)
      //    .then(async (res: any) => {
      //    })
      //    .catch((err: any) => {
      //       console.log(err);
      //    });
      // state.loading.signIn = true;
      await emit('login', res, currentTime.value);
      // state.loading.signIn = false;
   });
};
</script>