history-new.vue 12 KB

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