history.vue 12 KB

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