index.vue 5.85 KB
<template>
  <div>
    <PageWrapper dense contentFullHeight contentClass="flex">
      <OrganizationIdTree
        class="w-1/4 xl:w-1/5"
        @select="handleSelect"
        ref="organizationIdTreeRef"
      />
      <BasicTable
        :clickToRowSelect="false"
        @register="registerTable"
        :searchInfo="searchInfo"
        class="w-3/4 xl:w-4/5"
      >
        <template #toolbar>
          <a-button type="primary" @click="handleCreateOrEdit(null)"> 新增视频 </a-button>
          <a-button
            type="primary"
            color="error"
            @click="handleDeleteOrBatchDelete(null)"
            :disabled="hasBatchDelete"
          >
            批量删除
          </a-button>
        </template>
        <template #img="{ record }">
          <TableImg
            :size="30"
            :showBadge="false"
            :simpleShow="true"
            :imgList="
              typeof record.avatar !== 'undefined' && record.avatar !== '' && record.avatar != null
                ? [record.avatar]
                : null
            "
          />
        </template>
        <template #action="{ record }">
          <TableAction
            :actions="[
              {
                label: '预览',
                icon: 'clarity:note-edit-line',
                onClick: handleViewVideo.bind(null, record),
              },
              {
                label: '编辑',
                icon: 'clarity:note-edit-line',
                onClick: handleCreateOrEdit.bind(null, record),
              },
              {
                label: '删除',
                icon: 'ant-design:delete-outlined',
                color: 'error',
                popConfirm: {
                  title: '是否确认删除',
                  confirm: handleDeleteOrBatchDelete.bind(null, record),
                },
              },
            ]"
          />
        </template>
      </BasicTable>
    </PageWrapper>
    <ContactDrawer @register="registerDrawer" @success="handleSuccess" />
    <VideoPreviewModal @register="registerModal" />
  </div>
</template>

<script lang="ts">
  import { defineComponent, reactive, ref, computed } from 'vue';
  import { BasicTable, useTable, TableAction, TableImg } from '/@/components/Table';
  import { PageWrapper } from '/@/components/Page';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { useDrawer } from '/@/components/Drawer';
  import ContactDrawer from './ContactDrawer.vue';
  import { useResetOrganizationTree, OrganizationIdTree } from '/@/views/common/organizationIdTree';
  import { cameraPage, deleteCameraManage } from '/@/api/camera/cameraManager';
  import { searchFormSchema, columns } from './config.data';
  import VideoPreviewModal from './DialogPreviewVideo.vue';
  import { useModal } from '/@/components/Modal';

  export default defineComponent({
    components: {
      PageWrapper,
      OrganizationIdTree,
      BasicTable,
      TableAction,
      ContactDrawer,
      VideoPreviewModal,
      TableImg,
    },
    setup() {
      let selectedRowIds = ref<string[]>([]);
      const hasBatchDelete = computed(() => selectedRowIds.value.length <= 0);
      // 复选框事件
      const onSelectRowChange = (selectedRowKeys: string[]) => {
        selectedRowIds.value = selectedRowKeys;
      };
      const searchInfo = reactive<Recordable>({});
      const { organizationIdTreeRef, resetFn } = useResetOrganizationTree(searchInfo);
      const [registerModal, { openModal }] = useModal();
      // 表格hooks
      const [registerTable, { reload }] = useTable({
        title: '视频列表',
        api: cameraPage,
        columns,
        showIndexColumn: false,
        clickToRowSelect: false,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
          resetFunc: resetFn,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        rowSelection: {
          onChange: onSelectRowChange,
          type: 'checkbox',
        },
        rowKey: 'id',
        actionColumn: {
          width: 200,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });
      // 弹框
      const [registerDrawer, { openDrawer }] = useDrawer();
      const { createMessage } = useMessage();

      // 刷新
      const handleSuccess = () => {
        reload();
      };
      // 新增或编辑
      const handleCreateOrEdit = (record: Recordable | null) => {
        if (record) {
          openDrawer(true, {
            isUpdate: true,
            record,
          });
        } else {
          openDrawer(true, {
            isUpdate: false,
          });
        }
      };
      // 删除或批量删除
      const handleDeleteOrBatchDelete = async (record: Recordable | null) => {
        if (record) {
          try {
            await deleteCameraManage([record.id]);
            createMessage.success('删除视频成功');
            handleSuccess();
          } catch (e) {}
        } else {
          try {
            await deleteCameraManage(selectedRowIds.value);
            createMessage.success('批量删除视频成功');
            selectedRowIds.value = [];
            handleSuccess();
          } catch (e) {}
        }
      };

      // 树形选择器
      const handleSelect = (organizationId: string) => {
        searchInfo.organizationId = organizationId;
        handleSuccess();
      };
      const handleViewVideo = (record) => {
        openModal(true, {
          isUpdate: true,
          record,
        });
      };
      return {
        searchInfo,
        hasBatchDelete,
        handleCreateOrEdit,
        handleDeleteOrBatchDelete,
        handleSelect,
        handleSuccess,
        registerTable,
        registerDrawer,
        organizationIdTreeRef,
        handleViewVideo,
        registerModal,
      };
    },
  });
</script>