chenjj 19 timmar sedan
förälder
incheckning
2a961e6c81

+ 5 - 4
components/CustomTabBar/index.vue

@@ -4,7 +4,8 @@
             <view class="handleBox" v-for="(item) in tabBarList" :key="item.key + 'tab_bar'">
                 <view class="menuBox" @click="goPages(item)">
                     <view class="menuIcon">
-                        <view class="message-style" v-if="item.key === 'chat' && messageCount > 0">{{  messageCount }}
+                        <view class="message-style" v-if="item.key === 'chat' && messageCount > 0">
+                            <!-- {{  messageCount }} -->
                         </view>
                         <image v-if="item.key != selectIndex" class="img" :src="item.iconPath"></image>
                         <image v-else class="img" :src="item.selectedIconPath"></image>
@@ -212,9 +213,9 @@ export default {
     align-items: center;
     justify-content: center;
 
-    width: 20px;
-    height: 20px;
-    border-radius: 20px;
+    width: 10px;
+    height: 10px;
+    border-radius: 10px;
 
     position: absolute;
     right: 0;

+ 3 - 3
config.js

@@ -2,9 +2,9 @@
 const config = {
 	// baseUrl: 'https://vue.ruoyi.vip/prod-api',
 	//cloud后台网关地址
-	baseUrl: 'http://192.168.100.139:9527',//嵘哥
-	// baseUrl: 'http://192.168.100.101:9527',//龙哥
-	// baseUrl: 'https://zybooks.tech/prod-api',
+	// baseUrl: 'http://192.168.100.110:9527',//嵘哥
+	// baseUrl: 'http://192.168.100.127:9527',//龙哥
+	baseUrl: 'http://goldshulin.com/prod-api',
 	mapKey:'KFEBZ-P2GKZ-A5PX4-7Q6Y7-KXOBF-XCB4C',
 	appName: '金邻助家',
 	// 应用信息

+ 62 - 21
pages_orderuser/pages/talk/pages/index/index.vue

@@ -1,5 +1,8 @@
 <template>
 	<view>
+		<view class="notice">
+			<up-notice-bar text="为了您的交易安全和售后保障,请您务必在平台内完成交易!" icon=""></up-notice-bar>
+		</view>
 		<view class="container" :style="pageHeight">
 			<view class="box-1">
 				<scroll-view scroll-y refresher-background="transparent" style="height: 100%;"
@@ -7,9 +10,11 @@
 					:refresher-triggered="scrollView.refresherTriggered" :scroll-into-view="scrollView.intoView">
 					<view class="talk-list">
 						<view v-for="(item, index) in talkList" :key="item.msgSendTime" :id="'msg-' + item.msgSendTime">
+							<view v-if="showTimeLabel(item, index)" class="time-label"> {{ showTimeLabel(item, index) }}</view>
 							<view class="item flex-col" :class="item.senderId == this.userId ? 'push' : 'pull'">
 								<!-- <image :src="item.pic" mode="aspectFill" class="pic"></image> -->
-								<img v-if="item.senderId !== this.userId" :src="orderInfo.conversationAvatar || '/static/serverImg/mine/user.png' " alt=""
+								<img v-if="item.senderId !== this.userId"
+									:src="orderInfo.conversationAvatar || '/static/serverImg/mine/user.png'" alt=""
 									class="pic" mode="aspectFill" />
 								<img src="/static/serverImg/mine/user.png" alt="" class="pic" mode="aspectFill"
 									v-else />
@@ -45,9 +50,11 @@
 
 <script>
 import { wxUploadFile, wxMakePhoneCall } from '@/utils/wxRequest.js'
-import { sendMsg, getOrderConversationInfo, getListConversationInfo, setRead,getHistoryMsg } from '@/api/conversation.js';
+import { sendMsg, getOrderConversationInfo, getListConversationInfo, setRead, getHistoryMsg } from '@/api/conversation.js';
 import { onMounted } from "vue";
-import store from "@/store"
+import dayjs from 'dayjs/esm/index'
+import store from "@/store";
+import { handleTime } from '../../request/dateTime';
 export default {
 	data() {
 		return {
@@ -73,8 +80,8 @@ export default {
 			system: '2',
 			userId: uni.getStorageSync('userId'), //读取本地存储
 			conversationRecordId: null,//会话id
-			storeUser:  store.state.user,
-			store:store,
+			storeUser: store.state.user,
+			store: store,
 		}
 	},
 	computed: {
@@ -107,7 +114,7 @@ export default {
 
 		this.getMessage();
 
-	
+
 
 	},
 	onMounted() {
@@ -122,7 +129,7 @@ export default {
 
 
 		// });
-		
+
 
 	},
 	methods: {
@@ -131,13 +138,13 @@ export default {
 			console.log("TCL: 下拉刷新 -> e", e)
 			this.scrollView.refresherTriggered = true;
 			// this.getMessage();
-			const conversationMsgRecordId = this.talkList[this.talkList.length-1].conversationMsgRecordId;
-			console.log("TCL: refresherrefresh -> conversationMsgRecordId", conversationMsgRecordId,this.talkList[this.talkList.length-1])
-			const msgSendTime =  this.talkList[this.talkList.length-1].msgSendTime
-			getHistoryMsg({conversationMsgRecordId,conversationRecordId:this.conversationRecordId}).then(res => {
+			const conversationMsgRecordId = this.talkList[this.talkList.length - 1].conversationMsgRecordId;
+			console.log("TCL: refresherrefresh -> conversationMsgRecordId", conversationMsgRecordId, this.talkList[this.talkList.length - 1])
+			const msgSendTime = this.talkList[this.talkList.length - 1].msgSendTime
+			getHistoryMsg({ conversationMsgRecordId, conversationRecordId: this.conversationRecordId }).then(res => {
 				console.log("TCL: refresherrefresh -> res", res)
-				if(res.code === 200){
-					if(res.data.length === 0) {
+				if (res.code === 200) {
+					if (res.data.length === 0) {
 						uni.showToast({
 							title: '没有更多消息了',
 							icon: 'none'
@@ -145,14 +152,14 @@ export default {
 						this.scrollView.refresherTriggered = false;
 						return
 					}
-					this.talkList = [...this.talkList,...res.data];
+					this.talkList = [...this.talkList, ...res.data];
 					this.scrollView.refresherTriggered = false;
 					this.scrollView.intoView = `msg-${msgSendTime}`;
 				}
 			})
 		},
-		listsMessage(){
-			console.log('-----listsMessage---->', this.storeUser,this.storeUser.wsManager);
+		listsMessage() {
+			console.log('-----listsMessage---->', this.storeUser, this.storeUser.wsManager);
 
 			this.storeUser.wsManager.onMessage(res => {
 				console.log('--------->', res)
@@ -173,8 +180,8 @@ export default {
 			if (!this.storeUser.wsManager) {
 				store.dispatch('GetInfo').then((res) => {
 					this.listsMessage();
-				 });
-			}else{
+				});
+			} else {
 				this.listsMessage();
 			}
 
@@ -197,7 +204,7 @@ export default {
 
 				const res = await apiFun(parmas);
 				console.log("TCL: getOrder -> res", res)
-			
+
 				if (res.code === 200) {
 					const data = res.data.vos;
 					// 获取待滚动元素选择器,解决插入数据后,滚动条定位时使用。取当前消息数据的第一条信息元素
@@ -255,7 +262,7 @@ export default {
 				msgContent: content,
 				msgSendTime: new Date().getTime(),
 				senderId: this.userId,
-				msgType: contentType =='text'?'1':'2',//消息类型 1文字消息 2图片消息
+				msgType: contentType == 'text' ? '1' : '2',//消息类型 1文字消息 2图片消息
 			}
 			const res = await sendMsg({
 				...this.orderInfo,
@@ -266,6 +273,31 @@ export default {
 			this.talkList.unshift({ ...data, code: res.code });
 			this.scrollView.intoView = `msg-${data.msgSendTime}`;
 		},
+		showTimeLabel(item, index) {
+			const { talkList } = this;
+			const isLastItem = index === talkList.length - 1;
+
+			// 最后一条消息,强制显示时间
+			if (isLastItem) {
+				return handleTime(item.msgSendTime);
+			}
+
+			const nextItem = talkList[index + 1];
+
+			// 如果没有下一条,不显示
+			if (!nextItem) {
+				return null;
+			}
+
+			const diffInMinutes = dayjs(nextItem.msgSendTime).diff(dayjs(item.msgSendTime), 'minute');
+			
+			// 如果下一条消息与当前消息间隔 >= 30 分钟,则由下一条显示时间
+			if (Math.abs(diffInMinutes) >= 30) {
+				return handleTime(item.msgSendTime);
+			}
+
+			return null;
+		}
 
 	},
 
@@ -280,8 +312,12 @@ page {
 	font-size: 28rpx;
 }
 
+.notice {
+	height: 40px;
+}
+
 .container {
-	height: calc(100vh - var(--window-top));
+	height: calc(100vh - var(--window-top) - 40px);
 	display: flex;
 	flex-direction: column;
 	flex-wrap: nowrap;
@@ -446,4 +482,9 @@ page {
 		}
 	}
 }
+
+.time-label {
+	text-align: center;
+	margin-top: 16rpx;
+}
 </style>

+ 58 - 0
pages_orderuser/pages/talk/request/dateTime.js

@@ -0,0 +1,58 @@
+import dayjs from 'dayjs';
+import relativeTime from 'dayjs/plugin/relativeTime';
+import isToday from 'dayjs/plugin/isToday';
+import isYesterday from 'dayjs/plugin/isYesterday';
+import weekday from 'dayjs/plugin/weekday';
+
+// 加载插件
+dayjs.extend(relativeTime);
+dayjs.extend(isToday);
+dayjs.extend(isYesterday);
+dayjs.extend(weekday);
+
+function handleTime(timestamp) {
+  const msgDate = dayjs(timestamp);
+  const now = dayjs();
+
+  // 获取当前时区的零点时间戳
+  const todayStart = now.startOf('day');
+  const yesterdayStart = todayStart.subtract(1, 'day');
+  const lastWeekStart = todayStart.subtract(7, 'day');
+
+  if (msgDate.isToday()) {
+    // 今天:上午/下午 + 小时分钟
+    const hour = msgDate.hour();
+    let period = '凌晨';
+    if (hour >= 6 && hour < 12) {
+      period = '上午';
+    } else if (hour >= 12 && hour < 18) {
+      period = '下午';
+    } else if (hour >= 18 || hour < 6) {
+      period = '晚上';
+    }
+    return `${period}${msgDate.format('HH:mm')}`;
+  }
+
+  if (msgDate.isYesterday()) {
+    // 昨天:昨天 + 小时分钟
+    return `昨天 ${msgDate.format('HH:mm')}`;
+  }
+
+  if (msgDate.isAfter(lastWeekStart)) {
+    // 本周内(非今天、非昨天):星期几 + 小时分钟
+    const weekDays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
+    const day = weekDays[msgDate.day()];
+    return `${day} ${msgDate.format('HH:mm')}`;
+  }
+
+  if (msgDate.year() === now.year()) {
+    // 同一年,不同周:月/日 + 小时分钟
+    return msgDate.format('MM/DD HH:mm');
+  }
+
+  // 跨年:年/月/日 + 小时分钟
+  return msgDate.format('YYYY/MM/DD HH:mm');
+}
+
+
+export { handleTime }

+ 3 - 2
utils/WebSocketManager.js

@@ -6,8 +6,9 @@ class WebSocketManager {
         this.system = uni.getStorageSync('userType') === 1 ? '1' : '2';
         this.userId = userId;
         const url = baseUrl.split('/')[2];
-		console.log("TCL: WebSocketManager -> constructor -> url", url)
-        this.url = `ws://${url}/websocket/${this.system}/${this.userId}`;
+        const header = baseUrl.split('/')[0] === 'https:' ? 'wss' : 'ws';
+		console.log("TCL: WebSocketManager -> constructor -> url",header, url)
+        this.url = `${header}://${url}/websocket/${this.system}/${this.userId}`;
 
         this.socketTask = null;
         this.heartbeatInterval = null;