history.vue 12 KB

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