history.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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. this.historydata(option.device_id)
  311. this.listhistorydata(option.device_id)
  312. }
  313. }
  314. </script>
  315. <style lang="scss">
  316. .graph {
  317. position: absolute;
  318. top: 54px;
  319. width: 90%;
  320. left: 5%;
  321. .canvasbox {
  322. width: 100%;
  323. height: 550rpx;
  324. position: relative;
  325. box-shadow: 0 0 10rpx #bcb9ca;
  326. padding-top: 20px;
  327. .charts{
  328. }
  329. .canvastishi {
  330. font-size: 32rpx;
  331. position: absolute;
  332. top: 50%;
  333. left: 50%;
  334. margin-left: -64rpx;
  335. margin-top: -21rpx;
  336. }
  337. .schedule {
  338. display: flex;
  339. width: 280rpx;
  340. height: 50rpx;
  341. border: 2rpx solid #F0F0F0;
  342. margin-right: 40rpx;
  343. .schedule_value {
  344. width: 70%;
  345. text-align: center;
  346. line-height: 50rpx;
  347. font-size: 24rpx;
  348. }
  349. .schedule_icon {
  350. width: 30%;
  351. background-color: #F2F2F2;
  352. text-align: center;
  353. line-height: 50rpx;
  354. }
  355. }
  356. }
  357. .none_hint {
  358. font-size: 32rpx;
  359. font-weight: 700;
  360. position: absolute;
  361. top: 0;
  362. left: 50%;
  363. margin-left: -64rpx;
  364. }
  365. }
  366. .shuju_one_title {
  367. width: 70%;
  368. margin: 0 auto;
  369. display: flex;
  370. .tltle_text {
  371. width: 25%;
  372. border: 2rpx solid #B2B2B2;
  373. color: #B2B2B2;
  374. text-align: center;
  375. font-size: 24rpx;
  376. height: 50rpx;
  377. line-height: 50rpx;
  378. }
  379. .title_text_color {
  380. width: 25%;
  381. border: 2rpx solid #28AE4F;
  382. color: #28AE4F;
  383. text-align: center;
  384. font-size: 24rpx;
  385. height: 50rpx;
  386. line-height: 50rpx;
  387. }
  388. }
  389. .selecttimes {
  390. width: 100%;
  391. box-shadow: 0 0 10rpx #bcb9ca;
  392. margin-top: 20rpx;
  393. .tishi {
  394. width: 90%;
  395. margin: 0 auto;
  396. color: #f00000;
  397. text-align: center;
  398. font-size: 24rpx;
  399. }
  400. .btnser {
  401. width: 90%;
  402. margin: 10rpx auto;
  403. color: #FFFFFF;
  404. text-align: center;
  405. font-size: 28rpx;
  406. background-color: #58BD4D;
  407. border-radius: 20rpx;
  408. height: 50rpx;
  409. line-height: 50rpx;
  410. }
  411. .newtimes {
  412. width: 100%;
  413. padding: 20rpx 20rpx;
  414. box-sizing: border-box;
  415. .newtimes_state,
  416. .newtimes_end {
  417. display: flex;
  418. justify-content: space-between;
  419. margin-bottom: 20rpx;
  420. .oldtimes_left {
  421. position: relative;
  422. padding-left: 36rpx;
  423. font-size: 28rpx;
  424. image {
  425. width: 30rpx;
  426. height: 30rpx;
  427. vertical-align: top;
  428. position: absolute;
  429. top: 7rpx;
  430. left: 0;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. .condition {
  437. display: flex;
  438. flex-wrap: wrap;
  439. width: 100%;
  440. box-shadow: 0 0 10rpx #bcb9ca;
  441. margin: 30rpx 0;
  442. .scroll-X {
  443. width: 95%;
  444. margin: 20rpx auto;
  445. .table{
  446. // width: 10420px;
  447. }
  448. .tr {
  449. display: flex;
  450. overflow: hidden;
  451. .th,
  452. .td {
  453. display: inline-block;
  454. padding: 5rpx;
  455. width: 240rpx;
  456. text-align: center;
  457. height: 52rpx;
  458. line-height: 52rpx;
  459. border: 2rpx solid #F1F1F1;
  460. }
  461. .th:first-child,
  462. .td:first-child {
  463. width: 300rpx;
  464. }
  465. }
  466. }
  467. .pagenumber {
  468. display: flex;
  469. margin: 20rpx auto;
  470. button {
  471. width: 150rpx;
  472. height: 50rpx;
  473. line-height: 50rpx;
  474. font-size: 26rpx;
  475. text-align: center;
  476. background-color: #17BB89;
  477. color: #FFFFFF;
  478. }
  479. .pagenumber_page {
  480. width: 150rpx;
  481. height: 50rpx;
  482. line-height: 50rpx;
  483. font-size: 26rpx;
  484. text-align: center;
  485. }
  486. }
  487. }
  488. </style>