history.vue 12 KB

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