history.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585
  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 class="graph">
  21. <view class="canvasbox">
  22. <view class="" style="display: flex; justify-content: flex-end">
  23. <view class="schedule" @click="pickertfone = !pickertfone">
  24. <p class="schedule_value">{{ titletext[indexone] }}</p>
  25. <p class="schedule_icon">
  26. <u-icon name="arrow-down"></u-icon>
  27. </p>
  28. </view>
  29. </view>
  30. <u-picker
  31. v-model="pickertfone"
  32. mode="selector"
  33. @confirm="confirmFun"
  34. :default-selector="[indexone]"
  35. :range="titletext"
  36. ></u-picker>
  37. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  38. 暂无数据
  39. </view>
  40. <view class="canvastishi" v-if="dataloadingtf">
  41. <p class="dataloading">加载中</p>
  42. </view>
  43. <canvas
  44. v-if="canvastishiTF"
  45. canvas-id="canvasColumnA"
  46. id="canvasColumnA"
  47. class="charts"
  48. @touchstart="touchLineA($event)"
  49. @touchmove="moveLineA($event)"
  50. @touchend="touchEndLineA($event)"
  51. disable-scroll="true"
  52. :style="{
  53. width: cWidth * pixelRatio + 'px',
  54. height: cHeight * pixelRatio + 'px',
  55. transform: 'scale(' + 1 / pixelRatio + ')',
  56. 'margin-left': (-cWidth * (pixelRatio - 1)) / 2 + 'px',
  57. 'margin-top': (-cHeight * (pixelRatio - 1)) / 2 + 'px',
  58. }"
  59. ></canvas>
  60. </view>
  61. <view class="selecttimes" @click="tiemshow = !tiemshow">
  62. <view class="timesbox">
  63. <image
  64. :src="
  65. $imageURL+ '/bigdata_app' +
  66. '/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'
  67. "
  68. mode=""
  69. ></image>
  70. <p>{{ timetab(begintime) }}</p>
  71. <p class="or">~</p>
  72. <p>{{ timetab(end) }}</p>
  73. <u-icon
  74. name="rili"
  75. custom-prefix="custom-icon"
  76. class="icon"
  77. ></u-icon>
  78. </view>
  79. <u-calendar
  80. v-model="tiemshow"
  81. mode="range"
  82. @change="tiemchange"
  83. ></u-calendar>
  84. </view>
  85. <view class="condition" v-if="scrollTF">
  86. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  87. <!-- @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" -->
  88. <table
  89. class="table"
  90. :style="{ width: 300 + 240 * datalength + 'rpx' }"
  91. >
  92. <tr class="tr">
  93. <th class="th">日期</th>
  94. <th
  95. class="th"
  96. v-for="(key, index) in historydatas.conf"
  97. :key="index"
  98. v-show="key"
  99. >
  100. {{ key.replace('#', '(') + ')' }}
  101. </th>
  102. </tr>
  103. <tr
  104. :class="`tr ${
  105. items.is_history && myuser_type == 1 ? 'redText' : ''
  106. }`"
  107. v-for="(items, index) in historydatas.data"
  108. :key="index"
  109. v-if="!forbidden"
  110. >
  111. <td class="td">{{ items.time | timeFormat() }}</td>
  112. <td
  113. class="td"
  114. v-for="(item, indexss) in datalength"
  115. :key="indexss"
  116. >
  117. {{
  118. parseFloat(items.dat['e' + (indexss + 1)]) == -99.99
  119. ? 'N/A'
  120. : parseFloat(items.dat['e' + (indexss + 1)])
  121. }}
  122. </td>
  123. </tr>
  124. <tr class="tr" v-if="forbidden">
  125. <td class="td" v-for="item in 10">暂无数据</td>
  126. </tr>
  127. </table>
  128. </scroll-view>
  129. <view class="pagenumber">
  130. <button @click="prev">上一页</button>
  131. <view class="pagenumber_page"> 第{{ page }}页 </view>
  132. <view class="pagenumber_page"> 共 {{ pagesum }} 页 </view>
  133. <button @click="next" :disabled="forbidden">下一页</button>
  134. </view>
  135. </view>
  136. </view>
  137. </view>
  138. </view>
  139. </template>
  140. <script>
  141. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  142. var canvasColumnA = null;
  143. var presenttime = +new Date();
  144. export default {
  145. data() {
  146. return {
  147. myuser_type: null,
  148. cWidth: '400',
  149. cHeight: '400',
  150. pixelRatio: 1,
  151. canvastishiTF: false, //暂无数据提示
  152. dataloadingtf: true, //加载中提示
  153. id: '',
  154. begintime: '', //开始时间
  155. end: '', //结束时间
  156. titletext: [], //折线图数据切换列表数据
  157. titleidnex: 0,
  158. historydatas: [],
  159. page: 1,
  160. forbidden: false,
  161. pagesum: 1,
  162. datalength: 0,
  163. scrollTF: true,
  164. indexone: 0, //折线图数据切换列表下标
  165. pickertfone: false, //折线图数据切换列表
  166. chartdata: {}, //折线图数据
  167. tiemshow: false, //日期选择
  168. };
  169. },
  170. methods: {
  171. //weather.weather.qxz_detail
  172. async listhistorydata(datas) {
  173. //历史记录表格信息
  174. const res = await this.$myRequest({
  175. url: '/api/api_gateway?method=weather.weather.qxz_detail',
  176. data: {
  177. device_id: datas,
  178. start_time: parseInt(this.begintime),
  179. end_time: parseInt(this.end),
  180. page: this.page,
  181. },
  182. });
  183. this.historydatas = res;
  184. console.log(res);
  185. this.datalength = 0;
  186. for (var key in res.conf) {
  187. if (key && res.conf[key] != '') {
  188. this.datalength++;
  189. }
  190. }
  191. console.log(this.datalength);
  192. if (this.datalength == 0) {
  193. this.scrollTF = false;
  194. } else {
  195. this.scrollTF = true;
  196. }
  197. this.pagesum = Math.ceil(res.nums / 10) || 1;
  198. if (res.data.length == 0) {
  199. this.forbidden = true;
  200. } else {
  201. this.forbidden = false;
  202. }
  203. },
  204. async historydata(datas) {
  205. //上传时间 //折线图
  206. this.dataloadingtf = true;
  207. const res = await this.$myRequest({
  208. url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
  209. data: {
  210. device_id: datas,
  211. begin: parseInt(this.begintime),
  212. end: parseInt(this.end),
  213. },
  214. });
  215. this.dataloadingtf = false;
  216. console.log(res);
  217. this.chartdata = res;
  218. this.titletext = [];
  219. if (res.data.length == 0) {
  220. this.canvastishiTF = false;
  221. } else {
  222. this.canvastishiTF = true;
  223. for (var key in res.conf) {
  224. if (res.conf[key]) {
  225. this.titletext.push(res.conf[key]);
  226. }
  227. }
  228. this.conflist(res, 'e1');
  229. }
  230. console.log(this.titletext);
  231. },
  232. conflist(res, eindex) {
  233. var xtitle = [];
  234. var linearr = [];
  235. for (var i = 0; i < res.data.length; i++) {
  236. var times = new Date(res.data[i].time * 1000);
  237. xtitle.unshift(
  238. times.getMonth() +
  239. 1 +
  240. '/' +
  241. times.getDate() +
  242. '-' +
  243. times.getHours() +
  244. ':' +
  245. times.getMinutes()
  246. );
  247. }
  248. var obj = {};
  249. obj.name = res.conf[eindex];
  250. var arr = [];
  251. for (var i = 0; i < res.data.length; i++) {
  252. if (parseFloat(res.data[i].dat[0][eindex].split('#')[0]) != -99.99) {
  253. arr.unshift(parseFloat(res.data[i].dat[0][eindex].split('#')[0]));
  254. }
  255. }
  256. obj.data = arr;
  257. if (obj.name) {
  258. linearr.push(obj);
  259. }
  260. this.canvastishiTF = linearr.some((item) => {
  261. return item.data.length != 0;
  262. });
  263. console.log(obj);
  264. this.showColumn('canvasColumnA', xtitle, linearr);
  265. },
  266. confirmFun(index) {
  267. console.log(index);
  268. this.indexone = index[0];
  269. var str = 'e' + (index[0] + 1);
  270. console.log(str);
  271. this.conflist(this.chartdata, str);
  272. },
  273. tiemchange(e) {
  274. console.log(e);
  275. this.begintime = +new Date(e.startDate) / 1000;
  276. this.end = +new Date(e.endDate) / 1000 + 16 * 60 * 60;
  277. this.historydata(this.id);
  278. this.listhistorydata(this.id);
  279. },
  280. prev() {
  281. //上一页
  282. if (this.page > 1) {
  283. this.page--;
  284. this.listhistorydata(this.id);
  285. }
  286. },
  287. next() {
  288. //下一页
  289. if (this.page < this.pagesum) {
  290. this.page++;
  291. this.listhistorydata(this.id);
  292. }
  293. },
  294. clickLeft() {
  295. uni.navigateBack({
  296. delta: 1,
  297. });
  298. },
  299. showColumn(id, xtitle, xinfo) {
  300. var _self = this;
  301. const ctx = uni.createCanvasContext(id, this);
  302. canvasColumnA = new uCharts({
  303. context: ctx,
  304. type: 'line',
  305. legend: {
  306. position: 'top',
  307. },
  308. fontSize: 11,
  309. background: '#FFFFFF',
  310. pixelRatio: 1,
  311. animation: true,
  312. dataLabel: false,
  313. categories: xtitle,
  314. series: xinfo,
  315. enableScroll: true, //开启图表拖拽功能
  316. xAxis: {
  317. disableGrid: true,
  318. type: 'grid',
  319. gridType: 'dash',
  320. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  321. scrollShow: true, //新增是否显示滚动条,默认false
  322. // scrollAlign: 'left', //滚动条初始位置
  323. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  324. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  325. },
  326. yAxis: {},
  327. width: _self.cWidth * 1,
  328. height: _self.cHeight * 1,
  329. extra: {
  330. line: {
  331. type: 'curve',
  332. },
  333. },
  334. });
  335. },
  336. touchLineA(e) {
  337. canvasColumnA.scrollStart(e);
  338. },
  339. moveLineA(e) {
  340. canvasColumnA.scroll(e);
  341. },
  342. touchEndLineA(e) {
  343. canvasColumnA.scrollEnd(e);
  344. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  345. canvasColumnA.showToolTip(e, {
  346. format: function (item, category) {
  347. return category + ' ' + item.name + ':' + item.data;
  348. },
  349. });
  350. },
  351. timetab(e) {
  352. e = new Date(e * 1000);
  353. var year = e.getFullYear();
  354. var month =
  355. e.getMonth() + 1 < 10 ? '0' + (e.getMonth() + 1) : e.getMonth() + 1;
  356. var day = e.getDate() < 10 ? '0' + e.getDate() : e.getDate();
  357. var time = year + '/' + month + '/' + day;
  358. return time;
  359. },
  360. },
  361. onLoad(option) {
  362. this.cWidth = uni.upx2px(650);
  363. this.cHeight = uni.upx2px(500);
  364. this.id = option.device_id;
  365. this.end = presenttime / 1000;
  366. this.begintime = presenttime / 1000 - 24 * 60 * 60;
  367. console.log(new Date(1616145097 * 1000), new Date(1616231497 * 1000));
  368. this.historydata(option.device_id);
  369. this.listhistorydata(option.device_id);
  370. this.myuser_type = uni.getStorageSync('myuser_type');
  371. },
  372. };
  373. </script>
  374. <style lang="scss">
  375. .graph {
  376. position: absolute;
  377. top: 54px;
  378. width: 90%;
  379. left: 5%;
  380. .canvasbox {
  381. width: 100%;
  382. height: 550rpx;
  383. position: relative;
  384. box-shadow: 0 0 10rpx #bcb9ca;
  385. padding-top: 20px;
  386. .charts {
  387. }
  388. .canvastishi {
  389. font-size: 32rpx;
  390. position: absolute;
  391. top: 50%;
  392. left: 50%;
  393. margin-left: -64rpx;
  394. margin-top: -21rpx;
  395. .dataloading:after {
  396. overflow: hidden;
  397. display: inline-block;
  398. vertical-align: bottom;
  399. animation: ellipsis 2s infinite;
  400. content: '\2026';
  401. }
  402. @keyframes ellipsis {
  403. from {
  404. width: 2px;
  405. }
  406. to {
  407. width: 15px;
  408. }
  409. }
  410. }
  411. .schedule {
  412. display: flex;
  413. width: 280rpx;
  414. height: 50rpx;
  415. border: 2rpx solid #f0f0f0;
  416. margin-right: 40rpx;
  417. .schedule_value {
  418. width: 70%;
  419. text-align: center;
  420. line-height: 50rpx;
  421. font-size: 24rpx;
  422. }
  423. .schedule_icon {
  424. width: 30%;
  425. background-color: #f2f2f2;
  426. text-align: center;
  427. line-height: 50rpx;
  428. }
  429. }
  430. }
  431. .none_hint {
  432. font-size: 32rpx;
  433. font-weight: 700;
  434. position: absolute;
  435. top: 0;
  436. left: 50%;
  437. margin-left: -64rpx;
  438. }
  439. }
  440. .shuju_one_title {
  441. width: 70%;
  442. margin: 0 auto;
  443. display: flex;
  444. .tltle_text {
  445. width: 25%;
  446. border: 2rpx solid #b2b2b2;
  447. color: #57c878;
  448. text-align: center;
  449. font-size: 24rpx;
  450. height: 50rpx;
  451. line-height: 50rpx;
  452. }
  453. .title_text_color {
  454. width: 25%;
  455. border: 2rpx solid #57c878;
  456. color: #fff;
  457. text-align: center;
  458. font-size: 24rpx;
  459. height: 50rpx;
  460. line-height: 50rpx;
  461. }
  462. }
  463. .selecttimes {
  464. width: 100%;
  465. box-shadow: 0 0 10rpx #bcb9ca;
  466. margin-top: 20rpx;
  467. padding: 10rpx 20rpx;
  468. box-sizing: border-box;
  469. .timesbox {
  470. display: flex;
  471. justify-content: space-around;
  472. image {
  473. width: 30rpx;
  474. height: 30rpx;
  475. margin-top: 6rpx;
  476. }
  477. .icon {
  478. color: #949494;
  479. text-align: right;
  480. margin-left: 30rpx;
  481. }
  482. }
  483. }
  484. .condition {
  485. display: flex;
  486. flex-wrap: wrap;
  487. width: 100%;
  488. box-shadow: 0 0 10rpx #bcb9ca;
  489. margin: 30rpx 0;
  490. .scroll-X {
  491. width: 95%;
  492. margin: 20rpx auto;
  493. .table {
  494. // width: 10420px;
  495. }
  496. .tr {
  497. display: flex;
  498. overflow: hidden;
  499. .th,
  500. .td {
  501. display: inline-block;
  502. padding: 5rpx;
  503. width: 240rpx;
  504. text-align: center;
  505. height: 52rpx;
  506. line-height: 52rpx;
  507. }
  508. .th:first-child,
  509. .td:first-child {
  510. width: 300rpx;
  511. }
  512. }
  513. .redText {
  514. .td {
  515. color: #dc143c;
  516. }
  517. }
  518. .tr:nth-child(2n-1) {
  519. background-color: #f5fff8;
  520. }
  521. .tr:first-child {
  522. background-color: #57c878;
  523. color: #fff;
  524. }
  525. }
  526. .pagenumber {
  527. display: flex;
  528. margin: 20rpx auto;
  529. button {
  530. width: 150rpx;
  531. height: 50rpx;
  532. line-height: 50rpx;
  533. font-size: 26rpx;
  534. text-align: center;
  535. background-color: #57c878;
  536. color: #ffffff;
  537. }
  538. .pagenumber_page {
  539. width: 150rpx;
  540. height: 50rpx;
  541. line-height: 50rpx;
  542. font-size: 26rpx;
  543. text-align: center;
  544. }
  545. }
  546. }
  547. ::v-deep .u-calendar__action {
  548. display: flex;
  549. justify-content: space-around;
  550. .u-calendar__action__text {
  551. line-height: 25px;
  552. }
  553. }
  554. </style>