meLaboratory.vue 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. <!-- 我的实验室 -->
  2. <template>
  3. <view id="meLaboratory">
  4. <view class="top-picker-max-box">
  5. <view class="top-picker-box">
  6. <picker @change="facultyChange" :value="facultyIndex" :range="facultyArray">
  7. <view class="picker-view">
  8. <view>{{!facultyIndex?'学院':facultyArray[facultyIndex]}}</view>
  9. <img class="picker-img" src="@/images/icon_06.png" alt="">
  10. </view>
  11. </picker>
  12. </view>
  13. <view class="top-picker-box">
  14. <picker @change="subjectChange" :value="subjectIndex" :range="subjectArray">
  15. <view class="picker-view">
  16. <view>{{!subjectIndex?'分类':subjectArray[subjectIndex]}}</view>
  17. <img class="picker-img" src="@/images/icon_06.png" alt="">
  18. </view>
  19. </picker>
  20. </view>
  21. <view class="top-picker-box">
  22. <picker @change="levelChange" :value="levelIndex" :range="levelArray">
  23. <view class="picker-view">
  24. <view>{{!levelIndex?'分级':levelArray[levelIndex]}}</view>
  25. <img class="picker-img" src="@/images/icon_06.png" alt="">
  26. </view>
  27. </picker>
  28. </view>
  29. </view>
  30. <view class="for-max-box">
  31. <img class="null-img" v-if="!dataList[0]" src="@/images/null-data-1.png">
  32. <view class="for-box" v-for="(item,index) in dataList" :key="index" @click="laboratoryInfo(item)">
  33. <view class="title-box">
  34. <view :style="'border:1rpx solid '+item.fiedColor+';background:#fff;color:'+item.fiedColor+';'">{{item.levelName}}</view>
  35. <view>{{item.name}}</view>
  36. <img src="@/images/icon_04.png">
  37. </view>
  38. <view class="address-box"><span>{{item.typeName}}</span>{{item.deptName}}</view>
  39. <view class="address-box-two">
  40. <img src="@/images/icon_14.png">
  41. <view>{{item.subAddrrStr}}</view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </template>
  47. <script>
  48. import $mqtt from '@/utils/mqtt.min.js';
  49. import { config } from '@/api/request/config.js'
  50. import { laboratoryList,subject_class,listDepartments,mangerControl,laboratoryInfo } from '@/api/index.js'
  51. export default {
  52. data() {
  53. return {
  54. dataList:[],
  55. subject_classData:[],
  56. //MQTT请求参数-传感器
  57. client:{},
  58. mqttIdList:[],
  59. //院系选择器数据
  60. facultyList:[],
  61. facultyArray:[],
  62. facultyIndex:"",
  63. //学科选择器数据
  64. subjectList:[],
  65. subjectArray:[],
  66. subjectIndex:"",
  67. //级别选择器数据
  68. levelList:[
  69. {dictLabel:"全部级别", dictValue:""},
  70. {dictLabel:"一级", dictValue:"1"},
  71. {dictLabel:"二级", dictValue:"2"},
  72. {dictLabel:"三级", dictValue:"3"},
  73. {dictLabel:"四级", dictValue:"4"},
  74. ],
  75. levelArray:['全部级别','一级','二级','三级','四级'],
  76. levelIndex:"",
  77. }
  78. },
  79. onLoad() {
  80. },
  81. onShow(){
  82. this.listDepartments();
  83. this.subject_class();
  84. //监听传感器信息
  85. getApp().watch(this.getMqttSensorData,'mqttSensorData')
  86. },
  87. methods: {
  88. //监听传感器信息
  89. getMqttSensorData(val){
  90. let self = this;
  91. // console.log('页面获取的-传感器信息',val)
  92. if(val.subId){
  93. for(let i=0;i<self.dataList.length;i++){
  94. if(self.dataList[i].id == val.subId){
  95. self.$set(self.dataList[i],'sensorFunctionList',val.functionStatuses);
  96. }
  97. }
  98. }
  99. },
  100. async laboratoryInfo(item){
  101. const {data} = await laboratoryInfo(item.id);
  102. if(data.code == 200){
  103. let obj = data.data[0];
  104. obj.subClassVO = item.subClassVO;
  105. obj.name = item.name;
  106. obj.subTypeLable = item.subTypeLable;
  107. obj.deptName = item.deptName;
  108. obj.subAddrrStr = item.subAddrrStr;
  109. obj.sensorFunctionList = item.sensorFunctionList;
  110. uni.navigateTo({
  111. url: '/pages_manage/workbench/laboratory/laboratoryInfo?item='+encodeURIComponent(JSON.stringify(obj))+'&deptId='+item.deptId
  112. });
  113. }
  114. },
  115. //滚动选择器
  116. facultyChange: function(e) {
  117. if(this.facultyArray[0]){
  118. this.facultyIndex = parseInt(e.target.value);
  119. this.laboratoryList();
  120. }
  121. },
  122. subjectChange: function(e) {
  123. if(this.subjectArray[0]){
  124. this.subjectIndex = parseInt(e.target.value);
  125. this.laboratoryList();
  126. }
  127. },
  128. levelChange: function(e) {
  129. if(this.levelArray[0]){
  130. this.levelIndex = parseInt(e.target.value);
  131. this.laboratoryList();
  132. }
  133. },
  134. //设备开关按钮
  135. hardwareButton(minItem,command){
  136. let self = this;
  137. let text = '';
  138. if(command == 'close'){
  139. text = '关闭';
  140. }else if(command == 'open'){
  141. text = '开启';
  142. }
  143. uni.showModal({
  144. content: '确认要'+text+'吗?',
  145. cancelColor:"#999",
  146. confirmColor:"#0183FA",
  147. success: function (res) {
  148. if (res.confirm) {
  149. self.mangerControl(minItem,command);
  150. console.log('用户点击确定');
  151. } else if (res.cancel) {
  152. console.log('用户点击取消');
  153. }
  154. }
  155. });
  156. },
  157. //设备开关
  158. async mangerControl(minItem,command){
  159. let obj = {
  160. id:minItem.id,
  161. command:command,
  162. };
  163. const {data} = await mangerControl(obj);
  164. if(data.code == 200){
  165. if(command == 'open'){
  166. minItem.type = 3;
  167. }else if(command == 'close'){
  168. minItem.type = 4;
  169. }
  170. uni.showToast({
  171. title: '操作成功',
  172. icon:"none",
  173. mask:true,
  174. duration: 2000
  175. });
  176. }
  177. },
  178. //获取院系
  179. async listDepartments(){
  180. const {data} = await listDepartments();
  181. if(data.code == 200){
  182. let list = [];
  183. for(let i=0;i<data.data.length;i++){
  184. list.push(data.data[i].deptName)
  185. }
  186. this.facultyArray = list;
  187. list.unshift('全部院系');
  188. this.facultyList = data.data;
  189. this.facultyList.unshift({deptName:"全部院系", deptId:""})
  190. }
  191. },
  192. //获取学科字典
  193. async subject_class(){
  194. const {data} = await subject_class();
  195. if(data.code == 200){
  196. this.subject_classData = data.data;
  197. let list = [];
  198. for(let i=0;i<data.data.length;i++){
  199. list.push(data.data[i].dictLabel)
  200. }
  201. this.subjectArray = list;
  202. list.unshift('全部分类');
  203. this.subjectList = data.data;
  204. this.subjectList.unshift({dictLabel:"全部分类", dictValue:""})
  205. this.laboratoryList()
  206. }
  207. },
  208. //获取实验室列表
  209. async laboratoryList(){
  210. let self = this;
  211. let obj = {
  212. deptId:this.facultyIndex?this.facultyList[this.facultyIndex].deptId:'',
  213. subDept:this.subjectIndex?this.subjectList[this.subjectIndex].dictValue:'',
  214. level:this.levelIndex?this.levelList[this.levelIndex].dictValue:'',
  215. };
  216. const {data} = await laboratoryList(obj);
  217. if(data.code == 200){
  218. for(let o=0;o<data.data.length;o++){
  219. if(data.data[o].labHardwareVOList){
  220. data.data[o].hardwareList = [];
  221. for(let i=0;i<data.data[o].labHardwareVOList.length;i++){
  222. if(data.data[o].labHardwareVOList[i].hardwareTypeEnum.code == 4 &&data.data[o].labHardwareVOList[i].hardwareNUM){
  223. if(data.data[o].hardwareNUM){
  224. data.data[o].hardwareNUM = data.data[o].hardwareNUM + ',' + data.data[o].labHardwareVOList[i].hardwareNUM
  225. }else{
  226. data.data[o].hardwareNUM = data.data[o].labHardwareVOList[i].hardwareNUM
  227. }
  228. }else{
  229. let obj = {
  230. name:"",
  231. type:"",
  232. };
  233. obj.name = data.data[o].labHardwareVOList[i].hardwareTypeEnum.hardwareTypeName
  234. obj.type = data.data[o].labHardwareVOList[i].state.code;
  235. obj.id = data.data[o].labHardwareVOList[i].id;
  236. data.data[o].hardwareList.push(obj);
  237. }
  238. }
  239. }
  240. }
  241. this.dataList = data.data;
  242. let list = [];
  243. let obj = {
  244. type:"lab/function/data",
  245. idList:[],
  246. }
  247. let objOne = {
  248. type:"lab/hardware/data",
  249. idList:[],
  250. }
  251. for(let i=0;i<self.dataList.length;i++){
  252. let num = 0;
  253. for(let o=0;o<obj.idList.length;o++){
  254. if(obj.idList[o] == self.dataList[i].id){
  255. num++
  256. }
  257. }
  258. if(num == 0){
  259. obj.idList.push(self.dataList[i].id)
  260. objOne.idList.push(self.dataList[i].id)
  261. }
  262. }
  263. list.push(obj);
  264. list.push(objOne);
  265. this.$set(self,'mqttIdList',list);
  266. getApp().appMqttOn(1,list);
  267. // self.subscriptionMQTT();
  268. }
  269. },
  270. },
  271. onHide(){
  272. // this.offMQTT();
  273. // //删除传感器监听
  274. // getApp().appMqttOn(2);
  275. getApp().deleteSensorWatch();
  276. console.log("onHide",this.mtopic);
  277. },
  278. beforeDestroy(){
  279. // this.offMQTT();
  280. // //删除传感器监听
  281. getApp().offMQTT();
  282. getApp().deleteSensorWatch();
  283. console.log("beforeDestroy",this.mtopic);
  284. }
  285. }
  286. </script>
  287. <style lang="stylus" scoped>
  288. #meLaboratory{
  289. height:100%;
  290. display flex
  291. flex-direction column
  292. .top-picker-max-box{
  293. display:flex;
  294. padding:0 20rpx;
  295. background #fff
  296. border-bottom:1rpx solid #E0E0E0;
  297. .top-picker-box{
  298. line-height:80rpx;
  299. height:80rpx;
  300. .picker-view{
  301. display flex
  302. view{
  303. display:block;
  304. overflow:hidden;
  305. text-overflow:ellipsis;
  306. white-space:nowrap;
  307. font-size:28rpx;
  308. }
  309. .picker-img{
  310. width:24rpx;
  311. height:13rpx;
  312. margin-top:36rpx;
  313. margin-left:13rpx;
  314. }
  315. }
  316. }
  317. .top-picker-box:nth-child(1){
  318. text-align left
  319. width:320rpx;
  320. .picker-view{
  321. view{
  322. max-width:260rpx;
  323. }
  324. }
  325. }
  326. .top-picker-box:nth-child(2){
  327. text-align left
  328. width:215rpx;
  329. .picker-view{
  330. view{
  331. max-width:156rpx;
  332. }
  333. }
  334. }
  335. .top-picker-box:nth-child(3){
  336. text-align right
  337. width:195rpx;
  338. .picker-view{
  339. view{
  340. flex:1;
  341. }
  342. }
  343. }
  344. }
  345. .for-max-box{
  346. flex:1;
  347. overflow-y scroll
  348. .null-img{
  349. display block
  350. width:276rpx;
  351. height:321rpx;
  352. position absolute
  353. top:200rpx;
  354. left:274rpx;
  355. }
  356. .for-box{
  357. overflow hidden
  358. background #ffffff
  359. margin-bottom:20rpx;
  360. .title-box{
  361. margin:20rpx 20rpx 0;
  362. display flex
  363. view:nth-child(1){
  364. height:40rpx;
  365. line-height:40rpx;
  366. font-size:20rpx;
  367. border-radius:10rpx;
  368. padding:0 20rpx;
  369. color:#fff;
  370. margin-right:20rpx;
  371. }
  372. view:nth-child(2){
  373. line-height:42rpx;
  374. font-size:30rpx;
  375. color:#333;
  376. max-width:600rpx;
  377. flex:1;
  378. }
  379. img{
  380. width:12rpx;
  381. height:20rpx;
  382. margin-top:11rpx;
  383. }
  384. .colorA{
  385. background:#aa2315;
  386. }
  387. .colorB{
  388. background:#ff9b09;
  389. }
  390. .colorC{
  391. background:#3ea3e9;
  392. }
  393. .colorD{
  394. background:#3ea34c;
  395. }
  396. }
  397. .address-box{
  398. margin:20rpx 20rpx;
  399. font-size:26rpx;
  400. color:#999999;
  401. span{
  402. margin-right:60rpx;
  403. }
  404. }
  405. .address-box-two{
  406. display flex
  407. margin:0 20rpx 20rpx 20rpx;
  408. img{
  409. width:28rpx;
  410. height:30rpx;
  411. margin-right:18rpx;
  412. }
  413. view{
  414. line-height:30rpx;
  415. font-size:24rpx;
  416. color:#999999;
  417. }
  418. }
  419. .text-box{
  420. /*border-top:1rpx dashed #e0e0e0;*/
  421. border-top:1rpx solid #E0E0E0;
  422. padding:0 20rpx;
  423. /*
  424. overflow-x:scroll;
  425. overflow-y:hidden;
  426. white-space: nowrap;
  427. */
  428. .min-box{
  429. display inline-block
  430. /*padding:0 30rpx 0 10rpx;*/
  431. width:355rpx;
  432. .min-min-box{
  433. display: flex
  434. img{
  435. width:30rpx;
  436. height:27rpx;
  437. margin-top:24rpx;
  438. margin-right:10rpx;
  439. }
  440. view{
  441. line-height:74rpx;
  442. text-align center
  443. font-size:28rpx;
  444. color:#333;
  445. }
  446. .colorA{
  447. color:#EE3A3A;
  448. }
  449. }
  450. }
  451. }
  452. .sensor-max-box{
  453. margin:0 20rpx;
  454. border-top:1rpx solid #e0e0e0;
  455. border-bottom:1rpx solid #e0e0e0;
  456. display flex
  457. .for-sensor-box{
  458. flex:1;
  459. display flex
  460. font-size:28rpx;
  461. line-height:94rpx;
  462. view{
  463. margin-left:20rpx;
  464. font-size:25rpx;
  465. line-height:94rpx;
  466. color:#0183FA;
  467. }
  468. }
  469. }
  470. .button-max-box{
  471. .button-box{
  472. display flex
  473. view:nth-child(1){
  474. flex:1;
  475. line-height:90rpx;
  476. color:#333333;
  477. margin-left:30rpx;
  478. font-size:28rpx;
  479. }
  480. view:nth-child(2){
  481. width:142rpx;
  482. line-height:42rpx;
  483. border:4rpx solid #0183FA;
  484. border-radius:25rpx;
  485. color: #0183FA;
  486. font-size: 30rpx;
  487. text-align center;
  488. margin:20rpx 20rpx 20rpx 0;
  489. }
  490. }
  491. .for-button-box{
  492. display flex
  493. view{
  494. flex:1;
  495. line-height:90rpx;
  496. color:#333333;
  497. margin-left:30rpx;
  498. font-size:28rpx;
  499. }
  500. img{
  501. height:50rpx;
  502. width:100rpx;
  503. margin:20rpx 20rpx 20rpx 0;
  504. }
  505. view:nth-child(2){
  506. text-align right
  507. color:#999;
  508. margin-right:30rpx;
  509. }
  510. }
  511. }
  512. }
  513. }
  514. }
  515. </style>