ucharts.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584
  1. <template>
  2. <view>
  3. <view style="position: fixed;z-index: 100;width: 100%;">
  4. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="历史数据"></uni-nav-bar>
  5. </view>
  6. <view class="shuju_one">
  7. <view class="shuju_one_title">
  8. <view :class="titleidnex==index?'title_text_color':'tltle_text'" v-for="(item,index) in titletext" :key="index"
  9. @click="changeindex(index)">
  10. {{item}}
  11. </view>
  12. </view>
  13. <highcharts :chartOptions="options" :styles="styles" ref="simpleChart"></highcharts>
  14. </view>
  15. <view class="shuju_two">
  16. <highcharts :chartOptions="optionstwo" :styles="styles" ref="simpleChart"></highcharts>
  17. </view>
  18. <view class="selecttimes">
  19. <view class="newtimes">
  20. <view class="newtimes_state" @click="pickshow = !pickshow">
  21. <view class="oldtimes_left">
  22. <image src="../../static/image/prevention/841f87bfd8abb1b09610fa0789f9d8e.png" mode=""></image>
  23. 开始时间:{{this.oldtime|timeFormat()}}
  24. </view>
  25. <view class="oldtimes_left">
  26. <u-icon name="arrow-down"></u-icon>
  27. </view>
  28. <u-picker mode="time" v-model="pickshow" :params="params" @confirm="pickone"></u-picker>
  29. </view>
  30. <view class="newtimes_end" @click="picktwoshow = !picktwoshow">
  31. <view class="oldtimes_left">
  32. <image src="../../static/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png" mode=""></image>
  33. 结束时间:{{this.newtime|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="picktwoshow" :params="params" @confirm="picktwo"></u-picker>
  39. </view>
  40. <p class="tishi" v-if="tishiTF">请选择正确的结束时间</p>
  41. <view class="btnser" @click="serter">
  42. 搜 索
  43. </view>
  44. </view>
  45. </view>
  46. <view class="condition">
  47. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  48. <!-- @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" -->
  49. <table class="table">
  50. <tr class="tr">
  51. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  52. </tr>
  53. <tr class="tr" v-for="(items,indexs) in eqlistdata" :key="'b'+indexs" v-if="forbidden">
  54. <td class="td">{{items.d_h_t.ds==0?"关机":"开机"}}</td>
  55. <td class="td">{{items.d_h_t.ws==0?"待机":"工作"}}</td>
  56. <td class="td">{{items.d_h_t.lamp==0?"灭":"亮"}}</td>
  57. <td class="td">{{items.d_h_t.rps==0?"正常":"保护"}}</td>
  58. <td class="td">{{items.d_h_t.tps==0?"正常":"保护"}}</td>
  59. <td class="td">{{items.d_h_t.dps==0?"正常":"保护"}}</td>
  60. <td class="td">{{items.d_h_t.tt}}</td>
  61. <td class="td">{{items.d_h_t.ct}}</td>
  62. <td class="td">{{items.d_h_t.at}}</td>
  63. <td class="td">{{items.d_h_t.ah}}</td>
  64. <td class="td">{{items.d_h_t.cv}}</td>
  65. <td class="td">{{items.d_h_t.bv}}</td>
  66. <td class="td">{{items.d_h_t.addtime|timeFormat()}}</td>
  67. </tr>
  68. <tr class="tr" v-if="!forbidden">
  69. <td class="td" v-for="item in 13">暂无数据</td>
  70. </tr>
  71. </table>
  72. </scroll-view>
  73. <view class="pagenumber">
  74. <button @click="prev">上一页</button>
  75. <view class="pagenumber_page">
  76. 第{{page}}页
  77. </view>
  78. <button @click="next" :disabled="!forbidden">下一页</button>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. <style lang="scss">
  84. </style>
  85. <script>
  86. import highcharts from "@/components/highcharts/highcharts"
  87. // import uCharts from '../../js_sdk/u-charts/u-charts/u-charts.js';
  88. // var _self;
  89. // var canvaLineA = null;
  90. var presenttime = +new Date();
  91. // var oldpresenttime = presenttime - 24*60*60*1000
  92. export default {
  93. data() {
  94. return {
  95. thdata: ["设备开关", "工作状态", "灯管状态", "雨控状态", "温控状态", "倾倒状态", "定时(h)", "电击次数", "温度(℃)", "湿度(%)", "充电电压(v)", "电池电压(v)",
  96. "上报时间"
  97. ],
  98. eqlistdata: [],
  99. cWidth: '',
  100. cHeight: '',
  101. pixelRatio: 1,
  102. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  103. titleidnex: 0,
  104. chartsdata: [],
  105. oldtime: '',
  106. newtime: '',
  107. page: 1,
  108. forbidden: false, //暂无数据
  109. params: {
  110. year: true,
  111. month: true,
  112. day: true,
  113. hour: true,
  114. minute: true,
  115. second: false
  116. },
  117. pickshow: false,
  118. picktwoshow: false,
  119. tishiTF: false,
  120. times: {
  121. d_id: null,
  122. start_time: null,
  123. end_time: null,
  124. device_id: null
  125. },
  126. styles: {
  127. // width: "650rpx",
  128. height: "400rpx"
  129. },
  130. options: {
  131. lang:{
  132. noData:"暂无数据"
  133. },
  134. chart: {
  135. type: 'spline', //指定图表的类型,默认是折线图(line)
  136. zoomType: 'x',
  137. panning: true,
  138. panKey: 'shift'
  139. },
  140. title: {
  141. text: '' // 标题
  142. },
  143. credits: {
  144. enabled: false
  145. },
  146. xAxis: {
  147. type: 'datetime',
  148. crosshair: true, //十字基准线
  149. dateTimeLabelFormats: {
  150. //根据时间间距X轴自动显示哪种格式
  151. millisecond: "%H:%M:%S.%L",
  152. second: "%H:%M:%S",
  153. minute: "%H:%M",
  154. hour: "%H:%M",
  155. day: "%m-%d",
  156. week: "%m-%d",
  157. month: "%Y-%m",
  158. year: "%Y",
  159. },
  160. },
  161. yAxis: {
  162. title: false,
  163. },
  164. legend: {
  165. // layout: 'vertical',
  166. align: "center",
  167. verticalAlign: "top",
  168. },
  169. tooltip: {
  170. // crosshairs: true,
  171. shared: true, //折线共享
  172. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  173. },
  174. plotOptions: {
  175. spline: {
  176. marker: {
  177. enabled: false
  178. },
  179. }
  180. },
  181. series: [{
  182. name: "温度",
  183. data: [],
  184. color: "#F97000"
  185. },
  186. {
  187. name: "湿度",
  188. data: [],
  189. color: "#00E29D"
  190. },
  191. {
  192. name: "充电电压",
  193. data: [],
  194. color: "#6CBBFF"
  195. },
  196. {
  197. name: "电池电压",
  198. data: [],
  199. color: "#f00000"
  200. }
  201. ],
  202. },
  203. optionstwo: {
  204. lang:{
  205. noData:"暂无数据"
  206. },
  207. chart: {
  208. type: 'spline', //指定图表的类型,默认是折线图(line)
  209. zoomType: 'x',
  210. panning: true,
  211. panKey: 'shift'
  212. },
  213. title: {
  214. text: '击虫次数', // 标题
  215. style: {
  216. "font-size": "16px",
  217. color: "#00E29D"
  218. }
  219. },
  220. credits: {
  221. enabled: false
  222. },
  223. xAxis: {
  224. type: 'datetime',
  225. crosshair: true, //十字基准线
  226. dateTimeLabelFormats: {
  227. //根据时间间距X轴自动显示哪种格式
  228. millisecond: "%H:%M:%S.%L",
  229. second: "%H:%M:%S",
  230. minute: "%H:%M",
  231. hour: "%H:%M",
  232. day: "%m-%d",
  233. week: "%m-%d",
  234. month: "%Y-%m",
  235. year: "%Y",
  236. },
  237. },
  238. yAxis: {
  239. title: false,
  240. },
  241. legend: {
  242. // layout: 'vertical',
  243. align: "center",
  244. verticalAlign: "top",
  245. },
  246. tooltip: {
  247. // crosshairs: true,
  248. shared: true, //折线共享
  249. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  250. },
  251. plotOptions: {
  252. spline: {
  253. marker: {
  254. enabled: false
  255. },
  256. }
  257. },
  258. series: [{
  259. name: "击虫次数",
  260. data: [],
  261. color: "#00E29D"
  262. }, ],
  263. }
  264. }
  265. },
  266. // 页面加载执行的函数
  267. onLoad(option) {
  268. this.times.d_id = option.d_id
  269. this.times.device_id = option.device_id
  270. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  271. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  272. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  273. this.newtime = parseInt(presenttime / 1000)
  274. },
  275. methods: { //
  276. //forecast.worm_lamp.device_polyline_data
  277. // 获取数据,发请求
  278. async getServerData(newtime, oldtimes) { //设备列表
  279. const res = await this.$myRequest({
  280. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  281. data: {
  282. device_type_id: 2,
  283. d_id: this.times.d_id,
  284. end_time: newtime,
  285. start_time: oldtimes
  286. }
  287. })
  288. this.options.series[0].data = []
  289. this.options.series[1].data = []
  290. this.options.series[2].data = []
  291. this.options.series[3].data = []
  292. this.optionstwo.series[0].data = []
  293. for (var i = 0; i < res.length; i++) {
  294. // this.chartsdata.unshift(res[i].humidity)
  295. let arr0 = []
  296. arr0.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].humidity))
  297. this.options.series[0].data.unshift(arr0)
  298. let arr1 = []
  299. arr1.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].temperature))
  300. this.options.series[1].data.unshift(arr1)
  301. let arr2 = []
  302. arr2.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].others.cv / 1000))
  303. this.options.series[2].data.unshift(arr2)
  304. let arr3 = []
  305. arr3.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].others.bv / 1000))
  306. this.options.series[3].data.unshift(arr3)
  307. let arr4 = []
  308. arr4.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].others.ct / 1000))
  309. this.optionstwo.series[0].data.unshift(arr4)
  310. }
  311. console.log(this.optionstwo.series[0].data)
  312. },
  313. changeindex(index) { //选择日期
  314. this.titleidnex = index
  315. var now = new Date();
  316. if (index == 0) {
  317. this.newtime = parseInt(+new Date(now) / 1000)
  318. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  319. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  320. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  321. } else if (index == 1) {
  322. this.newtime = parseInt(+new Date(now) / 1000)
  323. var oldtime = now.setMonth(now.getMonth() - 1) / 1000
  324. this.oldtime = parseInt(oldtime)
  325. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  326. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  327. } else if (index == 2) {
  328. this.newtime = parseInt(+new Date(now) / 1000)
  329. var oldtime = now.setMonth(now.getMonth() - 6) / 1000
  330. this.oldtime = parseInt(oldtime)
  331. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  332. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  333. } else if (index == 3) {
  334. this.newtime = parseInt(+new Date(now) / 1000)
  335. var oldtime = now.setFullYear(now.getFullYear() - 1) / 1000
  336. this.oldtime = parseInt(oldtime)
  337. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  338. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  339. }
  340. if (this.newtime < this.oldtime) {
  341. this.tishiTF = true
  342. } else {
  343. this.tishiTF = false
  344. }
  345. },
  346. async historydata(newtime, oldtimes) { //设备列表
  347. const res = await this.$myRequest({
  348. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  349. data: {
  350. device_type_id: 2,
  351. device_id: this.times.device_id,
  352. page: this.page,
  353. page_size: 10,
  354. start_time: oldtimes,
  355. end_time: newtime
  356. }
  357. })
  358. this.eqlistdata = res.data
  359. if (this.eqlistdata.length == 0) {
  360. this.forbidden = false
  361. } else {
  362. this.forbidden = true
  363. }
  364. },
  365. prev() { //上一页
  366. if (this.page != 1) {
  367. this.page--
  368. }
  369. this.historydata(this.newtime, this.oldtime)
  370. },
  371. next() { //下一页
  372. this.page++
  373. this.historydata(this.newtime, this.oldtime)
  374. },
  375. pickone(e) {
  376. this.oldtime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  377. if (this.newtime < this.oldtime) {
  378. this.tishiTF = true
  379. } else {
  380. this.tishiTF = false
  381. }
  382. },
  383. picktwo(e) {
  384. this.newtime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  385. if (this.newtime < this.oldtime) {
  386. this.tishiTF = true
  387. } else {
  388. this.tishiTF = false
  389. }
  390. },
  391. serter() {
  392. if (this.tishiTF == false) {
  393. this.getServerData(parseInt(presenttime / 1000), parseInt(this.oldtime))
  394. this.historydata(this.newtime, this.oldtime)
  395. }
  396. },
  397. clickLeft(){
  398. uni.navigateBack({
  399. delta:1
  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. .shuju_one_title {
  416. width: 70%;
  417. margin: 0 auto;
  418. display: flex;
  419. .tltle_text {
  420. width: 25%;
  421. border: 2rpx solid #B2B2B2;
  422. color: #B2B2B2;
  423. text-align: center;
  424. font-size: 24rpx;
  425. height: 50rpx;
  426. line-height: 50rpx;
  427. }
  428. .title_text_color {
  429. width: 25%;
  430. border: 2rpx solid #28AE4F;
  431. color: #28AE4F;
  432. text-align: center;
  433. font-size: 24rpx;
  434. height: 50rpx;
  435. line-height: 50rpx;
  436. }
  437. }
  438. .qiun-columns {
  439. .qiun-charts {
  440. width: 650upx;
  441. height: 400upx;
  442. background-color: #FFFFFF;
  443. }
  444. .charts {
  445. width: 650upx;
  446. height: 400upx;
  447. background-color: #FFFFFF;
  448. }
  449. }
  450. }
  451. .shuju_two {
  452. top: 598rpx;
  453. }
  454. .selecttimes {
  455. position: absolute;
  456. top: 1040rpx;
  457. width: 90%;
  458. box-shadow: 0 0 10rpx #bcb9ca;
  459. left: 5%;
  460. .tishi {
  461. width: 90%;
  462. margin: 0 auto;
  463. color: #f00000;
  464. text-align: center;
  465. font-size: 24rpx;
  466. }
  467. .btnser {
  468. width: 90%;
  469. margin: 10rpx auto;
  470. color: #FFFFFF;
  471. text-align: center;
  472. font-size: 28rpx;
  473. background-color: #58BD4D;
  474. border-radius: 20rpx;
  475. height: 50rpx;
  476. line-height: 50rpx;
  477. }
  478. .newtimes {
  479. width: 100%;
  480. padding: 20rpx 20rpx;
  481. box-sizing: border-box;
  482. .newtimes_state,
  483. .newtimes_end {
  484. display: flex;
  485. justify-content: space-between;
  486. margin-bottom: 20rpx;
  487. .oldtimes_left {
  488. position: relative;
  489. padding-left: 36rpx;
  490. font-size: 28rpx;
  491. image {
  492. width: 30rpx;
  493. height: 30rpx;
  494. vertical-align: top;
  495. position: absolute;
  496. top: 7rpx;
  497. left: 0;
  498. }
  499. }
  500. }
  501. }
  502. }
  503. .condition {
  504. position: absolute;
  505. top: 1280rpx;
  506. display: flex;
  507. flex-wrap: wrap;
  508. width: 90%;
  509. left: 5%;
  510. box-shadow: 0 0 10rpx #bcb9ca;
  511. margin-bottom: 30rpx;
  512. .scroll-X {
  513. width: 95%;
  514. margin: 20rpx auto;
  515. .tr {
  516. display: flex;
  517. overflow: hidden;
  518. .th,
  519. .td {
  520. display: inline-block;
  521. padding: 5rpx;
  522. width: 140rpx;
  523. text-align: center;
  524. height: 52rpx;
  525. line-height: 52rpx;
  526. border: 2rpx solid #F1F1F1;
  527. }
  528. .th:last-child,
  529. .td:last-child {
  530. width: 300rpx;
  531. }
  532. .th:nth-last-child(2),
  533. .th:nth-last-child(3),
  534. .td:nth-last-child(2),
  535. .td:nth-last-child(3) {
  536. width: 200rpx;
  537. }
  538. }
  539. }
  540. .pagenumber {
  541. display: flex;
  542. margin: 20rpx auto;
  543. button {
  544. width: 150rpx;
  545. height: 50rpx;
  546. line-height: 50rpx;
  547. font-size: 26rpx;
  548. text-align: center;
  549. background-color: #17BB89;
  550. color: #FFFFFF;
  551. }
  552. .pagenumber_page {
  553. width: 150rpx;
  554. height: 50rpx;
  555. line-height: 50rpx;
  556. font-size: 26rpx;
  557. text-align: center;
  558. }
  559. }
  560. }
  561. </style>