增加前端格式检查配置
This commit is contained in:
@@ -1,79 +1,78 @@
|
||||
<script setup lang="ts">
|
||||
import { ElMessage } from "element-plus";
|
||||
import { ChatLineRound, Iphone } from "@element-plus/icons-vue";
|
||||
import { onUnmounted, reactive, ref } from "vue";
|
||||
import { useRouter } from "vue-router";
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { ChatLineRound, Iphone } from '@element-plus/icons-vue'
|
||||
import { onUnmounted, reactive, ref } from 'vue'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import { sendSmsCode } from "@/features/auth/api/auth";
|
||||
import { useSessionStore } from "@/stores/session";
|
||||
import { sendSmsCode } from '@/features/auth/api/auth'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
|
||||
const router = useRouter();
|
||||
const session = useSessionStore();
|
||||
const loading = ref(false);
|
||||
const sending = ref(false);
|
||||
const countDown = ref(0);
|
||||
const router = useRouter()
|
||||
const session = useSessionStore()
|
||||
const loading = ref(false)
|
||||
const sending = ref(false)
|
||||
const countDown = ref(0)
|
||||
const form = reactive({
|
||||
phone: "",
|
||||
code: "",
|
||||
});
|
||||
phone: '',
|
||||
code: '',
|
||||
})
|
||||
|
||||
let timer: ReturnType<typeof setInterval> | null = null;
|
||||
let timer: ReturnType<typeof setInterval> | null = null
|
||||
|
||||
function startCountDown() {
|
||||
countDown.value = 60;
|
||||
countDown.value = 60
|
||||
timer = setInterval(() => {
|
||||
countDown.value--;
|
||||
countDown.value--
|
||||
if (countDown.value <= 0) {
|
||||
clearInterval(timer!);
|
||||
timer = null;
|
||||
clearInterval(timer!)
|
||||
timer = null
|
||||
}
|
||||
}, 1000);
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
onUnmounted(() => {
|
||||
if (timer) {
|
||||
clearInterval(timer);
|
||||
timer = null;
|
||||
clearInterval(timer)
|
||||
timer = null
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
async function handleSendCode() {
|
||||
if (!form.phone.trim()) {
|
||||
ElMessage.warning("请输入手机号");
|
||||
return;
|
||||
ElMessage.warning('请输入手机号')
|
||||
return
|
||||
}
|
||||
sending.value = true;
|
||||
sending.value = true
|
||||
try {
|
||||
await sendSmsCode(form.phone);
|
||||
ElMessage.success("验证码已发送,请注意查收");
|
||||
startCountDown();
|
||||
await sendSmsCode(form.phone)
|
||||
ElMessage.success('验证码已发送,请注意查收')
|
||||
startCountDown()
|
||||
} catch (error) {
|
||||
ElMessage.error(readError(error, "验证码发送失败"));
|
||||
ElMessage.error(readError(error, '验证码发送失败'))
|
||||
} finally {
|
||||
sending.value = false;
|
||||
sending.value = false
|
||||
}
|
||||
}
|
||||
|
||||
async function handleLogin() {
|
||||
loading.value = true;
|
||||
loading.value = true
|
||||
try {
|
||||
await session.login(form.phone, form.code);
|
||||
ElMessage.success("登录成功");
|
||||
await router.push("/");
|
||||
await session.login(form.phone, form.code)
|
||||
ElMessage.success('登录成功')
|
||||
await router.push('/')
|
||||
} catch (error) {
|
||||
ElMessage.error(readError(error, "登录失败"));
|
||||
ElMessage.error(readError(error, '登录失败'))
|
||||
} finally {
|
||||
loading.value = false;
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function readError(error: unknown, fallback: string) {
|
||||
if (typeof error === "object" && error && "response" in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } })
|
||||
.response;
|
||||
return response?.data?.message || fallback;
|
||||
if (typeof error === 'object' && error && 'response' in error) {
|
||||
const response = (error as { response?: { data?: { message?: string } } }).response
|
||||
return response?.data?.message || fallback
|
||||
}
|
||||
return fallback;
|
||||
return fallback
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -131,13 +130,7 @@ function readError(error: unknown, fallback: string) {
|
||||
:loading="sending"
|
||||
@click="handleSendCode"
|
||||
>
|
||||
{{
|
||||
countDown > 0
|
||||
? `${countDown}s`
|
||||
: sending
|
||||
? "发送中"
|
||||
: "发送验证码"
|
||||
}}
|
||||
{{ countDown > 0 ? `${countDown}s` : sending ? '发送中' : '发送验证码' }}
|
||||
</el-button>
|
||||
</div>
|
||||
</el-form-item>
|
||||
@@ -179,7 +172,8 @@ function readError(error: unknown, fallback: string) {
|
||||
border-radius: 20px;
|
||||
background: rgba(255, 255, 255, 0.65);
|
||||
backdrop-filter: blur(20px);
|
||||
box-shadow: 0 24px 80px rgba(17, 24, 39, 0.08),
|
||||
box-shadow:
|
||||
0 24px 80px rgba(17, 24, 39, 0.08),
|
||||
0 1px 0 rgba(255, 255, 255, 0.6) inset;
|
||||
overflow: hidden;
|
||||
}
|
||||
@@ -190,16 +184,9 @@ function readError(error: unknown, fallback: string) {
|
||||
flex-direction: column;
|
||||
justify-content: space-between;
|
||||
padding: 40px 36px;
|
||||
background: radial-gradient(
|
||||
circle at 30% 20%,
|
||||
rgba(20, 119, 255, 0.08),
|
||||
transparent 50%
|
||||
),
|
||||
radial-gradient(
|
||||
circle at 80% 90%,
|
||||
rgba(109, 40, 217, 0.06),
|
||||
transparent 50%
|
||||
),
|
||||
background:
|
||||
radial-gradient(circle at 30% 20%, rgba(20, 119, 255, 0.08), transparent 50%),
|
||||
radial-gradient(circle at 80% 90%, rgba(109, 40, 217, 0.06), transparent 50%),
|
||||
linear-gradient(160deg, rgba(20, 119, 255, 0.06), rgba(109, 40, 217, 0.03));
|
||||
}
|
||||
|
||||
@@ -298,14 +285,17 @@ function readError(error: unknown, fallback: string) {
|
||||
box-shadow: 0 0 0 1px #e2e8f0 inset;
|
||||
border-radius: 10px;
|
||||
padding: 0 12px;
|
||||
transition: box-shadow 0.2s, background 0.2s;
|
||||
transition:
|
||||
box-shadow 0.2s,
|
||||
background 0.2s;
|
||||
}
|
||||
.user-form :deep(.el-input__wrapper:hover) {
|
||||
background: #ffffff;
|
||||
}
|
||||
.user-form :deep(.el-input__wrapper.is-focus) {
|
||||
background: #ffffff;
|
||||
box-shadow: 0 0 0 1px rgba(20, 119, 255, 0.45) inset,
|
||||
box-shadow:
|
||||
0 0 0 1px rgba(20, 119, 255, 0.45) inset,
|
||||
0 0 0 3px rgba(20, 119, 255, 0.08);
|
||||
}
|
||||
.user-form :deep(.el-input__inner) {
|
||||
@@ -337,7 +327,9 @@ function readError(error: unknown, fallback: string) {
|
||||
border-color: #1477ff;
|
||||
color: #1477ff;
|
||||
box-shadow: none;
|
||||
transition: background 0.2s, color 0.2s;
|
||||
transition:
|
||||
background 0.2s,
|
||||
color 0.2s;
|
||||
}
|
||||
.user-code-row .el-button:hover:not(:disabled) {
|
||||
background: #1477ff;
|
||||
@@ -360,7 +352,9 @@ function readError(error: unknown, fallback: string) {
|
||||
background: linear-gradient(135deg, #1477ff, #2f8dff);
|
||||
border: none;
|
||||
box-shadow: 0 10px 28px rgba(20, 119, 255, 0.22);
|
||||
transition: transform 0.15s, box-shadow 0.2s;
|
||||
transition:
|
||||
transform 0.15s,
|
||||
box-shadow 0.2s;
|
||||
}
|
||||
.user-login-btn:hover {
|
||||
transform: translateY(-1px);
|
||||
|
||||
Reference in New Issue
Block a user