history.vue 12 KB

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