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:
@@ -17,8 +17,9 @@
|
|||||||
const { isLoggedIn, user, logout } = useHjcAuth()
|
const { isLoggedIn, user, logout } = useHjcAuth()
|
||||||
const loggedIn = ref(isLoggedIn())
|
const loggedIn = ref(isLoggedIn())
|
||||||
|
|
||||||
function doLogout() {
|
async function doLogout() {
|
||||||
logout()
|
// logout() 会先通知后端(无服务端会话),再清本地凭据
|
||||||
|
await logout()
|
||||||
return navigateTo('/tender')
|
return navigateTo('/tender')
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -1,5 +1,17 @@
|
|||||||
import type { HjcUser } from '~/types/tender'
|
import type { HjcUser } from '~/types/tender'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 后端 ApiResult.code 的登录态语义。
|
||||||
|
*
|
||||||
|
* <b>HTTP 状态码恒为 200</b>,失败一律靠 body 的 code 判定:
|
||||||
|
* - 0 成功
|
||||||
|
* - 401 未登录或 token 失效 → 清本地凭据并跳登录页
|
||||||
|
* - 403 已登录但无权限(message「没有访问权限」)→ 只提示,<b>不清 token、不跳登录页</b>
|
||||||
|
* - 其他非 0 → 业务失败,展示 message
|
||||||
|
*/
|
||||||
|
export const HJC_CODE_UNAUTHORIZED = 401
|
||||||
|
export const HJC_CODE_FORBIDDEN = 403
|
||||||
|
|
||||||
/** 登录态(token 存 cookie,SSR 安全;服务器端代理从 cookie 读取并转发 Authorization) */
|
/** 登录态(token 存 cookie,SSR 安全;服务器端代理从 cookie 读取并转发 Authorization) */
|
||||||
export function useHjcAuth() {
|
export function useHjcAuth() {
|
||||||
const token = useCookie<string | null>('hjc_token', {
|
const token = useCookie<string | null>('hjc_token', {
|
||||||
@@ -12,11 +24,82 @@ export function useHjcAuth() {
|
|||||||
return !!token.value
|
return !!token.value
|
||||||
}
|
}
|
||||||
|
|
||||||
async function login(enterpriseName: string, password: string) {
|
/** 清本地凭据(token 是无状态 JWT,后端无会话,清本地即退出) */
|
||||||
|
function clearCredentials() {
|
||||||
|
token.value = null
|
||||||
|
user.value = null
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 统一处理 ApiResult 的登录态失败:**只看 body.code,不看 HTTP 状态码**。
|
||||||
|
*
|
||||||
|
* @param res 服务器代理透传的 ApiResult
|
||||||
|
* @param redirect 401 跳登录页时带上,便于登录后回跳
|
||||||
|
* @returns handled=true 表示已按登录态问题处理完(401 已跳转 / 403 带提示文案);
|
||||||
|
* handled=false 表示不是登录态问题,交调用方按业务失败处理
|
||||||
|
*/
|
||||||
|
async function handleAuthCode(
|
||||||
|
res: any,
|
||||||
|
redirect = '/'
|
||||||
|
): Promise<{ handled: boolean; message?: string }> {
|
||||||
|
const code = Number(res?.code)
|
||||||
|
if (code === HJC_CODE_UNAUTHORIZED) {
|
||||||
|
clearCredentials()
|
||||||
|
await navigateTo(`/login?redirect=${encodeURIComponent(redirect)}`)
|
||||||
|
return { handled: true }
|
||||||
|
}
|
||||||
|
if (code === HJC_CODE_FORBIDDEN) {
|
||||||
|
// 已登录但无权限:不清 token、不跳登录页,仅提示后端 message
|
||||||
|
return { handled: true, message: res?.message || '没有访问权限' }
|
||||||
|
}
|
||||||
|
return { handled: false }
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 拉取登录用图形验证码。
|
||||||
|
* 后端只返回图片(data:image/png;base64,...),不下发答案,需用户肉眼识别后输入。
|
||||||
|
*/
|
||||||
|
async function fetchCaptcha(): Promise<{ ok: boolean; image?: string; message?: string }> {
|
||||||
|
try {
|
||||||
|
// 带时间戳,避免浏览器/中间层缓存旧验证码图片
|
||||||
|
const res: any = await $fetch('/api/tender/captcha', { query: { t: Date.now() } })
|
||||||
|
if (res?.code === 0 && res.data?.image) {
|
||||||
|
return { ok: true, image: res.data.image }
|
||||||
|
}
|
||||||
|
return { ok: false, message: res?.message || '验证码获取失败' }
|
||||||
|
} catch (e: any) {
|
||||||
|
return { ok: false, message: e?.data?.statusMessage || e?.data?.message || e?.message || '验证码获取失败' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送注册短信验证码。
|
||||||
|
* @param phone 经办人手机号(即账号手机号),后端据此发码
|
||||||
|
*/
|
||||||
|
async function sendSms(phone: string): Promise<{ ok: boolean; message?: string }> {
|
||||||
|
try {
|
||||||
|
const res: any = await $fetch('/api/tender/sms', {
|
||||||
|
method: 'POST',
|
||||||
|
body: { phone }
|
||||||
|
})
|
||||||
|
if (res?.code === 0) {
|
||||||
|
return { ok: true, message: res?.message || '验证码已发送' }
|
||||||
|
}
|
||||||
|
return { ok: false, message: res?.message || '验证码发送失败' }
|
||||||
|
} catch (e: any) {
|
||||||
|
return { ok: false, message: e?.data?.statusMessage || e?.data?.message || e?.message || '验证码发送失败' }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业登录
|
||||||
|
* @param code 图形验证码(必填,后端先校验非空)
|
||||||
|
*/
|
||||||
|
async function login(enterpriseName: string, password: string, code: string) {
|
||||||
try {
|
try {
|
||||||
const res: any = await $fetch('/api/tender/login', {
|
const res: any = await $fetch('/api/tender/login', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: { enterpriseName, password }
|
body: { enterpriseName, password, code }
|
||||||
})
|
})
|
||||||
// mp-api 统一返回 ApiResult{code,message,data},code===0 成功
|
// mp-api 统一返回 ApiResult{code,message,data},code===0 成功
|
||||||
if (res?.code === 0 && res.data?.access_token) {
|
if (res?.code === 0 && res.data?.access_token) {
|
||||||
@@ -30,6 +113,10 @@ export function useHjcAuth() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 企业注册(一站式)
|
||||||
|
* @param payload 注册字段 + `code`(短信验证码,发给经办人手机号)
|
||||||
|
*/
|
||||||
async function register(payload: Record<string, any>) {
|
async function register(payload: Record<string, any>) {
|
||||||
try {
|
try {
|
||||||
const res: any = await $fetch('/api/tender/register', {
|
const res: any = await $fetch('/api/tender/register', {
|
||||||
@@ -47,10 +134,26 @@ export function useHjcAuth() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function logout() {
|
/** 退出登录:先通知后端(无服务端会话,仅为契约完整),再清本地凭据 */
|
||||||
token.value = null
|
async function logout() {
|
||||||
user.value = null
|
try {
|
||||||
|
await $fetch('/api/tender/logout', { method: 'POST' })
|
||||||
|
} catch {
|
||||||
|
// 退出接口失败不阻断本地退出:token 是无状态 JWT,清本地凭据即已登出
|
||||||
|
}
|
||||||
|
clearCredentials()
|
||||||
}
|
}
|
||||||
|
|
||||||
return { token, user, isLoggedIn, login, register, logout }
|
return {
|
||||||
|
token,
|
||||||
|
user,
|
||||||
|
isLoggedIn,
|
||||||
|
clearCredentials,
|
||||||
|
handleAuthCode,
|
||||||
|
fetchCaptcha,
|
||||||
|
sendSms,
|
||||||
|
login,
|
||||||
|
register,
|
||||||
|
logout
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+80
-3
@@ -11,6 +11,33 @@
|
|||||||
<label class="text-sm text-gray-600">密码</label>
|
<label class="text-sm text-gray-600">密码</label>
|
||||||
<input v-model="password" type="password" class="mt-1 w-full rounded-md border border-gray-300 px-4 py-2 text-sm" placeholder="请输入密码" />
|
<input v-model="password" type="password" class="mt-1 w-full rounded-md border border-gray-300 px-4 py-2 text-sm" placeholder="请输入密码" />
|
||||||
</div>
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="text-sm text-gray-600">图形验证码</label>
|
||||||
|
<div class="mt-1 flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
v-model="code"
|
||||||
|
class="w-full rounded-md border border-gray-300 px-4 py-2 text-sm"
|
||||||
|
placeholder="请输入图片中的验证码"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
<img
|
||||||
|
v-if="captchaImage"
|
||||||
|
:src="captchaImage"
|
||||||
|
alt="图形验证码"
|
||||||
|
title="看不清?点击换一张"
|
||||||
|
class="h-[38px] w-28 shrink-0 cursor-pointer rounded-md border border-gray-300 object-cover"
|
||||||
|
@click="refreshCaptcha"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
v-else
|
||||||
|
type="button"
|
||||||
|
class="h-[38px] w-28 shrink-0 rounded-md border border-gray-300 text-xs text-gray-600 hover:bg-gray-50"
|
||||||
|
@click="refreshCaptcha"
|
||||||
|
>
|
||||||
|
获取验证码
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<button type="submit" class="w-full rounded-md bg-blue-600 py-3 text-white font-medium hover:bg-blue-700 disabled:opacity-50" :disabled="loading">
|
<button type="submit" class="w-full rounded-md bg-blue-600 py-3 text-white font-medium hover:bg-blue-700 disabled:opacity-50" :disabled="loading">
|
||||||
{{ loading ? '登录中...' : '登录' }}
|
{{ loading ? '登录中...' : '登录' }}
|
||||||
</button>
|
</button>
|
||||||
@@ -25,22 +52,72 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { login } = useHjcAuth()
|
const { login, fetchCaptcha } = useHjcAuth()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const enterpriseName = ref('')
|
const enterpriseName = ref('')
|
||||||
const password = ref('')
|
const password = ref('')
|
||||||
|
/** 图形验证码(后端只下发图片,答案由用户肉眼识别后输入) */
|
||||||
|
const code = ref('')
|
||||||
|
const captchaImage = ref('')
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
|
|
||||||
|
/** 拉取/刷新图形验证码图片;失败时提示并允许点击重试 */
|
||||||
|
async function refreshCaptcha() {
|
||||||
|
code.value = ''
|
||||||
|
const res = await fetchCaptcha()
|
||||||
|
if (res.ok && res.image) {
|
||||||
|
captchaImage.value = res.image
|
||||||
|
return
|
||||||
|
}
|
||||||
|
captchaImage.value = ''
|
||||||
|
// 不覆盖已有错误(如登录失败 message),仅在无错误时提示验证码本身的问题
|
||||||
|
if (!error.value) error.value = res.message || '验证码获取失败,请点击重试'
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 登录成功后的去向:`redirect` 可能被 encodeURIComponent 过(如 /buy%3Fid%3D3),
|
||||||
|
* 这里安全解码;仅接受站内路径,避免开放重定向。
|
||||||
|
*/
|
||||||
|
function resolveRedirect() {
|
||||||
|
const raw = (route.query.redirect as string) || ''
|
||||||
|
if (!raw) return '/tender'
|
||||||
|
let target = raw
|
||||||
|
try {
|
||||||
|
target = decodeURIComponent(raw)
|
||||||
|
} catch {
|
||||||
|
target = raw
|
||||||
|
}
|
||||||
|
// 必须以单个 '/' 开头:排除 http(s)://、协议相对地址 //evil.com,
|
||||||
|
// 以及反斜杠变体 /\evil.com(部分浏览器把 '\' 归一成 '/',等价于 //evil.com)
|
||||||
|
return target.startsWith('/') && !target.startsWith('//') && !target.includes('\\') ? target : '/tender'
|
||||||
|
}
|
||||||
|
|
||||||
|
onMounted(refreshCaptcha)
|
||||||
|
|
||||||
async function submitForm() {
|
async function submitForm() {
|
||||||
error.value = ''
|
error.value = ''
|
||||||
|
if (!enterpriseName.value.trim()) {
|
||||||
|
error.value = '请输入企业名称'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!password.value) {
|
||||||
|
error.value = '请输入密码'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (!code.value.trim()) {
|
||||||
|
error.value = '请输入图形验证码'
|
||||||
|
return
|
||||||
|
}
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
const res = await login(enterpriseName.value, password.value)
|
const res = await login(enterpriseName.value.trim(), password.value, code.value.trim())
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
return navigateTo((route.query.redirect as string) || '/tender')
|
return navigateTo(resolveRedirect())
|
||||||
}
|
}
|
||||||
error.value = res.message || '登录失败'
|
error.value = res.message || '登录失败'
|
||||||
|
// 验证码一次性,失败后换一张,避免用户用同一个码反复提交
|
||||||
|
await refreshCaptcha()
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
error.value = e?.message || '登录失败'
|
error.value = e?.message || '登录失败'
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
+92
-2
@@ -12,6 +12,28 @@
|
|||||||
show-password
|
show-password
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
<!-- 短信验证码:发到「经办人手机号」(即账号手机号),注册接口的 code 用它校验 -->
|
||||||
|
<div class="space-y-1">
|
||||||
|
<label class="block text-sm text-gray-600">短信验证码</label>
|
||||||
|
<div class="flex items-center gap-2">
|
||||||
|
<input
|
||||||
|
v-model="smsCode"
|
||||||
|
class="w-full rounded-md border border-gray-300 px-4 py-2 text-sm"
|
||||||
|
placeholder="发送至上方填写的经办人手机号"
|
||||||
|
autocomplete="off"
|
||||||
|
/>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
class="h-[38px] w-32 shrink-0 rounded-md border border-gray-300 text-xs text-gray-600 hover:bg-gray-50 disabled:cursor-not-allowed disabled:opacity-50"
|
||||||
|
:disabled="countdown > 0 || sending"
|
||||||
|
@click="sendCode"
|
||||||
|
>
|
||||||
|
{{ countdown > 0 ? `${countdown} 秒后重发` : sending ? '发送中...' : '发送验证码' }}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
<p class="text-xs text-gray-400">验证码发到「经办人手机号」,该号码就是登录账号手机号</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
<p class="text-center text-xs text-gray-500">
|
<p class="text-center text-xs text-gray-500">
|
||||||
企业联系电话、企业地址选填,其余项必填;提交后等待平台审核,审核通过方可购买标书
|
企业联系电话、企业地址选填,其余项必填;提交后等待平台审核,审核通过方可购买标书
|
||||||
</p>
|
</p>
|
||||||
@@ -35,12 +57,38 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { register } = useHjcAuth()
|
const { register, sendSms } = useHjcAuth()
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const loading = ref(false)
|
const loading = ref(false)
|
||||||
const error = ref('')
|
const error = ref('')
|
||||||
const entForm = ref<any>(null)
|
const entForm = ref<any>(null)
|
||||||
|
|
||||||
|
/** 短信验证码(注册接口的 code)+ 发送倒计时 */
|
||||||
|
const smsCode = ref('')
|
||||||
|
const sending = ref(false)
|
||||||
|
const countdown = ref(0)
|
||||||
|
let countdownTimer: ReturnType<typeof setInterval> | null = null
|
||||||
|
|
||||||
|
const SMS_COUNTDOWN_SECONDS = 60
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 注册成功后的去向:`redirect` 可能被 encodeURIComponent 过(如 /buy%3Fid%3D3),
|
||||||
|
* 这里安全解码;仅接受站内路径,避免开放重定向。
|
||||||
|
*/
|
||||||
|
function resolveRedirect() {
|
||||||
|
const raw = (route.query.redirect as string) || ''
|
||||||
|
if (!raw) return '/tender'
|
||||||
|
let target = raw
|
||||||
|
try {
|
||||||
|
target = decodeURIComponent(raw)
|
||||||
|
} catch {
|
||||||
|
target = raw
|
||||||
|
}
|
||||||
|
// 必须以单个 '/' 开头:排除 http(s)://、协议相对地址 //evil.com,
|
||||||
|
// 以及反斜杠变体 /\evil.com(部分浏览器把 '\' 归一成 '/',等价于 //evil.com)
|
||||||
|
return target.startsWith('/') && !target.startsWith('//') && !target.includes('\\') ? target : '/tender'
|
||||||
|
}
|
||||||
|
|
||||||
const form = ref<Record<string, any>>({
|
const form = ref<Record<string, any>>({
|
||||||
name: '',
|
name: '',
|
||||||
password: '',
|
password: '',
|
||||||
@@ -62,9 +110,49 @@ const materials = ref<any[]>([
|
|||||||
{ materialType: 'license', label: '营业执照', materialName: '营业执照', fileUrl: '' }
|
{ materialType: 'license', label: '营业执照', materialName: '营业执照', fileUrl: '' }
|
||||||
])
|
])
|
||||||
|
|
||||||
|
/** 停止倒计时(倒计时结束或页面卸载时调用) */
|
||||||
|
function stopCountdown() {
|
||||||
|
if (countdownTimer) {
|
||||||
|
clearInterval(countdownTimer)
|
||||||
|
countdownTimer = null
|
||||||
|
}
|
||||||
|
countdown.value = 0
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 发送短信验证码到经办人手机号(= 账号手机号) */
|
||||||
|
async function sendCode() {
|
||||||
|
error.value = ''
|
||||||
|
const phone = String(form.value.agentPhone || '').trim()
|
||||||
|
if (!phone) {
|
||||||
|
error.value = '请先填写经办人手机号'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
sending.value = true
|
||||||
|
try {
|
||||||
|
const res = await sendSms(phone)
|
||||||
|
if (!res.ok) {
|
||||||
|
error.value = res.message || '验证码发送失败'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
countdown.value = SMS_COUNTDOWN_SECONDS
|
||||||
|
countdownTimer = setInterval(() => {
|
||||||
|
countdown.value -= 1
|
||||||
|
if (countdown.value <= 0) stopCountdown()
|
||||||
|
}, 1000)
|
||||||
|
} finally {
|
||||||
|
sending.value = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onUnmounted(stopCountdown)
|
||||||
|
|
||||||
async function submitForm() {
|
async function submitForm() {
|
||||||
error.value = ''
|
error.value = ''
|
||||||
if (!entForm.value?.validate()) return
|
if (!entForm.value?.validate()) return
|
||||||
|
if (!smsCode.value.trim()) {
|
||||||
|
error.value = '请输入短信验证码'
|
||||||
|
return
|
||||||
|
}
|
||||||
loading.value = true
|
loading.value = true
|
||||||
try {
|
try {
|
||||||
// buildPayload 返回 { name, ... };注册接口用 enterpriseName 作为登录账号
|
// buildPayload 返回 { name, ... };注册接口用 enterpriseName 作为登录账号
|
||||||
@@ -72,10 +160,12 @@ async function submitForm() {
|
|||||||
const res = await register({
|
const res = await register({
|
||||||
enterpriseName: name,
|
enterpriseName: name,
|
||||||
password: form.value.password,
|
password: form.value.password,
|
||||||
|
// code = 短信验证码(登录接口的 code 是图形验证码,两者不同)
|
||||||
|
code: smsCode.value.trim(),
|
||||||
...rest
|
...rest
|
||||||
})
|
})
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
return navigateTo((route.query.redirect as string) || '/tender')
|
return navigateTo(resolveRedirect())
|
||||||
}
|
}
|
||||||
error.value = res.message || '注册失败'
|
error.value = res.message || '注册失败'
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
|
|||||||
@@ -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>
|
<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>
|
||||||
|
|
||||||
|
<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-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 v-for="o in orders" :key="o.id" class="rounded-lg border border-gray-200 p-5">
|
||||||
<div class="flex items-start justify-between">
|
<div class="flex items-start justify-between">
|
||||||
@@ -32,10 +34,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { isLoggedIn } = useHjcAuth()
|
const { isLoggedIn, handleAuthCode } = useHjcAuth()
|
||||||
const loggedIn = ref(false)
|
const loggedIn = ref(false)
|
||||||
const orders = shallowRef<any[]>([])
|
const orders = shallowRef<any[]>([])
|
||||||
const loaded = ref(false)
|
const loaded = ref(false)
|
||||||
|
const error = ref('')
|
||||||
|
|
||||||
function formatMoney(n?: number | string) {
|
function formatMoney(n?: number | string) {
|
||||||
return Number(n ?? 0).toFixed(2)
|
return Number(n ?? 0).toFixed(2)
|
||||||
@@ -54,8 +57,18 @@ function payStatusClass(s?: number) {
|
|||||||
|
|
||||||
loggedIn.value = isLoggedIn()
|
loggedIn.value = isLoggedIn()
|
||||||
if (loggedIn.value) {
|
if (loggedIn.value) {
|
||||||
|
// 代理原样透传 ApiResult:按 body.code 判定(HTTP 状态码恒为 200,不可用于判定)
|
||||||
const res: any = await $fetch('/api/tender/my-orders')
|
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
|
loaded.value = true
|
||||||
} else {
|
} else {
|
||||||
loaded.value = true
|
loaded.value = true
|
||||||
|
|||||||
@@ -47,7 +47,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
const { isLoggedIn } = useHjcAuth()
|
const { isLoggedIn, handleAuthCode } = useHjcAuth()
|
||||||
const loggedIn = ref(false)
|
const loggedIn = ref(false)
|
||||||
const authStatus = ref(-1)
|
const authStatus = ref(-1)
|
||||||
const rejectReason = ref('')
|
const rejectReason = ref('')
|
||||||
@@ -88,11 +88,24 @@ const authStatusClass = computed(() => {
|
|||||||
const readonly = computed(() => authStatus.value === 0 || authStatus.value === 1)
|
const readonly = computed(() => authStatus.value === 0 || authStatus.value === 1)
|
||||||
|
|
||||||
async function load() {
|
async function load() {
|
||||||
|
// 代理原样透传 ApiResult:按 body.code 判定(HTTP 状态码恒为 200,不可用于判定)
|
||||||
const res: any = await $fetch('/api/tender/enterprise')
|
const res: any = await $fetch('/api/tender/enterprise')
|
||||||
if (res) {
|
const auth = await handleAuthCode(res, '/tender/qualification')
|
||||||
authStatus.value = res.authStatus ?? -1
|
if (auth.handled) {
|
||||||
rejectReason.value = res.rejectReason || ''
|
// 401 已清凭据并跳登录页;403 只提示「没有访问权限」,不清 token
|
||||||
entForm.value?.fill(res)
|
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',
|
method: 'POST',
|
||||||
body: entForm.value.buildPayload()
|
body: entForm.value.buildPayload()
|
||||||
})
|
})
|
||||||
|
const auth = await handleAuthCode(res, '/tender/qualification')
|
||||||
|
if (auth.handled) {
|
||||||
|
error.value = auth.message || ''
|
||||||
|
return
|
||||||
|
}
|
||||||
if (res?.code !== 0) {
|
if (res?.code !== 0) {
|
||||||
error.value = res?.message || '提交失败'
|
error.value = res?.message || '提交失败'
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ import type { Tender } from '~/types/tender'
|
|||||||
|
|
||||||
const route = useRoute()
|
const route = useRoute()
|
||||||
const id = route.query.id as string
|
const id = route.query.id as string
|
||||||
const { isLoggedIn } = useHjcAuth()
|
const { isLoggedIn, handleAuthCode } = useHjcAuth()
|
||||||
|
|
||||||
const loggedIn = ref(false)
|
const loggedIn = ref(false)
|
||||||
const tender = shallowRef<Tender | null>(null)
|
const tender = shallowRef<Tender | null>(null)
|
||||||
@@ -102,6 +102,7 @@ async function submit() {
|
|||||||
error.value = ''
|
error.value = ''
|
||||||
submitting.value = true
|
submitting.value = true
|
||||||
try {
|
try {
|
||||||
|
// 代理原样透传 ApiResult:按 body.code 判定(HTTP 状态码恒为 200,不可用于判定)
|
||||||
const order: any = await $fetch('/api/tender/order', {
|
const order: any = await $fetch('/api/tender/order', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: {
|
body: {
|
||||||
@@ -112,15 +113,31 @@ async function submit() {
|
|||||||
contactEmail: form.contactEmail
|
contactEmail: form.contactEmail
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
if (order && order.orderNo) {
|
const orderAuth = await handleAuthCode(order, redirect.value)
|
||||||
orderNo.value = order.orderNo
|
if (orderAuth.handled) {
|
||||||
totalAmount.value = order.totalAmount || 0
|
// 401 已清凭据并跳登录页;403 只提示「没有访问权限」,不清 token
|
||||||
// 发起支付
|
error.value = orderAuth.message || ''
|
||||||
const pay: any = await $fetch('/api/tender/pay', { method: 'POST', body: { orderNo: order.orderNo } })
|
return
|
||||||
codeUrl.value = pay?.codeUrl || ''
|
}
|
||||||
step.value = 'pay'
|
if (order?.code !== 0) {
|
||||||
} else {
|
|
||||||
error.value = order?.message || '下单失败'
|
error.value = order?.message || '下单失败'
|
||||||
|
return
|
||||||
|
}
|
||||||
|
orderNo.value = order.data?.orderNo || ''
|
||||||
|
totalAmount.value = order.data?.totalAmount || 0
|
||||||
|
// 发起支付
|
||||||
|
const pay: any = await $fetch('/api/tender/pay', { method: 'POST', body: { orderNo: orderNo.value } })
|
||||||
|
const payAuth = await handleAuthCode(pay, redirect.value)
|
||||||
|
if (payAuth.handled) {
|
||||||
|
error.value = payAuth.message || ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 订单已创建:即使发起支付失败也停在支付步骤,避免用户重提交产生重复订单
|
||||||
|
step.value = 'pay'
|
||||||
|
if (pay?.code === 0) {
|
||||||
|
codeUrl.value = pay.data?.codeUrl || ''
|
||||||
|
} else {
|
||||||
|
error.value = pay?.message || '发起支付失败,请稍后重试'
|
||||||
}
|
}
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
error.value = e?.data?.message || e?.message || '下单失败'
|
error.value = e?.data?.message || e?.message || '下单失败'
|
||||||
@@ -133,7 +150,16 @@ async function markPaid() {
|
|||||||
error.value = ''
|
error.value = ''
|
||||||
marking.value = true
|
marking.value = true
|
||||||
try {
|
try {
|
||||||
await $fetch('/api/tender/mark-paid', { method: 'PUT', body: { orderNo: orderNo.value } })
|
const res: any = await $fetch('/api/tender/mark-paid', { method: 'PUT', body: { orderNo: orderNo.value } })
|
||||||
|
const auth = await handleAuthCode(res, redirect.value)
|
||||||
|
if (auth.handled) {
|
||||||
|
error.value = auth.message || ''
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (res?.code !== 0) {
|
||||||
|
error.value = res?.message || '确认失败'
|
||||||
|
return
|
||||||
|
}
|
||||||
step.value = 'done'
|
step.value = 'done'
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
error.value = e?.data?.message || e?.message || '确认失败'
|
error.value = e?.data?.message || e?.message || '确认失败'
|
||||||
|
|||||||
@@ -0,0 +1,32 @@
|
|||||||
|
import { $fetch } from 'ofetch'
|
||||||
|
import { createError, defineEventHandler } from 'h3'
|
||||||
|
import { useRuntimeConfig } from '#imports'
|
||||||
|
import { getTenantFromContext } from '../../utils/tenant'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 图形验证码(登录用)
|
||||||
|
* GET /api/tender/captcha
|
||||||
|
* 代理到 mp-api /api/hjc/auth/captcha;匿名可访问。
|
||||||
|
*
|
||||||
|
* 约定:mp-api 原样透传 ApiResult{code,message,data},
|
||||||
|
* data = { image: 'data:image/png;base64,...' }。<b>后端刻意不下发答案</b>,
|
||||||
|
* 必须把图片显示给用户肉眼识别后输入,前端不得(也无法)自行校验答案。
|
||||||
|
*/
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
const ctx = getTenantFromContext(event, config)
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await $fetch('/hjc/auth/captcha', {
|
||||||
|
baseURL: config.public.modulesApiBase,
|
||||||
|
method: 'GET',
|
||||||
|
headers: { TenantId: ctx.tenantId },
|
||||||
|
query: { TenantId: ctx.tenantId }
|
||||||
|
})
|
||||||
|
} catch (error: any) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
statusMessage: error?.data?.message || error?.statusMessage || 'Failed to fetch captcha'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -7,6 +7,10 @@ import { getTenantFromContext } from '../../utils/tenant'
|
|||||||
* 我的企业资质(含证件材料)
|
* 我的企业资质(含证件材料)
|
||||||
* GET /api/tender/enterprise
|
* GET /api/tender/enterprise
|
||||||
* 代理到 mp-api /api/hjc/enterprise/my;需登录态。
|
* 代理到 mp-api /api/hjc/enterprise/my;需登录态。
|
||||||
|
*
|
||||||
|
* 约定:原样透传 ApiResult{code,message,data}。HTTP 状态码恒为 200,
|
||||||
|
* 「未登录/token 失效」是 code=401、「无权限」是 code=403,前端必须按 code 判定;
|
||||||
|
* 故这里**不能**只取 data,否则登录态失败会被误当成「未提交资质」。
|
||||||
*/
|
*/
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
@@ -15,16 +19,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await $fetch('/hjc/enterprise/my', {
|
return await $fetch('/hjc/enterprise/my', {
|
||||||
baseURL: config.public.modulesApiBase,
|
baseURL: config.public.modulesApiBase,
|
||||||
headers: {
|
headers: {
|
||||||
TenantId: ctx.tenantId,
|
TenantId: ctx.tenantId,
|
||||||
...(auth ? { Authorization: auth } : {})
|
...(auth ? { Authorization: auth } : {})
|
||||||
},
|
},
|
||||||
query: { TenantId: ctx.tenantId }
|
query: { TenantId: ctx.tenantId }
|
||||||
}) as any
|
})
|
||||||
const data = res && res.data !== undefined ? res.data : res
|
|
||||||
return data
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: error?.statusCode || error?.response?.status || 502,
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
import { $fetch } from 'ofetch'
|
||||||
|
import { createError, defineEventHandler, getHeader, getCookie } from 'h3'
|
||||||
|
import { useRuntimeConfig } from '#imports'
|
||||||
|
import { getTenantFromContext } from '../../utils/tenant'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 退出登录
|
||||||
|
* POST /api/tender/logout
|
||||||
|
* 代理到 mp-api /api/hjc/auth/logout。
|
||||||
|
*
|
||||||
|
* 说明:后端不维护服务端会话与 token 黑名单(token 是无状态 JWT),
|
||||||
|
* 调用本接口只为契约完整;<b>前端清本地凭据才是真正生效的退出</b>。
|
||||||
|
*/
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
const ctx = getTenantFromContext(event, config)
|
||||||
|
const cookieToken = getCookie(event, 'hjc_token')
|
||||||
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await $fetch('/hjc/auth/logout', {
|
||||||
|
baseURL: config.public.modulesApiBase,
|
||||||
|
method: 'POST',
|
||||||
|
headers: {
|
||||||
|
TenantId: ctx.tenantId,
|
||||||
|
...(auth ? { Authorization: auth } : {})
|
||||||
|
},
|
||||||
|
query: { TenantId: ctx.tenantId }
|
||||||
|
})
|
||||||
|
} catch (error: any) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
statusMessage: error?.data?.message || error?.statusMessage || 'Failed to logout'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
@@ -7,6 +7,8 @@ import { getTenantFromContext } from '../../utils/tenant'
|
|||||||
* 标记订单已支付(幂等)并触发一站式推送
|
* 标记订单已支付(幂等)并触发一站式推送
|
||||||
* PUT /api/tender/mark-paid { orderNo }
|
* PUT /api/tender/mark-paid { orderNo }
|
||||||
* 代理到 mp-api /api/hjc/order/mark-paid;需登录态。
|
* 代理到 mp-api /api/hjc/order/mark-paid;需登录态。
|
||||||
|
*
|
||||||
|
* 约定:原样透传 ApiResult{code,message,data},由前端按 code 判定登录态与业务失败。
|
||||||
*/
|
*/
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
@@ -16,7 +18,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await $fetch('/hjc/order/mark-paid', {
|
return await $fetch('/hjc/order/mark-paid', {
|
||||||
baseURL: config.public.modulesApiBase,
|
baseURL: config.public.modulesApiBase,
|
||||||
method: 'PUT',
|
method: 'PUT',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -25,9 +27,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
},
|
},
|
||||||
query: { TenantId: ctx.tenantId },
|
query: { TenantId: ctx.tenantId },
|
||||||
body
|
body
|
||||||
}) as any
|
})
|
||||||
const data = res && res.data !== undefined ? res.data : res
|
|
||||||
return data
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: error?.statusCode || error?.response?.status || 502,
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ import { getTenantFromContext } from '../../utils/tenant'
|
|||||||
* 我的订单列表
|
* 我的订单列表
|
||||||
* GET /api/tender/my-orders
|
* GET /api/tender/my-orders
|
||||||
* 代理到 mp-api /api/hjc/order/my;需登录态。
|
* 代理到 mp-api /api/hjc/order/my;需登录态。
|
||||||
|
*
|
||||||
|
* 约定:原样透传 ApiResult{code,message,data}。HTTP 状态码恒为 200,
|
||||||
|
* 「未登录/token 失效」是 code=401、「无权限」是 code=403,前端必须按 code 判定;
|
||||||
|
* 故这里**不能**只取 data,否则登录态失败会被误当成「没有订单」。
|
||||||
*/
|
*/
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
@@ -15,16 +19,14 @@ export default defineEventHandler(async (event) => {
|
|||||||
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await $fetch('/hjc/order/my', {
|
return await $fetch('/hjc/order/my', {
|
||||||
baseURL: config.public.modulesApiBase,
|
baseURL: config.public.modulesApiBase,
|
||||||
headers: {
|
headers: {
|
||||||
TenantId: ctx.tenantId,
|
TenantId: ctx.tenantId,
|
||||||
...(auth ? { Authorization: auth } : {})
|
...(auth ? { Authorization: auth } : {})
|
||||||
},
|
},
|
||||||
query: { TenantId: ctx.tenantId }
|
query: { TenantId: ctx.tenantId }
|
||||||
}) as any
|
})
|
||||||
const data = res && res.data !== undefined ? res.data : res
|
|
||||||
return data
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: error?.statusCode || error?.response?.status || 502,
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
|||||||
@@ -7,6 +7,9 @@ import { getTenantFromContext } from '../../utils/tenant'
|
|||||||
* 创建标书订单
|
* 创建标书订单
|
||||||
* POST /api/tender/order { projectId, quantity, contactName, contactPhone, contactEmail }
|
* POST /api/tender/order { projectId, quantity, contactName, contactPhone, contactEmail }
|
||||||
* 代理到 mp-api(mp-java) /api/hjc/order/create;需登录态(从 cookie hjc_token 或 Authorization 透传)。
|
* 代理到 mp-api(mp-java) /api/hjc/order/create;需登录态(从 cookie hjc_token 或 Authorization 透传)。
|
||||||
|
*
|
||||||
|
* 约定:原样透传 ApiResult{code,message,data},由前端按 code 判定
|
||||||
|
* (401 未登录/token 失效、403 无权限、其余为业务失败)。
|
||||||
*/
|
*/
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
@@ -16,7 +19,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await $fetch('/hjc/order/create', {
|
return await $fetch('/hjc/order/create', {
|
||||||
baseURL: config.public.modulesApiBase,
|
baseURL: config.public.modulesApiBase,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -25,8 +28,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
},
|
},
|
||||||
query: { TenantId: ctx.tenantId },
|
query: { TenantId: ctx.tenantId },
|
||||||
body
|
body
|
||||||
}) as any
|
})
|
||||||
return res?.data ?? res
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: error?.statusCode || error?.response?.status || 502,
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
|||||||
@@ -7,6 +7,8 @@ import { getTenantFromContext } from '../../utils/tenant'
|
|||||||
* 发起支付(微信Native扫码,返回 codeUrl)
|
* 发起支付(微信Native扫码,返回 codeUrl)
|
||||||
* POST /api/tender/pay { orderNo }
|
* POST /api/tender/pay { orderNo }
|
||||||
* 代理到 mp-api /api/hjc/order/pay;需登录态。
|
* 代理到 mp-api /api/hjc/order/pay;需登录态。
|
||||||
|
*
|
||||||
|
* 约定:原样透传 ApiResult{code,message,data},由前端按 code 判定登录态与业务失败。
|
||||||
*/
|
*/
|
||||||
export default defineEventHandler(async (event) => {
|
export default defineEventHandler(async (event) => {
|
||||||
const config = useRuntimeConfig()
|
const config = useRuntimeConfig()
|
||||||
@@ -16,7 +18,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
const auth = getHeader(event, 'authorization') || (cookieToken ? `Bearer ${cookieToken}` : null)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await $fetch('/hjc/order/pay', {
|
return await $fetch('/hjc/order/pay', {
|
||||||
baseURL: config.public.modulesApiBase,
|
baseURL: config.public.modulesApiBase,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -25,9 +27,7 @@ export default defineEventHandler(async (event) => {
|
|||||||
},
|
},
|
||||||
query: { TenantId: ctx.tenantId },
|
query: { TenantId: ctx.tenantId },
|
||||||
body
|
body
|
||||||
}) as any
|
})
|
||||||
const data = res && res.data !== undefined ? res.data : res
|
|
||||||
return data
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
throw createError({
|
throw createError({
|
||||||
statusCode: error?.statusCode || error?.response?.status || 502,
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { $fetch } from 'ofetch'
|
||||||
|
import { createError, defineEventHandler, readBody } from 'h3'
|
||||||
|
import { useRuntimeConfig } from '#imports'
|
||||||
|
import { getTenantFromContext } from '../../utils/tenant'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送注册短信验证码
|
||||||
|
* POST /api/tender/sms { phone }
|
||||||
|
* 代理到 mp-api /api/hjc/auth/sms;匿名可访问(注册在登录前调用)。
|
||||||
|
*
|
||||||
|
* 说明:`phone` 必须传<b>经办人手机号</b>——后端以「经办人手机号」作为账号手机号建号,
|
||||||
|
* 注册接口的 `code` 校验的正是发给该号码的短信验证码。
|
||||||
|
* 原样透传 ApiResult{code,message,data},成功 message 为「验证码已发送」。
|
||||||
|
*/
|
||||||
|
export default defineEventHandler(async (event) => {
|
||||||
|
const config = useRuntimeConfig()
|
||||||
|
const ctx = getTenantFromContext(event, config)
|
||||||
|
const body = await readBody(event)
|
||||||
|
|
||||||
|
try {
|
||||||
|
return await $fetch('/hjc/auth/sms', {
|
||||||
|
baseURL: config.public.modulesApiBase,
|
||||||
|
method: 'POST',
|
||||||
|
headers: { TenantId: ctx.tenantId },
|
||||||
|
query: { TenantId: ctx.tenantId },
|
||||||
|
body
|
||||||
|
})
|
||||||
|
} catch (error: any) {
|
||||||
|
throw createError({
|
||||||
|
statusCode: error?.statusCode || error?.response?.status || 502,
|
||||||
|
statusMessage: error?.data?.message || error?.statusMessage || 'Failed to send sms'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user