ruoyi-plus-vben5/apps/web-antd/src/views/system/post/index.vue

194 lines
5.0 KiB
Vue
Raw Normal View History

2024-08-07 08:57:56 +08:00
<script setup lang="ts">
2024-10-05 16:02:02 +08:00
import type { Recordable } from '@vben/types';
2024-09-13 15:27:29 +08:00
2024-10-05 16:02:02 +08:00
import { ref } from 'vue';
2024-09-24 11:23:02 +08:00
2024-10-05 16:02:02 +08:00
import { Page, useVbenDrawer, type VbenFormProps } from '@vben/common-ui';
import { getVxePopupContainer } from '@vben/utils';
2024-09-24 11:23:02 +08:00
2024-10-05 16:02:02 +08:00
import { Modal, Popconfirm, Space } from 'ant-design-vue';
import {
tableCheckboxEvent,
useVbenVxeGrid,
type VxeGridProps,
} from '#/adapter/vxe-table';
2024-10-05 16:02:02 +08:00
import { postExport, postList, postRemove } from '#/api/system/post';
2024-11-14 14:58:42 +08:00
import { commonDownloadExcel } from '#/utils/file/download';
2024-10-05 16:02:02 +08:00
import DeptTree from '#/views/system/user/dept-tree.vue';
import { columns, querySchema } from './data';
2024-09-13 15:27:29 +08:00
import postDrawer from './post-drawer.vue';
2024-10-05 22:20:00 +08:00
// 左边部门用
const selectDeptId = ref<string[]>([]);
2024-10-05 16:02:02 +08:00
const formOptions: VbenFormProps = {
2024-10-05 22:20:00 +08:00
commonConfig: {
labelWidth: 80,
componentProps: {
allowClear: true,
},
2024-10-05 22:20:00 +08:00
},
2024-10-05 16:02:02 +08:00
schema: querySchema(),
wrapperClass: 'grid-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4',
2024-10-05 22:20:00 +08:00
handleReset: async () => {
selectDeptId.value = [];
// eslint-disable-next-line no-use-before-define
2024-10-07 14:01:31 +08:00
const { formApi, reload } = tableApi;
await formApi.resetForm();
const formValues = formApi.form.values;
formApi.setLatestSubmissionValues(formValues);
await reload(formValues);
2024-10-05 22:20:00 +08:00
},
2024-10-05 16:02:02 +08:00
};
const gridOptions: VxeGridProps = {
checkboxConfig: {
// 高亮
highlight: true,
// 翻页时保留选中状态
reserve: true,
2024-10-05 22:20:00 +08:00
trigger: 'cell',
2024-10-05 16:02:02 +08:00
},
columns,
height: 'auto',
keepSource: true,
pagerConfig: {},
proxyConfig: {
ajax: {
2024-10-06 09:53:00 +08:00
query: async ({ page }, formValues = {}) => {
2024-10-05 16:02:02 +08:00
// 部门树选择处理
if (selectDeptId.value.length === 1) {
2024-10-20 10:39:03 +08:00
formValues.belongDeptId = selectDeptId.value[0];
2024-10-05 16:02:02 +08:00
} else {
2024-10-20 10:39:03 +08:00
Reflect.deleteProperty(formValues, 'belongDeptId');
2024-10-05 16:02:02 +08:00
}
return await postList({
pageNum: page.currentPage,
pageSize: page.pageSize,
...formValues,
});
},
},
},
rowConfig: {
isHover: true,
keyField: 'postId',
},
id: 'system-post-index',
2024-10-05 16:02:02 +08:00
};
2024-10-05 22:20:00 +08:00
const checked = ref(false);
const [BasicTable, tableApi] = useVbenVxeGrid({
formOptions,
gridOptions,
gridEvents: {
checkboxChange: tableCheckboxEvent(checked),
checkboxAll: tableCheckboxEvent(checked),
2024-10-05 22:20:00 +08:00
},
});
2024-09-13 15:27:29 +08:00
const [PostDrawer, drawerApi] = useVbenDrawer({
connectedComponent: postDrawer,
});
function handleAdd() {
2024-10-05 16:02:02 +08:00
drawerApi.setData({});
2024-09-13 15:27:29 +08:00
drawerApi.open();
}
2024-09-24 11:23:02 +08:00
2024-10-05 16:02:02 +08:00
async function handleEdit(record: Recordable<any>) {
drawerApi.setData({ id: record.postId });
drawerApi.open();
}
async function handleDelete(row: Recordable<any>) {
await postRemove(row.postId);
2024-10-05 22:20:00 +08:00
await tableApi.query();
2024-10-05 16:02:02 +08:00
}
function handleMultiDelete() {
const rows = tableApi.grid.getCheckboxRecords();
const ids = rows.map((row: any) => row.postId);
Modal.confirm({
title: '提示',
okType: 'danger',
content: `确认删除选中的${ids.length}条记录吗?`,
onOk: async () => {
await postRemove(ids);
2024-10-06 09:53:00 +08:00
await tableApi.query();
2024-10-06 10:15:17 +08:00
checked.value = false;
2024-09-24 11:23:02 +08:00
},
2024-10-05 16:02:02 +08:00
});
}
2024-11-14 14:58:42 +08:00
function handleDownloadExcel() {
commonDownloadExcel(postExport, '岗位信息', tableApi.formApi.form.values);
}
2024-08-07 08:57:56 +08:00
</script>
<template>
2024-10-25 08:09:53 +08:00
<Page :auto-content-height="true" content-class="flex gap-[8px] w-full">
2024-10-05 16:02:02 +08:00
<DeptTree
v-model:select-dept-id="selectDeptId"
class="w-[260px]"
@reload="() => tableApi.reload()"
@select="() => tableApi.reload()"
2024-10-05 16:02:02 +08:00
/>
2024-10-25 08:09:53 +08:00
<BasicTable class="flex-1 overflow-hidden" table-title="岗位列表">
2024-10-05 16:02:02 +08:00
<template #toolbar-tools>
<Space>
<a-button
v-access:code="['system:post:export']"
2024-11-14 14:58:42 +08:00
@click="handleDownloadExcel"
2024-10-05 16:02:02 +08:00
>
{{ $t('pages.common.export') }}
</a-button>
<a-button
2024-10-05 22:20:00 +08:00
:disabled="!checked"
2024-10-05 16:02:02 +08:00
danger
type="primary"
2024-10-05 22:20:00 +08:00
v-access:code="['system:post:remove']"
2024-10-05 16:02:02 +08:00
@click="handleMultiDelete"
>
{{ $t('pages.common.delete') }}
</a-button>
<a-button
type="primary"
v-access:code="['system:post:add']"
@click="handleAdd"
>
{{ $t('pages.common.add') }}
</a-button>
</Space>
</template>
<template #action="{ row }">
2024-10-07 16:56:32 +08:00
<Space>
<GhostButton
v-access:code="['system:post:edit']"
@click="handleEdit(row)"
2024-10-05 16:02:02 +08:00
>
2024-10-07 16:56:32 +08:00
{{ $t('pages.common.edit') }}
</GhostButton>
<Popconfirm
:get-popup-container="getVxePopupContainer"
2024-10-07 16:56:32 +08:00
placement="left"
title="确认删除?"
@confirm="handleDelete(row)"
>
<GhostButton
danger
v-access:code="['system:post:remove']"
@click.stop=""
>
{{ $t('pages.common.delete') }}
</GhostButton>
</Popconfirm>
</Space>
2024-10-05 16:02:02 +08:00
</template>
</BasicTable>
2024-10-05 22:20:00 +08:00
<PostDrawer @reload="tableApi.query()" />
2024-09-13 15:27:29 +08:00
</Page>
2024-08-07 08:57:56 +08:00
</template>