equipment.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 44px;">
  5. <view style="position: fixed;z-index: 100;width: 100%;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="设备详情"></uni-nav-bar>
  7. </view>
  8. <view class="info">
  9. <view class="info_item">
  10. <image :src="eqinfo.item.is_online==1?'http://www.hnyfwlw.com:8006/bigdata_app/image/cb/onBg.png':'http://www.hnyfwlw.com:8006/bigdata_app/image/cb/offBg.png'"
  11. mode="" class="bgi"></image>
  12. <p style="font-size: 32rpx;" @click="copy(eqinfo.item)">设备 ID:{{eqinfo.item.equip_id||eqinfo.item.device_id}}
  13. <image src="http://www.hnyfwlw.com:8006/bigdata_app/image/environment/fuzhi.png" mode="" class="tishi"></image>
  14. </p>
  15. <p>设备名称:{{eqinfo.item.equip_name?eqinfo.item.equip_name:"无"}}</p>
  16. <p>最近上报时间:<span v-if="eqinfo.item.uptime">{{eqinfo.item.uptime|timeFormat()}}</span><span v-else>{{eqinfo.item.addtime|timeFormat()}}</span></p>
  17. <p>地址:{{city}}</p>
  18. </view>
  19. </view>
  20. <view class="control">
  21. <view class="control_item" v-if="kongtf" @click="control">
  22. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/environment/8.png'" mode=""></image>
  23. <p>设备控制</p>
  24. </view>
  25. <view class="control_item" @click="repairs">
  26. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/environment/7.png'" mode=""></image>
  27. <p>一键报修</p>
  28. </view>
  29. <view class="control_item" v-if="shujutf" @click="charts">
  30. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/environment/10.png'" mode=""></image>
  31. <p>历史数据</p>
  32. </view>
  33. <view class="control_item" v-if="eqinfo.item.iccid" @click="siminfo(eqinfo.item.iccid)">
  34. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/cb/6.png'" mode=""></image>
  35. <p>SIM卡信息</p>
  36. </view>
  37. </view>
  38. <view class="realtime">
  39. <p class="realtime_title"><span>实时数据</span></p>
  40. <view class="realtime_text">
  41. <view class="realtime_text_item">
  42. <view class="realtime_text_item_info" v-for="(item,index) in olddata.conf" :key="index" v-if="olddata.dat[index][1]" @click="oneday(item,index)">
  43. <view class="item_info_img" :style="{'background-color':olddatas[Number(index.substr(1))%6]}">
  44. <image :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/environment/icon_'+olddata.dat[index][1]+'.png'"
  45. mode=""></image>
  46. </view>
  47. <view class="item_info_text">
  48. <p>{{item}}</p>
  49. <p style="margin-top: 20rpx;">{{parseFloat(olddata.dat[index][0]) == -99.99 ?'N/A':parseFloat(olddata.dat[index])}}</p>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="realtime_tishi" v-if="!realtimeTF && !dataloadingtf">
  55. 暂无数据
  56. </view>
  57. <view class="realtime_tishi" v-if="dataloadingtf">
  58. <p class="dataloading">加载中</p>
  59. </view>
  60. </view>
  61. </view>
  62. <u-modal v-model="show" :title-style="{color: 'red'}" :mask-close-able="true" title="24小时数据">
  63. <p class="tishiTF" v-if="tishiTF">暂无24小时数据</p>
  64. <view class="slot-content" v-else>
  65. <canvas canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  66. @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)" disable-scroll=true :style="{'width':cWidth*pixelRatio+'px','height':cHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  67. <view class="maxdata">
  68. <view class="maxdata_box">
  69. <p class="dian"></p>
  70. <p>当天最大值:{{onedatasMax}}&nbsp&nbsp{{onedatasMaxtime|timeFormat()}}</p>
  71. </view>
  72. <view class="maxdata_box">
  73. <p class="dian diantwo"></p>
  74. <p>当天最小值:{{onedatasMin}}&nbsp&nbsp{{onedatasMintime|timeFormat()}}</p>
  75. </view>
  76. </view>
  77. </view>
  78. </u-modal>
  79. </view>
  80. </template>
  81. <script>
  82. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  83. var canvasColumnA = null;
  84. export default {
  85. data() {
  86. return {
  87. eqinfo: {},
  88. olddata: {},
  89. olddatas: ["#fba825", "#53d67c", "#008cf2", "#fb504d", "#d87ffc", "#4ec5f0"],
  90. city: "",
  91. kongtf: false,
  92. daydatatf: false,
  93. shujutf: false,
  94. onedatas: [],
  95. canvastishiTF: true,
  96. cWidth: '300',
  97. cHeight: '200',
  98. pixelRatio: 1,
  99. show: false,
  100. onedatasMax: 0,
  101. onedatasMin: 0,
  102. onedatasMaxtime:"",
  103. onedatasMintime:"",
  104. tishiTF:false,
  105. realtimeTF:false,//暂无数据提示
  106. dataloadingtf:true,//加载中提示
  107. }
  108. },
  109. methods: {
  110. clickLeft() {
  111. uni.navigateBack({
  112. delta: 1
  113. })
  114. },
  115. async history() { //设备列表
  116. const res = await this.$myRequest({
  117. url: '/api/api_gateway?method=weather.weather.qxz_status',
  118. data: {
  119. device_id: this.eqinfo.item.equip_id || this.eqinfo.item.device_id
  120. }
  121. })
  122. this.olddata = res
  123. var arr = []
  124. for (var key in this.olddata.conf) {
  125. if (this.olddata.conf[key].indexOf("#") != -1) {
  126. this.olddata.conf[key] = this.olddata.conf[key].replace("#", "(") + ")"
  127. }
  128. this.olddata.dat[key] = this.olddata.dat[key].split("#")
  129. arr.push(this.olddata.dat[key][0])
  130. }
  131. console.log(this.olddata.conf)
  132. console.log(arr)
  133. this.realtimeTF = arr.some(function(item){
  134. return item!=""
  135. })
  136. console.log(this.realtimeTF)
  137. },
  138. // weather.weather.qxz_data_chart 一天的数据
  139. async onehistory() { //设备列表
  140. var newtime = +new Date()/1000
  141. var oldtime = newtime-24*60*60
  142. this.dataloadingtf = true
  143. const res = await this.$myRequest({
  144. url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
  145. data: {
  146. device_id: this.eqinfo.item.equip_id || this.eqinfo.item.device_id,
  147. begin: parseInt(oldtime),
  148. end: parseInt(newtime)
  149. }
  150. })
  151. this.dataloadingtf =false
  152. this.onedatas = res.data
  153. console.log(this.onedatas)
  154. },
  155. control() { //设备控制
  156. uni.navigateTo({
  157. url: "./contros?id=" + this.eqinfo.item.d_id
  158. })
  159. },
  160. charts() { //历史数据
  161. uni.navigateTo({
  162. url: "./history?device_id=" + this.eqinfo.item.equip_id || this.eqinfo.item.device_id
  163. })
  164. },
  165. reverseGeocode(lat, lng) {
  166. uni.request({
  167. type: "GET",
  168. url: "https://restapi.amap.com/v3/geocode/regeo?output=JSON&location=" + lng + "," + lat +
  169. "&key=27273b81090f78759e4057f94474516f&radius=1000&extensions=all",
  170. dataType: "json",
  171. complete: ress => {
  172. console.log(ress)
  173. // this.city = ress.data.regeocode.formatted_address
  174. if(ress.data.regeocode.formatted_address.length==0){
  175. this.city="--"
  176. }else{
  177. this.city = ress.data.regeocode.formatted_address
  178. }
  179. }
  180. });
  181. },
  182. copy(item) {
  183. uni.setClipboardData({
  184. data: item.equip_id || item.device_id,
  185. success: function() {
  186. console.log('success');
  187. }
  188. });
  189. },
  190. repairs() {
  191. console.log(this.eqinfo.item)
  192. var device_id = this.eqinfo.item.equip_id || this.eqinfo.item.device_id
  193. uni.navigateTo({
  194. url: "../afterSale/addafter?device_id=" + device_id + "&device_type=" + 5
  195. })
  196. },
  197. oneday(item, index) {
  198. console.log(item, index)
  199. var obj = {
  200. name: item,
  201. data: [],
  202. }
  203. var xtitle = []
  204. var linearr = []
  205. var arr = []
  206. var timearr = []
  207. for (var i = 0; i < this.onedatas.length; i++) {
  208. if(Number(this.onedatas[i].dat[index].slice(0, this.onedatas[i].dat[index].indexOf("#")))!=-99.99){
  209. obj.data.unshift(Number(this.onedatas[i].dat[index].slice(0, this.onedatas[i].dat[index].indexOf("#"))))
  210. arr.unshift(Number(this.onedatas[i].dat[index].slice(0, this.onedatas[i].dat[index].indexOf("#"))))
  211. var times = new Date(this.onedatas[i].time * 1000)
  212. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  213. timearr.unshift(+new Date(times)/1000)
  214. }
  215. }
  216. arr.sort(function(a, b) {
  217. return a - b
  218. })
  219. this.onedatasMin = arr[0]
  220. this.onedatasMax = arr[arr.length - 1]
  221. for(var i = 0; i < obj.data.length; i++){
  222. if(this.onedatasMax==obj.data[i]){
  223. this.onedatasMaxtime = timearr[i]
  224. }
  225. if(this.onedatasMin==obj.data[i]){
  226. this.onedatasMintime = timearr[i]
  227. }
  228. }
  229. linearr.push(obj)
  230. if(obj.data.length==0){
  231. this.tishiTF = true
  232. }else{
  233. this.tishiTF = false
  234. }
  235. this.showColumn("canvasColumnA", xtitle, linearr)
  236. this.show = true
  237. },
  238. showColumn(id, xtitle, xinfo) {
  239. var _self = this
  240. canvasColumnA = new uCharts({
  241. canvasId: id,
  242. type: 'line',
  243. legend: {
  244. position: "top"
  245. },
  246. fontSize: 11,
  247. background: '#FFFFFF',
  248. pixelRatio: 1,
  249. animation: true,
  250. dataLabel: false,
  251. categories: xtitle,
  252. series: xinfo,
  253. enableScroll: true, //开启图表拖拽功能
  254. xAxis: {
  255. disableGrid: true,
  256. type: 'grid',
  257. gridType: 'dash',
  258. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  259. scrollShow: true, //新增是否显示滚动条,默认false
  260. // scrollAlign: 'left', //滚动条初始位置
  261. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  262. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  263. },
  264. yAxis: {
  265. format:(val)=>{return val.toFixed(2)}
  266. },
  267. width: _self.cWidth * 1,
  268. height: _self.cHeight * 1,
  269. extra: {
  270. line: {
  271. type: 'curve'
  272. },
  273. },
  274. });
  275. },
  276. touchLineA(e) {
  277. canvasColumnA.scrollStart(e);
  278. },
  279. moveLineA(e) {
  280. canvasColumnA.scroll(e);
  281. },
  282. touchEndLineA(e) {
  283. canvasColumnA.scrollEnd(e);
  284. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  285. canvasColumnA.showToolTip(e, {
  286. format: function(item, category) {
  287. return category + ' ' + item.name + ':' + item.data
  288. }
  289. });
  290. },
  291. siminfo(sim){
  292. uni.navigateTo({
  293. url: "./sim?simid="+sim
  294. })
  295. }
  296. },
  297. onLoad(option) {
  298. this.$forceUpdate()
  299. this.eqinfo.item = JSON.parse(option.shebei)
  300. console.log(JSON.parse(option.shebei))
  301. this.history()
  302. this.onehistory()
  303. if (this.eqinfo.item.lat == '' || this.eqinfo.item.lng == "") {
  304. console.log(1)
  305. } else {
  306. this.reverseGeocode(this.eqinfo.item.lat, this.eqinfo.item.lng)
  307. }
  308. uni.getStorage({
  309. key: "jurisdiction",
  310. success: (res) => {
  311. console.log(JSON.parse(res.data))
  312. let items = JSON.parse(res.data).filter((item) => {
  313. return item.purview_name == "环境监测系统"
  314. })
  315. let items2 = items[0].children.filter((item) => {
  316. return item.purview_name == "环境监测"
  317. })
  318. var arr = items2[0].children
  319. console.log(arr)
  320. for (var i = 0; i < arr.length; i++) {
  321. switch (arr[i].purview_name) {
  322. case "设备控制":
  323. this.kongtf = true
  324. break
  325. case "24小时数据":
  326. this.daydatatf = true
  327. break
  328. case "历史数据":
  329. this.shujutf = true
  330. break
  331. }
  332. }
  333. },
  334. })
  335. }
  336. }
  337. </script>
  338. <style lang="scss">
  339. .info {
  340. width: 100%;
  341. position: absolute;
  342. top: 44px;
  343. .info_item {
  344. width: 90%;
  345. margin: 0 auto;
  346. height: 250rpx;
  347. padding: 26rpx 50rpx;
  348. position: relative;
  349. box-sizing: border-box;
  350. .bgi {
  351. width: 100%;
  352. height: 250rpx;
  353. position: absolute;
  354. top: 0;
  355. left: 0;
  356. z-index: -1;
  357. }
  358. p {
  359. font-size: 24rpx;
  360. color: #FFFFFF;
  361. margin-bottom: 10rpx;
  362. .tishi {
  363. width: 30rpx;
  364. height: 30rpx;
  365. margin: 0rpx 0 0 20rpx;
  366. }
  367. }
  368. }
  369. }
  370. .control {
  371. width: 90%;
  372. position: absolute;
  373. top: 372rpx;
  374. left: 5%;
  375. display: flex;
  376. text-align: center;
  377. // padding: 0 30rpx;
  378. box-sizing: border-box;
  379. .control_item {
  380. width: 128rpx;
  381. height: 120rpx;
  382. width: 33%;
  383. image {
  384. width: 70rpx;
  385. height: 70rpx;
  386. }
  387. p {
  388. font-size: 24rpx;
  389. }
  390. }
  391. }
  392. .realtime {
  393. width: 100%;
  394. position: absolute;
  395. top: 500rpx;
  396. .realtime_title {
  397. font-weight: 700;
  398. width: 90%;
  399. margin: 0 auto;
  400. }
  401. .dataloading:after {
  402. overflow: hidden;
  403. display: inline-block;
  404. vertical-align: bottom;
  405. animation: ellipsis 2s infinite;
  406. content: "\2026";
  407. }
  408. @keyframes ellipsis {
  409. from {
  410. width: 2px;
  411. }
  412. to {
  413. width: 15px;
  414. }
  415. }
  416. .realtime_tishi {
  417. width: 90%;
  418. margin: 0 auto;
  419. text-align: center;
  420. font-size: 32rpx;
  421. padding-top: 40rpx;
  422. }
  423. .realtime_text {
  424. width: 90%;
  425. margin: 0 auto;
  426. .realtime_text_item {
  427. width: 100%;
  428. display: flex;
  429. justify-content: space-between;
  430. flex-wrap: wrap;
  431. margin-bottom: 50rpx;
  432. .realtime_text_item_info {
  433. width: 48%;
  434. box-shadow: 0 0 10rpx #bcb9ca;
  435. margin-top: 20rpx;
  436. display: flex;
  437. padding: 20rpx 0rpx 20rpx 20rpx;
  438. box-sizing: border-box;
  439. .item_info_img {
  440. width: 90rpx;
  441. text-align: center;
  442. margin-right: 28rpx;
  443. border-radius: 50%;
  444. height: 90rpx;
  445. image {
  446. width: 64rpx;
  447. height: 64rpx;
  448. margin-top: 15rpx
  449. }
  450. }
  451. .item_info_text {
  452. font-size: 24rpx;
  453. }
  454. }
  455. }
  456. }
  457. }
  458. .charts {
  459. // width: 650upx;
  460. // height: 400upx;
  461. background-color: #FFFFFF;
  462. }
  463. .tishiTF{
  464. text-align: center;
  465. margin-top: 20rpx;
  466. }
  467. .maxdata {
  468. font-size: 26rpx;
  469. .maxdata_box {
  470. display: flex;
  471. padding-left: 30rpx;
  472. box-sizing: border-box;
  473. }
  474. .dian {
  475. width: 20rpx;
  476. height: 20rpx;
  477. background-color: red;
  478. margin: 8rpx 10rpx 0 0;
  479. border-radius: 50%;
  480. }
  481. .diantwo {
  482. background-color: #16c60d;
  483. }
  484. }
  485. </style>