feat: migrate app routes and business modules
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
import { hasRemoteConfig } from '@/utils/runtime-config.js'
|
||||
import {
|
||||
normalizeRegionCode,
|
||||
normalizeRegionParentCode,
|
||||
normalizeRegionSelectorItems
|
||||
} from './region-contract.js'
|
||||
import {
|
||||
createRequestError,
|
||||
requestStrict
|
||||
} from './request-client.js'
|
||||
|
||||
const requireRemoteRegion = (label) => {
|
||||
if (hasRemoteConfig()) return
|
||||
throw createRequestError(`${label}读取需要真实服务,当前本地预览不会伪造结果`, 'REMOTE_READ_REQUIRED')
|
||||
}
|
||||
|
||||
export const regionApi = {
|
||||
async getRegionChildren(parentCode, requestOptions = {}) {
|
||||
requireRemoteRegion('地区选择')
|
||||
const regionChildren = await requestStrict({
|
||||
url: '/genealogy/app/region/children',
|
||||
method: 'GET',
|
||||
data: { parentCode: normalizeRegionParentCode(parentCode) }
|
||||
}, {
|
||||
requestController: requestOptions.requestController ?? null
|
||||
})
|
||||
return normalizeRegionSelectorItems(regionChildren)
|
||||
},
|
||||
|
||||
async getRegionPath(regionCode, requestOptions = {}) {
|
||||
requireRemoteRegion('行政区划路径')
|
||||
const regionPath = await requestStrict({
|
||||
url: `/genealogy/app/region/path/${encodeURIComponent(normalizeRegionCode(regionCode))}`,
|
||||
method: 'GET'
|
||||
}, {
|
||||
requestController: requestOptions.requestController ?? null
|
||||
})
|
||||
if (!Array.isArray(regionPath)) {
|
||||
throw createRequestError('行政区划路径响应不是列表', 'REGION_PATH_RESPONSE_INVALID')
|
||||
}
|
||||
return regionPath
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user