修复: 设置页渲染崩溃(AdvancedSection clampApprovalTimeout 打包后 TDZ)

- 根因:VALID_APPROVAL_TIMEOUTS 常量定义在文件末尾,但 clampApprovalTimeout 在 settings reactive 初始化时调用。Rollup 打包后 const 声明顺序变了,导致 TDZ
- 修复:把 VALID_APPROVAL_TIMEOUTS + clampApprovalTimeout 移到 settings reactive 之前
- 附带修复:@/i18n 去掉对 @/stores/appSettings 的 import,改直读 localStorage,消除循环依赖链
This commit is contained in:
2026-07-01 00:48:07 +08:00
parent a3d89803f1
commit 948abb4099
3 changed files with 17 additions and 17 deletions

View File

@@ -1,7 +1,7 @@
{
"identifier": "default",
"description": "DevFlow default permissions",
"windows": ["main", "ai-detached"],
"windows": ["main", "ai-detached", "ai-detached-*", "fe-detached-*"],
"permissions": [
"core:default",
"core:event:default",

View File

@@ -86,8 +86,14 @@ onMounted(async () => {
// 字段。此处用 msg 拼标题+内容,dangerLabel 作确认按钮文案,自渲染独立弹层(上方模板)。
const { confirmState, confirmDialog, answerConfirm } = useConfirm()
// 三档合法值 + 脏值白名单兜底:KV 被外部改库为非法值(空串/非三档)时回退 low,
// 防 <select v-model> 无匹配 option 致控件空白(后端 audit 脏值 fail-safe 降级审批,前端需对齐可视)
// 审批超时合法选项白名单(对齐 <select> option);脏值回退默认 15min。
// 必须在 settings reactive 之前定义,防打包后初始化顺序导致 TDZ
const VALID_APPROVAL_TIMEOUTS = [0, 300_000, 900_000, 1_800_000, 3_600_000]
function clampApprovalTimeout(raw: number): number {
return VALID_APPROVAL_TIMEOUTS.includes(raw) ? raw : 900_000
}
// 三档合法值 + 脏值白名单兜底
const VALID_MODES = ['low', 'medium', 'all'] as const
type AutoMode = (typeof VALID_MODES)[number]
function clampMode(raw: string): AutoMode {
@@ -145,14 +151,6 @@ function markSaved() {
rowLogLevel.value?.markSaved()
}
// 审批超时合法选项白名单(对齐 <select> option);脏值(外部改库为非法数字)回退默认 15min,
// 防 <select v-model> 无匹配 option 致控件空白。允许的取值:0/5/15/30/60 分钟对应毫秒数。
const VALID_APPROVAL_TIMEOUTS = [0, 300_000, 900_000, 1_800_000, 3_600_000]
function clampApprovalTimeout(raw: number): number {
return VALID_APPROVAL_TIMEOUTS.includes(raw) ? raw : 900_000
}
// 审批超时下拉变更:落 KV(df-approval-timeout,ms)+ 显「已保存」反馈。
// 下一笔发起的审批即生效(aiShared.startApprovalTimer 每次实时读),已在跑的计时器沿用旧值。
function onApprovalTimeoutChange() {
appSettings.set('df-approval-timeout', settings.approvalTimeout)

View File

@@ -1,14 +1,16 @@
import { createI18n } from 'vue-i18n'
import zhCN from './zh-CN'
import en from './en'
import { useAppSettingsStore } from '@/stores/appSettings'
// 界面语言:模块加载时 appSettings 缓存尚未填充(loadAll 在 App.vue onMounted 异步执行),
// 故这里 get() 拿到默认 'zh-CN';真实用户偏好由 App.vue 在 loadAll 完成后回填到
// i18n.global.locale.value,初帧渲染短暂 zh-CN 不影响功能。
const getInitialLocale = () => {
// 界面语言:直接读 localStorage(避免 import @/stores/appSettings 形成循环依赖 TDZ)。
// appSettings.loadAll 也会从 SQLite 写入 localStorage,此处直读与 store 行为一致。
const getInitialLocale = (): string => {
if (typeof window !== 'undefined') {
return useAppSettingsStore().get<string>('df-language', 'zh-CN')
try {
return localStorage.getItem('df-language') || 'zh-CN'
} catch {
return 'zh-CN'
}
}
return 'zh-CN'
}