gshistory.vue 12 KB

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