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-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 11:34:25 +08:00
|
|
|
<template #tableHeader='scope'>
|
|
|
|
|
<el-button type='primary' :icon='CirclePlus' @click="openDialog('add')">新增</el-button>
|
|
|
|
|
<el-button type='danger' :icon='Delete' plain :disabled='!scope.isSelected'
|
|
|
|
|
@click='batchDelete(scope.selectedListIds)'>
|
2024-10-24 12:28:12 +08:00
|
|
|
批量删除
|
2024-10-17 15:09:27 +08:00
|
|
|
</el-button>
|
|
|
|
|
</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-10-28 08:39:09 +08:00
|
|
|
{ type: 'selection', fixed: 'left', width: 70 },
|
2024-10-17 15:09:27 +08:00
|
|
|
{
|
|
|
|
|
prop: 'name',
|
|
|
|
|
label: '名称',
|
2024-10-30 15:19:47 +08:00
|
|
|
minWidth: 200,
|
2024-10-17 15:09:27 +08:00
|
|
|
search: { el: 'input', tooltip: '我是搜索提示' },
|
|
|
|
|
},
|
2024-10-30 15:19:47 +08:00
|
|
|
{
|
|
|
|
|
prop: 'code',
|
|
|
|
|
label: '资源标识',
|
|
|
|
|
minWidth: 100,
|
|
|
|
|
},
|
2024-10-17 15:09:27 +08:00
|
|
|
{
|
|
|
|
|
prop: 'path',
|
|
|
|
|
label: '路径',
|
2024-10-30 15:19:47 +08:00
|
|
|
minWidth: 200,
|
2024-10-17 15:09:27 +08:00
|
|
|
},
|
|
|
|
|
{
|
2024-10-30 15:19:47 +08:00
|
|
|
prop: 'type',
|
|
|
|
|
label: '类型',
|
|
|
|
|
width: 150,
|
2024-10-30 19:07:41 +08:00
|
|
|
enum: dictStore.getDictData('resourceType'),
|
|
|
|
|
search: { el: 'select', props: { filterable: true } },
|
|
|
|
|
fieldNames: { label: 'label', value: 'code' },
|
2024-10-30 15:19:47 +08:00
|
|
|
},
|
2024-10-17 15:09:27 +08:00
|
|
|
{
|
2024-10-30 15:19:47 +08:00
|
|
|
prop: 'state',
|
|
|
|
|
label: '权限资源状态',
|
|
|
|
|
minWidth: 120,
|
|
|
|
|
enum: dictStore.getDictData('status'),
|
|
|
|
|
fieldNames: { label: 'label', value: 'code' },
|
|
|
|
|
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-10-30 15:19:47 +08:00
|
|
|
{ prop: 'operation', label: '操作', fixed: 'right',minWidth: 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) => {
|
|
|
|
|
await useHandleData(deleteFunction, [params.id] , `删除【${params.name}】用户`)
|
|
|
|
|
proTable.value?.getTableList()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 批量删除用户信息
|
|
|
|
|
const batchDelete = async (id: string[]) => {
|
|
|
|
|
await useHandleData(deleteFunction, { id }, '删除所选用户信息')
|
|
|
|
|
proTable.value?.clearSelection()
|
|
|
|
|
proTable.value?.getTableList()
|
2024-10-17 15:09:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</script>
|