|
@@ -19,7 +19,7 @@
|
|
|
<el-form ref="passwordFormRef" :model="passwordForm" :rules="passwordRules" label-width="0">
|
|
<el-form ref="passwordFormRef" :model="passwordForm" :rules="passwordRules" label-width="0">
|
|
|
<el-form-item prop="username" class="login-form-item">
|
|
<el-form-item prop="username" class="login-form-item">
|
|
|
<el-input
|
|
<el-input
|
|
|
- v-model="passwordForm.username"
|
|
|
|
|
|
|
+ v-model="passwordForm.account"
|
|
|
placeholder="请输入账号"
|
|
placeholder="请输入账号"
|
|
|
prefix-icon="User"
|
|
prefix-icon="User"
|
|
|
clearable
|
|
clearable
|
|
@@ -36,6 +36,20 @@
|
|
|
class="login-input"
|
|
class="login-input"
|
|
|
/>
|
|
/>
|
|
|
</el-form-item>
|
|
</el-form-item>
|
|
|
|
|
+ <!-- 增加动态验证码图片 -->
|
|
|
|
|
+ <el-form-item prop="verifyCode" class="login-form-item">
|
|
|
|
|
+ <div class="gap10">
|
|
|
|
|
+ <el-input
|
|
|
|
|
+ v-model="passwordForm.verifyCode"
|
|
|
|
|
+ placeholder="请输入验证码"
|
|
|
|
|
+ prefix-icon="Lock"
|
|
|
|
|
+ show-password
|
|
|
|
|
+ class="login-input"
|
|
|
|
|
+ />
|
|
|
|
|
+ <img :src="captchaImg" alt="验证码" class="captcha-img" @click="getCaptchaFn">
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </el-form-item>
|
|
|
|
|
+
|
|
|
<el-form-item class="login-form-item remember-item">
|
|
<el-form-item class="login-form-item remember-item">
|
|
|
<el-checkbox v-model="passwordForm.remember" class="remember-checkbox">
|
|
<el-checkbox v-model="passwordForm.remember" class="remember-checkbox">
|
|
|
<span class="remember-text">记住密码</span>
|
|
<span class="remember-text">记住密码</span>
|
|
@@ -181,42 +195,65 @@
|
|
|
</template>
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
|
<script setup>
|
|
|
-import { ref, reactive, watch } from 'vue'
|
|
|
|
|
|
|
+import { ref, reactive, watch, computed } from 'vue'
|
|
|
import { ElMessage } from 'element-plus'
|
|
import { ElMessage } from 'element-plus'
|
|
|
import QQIcon from '@/assets/imgs/QQ.png'
|
|
import QQIcon from '@/assets/imgs/QQ.png'
|
|
|
import WeChatIcon from '@/assets/imgs/WeChat.png'
|
|
import WeChatIcon from '@/assets/imgs/WeChat.png'
|
|
|
|
|
+import { getCaptcha, loginUsername } from '@/api/auth.js'
|
|
|
|
|
+// 正则表达式
|
|
|
|
|
+const PHONE_REGEX = /^1[3-9]\d{9}$/;
|
|
|
|
|
+const EMAIL_REGEX = /^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$/;
|
|
|
|
|
+const isPasswordPhone = computed(() => {
|
|
|
|
|
+ return PHONE_REGEX.test(passwordForm.account);
|
|
|
|
|
+});
|
|
|
|
|
+
|
|
|
|
|
+const isPasswordEmail = computed(() => {
|
|
|
|
|
+ return EMAIL_REGEX.test(passwordForm.account);
|
|
|
|
|
+});
|
|
|
|
|
|
|
|
-// 定义props和emit
|
|
|
|
|
-const props = defineProps({
|
|
|
|
|
- modelValue: {
|
|
|
|
|
- type: Boolean,
|
|
|
|
|
- default: false
|
|
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
|
|
|
|
|
-const emit = defineEmits(['update:modelValue', 'login-success'])
|
|
|
|
|
|
|
+const emit = defineEmits(['login-success'])
|
|
|
|
|
|
|
|
// 对话框可见性
|
|
// 对话框可见性
|
|
|
-const dialogVisible = ref(props.modelValue)
|
|
|
|
|
|
|
+const dialogVisible = ref(true)
|
|
|
|
|
+// 验证码图片
|
|
|
|
|
+const captchaImg = ref('')
|
|
|
|
|
|
|
|
-// 监听对话框可见性变化
|
|
|
|
|
-watch(() => dialogVisible.value, (newVal) => {
|
|
|
|
|
- emit('update:modelValue', newVal)
|
|
|
|
|
-})
|
|
|
|
|
|
|
|
|
|
-// 监听props变化
|
|
|
|
|
-watch(() => props.modelValue, (newVal) => {
|
|
|
|
|
- dialogVisible.value = newVal
|
|
|
|
|
-})
|
|
|
|
|
|
|
+const open = () => {
|
|
|
|
|
+ dialogVisible.value = true;
|
|
|
|
|
+ getCaptchaFn()
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+const getCaptchaFn = async (type) => {
|
|
|
|
|
+ try {
|
|
|
|
|
+ const res = await getCaptcha()
|
|
|
|
|
+ passwordForm.uuid = res.data?.uuid;
|
|
|
|
|
+ if (res.data?.img.startsWith('data:image')) {
|
|
|
|
|
+ captchaImg.value = res.data?.img;
|
|
|
|
|
+ } else {
|
|
|
|
|
+ captchaImg.value = 'data:image/jpeg;base64,' + res.data?.img;
|
|
|
|
|
+ }
|
|
|
|
|
+ console.log(res)
|
|
|
|
|
+ // if (res.code === 200) {
|
|
|
|
|
+ // ElMessage.success('验证码获取成功')
|
|
|
|
|
+ // } else {
|
|
|
|
|
+ // ElMessage.error(res.msg || '验证码获取失败')
|
|
|
|
|
+ // }
|
|
|
|
|
+ } catch (error) {
|
|
|
|
|
+ ElMessage.error(error.message || '验证码获取失败')
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
// 当前激活的标签页
|
|
// 当前激活的标签页
|
|
|
const activeTab = ref('password')
|
|
const activeTab = ref('password')
|
|
|
|
|
|
|
|
// 密码登录表单
|
|
// 密码登录表单
|
|
|
const passwordForm = reactive({
|
|
const passwordForm = reactive({
|
|
|
- username: '',
|
|
|
|
|
|
|
+ account: '',
|
|
|
password: '',
|
|
password: '',
|
|
|
- remember: false
|
|
|
|
|
|
|
+ captcha: '',
|
|
|
|
|
+ uuid: ''
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
// 短信登录表单
|
|
// 短信登录表单
|
|
@@ -245,7 +282,7 @@ const emailCountdown = ref(0)
|
|
|
|
|
|
|
|
// 表单验证规则
|
|
// 表单验证规则
|
|
|
const passwordRules = reactive({
|
|
const passwordRules = reactive({
|
|
|
- username: [
|
|
|
|
|
|
|
+ account: [
|
|
|
{ required: true, message: '请输入账号', trigger: 'blur' }
|
|
{ required: true, message: '请输入账号', trigger: 'blur' }
|
|
|
],
|
|
],
|
|
|
password: [
|
|
password: [
|
|
@@ -337,16 +374,29 @@ const sendEmailCode = () => {
|
|
|
|
|
|
|
|
// 密码登录
|
|
// 密码登录
|
|
|
const handlePasswordLogin = () => {
|
|
const handlePasswordLogin = () => {
|
|
|
- passwordFormRef.value?.validate((valid) => {
|
|
|
|
|
|
|
+ passwordFormRef.value?.validate(async (valid) => {
|
|
|
if (valid) {
|
|
if (valid) {
|
|
|
loading.value = true
|
|
loading.value = true
|
|
|
- // 模拟登录请求
|
|
|
|
|
- setTimeout(() => {
|
|
|
|
|
- loading.value = false
|
|
|
|
|
|
|
+ const params = new URLSearchParams();
|
|
|
|
|
+ // 根据账号类型决定参数名
|
|
|
|
|
+ if (isPasswordPhone.value) {
|
|
|
|
|
+ params.append('phone', passwordForm.account);
|
|
|
|
|
+ } else if (isPasswordEmail.value) {
|
|
|
|
|
+ params.append('email', passwordForm.account);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ params.append('password', passwordForm.password);
|
|
|
|
|
+ params.append('captcha', passwordForm.captcha);
|
|
|
|
|
+ params.append('uuid', passwordForm.uuid);
|
|
|
|
|
+ const res = await loginUsername(params);
|
|
|
|
|
+ loading.value = false
|
|
|
|
|
+ if (res.code === 200) {
|
|
|
ElMessage.success('登录成功')
|
|
ElMessage.success('登录成功')
|
|
|
- emit('login-success', { type: 'password', userInfo: passwordForm })
|
|
|
|
|
|
|
+ // emit('login-success', { type: 'password', userInfo: passwordForm })
|
|
|
dialogVisible.value = false
|
|
dialogVisible.value = false
|
|
|
- }, 1500)
|
|
|
|
|
|
|
+ } else {
|
|
|
|
|
+ ElMessage.error(res.msg || '登录失败')
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
}
|
|
}
|
|
@@ -392,6 +442,10 @@ const handleWechatLogin = () => {
|
|
|
const handleQqLogin = () => {
|
|
const handleQqLogin = () => {
|
|
|
ElMessage.info('QQ登录功能开发中')
|
|
ElMessage.info('QQ登录功能开发中')
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+defineExpose({
|
|
|
|
|
+ open
|
|
|
|
|
+})
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
<style scoped lang="scss">
|