增加前端格式检查配置
This commit is contained in:
@@ -1,81 +1,76 @@
|
||||
<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 "@/features/auth/api/realname";
|
||||
import { realnameStatusLabel } from "@/utils/statusLabels";
|
||||
import { useSessionStore } from "@/stores/session";
|
||||
import { formatDateTime } from "@/utils/time";
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { showToast, showDialog } from 'vant'
|
||||
import { getRealnameStatus, startRealname, type RealnameStatus } from '@/features/auth/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 session = useSessionStore()
|
||||
const router = useRouter()
|
||||
const route = useRoute()
|
||||
const loading = ref(false)
|
||||
const status = ref<RealnameStatus | null>(null)
|
||||
const form = reactive({
|
||||
name: "",
|
||||
idNo: "",
|
||||
});
|
||||
name: '',
|
||||
idNo: '',
|
||||
})
|
||||
|
||||
onMounted(loadStatus);
|
||||
onMounted(loadStatus)
|
||||
|
||||
function redirectAfterVerified() {
|
||||
const redirect =
|
||||
typeof route.query.redirect === "string" ? route.query.redirect : "";
|
||||
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : ''
|
||||
if (redirect) {
|
||||
router.replace(redirect);
|
||||
router.replace(redirect)
|
||||
}
|
||||
}
|
||||
|
||||
async function loadStatus() {
|
||||
if (!session.token) return;
|
||||
if (!session.token) return
|
||||
try {
|
||||
status.value = await getRealnameStatus();
|
||||
if (status.value.status === "verified") {
|
||||
await session.loadMe();
|
||||
redirectAfterVerified();
|
||||
status.value = await getRealnameStatus()
|
||||
if (status.value.status === 'verified') {
|
||||
await session.loadMe()
|
||||
redirectAfterVerified()
|
||||
}
|
||||
} catch {
|
||||
status.value = null;
|
||||
status.value = null
|
||||
}
|
||||
}
|
||||
|
||||
async function handleSubmit() {
|
||||
if (!form.name.trim()) {
|
||||
showToast({ message: "请输入真实姓名", icon: "warning-o" });
|
||||
return;
|
||||
showToast({ message: '请输入真实姓名', icon: 'warning-o' })
|
||||
return
|
||||
}
|
||||
if (!form.idNo.trim() || form.idNo.length < 15) {
|
||||
showToast({ message: "请输入有效的证件号", icon: "warning-o" });
|
||||
return;
|
||||
showToast({ message: '请输入有效的证件号', icon: 'warning-o' })
|
||||
return
|
||||
}
|
||||
loading.value = true;
|
||||
loading.value = true
|
||||
try {
|
||||
status.value = await startRealname(form.name, form.idNo);
|
||||
await session.loadMe();
|
||||
status.value = await startRealname(form.name, form.idNo)
|
||||
await session.loadMe()
|
||||
showDialog({
|
||||
title: "认证成功",
|
||||
message: "实名认证已通过",
|
||||
confirmButtonText: "好的",
|
||||
title: '认证成功',
|
||||
message: '实名认证已通过',
|
||||
confirmButtonText: '好的',
|
||||
}).then(() => {
|
||||
redirectAfterVerified();
|
||||
});
|
||||
redirectAfterVerified()
|
||||
})
|
||||
} catch (error: unknown) {
|
||||
const msg =
|
||||
typeof error === "object" && error && "response" in error
|
||||
typeof error === 'object' && error && 'response' in error
|
||||
? (
|
||||
error as {
|
||||
response?: { data?: { message?: string } };
|
||||
response?: { data?: { message?: string } }
|
||||
}
|
||||
).response?.data?.message || "实名认证失败"
|
||||
: "实名认证失败";
|
||||
showToast({ message: msg, icon: "cross" });
|
||||
).response?.data?.message || '实名认证失败'
|
||||
: '实名认证失败'
|
||||
showToast({ message: msg, icon: 'cross' })
|
||||
} finally {
|
||||
loading.value = false;
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -91,31 +86,19 @@ async function handleSubmit() {
|
||||
</header>
|
||||
|
||||
<!-- 未登录提示 -->
|
||||
<van-empty
|
||||
v-if="!session.token"
|
||||
description="请先登录后再实名认证"
|
||||
image="search"
|
||||
/>
|
||||
<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
|
||||
>
|
||||
<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.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>
|
||||
@@ -124,9 +107,7 @@ async function handleSubmit() {
|
||||
<!-- 认证表单 -->
|
||||
<section v-if="status?.status !== 'verified'" class="form-card">
|
||||
<h2>提交认证</h2>
|
||||
<p class="form-hint">
|
||||
号主发布前必须完成实名认证,提交合法姓名和身份证号即可认证。
|
||||
</p>
|
||||
<p class="form-hint">号主发布前必须完成实名认证,提交合法姓名和身份证号即可认证。</p>
|
||||
<van-field
|
||||
v-model="form.name"
|
||||
label="姓名"
|
||||
|
||||
Reference in New Issue
Block a user