ucharts.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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. chart: {
  132. type: 'spline', //指定图表的类型,默认是折线图(line)
  133. zoomType: 'x',
  134. panning: true,
  135. panKey: 'shift'
  136. },
  137. title: {
  138. text: '' // 标题
  139. },
  140. credits: {
  141. enabled: false
  142. },
  143. xAxis: {
  144. type: 'datetime',
  145. crosshair: true, //十字基准线
  146. dateTimeLabelFormats: {
  147. //根据时间间距X轴自动显示哪种格式
  148. millisecond: "%H:%M:%S.%L",
  149. second: "%H:%M:%S",
  150. minute: "%H:%M",
  151. hour: "%H:%M",
  152. day: "%m-%d",
  153. week: "%m-%d",
  154. month: "%Y-%m",
  155. year: "%Y",
  156. },
  157. },
  158. yAxis: {
  159. title: false,
  160. },
  161. legend: {
  162. // layout: 'vertical',
  163. align: "center",
  164. verticalAlign: "top",
  165. },
  166. tooltip: {
  167. // crosshairs: true,
  168. shared: true, //折线共享
  169. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  170. },
  171. plotOptions: {
  172. spline: {
  173. marker: {
  174. enabled: false
  175. },
  176. }
  177. },
  178. series: [{
  179. name: "温度",
  180. data: [],
  181. color: "#F97000"
  182. },
  183. {
  184. name: "湿度",
  185. data: [],
  186. color: "#00E29D"
  187. },
  188. {
  189. name: "充电电压",
  190. data: [],
  191. color: "#6CBBFF"
  192. },
  193. {
  194. name: "电池电压",
  195. data: [],
  196. color: "#f00000"
  197. }
  198. ],
  199. },
  200. optionstwo: {
  201. chart: {
  202. type: 'spline', //指定图表的类型,默认是折线图(line)
  203. zoomType: 'x',
  204. panning: true,
  205. panKey: 'shift'
  206. },
  207. title: {
  208. text: '击虫次数', // 标题
  209. style: {
  210. "font-size": "16px",
  211. color: "#00E29D"
  212. }
  213. },
  214. credits: {
  215. enabled: false
  216. },
  217. xAxis: {
  218. type: 'datetime',
  219. crosshair: true, //十字基准线
  220. dateTimeLabelFormats: {
  221. //根据时间间距X轴自动显示哪种格式
  222. millisecond: "%H:%M:%S.%L",
  223. second: "%H:%M:%S",
  224. minute: "%H:%M",
  225. hour: "%H:%M",
  226. day: "%m-%d",
  227. week: "%m-%d",
  228. month: "%Y-%m",
  229. year: "%Y",
  230. },
  231. },
  232. yAxis: {
  233. title: false,
  234. },
  235. legend: {
  236. // layout: 'vertical',
  237. align: "center",
  238. verticalAlign: "top",
  239. },
  240. tooltip: {
  241. // crosshairs: true,
  242. shared: true, //折线共享
  243. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  244. },
  245. plotOptions: {
  246. spline: {
  247. marker: {
  248. enabled: false
  249. },
  250. }
  251. },
  252. series: [{
  253. name: "击虫次数",
  254. data: [],
  255. color: "#00E29D"
  256. }, ],
  257. }
  258. }
  259. },
  260. // 页面加载执行的函数
  261. onLoad(option) {
  262. this.times.d_id = option.d_id
  263. this.times.device_id = option.device_id
  264. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  265. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  266. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  267. this.newtime = parseInt(presenttime / 1000)
  268. },
  269. methods: { //
  270. //forecast.worm_lamp.device_polyline_data
  271. // 获取数据,发请求
  272. async getServerData(newtime, oldtimes) { //设备列表
  273. const res = await this.$myRequest({
  274. url: '/api/api_gateway?method=forecast.worm_lamp.device_polyline_data',
  275. data: {
  276. device_type_id: 2,
  277. d_id: this.times.d_id,
  278. end_time: newtime,
  279. start_time: oldtimes
  280. }
  281. })
  282. this.options.series[0].data = []
  283. this.options.series[1].data = []
  284. this.options.series[2].data = []
  285. this.options.series[3].data = []
  286. this.optionstwo.series[0].data = []
  287. for (var i = 0; i < res.length; i++) {
  288. // this.chartsdata.unshift(res[i].humidity)
  289. let arr0 = []
  290. arr0.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].humidity))
  291. this.options.series[0].data.unshift(arr0)
  292. let arr1 = []
  293. arr1.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].temperature))
  294. this.options.series[1].data.unshift(arr1)
  295. let arr2 = []
  296. arr2.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].others.cv / 1000))
  297. this.options.series[2].data.unshift(arr2)
  298. let arr3 = []
  299. arr3.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].others.bv / 1000))
  300. this.options.series[3].data.unshift(arr3)
  301. let arr4 = []
  302. arr4.push(res[i].addtime * 1000 + 8 * 3600000, Number(res[i].others.ct / 1000))
  303. this.optionstwo.series[0].data.unshift(arr4)
  304. }
  305. console.log(this.optionstwo.series[0].data)
  306. },
  307. changeindex(index) { //选择日期
  308. this.titleidnex = index
  309. var now = new Date();
  310. if (index == 0) {
  311. this.newtime = parseInt(+new Date(now) / 1000)
  312. this.oldtime = parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000)
  313. this.getServerData(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  314. this.historydata(parseInt(presenttime / 1000), parseInt((presenttime - 24 * 60 * 60 * 1000) / 1000))
  315. } else if (index == 1) {
  316. this.newtime = parseInt(+new Date(now) / 1000)
  317. var oldtime = now.setMonth(now.getMonth() - 1) / 1000
  318. this.oldtime = parseInt(oldtime)
  319. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  320. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  321. } else if (index == 2) {
  322. this.newtime = parseInt(+new Date(now) / 1000)
  323. var oldtime = now.setMonth(now.getMonth() - 6) / 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 == 3) {
  328. this.newtime = parseInt(+new Date(now) / 1000)
  329. var oldtime = now.setFullYear(now.getFullYear() - 1) / 1000
  330. this.oldtime = parseInt(oldtime)
  331. this.getServerData(parseInt(presenttime / 1000), parseInt(oldtime))
  332. this.historydata(parseInt(presenttime / 1000), parseInt(oldtime))
  333. }
  334. if (this.newtime < this.oldtime) {
  335. this.tishiTF = true
  336. } else {
  337. this.tishiTF = false
  338. }
  339. },
  340. async historydata(newtime, oldtimes) { //设备列表
  341. const res = await this.$myRequest({
  342. url: '/api/api_gateway?method=forecast.worm_lamp.device_history_data',
  343. data: {
  344. device_type_id: 2,
  345. device_id: this.times.device_id,
  346. page: this.page,
  347. page_size: 10,
  348. start_time: oldtimes,
  349. end_time: newtime
  350. }
  351. })
  352. this.eqlistdata = res.data
  353. if (this.eqlistdata.length == 0) {
  354. this.forbidden = false
  355. } else {
  356. this.forbidden = true
  357. }
  358. },
  359. prev() { //上一页
  360. if (this.page != 1) {
  361. this.page--
  362. }
  363. this.historydata(this.newtime, this.oldtime)
  364. },
  365. next() { //下一页
  366. this.page++
  367. this.historydata(this.newtime, this.oldtime)
  368. },
  369. pickone(e) {
  370. this.oldtime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  371. if (this.newtime < this.oldtime) {
  372. this.tishiTF = true
  373. } else {
  374. this.tishiTF = false
  375. }
  376. },
  377. picktwo(e) {
  378. this.newtime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  379. if (this.newtime < this.oldtime) {
  380. this.tishiTF = true
  381. } else {
  382. this.tishiTF = false
  383. }
  384. },
  385. serter() {
  386. if (this.tishiTF == false) {
  387. this.getServerData(parseInt(presenttime / 1000), parseInt(this.oldtime))
  388. this.historydata(this.newtime, this.oldtime)
  389. }
  390. },
  391. clickLeft(){
  392. uni.navigateBack({
  393. delta:1
  394. })
  395. }
  396. },
  397. }
  398. </script>
  399. <style lang="scss">
  400. /*样式的width和height一定要与定义的cWidth和cHeight相对应*/
  401. .shuju_one,
  402. .shuju_two {
  403. position: absolute;
  404. top: 54px;
  405. width: 90%;
  406. left: 5%;
  407. box-shadow: 0 0 10rpx #bcb9ca;
  408. padding-top: 20rpx;
  409. .shuju_one_title {
  410. width: 70%;
  411. margin: 0 auto;
  412. display: flex;
  413. .tltle_text {
  414. width: 25%;
  415. border: 2rpx solid #B2B2B2;
  416. color: #B2B2B2;
  417. text-align: center;
  418. font-size: 24rpx;
  419. height: 50rpx;
  420. line-height: 50rpx;
  421. }
  422. .title_text_color {
  423. width: 25%;
  424. border: 2rpx solid #28AE4F;
  425. color: #28AE4F;
  426. text-align: center;
  427. font-size: 24rpx;
  428. height: 50rpx;
  429. line-height: 50rpx;
  430. }
  431. }
  432. .qiun-columns {
  433. .qiun-charts {
  434. width: 650upx;
  435. height: 400upx;
  436. background-color: #FFFFFF;
  437. }
  438. .charts {
  439. width: 650upx;
  440. height: 400upx;
  441. background-color: #FFFFFF;
  442. }
  443. }
  444. }
  445. .shuju_two {
  446. top: 598rpx;
  447. }
  448. .selecttimes {
  449. position: absolute;
  450. top: 1040rpx;
  451. width: 90%;
  452. box-shadow: 0 0 10rpx #bcb9ca;
  453. left: 5%;
  454. .tishi {
  455. width: 90%;
  456. margin: 0 auto;
  457. color: #f00000;
  458. text-align: center;
  459. font-size: 24rpx;
  460. }
  461. .btnser {
  462. width: 90%;
  463. margin: 10rpx auto;
  464. color: #FFFFFF;
  465. text-align: center;
  466. font-size: 28rpx;
  467. background-color: #58BD4D;
  468. border-radius: 20rpx;
  469. height: 50rpx;
  470. line-height: 50rpx;
  471. }
  472. .newtimes {
  473. width: 100%;
  474. padding: 20rpx 20rpx;
  475. box-sizing: border-box;
  476. .newtimes_state,
  477. .newtimes_end {
  478. display: flex;
  479. justify-content: space-between;
  480. margin-bottom: 20rpx;
  481. .oldtimes_left {
  482. position: relative;
  483. padding-left: 36rpx;
  484. font-size: 28rpx;
  485. image {
  486. width: 30rpx;
  487. height: 30rpx;
  488. vertical-align: top;
  489. position: absolute;
  490. top: 7rpx;
  491. left: 0;
  492. }
  493. }
  494. }
  495. }
  496. }
  497. .condition {
  498. position: absolute;
  499. top: 1280rpx;
  500. display: flex;
  501. flex-wrap: wrap;
  502. width: 90%;
  503. left: 5%;
  504. box-shadow: 0 0 10rpx #bcb9ca;
  505. margin-bottom: 30rpx;
  506. .scroll-X {
  507. width: 95%;
  508. margin: 20rpx auto;
  509. .tr {
  510. display: flex;
  511. overflow: hidden;
  512. .th,
  513. .td {
  514. display: inline-block;
  515. padding: 5rpx;
  516. width: 140rpx;
  517. text-align: center;
  518. height: 52rpx;
  519. line-height: 52rpx;
  520. border: 2rpx solid #F1F1F1;
  521. }
  522. .th:last-child,
  523. .td:last-child {
  524. width: 300rpx;
  525. }
  526. .th:nth-last-child(2),
  527. .th:nth-last-child(3),
  528. .td:nth-last-child(2),
  529. .td:nth-last-child(3) {
  530. width: 200rpx;
  531. }
  532. }
  533. }
  534. .pagenumber {
  535. display: flex;
  536. margin: 20rpx auto;
  537. button {
  538. width: 150rpx;
  539. height: 50rpx;
  540. line-height: 50rpx;
  541. font-size: 26rpx;
  542. text-align: center;
  543. background-color: #17BB89;
  544. color: #FFFFFF;
  545. }
  546. .pagenumber_page {
  547. width: 150rpx;
  548. height: 50rpx;
  549. line-height: 50rpx;
  550. font-size: 26rpx;
  551. text-align: center;
  552. }
  553. }
  554. }
  555. </style>