newhistoryfile.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532
  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;">
  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-show="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. >
  36. </pest-line> -->
  37. <view class="title">监测数据
  38. <u-button size="mini" :loading='refreshLoading' class="refresh" throttle-time="500" @click="refresh"
  39. :customStyle="customStyle">刷 新</u-button>
  40. </view>
  41. <view class="condition">
  42. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  43. <u-table class="table">
  44. <u-tr>
  45. <u-th class="th" v-for="(value,key) in thdata" :key="key">{{value}}</u-th>
  46. </u-tr>
  47. <tr class="tr" v-for="(items,indexs) in historylistdata" :key="'b'+indexs" v-if="!forbidden">
  48. <u-td class="td" v-for="(value,key) in thdata">{{items[key]}}</u-td>
  49. </tr>
  50. <tr class="tr" v-if="forbidden">
  51. <u-td class="td" v-for="item in Object.keys(thdata)">暂无数据</u-td>
  52. </tr>
  53. </u-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. let 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. computed: {
  107. customStyle() {
  108. return {
  109. background: '#018B3F',
  110. fontSize: '12px',
  111. border: 'none',
  112. color: '#fff'
  113. }
  114. },
  115. },
  116. components:{pestLine},
  117. methods: {
  118. tiemchange(e) {
  119. console.log(e)
  120. this.start_time = e.startDate
  121. this.end_time = e.endDate
  122. this.history()
  123. this.historylist()
  124. this.notify++
  125. },
  126. async history() { //历史数据列表折线图
  127. this.dataloadingtf = true
  128. const res = await this.$myRequest({
  129. url: '/api/api_gateway?method=new_gateway.data_info.temp_hum',
  130. data: {
  131. device_type_id: this.device_type,
  132. id: this.d_id,
  133. start: +new Date(this.start_time + ' 00:00:00') / 1000,
  134. end: +new Date(this.end_time + ' 23:59:59') / 1000
  135. }
  136. })
  137. this.dataloadingtf = false
  138. this.historydatas = res || []
  139. console.log(this.historydatas)
  140. if (this.historydatas.length == 0) {
  141. this.canvastishiTF = false
  142. } else {
  143. this.canvastishiTF = true
  144. let arr1 = []
  145. let arr2 = []
  146. let arr3 = []
  147. let xtitle = []
  148. for (let i = 0; i < res.length; i++) {
  149. // let times = new Date(res[i].addtime * 1000)
  150. xtitle.push(res[i].addtime.split(' ')[0])
  151. arr1.push(res[i].tem)
  152. arr2.push(res[i].hum)
  153. if ('lux' in res[i]) {
  154. arr3.push(res[i].lux)
  155. }
  156. }
  157. // console.log(arr1)
  158. let obj = [{
  159. name: '温度',
  160. data: arr1,
  161. color: '#00E29D'
  162. }, {
  163. name: '湿度',
  164. data: arr2,
  165. color: '#6CBBFF'
  166. }]
  167. if (arr3.length > 0) {
  168. obj.push({
  169. index: 1,
  170. name: '光照',
  171. data: arr3,
  172. color: '#E67B3E'
  173. })
  174. }
  175. let yAxis = {
  176. data: [{
  177. position: 'left'
  178. }, {
  179. position: 'right'
  180. }]
  181. }
  182. console.log('----温度:',obj)
  183. this.showColumn("canvasColumnA", xtitle, obj, yAxis)
  184. }
  185. },
  186. //历史数据列表
  187. async historylist() {
  188. const res = await this.$myRequest({
  189. url: '/api/api_gateway?method=new_gateway.data_info.history_data',
  190. data: {
  191. device_type_id: this.device_type,
  192. id: this.d_id,
  193. start: +new Date(this.start_time + ' 00:00:00') / 1000,
  194. end: +new Date(this.end_time + ' 23:59:59') / 1000,
  195. page: this.page
  196. }
  197. })
  198. this.refreshLoading = false
  199. // this.thdata = Object.values(res.title)
  200. Object.keys(res.title).forEach(item => {
  201. this.$set(this.thdata, item, res.title[item])
  202. })
  203. this.historylistdata = res.data
  204. this.pagesum = Math.ceil(res.total / 10) || 1
  205. if (res.data.length == 0) {
  206. this.forbidden = true
  207. console.log(res.data.length)
  208. } else {
  209. this.forbidden = false
  210. console.log(res.data.length)
  211. }
  212. console.log(this.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 canvas = this.$refs[id];
  263. // const canvas = document.getElementById(id);
  264. // console.log(canvas,'pppppp')
  265. // const ctx = canvas.getContext("2d");
  266. const ctx = uni.createCanvasContext(id, this);
  267. canvaColumnA = new uCharts({
  268. context: ctx,
  269. type: 'line',
  270. legend: {
  271. position: "top"
  272. },
  273. fontSize: 11,
  274. background: '#FFFFFF',
  275. pixelRatio: 1,
  276. animation: true,
  277. dataLabel: false,
  278. categories: xtitle,
  279. series: xinfo,
  280. enableScroll: true, //开启图表拖拽功能
  281. xAxis: {
  282. disableGrid: true,
  283. type: 'grid',
  284. gridType: 'dash',
  285. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  286. scrollShow: true, //新增是否显示滚动条,默认false
  287. // scrollAlign: 'left', //滚动条初始位置
  288. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  289. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  290. },
  291. yAxis: yAxis || {},
  292. width: _self.cWidth * 1,
  293. height: _self.cHeight * 1,
  294. extra: {
  295. line: {
  296. type: 'curve'
  297. }
  298. }
  299. });
  300. },
  301. touchLineA(e) {
  302. console.log(e)
  303. canvaColumnA.scrollStart(e);
  304. },
  305. moveLineA(e) {
  306. canvaColumnA.scroll(e);
  307. },
  308. touchEndLineA(e) {
  309. canvaColumnA.scrollEnd(e);
  310. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  311. canvaColumnA.showToolTip(e, {
  312. format: function(item, category) {
  313. return category + ' ' + item.name + ':' + item.data
  314. }
  315. });
  316. },
  317. },
  318. onLoad(option) {
  319. this.d_id = option.d_id
  320. this.device_id = option.device_id
  321. this.device_type = option.device_type
  322. this.cWidth = uni.upx2px(650);
  323. this.cHeight = uni.upx2px(500);
  324. let endTime = +new Date() / 1000
  325. let startTime = endTime - 60 * 60 * 24
  326. this.end_time = this.formatTime(endTime * 1000, 'yyyy-MM-dd')
  327. console.log(this.end_time)
  328. this.start_time = this.formatTime(startTime * 1000, 'yyyy-MM-dd')
  329. setTimeout(() => {
  330. this.history()
  331. this.historylist()
  332. }, 1000)
  333. },
  334. onShow() {
  335. // this.end_time = +new Date()/1000
  336. // this.start_time = this.end_time - 24 * 60 * 60
  337. // // this.formatTime(date, 'yyyy-MM-dd')
  338. // setTimeout(()=>{
  339. // this.history()
  340. // this.historylist()
  341. // },1000)
  342. },
  343. onPullDownRefresh() {
  344. this.history()
  345. this.historylist()
  346. setTimeout(() => {
  347. uni.stopPullDownRefresh()
  348. }, 1000)
  349. },
  350. }
  351. </script>
  352. <style lang="scss" scoped>
  353. /deep/.u-calendar__action {
  354. display: flex;
  355. justify-content: space-around;
  356. .u-calendar__action__text {
  357. line-height: 25px;
  358. }
  359. }
  360. page {
  361. background: #f7f7f7;
  362. }
  363. .title {
  364. color: #999999;
  365. margin: 32rpx 0;
  366. }
  367. .date {
  368. height: 92rpx;
  369. line-height: 92rpx;
  370. border-radius: 92rpx;
  371. background: #fff;
  372. display: flex;
  373. justify-content: space-between;
  374. margin-top: 16rpx;
  375. padding: 0 48rpx;
  376. position: relative;
  377. }
  378. .shuju_one,
  379. .shuju_two {
  380. // position: absolute;
  381. // top: 54px;
  382. width: 100%;
  383. // left: 5%;
  384. // box-shadow: 0 0 10rpx #bcb9ca;
  385. padding-top: 20rpx;
  386. height: 550rpx;
  387. background-color: #fff;
  388. border-radius: 24rpx;
  389. .canvastishi {
  390. font-size: 32rpx;
  391. position: absolute;
  392. top: 50%;
  393. left: 50%;
  394. margin-left: -64rpx;
  395. margin-top: -21rpx;
  396. .dataloading:after {
  397. overflow: hidden;
  398. display: inline-block;
  399. vertical-align: bottom;
  400. animation: ellipsis 2s infinite;
  401. content: "\2026";
  402. }
  403. @keyframes ellipsis {
  404. from {
  405. width: 2px;
  406. }
  407. to {
  408. width: 15px;
  409. }
  410. }
  411. }
  412. }
  413. .refresh {
  414. // position: absolute;
  415. // top: 700rpx;
  416. // left: 5%;
  417. font-size: 12px;
  418. float: right;
  419. padding: 0 10rpx;
  420. height: 40rpx;
  421. border-radius: 8rpx;
  422. background-color: #018B3F;
  423. color: #FFFFFF;
  424. line-height: 40rpx;
  425. text-align: center;
  426. }
  427. .condition {
  428. // position: absolute;
  429. // top: 770rpx;
  430. display: flex;
  431. flex-wrap: wrap;
  432. width: 100%;
  433. // left: 5%;
  434. // box-shadow: 0 0 10rpx #bcb9ca;
  435. margin-bottom: 30rpx;
  436. .scroll-X {
  437. width: 100%;
  438. margin: 20rpx auto;
  439. .table {
  440. width: 1672px;
  441. }
  442. .tr {
  443. display: flex;
  444. overflow: hidden;
  445. .th,
  446. .td {
  447. display: inline-block;
  448. padding: 4rpx;
  449. width: 286rpx;
  450. text-align: center;
  451. height: 52rpx;
  452. line-height: 52rpx;
  453. border: 2rpx solid #F1F1F1;
  454. }
  455. .th:first-child,
  456. .td:first-child {
  457. width: 300rpx;
  458. }
  459. }
  460. .tr:nth-child(2n-1) {
  461. background-color: #f5fff8;
  462. }
  463. .tr:first-child {
  464. background-color: #57c878;
  465. color: #fff;
  466. }
  467. }
  468. .pagenumber {
  469. display: flex;
  470. margin: 20rpx auto;
  471. button {
  472. width: 150rpx;
  473. height: 50rpx;
  474. line-height: 50rpx;
  475. font-size: 26rpx;
  476. text-align: center;
  477. background-color: #17BB89;
  478. color: #FFFFFF;
  479. }
  480. .pagenumber_page {
  481. width: 100rpx;
  482. height: 50rpx;
  483. line-height: 50rpx;
  484. font-size: 26rpx;
  485. text-align: center;
  486. }
  487. }
  488. }
  489. </style>