zhou zhou
3 天以前 5d31cb5f1fb32a478d5b751ebfe97d47db890778
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
const CONFIG_TYPE_OPTIONS = [
  { label: 'boolean', value: 1 },
  { label: 'number', value: 2 },
  { label: 'string', value: 3 },
  { label: 'json', value: 4 },
  { label: 'date', value: 5 }
]
 
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() {
  return CONFIG_TYPE_OPTIONS
}
 
export function getConfigTypeMeta(type) {
  const normalizedType = Number(type)
  return CONFIG_TYPE_OPTIONS.find((item) => item.value === normalizedType) || { label: '-', value: normalizedType || '' }
}
 
export function getConfigStatusMeta(status) {
  return Number(status) === 1
    ? { text: '正常', type: 'success', bool: true }
    : { text: '冻结', 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 normalizeConfigListRow(record = {}) {
  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 || '',
    typeText: record['type$'] || getConfigTypeMeta(record.type).label,
    statusText: record['status$'] || statusMeta.text,
    statusType: statusMeta.type,
    statusBool: record.statusBool ?? statusMeta.bool,
    updateTimeText: record['updateTime$'] || record.updateTime || '',
    createTimeText: record['createTime$'] || record.createTime || ''
  }
}