equipment.vue 13 KB

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