| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309 |
- <template>
- <div class="home-index" :style="{ height: `calc(100vh - ${tabBarHeight}px)` }">
- <img class="banner" @click="handleBannerClick" :src="bannerObj?.media?.[0]" alt="" />
- <!-- 天气遮罩 -->
- <div class="weather-mask" v-show="isExpanded" @click="handleMaskClick"></div>
- <!-- 天气 -->
- <weather-info ref="weatherInfoRef" class="weather-info" @weatherExpanded="weatherExpanded" :isGarden="false" @changeGarden="changeGarden"></weather-info>
- <div class="farm-monitor-container" :class="{ 'container-role': curRole == 2 }">
- <div class="farm-monitor-left" @click="handleCardClick(monitorCards.left)">
- <div class="title">
- <span>{{ monitorCards.left.title }}</span>
- <el-icon v-if="curRole == 2" class="icon"><ArrowRightBold /></el-icon>
- </div>
- <div class="content">{{ monitorCards.left.content }}</div>
- <div class="arrow" v-if="curRole != 2">
- <el-icon class="icon"><ArrowRightBold /></el-icon>
- </div>
- </div>
- <div class="farm-monitor-right">
- <div
- v-for="(item, index) in monitorCards.right"
- :key="index"
- class="right-item"
- :class="{ expert: index === 1 }"
- @click="handleCardClick(item)"
- >
- <div class="title">
- <span>{{ item.title }}</span>
- <el-icon class="icon"><ArrowRightBold /></el-icon>
- </div>
- <div class="content">{{ item.content }}</div>
- </div>
- </div>
- </div>
- <AgriculturalDynamics />
- </div>
- <!-- 创建农场弹窗 -->
- <tip-popup
- v-model:show="showFarmPopup"
- :type="farmPopupType"
- :text="farmPopupType === 'create' ? ['您当前还没有农场', '请先创建农场'] : '农场创建成功'"
- @confirm="handleBtn"
- />
- <!-- 问题提醒 -->
- <problem-reminder></problem-reminder>
- </template>
- <script setup>
- import { ref, computed, onActivated } from "vue";
- import { useStore } from "vuex";
- import weatherInfo from "@/components/weatherInfo.vue";
- import AgriculturalDynamics from "./components/AgriculturalDynamics.vue";
- import { useRouter, useRoute } from "vue-router";
- import wx from "weixin-js-sdk";
- import problemReminder from "./components/problemReminder.vue";
- import { ElMessage } from "element-plus";
- import tipPopup from "@/components/popup/tipPopup.vue";
- const curRole = localStorage.getItem("SET_USER_CUR_ROLE");
- const store = useStore();
- const tabBarHeight = computed(() => store.state.home.tabBarHeight);
- const router = useRouter();
- const route = useRoute();
- const showFarmPopup = ref(false);
- const farmPopupType = ref("create");
- const gardenId = ref(null);
- const isGarden = ref(false);
- const changeGarden = ({id}) => {
- gardenId.value = id;
- getExpertByFarmId();
- }
- const expertInfo = ref({});
- const getExpertByFarmId = () => {
- VE_API.home.getExpertByFarmId({ farmId: gardenId.value }).then(({ data }) => {
- expertInfo.value = data || {};
- sessionStorage.setItem('expertId',data.appUserId);
- });
- }
- // 监测卡片数据
- const monitorCards = ref({
- left: {
- title: "农场监测",
- content: "实时监测农场状态",
- route: "/monitor",
- },
- right: [
- {
- title: "病虫识别",
- content: "精准识别病虫",
- route: "/pest",
- },
- {
- title: "专家咨询",
- content: "专家多年经验指导",
- route: "/chat_frame",
- },
- ],
- });
- // 卡片点击事件
- const handleCardClick = (card) => {
- if(curRole == 0){
- if(!isGarden.value){
- showFarmPopup.value = true;
- return;
- }
- }
- if (card.route === "/pest") {
- if(curRole == 2){
- ElMessage.warning("该功能正在升级中,敬请期待");
- }else{
- const dropdownGardenItem = ref({
- organId: 766,
- periodId: 1,
- wktVal: "wktVal",
- address: "address",
- district: "district",
- name: "荔博园",
- });
- wx.miniProgram.navigateTo({
- url: `/pages/subPages/new_recognize/index?gardenData=${JSON.stringify(dropdownGardenItem.value)}`,
- });
- }
- } else {
- if (card.route === "/chat_frame") {
- router.push(`/chat_frame?userId=${expertInfo.value.appUserId}`);
- } else {
- router.push(card.route);
- }
- }
- };
- const handleBtn = () => {
- if (farmPopupType.value === "create") {
- router.push("/create_farm?isReload=true&from=home");
- }
- };
- onActivated(() => {
- getBannerList();
- isGarden.value = Boolean(localStorage.getItem('isGarden'));
- // 检测是否从创建农场页面成功返回
- if (route.query.showSuccess === "true") {
- farmPopupType.value = "success";
- showFarmPopup.value = true;
- // 清除URL参数,避免刷新页面时再次显示弹窗
- router.replace({
- path: "/home",
- query: { reload: route.query.reload },
- });
- }
- if (curRole == 2) {
- monitorCards.value.left = {
- title: "新增客户",
- content: "实时监测农场状态",
- route: "/create_farm?type=client&isReload=true&from=home",
- };
- monitorCards.value.right = [
- {
- title: "病虫识别",
- content: "精准识别病虫",
- route: "/pest",
- },
- ];
- }
- });
- const bannerObj = ref({});
- const getBannerList = () => {
- const params = {
- page: 1,
- limit: 1,
- topicId: 5,
- };
- VE_API.home.warningPageList(params).then(({ data }) => {
- bannerObj.value = data[0] || {};
- });
- }
- const isExpanded = ref(false);
- const weatherInfoRef = ref(null);
- const weatherExpanded = (isExpandedValue) => {
- isExpanded.value = isExpandedValue;
- };
- // 点击遮罩时收起天气
- const handleMaskClick = () => {
- if (weatherInfoRef.value && weatherInfoRef.value.toggleExpand) {
- weatherInfoRef.value.toggleExpand();
- }
- };
- const handleBannerClick = () => {
- router.push(`/warning_detail?id=${bannerObj.value.id}`);
- }
- </script>
- <style scoped lang="scss">
- .home-index {
- width: 100%;
- height: 100vh;
- overflow: auto;
- position: relative;
- .banner {
- width: 100%;
- height: 200px;
- object-fit: cover;
- position: relative;
- z-index: 1;
- }
- .weather-mask {
- position: fixed;
- top: 0;
- left: 0;
- width: 100%;
- height: 100%;
- background-color: rgba(0, 0, 0, 0.52);
- z-index: 2;
- }
- .weather-info {
- width: calc(100% - 20px);
- position: absolute;
- top: calc(200px - 28px);
- left: 10px;
- z-index: 3;
- }
- .farm-monitor-container {
- padding-top: 60px;
- display: flex;
- align-items: center;
- gap: 7px;
- margin: 10px;
- height: 170px;
- .farm-monitor-left,
- .farm-monitor-right {
- .title {
- font-size: 16px;
- color: #1d2129;
- font-weight: 500;
- .icon {
- font-size: 12px;
- margin-left: 2px;
- }
- }
- .content {
- margin-top: 6px;
- font-size: 12px;
- color: rgba(29, 33, 41, 0.5);
- line-height: 1.5;
- }
- .arrow {
- border-radius: 5px;
- background: #fff;
- display: flex;
- align-items: center;
- justify-content: center;
- width: 34px;
- height: 25px;
- margin-top: 10px;
- font-size: 11px;
- }
- }
- .farm-monitor-left {
- flex: 1;
- height: 100%;
- padding: 25px 10px;
- box-sizing: border-box;
- background: url("@/assets/img/home/farm-bg-1.png") no-repeat center center / 100% 100%;
- }
- .farm-monitor-right {
- flex: 1;
- height: 100%;
- display: flex;
- flex-direction: column;
- gap: 7px;
- .right-item {
- padding: 10px;
- box-sizing: border-box;
- display: flex;
- flex-direction: column;
- justify-content: center;
- flex: 1;
- background: url("@/assets/img/home/farm-bg-2.png") no-repeat center center / 100% 100%;
- }
- .expert {
- background: url("@/assets/img/home/farm-bg-3.png") no-repeat center center / 100% 100%;
- }
- }
- &.container-role{
- height: 104px;
- .farm-monitor-left{
- background: url("@/assets/img/home/farm-bg-4.png") no-repeat center center / 100% 100%;
- }
- .farm-monitor-right {
- .right-item {
- background: url("@/assets/img/home/farm-bg-5.png") no-repeat center center / 100% 100%;
- }
- }
- }
- }
- }
- </style>
|