actionSerialItem.vue 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <template>
  2. <div class="type-item">
  3. <div v-for="(item, index) in serial" :key="index" class="item " :class="index > 0 ? 'biankang' : ''">
  4. <div class="conicon" style="width: 100%; text-align: right; position: relative; right: -8px; top: -8px; color: red" v-if="index > 0">
  5. <el-icon @click="delScene(index)">
  6. <CircleClose />
  7. </el-icon>
  8. </div>
  9. <div class="product flex flex-warp" style="flex-flow: row wrap;justify-content: flex-start;align-items: flex-start !important">
  10. <el-form-item label="动作类型:" prop="actionType" class="form-item">
  11. <el-select v-model="item.actionType" filterable clearable placeholder="请选择动作类型" @change="saveData" style="width: 100%;">
  12. <el-option v-for="it in sence_action_type" :key="it.value" :label="it.label" :value="it.value">
  13. <span style="float: left">{{ it.label }}</span>
  14. <span style="float: right; font-size: 13px">{{ it.value }}</span>
  15. </el-option>
  16. </el-select>
  17. </el-form-item>
  18. <DeviceOut :index="index" :data="serial[index]" :sourceData="sourceData" v-if="item.actionType === 'deviceOutput' && serial[index] && sourceData.length > 0" @SetSaveData="SetSaveData"></DeviceOut>
  19. <SendNotice :index="index" :data="serial[index]" v-else-if="item.actionType === 'sendNotice' && serial[index]" @SetSaveData="SetSaveData"></SendNotice>
  20. <CallWebService :index="index" :data="serial[index]" v-else-if="item.actionType === 'callWebService' && serial[index]" @SetSaveData="SetSaveData"></CallWebService>
  21. <TriggerAlarm :index="index" :data="serial[index]" v-else-if="item.actionType === 'triggerAlarm' && serial[index]" @SetSaveData="SetSaveData"></TriggerAlarm>
  22. <DelayExecution :index="index" :data="serial[index]" v-else-if="item.actionType === 'delayExecution' && serial[index]" @SetSaveData="SetSaveData"></DelayExecution>
  23. <TriggerCustomEvent :index="index" :data="serial[index]" v-else-if="item.actionType === 'triggerCustomEvent' && serial[index]" @SetSaveData="SetSaveData"></TriggerCustomEvent>
  24. </div>
  25. </div>
  26. <div>
  27. <div class=" flex-center">
  28. <el-button :icon="DocumentAdd" @click="addScene()" style="border: 1px solid #409eff;color: #409eff;">新增串行动作</el-button>
  29. </div>
  30. </div>
  31. </div>
  32. </template>
  33. <script lang="ts" setup>
  34. import { PropType, ref, watch, getCurrentInstance } from 'vue'
  35. import { DocumentAdd, CircleClose } from '@element-plus/icons-vue';
  36. import DeviceOut from './actionType/deviceOut.vue';
  37. import SendNotice from './actionType/sendNotice.vue';
  38. import CallWebService from './actionType/callWebService.vue';
  39. import TriggerAlarm from './actionType/triggerAlarm.vue';
  40. import DelayExecution from './actionType/delayExecution.vue';
  41. import TriggerCustomEvent from './actionType/triggerCustomEvent.vue';
  42. const emit = defineEmits(['addScenesDetail', 'delData', 'saveData']);
  43. const { proxy } = getCurrentInstance() as any;
  44. const { sence_action_type } = proxy.useDict('sence_action_type');
  45. interface IValueType {
  46. actionType?: string;
  47. }
  48. interface testIValueType {
  49. key?: string;
  50. name?: string;
  51. }
  52. const props = defineProps({
  53. serial: {
  54. type: Array as PropType<IValueType[]>,
  55. default: () => []
  56. },
  57. sourceData: {
  58. type: Array as PropType<testIValueType[]>,
  59. default: () => []
  60. },
  61. index: {
  62. type: Number,
  63. default: () => []
  64. }
  65. })
  66. const serialValue = ref(props.serial);
  67. const saveData = () => {
  68. let newData = {
  69. index: props.index,
  70. data: props.serial,
  71. }
  72. emit('saveData', newData);
  73. }
  74. watch(() => props.serial, (newSerial) => {
  75. serialValue.value = newSerial;
  76. });
  77. const SetSaveData = (data: any) => {
  78. serialValue.value[data.index] = data.data;
  79. let newData = {
  80. index: props.index,
  81. data: serialValue.value,
  82. }
  83. emit('saveData', newData);
  84. }
  85. const addScene = () => {
  86. props.serial.push({
  87. 'actionType': '',
  88. });
  89. };
  90. const delScene = (index: number) => {
  91. props.serial.splice(index, 1);
  92. let newData = {
  93. index: props.index,
  94. data: props.serial,
  95. }
  96. emit('saveData', newData);
  97. }
  98. </script>
  99. <style scoped lang="scss">
  100. .type-item {
  101. width: 100%;
  102. .edit {
  103. margin-left: 10px;
  104. color: #2041d4;
  105. }
  106. .conicon {
  107. width: 55px;
  108. height: 25px;
  109. font-size: 28px;
  110. line-height: 28px;
  111. cursor: pointer;
  112. }
  113. .item {
  114. margin-bottom: 20px;
  115. }
  116. .biankang {
  117. border-top: 1px solid #d6d6d6;
  118. // border-radius: 10px;
  119. }
  120. .title {
  121. height: 40px;
  122. .icon {
  123. margin-left: 2px;
  124. margin-right: 10px;
  125. width: 5px;
  126. height: 20px;
  127. background-color: #315efb;
  128. }
  129. }
  130. .product {
  131. margin-bottom: 20px;
  132. :deep(.el-form-item) {
  133. margin-left: 30px;
  134. margin-bottom: 10px;
  135. }
  136. }
  137. }
  138. .form-item {
  139. // flex: 0 0 25%;
  140. // flex: 1;
  141. width: 30%;
  142. max-width: 30%;
  143. min-width: 30%;
  144. overflow: hidden;
  145. }
  146. </style>