import { $fetch } from 'ofetch' import { createError, defineEventHandler, readBody } from 'h3' import { useRuntimeConfig } from '#imports' import { getTenantFromContext } from '../../../utils/tenant' /** * 企业登录 * POST /api/tender/login { enterpriseName, password } * 代理到 mp-api /api/hjc/auth/login;成功返回 LoginResult{ access_token, user }。 */ export default defineEventHandler(async (event) => { const config = useRuntimeConfig() const ctx = getTenantFromContext(event, config) const body = await readBody(event) try { const res = await $fetch('/hjc/auth/login', { baseURL: config.public.modulesApiBase, method: 'POST', headers: { TenantId: ctx.tenantId }, query: { TenantId: ctx.tenantId }, body }) as any const data = res && res.data !== undefined ? res.data : res return data } catch (error: any) { throw createError({ statusCode: error?.statusCode || error?.response?.status || 502, statusMessage: error?.statusMessage || 'Failed to login' }) } })