ucharts.vue 17 KB

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