smartVentilation.vue 27 KB

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