detail.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. <template>
  2. <el-card class="system-dic-container" style="position: relative;">
  3. <div class="content">
  4. <div class="flex cont_box">
  5. <div class="font26">场景名称:{{ detail.name }}</div>
  6. <div class="pro-status"><span :class="detail.status == 1 ? 'on' : 'off'"></span>{{ detail.status == 1
  7. ? '启用' : '未启用' }}</div>
  8. </div>
  9. <div class="flex">
  10. <div class="desc">场景描述:{{ detail.description }}</div>
  11. <div class="edit" @click="addOrEdit(detail)"><el-link type="primary"> <el-icon>
  12. <EditPen color="#409eff" />
  13. </el-icon>修改</el-link></div>
  14. </div>
  15. </div>
  16. </el-card>
  17. <el-card style=" margin-top: 15px;">
  18. <div class="font20">场景定义</div>
  19. <SceneItem v-if="showstatus && sourceData.length>0" :sceneList="sceneList" :sourceData="sourceData" :sceneType="detail.sceneType" @addScenesDetail="addScenesDetail"
  20. @delScenesDetail="delScenesDetail" @editScenesDetail="editScenesDetail"></SceneItem>
  21. </el-card>
  22. <el-card style=" margin-top: 15px;">
  23. <div class="font20">场景动作</div>
  24. <ActionItem :actionList="actionList" :sourceData="sourceData"></ActionItem>
  25. </el-card>
  26. <EditForm ref="editFormRef" @getList="getDetail()"></EditForm>
  27. </template>
  28. <script lang="ts">
  29. import { toRefs, reactive, ref, defineComponent } from 'vue';
  30. import { useRoute, useRouter } from 'vue-router';
  31. import { EditPen, DocumentAdd } from '@element-plus/icons-vue';
  32. import ActionItem from './component/actionItem.vue';
  33. import SceneItem from './component/sceneItem.vue';
  34. import EditForm from './edit.vue';
  35. import api from '/@/api/scene';
  36. import product from '/@/api/device';
  37. const editFormRef = ref();
  38. //原始
  39. const sceneList = {
  40. 'productKey': '',
  41. 'deviceKey': '',
  42. 'triggerType': '',
  43. 'timer': '',
  44. 'triggerSwitch': false,
  45. 'condition': [[{
  46. 'parameter': '',
  47. 'operator': '',
  48. 'value': ''
  49. }]]
  50. };
  51. const originalSceneList = ref([{
  52. id: 0
  53. }]);
  54. export default defineComponent({
  55. components: { EditPen, EditForm, DocumentAdd, SceneItem, ActionItem },
  56. setup(props, context) {
  57. const route = useRoute();
  58. const router = useRouter();
  59. const state = reactive({
  60. developer_status: 2,
  61. showstatus: false,
  62. sourceData: [],
  63. detail: {
  64. name: '',
  65. status: 0,
  66. description: '',
  67. sceneType: ''
  68. },
  69. actionList: [{
  70. 'seriallist': [{
  71. }],
  72. 'parallellist': [{
  73. }]
  74. }],
  75. sceneList: [{
  76. 'productKey': '',
  77. 'deviceKey': '',
  78. 'triggerType': '',
  79. 'timer': '',
  80. 'triggerSwitch': false,
  81. 'condition': [[{
  82. 'parameter': '',
  83. 'operator': '',
  84. 'value': ''
  85. }]]
  86. }],
  87. });
  88. const activeName = ref('first')
  89. const getDetail = () => {
  90. const id = route.params && route.params.id;
  91. api.manage.getDetail({ "id": id }).then((res: any) => {
  92. state.detail = res
  93. })
  94. getOneDetail();
  95. };
  96. const getProductList = () => {
  97. product.product.getSubList().then((res: any) => {
  98. state.sourceData = res.product;
  99. });
  100. };
  101. const getOneDetail = () => {
  102. const id = route.params && route.params.id;
  103. api.manage.getOneDetail({ "sceneId": id, 'group': 'definition' }).then((res: any) => {
  104. if (!res) {
  105. addScenesDetail('definition');
  106. getOneDetail();
  107. }
  108. originalSceneList.value = res;
  109. const scenes = res.map((scene: any) => {
  110. const parsedBodyJson = JSON.parse(scene.bodyjson);
  111. return {
  112. ...parsedBodyJson
  113. };
  114. });
  115. getProductList();
  116. state.sceneList = scenes;
  117. state.showstatus = true;
  118. })
  119. };
  120. //新增一条场景定义
  121. const addScenesDetail = (type: String) => {
  122. let data = {
  123. sceneId: route.params && route.params.id,
  124. group: type,
  125. bodyjson: sceneList,
  126. }
  127. api.manage.addDetail(data).then((res: any) => {
  128. getOneDetail();
  129. });
  130. }
  131. //删除一条场景
  132. const delScenesDetail = (index: number) => {
  133. let ids = originalSceneList.value[index].id;
  134. api.manage.delDetail(ids).then((res: any) => {
  135. // getOneDetail();
  136. });
  137. }
  138. //修改一条场景
  139. const editScenesDetail = (index: number) => {
  140. let saveData = state.sceneList[index];
  141. let ids = originalSceneList.value[index].id;
  142. api.manage.editDetail({ id: ids, bodyjson: saveData }).then((res: any) => {
  143. getOneDetail();
  144. });
  145. }
  146. const addOrEdit = async (row?: any) => {
  147. editFormRef.value.open(row);
  148. };
  149. getDetail();
  150. return {
  151. addOrEdit,
  152. delScenesDetail,
  153. addScenesDetail,
  154. editScenesDetail,
  155. editFormRef,
  156. activeName,
  157. getDetail,
  158. ...toRefs(props),
  159. ...toRefs(state),
  160. };
  161. },
  162. });
  163. </script>
  164. <style scoped lang="scss">
  165. .desc {
  166. margin-top: 15px;
  167. }
  168. .edit {
  169. line-height: 40px;
  170. margin-top: 15px;
  171. margin-left: 30px;
  172. }
  173. .cont_box .pro-status {
  174. line-height: 40px;
  175. margin-left: 30px;
  176. margin-top: 5px;
  177. .on {
  178. background: #52c41a;
  179. }
  180. .off {
  181. background: #c41a1a;
  182. }
  183. span {
  184. position: relative;
  185. top: -1px;
  186. display: inline-block;
  187. width: 6px;
  188. height: 6px;
  189. vertical-align: middle;
  190. border-radius: 50%;
  191. margin-right: 5px;
  192. }
  193. }
  194. </style>