ucharts.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  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%;color: #FFFFFF;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="历史数据"></uni-nav-bar>
  7. </view>
  8. <view class="selecttimes" @click="tiemshow=!tiemshow">
  9. <view class="timesbox">
  10. <image
  11. :src="'http://www.hnyfwlw.com:8006/bigdata_app'+'/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'"
  12. mode=""></image>
  13. <p>{{timetab(oldtime)}}</p>
  14. <p class="or">~</p>
  15. <p>{{timetab(newtime)}}</p>
  16. <u-icon name="rili" custom-prefix="custom-icon" class="icon"></u-icon>
  17. </view>
  18. <u-calendar v-model="tiemshow" mode="range" @change="tiemchange"></u-calendar>
  19. </view>
  20. <view class="shuju_one">
  21. <view class="shuju_one_title">
  22. <view :class="titleidnex==index?'title_text_color':'tltle_text'" v-for="(item,index) in titletext"
  23. :key="index" @click="changeindex(index)">
  24. {{item}}
  25. </view>
  26. </view>
  27. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  28. 暂无数据
  29. </view>
  30. <view class="canvastishi" v-if="dataloadingtf">
  31. <p class="dataloading">加载中</p>
  32. </view>
  33. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  34. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)"
  35. disable-scroll=true
  36. :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>
  37. </view>
  38. <view class="shuju_two">
  39. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  40. 暂无数据
  41. </view>
  42. <view class="canvastishi" v-if="dataloadingtf">
  43. <p class="dataloading">加载中</p>
  44. </view>
  45. <canvas v-if="canvastishiTF" canvas-id="canvasColumnB" id="canvasColumnB" class="charts"
  46. @touchstart="touchLineBb($event)" @touchmove="moveLineBb($event)" @touchend="touchEndLineBb($event)"
  47. disable-scroll=true
  48. :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>
  49. </view>
  50. <view class="refresh" @click="refresh">
  51. 刷 新
  52. </view>
  53. <view class="condition">
  54. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  55. <table class="table">
  56. <tr class="tr">
  57. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  58. </tr>
  59. <tr class="tr" v-for="(items,indexs) in eqlistdata" :key="'b'+indexs" v-if="forbidden">
  60. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  61. <td class="td">{{items.d_h_t.ds==0?"关机":"开机"}}</td>
  62. <td class="td">{{items.d_h_t.ws==0?"待机":(items.d_h_t.ws==1?"工作":"充电")}}</td>
  63. <td class="td">{{items.d_h_t.rps==0?"正常":"保护"}}</td>
  64. <td class="td">{{items.d_h_t.tps==0?"正常":"保护"}}</td>
  65. <td class="td">{{items.d_h_t.dps==0?"正常":"保护"}}</td>
  66. <td class="td">{{items.d_h_t.tt}}</td>
  67. <td class="td">{{items.d_h_t.ct}}</td>
  68. <td class="td">{{items.d_h_t.at==""?"--":items.d_h_t.at}}</td>
  69. <td class="td">{{items.d_h_t.ah==""?"--":items.d_h_t.ah}}</td>
  70. <td class="td">{{items.d_h_t.cv}}</td>
  71. <td class="td">{{items.d_h_t.bv}}</td>
  72. </tr>
  73. <tr class="tr" v-if="!forbidden">
  74. <td class="td" v-for="item in 12">暂无数据</td>
  75. </tr>
  76. </table>
  77. </scroll-view>
  78. <view class="pagenumber">
  79. <button @click="prev">上一页</button>
  80. <view class="pagenumber_page">
  81. 第{{page}}页
  82. </view>
  83. <view class="pagenumber_page">
  84. 共 {{pagesum}} 页
  85. </view>
  86. <button @click="next" :disabled="!forbidden">下一页</button>
  87. </view>
  88. </view>
  89. </view>
  90. </view>
  91. </template>
  92. <style lang="scss">
  93. </style>
  94. <script>
  95. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  96. var canvaColumnA = null;
  97. var canvaColumnB = null;
  98. var presenttime = null
  99. // var oldpresenttime = presenttime - 24*60*60*1000
  100. export default {
  101. data() {
  102. return {
  103. thdata: ["上报时间", "设备开关", "工作状态", "雨控状态", "温控状态", "倾倒状态", "定时(h)", "电击次数", "温度(℃)", "湿度(%)", "充电电压(v)",
  104. "电池电压(v)",
  105. ],
  106. eqlistdata: [],
  107. cWidth: '400',
  108. cHeight: '400',
  109. pixelRatio: 1,
  110. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  111. titleidnex: 0,
  112. oldtime: '',
  113. newtime: '',
  114. page: 1,
  115. forbidden: false, //暂无数据
  116. times: {
  117. d_id: null,
  118. start_time: null,
  119. end_time: null,
  120. device_id: null
  121. },
  122. canvastishiTF: false, //折线图暂无数据提示
  123. dataloadingtf: true, //加载中提示
  124. pagesum: 1,
  125. tiemshow: false, //日历选择器
  126. }
  127. },
  128. // 页面加载执行的函数
  129. onLoad(option) {
  130. this.times.d_id = option.d_id
  131. this.times.imei = option.imei
  132. this.cWidth = uni.upx2px(650);
  133. this.cHeight = uni.upx2px(500);
  134. },
  135. onShow() {
  136. presenttime = +new Date();
  137. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  138. this.newtime = parseInt(presenttime / 1000)
  139. setTimeout(() => {
  140. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) /
  141. 1000))
  142. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) /
  143. 1000))
  144. }, 1000)
  145. },
  146. onPullDownRefresh() {
  147. console.log('refresh');
  148. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) /
  149. 1000))
  150. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) /
  151. 1000))
  152. setTimeout(function() {
  153. uni.stopPullDownRefresh();
  154. }, 1000);
  155. },
  156. methods: { //
  157. //forecast.worm_lamp.device_polyline_data
  158. // 获取数据,发请求
  159. async getServerData(newtime, oldtimes) { //设备折线图
  160. this.dataloadingtf = true
  161. const res = await this.$myRequest({
  162. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  163. data: {
  164. device_type_id: 2,
  165. d_id: this.times.d_id,
  166. end_time: newtime,
  167. start_time: oldtimes
  168. }
  169. })
  170. this.dataloadingtf = false
  171. if (res.length == 0) {
  172. this.canvastishiTF = false
  173. } else {
  174. this.canvastishiTF = true
  175. var xtitle = []
  176. var arr = []
  177. var arr1 = []
  178. var arr2 = []
  179. var arr3 = []
  180. var arr4 = []
  181. var arr5 = []
  182. for (var i = 0; i < res.length; i++) {
  183. var times = new Date(res[i].addtime * 1000)
  184. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" +
  185. times.getMinutes())
  186. arr1.unshift(res[i].temperature)
  187. arr2.unshift(res[i].humidity)
  188. arr3.unshift(Number(res[i].others.bv))
  189. arr4.unshift(Number(res[i].others.cv))
  190. arr5.unshift(res[i].others.ct)
  191. }
  192. arr.unshift(arr1, arr2, arr3, arr4)
  193. var obj = [{
  194. name: '温度',
  195. data: arr[0],
  196. color: '#F97000'
  197. }, {
  198. name: '湿度',
  199. data: arr[1],
  200. color: '#00E29D'
  201. }, {
  202. name: '电池电压',
  203. data: arr[2],
  204. color: '#FF3F3F'
  205. }, {
  206. name: '充电电压',
  207. data: arr[3],
  208. color: '#6CBBFF'
  209. }]
  210. var obj2 = [{
  211. name: '击虫次数',
  212. data: arr5,
  213. color: '#00E29D'
  214. }]
  215. // console.log(obj)
  216. this.showColumn("canvasColumnA", xtitle, obj)
  217. this.showColumnb("canvasColumnB", xtitle, obj2)
  218. }
  219. },
  220. changeindex(index) { //选择日期
  221. this.titleidnex = index
  222. var now = new Date();
  223. if (index == 0) {
  224. this.newtime = parseInt(+new Date(now) / 1000)
  225. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  226. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  227. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  228. } else if (index == 1) {
  229. this.newtime = parseInt(+new Date(now) / 1000)
  230. var oldtime = now.setMonth(now.getMonth() - 1) / 1000
  231. this.oldtime = parseInt(oldtime)
  232. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  233. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  234. } else if (index == 2) {
  235. this.newtime = parseInt(+new Date(now) / 1000)
  236. var oldtime = now.setMonth(now.getMonth() - 6) / 1000
  237. this.oldtime = parseInt(oldtime)
  238. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  239. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  240. } else if (index == 3) {
  241. this.newtime = parseInt(+new Date(now) / 1000)
  242. var oldtime = now.setFullYear(now.getFullYear() - 1) / 1000
  243. this.oldtime = parseInt(oldtime)
  244. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  245. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  246. }
  247. },
  248. async historydata(newtime, oldtimes) { //设备表格数据
  249. const res = await this.$myRequest({
  250. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  251. data: {
  252. device_type_id: 2,
  253. device_id: this.times.imei,
  254. page: this.page,
  255. page_size: 10,
  256. start_time: oldtimes,
  257. end_time: newtime
  258. }
  259. })
  260. console.log(res.data)
  261. this.pagesum = Math.ceil(res.counts / 10) || 1
  262. this.eqlistdata = res.data
  263. if (res.data.length == 0) {
  264. this.forbidden = false
  265. } else {
  266. this.forbidden = true
  267. }
  268. },
  269. prev() { //上一页
  270. if (this.page != 1) {
  271. this.page--
  272. this.historydata(this.newtime, this.oldtime)
  273. }
  274. },
  275. next() { //下一页
  276. if (this.page < this.pagesum) {
  277. this.page++
  278. this.historydata(this.newtime, this.oldtime)
  279. }
  280. },
  281. tiemchange(e) {
  282. console.log(e)
  283. this.oldtime = +new Date(e.startDate) / 1000
  284. this.newtime = +new Date(e.endDate) / 1000 + 16 * 60 * 60
  285. this.getServerData(this.newtime, this.oldtime)
  286. this.historydata(this.newtime, this.oldtime)
  287. },
  288. timetab(e) {
  289. e = new Date(e * 1000)
  290. var year = e.getFullYear()
  291. var month = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1
  292. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()
  293. var time = year + "/" + month + "/" + day
  294. return time
  295. },
  296. clickLeft() {
  297. uni.navigateBack({
  298. delta: 1
  299. })
  300. },
  301. showColumn(id, xtitle, xinfo) {
  302. var _self = this
  303. canvaColumnA = new uCharts({
  304. canvasId: id,
  305. type: 'line',
  306. legend: {
  307. position: "top"
  308. },
  309. fontSize: 11,
  310. background: '#FFFFFF',
  311. pixelRatio: 1,
  312. animation: true,
  313. dataLabel: false,
  314. categories: xtitle,
  315. series: xinfo,
  316. enableScroll: true, //开启图表拖拽功能
  317. xAxis: {
  318. disableGrid: true,
  319. type: 'grid',
  320. gridType: 'dash',
  321. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  322. scrollShow: true, //新增是否显示滚动条,默认false
  323. // scrollAlign: 'left', //滚动条初始位置
  324. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  325. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  326. },
  327. yAxis: {},
  328. width: _self.cWidth * 1,
  329. height: _self.cHeight * 1,
  330. extra: {
  331. line: {
  332. type: 'curve'
  333. }
  334. }
  335. });
  336. },
  337. showColumnb(id, xtitle, xinfo) {
  338. var _self = this
  339. canvaColumnB = new uCharts({
  340. canvasId: id,
  341. type: 'line',
  342. legend: {
  343. position: "top"
  344. },
  345. fontSize: 11,
  346. background: '#FFFFFF',
  347. pixelRatio: 1,
  348. animation: true,
  349. dataLabel: false,
  350. categories: xtitle,
  351. series: xinfo,
  352. enableScroll: true, //开启图表拖拽功能
  353. xAxis: {
  354. disableGrid: true,
  355. type: 'grid',
  356. gridType: 'dash',
  357. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  358. scrollShow: true, //新增是否显示滚动条,默认false
  359. // scrollAlign: 'left', //滚动条初始位置
  360. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  361. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  362. },
  363. yAxis: {},
  364. width: _self.cWidth * 1,
  365. height: _self.cHeight * 1,
  366. extra: {
  367. line: {
  368. type: 'curve'
  369. }
  370. }
  371. });
  372. },
  373. touchLineA(e) {
  374. console.log(e)
  375. canvaColumnA.scrollStart(e);
  376. },
  377. moveLineA(e) {
  378. canvaColumnA.scroll(e);
  379. },
  380. touchEndLineA(e) {
  381. canvaColumnA.scrollEnd(e);
  382. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  383. canvaColumnA.showToolTip(e, {
  384. format: function(item, category) {
  385. return category + ' ' + item.name + ':' + Number(item.data).toFixed(3)
  386. }
  387. });
  388. },
  389. touchLineBb(e) {
  390. console.log(e)
  391. canvaColumnB.scrollStart(e);
  392. },
  393. moveLineBb(e) {
  394. canvaColumnB.scroll(e);
  395. },
  396. touchEndLineBb(e) {
  397. canvaColumnB.scrollEnd(e);
  398. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  399. canvaColumnB.showToolTip(e, {
  400. format: function(item, category) {
  401. return category + ' ' + item.name + ':' + item.data
  402. }
  403. });
  404. },
  405. async newdata() {
  406. const res = await this.$myRequest({
  407. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  408. data: {
  409. device_type_id: 2,
  410. d_id: this.times.d_id,
  411. control_type: "data"
  412. }
  413. })
  414. if (res) {
  415. uni.showToast({
  416. title: '刷新成功',
  417. duration: 2000,
  418. icon: "none"
  419. });
  420. } else {
  421. uni.showToast({
  422. title: '刷新失败',
  423. duration: 2000,
  424. icon: "none"
  425. });
  426. }
  427. },
  428. refresh() { //获取当前时间的数据
  429. this.newdata()
  430. },
  431. }
  432. }
  433. </script>
  434. <style lang="scss">
  435. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  436. .shuju_one,
  437. .shuju_two {
  438. position: absolute;
  439. top: 190rpx;
  440. width: 90%;
  441. left: 5%;
  442. box-shadow: 0 0 10rpx #bcb9ca;
  443. padding-top: 20rpx;
  444. height: 550rpx;
  445. .canvastishi {
  446. font-size: 32rpx;
  447. position: absolute;
  448. top: 50%;
  449. left: 50%;
  450. margin-left: -64rpx;
  451. margin-top: -21rpx;
  452. .dataloading:after {
  453. overflow: hidden;
  454. display: inline-block;
  455. vertical-align: bottom;
  456. animation: ellipsis 2s infinite;
  457. content: "\2026";
  458. }
  459. @keyframes ellipsis {
  460. from {
  461. width: 2px;
  462. }
  463. to {
  464. width: 15px;
  465. }
  466. }
  467. }
  468. .shuju_one_title {
  469. width: 70%;
  470. margin: 0 auto;
  471. display: flex;
  472. .tltle_text {
  473. width: 25%;
  474. border: 2rpx solid #B2B2B2;
  475. color: #57c878;
  476. text-align: center;
  477. font-size: 24rpx;
  478. height: 50rpx;
  479. line-height: 50rpx;
  480. }
  481. .title_text_color {
  482. width: 25%;
  483. border: 2rpx solid #57c878;
  484. background-color: #57c878;
  485. color: #fff;
  486. text-align: center;
  487. font-size: 24rpx;
  488. height: 50rpx;
  489. line-height: 50rpx;
  490. }
  491. }
  492. .qiun-columns {
  493. .qiun-charts {
  494. width: 650upx;
  495. height: 400upx;
  496. background-color: #FFFFFF;
  497. }
  498. .charts {
  499. width: 650upx;
  500. height: 400upx;
  501. background-color: #FFFFFF;
  502. }
  503. }
  504. }
  505. .shuju_two {
  506. top: 790rpx;
  507. }
  508. .selecttimes {
  509. position: absolute;
  510. top: 54px;
  511. width: 90%;
  512. box-shadow: 0 0 10rpx #bcb9ca;
  513. left: 5%;
  514. padding: 10rpx 20rpx;
  515. box-sizing: border-box;
  516. .timesbox {
  517. display: flex;
  518. justify-content: space-around;
  519. image {
  520. width: 30rpx;
  521. height: 30rpx;
  522. margin-top: 6rpx;
  523. }
  524. .icon {
  525. color: #949494;
  526. text-align: right;
  527. margin-left: 30rpx;
  528. }
  529. }
  530. }
  531. .refresh {
  532. position: absolute;
  533. top: 1380rpx;
  534. left: 5%;
  535. width: 160rpx;
  536. height: 50rpx;
  537. background-color: #57c878;
  538. color: #FFFFFF;
  539. line-height: 50rpx;
  540. text-align: center;
  541. box-shadow: 0 0 10rpx #bcb9ca;
  542. }
  543. .condition {
  544. position: absolute;
  545. top: 1450rpx;
  546. display: flex;
  547. flex-wrap: wrap;
  548. width: 90%;
  549. left: 5%;
  550. box-shadow: 0 0 10rpx #bcb9ca;
  551. margin-bottom: 30rpx;
  552. .scroll-X {
  553. width: 95%;
  554. margin: 20rpx auto;
  555. .table {
  556. width: 1056px;
  557. }
  558. .tr {
  559. display: flex;
  560. overflow: hidden;
  561. .th,
  562. .td {
  563. display: inline-block;
  564. padding: 5rpx;
  565. width: 140rpx;
  566. text-align: center;
  567. height: 52rpx;
  568. line-height: 52rpx;
  569. // border: 2rpx solid #F1F1F1;
  570. }
  571. .th:first-child,
  572. .td:first-child {
  573. width: 300rpx;
  574. }
  575. .th:nth-last-child(1),
  576. .th:nth-last-child(2),
  577. .td:nth-last-child(1),
  578. .td:nth-last-child(2) {
  579. width: 200rpx;
  580. }
  581. }
  582. .tr:nth-child(2n-1) {
  583. background-color: #f5fff8;
  584. }
  585. .tr:first-child {
  586. background-color: #57c878;
  587. color: #fff;
  588. }
  589. }
  590. .pagenumber {
  591. display: flex;
  592. margin: 20rpx auto;
  593. button {
  594. width: 150rpx;
  595. height: 50rpx;
  596. line-height: 50rpx;
  597. font-size: 26rpx;
  598. text-align: center;
  599. background-color: #57c878;
  600. color: #FFFFFF;
  601. }
  602. .pagenumber_page {
  603. width: 150rpx;
  604. height: 50rpx;
  605. line-height: 50rpx;
  606. font-size: 26rpx;
  607. text-align: center;
  608. }
  609. }
  610. }
  611. /deep/.u-calendar__action {
  612. display: flex;
  613. justify-content: space-around;
  614. .u-calendar__action__text {
  615. line-height: 25px;
  616. }
  617. }
  618. </style>