history-new.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. <template>
  2. <view>
  3. <view class="status_bar"></view>
  4. <view class="" style="position: relative;top: 40px;">
  5. <view style="position: fixed;z-index: 10000000;width: 100%;background-color: #000000;">
  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" v-if="false">
  10. <view class="" style="display: flex;justify-content: flex-end;">
  11. <view class="schedule" @click="pickertfone=!pickertfone">
  12. <p class="schedule_value">{{titletext[indexone]}}</p>
  13. <p class="schedule_icon">
  14. <u-icon name="arrow-down"></u-icon>
  15. </p>
  16. </view>
  17. </view>
  18. <u-picker v-model="pickertfone" mode="selector" @confirm="confirmFun" :default-selector="[indexone]"
  19. :range="titletext"></u-picker>
  20. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  21. 暂无数据
  22. </view>
  23. <view class="canvastishi" v-if="dataloadingtf">
  24. <p class="dataloading">加载中</p>
  25. </view>
  26. <canvas v-show="!tiemshow && !pickertfone" canvas-id="canvasColumnA" id="canvasColumnA" class="charts"
  27. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)"
  28. @touchend="touchEndLineA($event)" disable-scroll=true
  29. :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>
  30. </view>
  31. <view class="selecttimes" @click="tiemshow=!tiemshow">
  32. <view class="timesbox">
  33. <image
  34. :src="$imageURL+'/bigdata_app'+'/image/prevention/1acfe2751c01d3786cdc49b83d7e505.png'"
  35. mode=""></image>
  36. <p>{{timetab(begintime)}}</p>
  37. <p class="or">~</p>
  38. <p>{{timetab(end)}}</p>
  39. <u-icon name="rili" custom-prefix="custom-icon" class="icon"></u-icon>
  40. </view>
  41. <u-calendar v-model="tiemshow" mode="range" @change="tiemchange"></u-calendar>
  42. </view>
  43. <view class="condition" v-if="scrollTF">
  44. <scroll-view scroll-top="0" scroll-x="true" class="scroll-X">
  45. <!-- @scrolltoupper="upper" @scrolltolower="lower" @scroll="scroll" -->
  46. <table class="table" :style="{width:300+240*datalength+'rpx'}">
  47. <tr class="tr">
  48. <th class="th" v-for="(item,index) in thdata" :key="index">
  49. {{item}}</th>
  50. </tr>
  51. <tr class="tr" v-for="(items,index) in tableData" :key="index" v-if="!forbidden">
  52. <td class="td" v-for="(key,value) in items">{{key}}</td>
  53. </tr>
  54. <tr class="tr" v-if="forbidden">
  55. <td class="td" v-for="item in thdata.length">暂无数据</td>
  56. </tr>
  57. </table>
  58. </scroll-view>
  59. <view class="pagenumber">
  60. <button @click="prev">上一页</button>
  61. <view class="pagenumber_page">
  62. 第{{page}}页
  63. </view>
  64. <view class="pagenumber_page">
  65. 共 {{pagesum}} 页
  66. </view>
  67. <button @click="next" :disabled="page==pagesum">下一页</button>
  68. </view>
  69. </view>
  70. </view>
  71. </view>
  72. </view>
  73. </template>
  74. <script>
  75. import uCharts from '../../components/js_sdk/u-charts/u-charts/u-charts.js';
  76. var canvasColumnA = null;
  77. var presenttime = +new Date();
  78. export default {
  79. data() {
  80. return {
  81. cWidth: '400',
  82. cHeight: '400',
  83. pixelRatio: 1,
  84. canvastishiTF: false, //暂无数据提示
  85. dataloadingtf: true, //加载中提示
  86. id: "",
  87. begintime: '', //开始时间
  88. end: '', //结束时间
  89. titletext: [], //折线图数据切换列表数据
  90. titleidnex: 0,
  91. tiemshow: false, //选择时间
  92. tishiTF: false, //提示
  93. historydatas: [],
  94. thdata:[],
  95. tableData:[],
  96. page: 1,
  97. forbidden: false,
  98. pagesum: 1,
  99. datalength: 0,
  100. scrollTF: true,
  101. indexone: 0, //折线图数据切换列表下标
  102. pickertfone: false, //折线图数据切换列表
  103. chartdata: {}, //折线图数据
  104. device_type_id:0
  105. }
  106. },
  107. methods: { //weather.weather.qxz_detail
  108. async listhistorydata(datas) { //上传时间
  109. const res = await this.$myRequest({
  110. url: '/api/api_gateway?method=greenhouse.env_first.history_data',
  111. data: {
  112. device_id: datas,
  113. start: parseInt(this.begintime),
  114. end: parseInt(this.end),
  115. page: this.page
  116. }
  117. })
  118. this.tableData = res.table
  119. this.thdata = res.title
  120. console.log(res)
  121. if (this.thdata == 0) {
  122. this.scrollTF = false
  123. } else {
  124. this.scrollTF = true
  125. }
  126. this.pagesum = Math.ceil(res.total / 10) || 1
  127. if (res.table.length == 0) {
  128. this.forbidden = true
  129. } else {
  130. this.forbidden = false
  131. }
  132. },
  133. async historydata(datas) { //上传时间 //折线图
  134. this.dataloadingtf = true
  135. const res = await this.$myRequest({
  136. url: '/api/api_gateway?method=weather.weather.qxz_data_chart',
  137. data: {
  138. device_id: datas,
  139. begin: parseInt(this.begintime),
  140. end: parseInt(this.end)
  141. }
  142. })
  143. this.dataloadingtf = false
  144. console.log(res)
  145. this.chartdata = res
  146. if (res.data.length == 0) {
  147. this.canvastishiTF = false
  148. } else {
  149. this.canvastishiTF = true
  150. for (var key in res.conf) {
  151. if (res.conf[key]) {
  152. this.titletext.push(res.conf[key])
  153. }
  154. }
  155. this.conflist(res, "e1")
  156. }
  157. },
  158. conflist(res, eindex) {
  159. var xtitle = []
  160. var linearr = []
  161. for (var i = 0; i < res.data.length; i++) {
  162. var times = new Date(res.data[i].time * 1000)
  163. xtitle.unshift(times.getMonth() + 1 + "/" + times.getDate() + "-" + times.getHours() + ":" + times
  164. .getMinutes())
  165. }
  166. var obj = {}
  167. obj.name = res.conf[eindex]
  168. var arr = []
  169. for (var i = 0; i < res.data.length; i++) {
  170. if (parseFloat(((res.data[i].dat)[0][eindex].split('#'))[0]) != -99.99) {
  171. arr.unshift(parseFloat(((res.data[i].dat)[0][eindex].split('#'))[0]))
  172. }
  173. }
  174. obj.data = arr
  175. if (obj.name) {
  176. linearr.push(obj)
  177. }
  178. this.canvastishiTF = linearr.some((item) => {
  179. return item.data.length != 0;
  180. })
  181. console.log(this.canvastishiTF)
  182. this.showColumn("canvasColumnA", xtitle, linearr)
  183. },
  184. confirmFun(index) {
  185. console.log(index)
  186. this.indexone = index[0]
  187. var str = 'e' + (index[0] + 1)
  188. console.log(str)
  189. this.conflist(this.chartdata, str)
  190. },
  191. tiemchange(e){
  192. console.log(e)
  193. this.page =1
  194. this.begintime = +new Date(e.startDate)/1000
  195. this.end = +new Date(e.endDate)/1000+16*60*60-1
  196. // this.historydata(this.id)
  197. this.listhistorydata(this.id)
  198. },
  199. prev() { //上一页
  200. if (this.page > 1) {
  201. this.page--
  202. this.listhistorydata(this.id)
  203. }
  204. },
  205. next() { //下一页
  206. this.page++
  207. this.listhistorydata(this.id)
  208. },
  209. clickLeft() {
  210. uni.navigateBack({
  211. delta: 1
  212. })
  213. },
  214. timetab(e){
  215. e = new Date(e*1000)
  216. var year = e.getFullYear()
  217. var month = e.getMonth()+1<10?"0"+(e.getMonth()+1):e.getMonth()+1
  218. var day = e.getDate()<10?"0"+e.getDate():e.getDate()
  219. var time = year + "/" + month + "/" + day
  220. return time
  221. },
  222. showColumn(id, xtitle, xinfo) {
  223. var _self = this
  224. const ctx = uni.createCanvasContext(id, this);
  225. canvasColumnA = new uCharts({
  226. context: ctx,
  227. type: 'line',
  228. legend: {
  229. position: "top"
  230. },
  231. fontSize: 11,
  232. background: '#FFFFFF',
  233. pixelRatio: 1,
  234. animation: true,
  235. dataLabel: false,
  236. categories: xtitle,
  237. series: xinfo,
  238. enableScroll: true, //开启图表拖拽功能
  239. xAxis: {
  240. disableGrid: true,
  241. type: 'grid',
  242. gridType: 'dash',
  243. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  244. scrollShow: true, //新增是否显示滚动条,默认false
  245. // scrollAlign: 'left', //滚动条初始位置
  246. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  247. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  248. },
  249. yAxis: {},
  250. width: _self.cWidth * 1,
  251. height: _self.cHeight * 1,
  252. extra: {
  253. line: {
  254. type: 'curve'
  255. }
  256. }
  257. });
  258. },
  259. touchLineA(e) {
  260. canvasColumnA.scrollStart(e);
  261. },
  262. moveLineA(e) {
  263. canvasColumnA.scroll(e);
  264. },
  265. touchEndLineA(e) {
  266. canvasColumnA.scrollEnd(e);
  267. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  268. canvasColumnA.showToolTip(e, {
  269. format: function(item, category) {
  270. return category + ' ' + item.name + ':' + item.data
  271. }
  272. });
  273. },
  274. },
  275. onLoad(option) {
  276. this.cWidth = uni.upx2px(650);
  277. this.cHeight = uni.upx2px(500);
  278. this.id = option.device_id
  279. this.device_type_id = option.device_type_id
  280. this.end = presenttime / 1000
  281. this.begintime = presenttime / 1000 - 24 * 60 * 60
  282. // console.log(new Date(1616145097 * 1000), new Date(1616231497 * 1000))
  283. console.log(option.device_id)
  284. // this.historydata(option.device_id)
  285. this.listhistorydata(option.device_id)
  286. }
  287. }
  288. </script>
  289. <style lang="scss">
  290. .graph {
  291. position: absolute;
  292. top: 54px;
  293. width: 90%;
  294. left: 5%;
  295. .canvasbox {
  296. width: 100%;
  297. height: 550rpx;
  298. position: relative;
  299. box-shadow: 0 0 10rpx #bcb9ca;
  300. padding-top: 20px;
  301. .charts {}
  302. .canvastishi {
  303. font-size: 32rpx;
  304. position: absolute;
  305. top: 50%;
  306. left: 50%;
  307. margin-left: -64rpx;
  308. margin-top: -21rpx;
  309. .dataloading:after {
  310. overflow: hidden;
  311. display: inline-block;
  312. vertical-align: bottom;
  313. animation: ellipsis 2s infinite;
  314. content: "\2026";
  315. }
  316. @keyframes ellipsis {
  317. from {
  318. width: 2px;
  319. }
  320. to {
  321. width: 15px;
  322. }
  323. }
  324. }
  325. .schedule {
  326. display: flex;
  327. width: 280rpx;
  328. height: 50rpx;
  329. border: 2rpx solid #F0F0F0;
  330. margin-right: 40rpx;
  331. .schedule_value {
  332. width: 70%;
  333. text-align: center;
  334. line-height: 50rpx;
  335. font-size: 24rpx;
  336. }
  337. .schedule_icon {
  338. width: 30%;
  339. background-color: #F2F2F2;
  340. text-align: center;
  341. line-height: 50rpx;
  342. }
  343. }
  344. }
  345. .none_hint {
  346. font-size: 32rpx;
  347. font-weight: 700;
  348. position: absolute;
  349. top: 0;
  350. left: 50%;
  351. margin-left: -64rpx;
  352. }
  353. }
  354. .shuju_one_title {
  355. width: 70%;
  356. margin: 0 auto;
  357. display: flex;
  358. .tltle_text {
  359. width: 25%;
  360. border: 2rpx solid #B2B2B2;
  361. color: #B2B2B2;
  362. text-align: center;
  363. font-size: 24rpx;
  364. height: 50rpx;
  365. line-height: 50rpx;
  366. }
  367. .title_text_color {
  368. width: 25%;
  369. border: 2rpx solid #28AE4F;
  370. color: #28AE4F;
  371. text-align: center;
  372. font-size: 24rpx;
  373. height: 50rpx;
  374. line-height: 50rpx;
  375. }
  376. }
  377. .selecttimes {
  378. width: 100%;
  379. box-shadow: 0 0 10rpx #bcb9ca;
  380. margin-top: 20rpx;
  381. padding: 10rpx 20rpx;
  382. box-sizing: border-box;
  383. .timesbox {
  384. display: flex;
  385. justify-content: space-around;
  386. image {
  387. width: 30rpx;
  388. height: 30rpx;
  389. margin-top: 6rpx;
  390. }
  391. .icon {
  392. color: #949494;
  393. text-align: right;
  394. margin-left: 30rpx;
  395. }
  396. }
  397. }
  398. .condition {
  399. display: flex;
  400. flex-wrap: wrap;
  401. width: 100%;
  402. box-shadow: 0 0 10rpx #bcb9ca;
  403. margin: 30rpx 0;
  404. .scroll-X {
  405. width: 95%;
  406. margin: 20rpx auto;
  407. .table {
  408. // width: 10420px;
  409. }
  410. .tr {
  411. display: flex;
  412. overflow: hidden;
  413. .th,
  414. .td {
  415. display: inline-block;
  416. padding: 5rpx;
  417. width: 240rpx;
  418. text-align: center;
  419. height: 52rpx;
  420. line-height: 52rpx;
  421. border: 2rpx solid #F1F1F1;
  422. }
  423. .th:first-child,
  424. .td:first-child {
  425. width: 300rpx;
  426. }
  427. }
  428. }
  429. .pagenumber {
  430. display: flex;
  431. margin: 20rpx auto;
  432. button {
  433. width: 150rpx;
  434. height: 50rpx;
  435. line-height: 50rpx;
  436. font-size: 26rpx;
  437. text-align: center;
  438. background-color: #17BB89;
  439. color: #FFFFFF;
  440. }
  441. .pagenumber_page {
  442. width: 150rpx;
  443. height: 50rpx;
  444. line-height: 50rpx;
  445. font-size: 26rpx;
  446. text-align: center;
  447. }
  448. }
  449. }
  450. /deep/.u-calendar__action {
  451. display: flex;
  452. justify-content: space-around;
  453. .u-calendar__action__text {
  454. line-height: 25px;
  455. }
  456. }
  457. </style>