gshistory.vue 11 KB

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