history.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  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[eindex]) != -99.99) {
  181. arr.unshift(parseFloat(res.data[i].dat[eindex]))
  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(this.canvastishiTF)
  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. canvasColumnA = new uCharts({
  228. canvasId: id,
  229. type: 'line',
  230. legend: {
  231. position: "top"
  232. },
  233. fontSize: 11,
  234. background: '#FFFFFF',
  235. pixelRatio: 1,
  236. animation: true,
  237. dataLabel: false,
  238. categories: xtitle,
  239. series: xinfo,
  240. enableScroll: true, //开启图表拖拽功能
  241. xAxis: {
  242. disableGrid: true,
  243. type: 'grid',
  244. gridType: 'dash',
  245. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  246. scrollShow: true, //新增是否显示滚动条,默认false
  247. // scrollAlign: 'left', //滚动条初始位置
  248. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  249. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  250. },
  251. yAxis: {},
  252. width: _self.cWidth * 1,
  253. height: _self.cHeight * 1,
  254. extra: {
  255. line: {
  256. type: 'curve'
  257. }
  258. }
  259. });
  260. },
  261. touchLineA(e) {
  262. canvasColumnA.scrollStart(e);
  263. },
  264. moveLineA(e) {
  265. canvasColumnA.scroll(e);
  266. },
  267. touchEndLineA(e) {
  268. canvasColumnA.scrollEnd(e);
  269. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  270. canvasColumnA.showToolTip(e, {
  271. format: function(item, category) {
  272. return category + ' ' + item.name + ':' + item.data
  273. }
  274. });
  275. },
  276. timetab(e) {
  277. e = new Date(e * 1000)
  278. var year = e.getFullYear()
  279. var month = e.getMonth() + 1 < 10 ? "0" + (e.getMonth() + 1) : e.getMonth() + 1
  280. var day = e.getDate() < 10 ? "0" + e.getDate() : e.getDate()
  281. var time = year + "/" + month + "/" + day
  282. return time
  283. }
  284. },
  285. onLoad(option) {
  286. this.cWidth = uni.upx2px(650);
  287. this.cHeight = uni.upx2px(500);
  288. this.id = option.device_id
  289. this.end = presenttime / 1000
  290. this.begintime = presenttime / 1000 - 24 * 60 * 60
  291. console.log(new Date(1616145097 * 1000), new Date(1616231497 * 1000))
  292. this.historydata(option.device_id)
  293. this.listhistorydata(option.device_id)
  294. this.myuser_type = uni.getStorageSync('myuser_type')
  295. }
  296. }
  297. </script>
  298. <style lang="scss">
  299. .graph {
  300. position: absolute;
  301. top: 54px;
  302. width: 90%;
  303. left: 5%;
  304. .canvasbox {
  305. width: 100%;
  306. height: 550rpx;
  307. position: relative;
  308. box-shadow: 0 0 10rpx #bcb9ca;
  309. padding-top: 20px;
  310. .charts {}
  311. .canvastishi {
  312. font-size: 32rpx;
  313. position: absolute;
  314. top: 50%;
  315. left: 50%;
  316. margin-left: -64rpx;
  317. margin-top: -21rpx;
  318. .dataloading:after {
  319. overflow: hidden;
  320. display: inline-block;
  321. vertical-align: bottom;
  322. animation: ellipsis 2s infinite;
  323. content: "\2026";
  324. }
  325. @keyframes ellipsis {
  326. from {
  327. width: 2px;
  328. }
  329. to {
  330. width: 15px;
  331. }
  332. }
  333. }
  334. .schedule {
  335. display: flex;
  336. width: 280rpx;
  337. height: 50rpx;
  338. border: 2rpx solid #F0F0F0;
  339. margin-right: 40rpx;
  340. .schedule_value {
  341. width: 70%;
  342. text-align: center;
  343. line-height: 50rpx;
  344. font-size: 24rpx;
  345. }
  346. .schedule_icon {
  347. width: 30%;
  348. background-color: #F2F2F2;
  349. text-align: center;
  350. line-height: 50rpx;
  351. }
  352. }
  353. }
  354. .none_hint {
  355. font-size: 32rpx;
  356. font-weight: 700;
  357. position: absolute;
  358. top: 0;
  359. left: 50%;
  360. margin-left: -64rpx;
  361. }
  362. }
  363. .shuju_one_title {
  364. width: 70%;
  365. margin: 0 auto;
  366. display: flex;
  367. .tltle_text {
  368. width: 25%;
  369. border: 2rpx solid #B2B2B2;
  370. color: #57c878;
  371. text-align: center;
  372. font-size: 24rpx;
  373. height: 50rpx;
  374. line-height: 50rpx;
  375. }
  376. .title_text_color {
  377. width: 25%;
  378. border: 2rpx solid #57c878;
  379. color: #fff;
  380. text-align: center;
  381. font-size: 24rpx;
  382. height: 50rpx;
  383. line-height: 50rpx;
  384. }
  385. }
  386. .selecttimes {
  387. width: 100%;
  388. box-shadow: 0 0 10rpx #bcb9ca;
  389. margin-top: 20rpx;
  390. padding: 10rpx 20rpx;
  391. box-sizing: border-box;
  392. .timesbox {
  393. display: flex;
  394. justify-content: space-around;
  395. image {
  396. width: 30rpx;
  397. height: 30rpx;
  398. margin-top: 6rpx;
  399. }
  400. .icon {
  401. color: #949494;
  402. text-align: right;
  403. margin-left: 30rpx;
  404. }
  405. }
  406. }
  407. .condition {
  408. display: flex;
  409. flex-wrap: wrap;
  410. width: 100%;
  411. box-shadow: 0 0 10rpx #bcb9ca;
  412. margin: 30rpx 0;
  413. .scroll-X {
  414. width: 95%;
  415. margin: 20rpx auto;
  416. .table {
  417. // width: 10420px;
  418. }
  419. .tr {
  420. display: flex;
  421. overflow: hidden;
  422. .th,
  423. .td {
  424. display: inline-block;
  425. padding: 5rpx;
  426. width: 240rpx;
  427. text-align: center;
  428. height: 52rpx;
  429. line-height: 52rpx;
  430. }
  431. .th:first-child,
  432. .td:first-child {
  433. width: 300rpx;
  434. }
  435. }
  436. .redText{
  437. .td{
  438. color: #dc143c;
  439. }
  440. }
  441. .tr:nth-child(2n-1) {
  442. background-color: #f5fff8;
  443. }
  444. .tr:first-child {
  445. background-color: #57c878;
  446. color: #fff;
  447. }
  448. }
  449. .pagenumber {
  450. display: flex;
  451. margin: 20rpx auto;
  452. button {
  453. width: 150rpx;
  454. height: 50rpx;
  455. line-height: 50rpx;
  456. font-size: 26rpx;
  457. text-align: center;
  458. background-color: #57c878;
  459. color: #FFFFFF;
  460. }
  461. .pagenumber_page {
  462. width: 150rpx;
  463. height: 50rpx;
  464. line-height: 50rpx;
  465. font-size: 26rpx;
  466. text-align: center;
  467. }
  468. }
  469. }
  470. /deep/.u-calendar__action {
  471. display: flex;
  472. justify-content: space-around;
  473. .u-calendar__action__text {
  474. line-height: 25px;
  475. }
  476. }
  477. </style>