<script lang="ts" setup>
|
import type { ActionItem, BasicColumn, FormProps } from '@jnpf/ui/vxeTable';
|
|
import { useMessage } from '@jnpf/hooks';
|
import { useModal } from '@jnpf/ui/modal';
|
import { usePopup } from '@jnpf/ui/popup';
|
import { BasicVxeTable, TableAction, useVxeTable } from '@jnpf/ui/vxeTable';
|
|
import { $t } from '@vben/locales';
|
|
import { copy, del, getList } from '#/api/permission/authGroup';
|
|
import AuthPopup from './AuthPopup.vue';
|
import Form from './Form.vue';
|
import UserBox from './UserBox.vue';
|
|
defineOptions({ name: 'PermissionGrade' });
|
|
const { createMessage } = useMessage();
|
const [registerForm, { openModal: openFormModal }] = useModal();
|
const [registerAuth, { openPopup: openAuthPopup }] = usePopup();
|
const [registerUserBox, { openModal: openUserBox }] = useModal();
|
|
const columns: BasicColumn[] = [
|
{ title: '权限集合名称', dataIndex: 'fullName', width: 200 },
|
{ title: '权限集合编码', dataIndex: 'enCode', width: 200 },
|
{ title: '说明', dataIndex: 'description', minWidth: 200 },
|
{ title: '创建时间', dataIndex: 'creatorTime', width: 150, format: 'date|YYYY-MM-DD HH:mm:ss' },
|
{ title: '排序', dataIndex: 'sortCode', width: 70, align: 'center' },
|
];
|
const [registerTable, { reload }] = useVxeTable({
|
api: getList,
|
columns,
|
useSearchForm: true,
|
formConfig: getFormConfig(),
|
actionColumn: {
|
width: 180,
|
title: '操作',
|
dataIndex: 'action',
|
},
|
});
|
|
function getFormConfig(): Partial<FormProps> {
|
return {
|
schemas: [
|
{
|
field: 'keyword',
|
label: $t('common.keyword'),
|
component: 'Input',
|
componentProps: {
|
placeholder: $t('common.enterKeyword'),
|
submitOnPressEnter: true,
|
},
|
},
|
],
|
};
|
}
|
function getTableActions(record): ActionItem[] {
|
return [
|
{
|
label: $t('common.editText'),
|
onClick: addOrUpdateHandle.bind(null, record.id),
|
},
|
{
|
label: '配置权限',
|
color: 'error',
|
onClick: handleConfigureAuth.bind(null, record),
|
},
|
];
|
}
|
function getDropDownActions(record): ActionItem[] {
|
return [
|
{
|
label: '授权',
|
onClick: handleAuth.bind(null, record.id),
|
},
|
{
|
label: $t('common.copyText'),
|
modelConfirm: {
|
content: '您确定要复制该功能权限集合, 是否继续?',
|
onOk: handleCopy.bind(null, record.id),
|
},
|
},
|
{
|
label: $t('common.delText'),
|
color: 'error',
|
modelConfirm: {
|
onOk: handleDelete.bind(null, record.id),
|
},
|
},
|
];
|
}
|
function addOrUpdateHandle(id = '') {
|
openFormModal(true, { id });
|
}
|
function handleDelete(id) {
|
del(id).then((res) => {
|
createMessage.success(res.msg);
|
reload();
|
});
|
}
|
function handleConfigureAuth(record) {
|
openAuthPopup(true, { id: record.id, title: `${record.fullName}的权限` });
|
}
|
function handleAuth(id) {
|
openUserBox(true, { id });
|
}
|
function handleCopy(id) {
|
copy(id).then((res) => {
|
createMessage.success(res.msg);
|
reload();
|
});
|
}
|
</script>
|
<template>
|
<div class="jnpf-content-wrapper">
|
<div class="jnpf-content-wrapper-center">
|
<div class="jnpf-content-wrapper-content">
|
<BasicVxeTable @register="registerTable">
|
<template #tableTitle>
|
<a-button type="primary" pre-icon="icon-ym icon-ym-btn-add" @click="addOrUpdateHandle()">{{ $t('common.addText') }}</a-button>
|
</template>
|
<template #action="{ record }">
|
<TableAction :actions="getTableActions(record)" :drop-down-actions="getDropDownActions(record)" />
|
</template>
|
</BasicVxeTable>
|
</div>
|
</div>
|
<Form @register="registerForm" @reload="reload" />
|
<AuthPopup @register="registerAuth" />
|
<UserBox @register="registerUserBox" @reload="reload" />
|
</div>
|
</template>
|