feat: 完成前端业务闭环与后端联调
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { hasRemoteConfig } from '@/utils/runtime-config.js'
|
||||
import { normalizeGenealogyPathId } from './genealogy-contract.js'
|
||||
import {
|
||||
normalizeLineagePersonDetail,
|
||||
normalizeLineagePersonIdentity,
|
||||
normalizeLineagePersonOptions,
|
||||
normalizeLineagePersonPage
|
||||
normalizeLineagePersonPage,
|
||||
normalizeLineageSensitiveProfile
|
||||
} from './lineage-person-contract.js'
|
||||
import { normalizeLineageTree } from './lineage-tree-contract.js'
|
||||
import {
|
||||
@@ -12,19 +12,10 @@ import {
|
||||
normalizeLineageWritePayload
|
||||
} from './lineage-write-contract.js'
|
||||
import { normalizeResourcePathId } from './request-normalizers.js'
|
||||
import { createRequestError, requestStrict } from './request-client.js'
|
||||
|
||||
const requireRemoteLineage = (message, code) => {
|
||||
if (hasRemoteConfig()) return
|
||||
throw createRequestError(message, code)
|
||||
}
|
||||
import { requestStrict } from './request-client.js'
|
||||
|
||||
export const lineageApi = {
|
||||
async getTree(genealogyId, requestOptions = {}) {
|
||||
requireRemoteLineage(
|
||||
'世系树需要真实读取服务,当前本地预览不会伪造人物节点',
|
||||
'REMOTE_READ_REQUIRED'
|
||||
)
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const tree = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/lineage/tree`,
|
||||
@@ -36,10 +27,6 @@ export const lineageApi = {
|
||||
},
|
||||
|
||||
async getPerson(genealogyId, personId, requestOptions = {}) {
|
||||
requireRemoteLineage(
|
||||
'人物详情需要真实读取服务,当前本地预览不会伪造成员资料',
|
||||
'REMOTE_READ_REQUIRED'
|
||||
)
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedPersonId = normalizeLineagePersonIdentity(personId, '人物标识')
|
||||
const person = await requestStrict({
|
||||
@@ -52,10 +39,6 @@ export const lineageApi = {
|
||||
},
|
||||
|
||||
async getPersonPage(genealogyId, { pageNum = 1, pageSize = 10, keyword = '' } = {}, requestOptions = {}) {
|
||||
requireRemoteLineage(
|
||||
'成员目录需要真实读取服务,当前本地预览不会伪造目录数据',
|
||||
'REMOTE_READ_REQUIRED'
|
||||
)
|
||||
if (!Number.isSafeInteger(pageNum) || pageNum < 1) throw new TypeError('成员目录页码无效')
|
||||
if (!Number.isSafeInteger(pageSize) || pageSize < 1) throw new TypeError('成员目录页大小无效')
|
||||
if (typeof keyword !== 'string') throw new TypeError('成员目录关键词无效')
|
||||
@@ -73,10 +56,6 @@ export const lineageApi = {
|
||||
},
|
||||
|
||||
async createPerson(genealogyId, payload, requestOptions = {}) {
|
||||
requireRemoteLineage(
|
||||
'人物创建接口在本地预览模式不可用,当前内容不会保存',
|
||||
'WRITE_UNAVAILABLE'
|
||||
)
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
return requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/lineage/persons`,
|
||||
@@ -88,10 +67,6 @@ export const lineageApi = {
|
||||
},
|
||||
|
||||
async createRelatedPerson(genealogyId, personId, relationType, payload, requestOptions = {}) {
|
||||
requireRemoteLineage(
|
||||
'人物关系写入接口在本地预览模式不可用,当前内容不会保存',
|
||||
'WRITE_UNAVAILABLE'
|
||||
)
|
||||
const relationPath = lineageRelationPath[relationType]
|
||||
if (!relationPath) throw new TypeError('人物关系类型不属于当前合同')
|
||||
|
||||
@@ -107,10 +82,6 @@ export const lineageApi = {
|
||||
},
|
||||
|
||||
async updatePerson(genealogyId, personId, payload, requestOptions = {}) {
|
||||
requireRemoteLineage(
|
||||
'人物编辑接口在本地预览模式不可用,当前内容不会保存',
|
||||
'WRITE_UNAVAILABLE'
|
||||
)
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedPersonId = normalizeLineagePersonIdentity(personId, '人物标识')
|
||||
return requestStrict({
|
||||
@@ -122,13 +93,51 @@ export const lineageApi = {
|
||||
})
|
||||
},
|
||||
|
||||
async getSensitiveProfile(genealogyId, personId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedPersonId = normalizeLineagePersonIdentity(personId, '人物标识')
|
||||
const profile = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/lineage/persons/${normalizedPersonId}/sensitive-profile`,
|
||||
method: 'GET'
|
||||
}, {
|
||||
requestController: requestOptions.requestController ?? null
|
||||
})
|
||||
return normalizeLineageSensitiveProfile(profile, normalizedPersonId)
|
||||
},
|
||||
|
||||
async saveSensitiveProfile(genealogyId, personId, hereditaryMedicalHistory, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedPersonId = normalizeLineagePersonIdentity(personId, '人物标识')
|
||||
const normalizedHistory = typeof hereditaryMedicalHistory === 'string'
|
||||
? hereditaryMedicalHistory.trim()
|
||||
: ''
|
||||
if (!normalizedHistory) throw new TypeError('遗传病史不能为空')
|
||||
if (normalizedHistory.length > 500) throw new TypeError('遗传病史长度超出当前页面合同')
|
||||
const profile = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/lineage/persons/${normalizedPersonId}/sensitive-profile`,
|
||||
method: 'PUT',
|
||||
data: { hereditaryMedicalHistory: normalizedHistory }
|
||||
}, {
|
||||
requestController: requestOptions.requestController ?? null
|
||||
})
|
||||
return normalizeLineageSensitiveProfile(profile, normalizedPersonId)
|
||||
},
|
||||
|
||||
async clearSensitiveProfile(genealogyId, personId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedPersonId = normalizeLineagePersonIdentity(personId, '人物标识')
|
||||
const profile = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/lineage/persons/${normalizedPersonId}/sensitive-profile`,
|
||||
method: 'DELETE'
|
||||
}, {
|
||||
requestController: requestOptions.requestController ?? null
|
||||
})
|
||||
return normalizeLineageSensitiveProfile(profile, normalizedPersonId)
|
||||
},
|
||||
|
||||
async deletePerson(genealogyId, personId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedPersonId = normalizeResourcePathId(personId, '人物标识')
|
||||
requireRemoteLineage(
|
||||
'世系人物写入需要真实服务,当前本地预览不会伪造结果',
|
||||
'REMOTE_WRITE_REQUIRED'
|
||||
)
|
||||
await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/lineage/persons/${normalizedPersonId}`,
|
||||
method: 'DELETE'
|
||||
@@ -140,10 +149,6 @@ export const lineageApi = {
|
||||
},
|
||||
|
||||
async updatePersonSortOrder(genealogyId, personId, sortOrder, requestOptions = {}) {
|
||||
requireRemoteLineage(
|
||||
'排行调整接口在本地预览模式不可用,当前内容不会保存',
|
||||
'WRITE_UNAVAILABLE'
|
||||
)
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
const normalizedPersonId = normalizeLineagePersonIdentity(personId, '人物标识')
|
||||
const normalizedSortOrder = Number(sortOrder)
|
||||
@@ -161,10 +166,6 @@ export const lineageApi = {
|
||||
|
||||
async getLineagePersonOptions(genealogyId, requestOptions = {}) {
|
||||
const normalizedGenealogyId = normalizeGenealogyPathId(genealogyId)
|
||||
requireRemoteLineage(
|
||||
'世系人物选项需要真实读取服务,当前本地预览不会伪造候选项',
|
||||
'REMOTE_READ_REQUIRED'
|
||||
)
|
||||
const options = await requestStrict({
|
||||
url: `/genealogy/app/genealogies/${normalizedGenealogyId}/lineage/persons/options`,
|
||||
method: 'GET'
|
||||
|
||||
Reference in New Issue
Block a user