AddCameraByIP.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <template>
  2. <div>
  3. <div style="margin-bottom: 120px">
  4. <el-form
  5. class="ip-form"
  6. :inline="true"
  7. :model="cameraIPData"
  8. :rules="rules"
  9. label-width="84px"
  10. label-position="left"
  11. >
  12. <el-form-item
  13. v-for="item in cameraIPAddForm"
  14. :key="item.prop"
  15. :label="item.label"
  16. :prop="item.prop"
  17. >
  18. <el-input
  19. v-if="item.type === 'input'"
  20. v-model="cameraIPData[item.prop]"
  21. :placeholder="item.placeholder"
  22. style="width: 200px"
  23. :type="item.prop === 'password' ? 'password' : ''"
  24. :show-password="item.prop === 'password'"
  25. />
  26. <el-select
  27. v-if="item.type === 'select'"
  28. v-model="cameraIPData[item.prop]"
  29. :placeholder="item.placeholder"
  30. style="width: 200px"
  31. >
  32. <el-option
  33. v-for="protocal in item.option"
  34. :key="protocal.value"
  35. :label="protocal.label"
  36. :value="protocal.value"
  37. />
  38. </el-select>
  39. <el-tree-select
  40. v-if="item.type === 'tree-select'"
  41. v-model="cameraIPData[item.prop]"
  42. :data="scenesTree"
  43. :render-after-expand="false"
  44. :default-expand-all="true"
  45. check-strictly
  46. :placeholder="item.placeholder"
  47. style="width: 200px"
  48. />
  49. </el-form-item>
  50. </el-form>
  51. </div>
  52. <span class="pop-footer">
  53. <el-button @click="handleCancel">取消</el-button>
  54. <el-button type="primary" @click="handleConfirm">确定</el-button>
  55. </span>
  56. </div>
  57. </template>
  58. <script setup lang="ts">
  59. import { computed, onBeforeMount, ref } from 'vue';
  60. import { CameraIPItem } from '../type';
  61. import { cameraIPAddForm } from '../constant';
  62. import useSceneInfos from '@/hooks/useSceneInfos';
  63. import { cloneDeep } from 'lodash-es';
  64. const props = defineProps<{ formData?: CameraIPItem | null }>();
  65. const emits = defineEmits(['cancel-execute', 'confirm-execute']);
  66. const sceneInfos = useSceneInfos();
  67. const { scenesTree, flattendWorkspaces, getScenesTree } = sceneInfos;
  68. const cameraIPData = ref<CameraIPItem>({} as CameraIPItem);
  69. const rules = computed(() => {
  70. const newRule = {};
  71. cameraIPAddForm.forEach((item) => {
  72. if (item.required) {
  73. newRule[item.prop] = item.rule;
  74. }
  75. });
  76. return newRule;
  77. });
  78. const handleCancel = () => {
  79. emits('cancel-execute');
  80. };
  81. const handleConfirm = () => {
  82. const copyData = cloneDeep(cameraIPData.value);
  83. copyData.workspaceId = flattendWorkspaces.value.find(
  84. (item) => item.code === cameraIPData.value.workspaceId,
  85. ).id;
  86. emits('confirm-execute', copyData);
  87. };
  88. onBeforeMount(() => {
  89. getScenesTree({ level: 3, valueKey: 'code', labelKey: 'name', disabled: true });
  90. if (props.formData) {
  91. cameraIPData.value = props.formData;
  92. }
  93. });
  94. </script>
  95. <style scoped>
  96. .ip-form {
  97. width: 768px;
  98. display: flex;
  99. flex-wrap: wrap;
  100. justify-content: space-between;
  101. align-content: space-around;
  102. }
  103. .pop-footer {
  104. position: absolute;
  105. right: 24px;
  106. bottom: 27px;
  107. display: flex;
  108. justify-content: flex-end;
  109. }
  110. :deep(.el-form-item__label) {
  111. font-size: 14px;
  112. color: #363636;
  113. padding: 0;
  114. }
  115. :deep(.el-form--inline .el-form-item) {
  116. display: flex;
  117. margin-right: 0;
  118. margin-bottom: 28px;
  119. }
  120. </style>