zhou zhou
2 天以前 5454bbe86b1a22e9f05b6bc43f7ed7e9d6c4dc14
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const CONFIG_TYPE_OPTIONS = [
  { labelKey: 'pages.system.config.types.boolean', fallback: 'boolean', value: 1 },
  { labelKey: 'pages.system.config.types.number', fallback: 'number', value: 2 },
  { labelKey: 'pages.system.config.types.string', fallback: 'string', value: 3 },
  { labelKey: 'pages.system.config.types.json', fallback: 'json', value: 4 },
  { labelKey: 'pages.system.config.types.date', fallback: 'date', value: 5 }
]
const IMAGE_VALUE_RE = /(^data:image\/)|(\.(png|jpe?g|gif|bmp|webp|svg|ico)(\?.*)?$)|(([?&]path=).*?\.(png|jpe?g|gif|bmp|webp|svg|ico)($|&))/i
 
export const PROJECT_LOGO_FLAG = 'PROJECT_LOGO'
export const PROJECT_COPYRIGHT_FLAG = 'PROJECT_COPYRIGHT'
 
export function createConfigSearchState() {
  return {
    condition: '',
    flag: '',
    type: '',
    status: ''
  }
}
 
export function createConfigFormState() {
  return {
    id: null,
    uuid: '',
    name: '',
    flag: '',
    type: 3,
    val: '',
    content: '',
    status: 1,
    memo: ''
  }
}
 
export function getConfigPaginationKey() {
  return {
    current: 'current',
    size: 'pageSize'
  }
}
 
export function getConfigTypeOptions(t) {
  return CONFIG_TYPE_OPTIONS.map((item) => ({
    label: typeof t === 'function' ? t(item.labelKey) : item.fallback,
    value: item.value
  }))
}
 
export function getConfigTypeMeta(type) {
  const normalizedType = Number(type)
  return (
    CONFIG_TYPE_OPTIONS.find((item) => item.value === normalizedType) || {
      labelKey: 'common.placeholder.empty',
      fallback: '--',
      value: normalizedType || ''
    }
  )
}
 
export function getConfigStatusMeta(status) {
  return Number(status) === 1
    ? { textKey: 'common.status.normal', fallback: 'Normal', type: 'success', bool: true }
    : { textKey: 'common.status.frozen', fallback: 'Frozen', type: 'danger', bool: false }
}
 
export function buildConfigSearchParams(params = {}) {
  return {
    condition: String(params.condition || '').trim(),
    flag: String(params.flag || '').trim(),
    ...(params.type !== '' && params.type !== null && params.type !== undefined ? { type: Number(params.type) } : {}),
    ...(params.status !== '' && params.status !== null && params.status !== undefined
      ? { status: Number(params.status) }
      : {})
  }
}
 
export function buildConfigPageQueryParams(params = {}) {
  return {
    current: params.current || 1,
    pageSize: params.pageSize || params.size || 20,
    ...buildConfigSearchParams(params)
  }
}
 
export function buildConfigDialogModel(record = {}) {
  return {
    ...createConfigFormState(),
    ...(record.id ? { id: Number(record.id) } : {}),
    uuid: record.uuid || '',
    name: record.name || '',
    flag: record.flag || '',
    type: record.type !== undefined && record.type !== null ? Number(record.type) : 3,
    val: record.val || '',
    content: record.content || '',
    status: record.status !== undefined && record.status !== null ? Number(record.status) : 1,
    memo: record.memo || ''
  }
}
 
export function buildConfigSavePayload(formData = {}) {
  return {
    ...(formData.id ? { id: Number(formData.id) } : {}),
    uuid: String(formData.uuid || '').trim(),
    name: String(formData.name || '').trim(),
    flag: String(formData.flag || '').trim(),
    type: Number(formData.type || 3),
    val: String(formData.val || '').trim(),
    content: String(formData.content || '').trim(),
    status: Number(formData.status ?? 1),
    memo: String(formData.memo || '').trim()
  }
}
 
export function isImageConfigValue(value) {
  return IMAGE_VALUE_RE.test(String(value || '').trim())
}
 
export function normalizeConfigListRow(record = {}) {
  const typeMeta = getConfigTypeMeta(record.type)
  const statusMeta = getConfigStatusMeta(record.status)
  return {
    ...record,
    uuid: record.uuid || '',
    name: record.name || '',
    flag: record.flag || '',
    val: record.val || '',
    content: record.content || '',
    memo: record.memo || '',
    typeTextKey: typeMeta.labelKey,
    typeText: typeMeta.fallback,
    statusTextKey: statusMeta.textKey,
    statusText: statusMeta.fallback,
    statusType: statusMeta.type,
    statusBool: record.statusBool ?? statusMeta.bool,
    updateTimeText: record['updateTime$'] || record.updateTime || '',
    createTimeText: record['createTime$'] || record.createTime || ''
  }
}