history.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  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: 100;width: 100%;">
  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="../../static/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="../../static/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. }
  193. },
  194. prev() { //上一页
  195. if (this.page > 1) {
  196. this.page--
  197. this.listhistorydata(this.id)
  198. }
  199. },
  200. next() { //下一页
  201. this.page++
  202. this.listhistorydata(this.id)
  203. },
  204. clickLeft() {
  205. uni.navigateBack({
  206. delta: 1
  207. })
  208. },
  209. showColumn(id, xtitle, xinfo) {
  210. var _self = this
  211. canvasColumnA = new uCharts({
  212. canvasId: id,
  213. type: 'line',
  214. legend: {
  215. position: "top"
  216. },
  217. fontSize: 11,
  218. background: '#FFFFFF',
  219. pixelRatio: 1,
  220. animation: true,
  221. dataLabel: false,
  222. categories: xtitle,
  223. series: xinfo,
  224. enableScroll: true, //开启图表拖拽功能
  225. xAxis: {
  226. disableGrid: true,
  227. type: 'grid',
  228. gridType: 'dash',
  229. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  230. scrollShow: true, //新增是否显示滚动条,默认false
  231. // scrollAlign: 'left', //滚动条初始位置
  232. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  233. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  234. },
  235. yAxis: {},
  236. width: _self.cWidth * 1,
  237. height: _self.cHeight * 1,
  238. extra: {
  239. line: {
  240. type: 'curve'
  241. }
  242. }
  243. });
  244. },
  245. touchLineA(e) {
  246. canvasColumnA.scrollStart(e);
  247. },
  248. moveLineA(e) {
  249. canvasColumnA.scroll(e);
  250. },
  251. touchEndLineA(e) {
  252. canvasColumnA.scrollEnd(e);
  253. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  254. canvasColumnA.showToolTip(e, {
  255. format: function(item, category) {
  256. return category + ' ' + item.name + ':' + item.data
  257. }
  258. });
  259. },
  260. },
  261. onLoad(option) {
  262. this.cWidth = uni.upx2px(650);
  263. this.cHeight = uni.upx2px(500);
  264. this.id = option.device_id
  265. this.end = presenttime / 1000
  266. this.begintime = presenttime / 1000 - 24 * 60 * 60
  267. console.log(new Date(1616145097 * 1000), new Date(1616231497 * 1000))
  268. this.historydata(option.device_id)
  269. this.listhistorydata(option.device_id)
  270. }
  271. }
  272. </script>
  273. <style lang="scss">
  274. .graph {
  275. position: absolute;
  276. top: 54px;
  277. width: 90%;
  278. left: 5%;
  279. .canvasbox {
  280. width: 100%;
  281. height: 550rpx;
  282. position: relative;
  283. box-shadow: 0 0 10rpx #bcb9ca;
  284. .canvastishi {
  285. font-size: 32rpx;
  286. position: absolute;
  287. top: 50%;
  288. left: 50%;
  289. margin-left: -64rpx;
  290. margin-top: -21rpx;
  291. }
  292. }
  293. .none_hint {
  294. font-size: 32rpx;
  295. font-weight: 700;
  296. position: absolute;
  297. top: 0;
  298. left: 50%;
  299. margin-left: -64rpx;
  300. }
  301. }
  302. .shuju_one_title {
  303. width: 70%;
  304. margin: 0 auto;
  305. display: flex;
  306. .tltle_text {
  307. width: 25%;
  308. border: 2rpx solid #B2B2B2;
  309. color: #B2B2B2;
  310. text-align: center;
  311. font-size: 24rpx;
  312. height: 50rpx;
  313. line-height: 50rpx;
  314. }
  315. .title_text_color {
  316. width: 25%;
  317. border: 2rpx solid #28AE4F;
  318. color: #28AE4F;
  319. text-align: center;
  320. font-size: 24rpx;
  321. height: 50rpx;
  322. line-height: 50rpx;
  323. }
  324. }
  325. .selecttimes {
  326. width: 100%;
  327. box-shadow: 0 0 10rpx #bcb9ca;
  328. margin-top: 20rpx;
  329. .tishi {
  330. width: 90%;
  331. margin: 0 auto;
  332. color: #f00000;
  333. text-align: center;
  334. font-size: 24rpx;
  335. }
  336. .btnser {
  337. width: 90%;
  338. margin: 10rpx auto;
  339. color: #FFFFFF;
  340. text-align: center;
  341. font-size: 28rpx;
  342. background-color: #58BD4D;
  343. border-radius: 20rpx;
  344. height: 50rpx;
  345. line-height: 50rpx;
  346. }
  347. .newtimes {
  348. width: 100%;
  349. padding: 20rpx 20rpx;
  350. box-sizing: border-box;
  351. .newtimes_state,
  352. .newtimes_end {
  353. display: flex;
  354. justify-content: space-between;
  355. margin-bottom: 20rpx;
  356. .oldtimes_left {
  357. position: relative;
  358. padding-left: 36rpx;
  359. font-size: 28rpx;
  360. image {
  361. width: 30rpx;
  362. height: 30rpx;
  363. vertical-align: top;
  364. position: absolute;
  365. top: 7rpx;
  366. left: 0;
  367. }
  368. }
  369. }
  370. }
  371. }
  372. .condition {
  373. display: flex;
  374. flex-wrap: wrap;
  375. width: 100%;
  376. box-shadow: 0 0 10rpx #bcb9ca;
  377. margin: 30rpx 0;
  378. .scroll-X {
  379. width: 95%;
  380. margin: 20rpx auto;
  381. .tr {
  382. display: flex;
  383. overflow: hidden;
  384. .th,
  385. .td {
  386. display: inline-block;
  387. padding: 5rpx;
  388. width: 240rpx;
  389. text-align: center;
  390. height: 52rpx;
  391. line-height: 52rpx;
  392. border: 2rpx solid #F1F1F1;
  393. }
  394. .th:first-child,
  395. .td:first-child {
  396. width: 300rpx;
  397. }
  398. }
  399. }
  400. .pagenumber {
  401. display: flex;
  402. margin: 20rpx auto;
  403. button {
  404. width: 150rpx;
  405. height: 50rpx;
  406. line-height: 50rpx;
  407. font-size: 26rpx;
  408. text-align: center;
  409. background-color: #17BB89;
  410. color: #FFFFFF;
  411. }
  412. .pagenumber_page {
  413. width: 150rpx;
  414. height: 50rpx;
  415. line-height: 50rpx;
  416. font-size: 26rpx;
  417. text-align: center;
  418. }
  419. }
  420. }
  421. </style>