| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- <script lang="ts" setup>
- import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
- import { useAccess } from '@vben/access';
- import { alert, Page, useVbenModal } from '@vben/common-ui';
- import { Button } from 'ant-design-vue';
- import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
- import { DatabaseApi } from '#/api';
- import { TableAction } from '#/components/table-action';
- import FormEdit from './components/edit.vue';
- import { useColumns, useSearchSchema } from './data.config';
- const { hasAccessByCodes } = useAccess();
- const [FormEditModal, formEditApi] = useVbenModal({
- connectedComponent: FormEdit,
- });
- const handleDelete = async (id: number) => {
- await DatabaseApi.deleteDetail(id);
- alert('数据删除成功');
- reload();
- };
- const handelCreate = async (id: number) => {
- await DatabaseApi.getCreate(id);
- alert('创建表成功');
- reload();
- };
- const handleEdit = (record: any, isUpdate: boolean) => {
- formEditApi
- .setData({
- isUpdate,
- baseData: { id: record.id },
- })
- .open();
- };
- const handelSuccess = () => {
- reload();
- };
- const handleActionClick = async ({
- code,
- row,
- }: OnActionClickParams<DatabaseApi.RecordItem>) => {
- switch (code) {
- case 'create': {
- handelCreate(row.id);
- break;
- }
- case 'delete': {
- await handleDelete(row.id);
- break;
- }
- case 'edit': {
- handleEdit(row, true);
- break;
- }
- }
- };
- const [Grid, { reload }] = useVbenVxeGrid(
- useTableGridOptions({
- formOptions: {
- schema: useSearchSchema(),
- },
- gridOptions: {
- columns: useColumns(handleActionClick),
- proxyConfig: {
- ajax: {
- query: async ({ page }, formValues) => {
- return await DatabaseApi.getPage({
- pageIndex: page.currentPage,
- pageSize: page.pageSize,
- ...formValues,
- });
- },
- },
- },
- } as VxeTableGridOptions,
- }),
- );
- </script>
- <template>
- <Page auto-content-height>
- <FormEditModal @success="handelSuccess" />
- <Grid>
- <template #toolbar-tools>
- <Button
- class="mr-2"
- type="primary"
- v-access:code="'table:add'"
- @click="() => handleEdit({}, false)"
- >
- 新增表
- </Button>
- </template>
- <template #action="{ row }">
- <TableAction
- :actions="[
- {
- label: '编辑',
- type: 'text',
- disabled: !hasAccessByCodes(['table:edit']),
- onClick: handleEdit.bind(null, row, true),
- },
- {
- label: '创建表',
- type: 'text',
- disabled: !hasAccessByCodes(['table:create']),
- onClick: handelCreate.bind(null, row.id),
- },
- ]"
- :drop-down-actions="[
- {
- label: '删除',
- type: 'link',
- disabled: !hasAccessByCodes(['table:delete']),
- onClick: handleDelete.bind(null, row.id),
- },
- ]"
- />
- </template>
- </Grid>
- </Page>
- </template>
|