smartVentilation.vue 27 KB

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