gshistory.vue 14 KB

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