history.vue 9.8 KB

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