|
@@ -1,41 +1,42 @@
|
|
|
<template>
|
|
|
- <el-form ref="formRef" :model="state.ruleForm" size="large" class="login-content-form">
|
|
|
- <el-form-item class="login-animation1" prop="userName" :rules="[{ required: true, message: '请输入用户名', trigger: ['blur', 'change'] }]">
|
|
|
- <el-input
|
|
|
- text
|
|
|
- :placeholder="$t('message.account.accountPlaceholder1')"
|
|
|
- v-model="state.ruleForm.userName"
|
|
|
- clearable
|
|
|
- autocomplete="off"
|
|
|
- @keyup.enter="onSignIn"
|
|
|
- >
|
|
|
- <template #prefix>
|
|
|
- <el-icon class="el-input__icon"><ele-User /></el-icon>
|
|
|
- </template>
|
|
|
- </el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item class="login-animation2" prop="password" :rules="[{ required: true, message: '请输入密码', trigger: ['blur', 'change'] }]">
|
|
|
- <el-input
|
|
|
- :type="state.isShowPassword ? 'text' : 'password'"
|
|
|
- :placeholder="$t('message.account.accountPlaceholder2')"
|
|
|
- v-model="state.ruleForm.password"
|
|
|
- autocomplete="off"
|
|
|
- @keyup.enter="onSignIn"
|
|
|
- >
|
|
|
- <template #prefix>
|
|
|
- <el-icon class="el-input__icon"><ele-Unlock /></el-icon>
|
|
|
- </template>
|
|
|
- <template #suffix>
|
|
|
- <i
|
|
|
- class="iconfont el-input__icon login-content-password"
|
|
|
- :class="state.isShowPassword ? 'icon-yincangmima' : 'icon-xianshimima'"
|
|
|
- @click="state.isShowPassword = !state.isShowPassword"
|
|
|
- >
|
|
|
- </i>
|
|
|
- </template>
|
|
|
- </el-input>
|
|
|
- </el-form-item>
|
|
|
- <!-- <el-form-item class="login-animation3">
|
|
|
+ <div>
|
|
|
+ <el-form ref="formRef" :model="state.ruleForm" size="large" class="login-content-form">
|
|
|
+ <el-form-item class="login-animation1" prop="userName" :rules="[{ required: true, message: '请输入用户名', trigger: ['blur', 'change'] }]">
|
|
|
+ <el-input
|
|
|
+ text
|
|
|
+ :placeholder="$t('message.account.accountPlaceholder1')"
|
|
|
+ v-model="state.ruleForm.userName"
|
|
|
+ clearable
|
|
|
+ autocomplete="off"
|
|
|
+ @keyup.enter="onSignIn"
|
|
|
+ >
|
|
|
+ <template #prefix>
|
|
|
+ <el-icon class="el-input__icon"><ele-User /></el-icon>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item class="login-animation2" prop="password" :rules="[{ required: true, message: '请输入密码', trigger: ['blur', 'change'] }]">
|
|
|
+ <el-input
|
|
|
+ :type="state.isShowPassword ? 'text' : 'password'"
|
|
|
+ :placeholder="$t('message.account.accountPlaceholder2')"
|
|
|
+ v-model="state.ruleForm.password"
|
|
|
+ autocomplete="off"
|
|
|
+ @keyup.enter="onSignIn"
|
|
|
+ >
|
|
|
+ <template #prefix>
|
|
|
+ <el-icon class="el-input__icon"><ele-Unlock /></el-icon>
|
|
|
+ </template>
|
|
|
+ <template #suffix>
|
|
|
+ <i
|
|
|
+ class="iconfont el-input__icon login-content-password"
|
|
|
+ :class="state.isShowPassword ? 'icon-yincangmima' : 'icon-xianshimima'"
|
|
|
+ @click="state.isShowPassword = !state.isShowPassword"
|
|
|
+ >
|
|
|
+ </i>
|
|
|
+ </template>
|
|
|
+ </el-input>
|
|
|
+ </el-form-item>
|
|
|
+ <!-- <el-form-item class="login-animation3">
|
|
|
<el-col :span="15">
|
|
|
<el-input
|
|
|
text
|
|
@@ -55,16 +56,26 @@
|
|
|
<el-button class="login-content-code" v-waves>1234</el-button>
|
|
|
</el-col>
|
|
|
</el-form-item> -->
|
|
|
- <el-form-item class="login-animation4">
|
|
|
- <el-button type="primary" class="login-content-submit" round v-waves @click="onSignIn" :loading="state.loading.signIn">
|
|
|
- <span>{{ $t('message.account.accountBtnText') }}</span>
|
|
|
- </el-button>
|
|
|
- </el-form-item>
|
|
|
- </el-form>
|
|
|
+ <el-form-item class="login-animation4">
|
|
|
+ <el-button
|
|
|
+ type="primary"
|
|
|
+ class="login-content-submit"
|
|
|
+ round
|
|
|
+ v-waves
|
|
|
+ @click="onSignIn"
|
|
|
+ :disabled="state.disabled.signIn"
|
|
|
+ :loading="state.loading.signIn"
|
|
|
+ >
|
|
|
+ <span>{{ $t('message.account.accountBtnText') }}</span>
|
|
|
+ </el-button>
|
|
|
+ </el-form-item>
|
|
|
+ </el-form>
|
|
|
+ <MyCaptchaDialog ref="myCaptchaDialogRef" v-model="state.showDialog" @ok="onOk" />
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script setup lang="ts" name="loginAccount">
|
|
|
-import { reactive, computed, ref } from 'vue'
|
|
|
+import { reactive, computed, ref, defineAsyncComponent } from 'vue'
|
|
|
import { useRoute, useRouter } from 'vue-router'
|
|
|
import { ElMessage } from 'element-plus'
|
|
|
import { useI18n } from 'vue-i18n'
|
|
@@ -80,6 +91,8 @@ import { AuthApi } from '/@/api/admin/Auth'
|
|
|
import { AuthLoginInput } from '/@/api/admin/data-contracts'
|
|
|
import { useUserInfo } from '/@/stores/userInfo'
|
|
|
|
|
|
+const MyCaptchaDialog = defineAsyncComponent(() => import('/@/components/my-captcha/dialog.vue'))
|
|
|
+
|
|
|
// 定义变量内容
|
|
|
const { t } = useI18n()
|
|
|
// const storesThemeConfig = useThemeConfig()
|
|
@@ -88,41 +101,74 @@ const route = useRoute()
|
|
|
const router = useRouter()
|
|
|
const formRef = ref()
|
|
|
const state = reactive({
|
|
|
+ showDialog: false,
|
|
|
isShowPassword: false,
|
|
|
ruleForm: {
|
|
|
userName: 'admin',
|
|
|
password: '111111',
|
|
|
- //code: '1234',
|
|
|
+ captchaId: '',
|
|
|
+ captchaData: '',
|
|
|
} as AuthLoginInput,
|
|
|
loading: {
|
|
|
signIn: false,
|
|
|
},
|
|
|
+ disabled: {
|
|
|
+ signIn: false,
|
|
|
+ },
|
|
|
})
|
|
|
|
|
|
// 时间获取
|
|
|
const currentTime = computed(() => {
|
|
|
return formatAxis(new Date())
|
|
|
})
|
|
|
-// 登录
|
|
|
+
|
|
|
+//验证通过
|
|
|
+const onOk = (data: any) => {
|
|
|
+ state.showDialog = false
|
|
|
+ //开始登录
|
|
|
+ state.ruleForm.captchaId = data.captchaId
|
|
|
+ state.ruleForm.captchaData = JSON.stringify(data.captchaData)
|
|
|
+ login()
|
|
|
+}
|
|
|
+
|
|
|
+//登录
|
|
|
+const login = async () => {
|
|
|
+ state.loading.signIn = true
|
|
|
+ const res = await new AuthApi().login(state.ruleForm).catch(() => {
|
|
|
+ state.loading.signIn = false
|
|
|
+ })
|
|
|
+ if (!res?.success) {
|
|
|
+ state.loading.signIn = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ const token = res.data?.token
|
|
|
+ useUserInfo().setToken(token)
|
|
|
+ // 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
|
|
+ const isNoPower = await initBackEndControlRoutes()
|
|
|
+ // 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
|
|
+ signInSuccess(isNoPower)
|
|
|
+}
|
|
|
+
|
|
|
+// 点击登录
|
|
|
const onSignIn = async () => {
|
|
|
formRef.value.validate(async (valid: boolean) => {
|
|
|
if (!valid) return
|
|
|
|
|
|
- state.loading.signIn = true
|
|
|
- const res = await new AuthApi().login(state.ruleForm).catch(() => {
|
|
|
- state.loading.signIn = false
|
|
|
- })
|
|
|
- if (!res?.success) {
|
|
|
- state.loading.signIn = false
|
|
|
- return
|
|
|
- }
|
|
|
+ //检查是否开启验证码登录
|
|
|
+ state.disabled.signIn = true
|
|
|
+ const res = await new AuthApi()
|
|
|
+ .isCaptcha()
|
|
|
+ .catch(() => {})
|
|
|
+ .finally(() => {
|
|
|
+ state.disabled.signIn = false
|
|
|
+ })
|
|
|
|
|
|
- const token = res.data?.token
|
|
|
- useUserInfo().setToken(token)
|
|
|
- // 添加完动态路由,再进行 router 跳转,否则可能报错 No match found for location with path "/"
|
|
|
- const isNoPower = await initBackEndControlRoutes()
|
|
|
- // 执行完 initBackEndControlRoutes,再执行 signInSuccess
|
|
|
- signInSuccess(isNoPower)
|
|
|
+ if (res?.success && res.data) {
|
|
|
+ state.showDialog = true
|
|
|
+ } else {
|
|
|
+ login()
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
// 登录成功后的跳转
|