| | |
| | | export const taskStatuses = { |
| | | const defaultTaskStatuses = { |
| | | UNREPORTED: { text: '未上报', type: 'info' }, |
| | | REPORTED_XCB: { text: '已上报rk_XCB', type: 'warning' }, |
| | | RETURNED: { text: '上级打回', type: 'danger' }, |
| | |
| | | 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' }, |
| | |
| | | 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' } |
| | | } |