history.vue 12 KB

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