|
|
@@ -1,24 +1,72 @@
|
|
|
<script lang="ts" setup>
|
|
|
-import { useAccess } from '@vben/access';
|
|
|
+import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
|
|
|
+
|
|
|
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
|
|
|
|
|
|
-import { Button, message, Modal } from 'ant-design-vue';
|
|
|
+import { Button, message } from 'ant-design-vue';
|
|
|
|
|
|
-import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
|
|
+import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
|
|
|
import { RoleApi, UserApi } from '#/api';
|
|
|
import { SelectCard } from '#/components/select-card';
|
|
|
-import { TableAction } from '#/components/table-action';
|
|
|
import MenuGrant from '#/views/system/menu/components/grant.vue';
|
|
|
|
|
|
import FormEdit from './components/edit.vue';
|
|
|
-import { gridOptions, searchFormOptions } from './data.config';
|
|
|
+import { useColumns, useSearchSchema } from './data.config';
|
|
|
|
|
|
-const { hasAccessByCodes } = useAccess();
|
|
|
+const handleDelete = async (id: number) => {
|
|
|
+ await RoleApi.deleteDetail(id);
|
|
|
+ message.success('数据删除成功');
|
|
|
+ reload();
|
|
|
+};
|
|
|
+const handleActionClick = async ({
|
|
|
+ code,
|
|
|
+ row,
|
|
|
+}: OnActionClickParams<RoleApi.RecordItem>) => {
|
|
|
+ switch (code) {
|
|
|
+ case 'delete': {
|
|
|
+ await handleDelete(row.id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'edit': {
|
|
|
+ handleEdit(row, true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'grantMenu': {
|
|
|
+ await handleGrantMenu(row.id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'grantUser': {
|
|
|
+ await handleGrantUser(row.id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'setStatus': {
|
|
|
+ await handleUpdateStatus(row);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
|
|
|
-const [Grid, { reload }] = useVbenVxeGrid({
|
|
|
- formOptions: searchFormOptions,
|
|
|
- gridOptions,
|
|
|
-});
|
|
|
+const [Grid, { reload }] = useVbenVxeGrid(
|
|
|
+ useTableGridOptions({
|
|
|
+ formOptions: {
|
|
|
+ schema: useSearchSchema(),
|
|
|
+ },
|
|
|
+ gridOptions: {
|
|
|
+ columns: useColumns(handleActionClick),
|
|
|
+ proxyConfig: {
|
|
|
+ ajax: {
|
|
|
+ query: async ({ page }, formValues) => {
|
|
|
+ return await RoleApi.getPage({
|
|
|
+ pageIndex: page.currentPage,
|
|
|
+ pageSize: page.pageSize,
|
|
|
+ ...formValues,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ } as VxeTableGridOptions,
|
|
|
+ }),
|
|
|
+);
|
|
|
|
|
|
const [FormEditModal, formEditApi] = useVbenModal({
|
|
|
connectedComponent: FormEdit,
|
|
|
@@ -31,19 +79,6 @@ const [MenuGrantModal, menuGrantApi] = useVbenDrawer({
|
|
|
const [SelectCardModal, selectCardApi] = useVbenModal({
|
|
|
connectedComponent: SelectCard,
|
|
|
});
|
|
|
-const handleDelete = (id: number) => {
|
|
|
- Modal.confirm({
|
|
|
- iconType: 'info',
|
|
|
- title: '删除提示',
|
|
|
- content: `确定要删除选择的记录吗?`,
|
|
|
- cancelText: `关闭`,
|
|
|
- onOk: async () => {
|
|
|
- await RoleApi.deleteDetail(id);
|
|
|
- message.success('数据删除成功');
|
|
|
- reload();
|
|
|
- },
|
|
|
- });
|
|
|
-};
|
|
|
|
|
|
const handleUpdateStatus = async (record: any) => {
|
|
|
await RoleApi.updateStatus({
|
|
|
@@ -54,43 +89,43 @@ const handleUpdateStatus = async (record: any) => {
|
|
|
};
|
|
|
|
|
|
const handleEdit = (record: any, isUpdate: boolean) => {
|
|
|
- formEditApi.setData({
|
|
|
- isUpdate,
|
|
|
- baseData: { id: record.id },
|
|
|
- });
|
|
|
-
|
|
|
- formEditApi.open();
|
|
|
+ formEditApi
|
|
|
+ .setData({
|
|
|
+ isUpdate,
|
|
|
+ baseData: { id: record.id },
|
|
|
+ })
|
|
|
+ .open();
|
|
|
};
|
|
|
|
|
|
const handleGrantMenu = async (id: number) => {
|
|
|
- menuGrantApi.setData({
|
|
|
- baseData: { id, type: 'role' },
|
|
|
- });
|
|
|
-
|
|
|
- menuGrantApi.open();
|
|
|
+ menuGrantApi
|
|
|
+ .setData({
|
|
|
+ baseData: { id, type: 'role' },
|
|
|
+ })
|
|
|
+ .open();
|
|
|
};
|
|
|
|
|
|
const handleGrantUser = async (id: number) => {
|
|
|
const selectedIds = await RoleApi.getUserIds(id);
|
|
|
- selectCardApi.setData({
|
|
|
- baseData: {
|
|
|
- key: id,
|
|
|
- selectedIds,
|
|
|
- fieldNames: [
|
|
|
- { label: '电话', value: 'phone', maxLength: 12 },
|
|
|
- { label: '姓名', value: 'realName', maxLength: 8 },
|
|
|
- ],
|
|
|
- config: {
|
|
|
- type: 'user',
|
|
|
- },
|
|
|
- api: {
|
|
|
- url: UserApi.getPage,
|
|
|
+ selectCardApi
|
|
|
+ .setData({
|
|
|
+ baseData: {
|
|
|
+ key: id,
|
|
|
+ selectedIds,
|
|
|
+ fieldNames: [
|
|
|
+ { label: '电话', value: 'phone', maxLength: 12 },
|
|
|
+ { label: '姓名', value: 'realName', maxLength: 8 },
|
|
|
+ ],
|
|
|
+ config: {
|
|
|
+ type: 'user',
|
|
|
+ },
|
|
|
+ api: {
|
|
|
+ url: UserApi.getPage,
|
|
|
+ },
|
|
|
+ searchName: 'name',
|
|
|
},
|
|
|
- searchName: 'name',
|
|
|
- },
|
|
|
- });
|
|
|
-
|
|
|
- selectCardApi.open();
|
|
|
+ })
|
|
|
+ .open();
|
|
|
};
|
|
|
|
|
|
const handelSuccess = () => {
|
|
|
@@ -123,45 +158,6 @@ const handelUserSuccess = async (data: any) => {
|
|
|
新增角色
|
|
|
</Button>
|
|
|
</template>
|
|
|
- <template #action="{ row }">
|
|
|
- <TableAction
|
|
|
- :actions="[
|
|
|
- {
|
|
|
- label: '编辑',
|
|
|
- type: 'text',
|
|
|
- danger: true,
|
|
|
- disabled: !hasAccessByCodes(['role:edit']),
|
|
|
- onClick: handleEdit.bind(null, row, true),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '授权菜单',
|
|
|
- type: 'text',
|
|
|
- disabled: !hasAccessByCodes(['role:grantMenu']),
|
|
|
- onClick: handleGrantMenu.bind(null, row.id),
|
|
|
- },
|
|
|
- ]"
|
|
|
- :drop-down-actions="[
|
|
|
- {
|
|
|
- label: '添加成员',
|
|
|
- type: 'link',
|
|
|
- disabled: !hasAccessByCodes(['role:grantUser']),
|
|
|
- onClick: handleGrantUser.bind(null, row.id),
|
|
|
- },
|
|
|
- {
|
|
|
- label: row.status === 1 ? '禁用' : '启用',
|
|
|
- type: 'link',
|
|
|
- disabled: !hasAccessByCodes(['role:setStatus']),
|
|
|
- onClick: handleUpdateStatus.bind(null, row),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '删除',
|
|
|
- type: 'link',
|
|
|
- disabled: !hasAccessByCodes(['role:delete']),
|
|
|
- onClick: handleDelete.bind(null, row.id),
|
|
|
- },
|
|
|
- ]"
|
|
|
- />
|
|
|
- </template>
|
|
|
</Grid>
|
|
|
</Page>
|
|
|
</template>
|