equipment.vue 12 KB

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