Files
pqs-9100_client/frontend/src/views/authority/resource/index.vue

129 lines
3.7 KiB
Vue
Raw Normal View History

2024-10-17 15:09:27 +08:00
<template>
<div class='table-box'>
<ProTable
ref='proTable'
:columns='columns'
2024-11-14 11:34:25 +08:00
:request-api='getFunctionList'
2024-11-14 18:26:34 +08:00
:pagination="false"
2024-10-17 15:09:27 +08:00
>
2024-11-14 11:34:25 +08:00
<!-- :data='userData' -->
2024-10-17 15:09:27 +08:00
<!-- 表格 header 按钮 -->
2024-11-14 18:26:34 +08:00
<template #tableHeader>
2024-11-14 11:34:25 +08:00
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
2024-10-17 15:09:27 +08:00
</template>
<!-- 表格操作 -->
<template #operation='scope'>
2024-11-14 11:34:25 +08:00
<el-button type='primary' link :icon='EditPen' @click="openDialog('edit', scope.row)">编辑</el-button>
<el-button type='primary' link :icon='Delete' @click='handleDelete(scope.row)'>删除</el-button>
</template>
2024-10-17 15:09:27 +08:00
</ProTable>
2024-11-11 11:09:20 +08:00
2024-10-17 15:09:27 +08:00
</div>
2024-11-14 11:34:25 +08:00
<ResourcePopup :refresh-table='proTable?.getTableList' ref='resourcePopup' />
2024-10-17 15:09:27 +08:00
</template>
<script setup lang='tsx' name='useProTable'>
2024-11-14 11:34:25 +08:00
import { ref ,reactive} from 'vue'
import { useHandleData } from '@/hooks/useHandleData'
2024-11-11 11:09:20 +08:00
import { type Function } from '@/api/function/interface'
2024-10-17 15:09:27 +08:00
import ProTable from '@/components/ProTable/index.vue'
2024-10-30 15:19:47 +08:00
import {CirclePlus, Delete, EditPen,HomeFilled} from '@element-plus/icons-vue'
2024-10-17 15:09:27 +08:00
import type { ColumnProps, ProTableInstance } from '@/components/ProTable/interface'
2024-10-30 15:19:47 +08:00
import { useDictStore } from '@/stores/modules/dict'
2024-11-14 11:34:25 +08:00
import ResourcePopup from './components/resourcePopup.vue'
import {deleteFunction,getFunctionList} from '@/api/function/index.ts'
2024-10-30 15:19:47 +08:00
const dictStore = useDictStore()
2024-11-14 11:34:25 +08:00
const resourcePopup = ref()
2024-10-17 15:09:27 +08:00
// ProTable 实例
const proTable = ref<ProTableInstance>()
2024-10-30 15:19:47 +08:00
2024-10-17 15:09:27 +08:00
// 表格配置项
2024-11-11 11:09:20 +08:00
const columns = reactive<ColumnProps<Function.ResFunction>[]>([
2024-11-14 18:26:34 +08:00
{ type: 'index', fixed: 'left', width: 70, label: '序号' },
2024-10-17 15:09:27 +08:00
{
prop: 'name',
label: '名称',
2024-11-14 19:24:36 +08:00
minWidth: 150,
search: { el: 'input' },
2024-10-17 15:09:27 +08:00
},
2024-10-30 15:19:47 +08:00
{
prop: 'code',
2024-11-14 19:24:36 +08:00
label: '编码',
2024-10-30 15:19:47 +08:00
minWidth: 100,
},
2024-10-17 15:09:27 +08:00
{
2024-10-30 15:19:47 +08:00
prop: 'type',
label: '类型',
2024-11-14 19:24:36 +08:00
width: 100,
2024-11-14 20:36:54 +08:00
render: (scope) => {
const typeMap: { [key: number]: { label: string; type: string } } = {
0: { label: '菜单', type: 'info' },
1: { label: '按钮', type: 'warning' },
2: { label: '公共资源', type: 'success' },
3: { label: '服务间调用资源', type: 'primary' },
};
const typeInfo = typeMap[scope.row.type] || { label: '未知', type: 'danger' };
return (
<el-tag type={typeInfo.type}>{typeInfo.label}</el-tag>
);
},
},
2024-11-14 19:24:36 +08:00
{
prop: 'icon',
label: '图标',
minWidth: 100,
},
{
prop: 'path',
label: '路由地址',
minWidth: 200,
},
{
prop: 'component',
label: '组件地址',
minWidth: 200,
},
{
prop: 'sort',
label: '排序',
width: 70,
},
2024-10-17 15:09:27 +08:00
{
2024-10-30 15:19:47 +08:00
prop: 'state',
label: '权限资源状态',
2024-11-14 19:24:36 +08:00
minWidth: 100,
2024-10-30 15:19:47 +08:00
render: scope => {
2024-10-23 19:30:11 +08:00
return (
2024-10-30 15:19:47 +08:00
<el-tag type={scope.row.state ? 'success' : 'danger'} > {scope.row.state ? '正常' : '禁用'} </el-tag>
2024-10-23 19:30:11 +08:00
)
},
},
2024-11-14 19:24:36 +08:00
{ prop: 'operation', label: '操作', fixed: 'right',width: 200 },
2024-10-17 15:09:27 +08:00
])
2024-11-14 11:34:25 +08:00
2024-10-31 10:18:17 +08:00
2024-11-14 11:34:25 +08:00
// 打开 drawer(新增、编辑)
const openDialog = (titleType: string, row: Partial<Function.ResFunction> = {}) => {
resourcePopup.value?.open(titleType, row)
}
// 删除用户信息
const handleDelete = async (params: Function.ResFunction) => {
2024-11-14 18:26:34 +08:00
await useHandleData(deleteFunction, params , `删除【${params.name}】用户`)
2024-11-14 11:34:25 +08:00
proTable.value?.getTableList()
}
2024-11-14 18:26:34 +08:00
2024-11-14 11:34:25 +08:00
// 批量删除用户信息
const batchDelete = async (id: string[]) => {
await useHandleData(deleteFunction, { id }, '删除所选用户信息')
proTable.value?.clearSelection()
proTable.value?.getTableList()
2024-10-17 15:09:27 +08:00
}
</script>