pestLine.vue 9.6 KB

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