equipment.vue 12 KB

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