history.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  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. chart: {
  77. type: 'spline', //指定图表的类型,默认是折线图(line)
  78. zoomType: 'x',
  79. panning: true,
  80. panKey: 'shift'
  81. },
  82. title: {
  83. text: '' // 标题
  84. },
  85. credits: {
  86. enabled: false
  87. },
  88. xAxis: {
  89. type: 'datetime',
  90. crosshair: true, //十字基准线
  91. dateTimeLabelFormats: {
  92. //根据时间间距X轴自动显示哪种格式
  93. millisecond: "%H:%M:%S.%L",
  94. second: "%H:%M:%S",
  95. minute: "%H:%M",
  96. hour: "%H:%M",
  97. day: "%m-%d",
  98. week: "%m-%d",
  99. month: "%Y-%m",
  100. year: "%Y",
  101. },
  102. },
  103. yAxis: {
  104. title: false,
  105. },
  106. legend: {
  107. // layout: 'vertical',
  108. // align: "center",
  109. // verticalAlign: "top",
  110. },
  111. tooltip: {
  112. // crosshairs: true,
  113. shared: true, //折线共享
  114. headerFormat: "<b>{point.x:%Y-%m-%e %H:%M:%S}</b><br>",
  115. },
  116. plotOptions: {
  117. spline: {
  118. marker: {
  119. enabled: false
  120. },
  121. }
  122. },
  123. series: [],
  124. },
  125. id: "",
  126. begintime: '', //开始时间
  127. end: '', //结束时间
  128. titletext: ["24小时", "近一个月", "近半年", "近一年"],
  129. titleidnex: 0,
  130. pickshow: false, //选择时间一
  131. picktwoshow: false, //选择时间二
  132. params: { //时间格式
  133. year: true,
  134. month: true,
  135. day: true,
  136. hour: true,
  137. minute: true,
  138. second: false
  139. },
  140. tishiTF: false, //提示
  141. historydatas: [],
  142. page:1,
  143. forbidden:false
  144. }
  145. },
  146. methods: { //weather.weather.qxz_detail
  147. async listhistorydata(datas) { //上传时间
  148. const res = await this.$myRequest({
  149. url: '/api/api_gateway?method=weather.weather.qxz_detail',
  150. data: {
  151. device_id: datas,
  152. begin: parseInt(this.begintime),
  153. end: parseInt(this.end),
  154. page:this.page
  155. }
  156. })
  157. this.historydatas = res
  158. console.log(this.historydatas)
  159. if(res.data.length==0){
  160. this.forbidden = true
  161. }else{
  162. this.forbidden = false
  163. }
  164. },
  165. async historydata(datas) { //上传时间
  166. const res = await this.$myRequest({
  167. url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
  168. data: {
  169. device_id: datas,
  170. begin: parseInt(this.begintime),
  171. end: parseInt(this.end)
  172. }
  173. })
  174. // this.options.series[0].name = res.conf.e1.replace("#","(") + ")"
  175. console.log(res)
  176. for (var Key in res.conf) {
  177. let obj = {}
  178. if (res.conf[Key] != '') {
  179. obj.name = Key + res.conf[Key].replace("#", "(") + ")"
  180. obj.data = []
  181. obj.color = "rgb(" + parseInt(Math.random() * 256) + "," + parseInt(Math.random() * 256) + "," + parseInt(Math.random() *
  182. 256) + ")"
  183. this.options.series.push(obj)
  184. }
  185. }
  186. for (var i = 0; i < res.data.length; i++) {
  187. for (var key in res.data[i].dat) {
  188. if (res.data[i].dat[key] != "") {
  189. let arr = []
  190. if (parseFloat(res.data[i].dat[key]) != -99.99) {
  191. arr.push(res.data[i].time * 1000 + 8 * 3600000, parseFloat(res.data[i].dat[key]))
  192. for (var j = 0; j < this.options.series.length; j++) {
  193. if (this.options.series[j].name.indexOf(key) != -1) {
  194. this.options.series[j].data.push(arr)
  195. }
  196. }
  197. }
  198. }
  199. }
  200. }
  201. if (this.options.series[0].data.length == 0) {
  202. console.log(1)
  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.id
  246. this.end = presenttime / 1000
  247. this.begintime = presenttime / 1000 - 24 * 60 * 60
  248. this.historydata(option.id)
  249. this.listhistorydata(option.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: 70%;
  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. .newtimes_state,
  317. .newtimes_end {
  318. display: flex;
  319. justify-content: space-between;
  320. margin-bottom: 20rpx;
  321. .oldtimes_left {
  322. position: relative;
  323. padding-left: 36rpx;
  324. font-size: 28rpx;
  325. image {
  326. width: 30rpx;
  327. height: 30rpx;
  328. vertical-align: top;
  329. position: absolute;
  330. top: 7rpx;
  331. left: 0;
  332. }
  333. }
  334. }
  335. }
  336. }
  337. .condition {
  338. display: flex;
  339. flex-wrap: wrap;
  340. width: 100%;
  341. box-shadow: 0 0 10rpx #bcb9ca;
  342. margin:30rpx 0;
  343. .scroll-X {
  344. width: 95%;
  345. margin: 20rpx auto;
  346. .tr {
  347. display: flex;
  348. overflow: hidden;
  349. .th,
  350. .td {
  351. display: inline-block;
  352. padding: 5rpx;
  353. width: 240rpx;
  354. text-align: center;
  355. height: 52rpx;
  356. line-height: 52rpx;
  357. border: 2rpx solid #F1F1F1;
  358. }
  359. // .th:last-child,
  360. // .td:last-child {
  361. // width: 300rpx;
  362. // }
  363. // .th:nth-last-child(2),
  364. // .th:nth-last-child(3),
  365. // .td:nth-last-child(2),
  366. // .td:nth-last-child(3) {
  367. // width: 200rpx;
  368. // }
  369. }
  370. }
  371. .pagenumber {
  372. display: flex;
  373. margin: 20rpx auto;
  374. button {
  375. width: 150rpx;
  376. height: 50rpx;
  377. line-height: 50rpx;
  378. font-size: 26rpx;
  379. text-align: center;
  380. background-color: #17BB89;
  381. color: #FFFFFF;
  382. }
  383. .pagenumber_page {
  384. width: 150rpx;
  385. height: 50rpx;
  386. line-height: 50rpx;
  387. font-size: 26rpx;
  388. text-align: center;
  389. }
  390. }
  391. }
  392. </style>