index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <template>
  2. <div class="home-index" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
  3. <div class="banner-wrap">
  4. <img class="banner-img" @click="handleBannerClick" :src="bannerObj?.media?.[0]" alt="" />
  5. <div class="banner-title">
  6. <span class="van-multi-ellipsis--l2">{{ bannerObj?.title }}</span>
  7. </div>
  8. </div>
  9. <!-- 天气遮罩 -->
  10. <div class="weather-mask" v-show="isExpanded" @click="handleMaskClick"></div>
  11. <!-- 天气 -->
  12. <weather-info
  13. ref="weatherInfoRef"
  14. class="weather-info"
  15. @weatherExpanded="weatherExpanded"
  16. :isGarden="false"
  17. @changeGarden="changeGarden"
  18. ></weather-info>
  19. <div class="farm-monitor-container">
  20. <div class="farm-monitor-left" @click="handleCardClick(monitorCards.left)">
  21. <div class="title">
  22. <span>{{ monitorCards.left.title }}</span>
  23. <el-icon class="icon" v-if="monitorCards.left.title !== '农情采集'"><ArrowRightBold /></el-icon>
  24. </div>
  25. <div class="content">{{ monitorCards.left.content }}</div>
  26. <div class="arrow">
  27. <el-icon class="icon"><ArrowRightBold /></el-icon>
  28. </div>
  29. </div>
  30. <div class="farm-monitor-right">
  31. <div
  32. v-for="(item, index) in monitorCards.right"
  33. :key="index"
  34. class="right-item"
  35. :class="{ expert: index === 1 }"
  36. @click="handleCardClick(item)"
  37. >
  38. <div class="title">
  39. <span>{{ item.title }}</span>
  40. <el-icon class="icon"><ArrowRightBold /></el-icon>
  41. </div>
  42. <div class="content">{{ item.content }}</div>
  43. </div>
  44. </div>
  45. </div>
  46. <AgriculturalDynamics />
  47. </div>
  48. <!-- 创建农场弹窗 -->
  49. <tip-popup
  50. v-model:show="showFarmPopup"
  51. :type="farmPopupType"
  52. :text="farmPopupType === 'create' ? ['您当前还没有农场', '请先创建农场'] : '农场创建成功'"
  53. @confirm="handleBtn"
  54. />
  55. </template>
  56. <script setup>
  57. import { ref, computed, onActivated } from "vue";
  58. import { useStore } from "vuex";
  59. import weatherInfo from "@/components/weatherInfo.vue";
  60. import AgriculturalDynamics from "./components/AgriculturalDynamics.vue";
  61. import { useRouter, useRoute } from "vue-router";
  62. import wx from "weixin-js-sdk";
  63. import tipPopup from "@/components/popup/tipPopup.vue";
  64. const store = useStore();
  65. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  66. const router = useRouter();
  67. const route = useRoute();
  68. const showFarmPopup = ref(false);
  69. const farmPopupType = ref("create");
  70. const gardenId = ref(null);
  71. const isGarden = ref(false);
  72. const changeGarden = ({ id }) => {
  73. gardenId.value = id;
  74. getExpertByFarmId();
  75. };
  76. const expertInfo = ref({});
  77. const getExpertByFarmId = () => {
  78. VE_API.home.getExpertByFarmId({ farmId: gardenId.value }).then(({ data }) => {
  79. expertInfo.value = data || {};
  80. sessionStorage.setItem("expertId", data.appUserId);
  81. });
  82. };
  83. // 监测卡片数据
  84. const monitorCards = ref({
  85. left: {
  86. title: "农情采集",
  87. content: "精准监测 科学决策",
  88. route: "/pest",
  89. },
  90. right: [
  91. {
  92. title: "病虫识别",
  93. content: "智能识别 快速诊断",
  94. route: "/pest",
  95. },
  96. {
  97. title: "新增客户",
  98. content: "农情先知 高效管理",
  99. route: "/create_farm?type=client&isReload=true&from=home",
  100. },
  101. ],
  102. });
  103. // 卡片点击事件
  104. const handleCardClick = (card) => {
  105. const dropdownGardenItem = ref({
  106. organId: 766,
  107. periodId: 1,
  108. name: "荔博园",
  109. });
  110. if (card.title === "农情采集") {
  111. dropdownGardenItem.value.page = "create_farm";
  112. wx.miniProgram.navigateTo({
  113. url: `/pages/subPages/new_recognize/index?gardenData=${JSON.stringify(dropdownGardenItem.value)}`,
  114. });
  115. } else if (card.title === "病虫识别") {
  116. dropdownGardenItem.value.page = "album_recognize";
  117. wx.miniProgram.navigateTo({
  118. url: `/pages/subPages/new_recognize/index?gardenData=${JSON.stringify(dropdownGardenItem.value)}`,
  119. });
  120. } else {
  121. router.push(card.route);
  122. }
  123. };
  124. const handleBtn = () => {
  125. if (farmPopupType.value === "create") {
  126. router.push("/create_farm?isReload=true&from=home");
  127. }
  128. };
  129. onActivated(() => {
  130. getBannerList();
  131. isGarden.value = Boolean(localStorage.getItem("isGarden"));
  132. // 检测是否从创建农场页面成功返回
  133. if (route.query.showSuccess === "true") {
  134. farmPopupType.value = "success";
  135. showFarmPopup.value = true;
  136. // 清除URL参数,避免刷新页面时再次显示弹窗
  137. router.replace({
  138. path: "/home",
  139. query: { reload: route.query.reload },
  140. });
  141. }
  142. });
  143. const bannerObj = ref({});
  144. const getBannerList = () => {
  145. const params = {
  146. page: 1,
  147. limit: 1,
  148. topicId: 5,
  149. };
  150. VE_API.home.warningPageList(params).then(({ data }) => {
  151. bannerObj.value = data[0] || {};
  152. });
  153. };
  154. const isExpanded = ref(false);
  155. const weatherInfoRef = ref(null);
  156. const weatherExpanded = (isExpandedValue) => {
  157. isExpanded.value = isExpandedValue;
  158. };
  159. // 点击遮罩时收起天气
  160. const handleMaskClick = () => {
  161. if (weatherInfoRef.value && weatherInfoRef.value.toggleExpand) {
  162. weatherInfoRef.value.toggleExpand();
  163. }
  164. };
  165. const handleBannerClick = () => {
  166. router.push(`/warning_detail?id=${bannerObj.value.id}`);
  167. };
  168. </script>
  169. <style scoped lang="scss">
  170. .home-index {
  171. width: 100%;
  172. height: 100vh;
  173. overflow: auto;
  174. position: relative;
  175. background: linear-gradient(180deg, #f4f9fd 0%, #f9f9f9 100%);
  176. .banner-wrap {
  177. width: 100%;
  178. height: 200px;
  179. position: relative;
  180. z-index: 1;
  181. .banner-img {
  182. width: 100%;
  183. height: 100%;
  184. object-fit: cover;
  185. }
  186. .banner-title {
  187. position: absolute;
  188. bottom: 0;
  189. left: 0;
  190. width: 100%;
  191. padding: 10px 12px 34px 12px;
  192. box-sizing: border-box;
  193. background: linear-gradient(
  194. 180deg,
  195. rgba(102, 102, 102, 0) -64.3%,
  196. rgba(0, 0, 0, 0.0074) -1.43%,
  197. rgba(0, 0, 0, 0.684747) 39.67%,
  198. rgba(0, 0, 0, 0.74) 40.09%,
  199. rgba(0, 0, 0, 0.74) 83.2%
  200. );
  201. color: #fff;
  202. font-weight: bold;
  203. backdrop-filter: blur(2px);
  204. }
  205. }
  206. .weather-mask {
  207. position: fixed;
  208. top: 0;
  209. left: 0;
  210. width: 100%;
  211. height: 100%;
  212. background-color: rgba(0, 0, 0, 0.52);
  213. z-index: 2;
  214. }
  215. .weather-info {
  216. width: calc(100% - 20px);
  217. position: absolute;
  218. top: calc(200px - 28px);
  219. left: 10px;
  220. z-index: 3;
  221. }
  222. .farm-monitor-container {
  223. padding-top: 30px;
  224. display: flex;
  225. align-items: center;
  226. margin: 10px;
  227. gap: 6px;
  228. height: 134px;
  229. .farm-monitor-left,
  230. .farm-monitor-right {
  231. .title {
  232. font-size: 16px;
  233. color: #1d2129;
  234. font-weight: 500;
  235. .icon {
  236. font-size: 12px;
  237. margin-left: 2px;
  238. }
  239. }
  240. .content {
  241. margin-top: 6px;
  242. font-size: 12px;
  243. color: rgba(29, 33, 41, 0.5);
  244. line-height: 1.5;
  245. }
  246. .arrow {
  247. border-radius: 5px;
  248. background: #fff;
  249. display: flex;
  250. align-items: center;
  251. justify-content: center;
  252. width: 34px;
  253. height: 25px;
  254. margin-top: 10px;
  255. font-size: 11px;
  256. }
  257. }
  258. .farm-monitor-left {
  259. flex: 1;
  260. height: 100%;
  261. margin-top: 2px;
  262. padding: 25px 16px;
  263. box-sizing: border-box;
  264. max-width: 170px;
  265. background: url("@/assets/img/home/farm-bg-1.png") no-repeat center center / 105% 106%;
  266. }
  267. .farm-monitor-right {
  268. flex: 1;
  269. height: 100%;
  270. display: flex;
  271. flex-direction: column;
  272. .right-item {
  273. padding: 10px 12px;
  274. box-sizing: border-box;
  275. display: flex;
  276. flex-direction: column;
  277. justify-content: center;
  278. flex: 1;
  279. background: url("@/assets/img/home/farm-bg-2.png") no-repeat center center / 100% 100%;
  280. }
  281. .expert {
  282. background: url("@/assets/img/home/farm-bg-3.png") no-repeat center center / 100% 100%;
  283. }
  284. }
  285. }
  286. }
  287. </style>