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:
2026-09-10 23:44:19 +08:00
parent 5e7372d0c7
commit d0c2dd17cb
15 changed files with 485 additions and 49 deletions
+23 -5
View File
@@ -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