historydatas.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427
  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: arr1,
  120. color: '#00E29D'
  121. }, {
  122. name: '湿度',
  123. data: arr2,
  124. color: '#6CBBFF'
  125. },{
  126. name: '诱虫次数',
  127. data: arr3,
  128. color: '#ff0000'
  129. }]
  130. this.showColumn("canvasColumnA", xtitle, obj)
  131. })
  132. }
  133. },
  134. async Chistory() { //历史数据列表折线图
  135. const res = await this.$myRequest({
  136. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_line_chart',
  137. data: {
  138. device_id: this.device_id,
  139. strat_time: parseInt(this.start_time / 1000),
  140. end_time: parseInt(this.end_time / 1000),
  141. status: "pest"
  142. }
  143. })
  144. this.worms = res
  145. },
  146. //forecast.worm_lamp.device_history_data历史数据列表
  147. async historylist() { //历史数据列表
  148. const res = await this.$myRequest({
  149. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_history',
  150. data: {
  151. device_id:this.device_id,
  152. strat_time:parseInt(this.start_time / 1000),
  153. end_time:parseInt(this.end_time / 1000),
  154. page: this.page
  155. }
  156. })
  157. this.historylistdata = res.data
  158. console.log(res.data)
  159. this.pagesum = Math.ceil(res.nums / 10) + 1
  160. if (res.data.length == 0) {
  161. this.forbidden = true
  162. } else {
  163. this.forbidden = false
  164. }
  165. console.log(this.historylistdata)
  166. },
  167. // forecast.send_control.get_device_config 获取当前时间的数据
  168. async newdata() {
  169. const res = await this.$myRequest({
  170. url: '/api/api_gateway?method=sex_lure_nl.sex_lure.nl_device_mqtt',
  171. data: {
  172. d_id: this.d_id
  173. }
  174. })
  175. if(res){
  176. uni.showToast({
  177. title: '刷新成功',
  178. duration: 2000,
  179. icon: "none"
  180. });
  181. uni.navigateBack({
  182. delta: 1
  183. })
  184. }else{
  185. uni.showToast({
  186. title: '刷新失败',
  187. duration: 2000,
  188. icon: "none"
  189. });
  190. }
  191. },
  192. refresh() { //获取当前时间的数据
  193. this.newdata()
  194. },
  195. changeindex(index) {
  196. this.titleidnex = index
  197. var now = new Date()
  198. this.$forceUpdate()
  199. if (index == 0) {
  200. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  201. this.history()
  202. this.historylist()
  203. } else if (index == 1) {
  204. var oldtime = now.setMonth(now.getMonth() - 1)
  205. this.start_time = parseInt(oldtime)
  206. this.history()
  207. this.historylist()
  208. } else if (index == 2) {
  209. var oldtime = now.setMonth(now.getMonth() - 6)
  210. this.start_time = parseInt(oldtime)
  211. this.history()
  212. this.historylist()
  213. } else if (index == 3) {
  214. var oldtime = now.setFullYear(now.getFullYear() - 1)
  215. this.start_time = parseInt(oldtime)
  216. this.history()
  217. this.historylist()
  218. }
  219. },
  220. prev() { //上一页
  221. if (this.page > 1) {
  222. this.page--
  223. this.historylist()
  224. }
  225. },
  226. next() { //下一页
  227. this.page++
  228. this.historylist()
  229. },
  230. clickLeft() {
  231. uni.navigateBack({
  232. delta: 1
  233. })
  234. },
  235. showColumn(id, xtitle, xinfo) {
  236. var _self = this
  237. canvaColumnA = new uCharts({
  238. canvasId: id,
  239. type: 'line',
  240. legend: {
  241. position: "top"
  242. },
  243. fontSize: 11,
  244. background: '#FFFFFF',
  245. pixelRatio: 1,
  246. animation: true,
  247. dataLabel: false,
  248. categories: xtitle,
  249. series: xinfo,
  250. enableScroll: true, //开启图表拖拽功能
  251. xAxis: {
  252. disableGrid: true,
  253. type: 'grid',
  254. gridType: 'dash',
  255. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  256. scrollShow: true, //新增是否显示滚动条,默认false
  257. // scrollAlign: 'left', //滚动条初始位置
  258. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  259. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  260. },
  261. yAxis: {},
  262. width: _self.cWidth * 1,
  263. height: _self.cHeight * 1,
  264. extra: {
  265. line: {
  266. type: 'curve'
  267. }
  268. }
  269. });
  270. },
  271. touchLineA(e) {
  272. console.log(e)
  273. canvaColumnA.scrollStart(e);
  274. },
  275. moveLineA(e) {
  276. canvaColumnA.scroll(e);
  277. },
  278. touchEndLineA(e) {
  279. canvaColumnA.scrollEnd(e);
  280. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  281. canvaColumnA.showToolTip(e, {
  282. format: function(item, category) {
  283. return category + ' ' + item.name + ':' + item.data
  284. }
  285. });
  286. },
  287. },
  288. onLoad(option) {
  289. console.log(option)
  290. this.d_id = option.d_id
  291. this.device_id = option.device_id
  292. this.cWidth = uni.upx2px(650);
  293. this.cHeight = uni.upx2px(500);
  294. },
  295. onShow(){
  296. this.end_time = +new Date() + 1000
  297. this.start_time = this.end_time - 24 * 60 * 60 * 1000
  298. console.log(new Date(this.end_time),new Date(this.start_time))
  299. this.history()
  300. this.historylist()
  301. }
  302. }
  303. </script>
  304. <style lang="scss">
  305. .shuju_one,
  306. .shuju_two {
  307. position: absolute;
  308. top: 10px;
  309. width: 90%;
  310. left: 5%;
  311. box-shadow: 0 0 10rpx #bcb9ca;
  312. padding-top: 20rpx;
  313. height: 550rpx;
  314. .canvastishi {
  315. font-size: 32rpx;
  316. position: absolute;
  317. top: 50%;
  318. left: 50%;
  319. margin-left: -64rpx;
  320. margin-top: -21rpx;
  321. }
  322. .shuju_one_title {
  323. width: 70%;
  324. margin: 0 auto;
  325. display: flex;
  326. .tltle_text {
  327. width: 25%;
  328. border: 2rpx solid #B2B2B2;
  329. color: #B2B2B2;
  330. text-align: center;
  331. font-size: 24rpx;
  332. height: 50rpx;
  333. line-height: 50rpx;
  334. }
  335. .title_text_color {
  336. width: 25%;
  337. border: 2rpx solid #28AE4F;
  338. color: #28AE4F;
  339. text-align: center;
  340. font-size: 24rpx;
  341. height: 50rpx;
  342. line-height: 50rpx;
  343. }
  344. }
  345. }
  346. .refresh {
  347. position: absolute;
  348. top: 630rpx;
  349. left: 5%;
  350. width: 160rpx;
  351. height: 50rpx;
  352. background-color: #28AE4F;
  353. color: #FFFFFF;
  354. line-height: 50rpx;
  355. text-align: center;
  356. }
  357. .condition {
  358. position: absolute;
  359. top: 720rpx;
  360. display: flex;
  361. flex-wrap: wrap;
  362. width: 90%;
  363. left: 5%;
  364. box-shadow: 0 0 10rpx #bcb9ca;
  365. margin-bottom: 30rpx;
  366. .scroll-X {
  367. width: 95%;
  368. margin: 20rpx auto;
  369. .table{
  370. width: 1042px;
  371. }
  372. .tr {
  373. display: flex;
  374. overflow: hidden;
  375. .th,
  376. .td {
  377. display: inline-block;
  378. padding: 5rpx;
  379. width: 240rpx;
  380. text-align: center;
  381. height: 52rpx;
  382. line-height: 52rpx;
  383. border: 2rpx solid #F1F1F1;
  384. }
  385. .th:first-child,
  386. .td:first-child {
  387. width: 300rpx;
  388. }
  389. }
  390. }
  391. .pagenumber {
  392. display: flex;
  393. margin: 20rpx auto;
  394. button {
  395. width: 150rpx;
  396. height: 50rpx;
  397. line-height: 50rpx;
  398. font-size: 26rpx;
  399. text-align: center;
  400. background-color: #17BB89;
  401. color: #FFFFFF;
  402. }
  403. .pagenumber_page {
  404. width: 100rpx;
  405. height: 50rpx;
  406. line-height: 50rpx;
  407. font-size: 26rpx;
  408. text-align: center;
  409. }
  410. }
  411. }
  412. </style>