pestLine.vue 11 KB

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