index.vue 5.65 KB
<template>
  <PageWrapper dense contentFullHeight fixedHeight contentClass="flex">
    <OrganizationIdTree class="w-1/6 xl:w-1/5" @select="handleSelect" />
    <BasicTable @register="registerTable" class="w-5/6 xl:w-4/5">
      <template #toolbar>
        <a-button type="primary" @click="handleCreate"> 新增设备 </a-button>
      </template>
      <template #deviceProfile="{ record }">
        <!-- <a-button type="link" class="ml-2" @click="goDeviceProfile">
          {{ record.deviceProfile.name }}
        </a-button> -->
      </template>
      <template #organizationId="{ record }">
        {{ record.organizationDTO.name }}
      </template>
      <template #deviceType="{ record }">
        <Tag color="success" class="ml-2">
          {{
            record.deviceType === DeviceTypeEnum.GATEWAY
              ? '网关设备'
              : record.deviceType === DeviceTypeEnum.DIRECT_CONNECTION
              ? '直连设备'
              : '网关子设备'
          }}
        </Tag>
      </template>
      <template #deviceState="{ record }">
        <Tag
          :color="
            record.deviceState == DeviceState.INACTIVE
              ? 'warning'
              : record.deviceState == DeviceState.ONLINE
              ? 'success'
              : 'error'
          "
          class="ml-2"
        >
          {{
            record.deviceState == DeviceState.INACTIVE
              ? '待激活'
              : record.deviceState == DeviceState.ONLINE
              ? '在线'
              : '离线'
          }}
        </Tag>
      </template>
      <template #action="{ record }">
        <TableAction
          :actions="[
            {
              label: '详情',
              icon: 'ant-design:eye-outlined',
              onClick: handleDetail.bind(null, record),
            },
            {
              label: '编辑',
              icon: 'clarity:note-edit-line',
              onClick: handleEdit.bind(null, record),
            },
            {
              label: '删除',
              icon: 'ant-design:delete-outlined',
              color: 'error',
              popConfirm: {
                title: '是否确认删除',
                confirm: handleDelete.bind(null, record),
              },
            },
          ]"
        />
      </template>
    </BasicTable>
    <DeviceDetailDrawer @register="registerDetailDrawer" />
    <DeviceModal @register="registerModal" @success="handleSuccess" @reload="handleReload" />
  </PageWrapper>
</template>
<script lang="ts">
  import { defineComponent, reactive } from 'vue';
  import { DeviceState, DeviceTypeEnum } from '/@/api/device/model/deviceModel';
  import { BasicTable, useTable, TableAction } from '/@/components/Table';
  import { columns, searchFormSchema } from './config/device.data';
  import { Tag } from 'ant-design-vue';
  import { useMessage } from '/@/hooks/web/useMessage';
  import { deleteDevice, devicePage } from '/@/api/device/deviceManager';
  import { PageEnum } from '/@/enums/pageEnum';
  import { useGo } from '/@/hooks/web/usePage';
  import { PageWrapper } from '/@/components/Page';
  import { useModal } from '/@/components/Modal';
  import OrganizationIdTree from '/@/views/common/OrganizationIdTree.vue';
  import DeviceModal from './cpns/modal/DeviceModal.vue';
  import { useDrawer } from '/@/components/Drawer';
  import DeviceDetailDrawer from './cpns/modal/DeviceDetailDrawer.vue';

  export default defineComponent({
    name: 'DeviceManagement',
    components: {
      BasicTable,
      PageWrapper,
      TableAction,
      OrganizationIdTree,
      Tag,
      DeviceModal,
      DeviceDetailDrawer,
    },
    setup(_) {
      const { createMessage } = useMessage();
      const go = useGo();

      const searchInfo = reactive<Recordable>({});
      const [registerModal, { openModal }] = useModal();
      const [registerDetailDrawer, { openDrawer }] = useDrawer();
      const [registerTable, { reload }] = useTable({
        title: '设备列表',
        api: devicePage,
        columns,
        formConfig: {
          labelWidth: 120,
          schemas: searchFormSchema,
        },
        useSearchForm: true,
        showTableSetting: true,
        bordered: true,
        showIndexColumn: false,
        searchInfo: searchInfo,
        actionColumn: {
          width: 200,
          title: '操作',
          dataIndex: 'action',
          slots: { customRender: 'action' },
          fixed: 'right',
        },
      });
      const handleReload = () => {
        handleSuccess();
      };

      function handleCreate() {
        openModal(true, {
          isUpdate: false,
        });
      }

      function handleDetail(record: Recordable) {
        openDrawer(true, {
          record,
        });
      }

      function handleEdit(record: Recordable) {
        openModal(true, {
          isUpdate: true,
          record,
        });
      }

      function handleDelete(record: Recordable) {
        let ids = [record.id];
        deleteDevice(ids).then(() => {
          createMessage.success('删除设备成功');
          handleSuccess();
        });
      }

      function handleSuccess() {
        reload();
      }
      function handleSelect(organization) {
        searchInfo.organizationId = organization;
        handleSuccess();
      }
      function goDeviceProfile() {
        go(PageEnum.DEVICE_PROFILE);
      }

      return {
        registerTable,
        handleCreate,
        handleDetail,
        handleEdit,
        handleDelete,
        handleSuccess,
        goDeviceProfile,
        handleSelect,
        registerModal,
        handleReload,
        registerDetailDrawer,
        DeviceTypeEnum,
        DeviceState,
        searchInfo,
      };
    },
  });
</script>