ucharts.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  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.lamp==0?"灭":"亮"}}</td>
  66. <td class="td">{{items.d_h_t.rps==0?"正常":"保护"}}</td>
  67. <td class="td">{{items.d_h_t.tps==0?"正常":"保护"}}</td>
  68. <td class="td">{{items.d_h_t.dps==0?"正常":"保护"}}</td>
  69. <td class="td">{{items.d_h_t.tt}}</td>
  70. <td class="td">{{items.d_h_t.ct}}</td>
  71. <td class="td">{{items.d_h_t.at}}</td>
  72. <td class="td">{{items.d_h_t.ah}}</td>
  73. <td class="td">{{items.d_h_t.cv/1000}}</td>
  74. <td class="td">{{items.d_h_t.bv/1000}}</td>
  75. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  76. </tr>
  77. <tr class="tr" v-if="!forbidden">
  78. <td class="td" v-for="item in 13">暂无数据</td>
  79. </tr>
  80. </table>
  81. </scroll-view>
  82. <view class="pagenumber">
  83. <button @click="prev">上一页</button>
  84. <view class="pagenumber_page">
  85. 第{{page}}页
  86. </view>
  87. <button @click="next" :disabled="!forbidden">下一页</button>
  88. </view>
  89. </view>
  90. </view>
  91. </view>
  92. </template>
  93. <style lang="scss">
  94. </style>
  95. <script>
  96. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  97. var canvaColumnA = null;
  98. var canvaColumnB = null;
  99. var presenttime = +new Date();
  100. // var oldpresenttime = presenttime - 24*60*60*1000
  101. export default {
  102. data() {
  103. return {
  104. thdata: ["设备开关", "工作状态", "灯管状态", "雨控状态", "温控状态", "倾倒状态", "定时(h)", "电击次数", "温度(℃)", "湿度(%)", "充电电压(v)", "电池电压(v)",
  105. "上报时间"
  106. ],
  107. eqlistdata: [],
  108. cWidth: '400',
  109. cHeight: '400',
  110. pixelRatio: 1,
  111. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  112. titleidnex: 0,
  113. oldtime: '',
  114. newtime: '',
  115. page: 1,
  116. forbidden: false, //暂无数据
  117. params: {
  118. year: true,
  119. month: true,
  120. day: true,
  121. hour: true,
  122. minute: true,
  123. second: false
  124. },
  125. pickshow: false,
  126. picktwoshow: false,
  127. tishiTF: false,
  128. times: {
  129. d_id: null,
  130. start_time: null,
  131. end_time: null,
  132. device_id: null
  133. },
  134. canvastishiTF:false
  135. }
  136. },
  137. // 页面加载执行的函数
  138. onLoad(option) {
  139. console.log(option)
  140. this.times.d_id = option.d_id
  141. this.times.imei = option.imei
  142. this.cWidth = uni.upx2px(650);
  143. this.cHeight = uni.upx2px(500);
  144. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  145. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  146. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  147. this.newtime = parseInt(presenttime / 1000)
  148. },
  149. methods: { //
  150. //forecast.worm_lamp.device_polyline_data
  151. // 获取数据,发请求
  152. async getServerData(newtime, oldtimes) { //设备列表
  153. const res = await this.$myRequest({
  154. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  155. data: {
  156. device_type_id: 2,
  157. d_id: this.times.d_id,
  158. end_time: newtime,
  159. start_time: oldtimes
  160. }
  161. })
  162. if(res.length == 0){
  163. this.canvastishiTF = false
  164. }else{
  165. this.canvastishiTF = true
  166. var xtitle = []
  167. var arr = []
  168. var arr1 = []
  169. var arr2 = []
  170. var arr3 = []
  171. var arr4 = []
  172. var arr5 = []
  173. for (var i = 0; i < res.length; i++) {
  174. var times = new Date(res[i].addtime * 1000)
  175. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getSeconds())
  176. arr1.unshift(res[i].temperature)
  177. arr2.unshift(res[i].humidity)
  178. arr3.unshift(Number(res[i].others.bv)/1000)
  179. arr4.unshift(Number(res[i].others.cv)/1000)
  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. if (this.newtime < this.oldtime) {
  237. this.tishiTF = true
  238. } else {
  239. this.tishiTF = false
  240. }
  241. },
  242. async historydata(newtime, oldtimes) { //设备列表
  243. const res = await this.$myRequest({
  244. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  245. data: {
  246. device_type_id: 2,
  247. device_id: this.times.imei,
  248. page: this.page,
  249. page_size: 10,
  250. start_time: oldtimes,
  251. end_time: newtime
  252. }
  253. })
  254. console.log(res.data)
  255. this.eqlistdata = res.data
  256. if (res.data.length == 0) {
  257. this.forbidden = false
  258. } else {
  259. this.forbidden = true
  260. }
  261. },
  262. prev() { //上一页
  263. if (this.page != 1) {
  264. this.page--
  265. }
  266. this.historydata(this.newtime, this.oldtime)
  267. },
  268. next() { //下一页
  269. this.page++
  270. this.historydata(this.newtime, this.oldtime)
  271. },
  272. pickone(e) {
  273. this.oldtime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  274. if (this.newtime < this.oldtime) {
  275. this.tishiTF = true
  276. } else {
  277. this.tishiTF = false
  278. }
  279. },
  280. picktwo(e) {
  281. this.newtime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  282. if (this.newtime < this.oldtime) {
  283. this.tishiTF = true
  284. } else {
  285. this.tishiTF = false
  286. }
  287. },
  288. serter() {
  289. if (this.tishiTF == false) {
  290. this.getServerData(parseInt(presenttime / 1000), parseInt(this.oldtime))
  291. this.historydata(this.newtime, this.oldtime)
  292. }
  293. },
  294. clickLeft() {
  295. uni.navigateBack({
  296. delta: 1
  297. })
  298. },
  299. showColumn(id,xtitle,xinfo) {
  300. var _self = this
  301. canvaColumnA = new uCharts({
  302. canvasId: id,
  303. type: 'line',
  304. legend: {
  305. position:"top"
  306. },
  307. fontSize: 11,
  308. background: '#FFFFFF',
  309. pixelRatio: 1,
  310. animation: true,
  311. dataLabel: false,
  312. categories:xtitle,
  313. series: xinfo,
  314. enableScroll: true, //开启图表拖拽功能
  315. xAxis: {
  316. disableGrid: true,
  317. type: 'grid',
  318. gridType: 'dash',
  319. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  320. scrollShow: true, //新增是否显示滚动条,默认false
  321. // scrollAlign: 'left', //滚动条初始位置
  322. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  323. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  324. },
  325. yAxis: {},
  326. width: _self.cWidth * 1,
  327. height: _self.cHeight * 1,
  328. extra: {
  329. line: {
  330. type: 'curve'
  331. }
  332. }
  333. });
  334. },
  335. showColumnb(id,xtitle,xinfo) {
  336. var _self = this
  337. canvaColumnB = new uCharts({
  338. canvasId: id,
  339. type: 'line',
  340. legend: {
  341. position:"top"
  342. },
  343. fontSize: 11,
  344. background: '#FFFFFF',
  345. pixelRatio: 1,
  346. animation: true,
  347. dataLabel: false,
  348. categories: xtitle,
  349. series: xinfo,
  350. enableScroll: true, //开启图表拖拽功能
  351. xAxis: {
  352. disableGrid: true,
  353. type: 'grid',
  354. gridType: 'dash',
  355. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  356. scrollShow: true, //新增是否显示滚动条,默认false
  357. // scrollAlign: 'left', //滚动条初始位置
  358. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  359. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  360. },
  361. yAxis: {},
  362. width: _self.cWidth * 1,
  363. height: _self.cHeight * 1,
  364. extra: {
  365. line: {
  366. type: 'curve'
  367. }
  368. }
  369. });
  370. },
  371. touchLineA(e) {
  372. console.log(e)
  373. canvaColumnA.scrollStart(e);
  374. },
  375. moveLineA(e) {
  376. canvaColumnA.scroll(e);
  377. },
  378. touchEndLineA(e) {
  379. canvaColumnA.scrollEnd(e);
  380. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  381. canvaColumnA.showToolTip(e, {
  382. format: function(item, category) {
  383. return category + ' ' + item.name + ':' + item.data
  384. }
  385. });
  386. },
  387. touchLineBb(e) {
  388. console.log(e)
  389. canvaColumnB.scrollStart(e);
  390. },
  391. moveLineBb(e) {
  392. canvaColumnB.scroll(e);
  393. },
  394. touchEndLineBb(e) {
  395. canvaColumnB.scrollEnd(e);
  396. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  397. canvaColumnB.showToolTip(e, {
  398. format: function(item, category) {
  399. return category + ' ' + item.name + ':' + item.data
  400. }
  401. });
  402. },
  403. }
  404. }
  405. </script>
  406. <style lang="scss">
  407. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  408. .shuju_one,
  409. .shuju_two {
  410. position: absolute;
  411. top: 54px;
  412. width: 90%;
  413. left: 5%;
  414. box-shadow: 0 0 10rpx #bcb9ca;
  415. padding-top: 20rpx;
  416. height: 550rpx;
  417. .canvastishi{
  418. font-size: 32rpx;
  419. position: absolute;
  420. top: 50%;
  421. left: 50%;
  422. margin-left: -64rpx;
  423. margin-top: -21rpx;
  424. }
  425. .shuju_one_title {
  426. width: 70%;
  427. margin: 0 auto;
  428. display: flex;
  429. .tltle_text {
  430. width: 25%;
  431. border: 2rpx solid #B2B2B2;
  432. color: #B2B2B2;
  433. text-align: center;
  434. font-size: 24rpx;
  435. height: 50rpx;
  436. line-height: 50rpx;
  437. }
  438. .title_text_color {
  439. width: 25%;
  440. border: 2rpx solid #28AE4F;
  441. color: #28AE4F;
  442. text-align: center;
  443. font-size: 24rpx;
  444. height: 50rpx;
  445. line-height: 50rpx;
  446. }
  447. }
  448. .qiun-columns {
  449. .qiun-charts {
  450. width: 650upx;
  451. height: 400upx;
  452. background-color: #FFFFFF;
  453. }
  454. .charts {
  455. width: 650upx;
  456. height: 400upx;
  457. background-color: #FFFFFF;
  458. }
  459. }
  460. }
  461. .shuju_two {
  462. top: 700rpx;
  463. }
  464. .selecttimes {
  465. position: absolute;
  466. top: 1290rpx;
  467. width: 90%;
  468. box-shadow: 0 0 10rpx #bcb9ca;
  469. left: 5%;
  470. .tishi {
  471. width: 90%;
  472. margin: 0 auto;
  473. color: #f00000;
  474. text-align: center;
  475. font-size: 24rpx;
  476. }
  477. .btnser {
  478. width: 90%;
  479. margin: 10rpx auto;
  480. color: #FFFFFF;
  481. text-align: center;
  482. font-size: 28rpx;
  483. background-color: #58BD4D;
  484. border-radius: 20rpx;
  485. height: 50rpx;
  486. line-height: 50rpx;
  487. }
  488. .newtimes {
  489. width: 100%;
  490. padding: 20rpx 20rpx;
  491. box-sizing: border-box;
  492. .newtimes_state,
  493. .newtimes_end {
  494. display: flex;
  495. justify-content: space-between;
  496. margin-bottom: 20rpx;
  497. .oldtimes_left {
  498. position: relative;
  499. padding-left: 36rpx;
  500. font-size: 28rpx;
  501. image {
  502. width: 30rpx;
  503. height: 30rpx;
  504. vertical-align: top;
  505. position: absolute;
  506. top: 7rpx;
  507. left: 0;
  508. }
  509. }
  510. }
  511. }
  512. }
  513. .condition {
  514. position: absolute;
  515. top: 1530rpx;
  516. display: flex;
  517. flex-wrap: wrap;
  518. width: 90%;
  519. left: 5%;
  520. box-shadow: 0 0 10rpx #bcb9ca;
  521. margin-bottom: 30rpx;
  522. .scroll-X {
  523. width: 95%;
  524. margin: 20rpx auto;
  525. .tr {
  526. display: flex;
  527. overflow: hidden;
  528. .th,
  529. .td {
  530. display: inline-block;
  531. padding: 5rpx;
  532. width: 140rpx;
  533. text-align: center;
  534. height: 52rpx;
  535. line-height: 52rpx;
  536. border: 2rpx solid #F1F1F1;
  537. }
  538. .th:last-child,
  539. .td:last-child {
  540. width: 300rpx;
  541. }
  542. .th:nth-last-child(2),
  543. .th:nth-last-child(3),
  544. .td:nth-last-child(2),
  545. .td:nth-last-child(3) {
  546. width: 200rpx;
  547. }
  548. }
  549. }
  550. .pagenumber {
  551. display: flex;
  552. margin: 20rpx auto;
  553. button {
  554. width: 150rpx;
  555. height: 50rpx;
  556. line-height: 50rpx;
  557. font-size: 26rpx;
  558. text-align: center;
  559. background-color: #17BB89;
  560. color: #FFFFFF;
  561. }
  562. .pagenumber_page {
  563. width: 150rpx;
  564. height: 50rpx;
  565. line-height: 50rpx;
  566. font-size: 26rpx;
  567. text-align: center;
  568. }
  569. }
  570. }
  571. </style>