|
|
@@ -1,23 +1,16 @@
|
|
|
<script lang="ts" setup>
|
|
|
-import { useAccess } from '@vben/access';
|
|
|
+import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
|
|
|
+
|
|
|
import { Page, 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 { QueryApi } from '#/api';
|
|
|
-import { TableAction } from '#/components/table-action';
|
|
|
|
|
|
import FormEdit from './components/edit.vue';
|
|
|
import FormView from './components/view.vue';
|
|
|
-import { gridOptions, searchFormOptions } from './data.config';
|
|
|
-
|
|
|
-const { hasAccessByCodes } = useAccess();
|
|
|
-
|
|
|
-const [Grid, { reload }] = useVbenVxeGrid({
|
|
|
- formOptions: searchFormOptions,
|
|
|
- gridOptions,
|
|
|
-});
|
|
|
+import { useColumns, useSearchSchema } from './data.config';
|
|
|
|
|
|
const [FormEditModal, formEditApi] = useVbenModal({
|
|
|
connectedComponent: FormEdit,
|
|
|
@@ -26,37 +19,70 @@ const [FormEditModal, formEditApi] = useVbenModal({
|
|
|
const [FormViewModal, formViewApi] = useVbenModal({
|
|
|
connectedComponent: FormView,
|
|
|
});
|
|
|
-const handleDelete = (id: number) => {
|
|
|
- Modal.confirm({
|
|
|
- iconType: 'info',
|
|
|
- title: '删除提示',
|
|
|
- content: `确定要删除选择的记录吗?`,
|
|
|
- cancelText: `关闭`,
|
|
|
- onOk: async () => {
|
|
|
- await QueryApi.deleteDetail(id);
|
|
|
- message.success('数据删除成功');
|
|
|
- reload();
|
|
|
- },
|
|
|
- });
|
|
|
+const handleDelete = async (id: number) => {
|
|
|
+ await QueryApi.deleteDetail(id);
|
|
|
+ message.success('数据删除成功');
|
|
|
+ reload();
|
|
|
};
|
|
|
|
|
|
const handleEdit = (record: any, isUpdate: boolean) => {
|
|
|
- formEditApi.setData({
|
|
|
- isUpdate,
|
|
|
- baseData: { ...record },
|
|
|
- });
|
|
|
-
|
|
|
- formEditApi.open();
|
|
|
+ formEditApi
|
|
|
+ .setData({
|
|
|
+ isUpdate,
|
|
|
+ baseData: { ...record },
|
|
|
+ })
|
|
|
+ .open();
|
|
|
};
|
|
|
|
|
|
const handleView = (code: string) => {
|
|
|
- formViewApi.setData({ baseData: { code } });
|
|
|
- formViewApi.open();
|
|
|
+ formViewApi.setData({ baseData: { code } }).open();
|
|
|
};
|
|
|
|
|
|
const handelSuccess = () => {
|
|
|
reload();
|
|
|
};
|
|
|
+
|
|
|
+const handleActionClick = async ({
|
|
|
+ code,
|
|
|
+ row,
|
|
|
+}: OnActionClickParams<QueryApi.RecordItem>) => {
|
|
|
+ switch (code) {
|
|
|
+ case 'delete': {
|
|
|
+ await handleDelete(row.id);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'edit': {
|
|
|
+ handleEdit(row, true);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 'view': {
|
|
|
+ handleView(row.code);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+};
|
|
|
+
|
|
|
+const [Grid, { reload }] = useVbenVxeGrid(
|
|
|
+ useTableGridOptions({
|
|
|
+ formOptions: {
|
|
|
+ schema: useSearchSchema(),
|
|
|
+ },
|
|
|
+ gridOptions: {
|
|
|
+ columns: useColumns(handleActionClick),
|
|
|
+ proxyConfig: {
|
|
|
+ ajax: {
|
|
|
+ query: async ({ page }, formValues) => {
|
|
|
+ return await QueryApi.getPage({
|
|
|
+ pageIndex: page.currentPage,
|
|
|
+ pageSize: page.pageSize,
|
|
|
+ ...formValues,
|
|
|
+ });
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
+ } as VxeTableGridOptions,
|
|
|
+ }),
|
|
|
+);
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
@@ -74,32 +100,6 @@ const handelSuccess = () => {
|
|
|
新增查询
|
|
|
</Button>
|
|
|
</template>
|
|
|
- <template #action="{ row }">
|
|
|
- <TableAction
|
|
|
- :actions="[
|
|
|
- {
|
|
|
- label: '编辑',
|
|
|
- type: 'text',
|
|
|
- disabled: !hasAccessByCodes(['query:edit']),
|
|
|
- onClick: handleEdit.bind(null, row, true),
|
|
|
- },
|
|
|
- {
|
|
|
- label: '查看',
|
|
|
- type: 'text',
|
|
|
- disabled: !hasAccessByCodes(['query:view']),
|
|
|
- onClick: handleView.bind(null, row.code),
|
|
|
- },
|
|
|
- ]"
|
|
|
- :drop-down-actions="[
|
|
|
- {
|
|
|
- label: '删除',
|
|
|
- type: 'link',
|
|
|
- disabled: !hasAccessByCodes(['query:delete']),
|
|
|
- onClick: handleDelete.bind(null, row.id),
|
|
|
- },
|
|
|
- ]"
|
|
|
- />
|
|
|
- </template>
|
|
|
</Grid>
|
|
|
</Page>
|
|
|
</template>
|