historydatas.vue 11 KB

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