| | |
| | | const ROLE_STATUS_META = { |
| | | 1: { type: 'success', text: '正常', bool: true }, |
| | | 0: { type: 'danger', text: '禁用', bool: false } |
| | | } |
| | | |
| | | const ROLE_STATUS_OPTIONS = [ |
| | | { label: '正常', value: 1 }, |
| | | { label: '禁用', value: 0 } |
| | | ] |
| | | |
| | | export function createRoleSearchState() { |
| | | return { |
| | | name: '', |
| | |
| | | status: void 0, |
| | | condition: '' |
| | | } |
| | | } |
| | | |
| | | function hasValue(value) { |
| | | return value !== '' && value !== void 0 && value !== null |
| | | } |
| | | |
| | | function normalizeText(value) { |
| | | return String(value ?? '').trim() |
| | | } |
| | | |
| | | export function createRoleFormState() { |
| | |
| | | } |
| | | } |
| | | |
| | | export function getRoleStatusOptions() { |
| | | return ROLE_STATUS_OPTIONS.map((option) => ({ ...option })) |
| | | } |
| | | |
| | | export function buildRoleSearchParams(params = {}) { |
| | | const searchParams = { |
| | | name: params.name, |
| | | code: params.code, |
| | | memo: params.memo, |
| | | name: normalizeText(params.name), |
| | | code: normalizeText(params.code), |
| | | memo: normalizeText(params.memo), |
| | | status: params.status, |
| | | condition: params.condition |
| | | condition: normalizeText(params.condition) |
| | | } |
| | | |
| | | return Object.fromEntries( |
| | | Object.entries(searchParams).filter( |
| | | ([, value]) => value !== '' && value !== void 0 && value !== null |
| | | ) |
| | | ) |
| | | return Object.fromEntries(Object.entries(searchParams).filter(([, value]) => hasValue(value))) |
| | | } |
| | | |
| | | export function buildRolePageQueryParams(params = {}) { |
| | |
| | | export function buildRoleDialogModel(record = {}) { |
| | | return { |
| | | ...createRoleFormState(), |
| | | id: normalizeRoleId(record.id), |
| | | name: record.name || '', |
| | | code: record.code || '', |
| | | memo: record.memo || '', |
| | | status: record.status !== void 0 && record.status !== null ? record.status : 1 |
| | | ...buildRoleFormData(record) |
| | | } |
| | | } |
| | | |
| | | export function buildRoleSavePayload(form = {}) { |
| | | return { |
| | | id: normalizeRoleId(form.id), |
| | | name: form.name || '', |
| | | code: form.code || '', |
| | | memo: form.memo || '', |
| | | status: form.status !== void 0 && form.status !== null ? form.status : 1 |
| | | } |
| | | return buildRoleFormData(form) |
| | | } |
| | | |
| | | export function normalizeRoleListRow(record = {}) { |
| | |
| | | statusBool: record.statusBool !== void 0 ? Boolean(record.statusBool) : statusMeta.bool, |
| | | statusText: statusMeta.text, |
| | | statusType: statusMeta.type, |
| | | createTimeText: record.createTime$ || record.createTime || '', |
| | | updateTimeText: record.updateTime$ || record.updateTime || '' |
| | | createTimeText: normalizeText(record.createTime$ || record.createTime), |
| | | updateTimeText: normalizeText(record.updateTime$ || record.updateTime) |
| | | } |
| | | } |
| | | |
| | | export function getRoleStatusMeta(status) { |
| | | if (status === true || status === 1) { |
| | | return { type: 'success', text: '正常', bool: true } |
| | | if (status === true || status === 1 || status === '1') { |
| | | return ROLE_STATUS_META[1] |
| | | } |
| | | if (status === false || status === 0) { |
| | | return { type: 'danger', text: '禁用', bool: false } |
| | | if (status === false || status === 0 || status === '0') { |
| | | return ROLE_STATUS_META[0] |
| | | } |
| | | return { type: 'info', text: '未知', bool: false } |
| | | } |
| | |
| | | } |
| | | |
| | | function normalizeRoleId(value) { |
| | | if (value === '' || value === null || value === void 0) { |
| | | if (!hasValue(value)) { |
| | | return void 0 |
| | | } |
| | | const numeric = Number(value) |
| | |
| | | } |
| | | return numeric |
| | | } |
| | | |
| | | function buildRoleFormData(source = {}) { |
| | | return { |
| | | id: normalizeRoleId(source.id), |
| | | name: normalizeText(source.name), |
| | | code: normalizeText(source.code), |
| | | memo: normalizeText(source.memo), |
| | | status: hasValue(source.status) ? source.status : 1 |
| | | } |
| | | } |