powerControl.vue 26 KB

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