发布需要校验实名认证

This commit is contained in:
yml
2026-05-24 23:00:28 +08:00
parent c13bacbc3e
commit fd73bb39be
2 changed files with 29 additions and 3 deletions
+6 -3
View File
@@ -140,7 +140,7 @@ const router = createRouter({
path: "/seller/listings/create", path: "/seller/listings/create",
name: "seller-listing-create", name: "seller-listing-create",
component: () => import("@/views/seller/SellerListingCreateView.vue"), component: () => import("@/views/seller/SellerListingCreateView.vue"),
meta: { requiresAuth: true }, meta: { requiresAuth: true, requiresRealname: true },
}, },
{ {
path: "/seller/handoffs", path: "/seller/handoffs",
@@ -253,18 +253,21 @@ router.beforeEach(async (to) => {
if (to.meta.requiresRealname) { if (to.meta.requiresRealname) {
const session = useSessionStore(); const session = useSessionStore();
const loginPath = to.path.startsWith("/m") ? "/m/login" : "/login";
const realnamePath = to.path.startsWith("/m") ? "/m/realname" : "/realname";
if (session.realnameStatus !== "verified") { if (session.realnameStatus !== "verified") {
try { try {
await session.loadMe(); await session.loadMe();
} catch { } catch {
if (!localStorage.getItem("access_token")) { if (!localStorage.getItem("access_token")) {
return { path: "/m/login", query: { redirect: to.fullPath } }; return { path: loginPath, query: { redirect: to.fullPath } };
} }
} }
} }
if (session.realnameStatus !== "verified") { if (session.realnameStatus !== "verified") {
return { path: "/m/realname", query: { redirect: to.fullPath } }; return { path: realnamePath, query: { redirect: to.fullPath } };
} }
} }
@@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { ElMessage } from 'element-plus' import { ElMessage } from 'element-plus'
import { onMounted, reactive, ref } from 'vue' import { onMounted, reactive, ref } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { getRealnameStatus, startRealname, type RealnameStatus } from '@/api/realname' import { getRealnameStatus, startRealname, type RealnameStatus } from '@/api/realname'
import { useSessionStore } from '@/stores/session' import { useSessionStore } from '@/stores/session'
@@ -8,6 +9,8 @@ import { realnameStatusLabel } from '@/utils/statusLabels'
import { formatDateTime } from '@/utils/time' import { formatDateTime } from '@/utils/time'
const session = useSessionStore() const session = useSessionStore()
const route = useRoute()
const router = useRouter()
const loading = ref(false) const loading = ref(false)
const status = ref<RealnameStatus | null>(null) const status = ref<RealnameStatus | null>(null)
const form = reactive({ const form = reactive({
@@ -17,21 +20,41 @@ const form = reactive({
onMounted(loadStatus) onMounted(loadStatus)
function redirectAfterVerified() {
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : ''
if (redirect) {
router.replace(redirect)
}
}
async function loadStatus() { async function loadStatus() {
if (!session.token) return if (!session.token) return
try { try {
status.value = await getRealnameStatus() status.value = await getRealnameStatus()
if (status.value.status === 'verified') {
await session.loadMe()
redirectAfterVerified()
}
} catch { } catch {
status.value = null status.value = null
} }
} }
async function handleSubmit() { async function handleSubmit() {
if (!form.name.trim()) {
ElMessage.warning('请输入真实姓名')
return
}
if (!form.idNo.trim() || form.idNo.length < 15) {
ElMessage.warning('请输入有效的证件号')
return
}
loading.value = true loading.value = true
try { try {
status.value = await startRealname(form.name, form.idNo) status.value = await startRealname(form.name, form.idNo)
await session.loadMe() await session.loadMe()
ElMessage.success('实名认证已通过') ElMessage.success('实名认证已通过')
redirectAfterVerified()
} catch (error) { } catch (error) {
ElMessage.error(readError(error, '实名认证失败')) ElMessage.error(readError(error, '实名认证失败'))
} finally { } finally {