list.vue 4.41 KB
<template>
  <div>
    <BasicTable @register="registerTable">
      <template #content="{ record }">
        <a-button type="link" class="ml-2" @click="handleRecordContent(record)"> 查看 </a-button>
      </template>
      <template #toolbar>
        <a-button type="primary" @click="handleCreateOrEdit(null)"> 新增公共接口 </a-button>
        <Popconfirm
          title="您确定要批量删除数据"
          ok-text="确定"
          cancel-text="取消"
          @confirm="handleDeleteOrBatchDelete(null)"
        >
          <a-button color="error" :disabled="hasBatchDelete"> 批量删除 </a-button>
        </Popconfirm>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '发布',
              icon: 'ant-design:node-expand-outlined',
              onClick: handlePublish.bind(null, record),
              ifShow: () => {
                return record.state === 0;
              },
            },
            {
              label: '取消发布',
              icon: 'ant-design:node-collapse-outlined',
              onClick: handleCancelPublish.bind(null, record),
              ifShow: () => {
                return record.state === 1;
              },
            },
            {
              label: '修改',
              icon: 'clarity:note-edit-line',
              onClick: handleCreateOrEdit.bind(null, record),
              ifShow: () => {
                return record.state === 0;
              },
            },
            {
              label: '删除',
              icon: 'ant-design:delete-outlined',
              color: 'error',
              ifShow: () => {
                return record.state === 0;
              },
              popConfirm: {
                title: '是否确认删除',
                confirm: handleDeleteOrBatchDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
  </div>
  <PublicApiForm @register="registerDrawer" @success="handleSuccess" />
</template>
<script lang="ts" setup name="list">
  import { nextTick, h } from 'vue';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { useDrawer } from '/@/components/Drawer';
  import { columns, searchFormSchema } from './config';
  import { PublicApiForm } from './index';
  import {
    getDataViewInterfacePage,
    deleteBigViewInterface,
    getPublish,
    getCancelPublish,
  } from '/@/api/bigscreen/center/bigscreenCenter';
  import { useBatchDelete } from '/@/hooks/web/useBatchDelete';
  import { Popconfirm, Modal } from 'ant-design-vue';
  import { JsonPreview } from '/@/components/CodeEditor';
  import { useMessage } from '/@/hooks/web/useMessage';

  const [registerTable, { reload, setProps }] = useTable({
    api: getDataViewInterfacePage,
    columns,
    showIndexColumn: false,
    clickToRowSelect: false,
    showTableSetting: true,
    bordered: true,
    formConfig: {
      labelWidth: 120,
      schemas: searchFormSchema,
    },
    useSearchForm: true,
    actionColumn: {
      width: 150,
      title: '操作',
      dataIndex: 'action',
      slots: { customRender: 'action' },
      fixed: 'right',
    },
  });

  const [registerDrawer, { openDrawer }] = useDrawer();

  const { createMessage } = useMessage();

  const handleSuccess = () => reload();

  const { hasBatchDelete, handleDeleteOrBatchDelete, selectionOptions } = useBatchDelete(
    deleteBigViewInterface,
    handleSuccess,
    setProps
  );

  nextTick(() => {
    setProps(selectionOptions);
  });

  const handleCreateOrEdit = (record) => {
    const isUpdate = record === null ? false : true;
    const recordContent = record === null ? null : record;
    openDrawer(true, {
      isUpdate,
      record: recordContent,
    });
  };

  const handleRecordContent = (record) => {
    Modal.info({
      title: '接口内容',
      width: 600,
      content: h(JsonPreview, { data: JSON.parse(record.requestParams) }),
    });
  };

  const handlePublish = async (record) => {
    await getPublish(record.id);
    createMessage.success(`发布成功`);
    handleSuccess();
  };

  const handleCancelPublish = async (record) => {
    await getCancelPublish(record.id);
    createMessage.success(`取消发布成功`);
    handleSuccess();
  };
</script>