gshistory.vue 14 KB

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