history.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510
  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: 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-if="canvastishiTF" 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="'http://www.hnyfwlw.com:8006/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-show="key">
  50. {{key.replace("#","(")+")"}}
  51. </th>
  52. </tr>
  53. <tr :class="`tr ${items.is_history && myuser_type == 1 ? 'redText': ''}`" v-for="(items,index) in historydatas.data" :key="index" v-if="!forbidden">
  54. <td class="td">{{items.time|timeFormat()}}</td>
  55. <td class="td" v-for="item,indexss in datalength" :key="indexss">
  56. {{parseFloat(items.dat["e"+(indexss+1)])==-99.99?"N/A":parseFloat(items.dat["e"+(indexss+1)])}}
  57. </td>
  58. </tr>
  59. <tr class="tr" v-if="forbidden">
  60. <td class="td" v-for="item in 10">暂无数据</td>
  61. </tr>
  62. </table>
  63. </scroll-view>
  64. <view class="pagenumber">
  65. <button @click="prev">上一页</button>
  66. <view class="pagenumber_page">
  67. 第{{page}}页
  68. </view>
  69. <view class="pagenumber_page">
  70. 共 {{pagesum}} 页
  71. </view>
  72. <button @click="next" :disabled="forbidden">下一页</button>
  73. </view>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. </template>
  79. <script>
  80. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  81. var canvasColumnA = null;
  82. var presenttime = +new Date();
  83. export default {
  84. data() {
  85. return {
  86. myuser_type: null,
  87. cWidth: '400',
  88. cHeight: '400',
  89. pixelRatio: 1,
  90. canvastishiTF: false, //暂无数据提示
  91. dataloadingtf: true, //加载中提示
  92. id: "",
  93. begintime: '', //开始时间
  94. end: '', //结束时间
  95. titletext: [], //折线图数据切换列表数据
  96. titleidnex: 0,
  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. tiemshow: false, //日期选择
  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 (key && 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. this.titletext = []
  155. if (res.data.length == 0) {
  156. this.canvastishiTF = false
  157. } else {
  158. this.canvastishiTF = true
  159. for (var key in res.conf) {
  160. if (res.conf[key]) {
  161. this.titletext.push(res.conf[key])
  162. }
  163. }
  164. this.conflist(res, "e1")
  165. }
  166. console.log(this.titletext)
  167. },
  168. conflist(res, eindex) {
  169. var xtitle = []
  170. var linearr = []
  171. for (var i = 0; i < res.data.length; i++) {
  172. var times = new Date(res.data[i].time * 1000)
  173. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times
  174. .getMinutes())
  175. }
  176. var obj = {}
  177. obj.name = res.conf[eindex]
  178. var arr = []
  179. for (var i = 0; i < res.data.length; i++) {
  180. if (parseFloat(((res.data[i].dat)[0][eindex].split('#'))[0]) != -99.99) {
  181. arr.unshift(parseFloat(((res.data[i].dat)[0][eindex].split('#'))[0]))
  182. }
  183. }
  184. obj.data = arr
  185. if (obj.name) {
  186. linearr.push(obj)
  187. }
  188. this.canvastishiTF = linearr.some((item) => {
  189. return item.data.length != 0;
  190. })
  191. console.log(obj)
  192. this.showColumn("canvasColumnA", xtitle, linearr)
  193. },
  194. confirmFun(index) {
  195. console.log(index)
  196. this.indexone = index[0]
  197. var str = 'e' + (index[0] + 1)
  198. console.log(str)
  199. this.conflist(this.chartdata, str)
  200. },
  201. tiemchange(e) {
  202. console.log(e)
  203. this.begintime = +new Date(e.startDate) / 1000
  204. this.end = +new Date(e.endDate) / 1000 + 16 * 60 * 60
  205. this.historydata(this.id)
  206. this.listhistorydata(this.id)
  207. },
  208. prev() { //上一页
  209. if (this.page > 1) {
  210. this.page--
  211. this.listhistorydata(this.id)
  212. }
  213. },
  214. next() { //下一页
  215. if (this.page < this.pagesum) {
  216. this.page++
  217. this.listhistorydata(this.id)
  218. }
  219. },
  220. clickLeft() {
  221. uni.navigateBack({
  222. delta: 1
  223. })
  224. },
  225. showColumn(id, xtitle, xinfo) {
  226. var _self = this
  227. const ctx = uni.createCanvasContext(id, this);
  228. canvasColumnA = new uCharts({
  229. context: ctx,
  230. type: 'line',
  231. legend: {
  232. position: "top"
  233. },
  234. fontSize: 11,
  235. background: '#FFFFFF',
  236. pixelRatio: 1,
  237. animation: true,
  238. dataLabel: false,
  239. categories: xtitle,
  240. series: xinfo,
  241. enableScroll: true, //开启图表拖拽功能
  242. xAxis: {
  243. disableGrid: true,
  244. type: 'grid',
  245. gridType: 'dash',
  246. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  247. scrollShow: true, //新增是否显示滚动条,默认false
  248. // scrollAlign: 'left', //滚动条初始位置
  249. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  250. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  251. },
  252. yAxis: {},
  253. width: _self.cWidth * 1,
  254. height: _self.cHeight * 1,
  255. extra: {
  256. line: {
  257. type: 'curve'
  258. }
  259. }
  260. });
  261. },
  262. touchLineA(e) {
  263. canvasColumnA.scrollStart(e);
  264. },
  265. moveLineA(e) {
  266. canvasColumnA.scroll(e);
  267. },
  268. touchEndLineA(e) {
  269. canvasColumnA.scrollEnd(e);
  270. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  271. canvasColumnA.showToolTip(e, {
  272. format: function(item, category) {
  273. return category + ' ' + item.name + ':' + item.data
  274. }
  275. });
  276. },
  277. timetab(e) {
  278. e = new Date(e * 1000)
  279. var year = e.getFullYear()
  280. var month = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1
  281. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()
  282. var time = year + "/" + month + "/" + day
  283. return time
  284. }
  285. },
  286. onLoad(option) {
  287. this.cWidth = uni.upx2px(650);
  288. this.cHeight = uni.upx2px(500);
  289. this.id = option.device_id
  290. this.end = presenttime / 1000
  291. this.begintime = presenttime / 1000 - 24 * 60 * 60
  292. console.log(new Date(1616145097 * 1000), new Date(1616231497 * 1000))
  293. this.historydata(option.device_id)
  294. this.listhistorydata(option.device_id)
  295. this.myuser_type = uni.getStorageSync('myuser_type')
  296. }
  297. }
  298. </script>
  299. <style lang="scss">
  300. .graph {
  301. position: absolute;
  302. top: 54px;
  303. width: 90%;
  304. left: 5%;
  305. .canvasbox {
  306. width: 100%;
  307. height: 550rpx;
  308. position: relative;
  309. box-shadow: 0 0 10rpx #bcb9ca;
  310. padding-top: 20px;
  311. .charts {}
  312. .canvastishi {
  313. font-size: 32rpx;
  314. position: absolute;
  315. top: 50%;
  316. left: 50%;
  317. margin-left: -64rpx;
  318. margin-top: -21rpx;
  319. .dataloading:after {
  320. overflow: hidden;
  321. display: inline-block;
  322. vertical-align: bottom;
  323. animation: ellipsis 2s infinite;
  324. content: "\2026";
  325. }
  326. @keyframes ellipsis {
  327. from {
  328. width: 2px;
  329. }
  330. to {
  331. width: 15px;
  332. }
  333. }
  334. }
  335. .schedule {
  336. display: flex;
  337. width: 280rpx;
  338. height: 50rpx;
  339. border: 2rpx solid #F0F0F0;
  340. margin-right: 40rpx;
  341. .schedule_value {
  342. width: 70%;
  343. text-align: center;
  344. line-height: 50rpx;
  345. font-size: 24rpx;
  346. }
  347. .schedule_icon {
  348. width: 30%;
  349. background-color: #F2F2F2;
  350. text-align: center;
  351. line-height: 50rpx;
  352. }
  353. }
  354. }
  355. .none_hint {
  356. font-size: 32rpx;
  357. font-weight: 700;
  358. position: absolute;
  359. top: 0;
  360. left: 50%;
  361. margin-left: -64rpx;
  362. }
  363. }
  364. .shuju_one_title {
  365. width: 70%;
  366. margin: 0 auto;
  367. display: flex;
  368. .tltle_text {
  369. width: 25%;
  370. border: 2rpx solid #B2B2B2;
  371. color: #57c878;
  372. text-align: center;
  373. font-size: 24rpx;
  374. height: 50rpx;
  375. line-height: 50rpx;
  376. }
  377. .title_text_color {
  378. width: 25%;
  379. border: 2rpx solid #57c878;
  380. color: #fff;
  381. text-align: center;
  382. font-size: 24rpx;
  383. height: 50rpx;
  384. line-height: 50rpx;
  385. }
  386. }
  387. .selecttimes {
  388. width: 100%;
  389. box-shadow: 0 0 10rpx #bcb9ca;
  390. margin-top: 20rpx;
  391. padding: 10rpx 20rpx;
  392. box-sizing: border-box;
  393. .timesbox {
  394. display: flex;
  395. justify-content: space-around;
  396. image {
  397. width: 30rpx;
  398. height: 30rpx;
  399. margin-top: 6rpx;
  400. }
  401. .icon {
  402. color: #949494;
  403. text-align: right;
  404. margin-left: 30rpx;
  405. }
  406. }
  407. }
  408. .condition {
  409. display: flex;
  410. flex-wrap: wrap;
  411. width: 100%;
  412. box-shadow: 0 0 10rpx #bcb9ca;
  413. margin: 30rpx 0;
  414. .scroll-X {
  415. width: 95%;
  416. margin: 20rpx auto;
  417. .table {
  418. // width: 10420px;
  419. }
  420. .tr {
  421. display: flex;
  422. overflow: hidden;
  423. .th,
  424. .td {
  425. display: inline-block;
  426. padding: 5rpx;
  427. width: 240rpx;
  428. text-align: center;
  429. height: 52rpx;
  430. line-height: 52rpx;
  431. }
  432. .th:first-child,
  433. .td:first-child {
  434. width: 300rpx;
  435. }
  436. }
  437. .redText{
  438. .td{
  439. color: #dc143c;
  440. }
  441. }
  442. .tr:nth-child(2n-1) {
  443. background-color: #f5fff8;
  444. }
  445. .tr:first-child {
  446. background-color: #57c878;
  447. color: #fff;
  448. }
  449. }
  450. .pagenumber {
  451. display: flex;
  452. margin: 20rpx auto;
  453. button {
  454. width: 150rpx;
  455. height: 50rpx;
  456. line-height: 50rpx;
  457. font-size: 26rpx;
  458. text-align: center;
  459. background-color: #57c878;
  460. color: #FFFFFF;
  461. }
  462. .pagenumber_page {
  463. width: 150rpx;
  464. height: 50rpx;
  465. line-height: 50rpx;
  466. font-size: 26rpx;
  467. text-align: center;
  468. }
  469. }
  470. }
  471. /deep/.u-calendar__action {
  472. display: flex;
  473. justify-content: space-around;
  474. .u-calendar__action__text {
  475. line-height: 25px;
  476. }
  477. }
  478. </style>