ucharts.vue 16 KB

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