export function createRoleSearchState() {
|
return {
|
name: '',
|
code: '',
|
memo: '',
|
status: void 0,
|
condition: ''
|
}
|
}
|
|
export function createRoleFormState() {
|
return {
|
id: void 0,
|
name: '',
|
code: '',
|
memo: '',
|
status: 1
|
}
|
}
|
|
export function buildRoleSearchParams(params = {}) {
|
const searchParams = {
|
name: params.name,
|
code: params.code,
|
memo: params.memo,
|
status: params.status,
|
condition: params.condition
|
}
|
|
return Object.fromEntries(
|
Object.entries(searchParams).filter(([, value]) => value !== '' && value !== void 0 && value !== null)
|
)
|
}
|
|
export function buildRolePageQueryParams(params = {}) {
|
const { current, size, pageSize, ...filters } = params
|
return {
|
current: current || 1,
|
pageSize: pageSize || size || 20,
|
...buildRoleSearchParams(filters)
|
}
|
}
|
|
export function getRolePaginationKey() {
|
return {
|
current: 'current',
|
size: 'pageSize'
|
}
|
}
|
|
const ROLE_REPORT_COLUMNS = [
|
{ source: 'name', label: '角色名称' },
|
{ source: 'code', label: '角色编码' },
|
{ source: 'statusText', label: '状态' },
|
{ source: 'memo', label: '备注' },
|
{ source: 'createTimeText', label: '创建时间' },
|
{ source: 'updateTimeText', label: '更新时间' }
|
]
|
|
const ROLE_REPORT_SOURCE_ALIAS = {
|
status: 'statusText'
|
}
|
|
export const ROLE_REPORT_TITLE = '角色管理报表'
|
|
export const ROLE_REPORT_STYLE = {
|
titleAlign: 'center',
|
titleLevel: 'strong'
|
}
|
|
export function getRoleReportColumns() {
|
return ROLE_REPORT_COLUMNS.map((column) => ({ ...column }))
|
}
|
|
export function resolveRoleReportColumns(columns = []) {
|
if (!Array.isArray(columns)) {
|
return []
|
}
|
|
const allowedColumns = new Map(ROLE_REPORT_COLUMNS.map((column) => [column.source, column]))
|
const seenSources = new Set()
|
|
return columns
|
.map((column) => {
|
if (!column || typeof column !== 'object') {
|
return null
|
}
|
|
const source = ROLE_REPORT_SOURCE_ALIAS[column.source ?? column.prop] ?? column.source ?? column.prop
|
if (!source || !allowedColumns.has(source) || seenSources.has(source)) {
|
return null
|
}
|
|
seenSources.add(source)
|
const allowedColumn = allowedColumns.get(source)
|
return {
|
source,
|
label: column.label || allowedColumn.label
|
}
|
})
|
.filter(Boolean)
|
}
|
|
export function buildRolePrintRows(records = []) {
|
if (!Array.isArray(records)) {
|
return []
|
}
|
|
return records.map((record) => normalizeRoleListRow(record))
|
}
|
|
export function buildRoleReportMeta({
|
previewMeta = {},
|
count = 0,
|
titleAlign = ROLE_REPORT_STYLE.titleAlign,
|
titleLevel = ROLE_REPORT_STYLE.titleLevel
|
} = {}) {
|
return {
|
reportTitle: ROLE_REPORT_TITLE,
|
reportDate: previewMeta.reportDate,
|
printedAt: previewMeta.printedAt,
|
operator: previewMeta.operator,
|
count,
|
reportStyle: {
|
titleAlign,
|
titleLevel,
|
orientation: 'portrait',
|
density: 'compact',
|
showSequence: true
|
}
|
}
|
}
|
|
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
|
}
|
}
|
|
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
|
}
|
}
|
|
export function normalizeRoleListRow(record = {}) {
|
const statusMeta = getRoleStatusMeta(record.statusBool ?? record.status)
|
return {
|
...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 || ''
|
}
|
}
|
|
export function getRoleStatusMeta(status) {
|
if (status === true || status === 1) {
|
return { type: 'success', text: '正常', bool: true }
|
}
|
if (status === false || status === 0) {
|
return { type: 'danger', text: '禁用', bool: false }
|
}
|
return { type: 'info', text: '未知', bool: false }
|
}
|
|
export function getRoleScopeConfig(scopeType) {
|
const configMap = {
|
menu: {
|
scopeType: 'menu',
|
title: '网页权限',
|
listUrl: '/role/scope/list',
|
treeUrl: '/menu/tree'
|
},
|
pda: {
|
scopeType: 'pda',
|
title: 'PDA权限',
|
listUrl: '/rolePda/scope/list',
|
treeUrl: '/menuPda/tree'
|
},
|
matnr: {
|
scopeType: 'matnr',
|
title: '物料权限',
|
listUrl: '/roleMatnr/scope/list',
|
treeUrl: '/menuMatnrGroup/tree'
|
},
|
warehouse: {
|
scopeType: 'warehouse',
|
title: '仓库权限',
|
listUrl: '/roleWarehouse/scope/list',
|
treeUrl: '/menuWarehouse/tree'
|
}
|
}
|
|
const config = configMap[scopeType]
|
if (!config) {
|
throw new Error(`Unsupported scope type: ${scopeType}`)
|
}
|
return config
|
}
|
|
export function buildRoleScopeSubmitPayload(roleId, checkedKeys = [], halfCheckedKeys = []) {
|
return {
|
id: normalizeRoleId(roleId),
|
menuIds: {
|
checked: normalizeScopeKeys(checkedKeys),
|
halfChecked: normalizeScopeKeys(halfCheckedKeys)
|
}
|
}
|
}
|
|
export function normalizeRoleScopeTreeData(scopeType, treeData = []) {
|
if (!Array.isArray(treeData)) {
|
return []
|
}
|
|
return treeData
|
.map((node) => normalizeRoleScopeNode(scopeType, node))
|
.filter(Boolean)
|
}
|
|
function normalizeRoleScopeNode(scopeType, node) {
|
if (!node || typeof node !== 'object') {
|
return null
|
}
|
|
if (scopeType === 'menu' && node.type === 1) {
|
return buildScopeAuthNode(node)
|
}
|
|
const children = Array.isArray(node.children)
|
? normalizeRoleScopeTreeData(scopeType, node.children)
|
: []
|
const metaSource = node.meta && typeof node.meta === 'object' ? node.meta : node
|
const authNodes = scopeType === 'menu' && Array.isArray(metaSource.authList) && metaSource.authList.length
|
? metaSource.authList.map((auth, index) => ({
|
id: normalizeScopeKey(auth.id ?? auth.authMark ?? `${node.id || 'auth'}-${index}`),
|
label: normalizeScopeTitle(auth.title || auth.name || auth.authMark || ''),
|
type: 1,
|
isAuthButton: true,
|
authMark: auth.authMark || auth.authority || auth.code || '',
|
children: []
|
}))
|
: []
|
|
const mergedChildren =
|
authNodes.length > 0 && !children.some((child) => child.isAuthButton)
|
? [...children, ...authNodes]
|
: children
|
|
return {
|
id: normalizeScopeKey(node.id ?? node.value),
|
label: normalizeScopeTitle(
|
node.label || node.title || node.name || metaSource.title || node.code || ''
|
),
|
type: node.type,
|
path: node.path || '',
|
component: node.component || '',
|
isAuthButton: Boolean(node.isAuthButton),
|
authMark: node.authMark || metaSource.authMark || metaSource.authority || metaSource.code || '',
|
meta: metaSource,
|
children: mergedChildren
|
}
|
}
|
|
function buildScopeAuthNode(node) {
|
const metaSource = node.meta && typeof node.meta === 'object' ? node.meta : node
|
return {
|
id: normalizeScopeKey(node.id ?? node.value),
|
label: normalizeScopeTitle(node.label || node.title || node.name || metaSource.title || ''),
|
type: 1,
|
isAuthButton: true,
|
authMark: node.authMark || metaSource.authMark || metaSource.authority || metaSource.code || '',
|
children: []
|
}
|
}
|
|
export function normalizeScopeKeys(keys = []) {
|
if (!Array.isArray(keys)) {
|
return []
|
}
|
|
return Array.from(
|
new Set(
|
keys
|
.map((key) => normalizeRoleId(key))
|
.filter((key) => key !== void 0)
|
)
|
)
|
}
|
|
export function normalizeScopeKey(value) {
|
const normalized = normalizeRoleId(value)
|
return normalized === void 0 ? '' : String(normalized)
|
}
|
|
function normalizeScopeTitle(title) {
|
if (typeof title !== 'string') {
|
return ''
|
}
|
const trimmedTitle = title.trim()
|
if (trimmedTitle.startsWith('menu.')) {
|
return `menus.${trimmedTitle.slice('menu.'.length)}`
|
}
|
return trimmedTitle
|
}
|
|
function normalizeRoleId(value) {
|
if (value === '' || value === null || value === void 0) {
|
return void 0
|
}
|
const numeric = Number(value)
|
if (Number.isNaN(numeric)) {
|
return value
|
}
|
return numeric
|
}
|