smartVentilation.vue 26 KB

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