smartVentilation.vue 26 KB

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