powerControl.vue 27 KB

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