zzw
7 小时以前 3edc06d8b1e2449be45dbaa552f635eee72d1519
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
const defaultTaskStatuses = {
  UNREPORTED: { text: '未上报', type: 'info' },
  REPORTED_XCB: { text: '已上报rk_XCB', type: 'warning' },
  RETURNED: { text: '上级打回', type: 'danger' },
  XCB_REVIEWED: { text: 'rk_XCB助理审核完成', type: 'primary' },
  CMB_APPROVED: { text: 'rk_CMB领导审批完成', type: 'success' },
  JCC_ASSISTANT_APPROVED: { text: 'rk_JCC助理审批完成', type: 'success' },
  JCC_DIRECTOR_APPROVED: { text: 'rk_JCC处长已阅', type: 'success' },
  DISPATCHED: { text: '已派单', type: 'primary' },
  CANCELLED: { text: '已销项', type: 'info' }
}
 
const defaultCompletionStatuses = {
  UNFINISHED: { text: '未完工', type: 'info' },
  WAIT_PARTS: { text: '待备件', type: 'warning' },
  WAIT_TEST: { text: '完工待试验', type: 'primary' },
  COMPLETED: { text: '完工', type: 'success' }
}
 
const defaultAcceptanceStatuses = {
  APPLICATION_PENDING: { text: '待提交验收申请', type: 'warning' },
  QUALITY_INSPECTOR_PENDING: { text: '待质检员验收', type: 'primary' },
  QUALITY_LEADER_PENDING: { text: '待质检负责人验收', type: 'primary' },
  PRINT_PENDING: { text: '待打印输出', type: 'warning' },
  RATING_PENDING: { text: '待修后质量评级', type: 'warning' },
  COMPLETED: { text: '验收完成', type: 'success' },
  RETURNED_APPLICATION: { text: '已打回验收申请', type: 'danger' },
  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' }
}