powerControl.vue 26 KB

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