historydatas.vue 13 KB

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