20260511173242

This commit is contained in:
oneao committed 2026-05-11 17:32:43 +08:00
1 parent 56f5ba4e6b
commit 364d29dbaa
20 files changed
+2992 -88

No files matched your search

@@ -6,26 +6,45 @@ import { joinUrl } from '@/utils/common'
import { isH5 } from '@/utils/platform'
let dbJsonCache: Record<string, string> | null = null
let dbJsonPromise: Promise<Record<string, string>> | null = null
/**
* ======================
* 读取机构配置
* 读取机构配置(带缓存)
* ======================
*/
function readDbJson(): Promise<Record<string, string>> {
return new Promise((resolve, reject) => {
if (dbJsonCache) {
return Promise.resolve(dbJsonCache)
}
if (dbJsonPromise) {
return dbJsonPromise
}
dbJsonPromise = new Promise((resolve, reject) => {
if (isH5) {
const timestamp = Date.now()
uni.request({
url: `/g3ocr-app/static/db.json?t=${timestamp}`,
url: '/g3ocr-app/static/db.json',
method: 'GET',
success: r => resolve(r.data as Record<string, string>),
fail: err => reject(err),
success: (r) => {
dbJsonCache = r.data as Record<string, string>
resolve(dbJsonCache)
},
fail: (err) => {
dbJsonPromise = null
reject(err)
},
})
}
else {
resolve(dbJson as Record<string, string>)
dbJsonCache = dbJson as Record<string, string>
resolve(dbJsonCache)
}
})
return dbJsonPromise
}
/**
@@ -38,23 +57,7 @@ export async function getOrgBaseUrl(orgid: string): Promise<string> {
return ''
}
let dbRes: Record<string, string> = {}
// 读取配置(和你原逻辑保持一致)
if (isH5) {
const timestamp = Date.now()
dbRes = await new Promise((resolve, reject) => {
uni.request({
url: `/g3ocr-app/static/db.json?t=${timestamp}`,
method: 'GET',
success: res => resolve(res.data as Record<string, string>),
fail: err => reject(err),
})
})
}
else {
dbRes = dbJson as Record<string, string>
}
const dbRes = await readDbJson()
if (!dbRes || Object.keys(dbRes).length === 0) {
throw new Error('机构配置获取失败')
@@ -66,7 +69,6 @@ export async function getOrgBaseUrl(orgid: string): Promise<string> {
throw new Error('机构码无效')
}
// 👉 关键:只返回原始 JSON 里的值
return baseUrl
}