feat(config): 按业务模块拆分 Mock 开关
用 VITE_MOCK_* 系列环境变量替换全局 VITE_USE_MOCK,各模块独立控制演示数据 启用,并新增 src/utils/mock-flags.ts 统一解析缺省值。文档库关闭演示库时 如实提示接口待接入,避免静默沿用本地数据或覆盖已保存内容。
This commit is contained in:
@@ -6,6 +6,7 @@ import { useRouter } from 'vue-router'
|
||||
import NewSigningTaskDialog from '@/components/signing/NewSigningTaskDialog.vue'
|
||||
import type { SigningTaskRecord, SigningTemplate } from '@/api/workbench/types'
|
||||
import type { CampusRecord, DepartmentRecord } from '@/api/management/types'
|
||||
import { mockFlags } from '@/utils/mock-flags'
|
||||
import { clearMockState } from '@/utils/mock-storage'
|
||||
|
||||
import DocumentFilterTabs from './components/DocumentFilterTabs.vue'
|
||||
@@ -25,9 +26,13 @@ import type {
|
||||
|
||||
// 原型阶段:文档库数据与文书内容全部来自本地真实附件(mock.ts + contents.ts),暂不调用后端接口。
|
||||
// 后续接入时,仅需将 loadLibrary / saveTemplate / handleWorkflow 中的本地数据操作替换为文档模板接口。
|
||||
// 是否使用本地演示库由 VITE_MOCK_DOCUMENTS 控制,缺省开启。
|
||||
|
||||
const router = useRouter()
|
||||
|
||||
const useMockLibrary = mockFlags.documents
|
||||
/** 关掉演示库后,文书库本应改由模板接口提供,但该路径尚未实现:如实提示,不静默沿用本地数据 */
|
||||
const apiLibraryPending = ref(false)
|
||||
const library = ref<DocumentDepartment[]>([])
|
||||
const selectedTemplate = ref<DocumentTemplate | null>(null)
|
||||
const signingTemplate = ref<SigningTemplate | null>(null)
|
||||
@@ -114,11 +119,26 @@ function cloneLibrary(source: DocumentDepartment[]): DocumentDepartment[] {
|
||||
}
|
||||
|
||||
function loadLibrary() {
|
||||
if (!useMockLibrary) {
|
||||
library.value = []
|
||||
apiLibraryPending.value = true
|
||||
return
|
||||
}
|
||||
|
||||
library.value = cloneLibrary(loadDocumentLibrary())
|
||||
}
|
||||
|
||||
// 演示数据落本地:刷新后文书库还在,不用每次重新建文书
|
||||
watch(library, (value) => saveDocumentLibrary(value), { deep: true })
|
||||
// 演示数据落本地:刷新后文书库还在,不用每次重新建文书。
|
||||
// 关闭演示库时不写本地,否则会把之前保存的演示文书覆盖成空库。
|
||||
watch(
|
||||
library,
|
||||
(value) => {
|
||||
if (useMockLibrary) {
|
||||
saveDocumentLibrary(value)
|
||||
}
|
||||
},
|
||||
{ deep: true },
|
||||
)
|
||||
|
||||
function handlePreview(template: DocumentTemplate) {
|
||||
selectedTemplate.value = template
|
||||
@@ -323,7 +343,12 @@ onMounted(loadLibrary)
|
||||
:statuses="statusTabs"
|
||||
/>
|
||||
|
||||
<div v-if="filteredTemplates.length" class="template-grid">
|
||||
<p v-if="apiLibraryPending" class="library-pending">
|
||||
已关闭本地演示库(VITE_MOCK_DOCUMENTS=false),但文档库尚未接入模板接口,暂时无法展示文书。
|
||||
改回 VITE_MOCK_DOCUMENTS=true 可继续使用演示库。
|
||||
</p>
|
||||
|
||||
<div v-else-if="filteredTemplates.length" class="template-grid">
|
||||
<DocumentTemplateCard
|
||||
v-for="template in filteredTemplates"
|
||||
:key="template.id"
|
||||
@@ -391,6 +416,17 @@ onMounted(loadLibrary)
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.library-pending {
|
||||
padding: 16px 20px;
|
||||
margin: 0 0 16px;
|
||||
color: var(--warn);
|
||||
font-size: 13px;
|
||||
line-height: 1.7;
|
||||
background: var(--card);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: var(--r);
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
padding: 56px 24px;
|
||||
color: var(--mut);
|
||||
|
||||
@@ -408,7 +408,7 @@ function showImportMessage() {
|
||||
}
|
||||
|
||||
if (isUserMockEnabled) {
|
||||
ElMessage.info('批量导入需要切换到真实接口模式(VITE_USE_MOCK=false)')
|
||||
ElMessage.info('批量导入需要切换到真实接口模式(VITE_MOCK_USERS=false)')
|
||||
return
|
||||
}
|
||||
|
||||
@@ -467,7 +467,7 @@ function resetPassword(user: UserTableRow) {
|
||||
}
|
||||
|
||||
if (isUserMockEnabled) {
|
||||
ElMessage.info('密码重置需要切换到真实接口模式(VITE_USE_MOCK=false)')
|
||||
ElMessage.info('密码重置需要切换到真实接口模式(VITE_MOCK_USERS=false)')
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user