| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- <script lang="ts" setup>
- import type { OnActionClickParams, VxeTableGridOptions } from '#/adapter';
- import { Page, useVbenModal } from '@vben/common-ui';
- import { Button, message } from 'ant-design-vue';
- import { useTableGridOptions, useVbenVxeGrid } from '#/adapter';
- import { CmsSiteApi } from '#/api';
- import FormDomain from '../domain/index.vue';
- import FormMenu from '../menu/index.vue';
- import FormEdit from './components/edit.vue';
- import { useColumns, useSearchSchema } from './data.config';
- const [FormEditModal, formEditApi] = useVbenModal({
- connectedComponent: FormEdit,
- });
- const [FormDomainModal, formDomainApi] = useVbenModal({
- connectedComponent: FormDomain,
- });
- const [FormMenuModal, formMenuApi] = useVbenModal({
- connectedComponent: FormMenu,
- });
- const handelSuccess = () => {
- reload();
- };
- const handleDelete = async (id: number) => {
- await CmsSiteApi.deleteDetail(id);
- message.success('数据删除成功');
- handelSuccess();
- };
- const handleUpdateStatus = async (record: any) => {
- await CmsSiteApi.updateStatus({
- id: record.id,
- status: record.status === 1 ? 2 : 1,
- });
- handelSuccess();
- };
- const handleEdit = (record: any, isUpdate: boolean) => {
- formEditApi
- .setData({
- isUpdate,
- baseData: { id: record.id },
- })
- .open();
- };
- const handleDomain = (record: any) => {
- formDomainApi
- .setData({
- baseData: { ...record },
- })
- .open();
- };
- const handleMenu = (record: any) => {
- formMenuApi
- .setData({
- baseData: { ...record },
- })
- .open();
- };
- const handleActionClick = async ({
- code,
- row,
- }: OnActionClickParams<CmsSiteApi.RecordItem>) => {
- switch (code) {
- case 'delete': {
- await handleDelete(row.id);
- break;
- }
- case 'domain': {
- await handleDomain(row);
- break;
- }
- case 'edit': {
- handleEdit(row, true);
- break;
- }
- case 'menu': {
- await handleMenu(row);
- break;
- }
- case 'setStatus': {
- await handleUpdateStatus(row);
- break;
- }
- }
- };
- const [Grid, { reload }] = useVbenVxeGrid(
- useTableGridOptions({
- formOptions: {
- schema: useSearchSchema(),
- },
- gridOptions: {
- columns: useColumns(handleActionClick),
- proxyConfig: {
- ajax: {
- query: async ({ page }, formValues) => {
- return await CmsSiteApi.getPage({
- pageIndex: page.currentPage,
- pageSize: page.pageSize,
- ...formValues,
- });
- },
- },
- },
- } as VxeTableGridOptions,
- }),
- );
- </script>
- <template>
- <Page auto-content-height>
- <FormEditModal @success="handelSuccess" />
- <FormMenuModal />
- <FormDomainModal />
- <Grid>
- <template #toolbar-tools>
- <Button
- class="mr-2"
- type="primary"
- v-access:code="'site:add'"
- @click="() => handleEdit({}, false)"
- >
- 新增站点
- </Button>
- </template>
- </Grid>
- </Page>
- </template>
|