smartVentilation.vue 26 KB

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