From 3edc06d8b1e2449be45dbaa552f635eee72d1519 Mon Sep 17 00:00:00 2001
From: zzw <228544128@qq.com>
Date: 星期三, 07 十月 2026 16:17:38 +0800
Subject: [PATCH] feat: load status dictionary from public assets

---
 emergency-repair-web/src/utils/dict.js |   62 +++++++++++++++++++++++++++++-
 1 files changed, 59 insertions(+), 3 deletions(-)

diff --git a/emergency-repair-web/src/utils/dict.js b/emergency-repair-web/src/utils/dict.js
index e758711..fa9f561 100644
--- a/emergency-repair-web/src/utils/dict.js
+++ b/emergency-repair-web/src/utils/dict.js
@@ -1,4 +1,4 @@
-export const taskStatuses = {
+const defaultTaskStatuses = {
   UNREPORTED: { text: '鏈笂鎶�', type: 'info' },
   REPORTED_XCB: { text: '宸蹭笂鎶k_XCB', type: 'warning' },
   RETURNED: { text: '涓婄骇鎵撳洖', type: 'danger' },
@@ -10,14 +10,14 @@
   CANCELLED: { text: '宸查攢椤�', type: 'info' }
 }
 
-export const completionStatuses = {
+const defaultCompletionStatuses = {
   UNFINISHED: { text: '鏈畬宸�', type: 'info' },
   WAIT_PARTS: { text: '寰呭浠�', type: 'warning' },
   WAIT_TEST: { text: '瀹屽伐寰呰瘯楠�', type: 'primary' },
   COMPLETED: { text: '瀹屽伐', type: 'success' }
 }
 
-export const acceptanceStatuses = {
+const defaultAcceptanceStatuses = {
   APPLICATION_PENDING: { text: '寰呮彁浜ら獙鏀剁敵璇�', type: 'warning' },
   QUALITY_INSPECTOR_PENDING: { text: '寰呰川妫�鍛橀獙鏀�', type: 'primary' },
   QUALITY_LEADER_PENDING: { text: '寰呰川妫�璐熻矗浜洪獙鏀�', type: 'primary' },
@@ -28,6 +28,62 @@
   RETURNED_INSPECTOR: { text: '宸叉墦鍥炶川妫�鍛橀獙鏀�', type: 'danger' }
 }
 
+export const taskStatuses = { ...defaultTaskStatuses }
+export const completionStatuses = { ...defaultCompletionStatuses }
+export const acceptanceStatuses = { ...defaultAcceptanceStatuses }
+
+function normalizeDictionary(source, fallback) {
+  if (!source || typeof source !== 'object' || Array.isArray(source)) {
+    return fallback
+  }
+  const result = {}
+  Object.keys(source).forEach(key => {
+    const item = source[key]
+    if (item && typeof item === 'object' && item.text) {
+      result[key] = {
+        text: String(item.text),
+        type: item.type ? String(item.type) : 'info'
+      }
+    }
+  })
+  return Object.keys(result).length ? result : fallback
+}
+
+function replaceDictionary(target, source) {
+  Object.keys(target).forEach(key => { delete target[key] })
+  Object.keys(source).forEach(key => { target[key] = source[key] })
+}
+
+function applyRuntimeDictionary() {
+  const runtime = window.__APP_DICT__ || {}
+  replaceDictionary(taskStatuses, normalizeDictionary(runtime.taskStatuses, defaultTaskStatuses))
+  replaceDictionary(completionStatuses, normalizeDictionary(runtime.completionStatuses, defaultCompletionStatuses))
+  replaceDictionary(acceptanceStatuses, normalizeDictionary(runtime.acceptanceStatuses, defaultAcceptanceStatuses))
+}
+
+let loadingPromise = null
+
+export function loadDictionary() {
+  if (loadingPromise) {
+    return loadingPromise
+  }
+
+  loadingPromise = new Promise(resolve => {
+    const script = document.createElement('script')
+    const baseUrl = process.env.BASE_URL || '/'
+    script.async = true
+    script.src = baseUrl + 'dict.js?ts=' + Date.now()
+    script.onload = () => {
+      applyRuntimeDictionary()
+      resolve()
+    }
+    script.onerror = () => resolve()
+    document.head.appendChild(script)
+  })
+
+  return loadingPromise
+}
+
 export function statusMeta(dict, value) {
   return dict[value] || { text: value || '-', type: 'info' }
 }

--
Gitblit v1.9.1