ucharts.vue 17 KB

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