newhistoryfile.vue 11 KB

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