优化小程序部分

This commit is contained in:
hero920103 committed 2026-10-31 19:17:37 +08:00
1 parent 727319a6eb
commit d4e89788c5
46 files changed
+4906 -63

No files matched your search

+19
View File
@@ -11,6 +11,20 @@ const DEFAULT_PROD_API = 'https://api.yunzer.cn'
/**
* @returns {string} 去掉末尾斜杠的 baseURL
*/
/**
* 小程序端 baseURL 兜底:微信要求 request 必须走「已配置的 https 合法域名」,
* localhost / 127.0.0.1 / 相对路径 / http 明文在体验版与正式版都会直接报
* "url not in domain list"。出现这类取值一律回退生产 API(本地调试请用 H5 端,
* 或在开发者工具勾选「不校验合法域名」时用真机调试)。
*/
function sanitizeMiniProgramBase(base) {
const b = String(base || '')
if (!b || b.startsWith('/') || !/^https:\/\//i.test(b) || /(localhost|127\.0\.0\.1)/i.test(b)) {
return DEFAULT_PROD_API
}
return b
}
export function resolveBaseURL() {
let fromEnv = ''
try {
@@ -24,7 +38,12 @@ export function resolveBaseURL() {
}
if (fromEnv && fromEnv !== 'undefined' && fromEnv !== 'null') {
// #ifdef MP
return sanitizeMiniProgramBase(String(fromEnv))
// #endif
// #ifndef MP
return String(fromEnv).replace(/\/$/, '')
// #endif
}
// #ifdef H5