history.vue 11 KB

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