RiskReportPanel.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <template>
  2. <floating-panel
  3. class="risk-report-panel"
  4. :class="{
  5. 'risk-report-panel--dragging': isDragging,
  6. 'risk-report-panel--plot': viewType === 'plot',
  7. 'risk-report-panel--plot-fullscreen': isPlotFullscreen,
  8. }"
  9. :style="panelMotionStyle"
  10. v-model:height="height"
  11. :anchors="anchors"
  12. :duration="0.36"
  13. :content-draggable="true"
  14. @height-change="handleHeightChange"
  15. >
  16. <template v-if="viewType === 'risk'">
  17. <div class="panel-header-zone">
  18. <div class="panel-header" :class="{ 'panel-header--en': locale === 'en' }">
  19. <div class="panel-header__row">
  20. <div class="panel-header__left">
  21. <span class="panel-header__bar"></span>
  22. <span
  23. class="panel-header__title panel-header__title--toggle"
  24. @click="toggleLocale"
  25. >{{ t("growthReport.weatherRiskReport") }}</span>
  26. <span v-if="locale !== 'en'" class="panel-header__date">{{ reportDate }}</span>
  27. </div>
  28. <span v-if="locale === 'en'" class="panel-header__date">{{ reportDate }}</span>
  29. <div
  30. v-if="locale !== 'en'"
  31. class="panel-header__switch"
  32. @click="handleSwitchCategory"
  33. >
  34. <span>{{ t("growthReport.switchCategory") }}</span>
  35. <icon name="arrow-down" class="panel-header__switch-icon" />
  36. </div>
  37. </div>
  38. <div
  39. v-if="locale === 'en'"
  40. class="panel-header__switch panel-header__switch--en"
  41. @click="handleSwitchCategory"
  42. >
  43. <span>{{ t("growthReport.switchCategory") }}</span>
  44. <icon name="arrow-down" class="panel-header__switch-icon" />
  45. </div>
  46. </div>
  47. </div>
  48. <div class="panel-body">
  49. <risk-report-content
  50. :loading="loading"
  51. :risk-section="riskSection"
  52. :advice-list="adviceList"
  53. />
  54. </div>
  55. </template>
  56. <plot-detail-content
  57. v-else
  58. :detail="plotDetail"
  59. :fullscreen="isPlotFullscreen"
  60. @close="emit('closePlotDetail')"
  61. />
  62. </floating-panel>
  63. </template>
  64. <script setup>
  65. import { FloatingPanel, Icon } from "vant";
  66. import { computed, ref, watch } from "vue";
  67. import { useStore } from "vuex";
  68. import { useI18n } from "@/i18n";
  69. import PlotDetailContent from "./PlotDetailContent.vue";
  70. import RiskReportContent from "./RiskReportContent.vue";
  71. const { t, toggleLocale, locale } = useI18n();
  72. const store = useStore();
  73. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  74. const props = defineProps({
  75. viewType: {
  76. type: String,
  77. default: "risk",
  78. },
  79. plotDetail: {
  80. type: Object,
  81. default: () => ({}),
  82. },
  83. });
  84. const emit = defineEmits(["switchCategory", "expandProgress", "closePlotDetail"]);
  85. const MONTHS_EN = [
  86. "January", "February", "March", "April", "May", "June",
  87. "July", "August", "September", "October", "November", "December",
  88. ];
  89. const formatReportDate = (date = new Date(), lang = "zh") => {
  90. const year = date.getFullYear();
  91. const month = date.getMonth() + 1;
  92. const day = date.getDate();
  93. if (lang === "en") {
  94. return `${MONTHS_EN[month - 1]} ${day}, ${year}`;
  95. }
  96. return `${year}.${String(month).padStart(2, "0")}.${String(day).padStart(2, "0")}`;
  97. };
  98. const reportDate = computed(() => formatReportDate(new Date(), locale.value));
  99. const loading = ref(false);
  100. const riskSection = computed(() => ({
  101. title: "高温高湿风险",
  102. summary:
  103. "预计高温高湿风险达到高风险等级(Ⅲ级),持续性高温高湿不仅直接加重病虫危害,还将迫使种植户增加农药施用频次,推高生产成本,进而影响稻米品质与种植效益,构成基地水稻中后期生产的关键气象风险。",
  104. items: [
  105. {
  106. description:
  107. "预计未来十天潢涌基地将进入 持续高温高湿状态,日均温普遍维持在 28℃ 以上,相对湿度超过 80%,为水稻病虫害的发生与流行提供了充分的气象条件。在此背景下,水稻纹枯病 可能急剧发展,经函数对病虫气象适宜度进行计算,并叠加前期积累的气象胁迫背景,计算得到病虫胁迫指数为 6(0~9范围,0~3为低风险,4~6为中风险,7~9为高风险),达到 高风险等级(Ⅲ级),重发田块发病率 可超过 60%,可导致 10%~15% 的产量损失。",
  108. boldKeywords: [
  109. "持续高温高湿状态",
  110. "28℃",
  111. "80%",
  112. "水稻纹枯病",
  113. // "6",
  114. "高风险等级",
  115. "重发田块发病率",
  116. "60%",
  117. "10%~15%",
  118. ],
  119. },
  120. {
  121. description:
  122. "灌浆期遇高湿阴雨天气,稻瘟病 呈 中等偏重 发生趋势,感病品种 穗颈瘟 发病率可达 22.8% 。同时,稻飞虱、稻纵卷叶螟等迁飞性害虫在高温高湿环境中繁殖速度加快,若与台风外围虫源叠加,可造成 20% 左右的减产风险。此外,25~30℃日均温与80%以上相对湿度的组合,极有利于 水稻跗线螨 种群快速增长,可能导致叶片褪绿、千粒重下降 3%~5%。",
  123. boldKeywords: [
  124. "稻瘟病",
  125. "中等偏重",
  126. "穗颈瘟",
  127. "22.8%",
  128. "20%",
  129. "水稻跗线螨",
  130. " 3%~5%",
  131. ],
  132. },
  133. ],
  134. }));
  135. const adviceList = computed(() => [
  136. {
  137. title: "田间水肥调控(即刻执行)",
  138. description:
  139. "叶面补钾增强抗性:每亩喷施磷酸二氢钾100克,兑水30公斤,提高茎秆硬度和植株抗病能力。"
  140. },
  141. {
  142. title: "应急防控(未来3天内完成)",
  143. description:
  144. "立即喷施苯醚甲环唑·嘧菌酯悬浮剂,或井冈霉素水剂,重点喷施水稻茎秆中下部。重病田块间隔7天再补防一次。",
  145. },
  146. ]);
  147. const handleSwitchCategory = () => {
  148. emit("switchCategory");
  149. };
  150. const anchors = computed(() => {
  151. const viewportHeight = window.innerHeight - tabBarHeight.value;
  152. return [
  153. Math.round(viewportHeight * 0.4),
  154. window.innerHeight,
  155. ];
  156. });
  157. const height = ref(anchors.value[0]);
  158. const isDragging = ref(false);
  159. let dragEndTimer = null;
  160. const expandProgress = computed(() => {
  161. const min = anchors.value[0];
  162. const max = anchors.value[anchors.value.length - 1];
  163. if (max <= min) return 0;
  164. return Math.min(1, Math.max(0, (height.value - min) / (max - min)));
  165. });
  166. const isPlotFullscreen = computed(() => props.viewType === "plot" && expandProgress.value > 0.85);
  167. const panelMotionStyle = computed(() => {
  168. const progress = expandProgress.value;
  169. const margin = 10 * (1 - progress);
  170. const radius = 16 * (1 - progress);
  171. const headerScale = 1 + progress * 0.12;
  172. return {
  173. "--panel-radius": `${radius}px`,
  174. "--panel-progress": progress,
  175. left: `${margin}px`,
  176. width: `calc(100% - ${margin * 2}px)`,
  177. zIndex: progress > 0.82 ? 20 : 10,
  178. paddingTop: progress > 0.9 ? "env(safe-area-inset-top, 0px)" : "0px",
  179. "--header-bar-scale": headerScale,
  180. };
  181. });
  182. const syncExpandProgress = () => {
  183. emit("expandProgress", expandProgress.value);
  184. };
  185. watch(expandProgress, syncExpandProgress, { immediate: true });
  186. watch(height, () => {
  187. isDragging.value = true;
  188. if (dragEndTimer) {
  189. clearTimeout(dragEndTimer);
  190. }
  191. dragEndTimer = setTimeout(() => {
  192. isDragging.value = false;
  193. }, 380);
  194. });
  195. watch(anchors, (nextAnchors) => {
  196. if (height.value > nextAnchors[nextAnchors.length - 1]) {
  197. height.value = nextAnchors[0];
  198. }
  199. });
  200. watch(
  201. () => props.viewType,
  202. (type) => {
  203. if (type === "plot") {
  204. height.value = anchors.value[0];
  205. }
  206. }
  207. );
  208. const handleHeightChange = () => {
  209. syncExpandProgress();
  210. };
  211. </script>
  212. <style lang="scss" scoped>
  213. .risk-report-panel {
  214. z-index: 10;
  215. will-change: left, width;
  216. &.risk-report-panel--dragging {
  217. ::v-deep .van-floating-panel__header-bar {
  218. transform: scaleX(calc(var(--header-bar-scale, 1)));
  219. }
  220. }
  221. &.risk-report-panel--plot-fullscreen {
  222. ::v-deep {
  223. .van-floating-panel__header {
  224. background: #f5f7fb;
  225. }
  226. .van-floating-panel__content {
  227. background: #f5f7fb;
  228. }
  229. }
  230. }
  231. &.risk-report-panel--plot {
  232. ::v-deep {
  233. .van-floating-panel__header {
  234. background: #fff;
  235. }
  236. .van-floating-panel__header-bar {
  237. background: #c6c6c6;
  238. }
  239. .van-floating-panel__content {
  240. background: #fff;
  241. }
  242. }
  243. }
  244. ::v-deep {
  245. .van-floating-panel__header {
  246. height: 18px;
  247. background: linear-gradient(180deg, #acd5fb 0%, #bcddfc 100%);
  248. border-radius: var(--panel-radius, 16px) var(--panel-radius, 16px) 0 0;
  249. }
  250. .van-floating-panel__header-bar {
  251. width: 36px;
  252. height: 4px;
  253. background: rgba(255, 255, 255, 0.95);
  254. border-radius: 4px;
  255. transform: scaleX(var(--header-bar-scale, 1));
  256. transition: transform 0.2s ease;
  257. }
  258. .van-floating-panel__content {
  259. overflow-y: auto;
  260. padding-bottom: env(safe-area-inset-bottom);
  261. background: linear-gradient(180deg, #d2ebff 38%, #e3f2fd 68%, #ffffff 100%);
  262. }
  263. }
  264. }
  265. .panel-header-zone {
  266. padding-bottom: 4px;
  267. background: linear-gradient(180deg, #bcddfc 0%, #d9ebfd 100%);
  268. }
  269. .panel-header {
  270. display: flex;
  271. align-items: center;
  272. justify-content: space-between;
  273. gap: 8px;
  274. padding: 2px 12px 8px;
  275. box-sizing: border-box;
  276. &__row {
  277. display: flex;
  278. align-items: center;
  279. justify-content: space-between;
  280. width: 100%;
  281. gap: 8px;
  282. min-width: 0;
  283. }
  284. &--en {
  285. flex-direction: column;
  286. align-items: flex-start;
  287. gap: 10px;
  288. padding-bottom: 10px;
  289. .panel-header__row {
  290. width: 100%;
  291. }
  292. .panel-header__left {
  293. flex: 1;
  294. min-width: 0;
  295. }
  296. .panel-header__title {
  297. font-size: 17px;
  298. font-weight: 600;
  299. color: #000;
  300. }
  301. .panel-header__date {
  302. flex-shrink: 0;
  303. padding: 4px 8px;
  304. font-size: 12px;
  305. color: #313131;
  306. background: rgba(255, 255, 255, 0.72);
  307. border-radius: 4px;
  308. }
  309. .panel-header__switch--en {
  310. padding: 4px 10px;
  311. border-radius: 4px;
  312. border-color: rgba(33, 153, 248, 0.75);
  313. }
  314. }
  315. &__left {
  316. display: flex;
  317. align-items: center;
  318. gap: 6px;
  319. }
  320. &__bar {
  321. width: 4px;
  322. height: 16px;
  323. border-radius: 2px;
  324. background: #2199f8;
  325. }
  326. &__title {
  327. font-size: 16px;
  328. font-weight: 500;
  329. &--toggle {
  330. cursor: pointer;
  331. user-select: none;
  332. }
  333. }
  334. &__date {
  335. padding: 2px 6px;
  336. font-size: 12px;
  337. color: #313131;
  338. background: rgba(255, 255, 255, 0.5);
  339. border-radius: 2px;
  340. }
  341. &__switch {
  342. display: flex;
  343. align-items: center;
  344. gap: 2px;
  345. padding: 5px 10px;
  346. font-size: 12px;
  347. color: #2199f8;
  348. background: #fff;
  349. border: 1px solid rgba(33, 153, 248, 0.65);
  350. border-radius: 6px;
  351. white-space: nowrap;
  352. flex-shrink: 0;
  353. }
  354. &__switch-icon {
  355. font-size: 12px;
  356. color: #2199f8;
  357. }
  358. }
  359. .panel-body {
  360. margin: 0 10px;
  361. background: #fff;
  362. border-radius: 8px;
  363. padding: 10px;
  364. }
  365. </style>