powerControl.vue 26 KB

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