ectd-ui/src/api/login/trialApplication.ts
2026-09-15 10:54:51 +08:00

44 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export interface TrialSubmitPayload {
contact: string
company: string
businessEmail: string
phone: string
wechat: string
}
const TRIAL_SUBMIT_REMOTE = 'https://www.jinzhiqiaotech.com/submit'
const TRIAL_PROXY_PATH = 'jinzhiqiao-trial-submit'
/**
* 试用申请接口地址。
* - 开发环境:走 Vite 同源路径(见 vite.config.ts proxy),避免浏览器 CORS。
* - 生产环境:直连远程;若仍报 CORS,请在 nginx/网关将同域路径反向代理到上述地址,并设 env VITE_TRIAL_SUBMIT_URL。
*/
export function getTrialSubmitUrl(): string {
const fromEnv = import.meta.env.VITE_TRIAL_SUBMIT_URL as string | undefined
if (fromEnv) {
return fromEnv
}
if (import.meta.env.DEV) {
const base = import.meta.env.BASE_URL || '/'
const prefix = base === '/' ? '' : String(base).replace(/\/$/, '')
return `${prefix}/${TRIAL_PROXY_PATH}`.replace(/\/+/g, '/')
}
return TRIAL_SUBMIT_REMOTE
}
/** 试用申请(站外接口,使用 fetch 避免走项目 axios baseURL 与拦截器) */
export async function submitTrialApplication(payload: TrialSubmitPayload): Promise<void> {
const res = await fetch(getTrialSubmitUrl(), {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(payload)
})
if (!res.ok) {
const text = await res.text().catch(() => '')
throw new Error(text || `HTTP ${res.status}`)
}
}