feat(tender): 登录加图形验证码、注册加短信验证码;改按 body.code 判定 401/403
- 新增 captcha / sms / logout 三个 Nuxt server 代理 - 修复代理把 ApiResult 拍扁成 data 的问题(my-orders、enterprise、order、pay、 mark-paid):登录态失败被前端当成「没有订单 / 未提交资质」,无法区分 - 新增 handleAuthCode 统一处理:401 → 清凭据并跳 /login?redirect=…; 403 → 只提示「没有访问权限」,不清 token、不跳登录页 - 登录页与注册页分别接入图形验证码与短信验证码(含 60s 倒计时) - 修复回跳开放重定向:redirect 参数安全解码且只接受站内路径 (拒绝 //evil.com、https://… 及反斜杠变体 /\evil.com) - 下单成功但发起支付失败时停在支付步,避免用户重提交产生重复订单
This commit is contained in:
@@ -10,6 +10,8 @@
|
||||
<NuxtLink to="/login?redirect=/tender/orders" class="mt-4 inline-block rounded-md bg-blue-600 px-6 py-2 text-white hover:bg-blue-700">去登录</NuxtLink>
|
||||
</div>
|
||||
|
||||
<div v-else-if="error" class="py-20 text-center text-red-500">{{ error }}</div>
|
||||
|
||||
<div v-else-if="orders.length" class="space-y-4">
|
||||
<div v-for="o in orders" :key="o.id" class="rounded-lg border border-gray-200 p-5">
|
||||
<div class="flex items-start justify-between">
|
||||
@@ -32,10 +34,11 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { isLoggedIn } = useHjcAuth()
|
||||
const { isLoggedIn, handleAuthCode } = useHjcAuth()
|
||||
const loggedIn = ref(false)
|
||||
const orders = shallowRef<any[]>([])
|
||||
const loaded = ref(false)
|
||||
const error = ref('')
|
||||
|
||||
function formatMoney(n?: number | string) {
|
||||
return Number(n ?? 0).toFixed(2)
|
||||
@@ -54,8 +57,18 @@ function payStatusClass(s?: number) {
|
||||
|
||||
loggedIn.value = isLoggedIn()
|
||||
if (loggedIn.value) {
|
||||
// 代理原样透传 ApiResult:按 body.code 判定(HTTP 状态码恒为 200,不可用于判定)
|
||||
const res: any = await $fetch('/api/tender/my-orders')
|
||||
orders.value = Array.isArray(res) ? res : []
|
||||
const auth = await handleAuthCode(res, '/tender/orders')
|
||||
if (auth.handled) {
|
||||
// 401 已清凭据并跳登录页;403 只提示「没有访问权限」,不清 token
|
||||
error.value = auth.message || ''
|
||||
loggedIn.value = isLoggedIn()
|
||||
} else if (res?.code === 0) {
|
||||
orders.value = Array.isArray(res.data) ? res.data : []
|
||||
} else {
|
||||
error.value = res?.message || '订单加载失败'
|
||||
}
|
||||
loaded.value = true
|
||||
} else {
|
||||
loaded.value = true
|
||||
|
||||
@@ -47,7 +47,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
const { isLoggedIn } = useHjcAuth()
|
||||
const { isLoggedIn, handleAuthCode } = useHjcAuth()
|
||||
const loggedIn = ref(false)
|
||||
const authStatus = ref(-1)
|
||||
const rejectReason = ref('')
|
||||
@@ -88,11 +88,24 @@ const authStatusClass = computed(() => {
|
||||
const readonly = computed(() => authStatus.value === 0 || authStatus.value === 1)
|
||||
|
||||
async function load() {
|
||||
// 代理原样透传 ApiResult:按 body.code 判定(HTTP 状态码恒为 200,不可用于判定)
|
||||
const res: any = await $fetch('/api/tender/enterprise')
|
||||
if (res) {
|
||||
authStatus.value = res.authStatus ?? -1
|
||||
rejectReason.value = res.rejectReason || ''
|
||||
entForm.value?.fill(res)
|
||||
const auth = await handleAuthCode(res, '/tender/qualification')
|
||||
if (auth.handled) {
|
||||
// 401 已清凭据并跳登录页;403 只提示「没有访问权限」,不清 token
|
||||
error.value = auth.message || ''
|
||||
loggedIn.value = isLoggedIn()
|
||||
return
|
||||
}
|
||||
if (res?.code !== 0) {
|
||||
error.value = res?.message || '资质信息加载失败'
|
||||
return
|
||||
}
|
||||
const data = res.data
|
||||
if (data) {
|
||||
authStatus.value = data.authStatus ?? -1
|
||||
rejectReason.value = data.rejectReason || ''
|
||||
entForm.value?.fill(data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -106,6 +119,11 @@ async function submit() {
|
||||
method: 'POST',
|
||||
body: entForm.value.buildPayload()
|
||||
})
|
||||
const auth = await handleAuthCode(res, '/tender/qualification')
|
||||
if (auth.handled) {
|
||||
error.value = auth.message || ''
|
||||
return
|
||||
}
|
||||
if (res?.code !== 0) {
|
||||
error.value = res?.message || '提交失败'
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user