historydatas.vue 12 KB

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