history.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418
  1. <template>
  2. <view>
  3. <view style="position: fixed;z-index: 100;width: 100%;">
  4. <uni-nav-bar @clickLeft="clickLeft" left-icon="back" left-text="返回" title="历史数据"></uni-nav-bar>
  5. </view>
  6. <view class="graph">
  7. <highcharts :chartOptions="options" :styles="styles" ref="simpleChart"></highcharts>
  8. <!-- <p class="none_hint">暂无数据</p> -->
  9. <view class="selecttimes">
  10. <view class="newtimes">
  11. <view class="newtimes_state" @click="pickshow = !pickshow">
  12. <view class="oldtimes_left">
  13. <image src="../../static/image/prevention/841f87bfd8abb1b09610fa0789f9d8e.png" mode=""></image>
  14. 开始时间:{{this.begintime|timeFormat()}}
  15. </view>
  16. <view class="oldtimes_left">
  17. <u-icon name="arrow-down"></u-icon>
  18. </view>
  19. <u-picker mode="time" v-model="pickshow" :params="params" @confirm="pickone"></u-picker>
  20. </view>
  21. <view class="newtimes_end" @click="picktwoshow = !picktwoshow">
  22. <view class="oldtimes_left">
  23. <image src="../../static/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png" mode=""></image>
  24. 结束时间:{{this.end|timeFormat()}}
  25. </view>
  26. <view class="oldtimes_left">
  27. <u-icon name="arrow-down"></u-icon>
  28. </view>
  29. <u-picker mode="time" v-model="picktwoshow" :params="params" @confirm="picktwo"></u-picker>
  30. </view>
  31. <p class="tishi" v-if="tishiTF">请选择正确的结束时间</p>
  32. <view class="btnser" @click="serter">
  33. 搜 索
  34. </view>
  35. </view>
  36. </view>
  37. <view class="condition">
  38. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  39. <!-- @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" -->
  40. <table class="table">
  41. <tr class="tr">
  42. <th class="th">日期</th>
  43. <th class="th" v-for="key,index in historydatas.conf" :key="'a'+index" v-if="key">{{key.replace("#","(")+")"}}</th>
  44. </tr>
  45. <tr class="tr" v-for="(items,index) in historydatas.data" :key="'b'+index" v-if="!forbidden">
  46. <td class="td">{{items.time|timeFormat()}}</td>
  47. <td class="td" v-for="keys in items.dat" v-if="keys">{{parseFloat(keys)==-99.99?"N/A":parseFloat(keys)}}</td>
  48. </tr>
  49. <tr class="tr" v-if="forbidden">
  50. <td class="td" v-for="item in 10">暂无数据</td>
  51. </tr>
  52. </table>
  53. </scroll-view>
  54. <view class="pagenumber">
  55. <button @click="prev">上一页</button>
  56. <view class="pagenumber_page">
  57. 第{{page}}页
  58. </view>
  59. <button @click="next" :disabled="forbidden">下一页</button>
  60. </view>
  61. </view>
  62. </view>
  63. </view>
  64. </template>
  65. <script>
  66. import highcharts from "@/components/highcharts/highcharts"
  67. var presenttime = +new Date();
  68. export default {
  69. data() {
  70. return {
  71. styles: {
  72. // width: "650rpx",
  73. height: "400rpx"
  74. },
  75. options: {
  76. lang:{
  77. noData:"暂无数据"
  78. },
  79. chart: {
  80. type: 'spline', //指定图表的类型,默认是折线图(line)
  81. zoomType: 'x',
  82. panning: true,
  83. panKey: 'shift'
  84. },
  85. title: {
  86. text: '' // 标题
  87. },
  88. credits: {
  89. enabled: false
  90. },
  91. xAxis: {
  92. type: 'datetime',
  93. crosshair: true, //十字基准线
  94. dateTimeLabelFormats: {
  95. //根据时间间距X轴自动显示哪种格式
  96. millisecond: "%H:%M:%S.%L",
  97. second: "%H:%M:%S",
  98. minute: "%H:%M",
  99. hour: "%H:%M",
  100. day: "%m-%d",
  101. week: "%m-%d",
  102. month: "%Y-%m",
  103. year: "%Y",
  104. },
  105. },
  106. yAxis: {
  107. title: false,
  108. },
  109. legend: {
  110. // layout: 'vertical',
  111. // align: "center",
  112. // verticalAlign: "top",
  113. },
  114. tooltip: {
  115. // crosshairs: true,
  116. shared: true, //折线共享
  117. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  118. },
  119. plotOptions: {
  120. spline: {
  121. marker: {
  122. enabled: false
  123. },
  124. }
  125. },
  126. series: [],
  127. },
  128. id: "",
  129. begintime: '', //开始时间
  130. end: '', //结束时间
  131. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  132. titleidnex: 0,
  133. pickshow: false, //选择时间一
  134. picktwoshow: false, //选择时间二
  135. params: { //时间格式
  136. year: true,
  137. month: true,
  138. day: true,
  139. hour: true,
  140. minute: true,
  141. second: false
  142. },
  143. tishiTF: false, //提示
  144. historydatas: [],
  145. page: 1,
  146. forbidden: false
  147. }
  148. },
  149. methods: { //weather.weather.qxz_detail
  150. async listhistorydata(datas) { //上传时间
  151. const res = await this.$myRequest({
  152. url: '/api/api_gateway?method=weather.weather.qxz_detail',
  153. data: {
  154. device_id: datas,
  155. begin: parseInt(this.begintime),
  156. end: parseInt(this.end),
  157. page: this.page
  158. }
  159. })
  160. this.historydatas = res
  161. console.log(this.historydatas)
  162. if (res.data.length == 0) {
  163. this.forbidden = true
  164. } else {
  165. this.forbidden = false
  166. }
  167. },
  168. async historydata(datas) { //上传时间
  169. const res = await this.$myRequest({
  170. url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
  171. data: {
  172. device_id: datas,
  173. begin: parseInt(this.begintime),
  174. end: parseInt(this.end)
  175. }
  176. })
  177. // this.options.series[0].name = res.conf.e1.replace("#","(") + ")"
  178. console.log(res)
  179. for (var Key in res.conf) {
  180. let obj = {}
  181. if (res.conf[Key] != '') {
  182. obj.name = res.conf[Key].replace("#", "(") + ")"
  183. obj.data = []
  184. obj.color = "rgb(" + parseInt(Math.random() * 256) + "," + parseInt(Math.random() * 256) + "," + parseInt(Math.random() *
  185. 256) + ")"
  186. this.options.series.push(obj)
  187. }
  188. }
  189. for (var i = 0; i < res.data.length; i++) {
  190. for (var key in res.data[i].dat) {
  191. if (res.data[i].dat[key] != "") {
  192. let arr = []
  193. if (parseFloat(res.data[i].dat[key]) != -99.99) {
  194. arr.push(res.data[i].time * 1000 + 8 * 3600000, parseFloat(res.data[i].dat[key]))
  195. for (var j = 0; j < this.options.series.length; j++) {
  196. if (this.options.series[j].name.indexOf(key) != -1) {
  197. this.options.series[j].data.push(arr)
  198. }
  199. }
  200. }
  201. }
  202. }
  203. }
  204. this.$forceUpdate()
  205. },
  206. pickone(e) { //开始时间
  207. this.begintime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  208. if (this.newtime < this.oldtime) {
  209. this.tishiTF = true
  210. } else {
  211. this.tishiTF = false
  212. }
  213. },
  214. picktwo(e) { //结束时间
  215. this.end = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  216. if (this.newtime < this.oldtime) {
  217. this.tishiTF = true
  218. } else {
  219. this.tishiTF = false
  220. }
  221. },
  222. serter() {
  223. if (this.tishiTF == false) {
  224. this.historydata(this.id)
  225. this.listhistorydata(this.id)
  226. }
  227. },
  228. prev() { //上一页
  229. if (this.page > 1) {
  230. this.page--
  231. this.listhistorydata(this.id)
  232. }
  233. },
  234. next() { //下一页
  235. this.page++
  236. this.listhistorydata(this.id)
  237. },
  238. clickLeft() {
  239. uni.navigateBack({
  240. delta: 1
  241. })
  242. }
  243. },
  244. onLoad(option) {
  245. this.id = option.device_id
  246. this.end = presenttime / 1000
  247. this.begintime = presenttime / 1000 - 24 * 60 * 60
  248. this.historydata(option.device_id)
  249. this.listhistorydata(option.device_id)
  250. }
  251. }
  252. </script>
  253. <style lang="scss">
  254. .graph {
  255. position: absolute;
  256. top: 74px;
  257. width: 90%;
  258. left: 5%;
  259. .none_hint {
  260. font-size: 32rpx;
  261. font-weight: 700;
  262. position: absolute;
  263. top: 0;
  264. left: 50%;
  265. margin-left: -64rpx;
  266. }
  267. }
  268. .shuju_one_title {
  269. width: 70%;
  270. margin: 0 auto;
  271. display: flex;
  272. .tltle_text {
  273. width: 25%;
  274. border: 2rpx solid #B2B2B2;
  275. color: #B2B2B2;
  276. text-align: center;
  277. font-size: 24rpx;
  278. height: 50rpx;
  279. line-height: 50rpx;
  280. }
  281. .title_text_color {
  282. width: 25%;
  283. border: 2rpx solid #28AE4F;
  284. color: #28AE4F;
  285. text-align: center;
  286. font-size: 24rpx;
  287. height: 50rpx;
  288. line-height: 50rpx;
  289. }
  290. }
  291. .selecttimes {
  292. width: 100%;
  293. box-shadow: 0 0 10rpx #bcb9ca;
  294. margin-top: 20rpx;
  295. .tishi {
  296. width: 90%;
  297. margin: 0 auto;
  298. color: #f00000;
  299. text-align: center;
  300. font-size: 24rpx;
  301. }
  302. .btnser {
  303. width: 90%;
  304. margin: 10rpx auto;
  305. color: #FFFFFF;
  306. text-align: center;
  307. font-size: 28rpx;
  308. background-color: #58BD4D;
  309. border-radius: 20rpx;
  310. height: 50rpx;
  311. line-height: 50rpx;
  312. }
  313. .newtimes {
  314. width: 100%;
  315. padding: 20rpx 20rpx;
  316. box-sizing: border-box;
  317. .newtimes_state,
  318. .newtimes_end {
  319. display: flex;
  320. justify-content: space-between;
  321. margin-bottom: 20rpx;
  322. .oldtimes_left {
  323. position: relative;
  324. padding-left: 36rpx;
  325. font-size: 28rpx;
  326. image {
  327. width: 30rpx;
  328. height: 30rpx;
  329. vertical-align: top;
  330. position: absolute;
  331. top: 7rpx;
  332. left: 0;
  333. }
  334. }
  335. }
  336. }
  337. }
  338. .condition {
  339. display: flex;
  340. flex-wrap: wrap;
  341. width: 100%;
  342. box-shadow: 0 0 10rpx #bcb9ca;
  343. margin: 30rpx 0;
  344. .scroll-X {
  345. width: 95%;
  346. margin: 20rpx auto;
  347. .tr {
  348. display: flex;
  349. overflow: hidden;
  350. .th,
  351. .td {
  352. display: inline-block;
  353. padding: 5rpx;
  354. width: 240rpx;
  355. text-align: center;
  356. height: 52rpx;
  357. line-height: 52rpx;
  358. border: 2rpx solid #F1F1F1;
  359. }
  360. // .th:last-child,
  361. // .td:last-child {
  362. // width: 300rpx;
  363. // }
  364. // .th:nth-last-child(2),
  365. // .th:nth-last-child(3),
  366. // .td:nth-last-child(2),
  367. // .td:nth-last-child(3) {
  368. // width: 200rpx;
  369. // }
  370. }
  371. }
  372. .pagenumber {
  373. display: flex;
  374. margin: 20rpx auto;
  375. button {
  376. width: 150rpx;
  377. height: 50rpx;
  378. line-height: 50rpx;
  379. font-size: 26rpx;
  380. text-align: center;
  381. background-color: #17BB89;
  382. color: #FFFFFF;
  383. }
  384. .pagenumber_page {
  385. width: 150rpx;
  386. height: 50rpx;
  387. line-height: 50rpx;
  388. font-size: 26rpx;
  389. text-align: center;
  390. }
  391. }
  392. }
  393. </style>