equipment.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 64px;">
  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://static.yfpyx.com/bigdata_app/image/cb/onBg.png':'http://static.yfpyx.com/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://static.yfpyx.com/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://static.yfpyx.com/bigdata_app'+'/image/environment/8.png'" mode=""></image>
  23. <p>设备控制</p>
  24. </view>
  25. <view class="control_item" @click="repairs">
  26. <image :src="'http://static.yfpyx.com/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://static.yfpyx.com/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="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://static.yfpyx.com/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
  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. }
  162. });
  163. },
  164. copy(item) {
  165. uni.setClipboardData({
  166. data: item.equip_id || item.device_id,
  167. success: function() {
  168. console.log('success');
  169. }
  170. });
  171. },
  172. repairs() {
  173. console.log(this.eqinfo.item)
  174. var device_id = this.eqinfo.item.equip_id || this.eqinfo.item.device_id
  175. uni.navigateTo({
  176. url: "../afterSale/addafter?device_id=" + device_id + "&device_type=" + 5
  177. })
  178. },
  179. oneday(item, index) {
  180. console.log(item, index)
  181. var obj = {
  182. name: item,
  183. data: [],
  184. }
  185. var xtitle = []
  186. var linearr = []
  187. var arr = []
  188. var timearr = []
  189. for (var i = 0; i < this.onedatas.length; i++) {
  190. if(Number(this.onedatas[i].dat[index].slice(0, this.onedatas[i].dat[index].indexOf("#")))!=-99.99){
  191. obj.data.unshift(Number(this.onedatas[i].dat[index].slice(0, this.onedatas[i].dat[index].indexOf("#"))))
  192. arr.unshift(Number(this.onedatas[i].dat[index].slice(0, this.onedatas[i].dat[index].indexOf("#"))))
  193. var times = new Date(this.onedatas[i].time * 1000)
  194. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getMinutes())
  195. timearr.unshift(+new Date(times)/1000)
  196. }
  197. }
  198. arr.sort(function(a, b) {
  199. return a - b
  200. })
  201. this.onedatasMin = arr[0]
  202. this.onedatasMax = arr[arr.length - 1]
  203. for(var i = 0; i < obj.data.length; i++){
  204. if(this.onedatasMax==obj.data[i]){
  205. this.onedatasMaxtime = timearr[i]
  206. }
  207. if(this.onedatasMin==obj.data[i]){
  208. this.onedatasMintime = timearr[i]
  209. }
  210. }
  211. linearr.push(obj)
  212. if(obj.data.length==0){
  213. this.tishiTF = true
  214. }else{
  215. this.tishiTF = false
  216. }
  217. this.show = true
  218. this.showColumn("canvasColumnA", xtitle, linearr)
  219. },
  220. showColumn(id, xtitle, xinfo) {
  221. var _self = this
  222. canvasColumnA = new uCharts({
  223. canvasId: id,
  224. type: 'line',
  225. legend: {
  226. position: "top"
  227. },
  228. fontSize: 11,
  229. background: '#FFFFFF',
  230. pixelRatio: 1,
  231. animation: true,
  232. dataLabel: false,
  233. categories: xtitle,
  234. series: xinfo,
  235. enableScroll: true, //开启图表拖拽功能
  236. xAxis: {
  237. disableGrid: true,
  238. type: 'grid',
  239. gridType: 'dash',
  240. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  241. scrollShow: true, //新增是否显示滚动条,默认false
  242. // scrollAlign: 'left', //滚动条初始位置
  243. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  244. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  245. },
  246. yAxis: {
  247. format:(val)=>{return val.toFixed(2)}
  248. },
  249. width: _self.cWidth * 1,
  250. height: _self.cHeight * 1,
  251. extra: {
  252. line: {
  253. type: 'curve'
  254. },
  255. },
  256. });
  257. },
  258. touchLineA(e) {
  259. canvasColumnA.scrollStart(e);
  260. },
  261. moveLineA(e) {
  262. canvasColumnA.scroll(e);
  263. },
  264. touchEndLineA(e) {
  265. canvasColumnA.scrollEnd(e);
  266. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  267. canvasColumnA.showToolTip(e, {
  268. format: function(item, category) {
  269. return category + ' ' + item.name + ':' + item.data
  270. }
  271. });
  272. },
  273. },
  274. onLoad(option) {
  275. this.$forceUpdate()
  276. this.eqinfo.item = JSON.parse(option.shebei)
  277. console.log(JSON.parse(option.shebei))
  278. this.history()
  279. this.onehistory()
  280. if (this.eqinfo.item.lat == '' || this.eqinfo.item.lng == "") {
  281. console.log(1)
  282. } else {
  283. this.reverseGeocode(this.eqinfo.item.lat, this.eqinfo.item.lng)
  284. }
  285. uni.getStorage({
  286. key: "jurisdiction",
  287. success: (res) => {
  288. console.log(JSON.parse(res.data))
  289. let items = JSON.parse(res.data).filter((item) => {
  290. return item.purview_name == "环境监测系统"
  291. })
  292. let items2 = items[0].children.filter((item) => {
  293. return item.purview_name == "环境监测"
  294. })
  295. var arr = items2[0].children
  296. console.log(arr)
  297. for (var i = 0; i < arr.length; i++) {
  298. switch (arr[i].purview_name) {
  299. case "设备控制":
  300. this.kongtf = true
  301. break
  302. case "24小时数据":
  303. this.daydatatf = true
  304. break
  305. case "历史数据":
  306. this.shujutf = true
  307. break
  308. }
  309. }
  310. },
  311. })
  312. }
  313. }
  314. </script>
  315. <style lang="scss">
  316. .info {
  317. width: 100%;
  318. position: absolute;
  319. top: 44px;
  320. .info_item {
  321. width: 90%;
  322. margin: 0 auto;
  323. height: 250rpx;
  324. padding: 26rpx 50rpx;
  325. position: relative;
  326. box-sizing: border-box;
  327. .bgi {
  328. width: 100%;
  329. height: 250rpx;
  330. position: absolute;
  331. top: 0;
  332. left: 0;
  333. z-index: -1;
  334. }
  335. p {
  336. font-size: 24rpx;
  337. color: #FFFFFF;
  338. margin-bottom: 10rpx;
  339. .tishi {
  340. width: 30rpx;
  341. height: 30rpx;
  342. margin: 0rpx 0 0 20rpx;
  343. }
  344. }
  345. }
  346. }
  347. .control {
  348. width: 90%;
  349. position: absolute;
  350. top: 372rpx;
  351. left: 5%;
  352. display: flex;
  353. text-align: center;
  354. // padding: 0 30rpx;
  355. box-sizing: border-box;
  356. .control_item {
  357. width: 128rpx;
  358. height: 120rpx;
  359. width: 33%;
  360. image {
  361. width: 70rpx;
  362. height: 70rpx;
  363. }
  364. p {
  365. font-size: 24rpx;
  366. }
  367. }
  368. }
  369. .realtime {
  370. width: 100%;
  371. position: absolute;
  372. top: 500rpx;
  373. .realtime_title {
  374. font-weight: 700;
  375. width: 90%;
  376. margin: 0 auto;
  377. }
  378. .realtime_text {
  379. width: 90%;
  380. margin: 0 auto;
  381. .realtime_text_item {
  382. width: 100%;
  383. display: flex;
  384. justify-content: space-between;
  385. flex-wrap: wrap;
  386. margin-bottom: 50rpx;
  387. .realtime_text_item_info {
  388. width: 48%;
  389. box-shadow: 0 0 10rpx #bcb9ca;
  390. margin-top: 20rpx;
  391. display: flex;
  392. padding: 20rpx 0rpx 20rpx 20rpx;
  393. box-sizing: border-box;
  394. .item_info_img {
  395. width: 90rpx;
  396. text-align: center;
  397. margin-right: 28rpx;
  398. border-radius: 50%;
  399. height: 90rpx;
  400. image {
  401. width: 64rpx;
  402. height: 64rpx;
  403. margin-top: 15rpx
  404. }
  405. }
  406. .item_info_text {
  407. font-size: 24rpx;
  408. }
  409. }
  410. }
  411. }
  412. }
  413. .charts {
  414. // width: 650upx;
  415. // height: 400upx;
  416. background-color: #FFFFFF;
  417. }
  418. .tishiTF{
  419. text-align: center;
  420. margin-top: 20rpx;
  421. }
  422. .maxdata {
  423. font-size: 26rpx;
  424. .maxdata_box {
  425. display: flex;
  426. padding-left: 30rpx;
  427. box-sizing: border-box;
  428. }
  429. .dian {
  430. width: 20rpx;
  431. height: 20rpx;
  432. background-color: red;
  433. margin: 8rpx 10rpx 0 0;
  434. border-radius: 50%;
  435. }
  436. .diantwo {
  437. background-color: #16c60d;
  438. }
  439. }
  440. </style>