newhistoryfile.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487
  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. const ctx = uni.createCanvasContext(id, this);
  230. canvaColumnA = new uCharts({
  231. context: ctx,
  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. console.log(e)
  266. canvaColumnA.scrollStart(e);
  267. },
  268. moveLineA(e) {
  269. canvaColumnA.scroll(e);
  270. },
  271. touchEndLineA(e) {
  272. canvaColumnA.scrollEnd(e);
  273. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  274. canvaColumnA.showToolTip(e, {
  275. format: function(item, category) {
  276. return category + ' ' + item.name + ':' + item.data
  277. }
  278. });
  279. },
  280. },
  281. onLoad(option) {
  282. this.d_id = option.d_id
  283. this.device_id = option.device_id
  284. this.device_type = option.device_type
  285. this.cWidth = uni.upx2px(650);
  286. this.cHeight = uni.upx2px(500);
  287. let endTime = +new Date()/1000
  288. let startTime = endTime - 60 * 60 * 24
  289. this.end_time = this.formatTime(endTime*1000,'yyyy-MM-dd')
  290. console.log(this.end_time)
  291. this.start_time = this.formatTime(startTime*1000,'yyyy-MM-dd')
  292. setTimeout(()=>{
  293. this.history()
  294. this.historylist()
  295. },1000)
  296. },
  297. onShow(){
  298. // this.end_time = +new Date()/1000
  299. // this.start_time = this.end_time - 24 * 60 * 60
  300. // // this.formatTime(date, 'yyyy-MM-dd')
  301. // setTimeout(()=>{
  302. // this.history()
  303. // this.historylist()
  304. // },1000)
  305. },
  306. onPullDownRefresh() {
  307. this.history()
  308. this.historylist()
  309. setTimeout(() => {
  310. uni.stopPullDownRefresh()
  311. }, 1000)
  312. },
  313. }
  314. </script>
  315. <style lang="scss" scoped>
  316. page{
  317. background: #f7f7f7;
  318. }
  319. .title{
  320. color: #999999;
  321. margin: 32rpx 0;
  322. }
  323. .date{
  324. height: 92rpx;
  325. line-height: 92rpx;
  326. border-radius: 92rpx;
  327. background: #fff;
  328. display: flex;
  329. justify-content: space-between;
  330. margin-top: 16rpx;
  331. padding: 0 48rpx;
  332. position: relative;
  333. /deep/.u-calendar__action {
  334. display: flex;
  335. justify-content: space-around;
  336. .u-calendar__action__text {
  337. line-height: 25px;
  338. }
  339. }
  340. }
  341. .shuju_one,
  342. .shuju_two {
  343. // position: absolute;
  344. // top: 54px;
  345. width: 100%;
  346. // left: 5%;
  347. // box-shadow: 0 0 10rpx #bcb9ca;
  348. padding-top: 20rpx;
  349. height: 550rpx;
  350. background-color: #fff;
  351. border-radius: 24rpx;
  352. .canvastishi {
  353. font-size: 32rpx;
  354. position: absolute;
  355. top: 50%;
  356. left: 50%;
  357. margin-left: -64rpx;
  358. margin-top: -21rpx;
  359. .dataloading:after {
  360. overflow: hidden;
  361. display: inline-block;
  362. vertical-align: bottom;
  363. animation: ellipsis 2s infinite;
  364. content: "\2026";
  365. }
  366. @keyframes ellipsis {
  367. from {
  368. width: 2px;
  369. }
  370. to {
  371. width: 15px;
  372. }
  373. }
  374. }
  375. }
  376. .refresh {
  377. // position: absolute;
  378. // top: 700rpx;
  379. // left: 5%;
  380. font-size: 12px;
  381. float: right;
  382. // padding: 0 10rpx;
  383. // height: 40rpx;
  384. // border-radius: 8rpx;
  385. // background-color: #018B3F;
  386. // color: #FFFFFF;
  387. // line-height: 40rpx;
  388. // text-align: center;
  389. }
  390. .condition {
  391. // position: absolute;
  392. // top: 770rpx;
  393. display: flex;
  394. flex-wrap: wrap;
  395. width: 100%;
  396. // left: 5%;
  397. // box-shadow: 0 0 10rpx #bcb9ca;
  398. margin-bottom: 30rpx;
  399. .scroll-X {
  400. width: 100%;
  401. margin: 20rpx auto;
  402. .table{
  403. width: 1620px;
  404. }
  405. .tr {
  406. display: flex;
  407. overflow: hidden;
  408. .th,
  409. .td {
  410. display: inline-block;
  411. padding: 4rpx;
  412. width: 286rpx;
  413. text-align: center;
  414. height: 52rpx;
  415. line-height: 52rpx;
  416. border: 2rpx solid #F1F1F1;
  417. }
  418. .th:first-child,
  419. .td:first-child {
  420. width: 300rpx;
  421. }
  422. }
  423. .tr:nth-child(2n-1){
  424. // background-color: #f5fff8;
  425. }
  426. .tr:first-child{
  427. // background-color: #E6E8EB;
  428. color: #31373D;
  429. }
  430. }
  431. .pagenumber {
  432. display: flex;
  433. margin: 20rpx auto;
  434. button {
  435. width: 150rpx;
  436. height: 50rpx;
  437. line-height: 50rpx;
  438. font-size: 26rpx;
  439. text-align: center;
  440. background-color: #17BB89;
  441. color: #FFFFFF;
  442. }
  443. .pagenumber_page {
  444. width: 100rpx;
  445. height: 50rpx;
  446. line-height: 50rpx;
  447. font-size: 26rpx;
  448. text-align: center;
  449. }
  450. }
  451. }
  452. </style>