index.vue 9.7 KB

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