pestLine.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view>
  3. <view class="title">虫情趋势矩阵图</view>
  4. <view class="shuju_one">
  5. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  6. 暂无数据
  7. </view>
  8. <view class="canvastishi" v-if="dataloadingtf">
  9. <p class="dataloading">加载中</p>
  10. </view>
  11. <canvas v-show="canvastishiTF" canvas-id="canvasColumnB" id="canvasColumnB" class="charts"
  12. @touchstart="touchLineA($event)" @touchmove="moveLineA($event)" @touchend="touchEndLineA($event)"
  13. disable-scroll=true
  14. :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>
  15. </view>
  16. <view class="title">害虫排名</view>
  17. <view class="shuju_one">
  18. <view class="canvastishi" v-if="!canvastishiTF && !dataloadingtf">
  19. 暂无数据
  20. </view>
  21. <view class="canvastishi" v-if="dataloadingtf">
  22. <p class="dataloading">加载中</p>
  23. </view>
  24. <canvas v-show="canvastishiTF" canvas-id="canvasColumnC" id="canvasColumnC" class="charts"
  25. :style="{'width':cWidth*pixelRatio+'px','height':pestHeight*pixelRatio+'px', 'transform': 'scale('+(1/pixelRatio)+')','margin-left':-cWidth*(pixelRatio-1)/2+'px','margin-top':-cHeight*(pixelRatio-1)/2+'px'}"></canvas>
  26. </view>
  27. </view>
  28. </template>
  29. <script>
  30. import uCharts from '../../../../components/js_sdk/u-charts/u-charts/u-charts.js';
  31. let canvaColumnA = null;
  32. let canvaColumnB = null;
  33. const myColor = ['#FF5951', '#66EDED', '#E67B3E', '#6DE28B', '#FFC97A', '#E7EB4B', '#1561F3', '#FA73F5', '#159AFF',
  34. '#FA73F5'
  35. ]
  36. const temColor = ['#A2845E', '#018B3F', '#00C7BE']
  37. export default {
  38. data() {
  39. return {
  40. cWidth: '400',
  41. cHeight: '400',
  42. pixelRatio: 1,
  43. canvastishiTF: false, //暂无数据提示
  44. dataloadingtf: true, //加载中提示
  45. pestHeight: '400',
  46. }
  47. },
  48. props: {
  49. start_time: {
  50. type: String,
  51. default: ''
  52. },
  53. end_time: {
  54. type: String,
  55. default: ''
  56. },
  57. device_type_id: {
  58. type: String,
  59. default: '35'
  60. },
  61. d_id: {
  62. type: String,
  63. default: 0
  64. },
  65. notify: {
  66. type: Number,
  67. default: 0
  68. }
  69. },
  70. watch: {
  71. notify: {
  72. handler() {
  73. this.pestLine()
  74. }
  75. }
  76. },
  77. computed: {
  78. },
  79. methods: {
  80. async pestLine() { //害虫趋势折线图
  81. this.dataloadingtf = true
  82. const res = await this.$myRequest({
  83. url: '/api/api_gateway?method=new_gateway.photo_info.pest_order_and_char',
  84. data: {
  85. device_type_id: this.device_type_id,
  86. id: this.d_id,
  87. // device_type_id: 35,
  88. // id: '11630161',
  89. start: +new Date(this.start_time + ' 00:00:00') / 1000,
  90. end: +new Date(this.end_time + ' 23:59:59') / 1000,
  91. hour_st: '00',
  92. hour_ed: '00'
  93. }
  94. })
  95. this.dataloadingtf = false
  96. const {
  97. char_data,
  98. pest_total,
  99. at_ah_info: atah
  100. } = res
  101. console.log(res, '---------')
  102. if (Object.keys(char_data).length == 0) {
  103. this.canvastishiTF = false
  104. } else {
  105. this.canvastishiTF = true
  106. let arr1 = []
  107. let arr2 = []
  108. let arr3 = []
  109. let xtitle = []
  110. for (let i = 0; i < atah.length; i++) {
  111. xtitle.push(this.formatTime(atah[i].addtime * 1000, 'yyyy-MM-dd'))
  112. arr1.push(atah[i].height ? atah[i].height : 0)
  113. arr2.push(atah[i].low ? atah[i].low : 0)
  114. arr3.push(atah[i].ah ? atah[i].ah : 0)
  115. }
  116. // console.log(arr1)
  117. let objList = [{
  118. name: '高温',
  119. data: arr1
  120. }, {
  121. name: '低温',
  122. data: arr2
  123. }, {
  124. name: '湿度',
  125. data: arr3
  126. }]
  127. Object.keys(char_data).forEach((item, index) => {
  128. let countData = []
  129. char_data[item].forEach((item1, index1) => {
  130. countData.push(item1.sum)
  131. })
  132. let obj = {
  133. name: item,
  134. data: countData
  135. }
  136. objList.push(obj)
  137. })
  138. const pestName = Object.keys(pest_total)
  139. const dataList = Object.values(pest_total).reverse().map((value, index) => {
  140. let i = index % pestName.length
  141. return {
  142. value,
  143. color: myColor[i]
  144. }
  145. })
  146. const pestTotal = [{
  147. name: '排名',
  148. data: dataList
  149. }]
  150. this.showColumn("canvasColumnB", xtitle, objList)
  151. this.showColumnBar("canvasColumnC", pestName.reverse(), pestTotal)
  152. }
  153. },
  154. showColumn(id, xtitle, xinfo, yAxis) {
  155. console.log(xinfo)
  156. let _self = this
  157. if (xinfo.length > 12) {
  158. this.cHeight = xinfo.length * 15
  159. }
  160. // const canvas = document.getElementById(id);
  161. // const ctx = canvas.getContext("2d");
  162. const ctx = uni.createCanvasContext(id, this);
  163. canvaColumnA = new uCharts({
  164. context: ctx,
  165. type: 'line',
  166. legend: {
  167. position: "top"
  168. },
  169. fontSize: 11,
  170. background: '#FFFFFF',
  171. pixelRatio: 1,
  172. animation: true,
  173. dataLabel: false,
  174. categories: xtitle,
  175. series: xinfo,
  176. color: [...temColor, ...myColor],
  177. enableScroll: true, //开启图表拖拽功能
  178. xAxis: {
  179. disableGrid: true,
  180. type: 'grid',
  181. gridType: 'dash',
  182. itemCount: 4, //x轴单屏显示数据的数量,默认为5个
  183. scrollShow: true, //新增是否显示滚动条,默认false
  184. // scrollAlign: 'left', //滚动条初始位置
  185. scrollBackgroundColor: '#F7F7FF', //默认为 #EFEBEF
  186. scrollColor: '#DEE7F7', //默认为 #A6A6A6
  187. },
  188. yAxis: yAxis || {},
  189. width: _self.cWidth * 1,
  190. height: _self.cHeight * 1,
  191. extra: {
  192. line: {
  193. type: 'curve'
  194. }
  195. }
  196. });
  197. },
  198. showColumnBar(id, xtitle, xinfo) {
  199. console.log(xtitle, xinfo)
  200. let _self = this
  201. if (xtitle.length > 12) {
  202. this.pestHeight = xtitle.length * 20
  203. }
  204. const ctx = uni.createCanvasContext(id, this);
  205. canvaColumnB = new uCharts({
  206. context: ctx,
  207. type: 'bar',
  208. legend: {
  209. show: false
  210. },
  211. padding: [5, 25, 5, 0],
  212. fontSize: 11,
  213. background: '#FFFFFF',
  214. pixelRatio: 1,
  215. animation: true,
  216. // dataLabel: false,
  217. categories: xtitle,
  218. series: xinfo,
  219. // enableScroll: true, //开启图表拖拽功能
  220. xAxis: {
  221. boundaryGap: "justify",
  222. disableGrid: false,
  223. axisLine: false
  224. },
  225. yAxis: {
  226. },
  227. width: _self.cWidth * 1,
  228. height: _self.pestHeight * 1,
  229. extra: {
  230. bar: {
  231. type: "group",
  232. width: 30,
  233. barBorderCircle: true,
  234. seriesGap: 4,
  235. categoryGap: 4
  236. }
  237. }
  238. });
  239. },
  240. touchLineA(e) {
  241. console.log(e)
  242. canvaColumnA.scrollStart(e);
  243. },
  244. moveLineA(e) {
  245. canvaColumnA.scroll(e);
  246. },
  247. touchEndLineA(e) {
  248. canvaColumnA.scrollEnd(e);
  249. //下面是toolTip事件,如果滚动后不需要显示,可不填写
  250. canvaColumnA.showToolTip(e, {
  251. format: function(item, category) {
  252. return category + ' ' + item.name + ':' + item.data
  253. }
  254. });
  255. },
  256. touchLineB(e) {
  257. console.log(e)
  258. canvaColumnB.scrollStart(e);
  259. },
  260. moveLineB(e) {
  261. canvaColumnB.scroll(e);
  262. },
  263. touchEndLineB(e) {
  264. canvaColumnB.scrollEnd(e);
  265. },
  266. },
  267. mounted() {
  268. this.cWidth = uni.upx2px(650);
  269. this.cHeight = uni.upx2px(500);
  270. this.pestLine()
  271. console.log('mounted')
  272. },
  273. onLoad() {
  274. console.log('load')
  275. },
  276. onShow() {
  277. console.log('show')
  278. },
  279. }
  280. </script>
  281. <style lang="scss" scoped>
  282. page {
  283. background: #f7f7f7;
  284. }
  285. .title {
  286. color: #999999;
  287. margin: 32rpx 0;
  288. }
  289. .date {
  290. height: 92rpx;
  291. line-height: 92rpx;
  292. border-radius: 92rpx;
  293. background: #fff;
  294. display: flex;
  295. justify-content: space-between;
  296. margin-top: 16rpx;
  297. padding: 0 48rpx;
  298. position: relative;
  299. /deep/.u-calendar__action {
  300. display: flex;
  301. justify-content: space-around;
  302. .u-calendar__action__text {
  303. line-height: 25px;
  304. }
  305. }
  306. }
  307. .shuju_one,
  308. .shuju_two {
  309. // position: absolute;
  310. // top: 54px;
  311. width: 100%;
  312. // left: 5%;
  313. // box-shadow: 0 0 10rpx #bcb9ca;
  314. padding-top: 20rpx;
  315. height: 550rpx;
  316. background-color: #fff;
  317. border-radius: 24rpx;
  318. overflow: scroll;
  319. position: relative;
  320. .canvastishi {
  321. font-size: 32rpx;
  322. position: absolute;
  323. top: 50%;
  324. left: 50%;
  325. margin-left: -64rpx;
  326. margin-top: -21rpx;
  327. .dataloading:after {
  328. overflow: hidden;
  329. display: inline-block;
  330. vertical-align: bottom;
  331. animation: ellipsis 2s infinite;
  332. content: "\2026";
  333. }
  334. @keyframes ellipsis {
  335. from {
  336. width: 2px;
  337. }
  338. to {
  339. width: 15px;
  340. }
  341. }
  342. }
  343. }
  344. .refresh {
  345. // position: absolute;
  346. // top: 700rpx;
  347. // left: 5%;
  348. font-size: 12px;
  349. float: right;
  350. padding: 0 10rpx;
  351. height: 40rpx;
  352. border-radius: 8rpx;
  353. background-color: #018B3F;
  354. color: #FFFFFF;
  355. line-height: 40rpx;
  356. text-align: center;
  357. }
  358. .condition {
  359. // position: absolute;
  360. // top: 770rpx;
  361. display: flex;
  362. flex-wrap: wrap;
  363. width: 100%;
  364. // left: 5%;
  365. // box-shadow: 0 0 10rpx #bcb9ca;
  366. margin-bottom: 30rpx;
  367. .scroll-X {
  368. width: 100%;
  369. margin: 20rpx auto;
  370. .table {
  371. width: 1672px;
  372. }
  373. .tr {
  374. display: flex;
  375. overflow: hidden;
  376. .th,
  377. .td {
  378. display: inline-block;
  379. padding: 4rpx;
  380. width: 286rpx;
  381. text-align: center;
  382. height: 52rpx;
  383. line-height: 52rpx;
  384. border: 2rpx solid #F1F1F1;
  385. }
  386. .th:first-child,
  387. .td:first-child {
  388. width: 300rpx;
  389. }
  390. }
  391. .tr:nth-child(2n-1) {
  392. background-color: #f5fff8;
  393. }
  394. .tr:first-child {
  395. background-color: #57c878;
  396. color: #fff;
  397. }
  398. }
  399. .pagenumber {
  400. display: flex;
  401. margin: 20rpx auto;
  402. button {
  403. width: 150rpx;
  404. height: 50rpx;
  405. line-height: 50rpx;
  406. font-size: 26rpx;
  407. text-align: center;
  408. background-color: #17BB89;
  409. color: #FFFFFF;
  410. }
  411. .pagenumber_page {
  412. width: 100rpx;
  413. height: 50rpx;
  414. line-height: 50rpx;
  415. font-size: 26rpx;
  416. text-align: center;
  417. }
  418. }
  419. }
  420. </style>