equipment.vue 12 KB

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