feat(演示): 持久化 Mock 数据并打通文档库发起签署闭环
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* 本地演示文书库的读取与转换(仅 Mock 模式)。
|
||||
*
|
||||
* 管理端文档库的数据只存在前端:科室在 Word 编辑器里建好文书后写进 localStorage。
|
||||
* 文档库页面和签署侧的模板列表都要读这份数据,共享同一份读取逻辑,
|
||||
* 否则会出现「文档库刚建好文书,签署工作台却选不到」。
|
||||
*
|
||||
* 这里只声明实际用到的字段,不绑定文档库页面的类型,避免 api 层反向依赖 views。
|
||||
*/
|
||||
import type { SigningMethod, SigningTemplate } from '@/api/workbench/types'
|
||||
|
||||
import { MOCK_STORAGE_KEYS, readMockState } from './mock-storage'
|
||||
|
||||
interface LocalDocument {
|
||||
id: string
|
||||
name: string
|
||||
code: string
|
||||
version: string
|
||||
description?: string
|
||||
versionId?: string
|
||||
departmentId?: string | null
|
||||
campusId?: string | null
|
||||
contentHtml?: string
|
||||
}
|
||||
|
||||
interface LocalCategory {
|
||||
name: string
|
||||
documents: LocalDocument[]
|
||||
}
|
||||
|
||||
interface LocalDepartment {
|
||||
key: string
|
||||
name: string
|
||||
categories: LocalCategory[]
|
||||
}
|
||||
|
||||
/**
|
||||
* 把本地保存的文档库摊平成签署模板。
|
||||
* 科室刚建好的文书因此能直接在签署工作台、文档库「发起」里选到。
|
||||
*/
|
||||
export function readLocalSigningTemplates(): SigningTemplate[] {
|
||||
const departments = readMockState<LocalDepartment[]>(MOCK_STORAGE_KEYS.documentLibrary) ?? []
|
||||
|
||||
return departments.flatMap((department) =>
|
||||
(department.categories ?? []).flatMap((category) =>
|
||||
(category.documents ?? []).map((document) => ({
|
||||
id: document.id,
|
||||
versionId: document.versionId ?? document.id,
|
||||
name: document.name,
|
||||
code: document.code,
|
||||
version: document.version,
|
||||
department: department.name,
|
||||
departmentId: document.departmentId ?? null,
|
||||
campusId: document.campusId ?? undefined,
|
||||
category: category.name,
|
||||
description: document.description ?? '',
|
||||
supportedMethods: ['pad', 'sms'] as SigningMethod[],
|
||||
contentHtml: document.contentHtml,
|
||||
})),
|
||||
),
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user