index.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  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" :class="{ 'container-role': curRole == 2 }">
  20. <div class="farm-monitor-left" @click="handleCardClick(monitorCards.left)">
  21. <div class="title">
  22. <span>{{ monitorCards.left.title }}</span>
  23. <el-icon v-if="curRole == 2" class="icon"><ArrowRightBold /></el-icon>
  24. </div>
  25. <div class="content">{{ monitorCards.left.content }}</div>
  26. <div class="arrow" v-if="curRole != 2">
  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. <!-- 问题提醒 -->
  56. <problem-reminder></problem-reminder>
  57. </template>
  58. <script setup>
  59. import { ref, computed, onActivated } from "vue";
  60. import { useStore } from "vuex";
  61. import weatherInfo from "@/components/weatherInfo.vue";
  62. import AgriculturalDynamics from "./components/AgriculturalDynamics.vue";
  63. import { useRouter, useRoute } from "vue-router";
  64. import wx from "weixin-js-sdk";
  65. import problemReminder from "./components/problemReminder.vue";
  66. import { ElMessage } from "element-plus";
  67. import tipPopup from "@/components/popup/tipPopup.vue";
  68. const curRole = localStorage.getItem("SET_USER_CUR_ROLE");
  69. const store = useStore();
  70. const tabBarHeight = computed(() => store.state.home.tabBarHeight);
  71. const router = useRouter();
  72. const route = useRoute();
  73. const showFarmPopup = ref(false);
  74. const farmPopupType = ref("create");
  75. const gardenId = ref(null);
  76. const isGarden = ref(false);
  77. const changeGarden = ({ id }) => {
  78. gardenId.value = id;
  79. getExpertByFarmId();
  80. };
  81. const expertInfo = ref({});
  82. const getExpertByFarmId = () => {
  83. VE_API.home.getExpertByFarmId({ farmId: gardenId.value }).then(({ data }) => {
  84. expertInfo.value = data || {};
  85. sessionStorage.setItem("expertId", data.appUserId);
  86. });
  87. };
  88. // 监测卡片数据
  89. const monitorCards = ref({
  90. left: {
  91. title: "农场监测",
  92. content: "实时监测农场状态",
  93. route: "/monitor",
  94. },
  95. right: [
  96. {
  97. title: "病虫识别",
  98. content: "精准识别病虫",
  99. route: "/pest",
  100. },
  101. {
  102. title: "专家咨询",
  103. content: "专家多年经验指导",
  104. route: "/chat_frame",
  105. },
  106. ],
  107. });
  108. // 卡片点击事件
  109. const handleCardClick = (card) => {
  110. if (curRole == 0) {
  111. if (!isGarden.value) {
  112. showFarmPopup.value = true;
  113. return;
  114. }
  115. }
  116. if (card.route === "/pest") {
  117. // ElMessage.warning("该功能正在升级中,敬请期待");
  118. // if (curRole == 2) {
  119. // ElMessage.warning("该功能正在升级中,敬请期待");
  120. // } else {
  121. const dropdownGardenItem = ref({
  122. organId: 766,
  123. periodId: 1,
  124. wktVal: "wktVal",
  125. address: "address",
  126. district: "district",
  127. name: "荔博园",
  128. });
  129. wx.miniProgram.navigateTo({
  130. url: `/pages/subPages/new_recognize/index?gardenData=${JSON.stringify(dropdownGardenItem.value)}`,
  131. });
  132. // }
  133. } else {
  134. if (card.route === "/chat_frame") {
  135. router.push("/agri_services?active=1");
  136. // router.push(`/chat_frame?userId=${expertInfo.value.appUserId}`);
  137. } else {
  138. router.push(card.route);
  139. }
  140. }
  141. };
  142. const handleBtn = () => {
  143. if (farmPopupType.value === "create") {
  144. router.push("/create_farm?isReload=true&from=home");
  145. }
  146. };
  147. onActivated(() => {
  148. getBannerList();
  149. isGarden.value = Boolean(localStorage.getItem("isGarden"));
  150. // 检测是否从创建农场页面成功返回
  151. if (route.query.showSuccess === "true") {
  152. farmPopupType.value = "success";
  153. showFarmPopup.value = true;
  154. // 清除URL参数,避免刷新页面时再次显示弹窗
  155. router.replace({
  156. path: "/home",
  157. query: { reload: route.query.reload },
  158. });
  159. }
  160. if (curRole == 2) {
  161. monitorCards.value.left = {
  162. title: "新增客户",
  163. content: "实时监测农场状态",
  164. route: "/create_farm?type=client&isReload=true&from=home",
  165. };
  166. monitorCards.value.right = [
  167. {
  168. title: "病虫识别",
  169. content: "精准识别病虫",
  170. route: "/pest",
  171. },
  172. ];
  173. }
  174. });
  175. const bannerObj = ref({});
  176. const getBannerList = () => {
  177. const params = {
  178. page: 1,
  179. limit: 1,
  180. topicId: 5,
  181. };
  182. VE_API.home.warningPageList(params).then(({ data }) => {
  183. bannerObj.value = data[0] || {};
  184. });
  185. };
  186. const isExpanded = ref(false);
  187. const weatherInfoRef = ref(null);
  188. const weatherExpanded = (isExpandedValue) => {
  189. isExpanded.value = isExpandedValue;
  190. };
  191. // 点击遮罩时收起天气
  192. const handleMaskClick = () => {
  193. if (weatherInfoRef.value && weatherInfoRef.value.toggleExpand) {
  194. weatherInfoRef.value.toggleExpand();
  195. }
  196. };
  197. const handleBannerClick = () => {
  198. router.push(`/warning_detail?id=${bannerObj.value.id}`);
  199. };
  200. </script>
  201. <style scoped lang="scss">
  202. .home-index {
  203. width: 100%;
  204. height: 100vh;
  205. overflow: auto;
  206. position: relative;
  207. .banner-wrap {
  208. width: 100%;
  209. height: 200px;
  210. position: relative;
  211. z-index: 1;
  212. .banner-img {
  213. width: 100%;
  214. height: 100%;
  215. object-fit: cover;
  216. }
  217. .banner-title {
  218. position: absolute;
  219. bottom: 0;
  220. left: 0;
  221. width: 100%;
  222. padding: 10px 12px 34px 12px;
  223. box-sizing: border-box;
  224. background: linear-gradient(
  225. 180deg,
  226. rgba(102, 102, 102, 0) -64.3%,
  227. rgba(0, 0, 0, 0.0074) -1.43%,
  228. rgba(0, 0, 0, 0.684747) 39.67%,
  229. rgba(0, 0, 0, 0.74) 40.09%,
  230. rgba(0, 0, 0, 0.74) 83.2%
  231. );
  232. color: #fff;
  233. font-weight: bold;
  234. backdrop-filter: blur(2px);
  235. }
  236. }
  237. .weather-mask {
  238. position: fixed;
  239. top: 0;
  240. left: 0;
  241. width: 100%;
  242. height: 100%;
  243. background-color: rgba(0, 0, 0, 0.52);
  244. z-index: 2;
  245. }
  246. .weather-info {
  247. width: calc(100% - 20px);
  248. position: absolute;
  249. top: calc(200px - 28px);
  250. left: 10px;
  251. z-index: 3;
  252. }
  253. .farm-monitor-container {
  254. padding-top: 60px;
  255. display: flex;
  256. align-items: center;
  257. gap: 7px;
  258. margin: 10px;
  259. height: 170px;
  260. .farm-monitor-left,
  261. .farm-monitor-right {
  262. .title {
  263. font-size: 16px;
  264. color: #1d2129;
  265. font-weight: 500;
  266. .icon {
  267. font-size: 12px;
  268. margin-left: 2px;
  269. }
  270. }
  271. .content {
  272. margin-top: 6px;
  273. font-size: 12px;
  274. color: rgba(29, 33, 41, 0.5);
  275. line-height: 1.5;
  276. }
  277. .arrow {
  278. border-radius: 5px;
  279. background: #fff;
  280. display: flex;
  281. align-items: center;
  282. justify-content: center;
  283. width: 34px;
  284. height: 25px;
  285. margin-top: 10px;
  286. font-size: 11px;
  287. }
  288. }
  289. .farm-monitor-left {
  290. flex: 1;
  291. height: 100%;
  292. padding: 25px 10px;
  293. box-sizing: border-box;
  294. background: url("@/assets/img/home/farm-bg-1.png") no-repeat center center / 100% 100%;
  295. }
  296. .farm-monitor-right {
  297. flex: 1;
  298. height: 100%;
  299. display: flex;
  300. flex-direction: column;
  301. gap: 7px;
  302. .right-item {
  303. padding: 10px;
  304. box-sizing: border-box;
  305. display: flex;
  306. flex-direction: column;
  307. justify-content: center;
  308. flex: 1;
  309. background: url("@/assets/img/home/farm-bg-2.png") no-repeat center center / 100% 100%;
  310. }
  311. .expert {
  312. background: url("@/assets/img/home/farm-bg-3.png") no-repeat center center / 100% 100%;
  313. }
  314. }
  315. &.container-role {
  316. height: 104px;
  317. .farm-monitor-left {
  318. background: url("@/assets/img/home/farm-bg-4.png") no-repeat center center / 100% 100%;
  319. }
  320. .farm-monitor-right {
  321. .right-item {
  322. background: url("@/assets/img/home/farm-bg-5.png") no-repeat center center / 100% 100%;
  323. }
  324. }
  325. }
  326. }
  327. }
  328. </style>