sceneItem.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  1. <template>
  2. <div class="type-item">
  3. <div v-for="(item, index) in sceneList" :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"
  5. v-if="index > 0">
  6. <el-icon @click="delScene(index)">
  7. <CircleClose />
  8. </el-icon>
  9. </div>
  10. <div class="font16">场景定义</div>
  11. <div class="title flex">
  12. <div class="icon"></div>触发规则
  13. </div>
  14. <div class="product flex flex-warp">
  15. <el-form-item label="产品:" prop="product_key">
  16. <el-select v-model="item.product_key" filterable placeholder="请选择产品">
  17. <el-option v-for="it in sourceData" :key="it.key" :label="it.name" :value="it.key">
  18. <span style="float: left">{{ it.name }}</span>
  19. <span style="float: right; font-size: 13px">{{ it.key }}</span>
  20. </el-option>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="设备:" prop="device_key">
  24. <el-select v-model="item.device_key" filterable placeholder="请选择设备">
  25. <el-option v-for="it in sourceData" :key="it.key" :label="it.name" :value="it.key">
  26. <span style="float: left">{{ it.name }}</span>
  27. <span style="float: right; font-size: 13px">{{ it.key }}</span>
  28. </el-option>
  29. </el-select>
  30. </el-form-item>
  31. <el-form-item label="触发类型:" prop="type">
  32. <el-select v-model="item.type" filterable placeholder="请选择触发类型">
  33. <el-option v-for="it in sourceData" :key="it.key" :label="it.name" :value="it.key">
  34. <span style="float: left">{{ it.name }}</span>
  35. <span style="float: right; font-size: 13px">{{ it.key }}</span>
  36. </el-option>
  37. </el-select>
  38. </el-form-item>
  39. <el-form-item label="定时请求">
  40. <div style="display:flex">
  41. <el-input v-model="item.cronExpression" placeholder="请输入cron表达式" />
  42. <el-dialog v-model="dialogVisible" title="选择Cron规则" width="60%">
  43. <vue3cron @handlelisten="handlelisten" :type="index" @close="cronclose"></vue3cron>
  44. </el-dialog>
  45. <el-button type="success" @click="showCron()" style="margin-left: 5px;">设置</el-button>
  46. </div>
  47. </el-form-item>
  48. <el-form-item label="属性:" prop="type">
  49. <el-select v-model="item.type" filterable placeholder="请选择触发类型">
  50. <el-option v-for="it in sourceData" :key="it.key" :label="it.name" :value="it.key">
  51. <span style="float: left">{{ it.name }}</span>
  52. <span style="float: right; font-size: 13px">{{ it.key }}</span>
  53. </el-option>
  54. </el-select>
  55. </el-form-item>
  56. </div>
  57. <div class="title flex">
  58. <div class="icon"></div> 触发条件 <div class="ml10"> <el-switch v-model="item.where" />
  59. </div>
  60. </div>
  61. <Condition :condition="item.condition" :operate_index="index" v-if="item.where"></Condition>
  62. </div>
  63. <div>
  64. <div class="edit">
  65. <el-button type="primary" :icon="DocumentAdd" @click="addScene()">新增场景定义</el-button>
  66. </div>
  67. </div>
  68. </div>
  69. </template>
  70. <script lang="ts" setup>
  71. import { PropType, ref,unref } from 'vue'
  72. import { DocumentAdd, CircleClose, Right } from '@element-plus/icons-vue';
  73. import vue3cron from '/@/components/vue3cron/vue3cron.vue';
  74. import Condition from './condition.vue';
  75. const dialogVisible=ref();
  76. interface IConditionItem {
  77. param?: string;
  78. operator?: string;
  79. value?: string;
  80. }
  81. interface IValueType {
  82. type?: string;
  83. product_key?: string;
  84. device_key?: string;
  85. where?: string;
  86. cronExpression?: string;
  87. condition?: {
  88. list?: IConditionItem[] ;
  89. }[];
  90. }
  91. interface testIValueType {
  92. key: string;
  93. name?: string;
  94. }
  95. const props = defineProps({
  96. sceneList: {
  97. type: Array as PropType<IValueType[]>,
  98. default: () => []
  99. },
  100. sourceData: {
  101. type: Array as PropType<testIValueType[]>,
  102. default: () => [{
  103. 'key': 'test',
  104. 'name': '测试',
  105. }, {
  106. 'key': 'test',
  107. 'name': '测试',
  108. }, {
  109. 'key': 'test',
  110. 'name': '测试',
  111. }, {
  112. 'key': 'test',
  113. 'name': '测试',
  114. }, {
  115. 'key': 'test',
  116. 'name': '测试',
  117. }]
  118. }
  119. })
  120. const addScene = () => {
  121. props.sceneList.push({
  122. 'product_key': '',
  123. 'device_key': '',
  124. 'type': '',
  125. 'condition':[{
  126. 'list': [{
  127. 'param': '',
  128. 'operator': '',
  129. 'value': ''
  130. }]
  131. }]
  132. });
  133. console.log(props.sceneList);
  134. };
  135. const delScene = (index: number) => {
  136. props.sceneList.splice(index, 1);
  137. }
  138. const setNull = (row: any, key: string, val: string) => {
  139. if (!val) row[key] = null
  140. }
  141. const handlelisten = (e: any) => {
  142. props.sceneList[e.type].cronExpression=e.cron;
  143. };
  144. const showCron = () => {
  145. dialogVisible.value = true;
  146. };
  147. const cronclose = () => {
  148. dialogVisible.value = false;
  149. }
  150. </script>
  151. <style scoped lang="scss">
  152. .type-item {
  153. margin-top: 15px;
  154. .edit {
  155. margin-top: 15px;
  156. margin-left: 10px;
  157. color: #2041d4;
  158. }
  159. .conicon {
  160. width: 55px;
  161. height: 25px;
  162. font-size: 28px;
  163. line-height: 28px;
  164. cursor: pointer;
  165. }
  166. .item {
  167. padding: 20px;
  168. background-color: #f2f3f5;
  169. margin-top: 20px;
  170. }
  171. .biankang {
  172. border: 1px dashed #959596;;
  173. border-radius: 10px;
  174. }
  175. .title {
  176. height: 40px;
  177. .icon {
  178. margin-left: 2px;
  179. margin-right: 10px;
  180. width: 5px;
  181. height: 20px;
  182. background-color: #315efb;
  183. }
  184. }
  185. .product {
  186. .el-form-item {
  187. margin-left: 30px;
  188. margin-bottom: 10px;
  189. margin-top: 10px;
  190. }
  191. }
  192. }
  193. </style>