history.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  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: 100;width: 100%;">
  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="canvastishi" v-if="!canvastishiTF">
  11. 暂无数据
  12. </view>
  13. <canvas v-if="canvastishiTF" canvas-id="canvasColumnA" id="canvasColumnA" class="charts" @touchstart="touchLineA($event)"
  14. @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>
  15. </view>
  16. <view class="selecttimes">
  17. <view class="newtimes">
  18. <view class="newtimes_state" @click="pickshow = !pickshow">
  19. <view class="oldtimes_left">
  20. <image src="../../static/image/prevention/841f87bfd8abb1b09610fa0789f9d8e.png" mode=""></image>
  21. 开始时间:{{this.begintime|timeFormat()}}
  22. </view>
  23. <view class="oldtimes_left">
  24. <u-icon name="arrow-down"></u-icon>
  25. </view>
  26. <u-picker mode="time" v-model="pickshow" :params="params" @confirm="pickone"></u-picker>
  27. </view>
  28. <view class="newtimes_end" @click="picktwoshow = !picktwoshow">
  29. <view class="oldtimes_left">
  30. <image src="../../static/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png" mode=""></image>
  31. 结束时间:{{this.end|timeFormat()}}
  32. </view>
  33. <view class="oldtimes_left">
  34. <u-icon name="arrow-down"></u-icon>
  35. </view>
  36. <u-picker mode="time" v-model="picktwoshow" :params="params" @confirm="picktwo"></u-picker>
  37. </view>
  38. <p class="tishi" v-if="tishiTF">请选择正确的结束时间</p>
  39. <view class="btnser" @click="serter">
  40. 搜 索
  41. </view>
  42. </view>
  43. </view>
  44. <view class="condition">
  45. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  46. <!-- @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" -->
  47. <table class="table">
  48. <tr class="tr">
  49. <th class="th">日期</th>
  50. <th class="th" v-for="key,index in historydatas.conf" :key="'a'+index" v-if="key">{{key.replace("#","(")+")"}}</th>
  51. </tr>
  52. <tr class="tr" v-for="(items,index) in historydatas.data" :key="'b'+index" v-if="!forbidden">
  53. <td class="td">{{items.time|timeFormat()}}</td>
  54. <td class="td" v-for="keys in items.dat" v-if="keys">{{parseFloat(keys)==-99.99?"N/A":parseFloat(keys)}}</td>
  55. </tr>
  56. <tr class="tr" v-if="forbidden">
  57. <td class="td" v-for="item in 10">暂无数据</td>
  58. </tr>
  59. </table>
  60. </scroll-view>
  61. <view class="pagenumber">
  62. <button @click="prev">上一页</button>
  63. <view class="pagenumber_page">
  64. 第{{page}}页
  65. </view>
  66. <button @click="next" :disabled="forbidden">下一页</button>
  67. </view>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </template>
  73. <script>
  74. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  75. var canvasColumnA = null;
  76. var presenttime = +new Date();
  77. export default {
  78. data() {
  79. return {
  80. cWidth: '400',
  81. cHeight: '400',
  82. pixelRatio: 1,
  83. canvastishiTF: false,
  84. id: "",
  85. begintime: '', //开始时间
  86. end: '', //结束时间
  87. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  88. titleidnex: 0,
  89. pickshow: false, //选择时间一
  90. picktwoshow: false, //选择时间二
  91. params: { //时间格式
  92. year: true,
  93. month: true,
  94. day: true,
  95. hour: true,
  96. minute: true,
  97. second: false
  98. },
  99. tishiTF: false, //提示
  100. historydatas: [],
  101. page: 1,
  102. forbidden: false
  103. }
  104. },
  105. methods: { //weather.weather.qxz_detail
  106. async listhistorydata(datas) { //上传时间
  107. const res = await this.$myRequest({
  108. url: '/api/api_gateway?method=weather.weather.qxz_detail',
  109. data: {
  110. device_id: datas,
  111. begin: parseInt(this.begintime),
  112. end: parseInt(this.end),
  113. page: this.page
  114. }
  115. })
  116. this.historydatas = res
  117. console.log(this.historydatas)
  118. if (res.data.length == 0) {
  119. this.forbidden = true
  120. } else {
  121. this.forbidden = false
  122. }
  123. },
  124. async historydata(datas) { //上传时间 //折线图
  125. const res = await this.$myRequest({
  126. url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
  127. data: {
  128. device_id: datas,
  129. begin: parseInt(this.begintime),
  130. end: parseInt(this.end)
  131. }
  132. })
  133. console.log(res)
  134. if (res.data.length == 0) {
  135. this.canvastishiTF = false
  136. } else {
  137. this.canvastishiTF = true
  138. var xtitle = []
  139. var linearr = []
  140. for (var i = 0; i < res.data.length; i++) {
  141. var times = new Date(res.data[i].time * 1000)
  142. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times.getSeconds())
  143. }
  144. for (var key in res.conf) {
  145. var obj = {}
  146. if(res.conf[key]!=""){
  147. obj.name = res.conf[key]
  148. }
  149. var arr = []
  150. for (var i = 0; i < res.data.length; i++) {
  151. if(parseFloat(res.data[i].dat[key])!=-99.99){
  152. arr.push(parseFloat(res.data[i].dat[key]))
  153. }
  154. }
  155. obj.data=arr
  156. if(obj.name){
  157. linearr.push(obj)
  158. }
  159. }
  160. this.canvastishiTF = linearr.some((item)=>{
  161. return item.data.length!=0;
  162. })
  163. console.log(this.canvastishiTF)
  164. this.showColumn("canvasColumnA", xtitle, linearr)
  165. }
  166. },
  167. pickone(e) { //开始时间
  168. this.begintime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  169. if (this.newtime < this.oldtime) {
  170. this.tishiTF = true
  171. } else {
  172. this.tishiTF = false
  173. }
  174. },
  175. picktwo(e) { //结束时间
  176. this.end = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  177. if (this.newtime < this.oldtime) {
  178. this.tishiTF = true
  179. } else {
  180. this.tishiTF = false
  181. }
  182. },
  183. serter() {
  184. if (this.tishiTF == false) {
  185. this.historydata(this.id)
  186. this.listhistorydata(this.id)
  187. }
  188. },
  189. prev() { //上一页
  190. if (this.page > 1) {
  191. this.page--
  192. this.listhistorydata(this.id)
  193. }
  194. },
  195. next() { //下一页
  196. this.page++
  197. this.listhistorydata(this.id)
  198. },
  199. clickLeft() {
  200. uni.navigateBack({
  201. delta: 1
  202. })
  203. },
  204. showColumn(id, xtitle, xinfo) {
  205. var _self = this
  206. canvasColumnA = new uCharts({
  207. canvasId: id,
  208. type: 'line',
  209. legend: {
  210. position: "top"
  211. },
  212. fontSize: 11,
  213. background: '#FFFFFF',
  214. pixelRatio: 1,
  215. animation: true,
  216. dataLabel: false,
  217. categories: xtitle,
  218. series: xinfo,
  219. enableScroll: true, //开启图表拖拽功能
  220. xAxis: {
  221. disableGrid: true,
  222. type: 'grid',
  223. gridType: 'dash',
  224. itemCount: 5, //x轴单屏显示数据的数量,默认为5个
  225. scrollShow: true, //新增是否显示滚动条,默认false
  226. // scrollAlign: 'left', //滚动条初始位置
  227. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  228. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  229. },
  230. yAxis: {},
  231. width: _self.cWidth * 1,
  232. height: _self.cHeight * 1,
  233. extra: {
  234. line: {
  235. type: 'curve'
  236. }
  237. }
  238. });
  239. },
  240. touchLineA(e) {
  241. canvasColumnA.scrollStart(e);
  242. },
  243. moveLineA(e) {
  244. canvasColumnA.scroll(e);
  245. },
  246. touchEndLineA(e) {
  247. canvasColumnA.scrollEnd(e);
  248. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  249. canvasColumnA.showToolTip(e, {
  250. format: function(item, category) {
  251. return category + ' ' + item.name + ':' + item.data
  252. }
  253. });
  254. },
  255. },
  256. onLoad(option) {
  257. this.cWidth = uni.upx2px(650);
  258. this.cHeight = uni.upx2px(500);
  259. this.id = option.device_id
  260. this.end = presenttime / 1000
  261. this.begintime = presenttime / 1000 - 24 * 60 * 60
  262. this.historydata(option.device_id)
  263. this.listhistorydata(option.device_id)
  264. }
  265. }
  266. </script>
  267. <style lang="scss">
  268. .graph {
  269. position: absolute;
  270. top: 54px;
  271. width: 90%;
  272. left: 5%;
  273. .canvasbox {
  274. width: 100%;
  275. height: 550rpx;
  276. position: relative;
  277. box-shadow: 0 0 10rpx #bcb9ca;
  278. .canvastishi {
  279. font-size: 32rpx;
  280. position: absolute;
  281. top: 50%;
  282. left: 50%;
  283. margin-left: -64rpx;
  284. margin-top: -21rpx;
  285. }
  286. }
  287. .none_hint {
  288. font-size: 32rpx;
  289. font-weight: 700;
  290. position: absolute;
  291. top: 0;
  292. left: 50%;
  293. margin-left: -64rpx;
  294. }
  295. }
  296. .shuju_one_title {
  297. width: 70%;
  298. margin: 0 auto;
  299. display: flex;
  300. .tltle_text {
  301. width: 25%;
  302. border: 2rpx solid #B2B2B2;
  303. color: #B2B2B2;
  304. text-align: center;
  305. font-size: 24rpx;
  306. height: 50rpx;
  307. line-height: 50rpx;
  308. }
  309. .title_text_color {
  310. width: 25%;
  311. border: 2rpx solid #28AE4F;
  312. color: #28AE4F;
  313. text-align: center;
  314. font-size: 24rpx;
  315. height: 50rpx;
  316. line-height: 50rpx;
  317. }
  318. }
  319. .selecttimes {
  320. width: 100%;
  321. box-shadow: 0 0 10rpx #bcb9ca;
  322. margin-top: 20rpx;
  323. .tishi {
  324. width: 90%;
  325. margin: 0 auto;
  326. color: #f00000;
  327. text-align: center;
  328. font-size: 24rpx;
  329. }
  330. .btnser {
  331. width: 90%;
  332. margin: 10rpx auto;
  333. color: #FFFFFF;
  334. text-align: center;
  335. font-size: 28rpx;
  336. background-color: #58BD4D;
  337. border-radius: 20rpx;
  338. height: 50rpx;
  339. line-height: 50rpx;
  340. }
  341. .newtimes {
  342. width: 100%;
  343. padding: 20rpx 20rpx;
  344. box-sizing: border-box;
  345. .newtimes_state,
  346. .newtimes_end {
  347. display: flex;
  348. justify-content: space-between;
  349. margin-bottom: 20rpx;
  350. .oldtimes_left {
  351. position: relative;
  352. padding-left: 36rpx;
  353. font-size: 28rpx;
  354. image {
  355. width: 30rpx;
  356. height: 30rpx;
  357. vertical-align: top;
  358. position: absolute;
  359. top: 7rpx;
  360. left: 0;
  361. }
  362. }
  363. }
  364. }
  365. }
  366. .condition {
  367. display: flex;
  368. flex-wrap: wrap;
  369. width: 100%;
  370. box-shadow: 0 0 10rpx #bcb9ca;
  371. margin: 30rpx 0;
  372. .scroll-X {
  373. width: 95%;
  374. margin: 20rpx auto;
  375. .tr {
  376. display: flex;
  377. overflow: hidden;
  378. .th,
  379. .td {
  380. display: inline-block;
  381. padding: 5rpx;
  382. width: 240rpx;
  383. text-align: center;
  384. height: 52rpx;
  385. line-height: 52rpx;
  386. border: 2rpx solid #F1F1F1;
  387. }
  388. // .th:last-child,
  389. // .td:last-child {
  390. // width: 300rpx;
  391. // }
  392. // .th:nth-last-child(2),
  393. // .th:nth-last-child(3),
  394. // .td:nth-last-child(2),
  395. // .td:nth-last-child(3) {
  396. // width: 200rpx;
  397. // }
  398. }
  399. }
  400. .pagenumber {
  401. display: flex;
  402. margin: 20rpx auto;
  403. button {
  404. width: 150rpx;
  405. height: 50rpx;
  406. line-height: 50rpx;
  407. font-size: 26rpx;
  408. text-align: center;
  409. background-color: #17BB89;
  410. color: #FFFFFF;
  411. }
  412. .pagenumber_page {
  413. width: 150rpx;
  414. height: 50rpx;
  415. line-height: 50rpx;
  416. font-size: 26rpx;
  417. text-align: center;
  418. }
  419. }
  420. }
  421. </style>