feat(演示): 持久化 Mock 数据并打通文档库发起签署闭环
This commit is contained in:
@@ -1,17 +1,19 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, reactive, ref } from 'vue'
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue'
|
||||
import { ElMessage, ElMessageBox } from 'element-plus'
|
||||
import { useRouter } from 'vue-router'
|
||||
|
||||
import NewSigningTaskDialog from '@/components/signing/NewSigningTaskDialog.vue'
|
||||
import type { SigningTemplate } from '@/api/workbench/types'
|
||||
import type { SigningTaskRecord, SigningTemplate } from '@/api/workbench/types'
|
||||
import type { CampusRecord, DepartmentRecord } from '@/api/management/types'
|
||||
import { clearMockState } from '@/utils/mock-storage'
|
||||
|
||||
import DocumentFilterTabs from './components/DocumentFilterTabs.vue'
|
||||
import DocumentLibraryHeader from './components/DocumentLibraryHeader.vue'
|
||||
import DocumentPreviewDialog from './components/DocumentPreviewDialog.vue'
|
||||
import DocumentTemplateCard from './components/DocumentTemplateCard.vue'
|
||||
import WordEditorDialog from './components/WordEditorDialog.vue'
|
||||
import { documentLibrary, documentStatusOptions } from './mock'
|
||||
import { documentStatusOptions, loadDocumentLibrary, saveDocumentLibrary } from './mock'
|
||||
import type {
|
||||
DepartmentTab,
|
||||
DocumentDepartment,
|
||||
@@ -24,6 +26,8 @@ import type {
|
||||
// 原型阶段:文档库数据与文书内容全部来自本地真实附件(mock.ts + contents.ts),暂不调用后端接口。
|
||||
// 后续接入时,仅需将 loadLibrary / saveTemplate / handleWorkflow 中的本地数据操作替换为文档模板接口。
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const library = ref<DocumentDepartment[]>([])
|
||||
const selectedTemplate = ref<DocumentTemplate | null>(null)
|
||||
const signingTemplate = ref<SigningTemplate | null>(null)
|
||||
@@ -99,8 +103,8 @@ const filteredTemplates = computed(() => {
|
||||
})
|
||||
})
|
||||
|
||||
function cloneLibrary(): DocumentDepartment[] {
|
||||
return documentLibrary.map((department) => ({
|
||||
function cloneLibrary(source: DocumentDepartment[]): DocumentDepartment[] {
|
||||
return source.map((department) => ({
|
||||
...department,
|
||||
categories: department.categories.map((category) => ({
|
||||
...category,
|
||||
@@ -110,9 +114,12 @@ function cloneLibrary(): DocumentDepartment[] {
|
||||
}
|
||||
|
||||
function loadLibrary() {
|
||||
library.value = cloneLibrary()
|
||||
library.value = cloneLibrary(loadDocumentLibrary())
|
||||
}
|
||||
|
||||
// 演示数据落本地:刷新后文书库还在,不用每次重新建文书
|
||||
watch(library, (value) => saveDocumentLibrary(value), { deep: true })
|
||||
|
||||
function handlePreview(template: DocumentTemplate) {
|
||||
selectedTemplate.value = template
|
||||
}
|
||||
@@ -262,6 +269,31 @@ function closeSigningDialog() {
|
||||
signingTemplate.value = null
|
||||
}
|
||||
|
||||
// 闭环:文档库发起签署后跳到工作台并选中该任务,否则任务创建成功但用户看不到后续
|
||||
function handleTaskCreated(task: SigningTaskRecord) {
|
||||
closeSigningDialog()
|
||||
void router.push({ name: 'workbench-signing', query: { taskId: task.id } })
|
||||
}
|
||||
|
||||
// 自测用:一键清掉本地保存的演示文书与签署任务,回到初始状态。
|
||||
// 签署任务的演示数据在 api 层的内存里,清存储后直接刷新最彻底。
|
||||
async function resetMockData() {
|
||||
const confirmed = await ElMessageBox.confirm(
|
||||
'将清除本地保存的演示文书与签署任务,恢复到初始状态。',
|
||||
'重置演示数据',
|
||||
{ type: 'warning', confirmButtonText: '重置', cancelButtonText: '取消' },
|
||||
)
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
|
||||
if (!confirmed) {
|
||||
return
|
||||
}
|
||||
|
||||
clearMockState()
|
||||
window.location.reload()
|
||||
}
|
||||
|
||||
function clearFilters() {
|
||||
filters.keyword = ''
|
||||
filters.department = null
|
||||
@@ -281,6 +313,7 @@ onMounted(loadLibrary)
|
||||
:total="filteredTemplates.length"
|
||||
@add="showAddMessage"
|
||||
@export="showExportMessage"
|
||||
@reset="resetMockData"
|
||||
/>
|
||||
|
||||
<DocumentFilterTabs
|
||||
@@ -332,6 +365,7 @@ onMounted(loadLibrary)
|
||||
:visible="signingDialogVisible"
|
||||
:initial-template="signingTemplate"
|
||||
@close="closeSigningDialog"
|
||||
@created="handleTaskCreated"
|
||||
/>
|
||||
<WordEditorDialog
|
||||
:visible="wordEditorVisible"
|
||||
|
||||
Reference in New Issue
Block a user