feat: P2阶段完成 - listings和auth模块迁移

## P2.1: 商品浏览模块(listings)

### 完整迁移(23个文件)
- API: listings.ts, listingOptions.ts, homeConfig.ts
- Views: 5个页面(HomeView, ListingsView, ListingDetailView + 移动端2个)
- Composables: 3个(useHomeFilters, useFilterOptions, useListingQuery)
- Components: 9个(ListingCard, 各种过滤器组件)
- Tests: 2个测试文件

**功能:**
- 首页浏览、商品列表、详情查看
- 高级筛选(服务器、等级、哈夫币、皮肤等)
- 排序和分区功能
- 横幅、公告、统计展示

**技术改进:**
- 更新所有导入路径到 @/shared/
- 建立清晰的模块导出

---

## P2.2: 用户认证模块(auth)

### 完整迁移(12个文件)
- API: auth.ts, realname.ts, notifications.ts
- Views: 8个页面(登录、注册、个人资料、实名认证、通知 + 移动端)
- 模块导出

**功能:**
- 用户注册、登录、Token管理
- 实名认证、风险检查
- 个人资料编辑、头像上传
- 消息/通知中心

**技术改进:**
- 统一 API 导入路径
- 类型安全增强

---

## 里程碑

🎉 **P2 阶段完成!**

**累计完成:** 6个模块
-  P0: shared(基础设施)- 22个文件
-  P1: wallet, chats, orders - 24个文件
-  P2: listings, auth - 35个文件

**总计:** 81个文件已迁移

**剩余:** P3阶段(seller, disputes, admin)+ 清理工作

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
yml2213
2026-06-04 08:56:42 +08:00
co-authored by Claude Opus 4.7
parent f415832c19
commit 405abfa4f7
35 changed files with 9932 additions and 0 deletions
+56
View File
@@ -0,0 +1,56 @@
import { apiClient } from '@/shared/api/client'
import type { ApiResponse } from '@/shared/types/types'
import type { RealnameStatusValue, RiskStatus, UserStatus } from '@/types/status'
export interface AuthUser {
id: number
phone: string
nickname: string
avatar_url: string
realname_status: RealnameStatusValue
risk_status: RiskStatus
credit_score: number
status: UserStatus
}
export interface TokenPair {
access_token: string
refresh_token: string
token_type: string
expires_in: number
}
export interface LoginData {
user: AuthUser
tokens: TokenPair
}
export async function sendSmsCode(phone: string) {
const { data } = await apiClient.post<ApiResponse<{ phone: string; expires_in: number }>>('/auth/sms/send', {
phone,
})
return data.data
}
export async function loginWithSms(phone: string, code: string) {
const { data } = await apiClient.post<ApiResponse<LoginData>>('/auth/sms/login', { phone, code })
return data.data
}
export async function fetchMe() {
const { data } = await apiClient.get<ApiResponse<AuthUser>>('/me')
return data.data
}
export async function updateMe(payload: Pick<AuthUser, 'nickname' | 'avatar_url'>) {
const { data } = await apiClient.put<ApiResponse<AuthUser>>('/me', payload)
return data.data
}
/** Manually refresh user token (for store to call on app init) */
export async function refreshUserToken(refreshToken: string) {
const { data } = await apiClient.post<ApiResponse<TokenPair>>('/auth/refresh', {
refresh_token: refreshToken,
})
return data.data
}
@@ -0,0 +1,27 @@
import { apiClient } from './client'
import type { ApiResponse, PaginatedResult } from './types'
export interface NotificationItem {
id: number
user_id: number
type: string
title: string
content: string
biz_type: string
biz_id?: number
read_at?: string
created_at: string
}
export async function fetchNotifications(page = 1, pageSize = 20) {
const { data } = await apiClient.get<ApiResponse<PaginatedResult<NotificationItem>>>('/notifications', {
params: { page, page_size: pageSize },
})
return data.data
}
export async function markNotificationRead(id: number) {
const { data } = await apiClient.post<ApiResponse<{ read: boolean }>>(`/notifications/${id}/read`)
return data.data
}
@@ -0,0 +1,26 @@
import { apiClient } from '@/shared/api/client'
import type { ApiResponse } from './types'
import type { RealnameStatusValue } from '@/types/status'
export interface RealnameStatus {
status: RealnameStatusValue
provider?: string
provider_order_no?: string
masked_name?: string
masked_id_no?: string
verified_at?: string
fail_reason?: string
}
export async function startRealname(name: string, idNo: string) {
const { data } = await apiClient.post<ApiResponse<RealnameStatus>>('/realname/start', {
name,
id_no: idNo,
})
return data.data
}
export async function getRealnameStatus() {
const { data } = await apiClient.get<ApiResponse<RealnameStatus>>('/realname/status')
return data.data
}
+4
View File
@@ -0,0 +1,4 @@
// Auth 模块统一导出
export * from './api/auth'
export * from './api/realname'
export * from './api/notifications'
@@ -0,0 +1,409 @@
<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 { sendSmsCode } from "@/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 form = reactive({
phone: "",
code: "",
});
let timer: ReturnType<typeof setInterval> | null = null;
function startCountDown() {
countDown.value = 60;
timer = setInterval(() => {
countDown.value--;
if (countDown.value <= 0) {
clearInterval(timer!);
timer = null;
}
}, 1000);
}
onUnmounted(() => {
if (timer) {
clearInterval(timer);
timer = null;
}
});
async function handleSendCode() {
if (!form.phone.trim()) {
ElMessage.warning("请输入手机号");
return;
}
sending.value = true;
try {
await sendSmsCode(form.phone);
ElMessage.success("验证码已发送,请注意查收");
startCountDown();
} catch (error) {
ElMessage.error(readError(error, "验证码发送失败"));
} finally {
sending.value = false;
}
}
async function handleLogin() {
loading.value = true;
try {
await session.login(form.phone, form.code);
ElMessage.success("登录成功");
await router.push("/");
} catch (error) {
ElMessage.error(readError(error, "登录失败"));
} finally {
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;
}
return fallback;
}
</script>
<template>
<section class="login-shell">
<div class="login-card">
<div class="login-left">
<div class="brand-lockup">
<div class="brand-logo"></div>
<strong>大锤商行</strong>
</div>
<div class="login-hero">
<h2>安全租号<br />畅享游戏</h2>
<p>
高效安全的哈夫币账号交易平台<br />
7×24 小时智能订单系统随时为您服务
</p>
</div>
<div class="login-footer">
<span>© 哈夫币租号平台</span>
</div>
</div>
<div class="login-right">
<div class="login-header">
<p class="eyebrow">SMS Login</p>
<h1>欢迎回来</h1>
<p class="subtitle">登录后即可发布或租赁账号</p>
</div>
<el-form class="user-form" label-position="top" @submit.prevent>
<el-form-item label="手机号">
<el-input
v-model="form.phone"
maxlength="11"
placeholder="请输入手机号"
size="large"
:prefix-icon="Iphone"
/>
</el-form-item>
<el-form-item label="验证码">
<div class="user-code-row">
<el-input
v-model="form.code"
maxlength="6"
placeholder="6 位验证码"
size="large"
:prefix-icon="ChatLineRound"
@keyup.enter="handleLogin"
/>
<el-button
size="large"
:disabled="countDown > 0 || sending"
:loading="sending"
@click="handleSendCode"
>
{{
countDown > 0
? `${countDown}s`
: sending
? "发送中"
: "发送验证码"
}}
</el-button>
</div>
</el-form-item>
<el-button
class="user-login-btn"
type="primary"
size="large"
:loading="loading"
@click="handleLogin"
>
登录
</el-button>
<p class="login-notice">未收到验证码时请稍后重试或联系客服处理</p>
</el-form>
</div>
</div>
</section>
</template>
<style scoped>
.login-shell {
display: grid;
flex: 1;
place-items: center;
margin: -20px -24px;
padding: 32px 24px;
}
.login-card {
position: relative;
z-index: 1;
display: grid;
grid-template-columns: 1fr 420px;
width: min(940px, 100%);
min-height: 520px;
border: 1px solid rgba(255, 255, 255, 0.7);
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),
0 1px 0 rgba(255, 255, 255, 0.6) inset;
overflow: hidden;
}
/* ========== 左侧品牌区 ========== */
.login-left {
display: flex;
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%
),
linear-gradient(160deg, rgba(20, 119, 255, 0.06), rgba(109, 40, 217, 0.03));
}
.brand-lockup {
display: flex;
align-items: center;
gap: 10px;
}
.brand-logo {
display: grid;
width: 36px;
height: 36px;
place-items: center;
border-radius: 10px;
background: linear-gradient(135deg, #1477ff, #2f8dff);
box-shadow: 0 8px 24px rgba(20, 119, 255, 0.22);
color: #fff;
font-size: 15px;
font-weight: 900;
}
.brand-lockup strong {
color: #0f172a;
font-size: 15px;
font-weight: 800;
letter-spacing: 0.3px;
}
.login-hero h2 {
margin: 0 0 14px;
color: #0f172a;
font-size: 28px;
font-weight: 800;
line-height: 1.25;
}
.login-hero p {
margin: 0;
color: #475569;
font-size: 14px;
line-height: 1.7;
max-width: 300px;
}
.login-footer span {
color: #94a3b8;
font-size: 12px;
}
/* ========== 右侧表单区 ========== */
.login-right {
display: flex;
flex-direction: column;
justify-content: center;
padding: 36px 32px;
background: rgba(255, 255, 255, 0.45);
}
.login-header {
margin-bottom: 24px;
}
.login-header .eyebrow {
margin: 0 0 8px;
color: #1477ff;
font-size: 12px;
font-weight: 700;
letter-spacing: 1px;
text-transform: uppercase;
}
.login-header h1 {
margin: 0;
color: #0f172a;
font-size: 24px;
font-weight: 800;
line-height: 1.2;
}
.login-header .subtitle {
margin: 8px 0 0;
color: #64748b;
font-size: 13px;
}
.user-form :deep(.el-form-item__label) {
color: #334155;
font-size: 13px;
font-weight: 600;
padding-bottom: 6px;
}
.user-form :deep(.el-input__wrapper) {
background: #ffffff;
box-shadow: 0 0 0 1px #e2e8f0 inset;
border-radius: 10px;
padding: 0 12px;
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,
0 0 0 3px rgba(20, 119, 255, 0.08);
}
.user-form :deep(.el-input__inner) {
color: #0f172a;
font-size: 14px;
height: 44px;
}
.user-form :deep(.el-input__inner::placeholder) {
color: #94a3b8;
}
.user-form :deep(.el-input__prefix-inner) {
color: #94a3b8;
}
.user-code-row {
display: grid;
grid-template-columns: 1fr 120px;
gap: 10px;
width: 100%;
}
.user-code-row .el-button {
height: 46px;
border-radius: 10px;
font-size: 13px;
font-weight: 700;
letter-spacing: 0.3px;
background: #ffffff;
border-color: #1477ff;
color: #1477ff;
box-shadow: none;
transition: background 0.2s, color 0.2s;
}
.user-code-row .el-button:hover:not(:disabled) {
background: #1477ff;
border-color: #1477ff;
color: #ffffff;
}
.user-code-row .el-button:disabled {
opacity: 0.6;
cursor: not-allowed;
}
.user-login-btn {
width: 100%;
height: 46px;
border-radius: 10px;
font-size: 15px;
font-weight: 700;
margin-top: 8px;
letter-spacing: 0.5px;
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;
}
.user-login-btn:hover {
transform: translateY(-1px);
box-shadow: 0 14px 36px rgba(20, 119, 255, 0.28);
}
.login-notice {
margin: 18px 0 0;
color: #94a3b8;
font-size: 12px;
text-align: center;
line-height: 1.5;
}
/* ========== 响应式 ========== */
@media (max-width: 860px) {
.login-card {
grid-template-columns: 1fr;
max-width: 420px;
}
.login-left {
display: none;
}
.login-right {
padding: 32px 28px;
}
.login-shell {
padding: 24px 16px;
}
}
@media (max-width: 480px) {
.login-shell {
padding: 16px 12px;
}
.login-right {
padding: 24px 20px;
}
}
@media (prefers-reduced-motion: reduce) {
.user-login-btn {
transition: none;
}
}
</style>
@@ -0,0 +1,343 @@
<script setup lang="ts">
import { reactive, ref } from "vue";
import { RouterLink, useRoute, useRouter } from "vue-router";
import { showToast, showDialog } from "vant";
import { useSessionStore } from "@/stores/session";
import { useSmsCountdown } from "@/composables/useSmsCountdown";
const router = useRouter();
const route = useRoute();
const session = useSessionStore();
const loading = ref(false);
const agreed = ref(false);
const form = reactive({
phone: "",
code: "",
});
const { countDown, sending, handleSendCode, readError } = useSmsCountdown();
async function handleLogin() {
if (!agreed.value) {
showDialog({
title: "提示",
message: "请先阅读并同意用户协议和隐私政策",
});
return;
}
loading.value = true;
try {
await session.login(form.phone, form.code);
const redirect = typeof route.query.redirect === "string" ? route.query.redirect : "/m/profile";
await router.replace(redirect);
} catch {
showToast({ message: "登录失败,请检查手机号和验证码", icon: "cross" });
} finally {
loading.value = false;
}
}
</script>
<template>
<main class="mobile-login-shell">
<header class="page-header">
<button class="back-btn" type="button" @click="router.back()">
<van-icon name="arrow-left" :size="20" />
</button>
</header>
<section class="auth-body">
<div class="brand-lockup">
<div class="brand-logo"></div>
<strong>大锤商行</strong>
</div>
<div class="form-section">
<h1>登录</h1>
<label class="auth-input-row">
<input
v-model="form.phone"
type="tel"
maxlength="11"
placeholder="手机号"
/>
</label>
<label class="auth-input-row code-row">
<input
v-model="form.code"
type="text"
inputmode="numeric"
maxlength="6"
placeholder="验证码"
/>
<span class="code-action">
<van-button
size="small"
plain
:disabled="sending || countDown > 0"
:loading="sending"
class="code-btn"
@click="handleSendCode(form.phone)"
>
{{
countDown > 0
? `${countDown}s`
: sending
? "发送中"
: "发送验证码"
}}
</van-button>
</span>
</label>
<div class="assist-row">
<span>验证码登录</span>
<RouterLink to="/m/register">没有账号<b>立即注册</b></RouterLink>
</div>
<div class="agreement-row">
<van-checkbox v-model="agreed" shape="square" icon-size="16px">
我已阅读并同意<b>用户协议</b><b>隐私政策</b>
</van-checkbox>
</div>
<van-button
type="primary"
block
class="primary-button"
:loading="loading"
loading-text="登录中..."
@click="handleLogin"
>
登录
</van-button>
<RouterLink to="/m/register" class="secondary-entry">
还没有账号创建一个
</RouterLink>
</div>
</section>
</main>
</template>
<style scoped>
.mobile-login-shell {
min-height: 100dvh;
background:
radial-gradient(circle at 50% 12%, rgba(20, 119, 255, 0.1), transparent 34%),
linear-gradient(180deg, #f8fbff 0%, #ffffff 70%, #f7fafc 100%);
color: #111827;
}
.page-header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10;
display: flex;
align-items: center;
height: 48px;
margin: 0;
padding: 0 18px;
background: transparent;
}
.back-btn {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border: none;
border-radius: 999px;
background: none;
color: #111827;
}
.auth-body {
box-sizing: border-box;
display: flex;
min-height: 100dvh;
flex-direction: column;
justify-content: center;
padding: 54px 34px 28px;
}
.brand-lockup {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
margin: 0 auto clamp(34px, 6vh, 54px);
}
.brand-logo {
display: grid;
width: 46px;
height: 46px;
place-items: center;
border-radius: 14px;
background: linear-gradient(135deg, #1477ff, #2f8dff);
box-shadow: 0 14px 32px rgba(20, 119, 255, 0.18);
color: #ffffff;
font-size: 19px;
font-weight: 900;
}
.brand-lockup strong {
display: block;
color: #111827;
font-size: 18px;
font-weight: 900;
letter-spacing: 0;
}
.form-section {
width: min(100%, 420px);
margin: 0 auto;
}
.form-section h1 {
margin: 0 0 22px;
color: #05070a;
font-size: 22px;
font-weight: 900;
line-height: 1.2;
}
.auth-input-row {
display: flex;
align-items: center;
min-height: 48px;
margin-bottom: 10px;
padding: 0 16px;
border: 1px solid #e1e5eb;
border-radius: 10px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.03);
}
.auth-input-row.code-row {
gap: 8px;
}
.auth-input-row input {
width: 100%;
min-width: 0;
border: none;
background: transparent;
color: #0f172a;
font-size: 16px;
outline: none;
}
.auth-input-row input::placeholder {
color: #b6beca;
}
.code-action {
display: flex;
justify-content: flex-end;
}
.code-btn {
min-width: 82px;
height: 32px;
border-color: #1477ff !important;
border-radius: 8px;
color: #1477ff !important;
font-weight: 700;
}
.assist-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin: 14px 0 24px;
color: #111827;
font-size: 13px;
}
.assist-row span {
min-width: 0;
color: #1477ff;
}
.assist-row a {
flex-shrink: 0;
color: #22252b;
text-decoration: none;
}
.assist-row b {
color: #05070a;
font-weight: 900;
}
.agreement-row {
display: flex;
align-items: center;
margin: 0 0 20px;
}
.agreement-row :deep(.van-checkbox__label) {
margin-left: 8px;
color: #252b36;
font-size: 12px;
line-height: 1.4;
}
.agreement-row :deep(.van-checkbox__label b) {
color: #1477ff;
font-weight: 700;
}
.primary-button {
height: 48px;
border: none !important;
border-radius: 10px !important;
background: #1477ff !important;
box-shadow: 0 12px 24px rgba(20, 119, 255, 0.18);
font-size: 17px;
font-weight: 900;
}
.secondary-entry {
display: grid;
min-height: 46px;
margin-top: 12px;
place-items: center;
border: 1px solid #e4e8ee;
border-radius: 10px;
background: rgba(255, 255, 255, 0.82);
color: #1477ff;
font-size: 15px;
font-weight: 900;
text-align: center;
text-decoration: none;
}
@media (max-height: 700px) {
.auth-body {
justify-content: flex-start;
padding-top: 52px;
}
.brand-lockup {
margin-bottom: 26px;
}
.form-section h1 {
margin-bottom: 18px;
}
.assist-row {
margin-bottom: 18px;
}
}
</style>
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,266 @@
<script setup lang="ts">
import { onMounted, reactive, ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { showToast, showDialog } from "vant";
import {
getRealnameStatus,
startRealname,
type RealnameStatus,
} from "@/api/realname";
import { realnameStatusLabel } from "@/utils/statusLabels";
import { useSessionStore } from "@/stores/session";
import { formatDateTime } from "@/utils/time";
const session = useSessionStore();
const router = useRouter();
const route = useRoute();
const loading = ref(false);
const status = ref<RealnameStatus | null>(null);
const form = reactive({
name: "",
idNo: "",
});
onMounted(loadStatus);
function redirectAfterVerified() {
const redirect =
typeof route.query.redirect === "string" ? route.query.redirect : "";
if (redirect) {
router.replace(redirect);
}
}
async function loadStatus() {
if (!session.token) return;
try {
status.value = await getRealnameStatus();
if (status.value.status === "verified") {
await session.loadMe();
redirectAfterVerified();
}
} catch {
status.value = null;
}
}
async function handleSubmit() {
if (!form.name.trim()) {
showToast({ message: "请输入真实姓名", icon: "warning-o" });
return;
}
if (!form.idNo.trim() || form.idNo.length < 15) {
showToast({ message: "请输入有效的证件号", icon: "warning-o" });
return;
}
loading.value = true;
try {
status.value = await startRealname(form.name, form.idNo);
await session.loadMe();
showDialog({
title: "认证成功",
message: "实名认证已通过",
confirmButtonText: "好的",
}).then(() => {
redirectAfterVerified();
});
} catch (error: unknown) {
const msg =
typeof error === "object" && error && "response" in error
? (
error as {
response?: { data?: { message?: string } };
}
).response?.data?.message || "实名认证失败"
: "实名认证失败";
showToast({ message: msg, icon: "cross" });
} finally {
loading.value = false;
}
}
</script>
<template>
<main class="mobile-realname">
<header class="page-header">
<button class="back-btn" @click="router.back()">
<van-icon name="arrow-left" :size="20" />
</button>
<h1>实名认证</h1>
<span class="header-spacer"></span>
</header>
<!-- 未登录提示 -->
<van-empty
v-if="!session.token"
description="请先登录后再实名认证"
image="search"
/>
<template v-else>
<!-- 认证状态 -->
<section v-if="status" class="status-card">
<div class="status-row">
<span class="status-label">当前状态</span>
<van-tag
:type="status.status === 'verified' ? 'success' : 'warning'"
size="medium"
round
>
{{ realnameStatusLabel(status.status) }}
</van-tag>
</div>
<p v-if="status.masked_name" class="status-detail">
姓名{{ status.masked_name }}
</p>
<p v-if="status.masked_id_no" class="status-detail">
证件号{{ status.masked_id_no }}
</p>
<p v-if="status.verified_at" class="status-detail">
通过时间{{ formatDateTime(status.verified_at) }}
</p>
</section>
<!-- 认证表单 -->
<section v-if="status?.status !== 'verified'" class="form-card">
<h2>提交认证</h2>
<p class="form-hint">
号主发布前必须完成实名认证提交合法姓名和身份证号即可认证
</p>
<van-field
v-model="form.name"
label="姓名"
placeholder="请输入真实姓名"
clearable
class="realname-field"
/>
<van-field
v-model="form.idNo"
label="身份证号"
placeholder="请输入18位身份证号"
maxlength="18"
clearable
class="realname-field"
/>
<van-button
type="primary"
block
round
:loading="loading"
class="submit-btn"
@click="handleSubmit"
>
提交认证
</van-button>
</section>
</template>
</main>
</template>
<style scoped>
.mobile-realname {
min-height: 100dvh;
background: #f5f7fa;
padding-bottom: 20px;
}
/* ========== 顶部导航 ========== */
.page-header {
position: sticky;
top: 0;
z-index: 10;
display: flex;
align-items: center;
height: 48px;
padding: 0 12px;
background: #fff;
border-bottom: 1px solid #eee;
}
.page-header h1 {
flex: 1;
margin: 0;
font-size: 17px;
font-weight: 700;
text-align: center;
}
.back-btn {
display: grid;
width: 36px;
height: 36px;
place-items: center;
border: none;
background: none;
color: #333;
cursor: pointer;
}
.header-spacer {
width: 36px;
}
/* ========== 认证状态 ========== */
.status-card {
margin: 16px 12px;
padding: 16px;
border-radius: 16px;
background: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.status-row {
display: flex;
align-items: center;
justify-content: space-between;
}
.status-label {
font-size: 15px;
font-weight: 700;
color: #1a202c;
}
.status-detail {
margin: 8px 0 0;
font-size: 13px;
color: #666;
}
/* ========== 认证表单 ========== */
.form-card {
margin: 0 12px 16px;
padding: 18px 16px;
border-radius: 16px;
background: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
}
.form-card h2 {
margin: 0 0 6px;
font-size: 17px;
font-weight: 700;
}
.form-hint {
margin: 0 0 16px;
font-size: 13px;
color: #999;
line-height: 1.5;
}
.realname-field {
margin-bottom: 12px;
border-radius: 10px;
overflow: hidden;
}
.submit-btn {
margin-top: 8px;
background: #1477ff;
border-color: transparent;
font-weight: 800;
height: 44px;
font-size: 16px;
}
</style>
@@ -0,0 +1,353 @@
<script setup lang="ts">
import { reactive, ref } from "vue";
import { RouterLink, useRoute, useRouter } from "vue-router";
import { showToast } from "vant";
import { useSessionStore } from "@/stores/session";
import { useSmsCountdown } from "@/composables/useSmsCountdown";
const router = useRouter();
const route = useRoute();
const session = useSessionStore();
const loading = ref(false);
const agreed = ref(false);
const form = reactive({
phone: "",
code: "",
inviteCode: "",
});
const { countDown, sending, handleSendCode, readError } = useSmsCountdown();
async function handleRegister() {
if (!agreed.value) {
showToast({
message: "请先阅读并同意用户协议和隐私政策",
icon: "warning-o",
});
return;
}
loading.value = true;
try {
await session.login(form.phone, form.code);
const redirect = typeof route.query.redirect === "string" ? route.query.redirect : "/m/profile";
await router.replace(redirect);
} catch {
showToast({ message: "注册失败,请检查手机号和验证码", icon: "cross" });
} finally {
loading.value = false;
}
}
</script>
<template>
<main class="mobile-register-shell">
<header class="page-header">
<button class="back-btn" type="button" @click="router.back()">
<van-icon name="arrow-left" :size="20" />
</button>
</header>
<section class="auth-body">
<div class="brand-lockup">
<div class="brand-logo"></div>
<strong>大锤商行</strong>
</div>
<div class="form-section">
<h1>注册</h1>
<label class="auth-input-row">
<input
v-model="form.phone"
type="tel"
maxlength="11"
inputmode="tel"
placeholder="手机号"
/>
</label>
<label class="auth-input-row code-row">
<input
v-model="form.code"
type="text"
inputmode="numeric"
maxlength="6"
placeholder="验证码"
/>
<span class="code-action">
<van-button
size="small"
plain
:disabled="sending || countDown > 0"
:loading="sending"
class="code-btn"
@click="handleSendCode(form.phone)"
>
{{
countDown > 0
? `${countDown}s`
: sending
? "发送中"
: "发送验证码"
}}
</van-button>
</span>
</label>
<label class="auth-input-row">
<input
v-model="form.inviteCode"
maxlength="16"
placeholder="邀请码(选填)"
/>
</label>
<div class="assist-row">
<span>验证码注册</span>
<RouterLink to="/m/login">已有账号<b>去登录</b></RouterLink>
</div>
<div class="agreement-row">
<van-checkbox v-model="agreed" shape="square" icon-size="16px">
我已阅读并同意<b>用户协议</b><b>隐私政策</b>
</van-checkbox>
</div>
<van-button
type="primary"
block
class="primary-button"
:loading="loading"
loading-text="注册中..."
@click="handleRegister"
>
注册并登录
</van-button>
<RouterLink to="/m/login" class="secondary-entry">
返回登录
</RouterLink>
</div>
</section>
</main>
</template>
<style scoped>
.mobile-register-shell {
min-height: 100dvh;
background:
radial-gradient(circle at 50% 12%, rgba(20, 119, 255, 0.1), transparent 34%),
linear-gradient(180deg, #f8fbff 0%, #ffffff 70%, #f7fafc 100%);
color: #111827;
}
.page-header {
position: fixed;
top: 0;
left: 0;
right: 0;
z-index: 10;
display: flex;
align-items: center;
height: 48px;
margin: 0;
padding: 0 18px;
background: transparent;
}
.back-btn {
display: grid;
width: 34px;
height: 34px;
place-items: center;
border: none;
border-radius: 999px;
background: none;
color: #111827;
}
.auth-body {
box-sizing: border-box;
display: flex;
min-height: 100dvh;
flex-direction: column;
justify-content: center;
padding: 50px 34px 22px;
}
.brand-lockup {
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
margin: 0 auto clamp(24px, 4vh, 38px);
}
.brand-logo {
display: grid;
width: 46px;
height: 46px;
place-items: center;
border-radius: 14px;
background: linear-gradient(135deg, #1477ff, #2f8dff);
box-shadow: 0 14px 32px rgba(20, 119, 255, 0.18);
color: #ffffff;
font-size: 19px;
font-weight: 900;
}
.brand-lockup strong {
display: block;
color: #111827;
font-size: 18px;
font-weight: 900;
letter-spacing: 0;
}
.form-section {
width: min(100%, 420px);
margin: 0 auto;
}
.form-section h1 {
margin: 0 0 20px;
color: #05070a;
font-size: 22px;
font-weight: 900;
line-height: 1.2;
}
.auth-input-row {
display: flex;
align-items: center;
min-height: 48px;
margin-bottom: 10px;
padding: 0 16px;
border: 1px solid #e1e5eb;
border-radius: 10px;
background: rgba(255, 255, 255, 0.88);
box-shadow: 0 10px 24px rgba(15, 23, 42, 0.03);
}
.auth-input-row.code-row {
gap: 8px;
}
.auth-input-row input {
width: 100%;
min-width: 0;
border: none;
background: transparent;
color: #0f172a;
font-size: 16px;
outline: none;
}
.auth-input-row input::placeholder {
color: #b6beca;
}
.code-action {
display: flex;
justify-content: flex-end;
}
.code-btn {
min-width: 82px;
height: 32px;
border-color: #1477ff !important;
border-radius: 8px;
color: #1477ff !important;
font-weight: 700;
}
.assist-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 14px;
margin: 12px 0 18px;
color: #111827;
font-size: 13px;
}
.assist-row span {
min-width: 0;
color: #1477ff;
}
.assist-row a {
flex-shrink: 0;
color: #22252b;
text-decoration: none;
}
.assist-row b {
color: #05070a;
font-weight: 900;
}
.agreement-row {
display: flex;
align-items: center;
margin: 0 0 18px;
}
.agreement-row :deep(.van-checkbox__label) {
margin-left: 8px;
color: #252b36;
font-size: 12px;
line-height: 1.4;
}
.agreement-row :deep(.van-checkbox__label b) {
color: #1477ff;
font-weight: 700;
}
.primary-button {
height: 48px;
border: none !important;
border-radius: 10px !important;
background: #1477ff !important;
box-shadow: 0 12px 24px rgba(20, 119, 255, 0.18);
font-size: 17px;
font-weight: 900;
}
.secondary-entry {
display: grid;
min-height: 44px;
margin-top: 10px;
place-items: center;
border: 1px solid #e4e8ee;
border-radius: 10px;
background: rgba(255, 255, 255, 0.82);
color: #1477ff;
font-size: 15px;
font-weight: 900;
text-align: center;
text-decoration: none;
}
@media (max-height: 760px) {
.auth-body {
justify-content: flex-start;
padding-top: 48px;
}
.brand-lockup {
margin-bottom: 20px;
}
.form-section h1 {
margin-bottom: 16px;
}
.assist-row {
margin-bottom: 14px;
}
}
</style>
@@ -0,0 +1,77 @@
<script setup lang="ts">
import { ElMessage } from 'element-plus'
import { onMounted, ref } from 'vue'
import { fetchNotifications, markNotificationRead, type NotificationItem } from '@/api/notifications'
import { formatDateTime } from '@/utils/time'
const loading = ref(false)
const notifications = ref<NotificationItem[]>([])
const currentPage = ref(1)
const currentPageSize = ref(20)
const total = ref(0)
onMounted(loadNotifications)
async function loadNotifications() {
loading.value = true
try {
const result = await fetchNotifications(currentPage.value, currentPageSize.value)
notifications.value = result.items
total.value = result.total
} finally {
loading.value = false
}
}
function handleSizeChange() {
currentPage.value = 1
loadNotifications()
}
async function markRead(id: number) {
await markNotificationRead(id)
ElMessage.success('已标记为已读')
await loadNotifications()
}
</script>
<template>
<section class="page">
<div class="page-header">
<p class="eyebrow">Notifications</p>
<h1>站内信</h1>
<p>接收审核交接归还申诉和仲裁结果通知</p>
</div>
<el-empty v-if="!loading && notifications.length === 0" description="暂无站内信" />
<div v-else v-loading="loading" class="notification-list">
<div v-for="item in notifications" :key="item.id" class="notification-item" :class="{ unread: !item.read_at }">
<div>
<span>{{ item.type }}</span>
<h2>{{ item.title }}</h2>
<p>{{ item.content }}</p>
<small>{{ formatDateTime(item.created_at) }}</small>
</div>
<div class="notification-actions">
<RouterLink v-if="item.biz_type === 'order' && item.biz_id" :to="`/orders/${item.biz_id}`">
<el-button size="small">查看订单</el-button>
</RouterLink>
<el-button v-if="!item.read_at" size="small" type="primary" @click="markRead(item.id)">已读</el-button>
</div>
</div>
</div>
<div class="pagination-wrap" v-if="total > 0">
<el-pagination
v-model:current-page="currentPage"
v-model:page-size="currentPageSize"
:total="total"
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next"
@current-change="loadNotifications"
@size-change="handleSizeChange"
/>
</div>
</section>
</template>
@@ -0,0 +1,714 @@
<script setup lang="ts">
import {
Camera,
CircleCheckFilled,
CirclePlus,
Coin,
EditPen,
Finished,
Goods,
Postcard,
RefreshRight,
Shop,
Tickets,
User,
Van,
VideoPlay,
Wallet,
WarningFilled,
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { computed, onMounted, reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { uploadFile } from '@/api/files'
import { useSessionStore } from '@/stores/session'
import { realnameStatusLabel } from '@/utils/statusLabels'
const session = useSessionStore()
const router = useRouter()
const saving = ref(false)
const uploadingAvatar = ref(false)
const avatarFileInput = ref<HTMLInputElement | null>(null)
const form = reactive({
nickname: '',
avatar_url: '',
})
const buyerServices = [
{ label: '待支付', icon: Coin, tone: 'warning', to: { path: '/orders', query: { tab: 'pending_payment' } } },
{ label: '待交接', icon: Van, tone: 'info', to: { path: '/orders', query: { tab: 'pending_handoff' } } },
{ label: '使用中', icon: VideoPlay, tone: 'primary', to: { path: '/orders', query: { tab: 'renting' } } },
{ label: '已完成', icon: Finished, tone: 'success', to: { path: '/orders', query: { tab: 'completed' } } },
]
const sellerServices = [
{ label: '发布商品', icon: CirclePlus, tone: 'orange', to: '/seller/listings/create' },
{ label: '我的商品', icon: Shop, tone: 'purple', to: '/seller/listings' },
{ label: '提现/账单', icon: Wallet, tone: 'teal', to: '/wallet' },
]
const displayName = computed(() => session.displayName)
const maskedPhone = computed(() => {
if (!session.phone) return '未绑定手机号'
return `${session.phone.slice(0, 3)}****${session.phone.slice(-4)}`
})
const avatarText = computed(() => (form.nickname || displayName.value || 'U').slice(0, 1))
const realnameTone = computed(() => {
if (session.realnameStatus === 'verified') return 'verified'
if (session.realnameStatus === 'pending') return 'pending'
if (session.realnameStatus === 'rejected') return 'rejected'
return 'unverified'
})
onMounted(async () => {
if (!session.phone) {
await session.loadMe()
}
resetForm()
})
function resetForm() {
form.nickname = session.nickname || session.displayName
form.avatar_url = session.avatarUrl || ''
}
function resolveAvatarURL(url: string | undefined | null) {
if (!url) return ''
if (url.includes('/api/files/object?key=avatar/')) {
return url.replace('/api/files/object', '/api/public/files/object')
}
return url
}
function triggerAvatarUpload() {
avatarFileInput.value?.click()
}
async function handleAvatarFileChange(event: Event) {
const input = event.target as HTMLInputElement
const file = input.files?.[0]
input.value = ''
if (!file) return
uploadingAvatar.value = true
try {
const uploaded = await uploadFile(file, 'avatar')
form.avatar_url = uploaded.url
ElMessage.success('头像上传成功')
} catch (error) {
ElMessage.error(readError(error, '头像上传失败'))
} finally {
uploadingAvatar.value = false
}
}
async function saveProfile() {
const nickname = form.nickname.trim()
const avatarURL = form.avatar_url.trim()
if (!nickname) {
ElMessage.warning('请输入昵称')
return
}
if (nickname.length > 24) {
ElMessage.warning('昵称不能超过 24 个字符')
return
}
saving.value = true
try {
await session.updateProfile({ nickname, avatar_url: avatarURL })
resetForm()
ElMessage.success('个人资料已保存')
} catch (error) {
ElMessage.error(readError(error, '资料更新失败'))
} finally {
saving.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
}
return fallback
}
</script>
<template>
<section class="profile-page">
<div class="profile-hero">
<div class="hero-avatar">
<img v-if="session.avatarUrl" :src="resolveAvatarURL(session.avatarUrl)" alt="" />
<span v-else>{{ session.avatarText }}</span>
</div>
<div class="hero-copy">
<span class="eyebrow">Profile</span>
<h1>个人资料</h1>
<p>{{ displayName }} · {{ maskedPhone }}</p>
</div>
<button class="hero-realname" :class="`is-${realnameTone}`" type="button" @click="router.push('/realname')">
<el-icon><CircleCheckFilled v-if="session.realnameStatus === 'verified'" /><WarningFilled v-else /></el-icon>
<span>{{ realnameStatusLabel(session.realnameStatus) }}</span>
</button>
</div>
<div class="profile-layout">
<section class="edit-panel">
<div class="panel-head">
<div class="panel-icon">
<el-icon><EditPen /></el-icon>
</div>
<div>
<h2>资料编辑</h2>
<p>修改昵称和头像后会同步展示在顶部用户信息中</p>
</div>
</div>
<div class="avatar-editor">
<button class="avatar-preview" type="button" @click="triggerAvatarUpload">
<img v-if="form.avatar_url" :src="resolveAvatarURL(form.avatar_url)" alt="" />
<span v-else>{{ avatarText }}</span>
<i><el-icon><Camera /></el-icon></i>
</button>
<div class="avatar-actions">
<strong>{{ form.nickname || displayName }}</strong>
<p>支持上传本地图片也可以直接填写头像 URL</p>
<el-button :icon="Camera" :loading="uploadingAvatar" @click="triggerAvatarUpload">上传头像</el-button>
<input ref="avatarFileInput" type="file" accept="image/*" hidden @change="handleAvatarFileChange" />
</div>
</div>
<el-form class="profile-form" label-position="top">
<el-form-item label="昵称">
<el-input v-model="form.nickname" :prefix-icon="User" maxlength="24" placeholder="请输入昵称" size="large" />
</el-form-item>
<el-form-item label="头像地址">
<el-input
v-model="form.avatar_url"
:prefix-icon="Postcard"
maxlength="512"
placeholder="可填写图片 URL,留空使用文字头像"
size="large"
/>
</el-form-item>
<div class="form-actions">
<el-button size="large" :icon="RefreshRight" @click="resetForm">重置</el-button>
<el-button type="primary" size="large" :icon="EditPen" :loading="saving" @click="saveProfile">保存资料</el-button>
</div>
</el-form>
</section>
<aside class="account-card">
<span class="card-kicker">账号信息</span>
<dl>
<div>
<dt>用户 ID</dt>
<dd>{{ session.userId || '-' }}</dd>
</div>
<div>
<dt>手机号</dt>
<dd>{{ maskedPhone }}</dd>
</div>
<div>
<dt>实名状态</dt>
<dd :class="`is-${realnameTone}`">{{ realnameStatusLabel(session.realnameStatus) }}</dd>
</div>
</dl>
<button class="realname-shortcut" type="button" @click="router.push('/realname')">
<span>查看实名认证</span>
<el-icon><CircleCheckFilled /></el-icon>
</button>
</aside>
</div>
<div class="service-panels">
<section class="service-panel">
<div class="service-head">
<h2>买家服务</h2>
<RouterLink class="service-all" :to="{ path: '/orders', query: { tab: 'all' } }">
<span>全部订单</span>
<el-icon><Tickets /></el-icon>
</RouterLink>
</div>
<div class="service-grid buyer-grid">
<RouterLink v-for="item in buyerServices" :key="item.label" class="service-item" :to="item.to">
<span class="service-icon" :class="`is-${item.tone}`">
<el-icon><component :is="item.icon" /></el-icon>
</span>
<strong>{{ item.label }}</strong>
</RouterLink>
</div>
</section>
<section class="service-panel">
<div class="service-head">
<h2>卖家服务</h2>
<RouterLink class="service-all" to="/seller/listings">
<span>管理发布</span>
<el-icon><Goods /></el-icon>
</RouterLink>
</div>
<div class="service-grid seller-grid">
<RouterLink v-for="item in sellerServices" :key="item.label" class="service-item" :to="item.to">
<span class="service-icon" :class="`is-${item.tone}`">
<el-icon><component :is="item.icon" /></el-icon>
</span>
<strong>{{ item.label }}</strong>
</RouterLink>
</div>
</section>
</div>
</section>
</template>
<style scoped>
.profile-page {
width: min(1180px, 100%);
margin: 0 auto;
padding: 10px 0 40px;
}
.profile-hero {
display: flex;
align-items: center;
gap: 18px;
padding: 30px 34px;
border: 1px solid #eef1f5;
border-radius: 18px;
background:
linear-gradient(135deg, rgba(255, 106, 0, 0.12), rgba(37, 99, 235, 0.08)),
#ffffff;
box-shadow: 0 16px 36px rgba(23, 35, 61, 0.08);
}
.hero-avatar,
.avatar-preview {
display: grid;
place-items: center;
overflow: hidden;
border-radius: 999px;
background: #ff6a00;
color: #ffffff;
font-weight: 900;
}
.hero-avatar {
width: 74px;
height: 74px;
font-size: 28px;
flex-shrink: 0;
}
.hero-avatar img,
.avatar-preview img {
width: 100%;
height: 100%;
object-fit: cover;
}
.hero-copy {
min-width: 0;
flex: 1;
}
.eyebrow {
color: #ff6a00;
font-size: 13px;
font-weight: 900;
text-transform: uppercase;
}
.hero-copy h1 {
margin: 8px 0 0;
color: #17233d;
font-size: 34px;
line-height: 1.2;
}
.hero-copy p {
margin: 10px 0 0;
color: #64748b;
font-size: 15px;
font-weight: 700;
}
.hero-realname {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 40px;
padding: 0 14px;
border: none;
border-radius: 999px;
font-size: 14px;
font-weight: 900;
cursor: pointer;
}
.hero-realname.is-verified,
.account-card dd.is-verified {
background: #ecfdf3;
color: #16a34a;
}
.hero-realname.is-pending,
.account-card dd.is-pending {
background: #fff7ed;
color: #f97316;
}
.hero-realname.is-rejected,
.account-card dd.is-rejected {
background: #fff1f2;
color: #e11d48;
}
.hero-realname.is-unverified,
.account-card dd.is-unverified {
background: #eff6ff;
color: #2563eb;
}
.profile-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 360px;
gap: 22px;
margin-top: 22px;
}
.edit-panel,
.account-card {
border: 1px solid #eef1f5;
border-radius: 16px;
background: #ffffff;
box-shadow: 0 10px 28px rgba(23, 35, 61, 0.06);
}
.edit-panel {
padding: 28px;
}
.panel-head {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 26px;
}
.panel-icon {
display: grid;
width: 48px;
height: 48px;
place-items: center;
border-radius: 12px;
background: #fff3e8;
color: #ff6a00;
font-size: 24px;
}
.panel-head h2 {
margin: 0;
color: #17233d;
font-size: 22px;
}
.panel-head p {
margin: 6px 0 0;
color: #64748b;
font-size: 14px;
line-height: 1.6;
}
.avatar-editor {
display: flex;
align-items: center;
gap: 18px;
max-width: 640px;
padding: 20px;
border-radius: 14px;
background: #f8fafc;
border: 1px solid #e2e8f0;
}
.avatar-preview {
position: relative;
width: 82px;
height: 82px;
border: none;
font-size: 30px;
cursor: pointer;
flex-shrink: 0;
}
.avatar-preview i {
position: absolute;
right: 4px;
bottom: 4px;
display: grid;
width: 26px;
height: 26px;
place-items: center;
border-radius: 999px;
background: #ffffff;
color: #ff6a00;
box-shadow: 0 4px 12px rgba(23, 35, 61, 0.16);
}
.avatar-actions strong {
display: block;
color: #17233d;
font-size: 20px;
}
.avatar-actions p {
margin: 6px 0 12px;
color: #64748b;
font-size: 14px;
}
.profile-form {
display: grid;
gap: 6px;
max-width: 640px;
margin-top: 24px;
}
.profile-form :deep(.el-form-item__label) {
color: #475569;
font-size: 14px;
font-weight: 800;
}
.profile-form :deep(.el-input__wrapper) {
min-height: 48px;
border-radius: 10px;
box-shadow: 0 0 0 1px #dbe3ee inset;
}
.profile-form :deep(.el-input__wrapper.is-focus) {
box-shadow: 0 0 0 1px #ff6a00 inset, 0 0 0 4px rgba(255, 106, 0, 0.08);
}
.form-actions {
display: flex;
gap: 12px;
margin-top: 8px;
}
.form-actions .el-button {
height: 46px;
border-radius: 10px;
font-weight: 900;
}
.form-actions .el-button--primary {
border: none;
background: #ff6a00;
box-shadow: 0 10px 20px rgba(255, 106, 0, 0.18);
}
.account-card {
padding: 24px;
}
.card-kicker {
color: #8b9cb5;
font-size: 13px;
font-weight: 900;
}
.account-card dl {
display: grid;
gap: 12px;
margin: 18px 0 0;
}
.account-card dl div {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
min-height: 48px;
padding: 0 14px;
border-radius: 10px;
background: #f8fafc;
}
.account-card dt {
color: #8b9cb5;
font-size: 13px;
font-weight: 800;
}
.account-card dd {
margin: 0;
color: #334155;
font-size: 14px;
font-weight: 900;
text-align: right;
}
.realname-shortcut {
display: flex;
align-items: center;
justify-content: space-between;
width: 100%;
min-height: 44px;
margin-top: 18px;
padding: 0 14px;
border: 1px solid #e2e8f0;
border-radius: 10px;
background: #ffffff;
color: #475569;
font-size: 14px;
font-weight: 900;
cursor: pointer;
}
.realname-shortcut:hover {
border-color: #ff6a00;
color: #ff6a00;
}
.service-panels {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 22px;
margin-top: 22px;
}
.service-panel {
padding: 24px;
border: 1px solid #eef1f5;
border-radius: 16px;
background: #ffffff;
box-shadow: 0 10px 28px rgba(23, 35, 61, 0.06);
}
.service-head {
display: flex;
align-items: center;
justify-content: space-between;
gap: 18px;
}
.service-head h2 {
margin: 0;
color: #17233d;
font-size: 22px;
}
.service-all {
display: inline-flex;
align-items: center;
gap: 6px;
color: #64748b;
font-size: 14px;
font-weight: 900;
text-decoration: none;
}
.service-all:hover {
color: #ff6a00;
}
.service-grid {
display: grid;
gap: 14px;
margin-top: 22px;
}
.buyer-grid {
grid-template-columns: repeat(4, minmax(0, 1fr));
}
.seller-grid {
grid-template-columns: repeat(3, minmax(0, 1fr));
}
.service-item {
display: grid;
min-width: 0;
min-height: 118px;
place-items: center;
gap: 10px;
padding: 16px 10px;
border: 1px solid #edf2f7;
border-radius: 14px;
background: #fbfdff;
color: #1f2937;
text-align: center;
text-decoration: none;
transition:
border-color 0.18s ease,
box-shadow 0.18s ease,
transform 0.18s ease;
}
.service-item:hover {
border-color: rgba(255, 106, 0, 0.35);
box-shadow: 0 12px 24px rgba(23, 35, 61, 0.08);
transform: translateY(-2px);
}
.service-item strong {
color: #334155;
font-size: 15px;
font-weight: 900;
line-height: 1.35;
}
.service-icon {
display: grid;
width: 58px;
height: 58px;
place-items: center;
border-radius: 14px;
font-size: 28px;
}
.service-icon.is-warning {
background: #fff7ed;
color: #f59e0b;
}
.service-icon.is-info {
background: #eff6ff;
color: #2563eb;
}
.service-icon.is-primary {
background: #eef2ff;
color: #4f46e5;
}
.service-icon.is-success {
background: #ecfdf3;
color: #10b981;
}
.service-icon.is-orange {
background: #fff1e8;
color: #ff6a00;
}
.service-icon.is-purple {
background: #f3e8ff;
color: #8b5cf6;
}
.service-icon.is-teal {
background: #e8f7f5;
color: #0f766e;
}
@media (max-width: 1100px) {
.profile-layout {
grid-template-columns: 1fr;
}
.service-panels {
grid-template-columns: 1fr;
}
}
</style>
@@ -0,0 +1,584 @@
<script setup lang="ts">
import {
CircleCheckFilled,
CreditCard,
DocumentChecked,
Lock,
Postcard,
RefreshRight,
User,
WarningFilled,
} from '@element-plus/icons-vue'
import { ElMessage } from 'element-plus'
import { computed, onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getRealnameStatus, startRealname, type RealnameStatus } from '@/api/realname'
import { useSessionStore } from '@/stores/session'
import { realnameStatusLabel } from '@/utils/statusLabels'
import { formatDateTime } from '@/utils/time'
const session = useSessionStore()
const route = useRoute()
const router = useRouter()
const loading = ref(false)
const status = ref<RealnameStatus | null>(null)
const form = reactive({
name: '',
idNo: '',
})
const currentStatus = computed(() => status.value?.status || 'unverified')
const statusMeta = computed(() => {
switch (currentStatus.value) {
case 'verified':
return {
icon: CircleCheckFilled,
tone: 'verified',
title: '认证已完成',
summary: '可发布账号并参与需要实名的交易流程。',
}
case 'pending':
return {
icon: DocumentChecked,
tone: 'pending',
title: '认证处理中',
summary: '认证结果返回后会自动同步到账号状态。',
}
case 'rejected':
return {
icon: WarningFilled,
tone: 'rejected',
title: '认证未通过',
summary: status.value?.fail_reason || '请核对姓名与身份证号后重新提交。',
}
default:
return {
icon: Postcard,
tone: 'unverified',
title: '等待认证',
summary: '提交真实姓名与身份证号后即可完成核验。',
}
}
})
const canSubmit = computed(() => !!session.token && currentStatus.value !== 'verified')
onMounted(loadStatus)
function redirectAfterVerified() {
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : ''
if (redirect) {
router.replace(redirect)
}
}
async function loadStatus() {
if (!session.token) return
try {
status.value = await getRealnameStatus()
if (status.value.status === 'verified') {
await session.loadMe()
redirectAfterVerified()
}
} catch {
status.value = null
}
}
async function handleSubmit() {
if (!form.name.trim()) {
ElMessage.warning('请输入真实姓名')
return
}
if (!form.idNo.trim() || form.idNo.length < 15) {
ElMessage.warning('请输入有效的证件号')
return
}
loading.value = true
try {
status.value = await startRealname(form.name, form.idNo)
await session.loadMe()
ElMessage.success('实名认证已通过')
redirectAfterVerified()
} catch (error) {
ElMessage.error(readError(error, '实名认证失败'))
} finally {
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
}
return fallback
}
</script>
<template>
<section class="realname-page">
<div class="realname-hero">
<div class="hero-copy">
<span class="eyebrow">Realname</span>
<h1>实名认证</h1>
<p>完成实名后可发布账号进入交易流程并提升账号可信度</p>
</div>
<div class="hero-status" :class="`is-${statusMeta.tone}`">
<el-icon><component :is="statusMeta.icon" /></el-icon>
<div>
<span>当前状态</span>
<strong>{{ realnameStatusLabel(currentStatus) }}</strong>
</div>
</div>
</div>
<el-alert
v-if="!session.token"
class="login-alert"
type="warning"
:closable="false"
title="请先登录后再实名认证"
/>
<div class="realname-layout">
<section class="verify-panel">
<div class="panel-head">
<div class="panel-icon">
<el-icon><CreditCard /></el-icon>
</div>
<div>
<h2>{{ currentStatus === 'verified' ? '实名信息' : '提交认证' }}</h2>
<p>{{ currentStatus === 'verified' ? '实名信息已完成脱敏展示。' : '请使用本人真实身份信息完成核验。' }}</p>
</div>
</div>
<div v-if="currentStatus === 'verified'" class="verified-summary">
<div class="verified-mark">
<el-icon><CircleCheckFilled /></el-icon>
</div>
<div class="verified-copy">
<strong>认证通过</strong>
<span>{{ status?.verified_at ? formatDateTime(status.verified_at) : '已完成实名核验' }}</span>
</div>
</div>
<el-form v-else class="verify-form" label-position="top">
<el-form-item label="姓名">
<el-input v-model="form.name" :prefix-icon="User" placeholder="请输入真实姓名" size="large" />
</el-form-item>
<el-form-item label="身份证号">
<el-input
v-model="form.idNo"
:prefix-icon="Postcard"
maxlength="18"
placeholder="请输入 18 位身份证号"
size="large"
/>
</el-form-item>
<el-button
type="primary"
size="large"
:icon="DocumentChecked"
:disabled="!canSubmit"
:loading="loading"
@click="handleSubmit"
>
提交认证
</el-button>
</el-form>
</section>
<aside class="status-card" :class="`is-${statusMeta.tone}`">
<div class="status-visual">
<el-icon><component :is="statusMeta.icon" /></el-icon>
</div>
<div class="status-content">
<span class="status-kicker">认证状态</span>
<h2>{{ statusMeta.title }}</h2>
<p>{{ statusMeta.summary }}</p>
</div>
<dl class="status-details">
<div>
<dt>姓名</dt>
<dd>{{ status?.masked_name || '待提交' }}</dd>
</div>
<div>
<dt>证件号</dt>
<dd>{{ status?.masked_id_no || '待提交' }}</dd>
</div>
<div>
<dt>通过时间</dt>
<dd>{{ status?.verified_at ? formatDateTime(status.verified_at) : '暂无' }}</dd>
</div>
</dl>
<div class="security-note">
<el-icon><Lock /></el-icon>
<span>身份信息仅用于实名核验页面只展示脱敏结果</span>
</div>
</aside>
</div>
<div class="realname-actions">
<RouterLink class="secondary-action" to="/seller/listings/create">
<el-icon><RefreshRight /></el-icon>
<span>返回发布账号</span>
</RouterLink>
</div>
</section>
</template>
<style scoped>
.realname-page {
width: min(1180px, 100%);
margin: 0 auto;
padding: 10px 0 40px;
}
.realname-hero {
display: flex;
align-items: flex-end;
justify-content: space-between;
gap: 24px;
min-height: 156px;
padding: 34px 36px;
border: 1px solid #eef1f5;
border-radius: 18px;
background:
linear-gradient(135deg, rgba(255, 106, 0, 0.12) 0%, rgba(22, 163, 74, 0.08) 52%, rgba(37, 99, 235, 0.08) 100%),
#ffffff;
box-shadow: 0 16px 36px rgba(23, 35, 61, 0.08);
}
.hero-copy {
max-width: 640px;
}
.eyebrow {
display: inline-flex;
align-items: center;
margin-bottom: 12px;
color: #ff6a00;
font-size: 13px;
font-weight: 900;
letter-spacing: 0;
text-transform: uppercase;
}
.hero-copy h1 {
margin: 0;
color: #17233d;
font-size: 36px;
line-height: 1.2;
}
.hero-copy p {
margin: 14px 0 0;
color: #64748b;
font-size: 16px;
font-weight: 600;
line-height: 1.7;
}
.hero-status {
display: flex;
align-items: center;
gap: 14px;
min-width: 210px;
padding: 18px;
border-radius: 14px;
background: rgba(255, 255, 255, 0.88);
border: 1px solid rgba(255, 255, 255, 0.9);
box-shadow: 0 12px 28px rgba(23, 35, 61, 0.08);
}
.hero-status .el-icon {
display: grid;
width: 44px;
height: 44px;
place-items: center;
border-radius: 12px;
font-size: 24px;
}
.hero-status span,
.status-kicker {
color: #8b9cb5;
font-size: 13px;
font-weight: 800;
}
.hero-status strong {
display: block;
margin-top: 4px;
color: #17233d;
font-size: 22px;
line-height: 1.2;
}
.hero-status.is-verified .el-icon,
.status-card.is-verified .status-visual {
background: #ecfdf3;
color: #16a34a;
}
.hero-status.is-pending .el-icon,
.status-card.is-pending .status-visual {
background: #fff7ed;
color: #f97316;
}
.hero-status.is-rejected .el-icon,
.status-card.is-rejected .status-visual {
background: #fff1f2;
color: #e11d48;
}
.hero-status.is-unverified .el-icon,
.status-card.is-unverified .status-visual {
background: #eff6ff;
color: #2563eb;
}
.login-alert {
margin-top: 18px;
}
.realname-layout {
display: grid;
grid-template-columns: minmax(0, 1fr) 380px;
gap: 22px;
margin-top: 22px;
}
.verify-panel,
.status-card {
border: 1px solid #eef1f5;
border-radius: 16px;
background: #ffffff;
box-shadow: 0 10px 28px rgba(23, 35, 61, 0.06);
}
.verify-panel {
min-height: 430px;
padding: 28px;
}
.panel-head {
display: flex;
align-items: center;
gap: 14px;
margin-bottom: 28px;
}
.panel-icon {
display: grid;
width: 48px;
height: 48px;
place-items: center;
border-radius: 12px;
background: #fff3e8;
color: #ff6a00;
font-size: 24px;
}
.panel-head h2,
.status-content h2 {
margin: 0;
color: #17233d;
font-size: 22px;
line-height: 1.3;
}
.panel-head p,
.status-content p {
margin: 6px 0 0;
color: #64748b;
font-size: 14px;
line-height: 1.6;
}
.verify-form {
display: grid;
gap: 6px;
max-width: 620px;
}
.verify-form :deep(.el-form-item__label) {
color: #475569;
font-size: 14px;
font-weight: 800;
}
.verify-form :deep(.el-input__wrapper) {
min-height: 48px;
border-radius: 10px;
box-shadow: 0 0 0 1px #dbe3ee inset;
}
.verify-form :deep(.el-input__wrapper.is-focus) {
box-shadow: 0 0 0 1px #ff6a00 inset, 0 0 0 4px rgba(255, 106, 0, 0.08);
}
.verify-form .el-button {
width: 168px;
height: 46px;
margin-top: 8px;
border: none;
border-radius: 10px;
background: #ff6a00;
font-weight: 900;
box-shadow: 0 10px 20px rgba(255, 106, 0, 0.18);
}
.verified-summary {
display: flex;
align-items: center;
gap: 18px;
max-width: 620px;
padding: 24px;
border-radius: 14px;
background: #f8fafc;
border: 1px solid #e2e8f0;
}
.verified-mark {
display: grid;
width: 58px;
height: 58px;
place-items: center;
border-radius: 16px;
background: #ecfdf3;
color: #16a34a;
font-size: 34px;
}
.verified-copy strong {
display: block;
color: #17233d;
font-size: 22px;
}
.verified-copy span {
display: block;
margin-top: 6px;
color: #64748b;
font-size: 14px;
font-weight: 700;
}
.status-card {
padding: 24px;
}
.status-visual {
display: grid;
width: 56px;
height: 56px;
place-items: center;
border-radius: 16px;
font-size: 30px;
}
.status-content {
margin-top: 18px;
}
.status-details {
display: grid;
gap: 12px;
margin: 24px 0 0;
}
.status-details div {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
min-height: 46px;
padding: 0 14px;
border-radius: 10px;
background: #f8fafc;
}
.status-details dt {
color: #8b9cb5;
font-size: 13px;
font-weight: 800;
}
.status-details dd {
margin: 0;
color: #334155;
font-size: 14px;
font-weight: 800;
text-align: right;
}
.security-note {
display: flex;
align-items: flex-start;
gap: 10px;
margin-top: 22px;
padding: 14px;
border-radius: 12px;
background: #f8fafc;
color: #64748b;
font-size: 13px;
font-weight: 700;
line-height: 1.6;
}
.security-note .el-icon {
margin-top: 2px;
color: #2563eb;
font-size: 18px;
flex-shrink: 0;
}
.realname-actions {
display: flex;
justify-content: flex-end;
margin-top: 18px;
}
.secondary-action {
display: inline-flex;
align-items: center;
gap: 8px;
min-height: 40px;
padding: 0 16px;
border-radius: 10px;
background: #ffffff;
border: 1px solid #e2e8f0;
color: #475569;
font-size: 14px;
font-weight: 800;
text-decoration: none;
transition: all 0.2s;
}
.secondary-action:hover {
border-color: #ff6a00;
color: #ff6a00;
box-shadow: 0 8px 18px rgba(255, 106, 0, 0.08);
}
@media (max-width: 1100px) {
.realname-layout {
grid-template-columns: 1fr;
}
.realname-hero {
align-items: flex-start;
flex-direction: column;
}
.hero-status {
width: 100%;
}
}
</style>