rodentAnalysis.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. <template>
  2. <view class="rodent-analysis">
  3. <!-- 活动节律分析 -->
  4. <view class="analysis-card">
  5. <view class="analysis-card__header">
  6. <view class="analysis-card__title">活动节律分析</view>
  7. <view class="analysis-card__extra">
  8. <text class="peak-label">活跃高峰</text>
  9. <text class="peak-value">{{ peakRange }}</text>
  10. </view>
  11. </view>
  12. <view class="chart-legend">
  13. <view class="chart-legend__dot chart-legend__dot--bar"></view>
  14. <text class="chart-legend__text">鼠害数量</text>
  15. </view>
  16. <view class="chart-wrap chart-wrap--rhythm">
  17. <qiun-data-charts
  18. type="column"
  19. :chartData="rhythmChart"
  20. :opts="rhythmOpts"
  21. :reshow="active"
  22. :canvas2d="true"
  23. :inScrollView="true"
  24. :ontouch="true"
  25. />
  26. </view>
  27. </view>
  28. <!-- 群落结构分析 -->
  29. <view class="analysis-card">
  30. <view class="analysis-card__header">
  31. <view class="analysis-card__title">群落结构分析</view>
  32. </view>
  33. <view class="community-content">
  34. <view class="chart-wrap chart-wrap--ring">
  35. <qiun-data-charts
  36. type="ring"
  37. :chartData="communityChart"
  38. :opts="communityOpts"
  39. :reshow="active"
  40. :canvas2d="true"
  41. :inScrollView="true"
  42. :ontouch="true"
  43. />
  44. </view>
  45. <view class="community-total">
  46. <text>总鼠害数量</text>
  47. <text class="total-value">{{ totalCount }}
  48. <text class="unit">只</text>
  49. </text>
  50. </view>
  51. <view class="community-list">
  52. <view
  53. class="community-item"
  54. v-for="(item, index) in communityList"
  55. :key="index"
  56. >
  57. <view class="community-item__dot" :style="{ background: item.color }"></view>
  58. <view class="community-item__name">{{ item.name }}</view>
  59. <view class="community-item__count">{{ item.count }}只</view>
  60. <view class="community-item__percent">{{ item.percent }}%</view>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. <!-- 鼠情发生量与气象关系 -->
  66. <view class="analysis-card">
  67. <view class="analysis-card__header">
  68. <view class="analysis-card__title">鼠情发生量与气象关系</view>
  69. <view class="range-tabs">
  70. <view
  71. class="range-tab"
  72. :class="{ active: weatherRange === 'week' }"
  73. @click="switchRange('week')"
  74. >周</view>
  75. <view
  76. class="range-tab"
  77. :class="{ active: weatherRange === 'month' }"
  78. @click="switchRange('month')"
  79. >月</view>
  80. <view
  81. class="range-tab"
  82. :class="{ active: weatherRange === 'year' }"
  83. @click="switchRange('year')"
  84. >年</view>
  85. </view>
  86. </view>
  87. <view class="chart-wrap chart-wrap--weather">
  88. <qiun-data-charts
  89. type="mix"
  90. :chartData="weatherChart"
  91. :opts="weatherOpts"
  92. :reshow="active"
  93. :canvas2d="true"
  94. :inScrollView="true"
  95. :ontouch="true"
  96. />
  97. </view>
  98. </view>
  99. </view>
  100. </template>
  101. <script>
  102. // 鼠情发生量与气象关系 mock 数据
  103. const WEATHER_MOCK = {
  104. month: {
  105. categories: ['8-1','8-16','8-20','8-29','9-1','9-28','10-1','10-28','11-1','11-28','12-9'],
  106. pest: [12, 18, 25, 15, 32, 28, 40, 35, 22, 45, 38],
  107. temp: [28, 30, 26, 22, 25, 18, 15, 20, 24, 12, 8],
  108. humidity: [45, 42, 48, 40, 38, 44, 46, 42, 37, 48, 43]
  109. },
  110. week: {
  111. categories: ['8-12','8-13','8-14','8-15','8-16','8-17','8-18'],
  112. pest: [8, 15, 22, 12, 28, 35, 20],
  113. temp: [26, 28, 30, 29, 27, 25, 26],
  114. humidity: [40, 36, 32, 45, 48, 46, 42]
  115. },
  116. year: {
  117. categories: ['1月','2月','3月','4月','5月','6月','7月','8月','9月','10月','11月','12月'],
  118. pest: [35, 28, 22, 18, 15, 20, 32, 45, 48, 42, 38, 30],
  119. temp: [5, 8, 14, 20, 26, 30, 32, 31, 26, 20, 12, 6],
  120. humidity: [30, 34, 40, 44, 48, 46, 48, 46, 42, 40, 36, 32]
  121. }
  122. };
  123. function buildWeatherChart(range) {
  124. const mock = WEATHER_MOCK[range];
  125. return {
  126. categories: mock.categories,
  127. series: [
  128. { name: '鼠害总数', type: 'area', style: 'curve', index: 0, data: mock.pest },
  129. { name: '温度', type: 'line', style: 'curve', index: 1, data: mock.temp },
  130. { name: '湿度', type: 'line', style: 'curve', index: 1, data: mock.humidity }
  131. ]
  132. };
  133. }
  134. export default {
  135. name: 'RodentAnalysis',
  136. props: {
  137. // 当前 tab 是否激活(tab 用 v-show 切换时,隐藏状态下 canvas 容器测量为 0,需激活后重绘)
  138. active: {
  139. type: Boolean,
  140. default: true
  141. }
  142. },
  143. data() {
  144. return {
  145. // 活动节律(mock)
  146. peakRange: '22:00',
  147. rhythmChart: null,
  148. rhythmOpts: {
  149. color: ['#FFC107'],
  150. dataLabel: false,
  151. // 背景轨道系列会进 uCharts 图例,改用卡片内自定义图例(见 template 的 chart-legend)
  152. legend: { show: false },
  153. xAxis: {
  154. disableGrid: true,
  155. fontSize: 9,
  156. fontColor: '#656565'
  157. },
  158. yAxis: {
  159. showTitle: true,
  160. disableGrid: false,
  161. gridType: 'dash',
  162. gridColor: '#EEEEEE',
  163. data: [{
  164. title: '数量:只',
  165. titleFontSize: 10,
  166. titleFontColor: '#656565',
  167. titleOffsetX: -10,
  168. titleOffsetY: -6,
  169. min: 0,
  170. max: 100,
  171. splitNumber: 5,
  172. tofix: 0
  173. }]
  174. },
  175. extra: {
  176. column: {
  177. // 温度计模式:系列[0]绘制为整柱浅色背景轨道,系列[1]叠加实际数据柱
  178. type: 'meter',
  179. meterBorder: 0,
  180. meterFillColor: '#d6dbed66',
  181. width: 14,
  182. barBorderCircle: false,
  183. linearType: 'none'
  184. }
  185. }
  186. },
  187. // 群落结构(mock)
  188. communityList: [
  189. { name: '褐家鼠', count: 91, percent: 25, color: '#E53935' },
  190. { name: '黄胸鼠', count: 91, percent: 25, color: '#FFC107' },
  191. { name: '小家鼠', count: 91, percent: 25, color: '#2196F3' },
  192. { name: '黑线姬鼠', count: 91, percent: 25, color: '#9E9E9E' }
  193. ],
  194. communityChart: null,
  195. communityOpts: {
  196. color: ['#E53935', '#FFC107', '#2196F3', '#9E9E9E'],
  197. legend: { show: false },
  198. // 环形图:中心显示当前占比最高的物种
  199. dataLabel: false,
  200. title: {
  201. name: '25%',
  202. fontSize: 16,
  203. color: '#E53935',
  204. offsetY: -6
  205. },
  206. subtitle: {
  207. name: '褐家鼠',
  208. fontSize: 10,
  209. color: '#333333',
  210. offsetY: 8
  211. },
  212. extra: {
  213. ring: {
  214. // 环粗细约为半径的三分之一
  215. ringWidth: 16,
  216. offsetAngle: 0,
  217. // 去掉分段之间的白色分隔线(qiun-data-charts 的 ring 默认 border: true)
  218. border: false,
  219. // 关闭点击分段时外扩+半透明的高亮效果(默认 activeRadius: 10 / activeOpacity: 0.5)
  220. activeRadius: 5,
  221. activeOpacity: 1
  222. }
  223. }
  224. },
  225. // 总量(mock)
  226. totalCount: 126,
  227. weekOverWeek: '+12.8%',
  228. alarmThreshold: 100,
  229. barMax: 130,
  230. // 鼠情与气象(mock)
  231. weatherRange: 'month',
  232. weatherChart: null,
  233. weatherOpts: {
  234. color: ['#FF5252', '#FFC107', '#2196F3'],
  235. dataLabel: false,
  236. legend: {
  237. show: true,
  238. position: 'bottom',
  239. fontSize: 10,
  240. fontColor: '#656565',
  241. itemGap: 15,
  242. lineHeight: 15
  243. },
  244. xAxis: {
  245. disableGrid: true,
  246. fontSize: 9,
  247. fontColor: '#656565'
  248. },
  249. yAxis: {
  250. showTitle: true,
  251. disableGrid: false,
  252. gridType: 'dash',
  253. gridColor: '#EEEEEE',
  254. data: [
  255. {
  256. title: '鼠害数量:只',
  257. titleFontSize: 10,
  258. titleFontColor: '#656565',
  259. titleOffsetX: -10,
  260. titleOffsetY: -6,
  261. position: 'left',
  262. min: 0,
  263. splitNumber: 5,
  264. tofix: 0
  265. },
  266. {
  267. title: '湿度:%',
  268. titleFontSize: 10,
  269. titleFontColor: '#656565',
  270. titleOffsetX: 10,
  271. titleOffsetY: -6,
  272. position: 'right',
  273. min: 0,
  274. splitNumber: 5,
  275. tofix: 0
  276. }
  277. ]
  278. },
  279. extra: {
  280. mix: {
  281. line: { width: 2 },
  282. area: { opacity: 0.15, gradient: true }
  283. },
  284. tooltip: {
  285. showBox: true
  286. }
  287. }
  288. }
  289. };
  290. },
  291. computed: {
  292. // 进度条填充:总量/量程
  293. fillPercent() {
  294. return Math.min((this.totalCount / this.barMax) * 100, 100);
  295. },
  296. // 告警阈值标记位置
  297. thresholdPercent() {
  298. return (this.alarmThreshold / this.barMax) * 100;
  299. }
  300. },
  301. mounted() {
  302. // 延迟赋值图表数据:等页面布局稳定后再初始化 canvas,避免容器尺寸测量为 0
  303. setTimeout(() => {
  304. this.initChartData();
  305. }, 300);
  306. },
  307. methods: {
  308. initChartData() {
  309. this.rhythmChart = {
  310. categories: ['00:00','02:00','04:00','06:00','08:00','10:00','12:00','14:00','16:00','18:00','20:00','22:00','24:00'],
  311. series: [
  312. // 背景轨道:满量程高度(meter 模式下系列[0]用 meterFillColor 填充)
  313. { name: '背景', color: '#D6DBED', data: Array(13).fill(100) },
  314. { name: '鼠害数量', color: '#FFC107', data: [42, 58, 66, 48, 22, 12, 8, 15, 28, 45, 95, 88, 52] }
  315. ]
  316. };
  317. this.communityChart = {
  318. series: [{
  319. data: [
  320. { name: '褐家鼠', value: 91 },
  321. { name: '黄胸鼠', value: 91 },
  322. { name: '小家鼠', value: 91 },
  323. { name: '黑线姬鼠', value: 91 }
  324. ]
  325. }]
  326. };
  327. this.weatherChart = buildWeatherChart(this.weatherRange);
  328. },
  329. switchRange(range) {
  330. if (this.weatherRange === range) return;
  331. this.weatherRange = range;
  332. this.weatherChart = buildWeatherChart(range);
  333. }
  334. }
  335. };
  336. </script>
  337. <style lang="scss" scoped>
  338. .rodent-analysis {
  339. width: 100%;
  340. }
  341. .analysis-card {
  342. width: 100%;
  343. padding: 32rpx;
  344. box-sizing: border-box;
  345. background: #fff;
  346. border-radius: 16rpx;
  347. margin-bottom: 24rpx;
  348. &:last-child {
  349. margin-bottom: 0;
  350. }
  351. }
  352. .analysis-card__header {
  353. display: flex;
  354. align-items: center;
  355. justify-content: space-between;
  356. margin-bottom: 20rpx;
  357. }
  358. .analysis-card__title {
  359. position: relative;
  360. font-size: 32rpx;
  361. color: #042118;
  362. font-family: 'Source Han Sans CN VF';
  363. font-weight: 700;
  364. }
  365. .analysis-card__extra {
  366. display: flex;
  367. align-items: center;
  368. .peak-label {
  369. font-size: 24rpx;
  370. color: #656565;
  371. font-family: 'Source Han Sans CN VF';
  372. margin-right: 8rpx;
  373. }
  374. .peak-value {
  375. font-size: 24rpx;
  376. color: #E53935;
  377. font-family: 'Source Han Sans CN VF';
  378. font-weight: 700;
  379. }
  380. }
  381. .chart-legend {
  382. display: flex;
  383. align-items: center;
  384. justify-content: flex-end;
  385. margin-bottom:-20rpx;
  386. .chart-legend__dot--bar {
  387. width: 16rpx;
  388. height: 16rpx;
  389. border-radius: 4rpx;
  390. background: #FFC107;
  391. margin-right: 8rpx;
  392. }
  393. .chart-legend__text {
  394. font-size: 20rpx;
  395. color: #656565;
  396. font-family: 'Source Han Sans CN VF';
  397. }
  398. }
  399. .chart-wrap {
  400. position: relative;
  401. width: 100%;
  402. }
  403. .chart-wrap--rhythm {
  404. height: 400rpx;
  405. }
  406. .chart-wrap--ring {
  407. width: 360rpx;
  408. height: 320rpx;
  409. flex-shrink: 0;
  410. }
  411. .chart-wrap--weather {
  412. height: 420rpx;
  413. }
  414. // 群落结构:上下布局,环形图在上,图例列表在下
  415. .community-content {
  416. display: flex;
  417. flex-direction: column;
  418. align-items: center;
  419. }
  420. .community-total{
  421. width: 90%;
  422. display: flex;
  423. align-items: center;
  424. justify-content: space-between;
  425. font-family: 'Source Han Sans CN VF';
  426. .total-value {
  427. font-size: 32rpx;
  428. color: #042118;
  429. font-weight: 700;
  430. line-height: 1;
  431. }
  432. .unit {
  433. font-size: 28rpx;
  434. font-weight: 400;
  435. color:#999999;
  436. margin-left: 8rpx;
  437. }
  438. }
  439. .community-list {
  440. width: 90%;
  441. margin-top: 16rpx;
  442. }
  443. .community-item {
  444. display: flex;
  445. align-items: center;
  446. padding: 12rpx 0;
  447. font-family: 'Source Han Sans CN VF';
  448. .community-item__dot {
  449. width: 16rpx;
  450. height: 16rpx;
  451. border-radius: 4rpx;
  452. margin-right: 12rpx;
  453. flex-shrink: 0;
  454. }
  455. .community-item__name {
  456. flex: 1;
  457. font-size: 26rpx;
  458. color: #042118;
  459. }
  460. .community-item__count {
  461. font-size: 26rpx;
  462. color: #042118;
  463. margin-right: 16rpx;
  464. }
  465. .community-item__percent {
  466. font-size: 26rpx;
  467. color: #656565;
  468. width: 72rpx;
  469. text-align: right;
  470. }
  471. }
  472. // 总量害虫数量
  473. .total-main {
  474. display: flex;
  475. align-items: flex-end;
  476. margin-bottom: 24rpx;
  477. font-family: 'Source Han Sans CN VF';
  478. .total-value {
  479. font-size: 56rpx;
  480. color: #042118;
  481. font-weight: 700;
  482. line-height: 1;
  483. .total-unit {
  484. font-size: 28rpx;
  485. font-weight: 500;
  486. margin-left: 8rpx;
  487. }
  488. }
  489. .total-compare {
  490. font-size: 24rpx;
  491. color: #656565;
  492. margin-left: 24rpx;
  493. padding-bottom: 4rpx;
  494. .total-compare__value {
  495. color: #E53935;
  496. font-weight: 700;
  497. }
  498. }
  499. }
  500. .total-bar {
  501. .total-bar__track {
  502. position: relative;
  503. height: 16rpx;
  504. border-radius: 8rpx;
  505. background: #F1F4F8;
  506. overflow: visible;
  507. }
  508. .total-bar__fill {
  509. height: 100%;
  510. border-radius: 8rpx;
  511. background: #0BBC58;
  512. }
  513. .total-bar__marker {
  514. position: absolute;
  515. top: -6rpx;
  516. width: 4rpx;
  517. height: 28rpx;
  518. border-radius: 2rpx;
  519. background: #E53935;
  520. transform: translateX(-50%);
  521. }
  522. .total-bar__scale {
  523. display: flex;
  524. justify-content: space-between;
  525. margin-top: 8rpx;
  526. font-size: 22rpx;
  527. color: #999999;
  528. font-family: 'Source Han Sans CN VF';
  529. }
  530. }
  531. // 周/月/年切换
  532. .range-tabs {
  533. display: flex;
  534. align-items: center;
  535. .range-tab {
  536. width: 64rpx;
  537. height: 48rpx;
  538. line-height: 44rpx;
  539. text-align: center;
  540. font-size: 24rpx;
  541. color: #042118;
  542. font-family: 'Source Han Sans CN VF';
  543. background: #fff;
  544. border: 2rpx solid #E4E7ED;
  545. box-sizing: border-box;
  546. &:first-child {
  547. border-radius: 8rpx 0 0 8rpx;
  548. }
  549. &:last-child {
  550. border-radius: 0 8rpx 8rpx 0;
  551. }
  552. &.active {
  553. background: #0BBC58;
  554. border-color: #0BBC58;
  555. color: #fff;
  556. font-weight: 700;
  557. }
  558. }
  559. }
  560. </style>