Forráskód Böngészése

feat:对接我的消息列表和农事转发功能

wangsisi 3 napja
szülő
commit
b87fb2cc4d

+ 10 - 0
src/api/modules/bbs.js

@@ -17,4 +17,14 @@ module.exports = {
         url: config.base_dev_url + "chat/markRead",
         type: "get",
     },
+    //获取会话列表(所有农场)
+    getSessionListAll: {
+        url: config.base_dev_url + "chat/sessionList",
+        type: "get",
+    },
+    //获取会话列表(单个农场)
+    sessionListByFarm: {
+        url: config.base_dev_url + "chat/sessionListByFarm",
+        type: "get",
+    },
 }

+ 4 - 0
src/api/modules/home.js

@@ -34,4 +34,8 @@ module.exports = {
         url: config.base_dev_url + "work_code/phenology/quest/save",
         type: "post",
     },
+    getExpertByFarmId: {
+        url: config.base_dev_url + "v2/farm/getExpertByFarmId",
+        type: "get",
+    },
 }

+ 81 - 48
src/components/chatWindow.vue

@@ -37,41 +37,21 @@
 
                         <!-- 对话样式消息 -->
                         <div v-if="msg.messageType === 'dialog'" class="dialog-message">
-                            <div class="dialog-title">{{ msg.content.title }}</div>
-                            <div class="dialog-content">{{ msg.content.content }}</div>
-                            <div class="before-after-comparison">
-                                <div class="comparison-item before">
-                                    <div class="comparison-label">{{ msg.content.beforeAfter.before.title }}</div>
-                                    <div class="comparison-image">
-                                        <img :src="msg.content.beforeAfter.before.image" alt="农事前" />
-                                    </div>
-                                </div>
-                                <div class="vs-icon">VS</div>
-                                <div class="comparison-item after">
-                                    <div class="comparison-label">{{ msg.content.beforeAfter.after.title }}</div>
-                                    <div class="comparison-image">
-                                        <img :src="msg.content.beforeAfter.after.image" alt="农事后" />
-                                    </div>
-                                </div>
-                            </div>
-                            <div class="work-details">
-                                <div class="detail-item">
-                                    <span class="detail-label">农事名称:</span>
-                                    <span class="detail-value">{{ msg.content.workDetails.name }}</span>
-                                </div>
-                                <div class="detail-item">
-                                    <span class="detail-label">所属分类:</span>
-                                    <span class="detail-value">{{ msg.content.workDetails.section }}</span>
-                                </div>
-                                <div class="detail-item">
-                                    <span class="detail-label">推荐时间:</span>
-                                    <span class="detail-value">{{ msg.content.workDetails.executeDate }}</span>
-                                </div>
-                                <div class="detail-item">
-                                    <span class="detail-label">触发条件:</span>
-                                    <span class="detail-value">{{ msg.content.workDetails.condition }}</span>
-                                </div>
-                            </div>
+                            <template v-if="msg.content.type === 'farm_report'">
+                                <div class="report-title">{{ msg.content.title }}</div>
+                                <div class="dialog-title">{{ msg.content.content }}</div>
+                                <img src="@/assets/img/monitor/aaa.png" alt="" class="monitor-image" />
+                            </template>
+                            <template v-else>
+                                <div class="dialog-title">{{ msg.content.title }}</div>
+                                <img src="@/assets/img/monitor/image.png" alt="" class="monitor-image" />
+                            </template>
+                        </div>
+
+                         <!-- 对话样式消息 -->
+                         <div v-if="msg.messageType === 'card'" class="card-message" @click="handleCardClick(msg)">
+                            <div class="card-title">{{ msg.title || msg.content.title }}</div>
+                            <img :src="base_img_url2 + (msg.coverUrl || msg.content.coverUrl) + resize" alt="" />
                         </div>
 
                         <!-- <div class="time">{{ msg.time }}</div> -->
@@ -80,7 +60,7 @@
 
                 <!-- 我方消息 -->
                 <template v-else>
-                    <div class="bubble" :class="{ 'no-bubble': msg.messageType === 'image' }">
+                    <div class="bubble" :class="{ 'no-bubble': msg.messageType === 'image'}">
                         <!-- 文本消息 -->
                         <div v-if="msg.messageType === 'text'" class="content">{{ msg.content }}</div>
 
@@ -113,6 +93,12 @@
                             </template>
                         </div>
 
+                        <!-- 对话样式消息 -->
+                        <div v-if="msg.messageType === 'card'" class="card-message" @click="handleCardClick(msg)">
+                            <div class="card-title">{{ msg.title || msg.content.title }}</div>
+                            <img :src="base_img_url2 + (msg.coverUrl || msg.content.coverUrl) + resize" alt="" />
+                        </div>
+
                         <!-- <div class="time">{{ msg.time }}</div> -->
                     </div>
                     <!-- <div class="avatar avatar-r">{{ msg.senderName.charAt(0) }}</div> -->
@@ -184,7 +170,7 @@
 
 <script setup>
 import { ref, onUnmounted, nextTick, watch, onActivated, onDeactivated } from "vue";
-import { useRouter } from "vue-router";
+import { useRouter ,useRoute} from "vue-router";
 import { base_img_url2 } from "@/api/config";
 import { getFileExt } from "@/utils/util";
 import UploadFile from "@/utils/upliadFile";
@@ -240,7 +226,7 @@ senderIcon.value = localUserInfoIcon;
 //聊天会话
 const createSession = (targetUserId, callback) => {
     // 先保存当前的对话样式消息  要注释
-    const dialogMessages = messages.value.filter((msg) => msg.messageType === "dialog");
+    // const dialogMessages = messages.value.filter((msg) => msg.messageType === "dialog");
 
     VE_API.bbs.createSession({ farmId: farmVal.value, targetUserId }).then(({ data, code }) => {
         if (code === 0) {
@@ -261,6 +247,8 @@ const createSession = (targetUserId, callback) => {
                             console.error(e, "e");
                         }
                     }
+                }else if(item.messageType === 'card'){
+                    content = JSON.parse(item.content);
                 }
                 return {
                     ...item,
@@ -271,10 +259,10 @@ const createSession = (targetUserId, callback) => {
                 };
             });
 
-            // 重新添加对话样式消息   要注释
-            if (dialogMessages.length > 0) {
-                messages.value = [...messages.value, ...dialogMessages];
-            }
+            // // 重新添加对话样式消息   要注释
+            // if (dialogMessages.length > 0) {
+            //     messages.value = [...messages.value, ...dialogMessages];
+            // }
 
             setTimeout(() => {
                 scrollToBottom();
@@ -291,13 +279,13 @@ const handleFarmChange = (e) => {
 
 //发送消息接口
 //类型 text ,file,image
-const sendMsg = (messageType = "text", content = "", image = {}) => {
+const sendMsg = (messageType = "text", content = "", obj = {}) => {
     const params = {
         farmId: farmVal.value,
         senderId: curUserId,
         receiverId: userId.value,
         content,
-        image,
+        [messageType]:obj,
         messageType,
     };
     VE_API.bbs.sendMsg(params);
@@ -305,6 +293,9 @@ const sendMsg = (messageType = "text", content = "", image = {}) => {
 
 const userId = ref(null);
 
+const handleCardClick = (msg) => {
+    router.push(msg.linkUrl || msg.content.linkUrl);
+}
 watch(
     () => props.userId,
     async (newValue) => {
@@ -312,6 +303,22 @@ watch(
             await getFarmList();
             userId.value = newValue;
             createSession(newValue, () => {
+                if(route.query.pageParams) {
+                    const params = JSON.parse(route.query.pageParams);
+                    const imgArr = JSON.parse(params.executeEvidence);
+
+                    const message = {
+                        sender: "sent",
+                        messageType: "card",
+                        senderIcon: senderIcon.value,
+                        title: params.farmWorkName + ' 农事已完成,请您确认',
+                        coverUrl: imgArr[0],
+                        cardType:'farm_work',
+                        linkUrl:`/completed_work?json=${JSON.stringify({id:params.id})}`,
+                        time: getCurrentTime(),
+                    };
+                    sendMessage(message)
+                }
                 if (props.text) {
                     sendMsg("text", props.text);
                     messages.value.push({
@@ -376,11 +383,12 @@ const previewImage = ref(null);
 const initMqtt = () => {
     const topics = [`user/chat/message/${farmVal.value}/${curUserId}`]; // 订阅的主题数组
     mqttClient.value = new MqttClient(topics, (topic, message) => {
-        console.log(topic, "topic");
-        console.log("接收推送信息:", message);
         if (message && message.length > 10) {
             const obj = JSON.parse(message);
             console.log("message有值", obj);
+            if(obj.senderId === curUserId){
+                return;
+            }
             if (obj.senderId === receiverIdVal.value) {
                 if (obj.messageType === "image") {
                     if (obj.image && (obj.image.url || obj.image.originUrl)) {
@@ -417,6 +425,13 @@ const sendMessage = (message) => {
     } else if (message.messageType === "dialog") {
         // 对话样式消息不发送到服务器,只显示在本地
         console.log("发送对话样式消息:", message.content);
+    }else{
+        sendMsg('card','',{
+            title: message.title,
+            coverUrl: message.coverUrl,
+            cardType: message.cardType,
+            linkUrl: message.linkUrl
+        });
     }
     messages.value.push(message);
     scrollToBottom();
@@ -603,14 +618,18 @@ const scrollToBottom = () => {
 
 const farmVal = ref("");
 const options = ref([]);
-
+const route = useRoute();
 // 获取农场列表
 function getFarmList() {
     return VE_API.farm.userFarmSelectOption().then(({ data }) => {
         options.value = data || [];
         if (data && data.length > 0) {
             const defaultOption = data.find((item) => item.defaultOption === true);
-            farmVal.value = defaultOption ? defaultOption.id : data[0].id;
+            if(route.query.farmId) {
+                farmVal.value = Number(route.query.farmId);
+            }else{
+                farmVal.value = defaultOption ? defaultOption.id : data[0].id;
+            }
         }
     });
 }
@@ -999,6 +1018,20 @@ const sendFarmReportDialog = () => {
     }
 }
 
+.card-message{
+    .card-title{
+        font-size: 15px;
+        font-weight: 600;
+        color: #fff;
+        margin-bottom: 5px;
+    }
+    img{
+        width: 222px;
+        height: 180px;
+        object-fit: cover;
+    }
+}
+
 /* 我方消息中的对话样式 */
 .message.sent .dialog-message {
     background: #e3f2fd;

+ 18 - 14
src/components/weatherInfo.vue

@@ -34,7 +34,7 @@
                     <div class="temperature-text">
                         <span>晴天</span>
                         <div class="temperature-text-time">
-                            <span>10/22 周二</span>
+                            <span>{{ currentDateText }}</span>
                             <span v-show="!isExpanded" class="temperature-text-more" @click="toggleExpand">
                                 展开更多天气
                             </span>
@@ -55,7 +55,7 @@
 </template>
 
 <script setup>
-import { onMounted, ref } from "vue";
+import { ref, onActivated, computed } from "vue";
 import weatherChart from "./weatherChart.vue";
 import { useRouter } from "vue-router";
 const props = defineProps({
@@ -67,18 +67,16 @@ const props = defineProps({
 // 定义emit事件
 const emit = defineEmits(['weatherExpanded','changeGarden']);
 const router = useRouter();
-const containerIdVal = ref(null)
-const handleCommand = ({id, name, containerId}) => {
+const handleCommand = ({id, name}) => {
     farmName.value = name;
     farmId.value = id;
-    containerIdVal.value = containerId;
     // 更新默认农场标识
     const selectedFarm = farmList.value.find(farm => farm.id === id);
     isDefaultFarm.value = selectedFarm ? selectedFarm.defaultOption || false : false;
     // 保存用户选择的农场到 localStorage
     localStorage.setItem('selectedFarmId', id);
     localStorage.setItem('selectedFarmName', name);
-    emit('changeGarden',{id, containerId});
+    emit('changeGarden',{id, name});
 };
 
 const isExpanded = ref(false);
@@ -111,7 +109,6 @@ function getFarmList() {
                     farmName.value = savedFarmName;
                     farmId.value = Number(savedFarmId);
                     isDefaultFarm.value = savedFarm.defaultOption || false;
-                    containerIdVal.value = savedFarm.containerId;
                 } else {
                     // 如果保存的农场不在列表中,按优先级选择
                     selectDefaultFarm(data);
@@ -120,7 +117,7 @@ function getFarmList() {
                 // 如果没有保存的选择,按优先级选择
                 selectDefaultFarm(data);
             }
-            emit('changeGarden',{id: farmId.value, containerId: containerIdVal.value});
+            emit('changeGarden',{id: farmId.value, name: farmName.value});
         }
     })
 }
@@ -135,13 +132,11 @@ function selectDefaultFarm(data) {
         farmName.value = defaultFarm.name;
         farmId.value = defaultFarm.id;
         isDefaultFarm.value = true;
-        containerIdVal.value = defaultFarm.containerId;
     } else {
         // 如果没有默认农场,选择第一个
         farmName.value = data[0].name;
         farmId.value = data[0].id;
         isDefaultFarm.value = data[0].defaultOption || false;
-        containerIdVal.value = data[0].containerId;
     }
     
     // 保存到 localStorage
@@ -149,14 +144,23 @@ function selectDefaultFarm(data) {
     localStorage.setItem('selectedFarmName', farmName.value);
 }
 
-// 暴露getFarmList方法给父组件调用
-defineExpose({
-    getFarmList
-})
+onActivated(() => {
+    getFarmList();
+});
 
 const handleAddGarden = () => {
     router.push(`/create_farm?isReload=true&from=monitor`)
 }
+
+// 获取当前日期和星期
+const currentDateText = computed(() => {
+    const now = new Date();
+    const month = String(now.getMonth() + 1).padStart(2, '0');
+    const day = String(now.getDate()).padStart(2, '0');
+    const weekDays = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'];
+    const weekDay = weekDays[now.getDay()];
+    return `${month}/${day} ${weekDay}`;
+});
 </script>
 
 <style lang="scss" scoped>

+ 0 - 3
src/views/old_mini/agri_services/components/farmDynamics.vue

@@ -88,9 +88,6 @@ const filterType = ref([{
 }, {
     title: "已完成",
     value: 5,
-}, {
-    title: "已过期",
-    value: 6,
 }]);
 
 const activePlanIndex = ref(4);

+ 15 - 7
src/views/old_mini/home/components/problemReminder.vue

@@ -51,15 +51,21 @@
 </template>
 <script setup>
 import { Popup } from "vant";
-import { ref, onActivated } from "vue";
+import { ref,watch } from "vue";
 import wx from "weixin-js-sdk";
 import activeUploadPopup from "@/components/popup/activeUploadPopup.vue";
 import detailDialog from "@/components/detailDialog.vue";
 import eventBus from "@/api/eventBus";
 import { useRouter } from "vue-router";
-import { sassTrue } from "sass";
 const router = useRouter();
 
+const props = defineProps({
+    farmId: {
+        type: [Number, String],
+        default: null,
+    }
+}); 
+
 const show = ref(false);
 const noShow = ref(false);
 const dropdownGardenItem = ref({
@@ -83,15 +89,17 @@ const detailDialogRef = ref(null);
 
 const curRole = localStorage.getItem("SET_USER_CUR_ROLE");
 
-onActivated(() => {
-    fetchQuestPopup();
+watch(() => props.farmId, (newVal) => {
+    if (newVal) {
+        fetchQuestPopup();
+    }
 });
 
 const questPopupData = ref({});
 const bottomAnswerOptions = ref([]);
 const fetchQuestPopup = () => {
     VE_API.home
-        .fetchQuestPopup({ farmId: 93490 })
+        .fetchQuestPopup({ farmId: props.farmId })
         .then(({ data }) => {
             if (Array.isArray(data) && data.length > 0) {
                 show.value = true;
@@ -147,7 +155,7 @@ function onBottomOptionClick(opt) {
     optValue.value = opt.value;
     if (opt.value == 1) {
         eventBus.emit("activeUpload:show", {
-            gardenIdVal: 93490,
+            gardenIdVal: props.farmId,
             problemTitleVal: "请选择您出现白点的时间",
             typeVal: "question",
         });
@@ -159,7 +167,7 @@ function onBottomOptionClick(opt) {
 function saveQuestPopup() {
     const agriDate = getTodayStr();
     const params = {
-        farmId: 93490,
+        farmId: props.farmId,
         phenologyId: questPopupData.value.phenologyId,
         indicatorId: questPopupData.value.indicatorId,
         answerValue: optValue.value,

+ 17 - 4
src/views/old_mini/home/index.vue

@@ -4,7 +4,7 @@
         <!-- 天气遮罩 -->
         <div class="weather-mask" v-show="isExpanded"></div>
         <!-- 天气 -->
-        <weather-info class="weather-info" @weatherExpanded="weatherExpanded" :isGarden="false"></weather-info>
+        <weather-info 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">
@@ -52,11 +52,11 @@
         </div>
     </popup>
     <!-- 问题提醒 -->
-    <problem-reminder></problem-reminder>
+    <problem-reminder :farmId="gardenId"></problem-reminder>
 </template>
 
 <script setup>
-import { ref, computed, onMounted, onActivated } from "vue";
+import { ref, computed, onActivated } from "vue";
 import { useStore } from "vuex";
 import { Popup } from "vant";
 import weatherInfo from "@/components/weatherInfo.vue";
@@ -75,6 +75,19 @@ const route = useRoute();
 const showFarmPopup = ref(false);
 const farmPopupType = ref("create");
 
+const gardenId = ref(null);
+const changeGarden = ({id}) => {
+    gardenId.value = id;
+    getExpertByFarmId();
+}
+
+const expertInfo = ref({});
+const getExpertByFarmId = () => {
+    VE_API.home.getExpertByFarmId({ farmId: gardenId.value }).then(({ data }) => {
+        expertInfo.value = data || {};
+    });
+}
+
 // 监测卡片数据
 const monitorCards = ref({
     left: {
@@ -117,7 +130,7 @@ const handleCardClick = (card) => {
         }
     } else {
         if (card.route === "/chat_frame") {
-            router.push(`/chat_frame?userId=91754&name=专家1`);
+            router.push(`/chat_frame?userId=${expertInfo.value.appUserId}&name=${expertInfo.value.name}`);
         } else {
             router.push(card.route);
         }

+ 5 - 5
src/views/old_mini/home/subPages/expertList.vue

@@ -55,7 +55,7 @@
         </div>
         <div class="prescription-content">
             <div class="list">
-                <div class="list-item" v-for="(item, index) in list" :key="index" @click.stop="toPage(item.containerId)">
+                <div class="list-item" v-for="(item, index) in list" :key="index">
                     <div class="list-top">
                         <div class="user">
                             <img :src="item.pic" alt="" />
@@ -122,7 +122,8 @@ const isToSelect = route.query.isToSelect ? true : false
 
 const handlePage = ({isDefault,userId}) =>{
     if(isDefault==null){
-        router.push(`/expert_prescription?userId=${userId}&disabled=true`)
+        console.log('isDefault',isDefault);
+        // router.push(`/expert_prescription?userId=${userId}&disabled=true`)
     }else{
         router.push('/expert_prescription')
     }
@@ -151,13 +152,12 @@ onMounted(() => {
     getSpecieList()
 });
 
-function toPage(containerId) {
-    // userId=${id}&name=${name}
+function toPage({containerId,userId,name}) {
     if (isToSelect) {
         router.push(`/expert_homepage?containerId=${containerId}`)
         // router.replace(`/expert_homepage?containerId=${containerId}`)
     } else {
-        router.push(`/chat_frame?userId=91754&name=咨询专家`)
+        router.push(`/chat_frame?userId=${userId}&name=${name}`)
     }
 }
 

+ 1 - 2
src/views/old_mini/mine/pages/farm.vue

@@ -5,7 +5,7 @@
             <div class="list-item" v-for="item in 3" :key="item">
                 <div class="item-info">
                     <div class="item-top">
-                        <div class="left-img"></div>
+                        <img class="left-img" src="@/assets/img/home/farm.png" alt="">
                         <div class="left-content">
                             <div class="content-title">
                                 <span>荔枝博览园</span>
@@ -56,7 +56,6 @@ import { ref } from "vue";
                         width: 68px;
                         height: 68px;
                         border-radius: 8px;
-                        background-color: red;
                     }
                     .left-content {
                         .content-title {

+ 33 - 97
src/views/old_mini/mine/pages/messageList.vue

@@ -1,21 +1,20 @@
 <template>
     <div class="container">
-        <custom-header name="专家咨询"></custom-header>
+        <custom-header name="我的消息"></custom-header>
         <div class="message-list">
             <div class="message-item" v-for="(item, index) in messageList" :key="index" @click="handleItem(item)">
                 <div class="message">
-                    <!-- <img class="img" v-if="item.type!=='message'" :src="require(`@/assets/img/mine/${item.type}.png`)" alt="" /> -->
-                    <img class="img" v-if="item.senderId===userId&&item.type==='message'" :src="item.receiverIcon || 'https://birdseye-img.sysuimars.com/birdseye-look-mini/Group%201321316260.png'" alt="">
-                    <img class="img" v-else :src="item.senderIcon || 'https://birdseye-img.sysuimars.com/birdseye-look-mini/Group%201321316260.png'" alt="">
+                    <!-- <img class="img" v-if="item.senderId===userId&&item.type==='message'" :src="item.targetUserAvatar || 'https://birdseye-img.sysuimars.com/birdseye-look-mini/Group%201321316260.png'" alt=""> -->
+                    <img class="img" :src="item.targetUserAvatar || 'https://birdseye-img.sysuimars.com/birdseye-look-mini/Group%201321316260.png'" alt="">
                     <div class="info">
-                        <span class="name" v-if="item.senderId===userId">{{item.receiverName}}</span>
-                        <span class="name" v-else>{{item.senderName}}</span>
-                        <div class="van-ellipsis" v-if="item.content.type==='object'">[图片]</div>
+                        <!-- <span class="name" v-if="item.senderId===userId">{{item.receiverName}}</span> -->
+                        <span class="name">{{item.targetUserName || '飞鸟种植助手'}}</span>
+                        <div class="van-ellipsis" v-if="item.newMessageType==='image'">[图片]</div>
                         <div class="van-ellipsis" v-else>{{item.newContent}}</div>
                     </div>
                 </div>
                 <div class="date-time">
-                    <div>{{item.time || '03/22 13:08'}}</div>
+                    <div>{{timeFormat(item.updateTime) || '03/22 13:08'}}</div>
                     <badge v-show="item.unreadCount&&item.unreadCount!=0" class="badge" :content="item.unreadCount" max="99"></badge>
                 </div>
             </div>
@@ -25,53 +24,15 @@
 
 <script setup>
 import { Badge } from "vant";
-import { computed, onActivated, ref,onDeactivated } from "vue";
+import { onMounted, ref,onUnmounted } from "vue";
 import MqttClient from "@/plugins/MqttClient";
-import { useRouter } from "vue-router";
-import { deepClone } from "@/common/commonFun";
-import eventBus from "@/api/eventBus";
+import { useRouter,useRoute } from "vue-router";
 import customHeader from "@/components/customHeader.vue";
 const router = useRouter();
-
+const route = useRoute();
 const userId = Number(localStorage.getItem('MINI_USER_ID'))
 
-const defalutList = ref([
-    {
-        senderName: "专家1",
-        type: "report",
-        typeNum:3,
-        newContent: "好的,我看看后天有没有无人机安我看看后天有没有无人机安",
-        time: "",
-        content:{
-            type:'text'
-        },
-        unreadCount: 1,
-    },
-    {
-        senderName: "专家1",
-        type: "system",
-        typeNum:2,
-        newContent: "好的,我看看后天有没有无人机安...",
-        time: "",
-        content:{
-            type:'text'
-        },
-        unreadCount: 5,
-    },
-    {
-        senderName: "专家1",
-        typeNum:1,
-        type: "warn",
-        newContent: "好的,我看看后天有没有无人机安...",
-        time: "",
-        content:{
-            type:'text'
-        },
-        unreadCount: 10,
-    },
-])
-
-const messageList = ref(defalutList.value);
+const messageList = ref([]);
 
 const timeFormat = (dateStr) =>{
     // 提取月、日、时、分
@@ -82,36 +43,14 @@ const timeFormat = (dateStr) =>{
     return formattedDate
 }
 
-const handleItem = ({type,receiverName,receiverId,senderId,senderName,unreadCount,typeNum}) =>{
-    // let name = senderName
-    // let id = senderId
-    // if(senderId===userId){
-    //     name = receiverName
-    //     id = receiverId
-    // }
-    // if(type==='message'){
-    //     router.push(`/dialogue?userId=${id}&name=${name}`);
-    // }else{
-    //     router.push(`/warn_page?name=${name}&type=${typeNum}`);
-    // }
-    router.push(`/chat_frame?userId=91754&name=专家1`);
+const handleItem = ({targetUserId,targetUserName,farmId}) =>{
+    VE_API.bbs.readUpdate({ targetUserId,farmId }).then((res) => {
+        if (res.code === 0) {
+            router.push(`/chat_frame?userId=${targetUserId}&name=${targetUserName || '飞鸟种植助手'}&farmId=${farmId}`);
+        }
+    });
 }
 
-function checkJSON(str) {
-  try {
-    const parsed = JSON.parse(str);
-    return {
-      isJSON: true,
-      type: Array.isArray(parsed) ? 'array' : typeof parsed,
-      value: parsed
-    };
-  } catch (e) {
-    return {
-      isJSON: false,
-      value: str
-    };
-  }
-}
 const mqttClient = ref(null)
 const initMqtt = () =>{
     mqttClient.value = new MqttClient(['chat/message/'+userId], (topic, message) => {
@@ -122,32 +61,29 @@ const initMqtt = () =>{
 }
 
 const getMessageList = () =>{
-    messageList.value = deepClone(defalutList.value)
-    VE_API.bbs.list().then((res) => {
-        const arr = res.data.map(item =>{
-            return {
-                ...item,
-                content:checkJSON(item.newContent),
-                time:timeFormat(item.updateTime),
-                type:'message'
-            }
-        });
-        messageList.value.push(...arr)
+    VE_API.bbs.getSessionListAll().then((res) => {
+        messageList.value = res.data || [];
     });
 }
 
-const getGroupList = () =>{
-    // getMessageList()
+const getListByFarm = () =>{
+    VE_API.bbs.sessionListByFarm({ farmId: route.query.farmId }).then((res) => {
+        messageList.value = res.data || [];
+    });
 }
 
-onActivated(()=>{
-    initMqtt()
-    getGroupList()
+onMounted(()=>{
+    // initMqtt()
+    if(localStorage.getItem('SET_USER_CUR_ROLE') == 0){
+        getListByFarm()
+    }else{
+        getMessageList()
+    }
 })
 
-onDeactivated(()=>{
-    mqttClient.value.client.end(true);
-})
+// onUnmounted(()=>{
+//     mqttClient.value.client.end(true);
+// })
 </script>
 
 <style lang="scss" scoped>

+ 3 - 7
src/views/old_mini/monitor/index.vue

@@ -4,7 +4,6 @@
         <div class="weather-mask" v-show="isExpanded"></div>
         <!-- 天气 -->
         <weather-info
-            ref="weatherInfoRef"
             class="weather-info"
             @weatherExpanded="weatherExpanded"
             @changeGarden="changeGarden"
@@ -104,7 +103,6 @@ const router = useRouter();
 const route = useRoute();
 
 const farmInfoRef = ref(null);
-const weatherInfoRef = ref(null);
 
 function toFarmInfo() {
     farmInfoRef.value.handleShow();
@@ -254,11 +252,6 @@ const handleBroadcast = () => {
     speechSynthesis.speak(utterance);
 };
 
-// 组件激活时检查是否需要刷新农场列表
-onActivated(() => {
-    weatherInfoRef.value.getFarmList();
-});
-
 // 组件卸载时停止语音播放
 onUnmounted(() => {
     if (isSpeaking.value) {
@@ -288,6 +281,9 @@ const changeGarden = ({id}) => {
 function handlePage(url) {
     router.push({
         path: url,
+        query: {
+            farmId: gardenId.value
+        }
     });
 }
 </script>

+ 3 - 3
src/views/old_mini/task_condition/components/task.vue

@@ -261,7 +261,7 @@ function toPage(item) {
             onlyShare.value = false;
         }
         setTimeout(() => {
-            uploadExecuteRef.value.showPopup(item.id,'share-sheet');
+            uploadExecuteRef.value.showPopup(item,'share-sheet');
         }, 10);
     } else {
         // 下发农事请求
@@ -311,7 +311,7 @@ function handleAction(item) {
     }else{
         onlyShare.value = true;
         setTimeout(() => {
-            uploadExecuteRef.value.showPopup(item.id,'share-sheet');
+            uploadExecuteRef.value.showPopup(item,'share-sheet');
         }, 10);
     }
 }
@@ -329,7 +329,7 @@ function handlePopupBtn() {
 function handleForward(item) {
     onlyShare.value = true;
     setTimeout(() => {
-        uploadExecuteRef.value.showPopup(item.id,'share-sheet');
+        uploadExecuteRef.value.showPopup(item,'share-sheet');
     }, 10);
 }
 

+ 9 - 3
src/views/old_mini/task_condition/components/uploadExecute.vue

@@ -24,9 +24,11 @@
 import { Popup } from "vant";
 import { ref } from "vue";
 import upload from "@/components/upload";
+import { useRouter } from "vue-router";
 import { ElMessage } from "element-plus";
 import FnShareSheet from "@/components/pageComponents/FnShareSheet.vue";
 
+const router = useRouter();
 const props = defineProps({
     onlyShare: {
         type: Boolean,
@@ -37,16 +39,17 @@ const props = defineProps({
 const show = ref(false);
 const className = ref(null);
 const farmWorkRecordId = ref(null);
-function showPopup(id,classNameVal) {
+const farmData = ref({});
+function showPopup(data,classNameVal) {
     if (props.onlyShare) {
         showShare.value = true;
         className.value = classNameVal;
     } else {
         show.value = true;
-        farmWorkRecordId.value = id;
+        farmWorkRecordId.value = data.id;
     }
+    farmData.value = data;
 }
-
 const images = ref([]);
 function handleUpload({imgArr}) {
     images.value = imgArr;
@@ -68,6 +71,9 @@ function handleConfirm() {
 
 const showShare = ref(false);
 const onSelect = ({type}) => {
+    if(type === 'birdseye') {
+        router.push(`/chat_frame?userId=${farmData.value.farmMiniUserId}&name=${farmData.value.farmMiniUserName}&farmId=${farmData.value.farmId}&pageParams=${JSON.stringify(farmData.value)}`);
+    }
     console.log(type);
 };