ucharts.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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?"待机":"工作"}}</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.new_tem==""?"--":items.d_h_t.new_tem}}</td>
  69. <td class="td">{{items.d_h_t.new_hum==""?"--":items.d_h_t.new_hum}}</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. methods: { //
  147. //forecast.worm_lamp.device_polyline_data
  148. // 获取数据,发请求
  149. async getServerData(newtime, oldtimes) { //设备折线图
  150. this.dataloadingtf = true
  151. const res = await this.$myRequest({
  152. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  153. data: {
  154. device_type_id: 2,
  155. d_id: this.times.d_id,
  156. end_time: newtime,
  157. start_time: oldtimes
  158. }
  159. })
  160. this.dataloadingtf = false
  161. if (res.length == 0) {
  162. this.canvastishiTF = false
  163. } else {
  164. this.canvastishiTF = true
  165. var xtitle = []
  166. var arr = []
  167. var arr1 = []
  168. var arr2 = []
  169. var arr3 = []
  170. var arr4 = []
  171. var arr5 = []
  172. for (var i = 0; i < res.length; i++) {
  173. var times = new Date(res[i].addtime * 1000)
  174. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" +
  175. times.getMinutes())
  176. arr1.unshift(res[i].temperature)
  177. arr2.unshift(res[i].humidity)
  178. arr3.unshift(Number(res[i].others.bv))
  179. arr4.unshift(Number(res[i].others.cv))
  180. arr5.unshift(res[i].others.ct)
  181. }
  182. arr.unshift(arr1, arr2, arr3, arr4)
  183. var obj = [{
  184. name: '温度',
  185. data: arr[0],
  186. color: '#F97000'
  187. }, {
  188. name: '湿度',
  189. data: arr[1],
  190. color: '#00E29D'
  191. }, {
  192. name: '电池电压',
  193. data: arr[2],
  194. color: '#FF3F3F'
  195. }, {
  196. name: '充电电压',
  197. data: arr[3],
  198. color: '#6CBBFF'
  199. }]
  200. var obj2 = [{
  201. name: '击虫次数',
  202. data: arr5,
  203. color: '#00E29D'
  204. }]
  205. this.showColumn("canvasColumnA", xtitle, obj)
  206. this.showColumnb("canvasColumnB", xtitle, obj2)
  207. }
  208. },
  209. changeindex(index) { //选择日期
  210. this.titleidnex = index
  211. var now = new Date();
  212. if (index == 0) {
  213. this.newtime = parseInt(+new Date(now) / 1000)
  214. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  215. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  216. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  217. } else if (index == 1) {
  218. this.newtime = parseInt(+new Date(now) / 1000)
  219. var oldtime = now.setMonth(now.getMonth() - 1) / 1000
  220. this.oldtime = parseInt(oldtime)
  221. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  222. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  223. } else if (index == 2) {
  224. this.newtime = parseInt(+new Date(now) / 1000)
  225. var oldtime = now.setMonth(now.getMonth() - 6) / 1000
  226. this.oldtime = parseInt(oldtime)
  227. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  228. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  229. } else if (index == 3) {
  230. this.newtime = parseInt(+new Date(now) / 1000)
  231. var oldtime = now.setFullYear(now.getFullYear() - 1) / 1000
  232. this.oldtime = parseInt(oldtime)
  233. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  234. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  235. }
  236. },
  237. async historydata(newtime, oldtimes) { //设备表格数据
  238. const res = await this.$myRequest({
  239. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  240. data: {
  241. device_type_id: 2,
  242. device_id: this.times.imei,
  243. page: this.page,
  244. page_size: 10,
  245. start_time: oldtimes,
  246. end_time: newtime
  247. }
  248. })
  249. console.log(res.data)
  250. this.pagesum = Math.ceil(res.counts / 10) || 1
  251. this.eqlistdata = res.data
  252. if (res.data.length == 0) {
  253. this.forbidden = false
  254. } else {
  255. this.forbidden = true
  256. }
  257. },
  258. prev() { //上一页
  259. if (this.page != 1) {
  260. this.page--
  261. this.historydata(this.newtime, this.oldtime)
  262. }
  263. },
  264. next() { //下一页
  265. if (this.page < this.pagesum) {
  266. this.page++
  267. this.historydata(this.newtime, this.oldtime)
  268. }
  269. },
  270. tiemchange(e) {
  271. console.log(e)
  272. this.oldtime = +new Date(e.startDate) / 1000
  273. this.newtime = +new Date(e.endDate) / 1000 + 16 * 60 * 60
  274. this.getServerData(this.newtime, this.oldtime)
  275. this.historydata(this.newtime, this.oldtime)
  276. },
  277. timetab(e) {
  278. e = new Date(e * 1000)
  279. var year = e.getFullYear()
  280. var month = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1
  281. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()
  282. var time = year + "/" + month + "/" + day
  283. return time
  284. },
  285. clickLeft() {
  286. uni.navigateBack({
  287. delta: 1
  288. })
  289. },
  290. showColumn(id, xtitle, xinfo) {
  291. var _self = this
  292. canvaColumnA = new uCharts({
  293. canvasId: id,
  294. type: 'line',
  295. legend: {
  296. position: "top"
  297. },
  298. fontSize: 11,
  299. background: '#FFFFFF',
  300. pixelRatio: 1,
  301. animation: true,
  302. dataLabel: false,
  303. categories: xtitle,
  304. series: xinfo,
  305. enableScroll: true, //开启图表拖拽功能
  306. xAxis: {
  307. disableGrid: true,
  308. type: 'grid',
  309. gridType: 'dash',
  310. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  311. scrollShow: true, //新增是否显示滚动条,默认false
  312. // scrollAlign: 'left', //滚动条初始位置
  313. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  314. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  315. },
  316. yAxis: {},
  317. width: _self.cWidth * 1,
  318. height: _self.cHeight * 1,
  319. extra: {
  320. line: {
  321. type: 'curve'
  322. }
  323. }
  324. });
  325. },
  326. showColumnb(id, xtitle, xinfo) {
  327. var _self = this
  328. canvaColumnB = new uCharts({
  329. canvasId: id,
  330. type: 'line',
  331. legend: {
  332. position: "top"
  333. },
  334. fontSize: 11,
  335. background: '#FFFFFF',
  336. pixelRatio: 1,
  337. animation: true,
  338. dataLabel: false,
  339. categories: xtitle,
  340. series: xinfo,
  341. enableScroll: true, //开启图表拖拽功能
  342. xAxis: {
  343. disableGrid: true,
  344. type: 'grid',
  345. gridType: 'dash',
  346. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  347. scrollShow: true, //新增是否显示滚动条,默认false
  348. // scrollAlign: 'left', //滚动条初始位置
  349. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  350. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  351. },
  352. yAxis: {},
  353. width: _self.cWidth * 1,
  354. height: _self.cHeight * 1,
  355. extra: {
  356. line: {
  357. type: 'curve'
  358. }
  359. }
  360. });
  361. },
  362. touchLineA(e) {
  363. console.log(e)
  364. canvaColumnA.scrollStart(e);
  365. },
  366. moveLineA(e) {
  367. canvaColumnA.scroll(e);
  368. },
  369. touchEndLineA(e) {
  370. canvaColumnA.scrollEnd(e);
  371. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  372. canvaColumnA.showToolTip(e, {
  373. format: function(item, category) {
  374. return category + ' ' + item.name + ':' + Number(item.data).toFixed(3)
  375. }
  376. });
  377. },
  378. touchLineBb(e) {
  379. console.log(e)
  380. canvaColumnB.scrollStart(e);
  381. },
  382. moveLineBb(e) {
  383. canvaColumnB.scroll(e);
  384. },
  385. touchEndLineBb(e) {
  386. canvaColumnB.scrollEnd(e);
  387. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  388. canvaColumnB.showToolTip(e, {
  389. format: function(item, category) {
  390. return category + ' ' + item.name + ':' + item.data
  391. }
  392. });
  393. },
  394. async newdata() {
  395. const res = await this.$myRequest({
  396. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  397. data: {
  398. device_type_id: 2,
  399. d_id: this.times.d_id,
  400. control_type: "data"
  401. }
  402. })
  403. if (res) {
  404. uni.showToast({
  405. title: '刷新成功',
  406. duration: 2000,
  407. icon: "none"
  408. });
  409. uni.navigateBack({
  410. delta: 1
  411. })
  412. } else {
  413. uni.showToast({
  414. title: '刷新失败',
  415. duration: 2000,
  416. icon: "none"
  417. });
  418. }
  419. },
  420. refresh() { //获取当前时间的数据
  421. this.newdata()
  422. },
  423. }
  424. }
  425. </script>
  426. <style lang="scss">
  427. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  428. .shuju_one,
  429. .shuju_two {
  430. position: absolute;
  431. top: 190rpx;
  432. width: 90%;
  433. left: 5%;
  434. box-shadow: 0 0 10rpx #bcb9ca;
  435. padding-top: 20rpx;
  436. height: 550rpx;
  437. .canvastishi {
  438. font-size: 32rpx;
  439. position: absolute;
  440. top: 50%;
  441. left: 50%;
  442. margin-left: -64rpx;
  443. margin-top: -21rpx;
  444. .dataloading:after {
  445. overflow: hidden;
  446. display: inline-block;
  447. vertical-align: bottom;
  448. animation: ellipsis 2s infinite;
  449. content: "\2026";
  450. }
  451. @keyframes ellipsis {
  452. from {
  453. width: 2px;
  454. }
  455. to {
  456. width: 15px;
  457. }
  458. }
  459. }
  460. .shuju_one_title {
  461. width: 70%;
  462. margin: 0 auto;
  463. display: flex;
  464. .tltle_text {
  465. width: 25%;
  466. border: 2rpx solid #B2B2B2;
  467. color: #57c878;
  468. text-align: center;
  469. font-size: 24rpx;
  470. height: 50rpx;
  471. line-height: 50rpx;
  472. }
  473. .title_text_color {
  474. width: 25%;
  475. border: 2rpx solid #57c878;
  476. background-color: #57c878;
  477. color: #fff;
  478. text-align: center;
  479. font-size: 24rpx;
  480. height: 50rpx;
  481. line-height: 50rpx;
  482. }
  483. }
  484. .qiun-columns {
  485. .qiun-charts {
  486. width: 650upx;
  487. height: 400upx;
  488. background-color: #FFFFFF;
  489. }
  490. .charts {
  491. width: 650upx;
  492. height: 400upx;
  493. background-color: #FFFFFF;
  494. }
  495. }
  496. }
  497. .shuju_two {
  498. top: 790rpx;
  499. }
  500. .selecttimes {
  501. position: absolute;
  502. top: 54px;
  503. width: 90%;
  504. box-shadow: 0 0 10rpx #bcb9ca;
  505. left: 5%;
  506. padding: 10rpx 20rpx;
  507. box-sizing: border-box;
  508. .timesbox {
  509. display: flex;
  510. justify-content: space-around;
  511. image {
  512. width: 30rpx;
  513. height: 30rpx;
  514. margin-top: 6rpx;
  515. }
  516. .icon {
  517. color: #949494;
  518. text-align: right;
  519. margin-left: 30rpx;
  520. }
  521. }
  522. }
  523. .refresh {
  524. position: absolute;
  525. top: 1380rpx;
  526. left: 5%;
  527. width: 160rpx;
  528. height: 50rpx;
  529. background-color: #57c878;
  530. color: #FFFFFF;
  531. line-height: 50rpx;
  532. text-align: center;
  533. box-shadow: 0 0 10rpx #bcb9ca;
  534. }
  535. .condition {
  536. position: absolute;
  537. top: 1450rpx;
  538. display: flex;
  539. flex-wrap: wrap;
  540. width: 90%;
  541. left: 5%;
  542. box-shadow: 0 0 10rpx #bcb9ca;
  543. margin-bottom: 30rpx;
  544. .scroll-X {
  545. width: 95%;
  546. margin: 20rpx auto;
  547. .table {
  548. width: 1056px;
  549. }
  550. .tr {
  551. display: flex;
  552. overflow: hidden;
  553. .th,
  554. .td {
  555. display: inline-block;
  556. padding: 5rpx;
  557. width: 140rpx;
  558. text-align: center;
  559. height: 52rpx;
  560. line-height: 52rpx;
  561. // border: 2rpx solid #F1F1F1;
  562. }
  563. .th:first-child,
  564. .td:first-child {
  565. width: 300rpx;
  566. }
  567. .th:nth-last-child(1),
  568. .th:nth-last-child(2),
  569. .td:nth-last-child(1),
  570. .td:nth-last-child(2) {
  571. width: 200rpx;
  572. }
  573. }
  574. .tr:nth-child(2n-1) {
  575. background-color: #f5fff8;
  576. }
  577. .tr:first-child {
  578. background-color: #57c878;
  579. color: #fff;
  580. }
  581. }
  582. .pagenumber {
  583. display: flex;
  584. margin: 20rpx auto;
  585. button {
  586. width: 150rpx;
  587. height: 50rpx;
  588. line-height: 50rpx;
  589. font-size: 26rpx;
  590. text-align: center;
  591. background-color: #57c878;
  592. color: #FFFFFF;
  593. }
  594. .pagenumber_page {
  595. width: 150rpx;
  596. height: 50rpx;
  597. line-height: 50rpx;
  598. font-size: 26rpx;
  599. text-align: center;
  600. }
  601. }
  602. }
  603. /deep/.u-calendar__action {
  604. display: flex;
  605. justify-content: space-around;
  606. .u-calendar__action__text {
  607. line-height: 25px;
  608. }
  609. }
  610. </style>