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 || ''
|
}
|
}
|