feat(auth): implement OTP login flow with toast notifications

feat(content): enhance detail view with dynamic content and comments
feat(order): add polling for payment status in the payment view
feat(user): update dashboard to display wallet and recent orders
feat(user): improve orders view with dynamic order fetching and status mapping
feat(api): create API modules for auth, content, order, user, and common functionalities
refactor(request): implement a centralized request utility for API calls
This commit is contained in:
2025-12-30 21:15:13 +08:00
parent 179b6aa0e2
commit cf29a2bf1a
14 changed files with 400 additions and 310 deletions

View File

@@ -1,3 +1,43 @@
<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
import { useToast } from 'primevue/usetoast';
import Toast from 'primevue/toast';
import { authApi } from '../../api/auth';
const router = useRouter();
const toast = useToast();
const step = ref(1);
const phone = ref('');
const otpCode = ref('');
const agreed = ref(false);
const getOTP = async () => {
if(!agreed.value) return;
try {
await authApi.sendOTP(phone.value);
step.value = 2;
toast.add({ severity: 'success', summary: '发送成功', detail: '验证码已发送', life: 3000 });
} catch (e) {
toast.add({ severity: 'error', summary: '错误', detail: e.message, life: 3000 });
}
};
const login = async () => {
try {
const res = await authApi.login(phone.value, otpCode.value);
localStorage.setItem('token', res.token);
localStorage.setItem('user', JSON.stringify(res.user));
toast.add({ severity: 'success', summary: '登录成功', detail: '欢迎回来', life: 1000 });
setTimeout(() => {
router.push('/');
}, 1000);
} catch (e) {
toast.add({ severity: 'error', summary: '登录失败', detail: e.message, life: 3000 });
}
};
</script>
<template>
<div class="bg-white rounded-2xl shadow-xl w-full max-w-4xl overflow-hidden flex min-h-[550px]">
<!-- Left Brand Area -->
@@ -97,33 +137,6 @@
</button>
</div>
</div>
<Toast />
</div>
</template>
<script setup>
import { ref } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter();
const step = ref(1);
const phone = ref('');
const otpCode = ref('');
const agreed = ref(false);
const getOTP = () => {
if(!agreed.value) return;
// Simulate API call
setTimeout(() => {
step.value = 2;
}, 500);
};
const login = () => {
// Simulate Login
if (otpCode.value.length >= 4) {
setTimeout(() => {
router.push('/');
}, 800);
}
};
</script>
</template>