powerControl.vue 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. <!--硬件管理/电源控制-->
  2. <template>
  3. <div class="powerControl">
  4. <el-table v-loading="loading" border :data="hardwareList" @selection-change="handleSelectionChange">
  5. <el-table-column label="名称" align="left" prop="name" />
  6. <el-table-column label="学院" align="left" prop="deptName" />
  7. <el-table-column label="实验室" align="left" prop="subjectName" />
  8. <el-table-column label="继电器编号" align="left" prop="relayCode" />
  9. <el-table-column label="状态" align="left" >
  10. <template slot-scope="scope">
  11. <p :class="scope.row.status==4?'table-type-color-ash':(scope.row.status==3?'table-type-color-green':(scope.row.status==0?'table-type-color-red':''))">{{scope.row.status==4?'关闭':(scope.row.status==3?'开启':(scope.row.status==0?'离线':(!scope.row.status?'未知':'')))}}</p>
  12. </template>
  13. </el-table-column>
  14. <el-table-column label="开关" align="left" >
  15. <template slot-scope="scope">
  16. <!--@change="(event)=>switchChange(event,scope.row.id)"-->
  17. <el-switch
  18. v-if="scope.row.status == 3||scope.row.status == 4"
  19. class="switch"
  20. @click.native="changeIsNeedCaptcha(scope.row)"
  21. v-model="scope.row.status"
  22. :active-value="3"
  23. :inactive-value="4"
  24. active-text="开"
  25. inactive-text="关"
  26. disabled
  27. >
  28. </el-switch>
  29. <p v-else :class="scope.row.status==0?'table-type-color-red':''">{{scope.row.status==0?'离线':'未知'}}</p>
  30. </template>
  31. </el-table-column>
  32. <!--<el-table-column label="开关" align="left" >-->
  33. <!--<template slot-scope="scope">-->
  34. <!--<el-switch-->
  35. <!--class="switch"-->
  36. <!--@change="switchChange(scope.row.deptId)"-->
  37. <!--v-model="scope.row.deptId"-->
  38. <!--:active-value="1"-->
  39. <!--:inactive-value="0"-->
  40. <!--active-text="开"-->
  41. <!--inactive-text="关"-->
  42. <!--&gt;-->
  43. <!--</el-switch>-->
  44. <!--</template>-->
  45. <!--</el-table-column>-->
  46. <el-table-column label="操作" align="left" class-name="small-padding fixed-width" width="120" v-if="tableButtonType">
  47. <template slot-scope="scope">
  48. <div class="button-box">
  49. <el-dropdown @command="moreClick">
  50. <p class="table-min-button">更多>></p>
  51. <el-dropdown-menu slot="dropdown">
  52. <el-dropdown-item style="border-bottom:1px solid #E0E0E0;margin:0 10px;" :command="{row:scope.row,command:1}"
  53. v-hasPermiAnd="['laboratory:hardware:query','laboratory:hardware:edit']">修改设备</el-dropdown-item>
  54. <el-dropdown-item style="margin:0 10px;" :command="{row:scope.row,command:2}"
  55. v-hasPermi="['laboratory:hardware:remove']">删除设备</el-dropdown-item>
  56. </el-dropdown-menu>
  57. </el-dropdown>
  58. </div>
  59. </template>
  60. </el-table-column>
  61. </el-table>
  62. <pagination
  63. v-show="total>0"
  64. :total="total"
  65. layout="total, prev, pager, next, sizes, jumper"
  66. :page.sync="queryParams.pageNum"
  67. :limit.sync="queryParams.pageSize"
  68. @pagination="getList"
  69. />
  70. <!-- 添加或修改硬件对话框 -->
  71. <el-drawer
  72. class="videoSurveillance-drawer"
  73. :visible.sync="drawer"
  74. direction="rtl"
  75. ref="drawer"
  76. :with-header="false"
  77. :show-close="false"
  78. :before-close="handleClose">
  79. <div class="videoSurveillance-drawer-max-box">
  80. <div class="videoSurveillance-drawer-content">
  81. <el-form ref="form" :model="form" :rules="rules" label-width="80px">
  82. <el-form-item label="硬件名称" prop="name">
  83. <el-input
  84. v-model="form.name"
  85. placeholder="请输入硬件名称"
  86. clearable
  87. size="small"
  88. maxLength="8"
  89. />
  90. </el-form-item>
  91. <el-form-item label="硬件类型" v-if="pageType==''" prop="type">
  92. <el-select v-model="form.type" placeholder="请选择硬件类型">
  93. <el-option label="请选择硬件类型" value="" />
  94. <el-option v-for="hardType in hardTypeOptions"
  95. :key="hardType.enumName"
  96. :label="hardType.name"
  97. :value="hardType.enumName">
  98. </el-option>
  99. </el-select>
  100. </el-form-item>
  101. <el-form-item label="实验室" prop="subjectId">
  102. <el-select v-model="form.subjectId" placeholder="请选择实验室">
  103. <el-option v-for="lab in labListOptions"
  104. :key="lab.id"
  105. :label="lab.name"
  106. :value="lab.id">
  107. </el-option>
  108. </el-select>
  109. </el-form-item>
  110. <el-form-item label="继电器类型" label-width="1rem">
  111. <el-radio-group v-model="form.hardwareType" @change="radioChange">
  112. <el-radio :label="item.value" :key="item.value" v-for="(item,index) in hardwardTypeList">{{item.label}}</el-radio>
  113. </el-radio-group>
  114. </el-form-item>
  115. <el-form-item label="绑定继电器" prop="relayCode" v-if="form.hardwareType==1">
  116. <el-select v-model="form.relayCode" placeholder="请选择继电器" clearable @change="loadRelayNum" @clear="loadClear">
  117. <el-option v-for="relay in relayList"
  118. :key="relay.code"
  119. :label="relay.code"
  120. :value="relay.code">
  121. </el-option>
  122. </el-select>
  123. </el-form-item>
  124. <el-form-item label="继电器编号" prop="relayCode" v-if="form.hardwareType==2">
  125. <el-input
  126. v-model="form.relayCode"
  127. placeholder="请输入继电器编号"
  128. clearable
  129. size="small"
  130. maxlength="20"
  131. />
  132. </el-form-item>
  133. <el-form-item label="继电器位置" prop="bit" >
  134. <el-select v-model="form.bit" placeholder="请选择继电器位置" clearable >
  135. <el-option v-for="lab in relayNumList"
  136. :key="lab.name"
  137. :label="lab.name"
  138. :value="lab.name">
  139. </el-option>
  140. </el-select>
  141. </el-form-item>
  142. <el-form-item label="配置名称" prop="relayCode" v-if="form.hardwareType==2">
  143. <el-input
  144. v-model="form.configName"
  145. placeholder="请输入配置名称"
  146. clearable
  147. size="small"
  148. maxLength="15"
  149. />
  150. </el-form-item>
  151. <el-form-item label="配置状态" prop="relayCode" v-if="form.hardwareType==2">
  152. <el-input
  153. v-model="form.configStatus"
  154. placeholder="请输入配置状态"
  155. clearable
  156. size="small"
  157. maxLength="8"
  158. />
  159. </el-form-item>
  160. </el-form>
  161. </div>
  162. <div class="videoSurveillance-bottom-button-box">
  163. <p></p>
  164. <p @click="offDrawer">取消</p>
  165. <p @click="submitForm">提交</p>
  166. </div>
  167. </div>
  168. </el-drawer>
  169. </div>
  170. </template>
  171. <script>
  172. import mqtt from 'mqtt'
  173. import { subjectDictList } from "@/api/laboratory/group";
  174. import { listDepartments } from "@/api/system/dept";
  175. import { listHardware, getHardware, delHardware, addHardware, updateHardware,queryHardwareType,getHardwareDetail,getSubjectLayout,hardWareControl } from "@/api/laboratory/hardware";
  176. import { treeselect } from "@/api/system/dept";
  177. import Treeselect from "@riophae/vue-treeselect";
  178. import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  179. import { listRelay } from "@/api/laboratory/relay";
  180. export default {
  181. props:{
  182. pageType:{},
  183. queryParams:{}
  184. },
  185. components: { Treeselect },
  186. name: "powerControl",
  187. data() {
  188. return {
  189. tableButtonType:this.hasPermiDom(['laboratory:hardware:query','laboratory:hardware:edit','laboratory:hardware:remove']),
  190. index:'',
  191. // 遮罩层
  192. loading: true,
  193. // 选中数组
  194. ids: [],
  195. // 非单个禁用
  196. single: true,
  197. // 非多个禁用
  198. multiple: true,
  199. // 显示搜索条件
  200. showSearch: true,
  201. // 总条数
  202. total: 0,
  203. // 硬件表格数据
  204. hardwareList: [],
  205. // 弹出层标题
  206. title: "",
  207. // 是否显示弹出层
  208. open: false,
  209. // 部门树选项
  210. deptOptions: [],
  211. subjectOptions: undefined,
  212. isUpdate:false,
  213. // 表单参数
  214. form: {
  215. hardwareType:1
  216. },
  217. // 表单校验
  218. rules: {
  219. name: [
  220. { required: true, message: "请输入硬件名称", trigger: "blur" },
  221. { required: true, message: "请输入硬件名称", validator: this.spaceJudgment, trigger: "blur" }
  222. ],
  223. type: [
  224. { required: true, message: "请选择硬件类型", trigger: "blur" }
  225. ],
  226. subjectId:[
  227. { required: true, message: "请选择实验室", trigger: "blur" },
  228. ]
  229. },
  230. hardTypeOptions:{},
  231. labListOptions:{},
  232. // 关联实验室弹窗开关
  233. drawer:false,
  234. drawerData:{
  235. name:"甲烷检测实验室",
  236. text:"描述内容描述内容描述内容描述内容描述内容描述内容描述内容描述内容描述内容描述内容",
  237. img:"",
  238. },
  239. mapData:{
  240. widthData:"60",
  241. heightData:"123",
  242. list:[
  243. {
  244. id: "",
  245. top:0,
  246. left:0
  247. }
  248. ]
  249. },
  250. mapList:[],
  251. // 继电器
  252. relayList: [],
  253. relayNumList:[
  254. {name:1},
  255. {name:2},
  256. {name:3},
  257. {name:4},
  258. {name:5},
  259. {name:6},
  260. {name:7},
  261. {name:8},
  262. {name:9},
  263. {name:10},
  264. {name:11},
  265. {name:12}
  266. ],
  267. hardwardTypeList:[
  268. {value:1,label:"老继电器"},
  269. {value:2,label:"新继电器"}
  270. ],
  271. mtopic:"lab/hardware/data",
  272. //mqtt发送id数组
  273. mqttIdList:[],
  274. };
  275. },
  276. created() {
  277. this.getList();
  278. this.getDeptList();
  279. },
  280. methods: {
  281. radioChange(){
  282. let self = this;
  283. self.relayNumList=[];
  284. let num = 12;
  285. if(this.form.hardwareType==2){
  286. let list = [];
  287. for(let i=0;i<num;i++){
  288. let obj = {
  289. name:i+1
  290. }
  291. list.push(obj);
  292. }
  293. self.relayNumList = list;
  294. }
  295. },
  296. // 开启关闭验证
  297. async changeIsNeedCaptcha (row) {
  298. let self = this;
  299. console.log(row.status)
  300. if(row.status!=3 && row.status!=4){
  301. return
  302. }
  303. let text = row.status==3?'关闭':(row.status==4?'开启':'')
  304. this.$confirm(`是否`+text+`此设备`, "提示", {
  305. confirmButtonText: "确定",
  306. cancelButtonText: "取消",
  307. type: "warning"
  308. }).then(async () => {
  309. self.switchChange(row)
  310. }).catch(() => {
  311. })
  312. },
  313. //开关按钮
  314. switchChange(row){
  315. let switchData = {
  316. id:row.id,
  317. switchVal:row.status==3?'close':(row.status==4?'open':'')
  318. };
  319. hardWareControl(switchData).then(response => {
  320. console.log(response.data);
  321. if(response.code==200){
  322. row.status = row.status==3?4:(row.status==4?3:'')
  323. }
  324. });
  325. },
  326. //删除
  327. delBox(item){
  328. console.log(item)
  329. },
  330. moveClick(index){
  331. this.moveIndex = index
  332. console.log(",index",index)
  333. },
  334. //锚点拖动
  335. move(e){
  336. let odiv = e.target; //获取目标元素
  337. //算出鼠标相对元素的位置
  338. let disX = e.clientX - odiv.offsetLeft;
  339. let disY = e.clientY - odiv.offsetTop;
  340. document.onmousemove = (e)=>{ //鼠标按下并移动的事件
  341. //用鼠标的位置减去鼠标相对元素的位置,得到元素的位置
  342. let left = e.clientX - disX;
  343. let top = e.clientY - disY;
  344. //绑定元素位置到positionX和positionY上面
  345. //移动当前元素
  346. if(left>0&&left<(this.mapData.widthData*3-60)){
  347. odiv.style.left = left + 'px';
  348. this.mapData.list[this.moveIndex].left = left;
  349. this.mapData.list[this.moveIndex].minLeft = parseInt(left/6);
  350. }
  351. if(top>0&&top<(this.mapData.heightData*3-60)){
  352. odiv.style.top = top + 'px';
  353. this.mapData.list[this.moveIndex].top = top;
  354. this.mapData.list[this.moveIndex].minTop = parseInt(top/6);
  355. }
  356. };
  357. document.onmouseup = (e) => {
  358. document.onmousemove = null;
  359. document.onmouseup = null;
  360. };
  361. },
  362. getHardTypeList(){
  363. queryHardwareType().then(response => {
  364. if(response.code==200){
  365. this.hardTypeOptions=response.data;
  366. }
  367. console.log(this.hardTypeOptions)
  368. });
  369. },
  370. //关联实验室弹窗
  371. drawerBoxOnTwo(){
  372. this.drawerTwo = true;
  373. },
  374. //关联实验室弹窗
  375. drawerBoxOn(){
  376. this.drawer = true;
  377. },
  378. //关闭弹窗
  379. offDrawer(){
  380. this.$refs.drawer.closeDrawer();
  381. },
  382. //弹窗关闭前回调
  383. handleClose(done) {
  384. this.$confirm('确认关闭?')
  385. .then(_ => {
  386. done();
  387. })
  388. .catch(_ => {});
  389. },
  390. //更多选项
  391. moreClick(item){
  392. if(item.command == 1){
  393. this.handleUpdate(item.row)
  394. }else if(item.command == 2){
  395. this.handleDelete(item.row)
  396. }
  397. },
  398. getLabList(){
  399. subjectDictList().then(response => {
  400. console.log(response)
  401. if(response.code==200){
  402. this.labListOptions=response.data;
  403. }
  404. console.log(this.labListOptions)
  405. });
  406. },
  407. /** 查询硬件列表 */
  408. getList() {
  409. this.offMQTT();
  410. this.loading = true;
  411. this.queryParams.type = this.pageType;
  412. listHardware(this.queryParams).then(response => {
  413. this.hardwareList = response.rows;
  414. this.total = response.total;
  415. this.loading = false;
  416. //处理实验室id
  417. let list = [];
  418. for(let i=0;i<response.rows.length;i++){
  419. let num = 0;
  420. for(let o=0;o<list.length;o++){
  421. if(response.rows[i].subjectId == list){
  422. num++
  423. }
  424. }
  425. if(num == 0){
  426. list.push(response.rows[i].subjectId)
  427. }
  428. }
  429. this.$set(this,'mqttIdList',list);
  430. this.subscriptionMQTT();
  431. });
  432. },
  433. //MQTT订阅
  434. subscriptionMQTT(){
  435. let self = this;
  436. this.client = mqtt.connect(process.env.VUE_APP_BASE_MQTT_API, {
  437. username: process.env.VUE_APP_BASE_MQTT_USERNAME,
  438. password: process.env.VUE_APP_BASE_MQTT_PASSWORD
  439. });
  440. this.client.on("connect", e =>{
  441. console.log("连接成功");
  442. for(let i=0;i<self.mqttIdList.length;i++){
  443. this.client.subscribe(this.mtopic+self.mqttIdList[i], (err) => {
  444. if (!err) {
  445. console.log("订阅成功:" + this.mtopic+self.mqttIdList[i]);
  446. }
  447. });
  448. }
  449. });
  450. this.client.on("message", (topic, message) => {
  451. if (message){
  452. let data = JSON.parse(message)
  453. // this.getStatistics();
  454. for(let i=0;i<data.data.length;i++){
  455. for(let o=0;o<self.hardwareList.length;o++){
  456. if(data.data[i].num == self.hardwareList[o].id){
  457. if (data.data[i].hardwareOperate == 'CLOSE') {
  458. self.$set(self.hardwareList[o],'status',4);
  459. } else if (data.data[i].hardwareOperate == 'OPEN') {
  460. self.$set(self.hardwareList[o],'status',3);
  461. } else if (data.data[i].hardwareOperate == 'OFFLINE') {
  462. self.$set(self.hardwareList[o],'status',0);
  463. }
  464. }
  465. }
  466. }
  467. }
  468. });
  469. },
  470. // 查询继电器列表
  471. getRelayList(){
  472. listRelay({"type": 1}).then(response => {
  473. this.relayList = response.data;
  474. if(this.form.relayCode){
  475. let self = this
  476. let num = ""
  477. for(let i=0;i<self.relayList.length;i++){
  478. if(self.relayList[i].code == this.form.relayCode){
  479. num = self.relayList[i].routeNum
  480. }
  481. }
  482. let list = [];
  483. for(let i=0;i<num;i++){
  484. let obj = {
  485. name:i+1
  486. }
  487. list.push(obj);
  488. }
  489. this.relayNumList = list;
  490. }
  491. });
  492. },
  493. // 取消按钮
  494. cancel() {
  495. this.open = false;
  496. this.reset();
  497. },
  498. //清空按钮
  499. loadClear(){
  500. this.form.bit = '';
  501. },
  502. loadRelayNum(e){
  503. let self = this;
  504. let num = ""
  505. for(let i=0;i<self.relayList.length;i++){
  506. if(self.relayList[i].code == e){
  507. num = self.relayList[i].routeNum
  508. }
  509. }
  510. let list = [];
  511. for(let i=0;i<num;i++){
  512. let obj = {
  513. name:i+1
  514. }
  515. list.push(obj);
  516. }
  517. this.relayNumList = list;
  518. },
  519. loadHardware(){
  520. let self = this;
  521. this.mapList = [];
  522. let newId = this.mapData.list[0].id;
  523. // this.mapData.list = [];
  524. let queryParam = {};
  525. if(this.form.id){
  526. queryParam.id = this.form.id;
  527. }else{
  528. queryParam.id = -1;
  529. }
  530. queryParam.subjectId = this.form.subjectId;
  531. getHardwareDetail(queryParam).then(response => {
  532. let subHardList = response.data.subjectHardPosiList;
  533. for(var i=0;i<subHardList.length;i++){
  534. if(response.data.subjectHardPosiList[i].id!=newId){
  535. this.mapList.push({"name":response.data.subjectHardPosiList[i].hardName,"y":(response.data.subjectHardPosiList[i].horizontalAxis/3).toFixed(0),"x":(response.data.subjectHardPosiList[i].verticalAxis/3).toFixed(0)});
  536. }
  537. }
  538. this.$forceUpdate()
  539. });
  540. getSubjectLayout(this.form.subjectId).then(response => {
  541. if(response.data){
  542. this.mapData.widthData = response.data.layWidth;
  543. this.mapData.heightData = response.data.layHeight;
  544. }else{
  545. this.mapData.widthData = 60;
  546. this.mapData.heightData = 123;
  547. }
  548. this.$forceUpdate()
  549. });
  550. let obj = JSON.parse(JSON.stringify(this.mapData.list[0]));
  551. obj.x = 0;
  552. obj.y = 0;
  553. obj.top = 0;
  554. obj.left = 0;
  555. this.mapData.list.splice(0,1);
  556. setTimeout(function(){
  557. self.mapData.list.push(obj);
  558. },50);
  559. this.$forceUpdate()
  560. },
  561. /** 查询实验室字典列表 */
  562. getSubjectDictList (deptId) {
  563. this.subjectOptions = null;
  564. this.loading = true;
  565. // this.queryParams.deptId = deptId;
  566. let params = {};
  567. params.deptId = deptId;
  568. this.queryParams.subjectId = "";
  569. subjectDictList(params).then(response => {
  570. this.subjectOptions = response.data;
  571. this.loading = false;
  572. });
  573. },
  574. /** 查询学院列表 */
  575. getDeptList() {
  576. listDepartments().then(response => {
  577. this.$set(this, 'deptOptions', response.data)
  578. });
  579. },
  580. // 筛选节点
  581. filterNode(value, data) {
  582. if (!value) return true;
  583. return data.label.indexOf(value) !== -1;
  584. },
  585. // 节点单击事件
  586. handleNodeClick(data) {
  587. this.queryParams.deptId = data;
  588. // console.log("data",data);
  589. this.getSubjectDictList(data);
  590. // this.getList();
  591. },
  592. // 表单重置
  593. reset() {
  594. this.form = {
  595. id: null,
  596. name: null,
  597. factory: null,
  598. type: null,
  599. macAdd: null,
  600. subjectId: null,
  601. deptId: null,
  602. deptName: null,
  603. operate: 0,
  604. createTime: null,
  605. userId: null,
  606. createBy: null,
  607. updateTime: null,
  608. updateBy: null,
  609. remark: null
  610. };
  611. this.resetForm("form");
  612. },
  613. /** 搜索按钮操作 */
  614. handleQuery() {
  615. this.queryParams.pageNum = 1;
  616. this.getList();
  617. },
  618. /** 重置按钮操作 */
  619. resetQuery() {
  620. this.resetForm("queryForm");
  621. this.handleQuery();
  622. },
  623. // 多选框选中数据
  624. handleSelectionChange(selection) {
  625. this.ids = selection.map(item => item.id)
  626. this.single = selection.length!==1
  627. this.multiple = !selection.length
  628. },
  629. /** 新增按钮操作 */
  630. handleAdd() {
  631. // this.reset();
  632. // this.open = true;
  633. // this.title = "添加硬件";
  634. // this.getHardTypeList();
  635. // this.getLabList();
  636. // this.form.type=this.pageType;
  637. this.reset();
  638. this.mapList = []
  639. this.mapData.list = [{
  640. id: "",
  641. top:0,
  642. left:0
  643. }];
  644. this.isUpdate=true;
  645. this.form.hardwareType=1;
  646. this.form.type=this.pageType;
  647. this.drawer = true;
  648. this.title = "添加硬件";
  649. this.getHardTypeList();
  650. this.getLabList();
  651. this.getRelayList();
  652. },
  653. /** 修改按钮操作 */
  654. handleUpdate(row) {
  655. this.reset();
  656. this.mapList = [];
  657. this.mapData.list = [];
  658. this.isUpdate=true;
  659. this.form.type=this.pageType;
  660. this.getHardTypeList();
  661. this.getLabList();
  662. const id = row.id || this.ids
  663. let queryParam = {};
  664. queryParam.id = id;
  665. queryParam.subjectId = row.subjectId;
  666. getHardwareDetail(queryParam).then(response => {
  667. this.form = response.data;
  668. this.$forceUpdate;
  669. this.getRelayList()
  670. this.title = "修改硬件";
  671. this.drawer = true;
  672. });
  673. },
  674. /** 提交按钮 */
  675. submitForm() {
  676. this.form.hardwarePosition={
  677. horizontalAxis:'',
  678. verticalAxis:''
  679. }
  680. this.form.type=this.pageType;
  681. // this.form.hardwarePosition.horizontalAxis=this.mapData.list[0].top;
  682. // this.form.hardwarePosition.verticalAxis=this.mapData.list[0].left;
  683. this.$refs["form"].validate(valid => {
  684. if (valid) {
  685. if (this.form.id != null) {
  686. updateHardware(this.form).then(response => {
  687. this.msgSuccess("修改成功");
  688. this.drawer = false;
  689. this.getList();
  690. });
  691. } else {
  692. addHardware(this.form).then(response => {
  693. this.msgSuccess("新增成功");
  694. this.drawer = false;
  695. this.getList();
  696. });
  697. }
  698. }
  699. });
  700. // this.$refs["form"].validate(valid => {
  701. // if (valid) {
  702. // if (this.form.id != null) {
  703. // updateHardware(this.form).then(response => {
  704. // this.msgSuccess("修改成功");
  705. // this.open = false;
  706. // this.getList();
  707. // });
  708. // } else {
  709. // console.log("this.form",this.form)
  710. // addHardware(this.form).then(response => {
  711. // this.msgSuccess("新增成功");
  712. // this.open = false;
  713. // this.getList();
  714. // });
  715. // }
  716. // }
  717. // });
  718. },
  719. /** 删除按钮操作 */
  720. handleDelete(row) {
  721. const ids = row.id || this.ids;
  722. this.$confirm('是否确认删除硬件?', "警告", {
  723. confirmButtonText: "确定",
  724. cancelButtonText: "取消",
  725. type: "warning"
  726. }).then(function() {
  727. return delHardware(ids);
  728. }).then(() => {
  729. this.getList();
  730. this.msgSuccess("删除成功");
  731. }).catch(() => {});
  732. },
  733. /** 导出按钮操作 */
  734. handleExport() {
  735. this.download('laboratory/hardware/export', {
  736. ...this.queryParams
  737. }, `laboratory_hardware.xlsx`)
  738. },
  739. //取消订阅关闭MQTT连接
  740. offMQTT(){
  741. let self = this;
  742. if (self.mqttIdList[0]) {
  743. for (let i = 0; i < self.mqttIdList.length; i++) {
  744. self.client.unsubscribe(this.mtopic + self.mqttIdList[i], error => {
  745. if (error) {
  746. console.log('Unsubscribe error', error)
  747. }
  748. })
  749. }
  750. self.client.end();
  751. self.client = {};
  752. }
  753. },
  754. },
  755. beforeDestroy() {
  756. //清除定时器
  757. let self = this;
  758. self.offMQTT();
  759. console.log("beforeDestroy");
  760. },
  761. };
  762. </script>
  763. <style scoped lang="scss">
  764. .powerControl{
  765. flex: 1;
  766. display: flex!important;
  767. flex-direction: column;
  768. padding:20px!important;
  769. overflow: hidden;
  770. .form-box{
  771. }
  772. .button-box{
  773. width:90px;
  774. display: flex;
  775. }
  776. }
  777. </style>