Explorar o código

feat:修改农事流程分享飞鸟用户bug

wangsisi hai 2 semanas
pai
achega
42c5d123b8

+ 24 - 33
src/components/chatWindow.vue

@@ -56,7 +56,7 @@
                             </template>
                             <template v-else>
                                 <div class="card-title">{{ msg.title || msg.content.title }}</div>
-                                <img :src="base_img_url2 + (msg.coverUrl || msg.content.coverUrl) + resize" alt="" />
+                                <img :src="handleImgUrl(msg.coverUrl || msg.content.coverUrl)" alt="" />
                             </template>
                         </div>
 
@@ -246,9 +246,7 @@ watch(nameVal, (newVal) => {
 
 //聊天会话
 const createSession = (targetUserId, callback) => {
-    // 先保存当前的对话样式消息  要注释
-    // const dialogMessages = messages.value.filter((msg) => msg.messageType === "dialog");
-
+    nameVal.value = '';
     VE_API.bbs.createSession({ farmId: farmVal.value, targetUserId }).then(({ data, code }) => {
         if (code === 0) {
             nameVal.value = data.session.targetUserName;
@@ -281,11 +279,6 @@ const createSession = (targetUserId, callback) => {
                 };
             });
 
-            // // 重新添加对话样式消息   要注释
-            // if (dialogMessages.length > 0) {
-            //     messages.value = [...messages.value, ...dialogMessages];
-            // }
-
             setTimeout(() => {
                 scrollToBottom();
             }, 300);
@@ -348,7 +341,7 @@ watch(
                         const imgArr = JSON.parse(params.executeEvidence);
                         message.coverUrl = imgArr[imgArr.length - 1];
                     }
-                    console.log('params.imageList', params.imageList)
+
                     if(params.imageList && params.imageList.length) {
                         const img = params.imageList[params.imageList.length - 1];
                         if (img.cloudFilename) {
@@ -372,7 +365,7 @@ watch(
                     if(params.type === 'reviewWork') {
                         message.cardType = 'reviewWork';
                         message.title = '向您分享了农事执行成果'
-                        message.linkUrl = `/review_work?json=${JSON.stringify({id: params.id})}`;
+                        message.linkUrl = `/review_work?json=${JSON.stringify({id: params.id,goBack: true})}`;
                     }
 
                     if(params.type === 'remindExecute' || params.type === 'remindUser') {
@@ -385,7 +378,7 @@ watch(
                             message.linkUrl = `/completed_work?json=${JSON.stringify(jsonParams)}`;
                         } else if(params.type === 'remindUser') {
                             message.title = '请您尽快完成复核';
-                            message.linkUrl = `/review_work?json=${JSON.stringify({id:params.id})}`;
+                            message.linkUrl = `/review_work?json=${JSON.stringify({id:params.id,goBack: true})}`;
                         }
                         message.cardType = params.type
                     }
@@ -471,6 +464,10 @@ const initMqtt = () => {
                 return;
             }
             if (obj.senderId === receiverIdVal.value) {
+                // 检查是否已存在相同 id 的消息,避免重复添加
+                if (obj.id && messages.value.some(msg => msg.id === obj.id)) {
+                    return;
+                }
                 if (obj.messageType === "image") {
                     if (obj.image && (obj.image.url || obj.image.originUrl)) {
                         obj.content = obj.image.url || obj.image.originUrl;
@@ -482,6 +479,8 @@ const initMqtt = () => {
                             console.error(e, "e");
                         }
                     }
+                }else{
+                    obj.content = JSON.parse(obj.content);
                 }
                 obj.receiverId = curUserId;
                 (obj.sender = obj.senderId === curUserId ? "sent" : "received"), (obj.senderIcon = senderIcon.value);
@@ -703,31 +702,23 @@ const route = useRoute();
 
 // 获取农场列表
 function getFarmList() {
-    if(curRole.value == 2) {
-        return VE_API.user.userList().then(({ data }) => {
-            options.value = data.map(item => ({
-                id: item.farmId,
-                name: item.farmName,
-            }));
+    let params = {
+        agriculturalQuery: false,
+    }
+    if(curRole.value == 2){
+        params.userId = props.userId;
+    }
+    return VE_API.farm.userFarmSelectOption(params).then(({ data }) => {
+        options.value = data || [];
+        if (data && data.length > 0) {
+            const defaultOption = data.find((item) => item.defaultOption === true);
             if(route.query.farmId) {
                 farmVal.value = Number(route.query.farmId);
             }else{
-                farmVal.value = data[0].farmId;
+                farmVal.value = defaultOption ? defaultOption.id : data[0].id;
             }
-        });
-    }else{
-        return VE_API.farm.userFarmSelectOption({ agriculturalQuery: false }).then(({ data }) => {
-            options.value = data || [];
-            if (data && data.length > 0) {
-                const defaultOption = data.find((item) => item.defaultOption === true);
-                if(route.query.farmId) {
-                    farmVal.value = Number(route.query.farmId);
-                }else{
-                    farmVal.value = defaultOption ? defaultOption.id : data[0].id;
-                }
-            }
-        });
-    }
+        }
+    });
 }
 
 const curRole = ref(null);

+ 0 - 2
src/components/customHeader.vue

@@ -11,7 +11,6 @@
 </template>
 
 <script setup>
-import eventBus from "@/api/eventBus";
 import { ref } from "vue";
 import { useRouter} from "vue-router";
 const router = useRouter();
@@ -45,7 +44,6 @@ const goback = () => {
   if(!props.isGoBack){
     router.go(-1);
   }else{
-    // eventBus.emit('header:goback')
     emit('goback')
   }
 };

+ 1 - 1
src/components/popup/priceSheetPopup.vue

@@ -237,7 +237,7 @@ const handleShare = () => {
         type:'quotation'
     }
     if(userId){
-        router.push(`/chat_frame?userId=${userId}&name=${parmasPage.farmMiniUserName}&farmId=${parmasPage.farmId}&pageParams=${JSON.stringify(parmasPage)}`);
+        router.push(`/chat_frame?userId=${userId}&farmId=${parmasPage.farmId}&pageParams=${JSON.stringify(parmasPage)}`);
     }else{
         ElMessage.warning('尚未绑定用户,暂时无法分享')
     }   

+ 1 - 1
src/components/taskItem.vue

@@ -287,7 +287,7 @@ const toDetail = (status, id, farmWorkId) => {
         // 复核成效
         router.push({
             path: "/review_work",
-            query: { json: JSON.stringify({ id }) }
+            query: { json: JSON.stringify({ id, goBack: true }) }
         });
     } else {
         detailDialogRef.value.showDialog(farmWorkId, '', false);

+ 5 - 0
src/components/upload.vue

@@ -100,6 +100,11 @@ function uploadReset(){
     imgArr.value = []
 }
 
+
+defineExpose({
+    uploadReset
+})
+
 onMounted(()=>{
     eventBus.off('upload:reset',uploadReset)
     eventBus.on('upload:reset',uploadReset)

+ 1 - 1
src/views/old_mini/agri_services/components/farmDynamics.vue

@@ -120,7 +120,7 @@ const hasUploadedPhotos = (section) => {
 
 const handleClick = (section) => {
     if(activePlanIndex.value == 5){
-        router.push(`/review_work?json=${JSON.stringify({id:section.id})}`);
+        router.push(`/review_work?json=${JSON.stringify({id:section.id, goBack: true})}`);
     }else{
         router.push({
             path: "/completed_work",

+ 18 - 18
src/views/old_mini/chat_frame/index.vue

@@ -1,13 +1,13 @@
 <template>
     <div class="dialogue">
-        <custom-header :name="nameVal" bgColor="#f2f3f5"></custom-header>
+        <custom-header :name="nameVal" bgColor="#f2f3f5" isGoBack @goback="headerCallBack"></custom-header>
         <chat-window :text="desc" :userId="userIdVal" :img="imgVal" @update:name="nameVal = $event"></chat-window>
     </div>
 </template>
 
 <script setup>
 import customHeader from "@/components/customHeader.vue";
-import { onActivated, onDeactivated, ref } from "vue";
+import { onActivated, ref } from "vue";
 import chatWindow from "@/components/chatWindow";
 import { useRoute, useRouter } from "vue-router";
 import eventBus from "@/api/eventBus";
@@ -18,35 +18,35 @@ const desc = ref("");
 const nameVal = ref("");
 const userIdVal = ref(null);
 const imgVal = ref("");
+const formPageVal = ref("");
 onActivated(() => {
     userIdVal.value = null;
-    eventBus.off("header:goback", headerCallBack);
     setTimeout(() => {
-        const { text, name, userId, img } = route.query;
+        const { text, formPage, userId, img } = route.query;
         desc.value = text;
-        nameVal.value = name;
         userIdVal.value = userId;
         imgVal.value = img;
-        eventBus.on("header:goback", headerCallBack);
+        formPageVal.value = formPage;
+        if(formPage) {
+            sessionStorage.setItem('chat_frame_page', formPage);
+        }
     }, 100);
 });
 
 function headerCallBack() {
-    if (desc.value) {
-        router.go("-2");
+    const page = sessionStorage.getItem('chat_frame_page');
+    console.log("page", page);
+    if(page === 'messageList') {
+        VE_API.bbs.readUpdate({ targetUserId: userIdVal.value, farmId: route.query.farmId }).then((res) => {
+            if (res.code === 0) {
+                sessionStorage.removeItem('chat_frame_page');
+                router.replace({ path: '/message_list', query: { farmId: route.query.farmId, from: 'monitor' } });
+            }
+        });
     } else {
-        router.go("-1");
+        router.go(-1);
     }
 }
-
-onDeactivated(() => {
-    eventBus.off("header:goback", headerCallBack);
-    VE_API.bbs.readUpdate({ targetUserId: userIdVal.value }).then((res) => {
-        if (res.success) {
-            eventBus.emit("isUpdateTotal");
-        }
-    });
-});
 </script>
 
 <style lang="scss" scoped>

+ 1 - 1
src/views/old_mini/home/index.vue

@@ -131,7 +131,7 @@ const handleCardClick = (card) => {
         }
     } else {
         if (card.route === "/chat_frame") {
-            router.push(`/chat_frame?userId=${expertInfo.value.appUserId}&name=${expertInfo.value.name}`);
+            router.push(`/chat_frame?userId=${expertInfo.value.appUserId}`);
         } else {
             router.push(card.route);
         }

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

@@ -212,7 +212,7 @@ function toPage({ containerId, userId, name }) {
         router.push(`/expert_homepage?containerId=${containerId}`);
         // router.replace(`/expert_homepage?containerId=${containerId}`)
     } else {
-        router.push(`/chat_frame?userId=${userId}&name=${name}`);
+        router.push(`/chat_frame?userId=${userId}`);
     }
 }
 

+ 11 - 3
src/views/old_mini/mine/pages/messageList.vue

@@ -1,6 +1,6 @@
 <template>
     <div class="container">
-        <custom-header name="我的消息"></custom-header>
+        <custom-header name="我的消息" isGoBack @goback="headerCallBack"></custom-header>
         <div class="message-list">
             <div class="message-item" v-for="(item, index) in messageList" :key="index" @click="handleItem(item)">
                 <div class="message">
@@ -43,14 +43,22 @@ const timeFormat = (dateStr) =>{
     return formattedDate
 }
 
-const handleItem = ({targetUserId,targetUserName,farmId}) =>{
+const handleItem = ({targetUserId,farmId}) =>{
     VE_API.bbs.readUpdate({ targetUserId,farmId }).then((res) => {
         if (res.code === 0) {
-            router.push(`/chat_frame?userId=${targetUserId}&name=${targetUserName || '飞鸟种植助手'}&farmId=${farmId}`);
+            router.push(`/chat_frame?userId=${targetUserId}&farmId=${farmId}&formPage=messageList`);
         }
     });
 }
 
+const headerCallBack = () =>{
+    if(route.query.from === 'monitor') {
+        router.replace('/monitor');
+    } else {
+        router.replace('/mine');
+    }
+}
+
 const mqttClient = ref(null)
 const initMqtt = () =>{
     mqttClient.value = new MqttClient(['chat/message/'+userId], (topic, message) => {

+ 6 - 1
src/views/old_mini/mine/pages/serviceDetail.vue

@@ -107,7 +107,7 @@ const getDetailList = () => {
 };
 
 const handleClick = (section) => {
-    router.push(`/review_work?json=${JSON.stringify({id:section.id})}`);
+    router.push(`/review_work?json=${JSON.stringify({id:section.id,goBack: true})}`);
 };
 
 const handleChatFarm = () => {
@@ -133,7 +133,12 @@ const handleTitleRightClick = ({id, reviewImage}) => {
     width: 100%;
     height: 100vh;
     background: #f7f7f7;
+    display: flex;
+    flex-direction: column;
+    overflow: hidden;
     .service-detail-content {
+        flex: 1;
+        overflow-y: auto;
         padding: 10px 12px;
         .record-box {
             margin-bottom: 0;

+ 1 - 1
src/views/old_mini/modify_work/completedWork.vue

@@ -476,7 +476,7 @@ const handlePopupBtn = () => {
             router.replace({
                 path: "/review_work",
                 query: {
-                    json: JSON.stringify({ id: query.value.id }),
+                    json: JSON.stringify({ id: query.value.id,goBack: true }),
                 },
             });
         }

+ 14 - 16
src/views/old_mini/modify_work/reviewWork.vue

@@ -1,6 +1,6 @@
 <template>
     <div class="work-wrap">
-        <custom-header name="农事成效"></custom-header>
+        <custom-header name="农事成效" :isClose="paramsPage.goBack ? false : true"></custom-header>
         <div class="work-content recheck-title" :class="{ 'no-bottom': curRole == '0' && (!workItem.reviewImage ||!workItem.reviewImage.length) }" v-loading="loading">
             <div class="tabs-content-item">
                 <div class="common-card-title">
@@ -82,17 +82,17 @@
                     <img class="icon" src="@/assets/img/home/label-icon.png" alt="" />
                     <span>复核成效</span>
                 </div>
-                <div class="info-box bottom-box">
-                    <div class="result-box">
-                        <div class="result-text" v-if="workItem.reviewImage && workItem.reviewImage.length">
-                            促进分蘖芽萌发、加快分蘖生长,同时补充氮素等关键养分,增强植株长势,为形成足够穗数、提高群体产量打基础。
-                            <!-- 通过精准农业技术的应用,作物产量实现了两位数的增长,病虫害的发生率大幅下降,土壤肥力的提升 -->
-                        </div>
-                        <div class="result-text time-text" v-else>
-                            请抓紧时间上传照片!系统为您生成农事成效分析!
-                            <!-- 距离农事执行已 15 天,请抓紧时间上传照片!系统为您生成农事成效分析! -->
-                        </div>
+                <div class="result-box">
+                    <div class="result-text" v-if="workItem.reviewImage && workItem.reviewImage.length">
+                        促进分蘖芽萌发、加快分蘖生长,同时补充氮素等关键养分,增强植株长势,为形成足够穗数、提高群体产量打基础。
+                        <!-- 通过精准农业技术的应用,作物产量实现了两位数的增长,病虫害的发生率大幅下降,土壤肥力的提升 -->
                     </div>
+                    <div class="result-text time-text" v-else>
+                        请抓紧时间上传照片!系统为您生成农事成效分析!
+                        <!-- 距离农事执行已 15 天,请抓紧时间上传照片!系统为您生成农事成效分析! -->
+                    </div>
+                </div>
+                <div class="info-box bottom-box">
                     <div class="recheck-box">
                         <div class="recheck-ablum">
                             <div class="img-list over-img-box">
@@ -418,6 +418,8 @@ const handleUpload = ({ imgArr }) => {
                 font-size: 16px;
                 display: flex;
                 align-items: center;
+                border-bottom: 1px solid #f5f5f5;
+                padding-bottom: 10px;
                 .icon {
                     width: 14px;
                     height: 8px;
@@ -543,8 +545,6 @@ const handleUpload = ({ imgArr }) => {
                 &.bottom-box {
                     flex-direction: column;
                 }
-                // margin-top: 12px;
-                border-top: 1px solid #f5f5f5;
                 padding-top: 12px;
                 display: flex;
                 align-items: center;
@@ -663,9 +663,6 @@ const handleUpload = ({ imgArr }) => {
                     padding-bottom: 5px;
                 }
             }
-            .recheck-box {
-                margin-top: 12px;
-            }
             .recheck-box,
             .recheck-ablum {
                 width: 100%;
@@ -748,6 +745,7 @@ const handleUpload = ({ imgArr }) => {
                 font-size: 12px;
                 color: #666666;
                 line-height: 18px;
+                margin-top: 12px;
             }
             .time-text {
                 color: #ff953d;

+ 13 - 4
src/views/old_mini/monitor/index.vue

@@ -75,7 +75,7 @@
                             </div>
                             <div class="item-title">{{ item.title }}</div>
                         </div>
-                        <div class="item-status van-multi-ellipsis--l2">{{ item.content }}</div>
+                        <div class="item-status van-multi-ellipsis--l2" v-html="item.content"></div>
                     </div>
                     <div class="item-zone" v-if="item.regionId">
                         <div class="point"></div>
@@ -390,11 +390,15 @@ const changeGarden = ({ id }) => {
 };
 
 function handlePage(url) {
+    const query = {
+        farmId: gardenId.value,
+    }
+    if(url === '/message_list') {
+        query.from = 'monitor';
+    }
     router.push({
         path: url,
-        query: {
-            farmId: gardenId.value,
-        },
+        query: query,
     });
 }
 </script>
@@ -630,6 +634,11 @@ function handlePage(url) {
                         margin-top: 3px;
                         font-size: 13px;
                         color: rgba(29, 33, 41, 0.5);
+                        ::v-deep{
+                            p{
+                                margin: 2px 0 0 0;
+                            }
+                        }
 
                         .countdown {
                             color: #ff7254;

+ 1 - 1
src/views/old_mini/monitor/subPages/plan copy.vue

@@ -584,7 +584,7 @@ const handleRowClick = (item) => {
         router.push({
             path: "/review_work",
             query: {
-                json: JSON.stringify({ id: item.id })
+                json: JSON.stringify({ id: item.id,goBack: true })
             },
         });
     } else if (item.type !== "term" && item.status === "default") {

+ 21 - 5
src/views/old_mini/monitor/subPages/plan.vue

@@ -145,6 +145,12 @@ onMounted(() => {
 });
 
 const getFarmWorkPlan = () => {
+    // 如果不是首次加载,保存当前滚动位置
+    let savedScrollTop = 0;
+    if (!isInitialLoad.value && timelineContainerRef.value) {
+        savedScrollTop = timelineContainerRef.value.scrollTop || 0;
+    }
+    
     VE_API.monitor
         .farmWorkPlan({ farmId: route.query.farmId })
         .then(({ data, code }) => {
@@ -177,11 +183,19 @@ const getFarmWorkPlan = () => {
                       }))
                     : [];
                 
-                // 设置默认季节为当前季节,并自动滚动到对应位置
-                const currentSeason = getCurrentSeason();
-                // 等待 DOM 更新后自动选中并滚动到当前季节
+                // 等待 DOM 更新后处理滚动
                 nextTick(() => {
-                    handleSeasonClick(currentSeason);
+                    if (isInitialLoad.value) {
+                        // 首次加载:设置默认季节为当前季节,并自动滚动到对应位置
+                        const currentSeason = getCurrentSeason();
+                        handleSeasonClick(currentSeason);
+                        isInitialLoad.value = false;
+                    } else {
+                        // 非首次加载:恢复之前的滚动位置
+                        if (timelineContainerRef.value && savedScrollTop > 0) {
+                            timelineContainerRef.value.scrollTop = savedScrollTop;
+                        }
+                    }
                 });
             }
         })
@@ -216,7 +230,7 @@ const handleRowClick = (item) => {
         router.push({
             path: "/review_work",
             query: {
-                json: JSON.stringify({ id: item.farmWorkRecordId }),
+                json: JSON.stringify({ id: item.farmWorkRecordId,goBack: true }),
             },
         });
     } else if (item.flowStatus === null) {
@@ -242,6 +256,8 @@ const manageTask = () => {
 
 const detailDialogRef = ref(null);
 const timelineContainerRef = ref(null);
+// 标记是否为首次加载
+const isInitialLoad = ref(true);
 
 // 安全解析时间到时间戳(ms)
 const safeParseDate = (val) => {

+ 1 - 1
src/views/old_mini/monitor/subPages/reviewResults.vue

@@ -138,7 +138,7 @@ const handleClick = (section, index) => {
     router.push({
         path: "/review_work",
         query: {
-            json: JSON.stringify({ id: section.id }),
+            json: JSON.stringify({ id: section.id,goBack: true }),
         },
     });
 };

+ 1 - 1
src/views/old_mini/task_condition/components/reviewPopup.vue

@@ -124,7 +124,7 @@ const handleShare = () => {
     };
     if (userId) {
         router.push(
-            `/chat_frame?userId=${userId}&name=${parmasPage.farmMiniUserName}&farmId=${
+            `/chat_frame?userId=${userId}&farmId=${
                 parmasPage.farmId
             }&pageParams=${JSON.stringify(parmasPage)}`
         );

+ 7 - 4
src/views/old_mini/task_condition/components/uploadExecute.vue

@@ -11,7 +11,7 @@
                 请上传执行照片
             </div>
         </div>
-        <upload exampleImg class="upload-wrap" @handleUpload="handleUpload">
+        <upload ref="uploadRef" exampleImg class="upload-wrap" @handleUpload="handleUpload">
             <img class="example" src="@/assets/img/home/example-4.png" alt="" />
             <img class="example" src="@/assets/img/home/plus.png" alt="">
         </upload>
@@ -59,14 +59,17 @@ function handleUpload({imgArr}) {
     images.value = imgArr;
 }
 
+const uploadRef = ref(null);
+
 function handleConfirm() {
+    if (images.value.length === 0) return ElMessage.warning("请上传图片");
     const params = {
         recordId: farmWorkRecordId.value,
         executeEvidence: images.value,
     };
     VE_API.z_farm_work_record.addExecuteImg(params).then((res) => {
         if (res.code === 0) {
-            // ElMessage.success('请求确认成功');
+            ElMessage.success('您已上传成功');
             show.value = false;
             VE_API.z_farm_work_record.getDetail({ id: farmData.value.id }).then(({ data }) => {
                 const dataItem = data[0];
@@ -80,7 +83,7 @@ function handleConfirm() {
                     id: dataItem.id,
                 }
                 farmData.value.type = 'confirmExecute'
-                // 通知父组件上传成功,需要刷新数据
+                uploadRef.value.uploadReset();
                 emit('uploadSuccess', farmData.value.id);
                 showShare.value = true;
             });
@@ -98,7 +101,7 @@ const onSelect = async ({type}) => {
             if(triggerImg.value.length) {
                 farmData.value.imageList = triggerImg.value;
             }
-            router.push(`/chat_frame?userId=${farmData.value.farmMiniUserId}&name=${farmData.value.farmMiniUserName}&farmId=${farmData.value.farmId}&pageParams=${JSON.stringify(farmData.value)}`);
+            router.push(`/chat_frame?userId=${farmData.value.farmMiniUserId}&farmId=${farmData.value.farmId}&pageParams=${JSON.stringify(farmData.value)}`);
         }else{
             ElMessage.warning('尚未绑定用户,暂时无法分享')
         }

+ 1 - 1
src/views/old_mini/user/farmDetails.vue

@@ -234,7 +234,7 @@ const handleShareFarm = () => {
 
 const handleChatFarm = () => {
     if(route.query.receiveUserId != 'null'){
-        router.push(`/chat_frame?userId=${route.query.receiveUserId}&name=${farmDetail.value.name}&farmId=${farmIdVal.value}`);
+        router.push(`/chat_frame?userId=${route.query.receiveUserId}&farmId=${farmIdVal.value}`);
     }else{
         ElMessage.warning('尚未绑定用户,暂时无法沟通');
     }

+ 2 - 2
src/views/old_mini/user/index.vue

@@ -32,7 +32,7 @@
                             variety: ele.speciesName,
                             address: ele.address,
                             mapImage: ele.mapImage || '/map.png',
-                            maxWidth: '100px',
+                            maxWidth: '90px',
                             // day: 15,
                             // farmInfo: '梢期杀虫',
                             // estimatedIncome: ele.estimatedIncome || 2585
@@ -128,7 +128,7 @@ const shareData = ref({});
 // 在线沟通
 const handleChat = (data) => {
     if(data.receiveUserId){
-        router.push(`/chat_frame?userId=${data.receiveUserId}&name=${data.name}&farmId=${data.id}`);
+        router.push(`/chat_frame?userId=${data.receiveUserId}&farmId=${data.id}`);
     }else{
         showShare.value = true;
         shareData.value = data;