history.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411
  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 = 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. this.$forceUpdate()
  202. },
  203. pickone(e) {//开始时间
  204. this.begintime = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  205. if (this.newtime < this.oldtime) {
  206. this.tishiTF = true
  207. } else {
  208. this.tishiTF = false
  209. }
  210. },
  211. picktwo(e) {//结束时间
  212. this.end = +new Date(e.year, e.month - 1, e.day, e.hour, e.minute) / 1000
  213. if (this.newtime < this.oldtime) {
  214. this.tishiTF = true
  215. } else {
  216. this.tishiTF = false
  217. }
  218. },
  219. serter() {
  220. if (this.tishiTF == false) {
  221. this.historydata(this.id)
  222. this.listhistorydata(this.id)
  223. }
  224. },
  225. prev(){//上一页
  226. if(this.page>1){
  227. this.page--
  228. this.listhistorydata(this.id)
  229. }
  230. },
  231. next(){//下一页
  232. this.page++
  233. this.listhistorydata(this.id)
  234. },
  235. clickLeft(){
  236. uni.navigateBack({
  237. delta:1
  238. })
  239. }
  240. },
  241. onLoad(option) {
  242. this.id = option.device_id
  243. this.end = presenttime / 1000
  244. this.begintime = presenttime / 1000 - 24 * 60 * 60
  245. this.historydata(option.device_id)
  246. this.listhistorydata(option.device_id)
  247. }
  248. }
  249. </script>
  250. <style lang="scss">
  251. .graph {
  252. position: absolute;
  253. top: 74px;
  254. width: 90%;
  255. left: 5%;
  256. .none_hint {
  257. font-size: 32rpx;
  258. font-weight: 700;
  259. position: absolute;
  260. top: 70%;
  261. left: 50%;
  262. margin-left: -64rpx;
  263. }
  264. }
  265. .shuju_one_title {
  266. width: 70%;
  267. margin: 0 auto;
  268. display: flex;
  269. .tltle_text {
  270. width: 25%;
  271. border: 2rpx solid #B2B2B2;
  272. color: #B2B2B2;
  273. text-align: center;
  274. font-size: 24rpx;
  275. height: 50rpx;
  276. line-height: 50rpx;
  277. }
  278. .title_text_color {
  279. width: 25%;
  280. border: 2rpx solid #28AE4F;
  281. color: #28AE4F;
  282. text-align: center;
  283. font-size: 24rpx;
  284. height: 50rpx;
  285. line-height: 50rpx;
  286. }
  287. }
  288. .selecttimes {
  289. width: 100%;
  290. box-shadow: 0 0 10rpx #bcb9ca;
  291. margin-top: 20rpx;
  292. .tishi {
  293. width: 90%;
  294. margin: 0 auto;
  295. color: #f00000;
  296. text-align: center;
  297. font-size: 24rpx;
  298. }
  299. .btnser {
  300. width: 90%;
  301. margin: 10rpx auto;
  302. color: #FFFFFF;
  303. text-align: center;
  304. font-size: 28rpx;
  305. background-color: #58BD4D;
  306. border-radius: 20rpx;
  307. height: 50rpx;
  308. line-height: 50rpx;
  309. }
  310. .newtimes {
  311. width: 100%;
  312. padding: 20rpx 20rpx;
  313. .newtimes_state,
  314. .newtimes_end {
  315. display: flex;
  316. justify-content: space-between;
  317. margin-bottom: 20rpx;
  318. .oldtimes_left {
  319. position: relative;
  320. padding-left: 36rpx;
  321. font-size: 28rpx;
  322. image {
  323. width: 30rpx;
  324. height: 30rpx;
  325. vertical-align: top;
  326. position: absolute;
  327. top: 7rpx;
  328. left: 0;
  329. }
  330. }
  331. }
  332. }
  333. }
  334. .condition {
  335. display: flex;
  336. flex-wrap: wrap;
  337. width: 100%;
  338. box-shadow: 0 0 10rpx #bcb9ca;
  339. margin:30rpx 0;
  340. .scroll-X {
  341. width: 95%;
  342. margin: 20rpx auto;
  343. .tr {
  344. display: flex;
  345. overflow: hidden;
  346. .th,
  347. .td {
  348. display: inline-block;
  349. padding: 5rpx;
  350. width: 240rpx;
  351. text-align: center;
  352. height: 52rpx;
  353. line-height: 52rpx;
  354. border: 2rpx solid #F1F1F1;
  355. }
  356. // .th:last-child,
  357. // .td:last-child {
  358. // width: 300rpx;
  359. // }
  360. // .th:nth-last-child(2),
  361. // .th:nth-last-child(3),
  362. // .td:nth-last-child(2),
  363. // .td:nth-last-child(3) {
  364. // width: 200rpx;
  365. // }
  366. }
  367. }
  368. .pagenumber {
  369. display: flex;
  370. margin: 20rpx auto;
  371. button {
  372. width: 150rpx;
  373. height: 50rpx;
  374. line-height: 50rpx;
  375. font-size: 26rpx;
  376. text-align: center;
  377. background-color: #17BB89;
  378. color: #FFFFFF;
  379. }
  380. .pagenumber_page {
  381. width: 150rpx;
  382. height: 50rpx;
  383. line-height: 50rpx;
  384. font-size: 26rpx;
  385. text-align: center;
  386. }
  387. }
  388. }
  389. </style>