newhistoryfile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534
  1. <template>
  2. <view style="background-color: #f7f7f7; height: 100vh;padding-top: 88rpx;">
  3. <!-- <view class="status_bar"></view> -->
  4. <view>
  5. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" title="历史数据" backgroundColor="#f7f7f7"></uni-nav-bar>
  6. </view>
  7. <view style="padding: 0 48rpx; background-color: #f7f7f7;">
  8. <u-calendar v-model="dataShow" :mode="mode" @change="tiemchange" :maxDate="maxDate"></u-calendar>
  9. <view class="date" @click="dataShow = true">
  10. <span>选择日期 </span>
  11. <span style="color: #cccccc;">
  12. {{start_time}} <span style="margin: 0 10rpx;"> /</span> {{end_time}}
  13. <u-icon style="margin-left: 20rpx;" name="arrow-right" size="28"></u-icon>
  14. </span>
  15. </view>
  16. <view class="title">温湿度数据</view>
  17. <view class="shuju_one">
  18. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  19. 暂无数据
  20. </view>
  21. <view class="canvastishi" v-if="dataloadingtf">
  22. <p class="dataloading">加载中</p>
  23. </view>
  24. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  25. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)"
  26. disable-scroll=true
  27. :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>
  28. </view>
  29. <!-- <pest-line
  30. :device_type_id="device_type"
  31. :d_id="d_id"
  32. :start_time="start_time"
  33. :end_time="end_time"
  34. :notify="notify"
  35. ></pest-line> -->
  36. <view class="title">监测数据
  37. <u-button size="mini" :loading='refreshLoading' class="refresh" throttle-time="500" @click="refresh"
  38. :customStyle="customStyle">刷 新</u-button>
  39. </view>
  40. <view class="condition">
  41. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  42. <table class="table" :style="tableStyle">
  43. <tr class="tr">
  44. <th style="background-color: #E6E8EB;" class="th" v-for="(value,key) in thdata" :key="key">
  45. {{value}}</th>
  46. </tr>
  47. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  48. <td class="td" v-for="(value,key) in thdata">{{items[key]}}</td>
  49. </tr>
  50. <tr class="tr" v-if="forbidden">
  51. <td class="td" v-for="item in Object.keys(thdata)">暂无数据</td>
  52. </tr>
  53. </table>
  54. </scroll-view>
  55. <view class="pagenumber">
  56. <button @click="prev">上一页</button>
  57. <view class="pagenumber_page">
  58. 第 {{page}} 页
  59. </view>
  60. <view class="pagenumber_page">
  61. 共 {{pagesum}} 页
  62. </view>
  63. <button @click="next" :disabled="forbidden">下一页</button>
  64. </view>
  65. </view>
  66. </view>
  67. </view>
  68. </view>
  69. </template>
  70. <script>
  71. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  72. import pestLine from './pestLine.vue';
  73. var canvaColumnA = null;
  74. export default {
  75. data() {
  76. return {
  77. maxDate: '2050-12-31',
  78. styles: {
  79. // width: "650rpx",
  80. height: "400rpx"
  81. },
  82. d_id: '',
  83. start_time: "",
  84. end_time: "",
  85. historydatas: [],
  86. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  87. titleidnex: 0,
  88. device_id: '',
  89. page: 1,
  90. historylistdata: [],
  91. thdata: {},
  92. forbidden: false,
  93. cWidth: '400',
  94. cHeight: '400',
  95. pixelRatio: 1,
  96. canvastishiTF: false, //暂无数据提示
  97. dataloadingtf: true, //加载中提示
  98. pagesum: 1,
  99. device_type: "",
  100. dataShow: false,
  101. mode: 'range',
  102. refreshLoading: false,
  103. notify: 0
  104. }
  105. },
  106. components: {
  107. pestLine
  108. },
  109. computed: {
  110. customStyle() {
  111. return {
  112. background: '#018B3F',
  113. fontSize: '12px',
  114. border: 'none',
  115. color: '#fff'
  116. }
  117. },
  118. tableStyle() {
  119. return {
  120. width: Object.keys(this.thdata).length * 150 + 'px'
  121. }
  122. }
  123. },
  124. methods: {
  125. tiemchange(e) {
  126. console.log(e)
  127. this.start_time = e.startDate
  128. this.end_time = e.endDate
  129. this.history()
  130. this.historylist()
  131. this.notify++
  132. },
  133. async history() { //历史数据列表折线图
  134. this.dataloadingtf = true
  135. const res = await this.$myRequest({
  136. url: '/api/api_gateway?method=new_gateway.data_info.temp_hum',
  137. data: {
  138. device_type_id: this.device_type,
  139. id: this.d_id,
  140. start: +new Date(this.start_time + ' 00:00:00') / 1000,
  141. end: +new Date(this.end_time + ' 23:59:59') / 1000
  142. }
  143. })
  144. this.dataloadingtf = false
  145. let {
  146. data,
  147. title
  148. } = res
  149. if (!data) {
  150. this.canvastishiTF = false
  151. } else {
  152. this.canvastishiTF = true
  153. if (title.addtime) delete title.addtime
  154. let xtitle = []
  155. let chartData = []
  156. if (data.length > 0) {
  157. data.forEach(item => {
  158. // 处理时间戳
  159. xtitle.push(item.addtime.split(' ')[0])
  160. })
  161. Object.keys(title).forEach(key => {
  162. let obj = {
  163. name: title[key],
  164. index: key === 'lux' ? 1 : 0,
  165. data: []
  166. }
  167. for (var i = 0; i < data.length; i++) {
  168. if (key in data[i]) {
  169. // 判断data中是否值
  170. obj.data.push(data[i][key])
  171. }
  172. }
  173. chartData.push(obj)
  174. })
  175. console.log('温湿度数据:', chartData)
  176. }
  177. let yAxis = {
  178. data: [{
  179. position: 'left'
  180. }, {
  181. position: 'right'
  182. }]
  183. }
  184. // console.log('----温度:',obj)
  185. this.showColumn("canvasColumnA", xtitle, chartData, yAxis)
  186. }
  187. },
  188. //历史数据列表
  189. async historylist() {
  190. const res = await this.$myRequest({
  191. url: '/api/api_gateway?method=new_gateway.data_info.history_data',
  192. data: {
  193. device_type_id: this.device_type,
  194. id: this.d_id,
  195. start: +new Date(this.start_time + ' 00:00:00') / 1000,
  196. end: +new Date(this.end_time + ' 23:59:59') / 1000,
  197. page: this.page
  198. }
  199. })
  200. this.refreshLoading = false
  201. // this.thdata = Object.values(res.title)
  202. Object.keys(res.title).forEach(item => {
  203. this.$set(this.thdata, item, res.title[item])
  204. })
  205. this.historylistdata = res.data
  206. this.pagesum = Math.ceil(res.total / 10) || 1
  207. if (res.data.length == 0) {
  208. this.forbidden = true
  209. } else {
  210. this.forbidden = false
  211. }
  212. console.log(this.historylistdata, 'historylistdata')
  213. },
  214. // forecast.send_control.get_device_config 获取当前时间的数据
  215. async newdata() {
  216. const res = await this.$myRequest({
  217. url: '/api/api_gateway?method=forecast.send_control.get_device_config',
  218. data: {
  219. device_type_id: 3,
  220. d_id: this.d_id,
  221. control_type: "data"
  222. }
  223. })
  224. if (res) {
  225. uni.showToast({
  226. title: '刷新成功',
  227. duration: 2000,
  228. icon: "none"
  229. });
  230. this.historylist()
  231. } else {
  232. uni.showToast({
  233. title: '刷新失败',
  234. duration: 2000,
  235. icon: "none"
  236. });
  237. }
  238. },
  239. refresh() { //获取当前时间的数据
  240. this.refreshLoading = true
  241. this.historylist()
  242. },
  243. prev() { //上一页
  244. if (this.page > 1) {
  245. this.page--
  246. this.historylist()
  247. }
  248. },
  249. next() { //下一页
  250. if (this.page < this.pagesum) {
  251. this.page++
  252. this.historylist()
  253. }
  254. },
  255. clickLeft() {
  256. uni.navigateBack({
  257. delta: 1
  258. })
  259. },
  260. showColumn(id, xtitle, xinfo, yAxis) {
  261. let _self = this
  262. const ctx = uni.createCanvasContext(id, this);
  263. canvaColumnA = new uCharts({
  264. context: ctx,
  265. type: 'line',
  266. legend: {
  267. position: "top"
  268. },
  269. fontSize: 11,
  270. background: '#FFFFFF',
  271. pixelRatio: 1,
  272. animation: true,
  273. dataLabel: false,
  274. categories: xtitle,
  275. series: xinfo,
  276. enableScroll: true, //开启图表拖拽功能
  277. xAxis: {
  278. disableGrid: true,
  279. type: 'grid',
  280. gridType: 'dash',
  281. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  282. scrollShow: true, //新增是否显示滚动条,默认false
  283. // scrollAlign: 'left', //滚动条初始位置
  284. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  285. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  286. },
  287. yAxis: yAxis || {},
  288. width: _self.cWidth * 1,
  289. height: _self.cHeight * 1,
  290. extra: {
  291. line: {
  292. type: 'curve'
  293. }
  294. }
  295. });
  296. },
  297. touchLineA(e) {
  298. console.log(e)
  299. canvaColumnA.scrollStart(e);
  300. },
  301. moveLineA(e) {
  302. canvaColumnA.scroll(e);
  303. },
  304. touchEndLineA(e) {
  305. canvaColumnA.scrollEnd(e);
  306. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  307. canvaColumnA.showToolTip(e, {
  308. format: function(item, category) {
  309. return category + ' ' + item.name + ':' + item.data
  310. }
  311. });
  312. },
  313. },
  314. onLoad(option) {
  315. this.d_id = option.d_id
  316. this.device_id = option.device_id
  317. this.device_type = option.device_type
  318. this.cWidth = uni.upx2px(650);
  319. this.cHeight = uni.upx2px(500);
  320. let endTime = +new Date() / 1000
  321. let startTime = endTime - 60 * 60 * 24
  322. this.end_time = this.formatTime(endTime * 1000, 'yyyy-MM-dd')
  323. console.log(this.end_time)
  324. this.start_time = this.formatTime(startTime * 1000, 'yyyy-MM-dd')
  325. setTimeout(() => {
  326. this.history()
  327. this.historylist()
  328. }, 1000)
  329. },
  330. onShow() {
  331. // this.end_time = +new Date()/1000
  332. // this.start_time = this.end_time - 24 * 60 * 60
  333. // // this.formatTime(date, 'yyyy-MM-dd')
  334. // setTimeout(()=>{
  335. // this.history()
  336. // this.historylist()
  337. // },1000)
  338. },
  339. onPullDownRefresh() {
  340. this.history()
  341. this.historylist()
  342. setTimeout(() => {
  343. uni.stopPullDownRefresh()
  344. }, 1000)
  345. },
  346. }
  347. </script>
  348. <style lang="scss" scoped>
  349. ::v-deep .u-calendar__action {
  350. display: flex;
  351. justify-content: space-around;
  352. .u-calendar__action__text {
  353. line-height: 25px;
  354. }
  355. }
  356. page {
  357. background: #f7f7f7;
  358. }
  359. .title {
  360. color: #999999;
  361. margin: 32rpx 0;
  362. }
  363. .date {
  364. height: 92rpx;
  365. line-height: 92rpx;
  366. border-radius: 92rpx;
  367. background: #fff;
  368. display: flex;
  369. justify-content: space-between;
  370. margin-top: 16rpx;
  371. padding: 0 48rpx;
  372. position: relative;
  373. }
  374. .shuju_one,
  375. .shuju_two {
  376. // position: absolute;
  377. // top: 54px;
  378. width: 100%;
  379. // left: 5%;
  380. // box-shadow: 0 0 10rpx #bcb9ca;
  381. padding-top: 20rpx;
  382. height: 550rpx;
  383. background-color: #fff;
  384. border-radius: 24rpx;
  385. .canvastishi {
  386. font-size: 32rpx;
  387. position: absolute;
  388. top: 50%;
  389. left: 50%;
  390. margin-left: -64rpx;
  391. margin-top: -21rpx;
  392. .dataloading:after {
  393. overflow: hidden;
  394. display: inline-block;
  395. vertical-align: bottom;
  396. animation: ellipsis 2s infinite;
  397. content: "\2026";
  398. }
  399. @keyframes ellipsis {
  400. from {
  401. width: 2px;
  402. }
  403. to {
  404. width: 15px;
  405. }
  406. }
  407. }
  408. }
  409. .refresh {
  410. // position: absolute;
  411. // top: 700rpx;
  412. // left: 5%;
  413. font-size: 12px;
  414. float: right;
  415. // padding: 0 10rpx;
  416. // height: 40rpx;
  417. // border-radius: 8rpx;
  418. // background-color: #018B3F;
  419. // color: #FFFFFF;
  420. // line-height: 40rpx;
  421. // text-align: center;
  422. }
  423. .condition {
  424. // position: absolute;
  425. // top: 770rpx;
  426. display: flex;
  427. flex-wrap: wrap;
  428. width: 100%;
  429. // left: 5%;
  430. // box-shadow: 0 0 10rpx #bcb9ca;
  431. margin-bottom: 30rpx;
  432. .scroll-X {
  433. width: 100%;
  434. margin: 20rpx auto;
  435. .table {
  436. width: 1620px;
  437. }
  438. .tr {
  439. display: flex;
  440. overflow: hidden;
  441. .th,
  442. .td {
  443. display: inline-block;
  444. padding: 4rpx;
  445. width: 286rpx;
  446. text-align: center;
  447. height: 52rpx;
  448. line-height: 52rpx;
  449. border: 2rpx solid #F1F1F1;
  450. }
  451. .th:first-child,
  452. .td:first-child {
  453. width: 300rpx;
  454. }
  455. }
  456. .tr:nth-child(2n-1) {
  457. // background-color: #f5fff8;
  458. }
  459. .tr:first-child {
  460. // background-color: #E6E8EB;
  461. color: #31373D;
  462. }
  463. }
  464. .pagenumber {
  465. display: flex;
  466. margin: 20rpx auto;
  467. button {
  468. width: 150rpx;
  469. height: 50rpx;
  470. line-height: 50rpx;
  471. font-size: 26rpx;
  472. text-align: center;
  473. background-color: #17BB89;
  474. color: #FFFFFF;
  475. }
  476. .pagenumber_page {
  477. width: 100rpx;
  478. height: 50rpx;
  479. line-height: 50rpx;
  480. font-size: 26rpx;
  481. text-align: center;
  482. }
  483. }
  484. }
  485. </style>