AddCameraByIP.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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-form-item>
  40. </el-form>
  41. </div>
  42. <span class="pop-footer">
  43. <el-button @click="handleCancel">取消</el-button>
  44. <el-button type="primary" @click="handleConfirm">确定</el-button>
  45. </span>
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. import { computed, onBeforeMount, ref } from 'vue';
  50. import { CameraIPItem } from '../type';
  51. import { cameraIPAddForm } from '../constant';
  52. const props = defineProps<{ formData?: CameraIPItem | null }>();
  53. const emits = defineEmits(['cancel-execute', 'confirm-execute']);
  54. const cameraIPData = ref<CameraIPItem>({} as CameraIPItem);
  55. const rules = computed(() => {
  56. const newRule = {};
  57. cameraIPAddForm.forEach((item) => {
  58. if (item.required) {
  59. newRule[item.prop] = item.rule;
  60. }
  61. });
  62. return newRule;
  63. });
  64. const handleCancel = () => {
  65. emits('cancel-execute');
  66. };
  67. const handleConfirm = () => {
  68. emits('confirm-execute', cameraIPData.value);
  69. };
  70. onBeforeMount(() => {
  71. if (props.formData) {
  72. cameraIPData.value = props.formData;
  73. }
  74. });
  75. </script>
  76. <style scoped>
  77. .ip-form {
  78. width: 768px;
  79. display: flex;
  80. flex-wrap: wrap;
  81. justify-content: space-between;
  82. align-content: space-around;
  83. }
  84. .pop-footer {
  85. position: absolute;
  86. right: 24px;
  87. bottom: 27px;
  88. display: flex;
  89. justify-content: flex-end;
  90. }
  91. :deep(.el-form-item__label) {
  92. font-size: 14px;
  93. color: #363636;
  94. padding: 0;
  95. }
  96. :deep(.el-form--inline .el-form-item) {
  97. display: flex;
  98. margin-right: 0;
  99. margin-bottom: 28px;
  100. }
  101. </style>