history-new.vue 12 KB

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