admin-vben5/apps/web-antd/src/views/system/role/index.vue

126 lines
2.8 KiB
Vue
Raw Normal View History

2024-08-07 08:57:56 +08:00
<script setup lang="ts">
2024-09-24 15:35:02 +08:00
import type { Recordable } from '@vben/types';
2024-09-09 11:16:38 +08:00
2024-09-24 15:35:02 +08:00
import { onMounted, ref } from 'vue';
2024-09-25 11:47:55 +08:00
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
2024-09-24 15:35:02 +08:00
import { $t } from '@vben/locales';
import { Card, Table } from 'ant-design-vue';
2024-09-09 11:16:38 +08:00
2024-09-24 10:39:36 +08:00
import { useVbenForm } from '#/adapter';
2024-09-24 15:35:02 +08:00
import { roleList } from '#/api/system/role';
2024-09-24 10:39:36 +08:00
import { querySchema } from './data';
2024-09-25 11:47:55 +08:00
import roleAuthModal from './role-auth-modal.vue';
2024-09-24 15:35:02 +08:00
import roleDrawer from './role-drawer.vue';
2024-09-24 10:39:36 +08:00
const [QueryForm] = useVbenForm({
// 默认展开
collapsed: false,
// 所有表单项共用,可单独在表单内覆盖
commonConfig: {
// 所有表单项
componentProps: {
class: 'w-full',
},
},
schema: querySchema(),
// 是否可展开
showCollapseButton: true,
submitButtonOptions: {
text: '查询',
},
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
});
2024-09-24 15:35:02 +08:00
const [RoleDrawer, drawerApi] = useVbenDrawer({
connectedComponent: roleDrawer,
});
function handleAdd() {
drawerApi.setData({});
drawerApi.open();
}
const columns = [
{
dataIndex: 'roleName',
title: '角色名称',
},
{
dataIndex: 'roleKey',
title: '权限字符',
},
{
dataIndex: 'dataScope',
title: '数据权限',
},
{
dataIndex: 'roleSort',
title: '排序',
},
{
dataIndex: 'status',
title: '状态',
},
{
dataIndex: 'createTime',
title: '创建时间',
},
{
dataIndex: 'action',
title: '操作',
},
];
const dataSource = ref([]);
onMounted(async () => {
const resp = await roleList();
dataSource.value = (resp as any).rows;
});
function handleEdit(record: Recordable<any>) {
drawerApi.setData({ id: record.roleId });
drawerApi.open();
}
2024-09-25 11:47:55 +08:00
const [RoleAuthModal, authModalApi] = useVbenModal({
connectedComponent: roleAuthModal,
});
function handleAuthEdit(record: Recordable<any>) {
authModalApi.setData({ id: record.roleId });
authModalApi.open();
}
2024-08-07 08:57:56 +08:00
</script>
<template>
2024-09-24 15:35:02 +08:00
<Page content-class="flex flex-col gap-[16px]">
2024-09-24 10:39:36 +08:00
<Card class="flex-1">
<QueryForm />
2024-09-09 11:16:38 +08:00
</Card>
2024-09-24 15:35:02 +08:00
<a-button @click="handleAdd">{{ $t('pages.common.add') }}</a-button>
<RoleDrawer />
2024-09-25 11:47:55 +08:00
<RoleAuthModal />
2024-09-24 15:35:02 +08:00
<div class="bg-background rounded-lg p-[16px]">
<Table :columns="columns" :data-source="dataSource">
<template #bodyCell="{ column, record }">
<template v-if="column.dataIndex === 'action'">
<a-button size="small" type="primary" @click="handleEdit(record)">
编辑
</a-button>
2024-09-25 11:47:55 +08:00
<a-button
size="small"
type="primary"
@click="handleAuthEdit(record)"
>
数据权限
</a-button>
2024-09-24 15:35:02 +08:00
</template>
</template>
</Table>
</div>
2024-09-09 11:16:38 +08:00
</Page>
2024-08-07 08:57:56 +08:00
</template>