index.vue 9.1 KB

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