gshistory.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  5. <view style="position: fixed;z-index: 10000000;width: 100%;background-color: #000000;">
  6. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="历史数据"></uni-nav-bar>
  7. </view>
  8. </view>
  9. <view class="" style="position: relative;top: 100px;">
  10. <view class="selecttimes" @click="tiemshow=!tiemshow">
  11. <view class="timesbox">
  12. <image
  13. :src="'https://www.hnyfwlw.com:8006/bigdata_app/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'"
  14. mode=""></image>
  15. <p>{{timetab(begintime)}}</p>
  16. <p class="or">~</p>
  17. <p>{{timetab(end)}}</p>
  18. <u-icon name="rili" custom-prefix="custom-icon" class="icon"></u-icon>
  19. </view>
  20. <u-calendar v-model="tiemshow" mode="range" @change="tiemchange"></u-calendar>
  21. </view>
  22. <view class="shuju_one">
  23. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  24. 暂无数据
  25. </view>
  26. <view class="canvastishi" v-if="dataloadingtf">
  27. <p class="dataloading">加载中</p>
  28. </view>
  29. <canvas v-show="!tiemshow" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  30. @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)" disable-scroll=true
  31. :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>
  32. </view>
  33. <view class="condition">
  34. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  35. <table class="table" :style="{width:300*thdata.length+'rpx'}">
  36. <tr class="tr">
  37. <th class="th" v-for="(item,index) in thdata" :key="'a'+index">{{item}}</th>
  38. </tr>
  39. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  40. <td class="td">{{items.uptime|timeFormat()}}</td>
  41. <td class="td">{{items.ats}}</td>
  42. <td class="td">{{items.at}}</td>
  43. <td class="td" v-for="(item,index) in items.temp" :key="'c'+index">{{item}}</td>
  44. <td class="td" v-for="(item,index) in items.swc" :key="'d'+index">{{item}}</td>
  45. <td class="td">{{items.atm}}</td>
  46. </tr>
  47. <tr class="tr" v-if="forbidden">
  48. <td class="td" v-for="item in 13">暂无数据</td>
  49. </tr>
  50. </table>
  51. </scroll-view>
  52. <view class="pagenumber">
  53. <button @click="prev">上一页</button>
  54. <view class="pagenumber_page">
  55. 第 {{page}} 页
  56. </view>
  57. <view class="pagenumber_page">
  58. 共 {{pagesum}} 页
  59. </view>
  60. <button @click="next">下一页</button>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </template>
  66. <script>
  67. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  68. var canvaColumnA = null;
  69. export default {
  70. data() {
  71. return {
  72. tiemshow: false, //时间筛选弹框
  73. begintime: "", //开始时间
  74. end: "", //结束时间
  75. dataloadingtf: true,
  76. canvastishiTF: false,
  77. device_id: '', //设备ID
  78. thdata: ["上传时间", "空气湿度(%RH)", "空气温度(℃)", "10cm土壤温度(%RH)", "20cm土壤温度(%RH)", "30cm土壤温度(%RH)", "10cm土壤湿度(%RH)", "20cm土壤湿度(%RH)", "30cm土壤湿度(%RH)",
  79. "大气压强(Pa)"
  80. ], //表格抬头
  81. forbidden: false,
  82. historylistdata: [], //历史数据
  83. pagesum: 1,
  84. page: 1,
  85. cWidth: '',
  86. cHeight: '',
  87. pixelRatio: 1,
  88. }
  89. },
  90. methods: {
  91. tiemchange(e) { //切换时间
  92. this.begintime = parseInt(+new Date(e.startDate) / 1000)
  93. this.end = parseInt(+new Date(e.endDate) / 1000)
  94. this.histprydatas()
  95. },
  96. timetab(e) { //时间转换
  97. e = new Date(e * 1000)
  98. var year = e.getFullYear()
  99. var month = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1
  100. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()
  101. var time = year + "/" + month + "/" + day
  102. return time
  103. },
  104. async histprydatas() { //历史数据
  105. this.dataloadingtf = true
  106. const res = await this.$myRequest({
  107. url: '/api/api_gateway?method=weather.weather.nd_data',
  108. data: {
  109. device_id: this.device_id,
  110. page: this.page,
  111. begin: this.begintime,
  112. end: this.end
  113. }
  114. })
  115. this.dataloadingtf = false
  116. console.log(res.nums)
  117. this.pagesum = Math.ceil(res.nums / 10) || 1
  118. this.historylistdata = res.dat_list
  119. for (var i = 0; i < this.historylistdata.length; i++) {
  120. this.historylistdata[i].temp = this.historylistdata[i].temp.split(",")
  121. this.historylistdata[i].swc = this.historylistdata[i].swc.split(",")
  122. this.historylistdata[i].ecs = this.historylistdata[i].ecs.split(",");
  123. }
  124. var arr1 = []
  125. var arr2 = []
  126. var xtitle = []
  127. var obj = [{
  128. name: '空气温度',
  129. data: [],
  130. color: '#00E29D'
  131. }, {
  132. name: '空气湿度',
  133. data: [],
  134. color: '#6CBBFF'
  135. }]
  136. var arr3 = []
  137. var k = 0
  138. for (var i = 0; i < res.dat_char.length; i++) {
  139. var times = new Date(res.dat_char[i].uptime * 1000)
  140. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times
  141. .getMinutes())
  142. arr1.unshift(res.dat_char[i].at == "" ? "0" : res.dat_char[i].at) //空气温度
  143. arr2.unshift(res.dat_char[i].ats == "" ? "0" : res.dat_char[i].ats) //空气湿度
  144. res.dat_char[i].temp = res.dat_char[i].temp.split(",")
  145. res.dat_char[i].swc = res.dat_char[i].swc.split(",")
  146. res.dat_char[i].ecs = res.dat_char[i].ecs.split(",")
  147. for (var j = 0; j < res.dat_char[i].temp.length; j++) {
  148. arr3.unshift(res.dat_char[i].temp[j] == "" ? "0" : res.dat_char[i].temp[j]) //10cm土壤温度
  149. }
  150. this.thdata.length = 1;
  151. res.depth.split(',').forEach((dep, index) => {
  152. this.thdata.push(`${dep}cm土壤温度(℃)`)
  153. res.dat_char[i].temp.forEach((items, indexs) => {
  154. var tempdata = [];
  155. var tempdatas = [];
  156. var ecsarr = [];
  157. tempdata.push(Number(items));
  158. tempdatas.push(Number(res.dat_char[i].swc[indexs]));
  159. if((res.dat_char[i]).ecs[indexs]) {
  160. ecsarr.push(Number(res.dat_char[i].ecs[indexs]));
  161. }
  162. var temparrs = {
  163. name: dep + "cm土壤温度(℃)",
  164. data: tempdata,
  165. };
  166. var temparr = {
  167. name: dep + "cm土壤湿度(%RH)",
  168. data: tempdatas,
  169. };
  170. var ecsparr = {
  171. name: dep + "cm电导率(ms/cm)",
  172. data: ecsarr,
  173. };
  174. obj.push(temparr);
  175. obj.push(temparrs);
  176. if(ecsarr.length > 0) {
  177. obj.push(ecsparr);
  178. }
  179. });
  180. })
  181. res.depth.split(',').forEach((dep, index) => {
  182. this.thdata.push(`${dep}cm土壤湿度(%RH)`)
  183. })
  184. res.depth.split(',').forEach((dep, index) => {
  185. this.thdata.push(`${dep}cm电导率(ms/cm)`)
  186. })
  187. }
  188. obj[0].data = arr1
  189. obj[1].data = arr2
  190. var listArr = [];
  191. obj.forEach(function(el, index) {
  192. for (var i = 0; i < listArr.length; i++) {
  193. // 对比相同的字段key,相同放入对应的数组中
  194. if (listArr[i].name == el.name && el.data !== undefined) {
  195. listArr[i].data.unshift(el.data[0]);
  196. return;
  197. }
  198. }
  199. // 第一次对比没有参照,放入参照
  200. listArr.push({
  201. name: el.name,
  202. data: el.data,
  203. });
  204. });
  205. console.log(listArr)
  206. if(listArr.length==0){
  207. this.canvastishiTF = false
  208. }else{
  209. this.canvastishiTF = true
  210. }
  211. this.showColumn("canvasColumnA", xtitle, listArr)
  212. // console.log(this.historylistdata)
  213. },
  214. prev() { //上一页
  215. if (this.page > 1) {
  216. this.page--
  217. this.histprydatas()
  218. }
  219. },
  220. next() { //下一页
  221. if (this.page < this.pagesum) {
  222. this.page++
  223. this.histprydatas()
  224. }
  225. },
  226. clickLeft() {
  227. uni.navigateBack({
  228. delta: 1
  229. })
  230. },
  231. showColumn(id, xtitle, xinfo) {
  232. var _self = this
  233. const ctx = uni.createCanvasContext(id, this);
  234. canvaColumnA = new uCharts({
  235. context: ctx,
  236. type: 'line',
  237. legend: {
  238. position: "top"
  239. },
  240. fontSize: 11,
  241. background: '#FFFFFF',
  242. pixelRatio: 1,
  243. animation: true,
  244. dataLabel: false,
  245. categories: xtitle,
  246. series: xinfo,
  247. enableScroll: true, //开启图表拖拽功能
  248. xAxis: {
  249. disableGrid: true,
  250. type: 'grid',
  251. gridType: 'dash',
  252. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  253. scrollShow: true, //新增是否显示滚动条,默认false
  254. // scrollAlign: 'left', //滚动条初始位置
  255. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  256. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  257. },
  258. yAxis: {},
  259. width: _self.cWidth * 1,
  260. height: _self.cHeight * 1,
  261. extra: {
  262. line: {
  263. type: 'curve'
  264. }
  265. }
  266. });
  267. },
  268. touchLineA(e) {
  269. console.log(e)
  270. canvaColumnA.scrollStart(e);
  271. },
  272. moveLineA(e) {
  273. canvaColumnA.scroll(e);
  274. },
  275. touchEndLineA(e) {
  276. canvaColumnA.scrollEnd(e);
  277. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  278. canvaColumnA.showToolTip(e, {
  279. format: function(item, category) {
  280. return category + ' ' + item.name + ':' + item.data
  281. }
  282. });
  283. },
  284. },
  285. onLoad(option) {
  286. this.cWidth = uni.upx2px(650);
  287. this.cHeight = uni.upx2px(500);
  288. this.device_id = option.id
  289. this.end = parseInt(+new Date() / 1000)
  290. this.begintime = parseInt(this.end - 24 * 60 * 60)
  291. this.histprydatas()
  292. }
  293. }
  294. </script>
  295. <style lang="scss">
  296. .selecttimes {
  297. width: 90%;
  298. box-shadow: 0 0 10rpx #bcb9ca;
  299. padding: 10rpx 20rpx;
  300. box-sizing: border-box;
  301. margin: 0 auto;
  302. font-size: 28rpx;
  303. .timesbox {
  304. display: flex;
  305. justify-content: space-around;
  306. image {
  307. width: 30rpx;
  308. height: 30rpx;
  309. margin-top: 6rpx;
  310. }
  311. .icon {
  312. color: #949494;
  313. text-align: right;
  314. margin-left: 30rpx;
  315. }
  316. }
  317. /deep/.u-calendar__action {
  318. display: flex;
  319. justify-content: space-around;
  320. .u-calendar__action__text {
  321. line-height: 25px;
  322. }
  323. }
  324. }
  325. .shuju_one {
  326. width: 90%;
  327. left: 5%;
  328. box-shadow: 0 0 10rpx #bcb9ca;
  329. padding-top: 20rpx;
  330. height: 550rpx;
  331. margin: 20rpx auto;
  332. .canvastishi {
  333. font-size: 32rpx;
  334. position: absolute;
  335. top: 50%;
  336. left: 50%;
  337. margin-left: -64rpx;
  338. margin-top: -21rpx;
  339. .dataloading:after {
  340. overflow: hidden;
  341. display: inline-block;
  342. vertical-align: bottom;
  343. animation: ellipsis 2s infinite;
  344. content: "\2026";
  345. }
  346. @keyframes ellipsis {
  347. from {
  348. width: 2px;
  349. }
  350. to {
  351. width: 15px;
  352. }
  353. }
  354. }
  355. }
  356. .condition {
  357. display: flex;
  358. flex-wrap: wrap;
  359. width: 90%;
  360. left: 5%;
  361. box-shadow: 0 0 10rpx #bcb9ca;
  362. margin-bottom: 30rpx;
  363. margin: 20rpx auto;
  364. .scroll-X {
  365. width: 95%;
  366. margin: 20rpx auto;
  367. .tr {
  368. display: flex;
  369. overflow: hidden;
  370. .th,
  371. .td {
  372. display: inline-block;
  373. padding: 5rpx;
  374. width: 300rpx;
  375. text-align: center;
  376. height: 52rpx;
  377. line-height: 52rpx;
  378. border: 2rpx solid #F1F1F1;
  379. }
  380. }
  381. .tr:nth-child(2n-1) {
  382. background-color: #f5fff8;
  383. }
  384. .tr:first-child {
  385. background-color: #57c878;
  386. color: #fff;
  387. }
  388. }
  389. .pagenumber {
  390. display: flex;
  391. margin: 20rpx auto;
  392. button {
  393. width: 150rpx;
  394. height: 50rpx;
  395. line-height: 50rpx;
  396. font-size: 26rpx;
  397. text-align: center;
  398. background-color: #57c878;
  399. color: #FFFFFF;
  400. }
  401. .pagenumber_page {
  402. width: 100rpx;
  403. height: 50rpx;
  404. line-height: 50rpx;
  405. font-size: 26rpx;
  406. text-align: center;
  407. }
  408. }
  409. }
  410. </style>