ucharts.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 64px;">
  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="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="'http://static.yfpyx.com/bigdata_app'+'/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="'http://static.yfpyx.com/bigdata_app'+'/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. uni.showToast({
  303. title: '搜索成功',
  304. duration: 2000
  305. });
  306. }
  307. },
  308. clickLeft() {
  309. uni.navigateBack({
  310. delta: 1
  311. })
  312. },
  313. showColumn(id,xtitle,xinfo) {
  314. var _self = this
  315. canvaColumnA = new uCharts({
  316. canvasId: id,
  317. type: 'line',
  318. legend: {
  319. position:"top"
  320. },
  321. fontSize: 11,
  322. background: '#FFFFFF',
  323. pixelRatio: 1,
  324. animation: true,
  325. dataLabel: false,
  326. categories:xtitle,
  327. series: xinfo,
  328. enableScroll: true, //开启图表拖拽功能
  329. xAxis: {
  330. disableGrid: true,
  331. type: 'grid',
  332. gridType: 'dash',
  333. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  334. scrollShow: true, //新增是否显示滚动条,默认false
  335. // scrollAlign: 'left', //滚动条初始位置
  336. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  337. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  338. },
  339. yAxis: {},
  340. width: _self.cWidth * 1,
  341. height: _self.cHeight * 1,
  342. extra: {
  343. line: {
  344. type: 'curve'
  345. }
  346. }
  347. });
  348. },
  349. showColumnb(id,xtitle,xinfo) {
  350. var _self = this
  351. canvaColumnB = new uCharts({
  352. canvasId: id,
  353. type: 'line',
  354. legend: {
  355. position:"top"
  356. },
  357. fontSize: 11,
  358. background: '#FFFFFF',
  359. pixelRatio: 1,
  360. animation: true,
  361. dataLabel: false,
  362. categories: xtitle,
  363. series: xinfo,
  364. enableScroll: true, //开启图表拖拽功能
  365. xAxis: {
  366. disableGrid: true,
  367. type: 'grid',
  368. gridType: 'dash',
  369. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  370. scrollShow: true, //新增是否显示滚动条,默认false
  371. // scrollAlign: 'left', //滚动条初始位置
  372. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  373. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  374. },
  375. yAxis: {},
  376. width: _self.cWidth * 1,
  377. height: _self.cHeight * 1,
  378. extra: {
  379. line: {
  380. type: 'curve'
  381. }
  382. }
  383. });
  384. },
  385. touchLineA(e) {
  386. console.log(e)
  387. canvaColumnA.scrollStart(e);
  388. },
  389. moveLineA(e) {
  390. canvaColumnA.scroll(e);
  391. },
  392. touchEndLineA(e) {
  393. canvaColumnA.scrollEnd(e);
  394. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  395. canvaColumnA.showToolTip(e, {
  396. format: function(item, category) {
  397. return category + ' ' + item.name + ':' + Number(item.data).toFixed(3)
  398. }
  399. });
  400. },
  401. touchLineBb(e) {
  402. console.log(e)
  403. canvaColumnB.scrollStart(e);
  404. },
  405. moveLineBb(e) {
  406. canvaColumnB.scroll(e);
  407. },
  408. touchEndLineBb(e) {
  409. canvaColumnB.scrollEnd(e);
  410. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  411. canvaColumnB.showToolTip(e, {
  412. format: function(item, category) {
  413. return category + ' ' + item.name + ':' + item.data
  414. }
  415. });
  416. },
  417. async newdata() {
  418. const res = await this.$myRequest({
  419. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  420. data: {
  421. device_type_id: 2,
  422. d_id: this.times.d_id,
  423. control_type: "data"
  424. }
  425. })
  426. if(res){
  427. uni.showToast({
  428. title: '刷新成功',
  429. duration: 2000,
  430. icon: "none"
  431. });
  432. uni.navigateBack({
  433. delta: 1
  434. })
  435. }else{
  436. uni.showToast({
  437. title: '刷新失败',
  438. duration: 2000,
  439. icon: "none"
  440. });
  441. }
  442. },
  443. refresh() { //获取当前时间的数据
  444. this.newdata()
  445. },
  446. }
  447. }
  448. </script>
  449. <style lang="scss">
  450. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  451. .shuju_one,
  452. .shuju_two {
  453. position: absolute;
  454. top: 54px;
  455. width: 90%;
  456. left: 5%;
  457. box-shadow: 0 0 10rpx #bcb9ca;
  458. padding-top: 20rpx;
  459. height: 550rpx;
  460. .canvastishi{
  461. font-size: 32rpx;
  462. position: absolute;
  463. top: 50%;
  464. left: 50%;
  465. margin-left: -64rpx;
  466. margin-top: -21rpx;
  467. }
  468. .shuju_one_title {
  469. width: 70%;
  470. margin: 0 auto;
  471. display: flex;
  472. .tltle_text {
  473. width: 25%;
  474. border: 2rpx solid #B2B2B2;
  475. color: #B2B2B2;
  476. text-align: center;
  477. font-size: 24rpx;
  478. height: 50rpx;
  479. line-height: 50rpx;
  480. }
  481. .title_text_color {
  482. width: 25%;
  483. border: 2rpx solid #28AE4F;
  484. color: #28AE4F;
  485. text-align: center;
  486. font-size: 24rpx;
  487. height: 50rpx;
  488. line-height: 50rpx;
  489. }
  490. }
  491. .qiun-columns {
  492. .qiun-charts {
  493. width: 650upx;
  494. height: 400upx;
  495. background-color: #FFFFFF;
  496. }
  497. .charts {
  498. width: 650upx;
  499. height: 400upx;
  500. background-color: #FFFFFF;
  501. }
  502. }
  503. }
  504. .shuju_two {
  505. top: 700rpx;
  506. }
  507. .selecttimes {
  508. position: absolute;
  509. top: 1290rpx;
  510. width: 90%;
  511. box-shadow: 0 0 10rpx #bcb9ca;
  512. left: 5%;
  513. .tishi {
  514. width: 90%;
  515. margin: 0 auto;
  516. color: #f00000;
  517. text-align: center;
  518. font-size: 24rpx;
  519. }
  520. .btnser {
  521. width: 90%;
  522. margin: 10rpx auto;
  523. color: #FFFFFF;
  524. text-align: center;
  525. font-size: 28rpx;
  526. background-color: #58BD4D;
  527. border-radius: 20rpx;
  528. height: 50rpx;
  529. line-height: 50rpx;
  530. }
  531. .newtimes {
  532. width: 100%;
  533. padding: 20rpx 20rpx;
  534. box-sizing: border-box;
  535. .newtimes_state,
  536. .newtimes_end {
  537. display: flex;
  538. justify-content: space-between;
  539. margin-bottom: 20rpx;
  540. .oldtimes_left {
  541. position: relative;
  542. padding-left: 36rpx;
  543. font-size: 28rpx;
  544. image {
  545. width: 30rpx;
  546. height: 30rpx;
  547. vertical-align: top;
  548. position: absolute;
  549. top: 7rpx;
  550. left: 0;
  551. }
  552. }
  553. }
  554. }
  555. }
  556. .refresh{
  557. position: absolute;
  558. top: 1530rpx;
  559. left: 5%;
  560. width: 160rpx;
  561. height: 50rpx;
  562. background-color: #28AE4F;
  563. color: #FFFFFF;
  564. line-height: 50rpx;
  565. text-align: center;
  566. }
  567. .condition {
  568. position: absolute;
  569. top: 1600rpx;
  570. display: flex;
  571. flex-wrap: wrap;
  572. width: 90%;
  573. left: 5%;
  574. box-shadow: 0 0 10rpx #bcb9ca;
  575. margin-bottom: 30rpx;
  576. .scroll-X {
  577. width: 95%;
  578. margin: 20rpx auto;
  579. .table{
  580. width: 1056px;
  581. }
  582. .tr {
  583. display: flex;
  584. overflow: hidden;
  585. .th,
  586. .td {
  587. display: inline-block;
  588. padding: 5rpx;
  589. width: 140rpx;
  590. text-align: center;
  591. height: 52rpx;
  592. line-height: 52rpx;
  593. border: 2rpx solid #F1F1F1;
  594. }
  595. .th:first-child,
  596. .td:first-child {
  597. width: 300rpx;
  598. }
  599. .th:nth-last-child(1),
  600. .th:nth-last-child(2),
  601. .td:nth-last-child(1),
  602. .td:nth-last-child(2) {
  603. width: 200rpx;
  604. }
  605. }
  606. }
  607. .pagenumber {
  608. display: flex;
  609. margin: 20rpx auto;
  610. button {
  611. width: 150rpx;
  612. height: 50rpx;
  613. line-height: 50rpx;
  614. font-size: 26rpx;
  615. text-align: center;
  616. background-color: #17BB89;
  617. color: #FFFFFF;
  618. }
  619. .pagenumber_page {
  620. width: 150rpx;
  621. height: 50rpx;
  622. line-height: 50rpx;
  623. font-size: 26rpx;
  624. text-align: center;
  625. }
  626. }
  627. }
  628. </style>