发布需要校验实名认证
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { onMounted, reactive, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
|
||||
import { getRealnameStatus, startRealname, type RealnameStatus } from '@/api/realname'
|
||||
import { useSessionStore } from '@/stores/session'
|
||||
@@ -8,6 +9,8 @@ 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({
|
||||
@@ -17,21 +20,41 @@ const form = reactive({
|
||||
|
||||
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 {
|
||||
|
||||
Reference in New Issue
Block a user