powerControl.vue 26 KB

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