meLaboratory.vue 20 KB

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