historydatas.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525
  1. <template>
  2. <view>
  3. <view class="">
  4. <view class="timeandtype">
  5. <view class="timebox">
  6. <view class="firsttime" @click="timeshow=true">
  7. <view class="" v-if="start_time!=''">
  8. {{(start_time==""?'请选择开始时间':start_time)/1000|timeFormat()}}
  9. </view>
  10. <view class="" v-else>
  11. {{start_time==""?'请选择开始时间':start_time}}
  12. </view>
  13. </view>
  14. <view class="jiange">
  15. -
  16. </view>
  17. <view class="endtime" @click="timeshow=true">
  18. <view class="" v-if="end_time!=''">
  19. {{(end_time==""?'请选择结束时间':end_time)/1000|timeFormat()}}
  20. </view>
  21. <view class="" v-else>
  22. {{end_time==""?'请选择结束时间':end_time}}
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="shuju_one">
  28. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  29. 暂无数据
  30. </view>
  31. <view class="canvastishi" v-if="dataloadingtf">
  32. <p class="dataloading">加载中</p>
  33. </view>
  34. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  35. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)"
  36. disable-scroll=true
  37. :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>
  38. </view>
  39. <view class="refresh" @click="refresh">
  40. 刷 新
  41. </view>
  42. <view class="condition">
  43. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  44. <table class="table" v-if="$QueryPermission(266)">
  45. <tr class="tr">
  46. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  47. </tr>
  48. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  49. <td class="td">{{items.xy_addtime|timeFormat()}}</td>
  50. <td class="td">{{items.at==""?"--":items.at}}</td>
  51. <td class="td">{{items.ah==""?"--":items.ah}}</td>
  52. <td class="td">{{items.warn==""?"--":items.warn}}</td>
  53. <td class="td">{{items.b_V==""?"--":items.b_V}}</td>
  54. <td class="td">{{items.b_c==""?"--":items.b_c}}</td>
  55. <td class="td">{{items.p_v==""?"--":items.p_v}}</td>
  56. <td class="td">{{items.p_c==""?"--":items.p_c}}</td>
  57. </tr>
  58. <tr class="tr" v-if="forbidden">
  59. <td class="td" v-for="item in 8">暂无数据</td>
  60. </tr>
  61. </table>
  62. <table class="thdata2" v-else>
  63. <tr class="tr">
  64. <th class="th" v-for="(item,index) in thdata2" :key="'a'+index">{{item}}</th>
  65. </tr>
  66. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  67. <td class="td">{{items.xy_addtime|timeFormat()}}</td>
  68. <td class="td">{{items.at==""?"--":items.at}}</td>
  69. <td class="td">{{items.ah==""?"--":items.ah}}</td>
  70. <td class="td">{{items.warn==""?"--":items.warn}}</td>
  71. </tr>
  72. <tr class="tr" v-if="forbidden">
  73. <td class="td" v-for="item in 4">暂无数据</td>
  74. </tr>
  75. </table>
  76. </scroll-view>
  77. <view class="pagenumber">
  78. <button @click="prev">上一页</button>
  79. <view class="pagenumber_page">
  80. 第 {{page}} 页
  81. </view>
  82. <view class="pagenumber_page">
  83. 共 {{pagesum}} 页
  84. </view>
  85. <button @click="next" :disabled="forbidden">下一页</button>
  86. </view>
  87. </view>
  88. </view>
  89. <u-calendar v-model="timeshow" :mode="mode" @change="timechange"></u-calendar>
  90. </view>
  91. </template>
  92. <script>
  93. import uCharts from '../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  94. var canvaColumnA = null;
  95. export default {
  96. data() {
  97. return {
  98. styles: {
  99. // width: "650rpx",
  100. height: "400rpx"
  101. },
  102. d_id: '',
  103. start_time: "",
  104. end_time: "",
  105. historydatas: [],
  106. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  107. titleidnex: 0,
  108. device_id: '',
  109. page: 1,
  110. historylistdata: [],
  111. thdata: ["上报时间", "环境温度(°C)", "环境湿度(%)", "虫害预警", "电池电压", "电池电流", "太阳能板电压", "太阳能板电流"],
  112. thdata2: ["上报时间", "环境温度(°C)", "环境湿度(%)", "虫害预警"],
  113. forbidden: false,
  114. cWidth: '400',
  115. cHeight: '400',
  116. pixelRatio: 1,
  117. canvastishiTF: false, //暂无数据提示
  118. dataloadingtf: true, //加载中提示
  119. pagesum: 1,
  120. worms: [],
  121. timeshow:false,
  122. mode: 'range',
  123. }
  124. },
  125. methods: {
  126. async Chistory() { //历史数据列表折线图
  127. this.dataloadingtf = true
  128. const res = await this.$myRequest({
  129. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_line_chart',
  130. data: {
  131. device_id: this.device_id,
  132. start_time: parseInt(this.start_time / 1000),
  133. end_time: parseInt(this.end_time / 1000),
  134. status: "pest"
  135. }
  136. })
  137. this.dataloadingtf = false
  138. this.worms = res
  139. console.log(this.worms)
  140. if (this.worms.data.length == 0) {
  141. this.canvastishiTF = false
  142. } else {
  143. this.canvastishiTF = true
  144. var arr3 = []
  145. var xtitle = []
  146. for (var i = 0; i < res.data.length; i++) {
  147. xtitle.push(res.data[i].xy_addtime)
  148. }
  149. for (var j = 0; j < this.worms.data.length; j++) {
  150. // unshift
  151. arr3.push(this.worms.data[j].pest_num == "" ? "0" : this.worms.data[j].pest_num)
  152. }
  153. console.log(arr3)
  154. this.$nextTick(() => {
  155. var obj = [{
  156. name: '诱虫次数',
  157. data: arr3,
  158. color: '#ff0000'
  159. }]
  160. this.showColumn("canvasColumnA", xtitle, obj)
  161. })
  162. }
  163. },
  164. //forecast.worm_lamp.device_history_data历史数据列表
  165. async historylist() { //历史数据列表
  166. const res = await this.$myRequest({
  167. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_history',
  168. data: {
  169. device_id: this.device_id,
  170. strat_time: parseInt(this.start_time / 1000),
  171. end_time: parseInt(this.end_time / 1000),
  172. page: this.page
  173. }
  174. })
  175. this.historylistdata = res.data
  176. console.log(res.data)
  177. this.pagesum = Math.ceil(res.nums / 10) || 1
  178. if (res.data.length == 0) {
  179. this.forbidden = true
  180. } else {
  181. this.forbidden = false
  182. }
  183. console.log(this.historylistdata)
  184. },
  185. // forecast.send_control.get_device_config 获取当前时间的数据
  186. async newdata() {
  187. const res = await this.$myRequest({
  188. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_mqtt',
  189. data: {
  190. d_id: this.d_id
  191. }
  192. })
  193. if (res) {
  194. uni.showToast({
  195. title: '刷新成功',
  196. duration: 2000,
  197. icon: "none"
  198. });
  199. } else {
  200. uni.showToast({
  201. title: '刷新失败',
  202. duration: 2000,
  203. icon: "none"
  204. });
  205. }
  206. },
  207. refresh() { //获取当前时间的数据
  208. this.newdata()
  209. },
  210. prev() { //上一页
  211. if (this.page > 1) {
  212. this.page--
  213. this.historylist()
  214. }
  215. },
  216. next() { //下一页
  217. if (this.page < this.pagesum) {
  218. this.page++
  219. this.historylist()
  220. }
  221. },
  222. clickLeft() {
  223. uni.navigateBack({
  224. delta: 1
  225. })
  226. },
  227. showColumn(id, xtitle, xinfo) {
  228. var _self = this
  229. const ctx = uni.createCanvasContext(id, this);
  230. canvaColumnA = new uCharts({
  231. context: ctx,
  232. type: 'line',
  233. legend: {
  234. position: "top"
  235. },
  236. fontSize: 10,
  237. background: '#FFFFFF',
  238. pixelRatio: 1,
  239. animation: true,
  240. dataLabel: false,
  241. categories: xtitle,
  242. series: xinfo,
  243. enableScroll: true, //开启图表拖拽功能
  244. xAxis: {
  245. disableGrid: true,
  246. type: 'grid',
  247. gridType: 'dash',
  248. itemCount: 3, //x轴单屏显示数据的数量,默认为5个
  249. scrollShow: true, //新增是否显示滚动条,默认false
  250. // scrollAlign: 'left', //滚动条初始位置
  251. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  252. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  253. },
  254. yAxis: {
  255. gridType: 'dash',
  256. gridColor: '#CCCCCC',
  257. dashLength: 8,
  258. splitNumber: 5,
  259. format: (val) => {
  260. return val.toFixed(1)
  261. }
  262. },
  263. width: _self.cWidth * 1,
  264. height: _self.cHeight * 1,
  265. extra: {
  266. line: {
  267. type: 'curve'
  268. }
  269. }
  270. });
  271. },
  272. touchLineA(e) {
  273. console.log(e)
  274. canvaColumnA.scrollStart(e);
  275. },
  276. moveLineA(e) {
  277. canvaColumnA.scroll(e);
  278. },
  279. touchEndLineA(e) {
  280. canvaColumnA.scrollEnd(e);
  281. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  282. canvaColumnA.showToolTip(e, {
  283. format: function(item, category) {
  284. return category + ' ' + item.name + ':' + item.data
  285. }
  286. });
  287. },
  288. closetime() {
  289. this.start_time = ""
  290. this.end_time = ""
  291. this.listpage = 1
  292. this.Chistory()
  293. this.historylist()
  294. },
  295. timechange(e) {
  296. console.log(e)
  297. this.start_time = +new Date(e.startDate)
  298. this.end_time = +new Date(e.endDate)
  299. this.listpage = 1
  300. this.Chistory()
  301. this.historylist()
  302. },
  303. },
  304. onLoad(option) {
  305. console.log(option)
  306. this.d_id = option.d_id
  307. this.device_id = option.device_id
  308. this.cWidth = uni.upx2px(650);
  309. this.cHeight = uni.upx2px(500);
  310. },
  311. onShow() {
  312. this.end_time = +new Date() + 1000
  313. this.start_time = this.end_time - 24 * 60 * 60 * 1000*30
  314. console.log(new Date(this.end_time), new Date(this.start_time))
  315. // this.history()
  316. this.Chistory()
  317. this.historylist()
  318. },
  319. onPullDownRefresh() {
  320. console.log('refresh');
  321. this.Chistory()
  322. this.historylist()
  323. setTimeout(function() {
  324. uni.stopPullDownRefresh();
  325. }, 1000);
  326. }
  327. }
  328. </script>
  329. <style lang="less">
  330. .timeandtype {
  331. // background-color: #F6F6FB;
  332. // padding: 20rpx;
  333. box-sizing: border-box;
  334. width: 90%;
  335. margin: 40rpx auto 0;
  336. .timebox {
  337. box-shadow: 0 0 10rpx #bcb9ca;
  338. display: flex;
  339. background-color: #fff;
  340. padding: 10px;
  341. border-top-right-radius: 5px;
  342. border-top-left-radius: 5px;
  343. .jiange {
  344. width: 5%;
  345. text-align: center;
  346. }
  347. .firsttime,
  348. .endtime {
  349. width: 45%;
  350. text-align: center;
  351. }
  352. }
  353. .warntypebox {
  354. display: flex;
  355. justify-content: space-between;
  356. background-color: #fff;
  357. padding: 10px;
  358. border-top: 1px solid #F6F6FB;
  359. border-bottom-right-radius: 5px;
  360. border-bottom-left-radius: 5px;
  361. }
  362. }
  363. .shuju_one,
  364. .shuju_two {
  365. // position: absolute;
  366. // top: 100px;
  367. // width: 90%;
  368. // left: 5%;
  369. width: 90%;
  370. margin: 40rpx auto;
  371. box-shadow: 0 0 10rpx #bcb9ca;
  372. padding-top: 20rpx;
  373. height: 550rpx;
  374. .canvastishi {
  375. font-size: 32rpx;
  376. position: absolute;
  377. top: 50%;
  378. left: 50%;
  379. margin-left: -64rpx;
  380. margin-top: -21rpx;
  381. .dataloading:after {
  382. overflow: hidden;
  383. display: inline-block;
  384. vertical-align: bottom;
  385. animation: ellipsis 2s infinite;
  386. content: "\2026";
  387. }
  388. @keyframes ellipsis {
  389. from {
  390. width: 2px;
  391. }
  392. to {
  393. width: 15px;
  394. }
  395. }
  396. }
  397. .shuju_one_title {
  398. width: 70%;
  399. margin: 0 auto;
  400. display: flex;
  401. .tltle_text {
  402. width: 25%;
  403. border: 2rpx solid #B2B2B2;
  404. color: #57c878;
  405. text-align: center;
  406. font-size: 24rpx;
  407. height: 50rpx;
  408. line-height: 50rpx;
  409. }
  410. .title_text_color {
  411. width: 25%;
  412. border: 2rpx solid #57c878;
  413. background-color: #57c878;
  414. color: #fff;
  415. text-align: center;
  416. font-size: 24rpx;
  417. height: 50rpx;
  418. line-height: 50rpx;
  419. }
  420. }
  421. }
  422. .refresh {
  423. width: 90%;
  424. // margin: 40rpx auto;
  425. margin-left: 5%;
  426. width: 160rpx;
  427. height: 50rpx;
  428. background-color: #57c878;
  429. color: #FFFFFF;
  430. line-height: 50rpx;
  431. text-align: center;
  432. }
  433. .condition {
  434. width: 90%;
  435. margin: 40rpx auto;
  436. display: flex;
  437. flex-wrap: wrap;
  438. width: 90%;
  439. box-shadow: 0 0 10rpx #bcb9ca;
  440. margin-bottom: 30rpx;
  441. .scroll-X {
  442. width: 95%;
  443. margin: 20rpx auto;
  444. .table {
  445. width: 1042px;
  446. }
  447. .tr {
  448. display: flex;
  449. overflow: hidden;
  450. .th,
  451. .td {
  452. display: inline-block;
  453. padding: 5rpx;
  454. width: 240rpx;
  455. text-align: center;
  456. height: 52rpx;
  457. line-height: 52rpx;
  458. }
  459. .th:first-child,
  460. .td:first-child {
  461. width: 300rpx;
  462. }
  463. }
  464. .tr:nth-child(2n-1) {
  465. background-color: #f5fff8;
  466. }
  467. .tr:first-child {
  468. background-color: #57c878;
  469. color: #fff;
  470. }
  471. }
  472. .pagenumber {
  473. display: flex;
  474. margin: 20rpx auto;
  475. button {
  476. width: 150rpx;
  477. height: 50rpx;
  478. line-height: 50rpx;
  479. font-size: 26rpx;
  480. text-align: center;
  481. background-color: #57c878;
  482. color: #FFFFFF;
  483. }
  484. .pagenumber_page {
  485. width: 100rpx;
  486. height: 50rpx;
  487. line-height: 50rpx;
  488. font-size: 26rpx;
  489. text-align: center;
  490. }
  491. }
  492. }
  493. /deep/.u-calendar__action {
  494. display: flex;
  495. justify-content: space-around;
  496. .u-calendar__action__text {
  497. line-height: 25px;
  498. }
  499. }
  500. </style>