history.vue 12 KB

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