history.vue 13 KB

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