DeviceModal.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <BasicModal
  3. v-bind="$attrs"
  4. @register="registerModal"
  5. :title="title"
  6. width="900px"
  7. :showCancelBtn="false"
  8. :showOkBtn="false"
  9. :footer="null"
  10. destroyOnClose
  11. >
  12. <a-tabs v-if="props.showTab">
  13. <a-tab-pane key="1" tab="基本信息" force-render>
  14. <FormModal :record="record" @saveOrUpdate="(values) => emit('saveOrUpdate', values)" />
  15. </a-tab-pane>
  16. <a-tab-pane key="2" tab="点表关联">
  17. <PointTable
  18. v-if="record.strtype"
  19. :columns="pointColumns"
  20. :pointType="record.strtype"
  21. :deviceId="deviceData.id"
  22. @save="savePointData"
  23. @delete="deletePointById"
  24. />
  25. </a-tab-pane>
  26. <a-tab-pane key="3" tab="设备关联" v-if="deviceType == 'managesys'">
  27. <WorkFacePointTable :columns="pointColumns" :deviceId="deviceData.id" @save="savePointData" @delete="deletePointById" />
  28. </a-tab-pane>
  29. <a-tab-pane key="4" tab="报警字段配置">
  30. <WarningTabel :deviceId="deviceData.id" :pointType="record.strtype" />
  31. </a-tab-pane>
  32. <a-tab-pane key="5" tab="摄像头配置"
  33. ><EditRowTable
  34. :columns="cameraColumns"
  35. :list="cameraList.bind(null, { deviceid: deviceData.id })"
  36. @saveOrUpdate="saveCameraData"
  37. @deleteById="deleteCameraById"
  38. :isAdd="true"
  39. /></a-tab-pane>
  40. </a-tabs>
  41. <FormModal v-else :record="record" @saveOrUpdate="(values) => emit('saveOrUpdate', values)" />
  42. </BasicModal>
  43. </template>
  44. <script lang="ts" setup>
  45. import { computed, unref, inject, reactive } from 'vue';
  46. import { BasicModal, useModalInner } from '/@/components/Modal';
  47. import EditRowTable from '../../comment/EditRowTable.vue';
  48. import PointTable from './pointTabel/PointTable.vue';
  49. import WarningTabel from './warningTabel/index.vue';
  50. import WorkFacePointTable from './pointTabel/WorkFacePointTable.vue';
  51. import FormModal from './FormModal.vue';
  52. import { cloneDeep } from 'lodash-es';
  53. import { columns as pointColumns } from './pointTabel/point.data';
  54. import { saveOrUpdate as pointSaveOrUpdate, deleteById as pointDeleteById, warningDeleteById } from './pointTabel/point.api';
  55. import { columns as cameraColumns } from './cameraTabel/camera.data';
  56. import { list as cameraList, saveOrUpdate as cameraSaveOrUpdate, deleteById as cameraDeleteById } from './cameraTabel/camera.api';
  57. const props = defineProps({
  58. showTab: { type: Boolean, required: true },
  59. deviceType: { type: String },
  60. });
  61. // 声明Emits
  62. const emit = defineEmits(['saveOrUpdate', 'register']);
  63. const isUpdate = inject('isUpdate');
  64. const deviceData = inject('formData') as any;
  65. const record = reactive({ strtype: '', strname: '' });
  66. //表单赋值
  67. const [registerModal, { setModalProps }] = useModalInner(async (data) => {
  68. //重置表单
  69. setModalProps({ confirmLoading: false });
  70. Object.assign(record, data.record);
  71. });
  72. //设置标题
  73. const title = computed(
  74. () => {
  75. if (!unref(isUpdate)) {
  76. if (record.strname || record.systemname) {
  77. return `新增(${record.strname || record.systemname})`;
  78. }
  79. return `新增`;
  80. } else {
  81. if (record.strname || record.systemname) {
  82. return `编辑(${record.strname || record.systemname})`;
  83. }
  84. return `编辑`;
  85. }
  86. }
  87. // !unref(isUpdate) ? `新增(${record.strname || record.systemname})` : `编辑(${record.strname || record.systemname})`
  88. );
  89. const savePointData = (data) => {
  90. const record = cloneDeep(data.editValueRefs);
  91. pointSaveOrUpdate(Object.assign(record, { id: data.id, deviceId: deviceData.id }), data.id);
  92. };
  93. const saveCameraData = (data: any) => {
  94. const record = cloneDeep(data.editValueRefs);
  95. cameraSaveOrUpdate(Object.assign(record, { id: data.id, deviceid: deviceData.id }), data.id);
  96. };
  97. const deletePointById = (id, reload) => {
  98. pointDeleteById({ id: id }, reload);
  99. };
  100. const deleteCameraById = (id, reload) => {
  101. cameraDeleteById({ id: id }, reload);
  102. };
  103. </script>
  104. <style scoped lang="less">
  105. ::v-deep .suffix {
  106. height: 32px;
  107. line-height: 32px;
  108. margin-left: 5px;
  109. color: #fff;
  110. }
  111. </style>