This commit is contained in:
@@ -190,6 +190,7 @@
|
||||
{ label: '权限类型', prop: 'perm_type' },
|
||||
{ label: '菜单路径', prop: 'url' },
|
||||
{ label: '适用端口', prop: 'platform' },
|
||||
// { label: '可用角色类型', prop: 'available_for_role_types' },
|
||||
{ label: '状态', prop: 'status' },
|
||||
{ label: '排序', prop: 'sort' },
|
||||
{ label: '操作', prop: 'operation' }
|
||||
@@ -242,7 +243,7 @@
|
||||
{
|
||||
prop: 'perm_name',
|
||||
label: '权限名称',
|
||||
width: 200
|
||||
width: 240
|
||||
},
|
||||
{
|
||||
prop: 'perm_code',
|
||||
@@ -276,6 +277,24 @@
|
||||
return platformMap[row.platform || 'all'] || row.platform
|
||||
}
|
||||
},
|
||||
// {
|
||||
// prop: 'available_for_role_types',
|
||||
// label: '可用角色类型',
|
||||
// width: 160,
|
||||
// formatter: (row: PermissionTreeNode) => {
|
||||
// if (!row.available_for_role_types) {
|
||||
// return '-'
|
||||
// }
|
||||
// const roleTypeMap: Record<string, string> = {
|
||||
// '1': '平台角色',
|
||||
// '2': '客户角色'
|
||||
// }
|
||||
// const types = row.available_for_role_types
|
||||
// .split(',')
|
||||
// .map((type) => roleTypeMap[type.trim()] || type)
|
||||
// return types.join(', ')
|
||||
// }
|
||||
// },
|
||||
{
|
||||
prop: 'status',
|
||||
label: '状态',
|
||||
@@ -417,7 +436,7 @@
|
||||
}
|
||||
|
||||
// 显示对话框
|
||||
const showDialog = (type: string, row?: PermissionTreeNode) => {
|
||||
const showDialog = async (type: string, row?: PermissionTreeNode) => {
|
||||
dialogVisible.value = true
|
||||
dialogType.value = type
|
||||
|
||||
@@ -428,18 +447,35 @@
|
||||
if (type === 'edit' && row) {
|
||||
currentRow.value = row
|
||||
currentPermissionId.value = row.id
|
||||
// 需要从API获取完整的权限数据,因为树节点可能不包含所有字段
|
||||
// 暂时使用树节点的数据
|
||||
Object.assign(form, {
|
||||
perm_name: row.perm_name,
|
||||
perm_code: row.perm_code,
|
||||
perm_type: row.perm_type,
|
||||
parent_id: undefined, // 树结构中没有parent_id,需要从API获取
|
||||
url: row.url || '',
|
||||
platform: row.platform || 'all',
|
||||
sort: row.sort || 0,
|
||||
status: row.status ?? CommonStatus.ENABLED
|
||||
})
|
||||
// 从API获取完整的权限数据(包含parent_id)
|
||||
try {
|
||||
const response = await PermissionService.getPermission(row.id)
|
||||
if (response.code === 0 && response.data) {
|
||||
Object.assign(form, {
|
||||
perm_name: response.data.perm_name,
|
||||
perm_code: response.data.perm_code,
|
||||
perm_type: response.data.perm_type,
|
||||
parent_id: response.data.parent_id || undefined,
|
||||
url: response.data.url || '',
|
||||
platform: response.data.platform || 'all',
|
||||
sort: response.data.sort || 0,
|
||||
status: response.data.status ?? CommonStatus.ENABLED
|
||||
})
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取权限详情失败:', error)
|
||||
// 如果API获取失败,使用树节点数据作为备选
|
||||
Object.assign(form, {
|
||||
perm_name: row.perm_name,
|
||||
perm_code: row.perm_code,
|
||||
perm_type: row.perm_type,
|
||||
parent_id: undefined,
|
||||
url: row.url || '',
|
||||
platform: row.platform || 'all',
|
||||
sort: row.sort || 0,
|
||||
status: row.status ?? CommonStatus.ENABLED
|
||||
})
|
||||
}
|
||||
} else {
|
||||
currentPermissionId.value = 0
|
||||
resetForm()
|
||||
|
||||
@@ -34,12 +34,21 @@
|
||||
:marginTop="10"
|
||||
@size-change="handleSizeChange"
|
||||
@current-change="handleCurrentChange"
|
||||
@row-contextmenu="handleRowContextMenu"
|
||||
>
|
||||
<template #default>
|
||||
<ElTableColumn v-for="col in columns" :key="col.prop || col.type" v-bind="col" />
|
||||
</template>
|
||||
</ArtTable>
|
||||
|
||||
<!-- 右键菜单 -->
|
||||
<ArtMenuRight
|
||||
ref="contextMenuRef"
|
||||
:menu-items="contextMenuItems"
|
||||
:menu-width="120"
|
||||
@select="handleContextMenuSelect"
|
||||
/>
|
||||
|
||||
<!-- 新增/编辑对话框 -->
|
||||
<ElDialog
|
||||
v-model="dialogVisible"
|
||||
@@ -226,6 +235,8 @@
|
||||
import { useCheckedColumns } from '@/composables/useCheckedColumns'
|
||||
import { useAuth } from '@/composables/useAuth'
|
||||
import ArtButtonTable from '@/components/core/forms/ArtButtonTable.vue'
|
||||
import ArtMenuRight from '@/components/core/others/ArtMenuRight.vue'
|
||||
import type { MenuItemType } from '@/components/core/others/ArtMenuRight.vue'
|
||||
import { formatDateTime } from '@/utils/business/format'
|
||||
import { CommonStatus, getStatusText } from '@/config/constants'
|
||||
|
||||
@@ -253,6 +264,8 @@
|
||||
const leftTreeFilter = ref('') // 左侧树搜索关键字
|
||||
const rightTreeFilter = ref('') // 右侧树搜索关键字
|
||||
const isHandlingCheck = ref(false) // 标志位:是否正在处理勾选事件
|
||||
const contextMenuRef = ref<InstanceType<typeof ArtMenuRight>>()
|
||||
const currentRow = ref<PlatformRole | null>(null)
|
||||
|
||||
// 搜索表单初始值
|
||||
const initialSearchState = {
|
||||
@@ -317,8 +330,7 @@
|
||||
{ label: '角色描述', prop: 'role_desc' },
|
||||
{ label: '角色类型', prop: 'role_type' },
|
||||
{ label: '状态', prop: 'status' },
|
||||
{ label: '创建时间', prop: 'CreatedAt' },
|
||||
{ label: '操作', prop: 'operation' }
|
||||
{ label: '创建时间', prop: 'CreatedAt' }
|
||||
]
|
||||
|
||||
const formRef = ref<FormInstance>()
|
||||
@@ -391,47 +403,6 @@
|
||||
label: '创建时间',
|
||||
width: 180,
|
||||
formatter: (row: any) => formatDateTime(row.CreatedAt)
|
||||
},
|
||||
{
|
||||
prop: 'operation',
|
||||
label: '操作',
|
||||
width: 240,
|
||||
fixed: 'right',
|
||||
formatter: (row: any) => {
|
||||
const buttons = []
|
||||
|
||||
// 分配权限按钮
|
||||
if (hasAuth('role:permission')) {
|
||||
buttons.push(
|
||||
h(ArtButtonTable, {
|
||||
text: '分配权限',
|
||||
onClick: () => showPermissionDialog(row)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// 编辑按钮
|
||||
if (hasAuth('role:edit')) {
|
||||
buttons.push(
|
||||
h(ArtButtonTable, {
|
||||
text: '编辑',
|
||||
onClick: () => showDialog('edit', row)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
// 删除按钮
|
||||
if (hasAuth('role:delete')) {
|
||||
buttons.push(
|
||||
h(ArtButtonTable, {
|
||||
text: '删除',
|
||||
onClick: () => deleteRole(row)
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
return h('div', { style: 'display: flex; gap: 8px;' }, buttons)
|
||||
}
|
||||
}
|
||||
])
|
||||
|
||||
@@ -1038,6 +1009,50 @@
|
||||
console.error(error)
|
||||
}
|
||||
}
|
||||
|
||||
// 右键菜单项配置
|
||||
const contextMenuItems = computed((): MenuItemType[] => {
|
||||
const items: MenuItemType[] = []
|
||||
|
||||
if (hasAuth('role:permission')) {
|
||||
items.push({ key: 'assignPermission', label: '分配权限' })
|
||||
}
|
||||
|
||||
if (hasAuth('role:edit')) {
|
||||
items.push({ key: 'edit', label: '编辑' })
|
||||
}
|
||||
|
||||
if (hasAuth('role:delete')) {
|
||||
items.push({ key: 'delete', label: '删除' })
|
||||
}
|
||||
|
||||
return items
|
||||
})
|
||||
|
||||
// 处理表格行右键菜单
|
||||
const handleRowContextMenu = (row: any, column: any, event: MouseEvent) => {
|
||||
event.preventDefault()
|
||||
event.stopPropagation()
|
||||
currentRow.value = row
|
||||
contextMenuRef.value?.show(event)
|
||||
}
|
||||
|
||||
// 处理右键菜单选择
|
||||
const handleContextMenuSelect = (item: MenuItemType) => {
|
||||
if (!currentRow.value) return
|
||||
|
||||
switch (item.key) {
|
||||
case 'assignPermission':
|
||||
showPermissionDialog(currentRow.value)
|
||||
break
|
||||
case 'edit':
|
||||
showDialog('edit', currentRow.value)
|
||||
break
|
||||
case 'delete':
|
||||
deleteRole(currentRow.value)
|
||||
break
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped lang="scss">
|
||||
|
||||
Reference in New Issue
Block a user