From 3b0ec518a0f89b8864e4bbdf7073d3d84861b0f7 Mon Sep 17 00:00:00 2001
From: xuan <3142316616@qq.com>
Date: Tue, 17 Dec 2024 00:00:17 +0800
Subject: [PATCH 1/3] =?UTF-8?q?=E7=99=BB=E5=BD=95=E6=8E=A5=E5=8F=A3?=
=?UTF-8?q?=E5=AE=8C=E6=88=90=EF=BC=8C=E7=99=BB=E5=BD=95=E6=88=90=E5=8A=9F?=
=?UTF-8?q?=E5=90=8E=E4=BC=9A=E5=B0=86ID=E5=AD=98=E5=82=A8=E5=88=B0?=
=?UTF-8?q?=E6=9C=AC=E5=9C=B0=EF=BC=8C=E7=9B=B8=E5=85=B3=E5=87=BD=E6=95=B0?=
=?UTF-8?q?=E5=9C=A8token=E6=96=87=E4=BB=B6=E5=A4=B9=E3=80=82=E8=81=8A?=
=?UTF-8?q?=E5=A4=A9=E6=8E=A5=E5=8F=A3=E8=BF=98=E6=9C=89=E5=B0=8Fbug?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/token/auth.js | 19 +++-
src/utils/axiosConfig.js | 2 +-
src/views/chat/chat.vue | 222 +++++++++++++++++++++++++++-----------
src/views/login/login.vue | 9 +-
vue.config.js | 16 +++
5 files changed, 202 insertions(+), 66 deletions(-)
diff --git a/src/token/auth.js b/src/token/auth.js
index 56c35e6f..bfe36193 100644
--- a/src/token/auth.js
+++ b/src/token/auth.js
@@ -13,6 +13,23 @@ export function getToken() {
export function removeToken() {
localStorage.removeItem('authToken');
}
-
+
+
+// 存储、获取、删除用户登录后的个人ID
+// 定义 setUserId 函数,用于将 UserId 存储到 localStorage
+export function setUserId(id) {
+ localStorage.setItem('UserId', id);
+}
+
+// 定义 getUserId 函数,用于从 localStorage 获取 UserId
+export function getUserId() {
+ return localStorage.getItem('UserId');
+}
+
+// 定义 removeUserId 函数,用于从 localStorage 删除 UserId
+export function removeUserId() {
+ localStorage.removeItem('UserId');
+}
+
\ No newline at end of file
diff --git a/src/utils/axiosConfig.js b/src/utils/axiosConfig.js
index c0dfc6da..a6561ad7 100644
--- a/src/utils/axiosConfig.js
+++ b/src/utils/axiosConfig.js
@@ -4,7 +4,7 @@ import {getToken} from '@/token/auth' // 注意这里使用了解构赋值来导
// 创建axios实例
const service = axios.create({
- // baseURL: 'http://47.122.59.26:8080/api', // 配置基础URL 如果服务器域名发生变化统一可以去.env文件修改
+ // baseURL: 'http://47.122.59.26:8080/api',
// baseURL: 'http://10.205.10.22:8081/loveforest/api/',
timeout: 5000, // 请求超时时间
});
diff --git a/src/views/chat/chat.vue b/src/views/chat/chat.vue
index ce8e6e13..6254a114 100644
--- a/src/views/chat/chat.vue
+++ b/src/views/chat/chat.vue
@@ -17,7 +17,8 @@
{{ item.name }}
{{ getLatestNew(item) }}
- {{ item.chatHistory[item.chatHistory.length - 1].time.split(' ')[1] }}
+ {{ item.chatHistory[item.chatHistory.length - 1].time.split(' ')[1] }}
+ 00:00
@@ -84,6 +85,9 @@
import HonneyBtn from './HonneyBtn.vue';
import ChatCard from './ChatCard.vue';
import ChatList from './ChatList.vue';
+import {getToken,getUserId} from '@/token/auth'
+import axios from 'axios';
+
export default {
name: 'chatIndex', // 添加组件名称
data(){
@@ -92,6 +96,7 @@ export default {
new_msg_nums: 1,
chatWith:'',
userInfo:{
+ id: Number(),
name:'我',
icon:'/icon/abc.jpg'
},
@@ -101,62 +106,62 @@ export default {
// 由于编译后文件夹名称会发生改变,所以把icon图片单独放到服务器的文件夹下面以此来跳过编译(public文件夹)
// 这里文件路径命名是相对于public的绝对路径
friendsInfoList: [
- {name:'潇潇',icon:'/icon/icon.png',position:'london',birth:'2004-1-1',concern_status:false,black_status:true,beeing_friends_time: 302,
- chatHistory:[
- {name:'我',content:'早重中之重做做做做做做做做做做做做做做做做做做做战争之子战争之子做做做做',time:'2024-11-24 1:24'},
- {name:'潇潇',content:'中',time:'2024-11-24 2:11'},
- {name:'我',content:'晚',time:'2024-11-24 3:24'},
- ]},
- {name:'小刚','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 2,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'小刚',content:'hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh',time:'2024-11-25 22:11'},
- ]},
- {name:'吴伟',icon:'/icon/icon.png',position:'endland',birth:'2004-5-2',concern_status:false,black_status:false,beeing_friends_time: 32,
- chatHistory:[
- {name:'我',content:'早上好',time:'2024-11-24 22:25'},
- {name:'吴伟',content:'iii',time:'2024-11-24 23:11'},
- ]},
- {name:'小闽','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'小闽',content:'h',time:'2024-11-25 22:11'},
- ]},
- {name:'小','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'小',content:'h',time:'2024-11-25 22:11'},
- ]},
- {name:'闽','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'闽',content:'h',time:'2024-11-25 22:11'},
- ]},
- {name:'哈哈','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'哈哈',content:'h',time:'2024-11-25 22:11'},
- ]},
- {name:'kk','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'kk',content:'h',time:'2024-11-25 22:11'},
- ]},
- {name:'44','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'44',content:'h',time:'2024-11-25 22:11'},
- ]},
- {name:'77','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'77',content:'h',time:'2024-11-25 22:11'},
- ]},
- {name:'88','icon':'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
- chatHistory:[
- {name:'我',content:'you are',time:'2024-11-24 22:24'},
- {name:'88',content:'h',time:'2024-11-25 22:11'},
- ]},
+ // {name:'潇潇',icon:'/icon/icon.png',position:'london',birth:'2004-1-1',concern_status:false,black_status:true,beeing_friends_time: 302,
+ // chatHistory:[
+ // {name:'我',content:'早重中之重做做做做做做做做做做做做做做做做做做做战争之子战争之子做做做做',time:'2024-11-24 1:24'},
+ // {name:'潇潇',content:'中',time:'2024-11-24 2:11'},
+ // {name:'我',content:'晚',time:'2024-11-24 3:24'},
+ // ]},
+ // {name:'小刚',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 2,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'小刚',content:'hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'吴伟',icon:'/icon/icon.png',position:'endland',birth:'2004-5-2',concern_status:false,black_status:false,beeing_friends_time: 32,
+ // chatHistory:[
+ // {name:'我',content:'早上好',time:'2024-11-24 22:25'},
+ // {name:'吴伟',content:'iii',time:'2024-11-24 23:11'},
+ // ]},
+ // {name:'小闽',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'小闽',content:'h',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'小',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'小',content:'h',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'闽',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'闽',content:'h',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'哈哈',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'哈哈',content:'h',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'kk',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'kk',content:'h',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'44',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'44',content:'h',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'77',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'77',content:'h',time:'2024-11-25 22:11'},
+ // ]},
+ // {name:'88',icon:'/icon/UserIcon.png',position:'china',birth:'2003-3-4',concern_status:false,black_status:false,beeing_friends_time: 1,
+ // chatHistory:[
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ // {name:'88',content:'h',time:'2024-11-25 22:11'},
+ // ]},
],
showSearchList: [],
recomendList: [
@@ -169,6 +174,8 @@ export default {
mounted(){
if(this.searchName == '')
this.showSearchList = this.friendsInfoList
+
+ this.get_friendsInfoList()
},
components:{
HonneyBtn,
@@ -177,6 +184,94 @@ export default {
ChatList
},
methods:{
+ async save_chat_message(senderId,receiverId,content){
+ try{
+ const response = await axios.post('/messages/send',{
+ senderId: senderId,
+ receiverId: receiverId,
+ content: content
+ },{
+ headers:{Authorization : 'Bearer '+getToken()}
+ })
+ console.log(response.data)
+ }catch(error){
+ alert('消息保存失败',error)
+ }
+ },
+ async get_friendsInfoList(){
+ try{
+ // const tempt_chat = {name:'',content:'',time:''}
+ const UserId = getUserId()
+ const token = 'Bearer '+getToken()
+ console.log(UserId,token)
+ const response1 =await axios.get(`/relationships/${UserId}`,{
+ headers:{Authorization : token}
+ })
+ const data = response1.data
+ console.log(data)
+
+ for(let i = 0;i< data.length;i++)
+ {
+ let tempt_data = {id:Number(),name:'',icon:'/icon/UserIcon.png',position:'DEFAULT',birth:'',concern_status:false,black_status:false,beeing_friends_time: 0,
+ chatHistory:[]}
+
+ // {name:'我',content:'you are',time:'2024-11-24 22:24'},
+ let response2
+ if(data[i].userId1 == UserId){
+ tempt_data.id = data[i].userId2
+ response2 = await axios.get(`/messages/chat?userId1=${UserId}&userId2=${data[i].userId2}`,{
+ headers:{Authorization : token}
+ })
+ }else if(data[i].userId2 == UserId){
+ tempt_data.id = data[i].userId1
+ response2 = await axios.get(`/messages/chat?userId1=${UserId}&userId2=${data[i].userId1}`,{
+ headers:{Authorization : token}
+ })
+ }
+
+ let chat_history = response2.data
+ console.log(chat_history)
+
+ if(chat_history.length != 0){
+ for(let j = 0;j < chat_history.length ; j++){
+ let tempt_chat = {name:'',content:'',time:''}
+
+ if(chat_history[j].senderId == UserId){
+ tempt_chat.name = data[i].myNickname
+ }else{
+ tempt_chat.name = data[i].otherUserNickname
+ }
+
+ tempt_chat.content = chat_history[j].content
+ tempt_chat.time = chat_history[j].timestamp.replace('T',' ')
+ // console.log(tempt_chat)
+ tempt_data.chatHistory.push(tempt_chat)
+ }
+ }
+
+ tempt_data.name = data[i].otherUserNickname
+ tempt_data.birth = data[i].otherUserBirthday
+ tempt_data.beeing_friends_time = data[i].daysSinceCreated
+ if(data[i].status == 'friend'){
+ tempt_data.concern_status = true
+ tempt_data.black_status = false
+ }else if(data[i].status == 'black'){
+ tempt_data.concern_status = false
+ tempt_data.black_status = true
+ }else if(data[i].status == 'normal'){
+ tempt_data.concern_status = false
+ tempt_data.black_status = false
+ }
+ this.friendsInfoList.push(tempt_data)
+ this.userInfo.name = data[i].myNickname
+ }
+
+ this.userInfo.id = UserId
+ console.log(this.friendsInfoList,this.userInfo)
+ }catch(error){
+ alert('获取好友信息失败',error)
+ }
+ },
clickFriendList(item){
let who = item.name
if(this.chatWith != who){
@@ -190,13 +285,15 @@ export default {
const dayjs = require('dayjs')
const formattedTime = dayjs().format('YYYY-MM-DD HH:mm');
console.log(formattedTime)
- for(let i=0;i 14){
- latest_new= latest_new.slice(0,13) + '...'
+ let latest_new = ''
+ if(object.chatHistory.length != 0){
+ latest_new = object.chatHistory[object.chatHistory.length - 1].content
+ if(latest_new.length > 14){
+ latest_new= latest_new.slice(0,13) + '...'
+ }
}
return latest_new
},
diff --git a/src/views/login/login.vue b/src/views/login/login.vue
index 64b5cdd1..d4d75316 100644
--- a/src/views/login/login.vue
+++ b/src/views/login/login.vue
@@ -177,7 +177,7 @@
// eslint-disable-next-line no-unused-vars
import {Axios as request} from "axios";
import axios from '@/utils/axiosConfig';
-import {setToken} from '@/token/auth'
+import {setToken,getToken,setUserId,getUserId} from '@/token/auth'
export default {
name:'loginIndex',
data(){
@@ -235,10 +235,13 @@ export default {
console.log('登录成功', response)
// 假设token在响应的data字段中
// !!存疑!!
- const token = response.token;
+ const token = response.jwt;
+ const userId = response.userId
+ // console.log(token)
// 存储token
setToken(token);
- // console.log( 'token是:' + getToken() )
+ setUserId(userId)
+ console.log( 'token是:' + getToken() + '\n' + '拿到的userId是:' + getUserId() )
// 登录成功后的操作,比如跳转到主页
this.$router.push('/main');
} catch (error) {
diff --git a/vue.config.js b/vue.config.js
index 2dc5ff8b..7c5a56ff 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -5,10 +5,26 @@ module.exports = defineConfig({
port: 8080,
https: false,
proxy:{
+ //登录接口
'/auth/login':{
target : 'https://911fb0525ms3.vicp.fun/loveforest/api',
changeOrigin : true,
},
+ //获取好友列表接口
+ '/relationships':{
+ target : 'https://911fb0525ms3.vicp.fun/loveforest/api',
+ changeOrigin : true
+ },
+ //获取相应的聊天记录的接口
+ '/messages/chat':{
+ target : 'https://911fb0525ms3.vicp.fun/loveforest/api',
+ changeOrigin : true
+ },
+ //保存聊天的一条消息接口
+ '/messages/send':{
+ target : 'https://911fb0525ms3.vicp.fun/loveforest/api',
+ changeOrigin : true
+ }
}
},
transpileDependencies: true
From 4d650512b00be80eb907b4930708e47bdba1789a Mon Sep 17 00:00:00 2001
From: xuan <3142316616@qq.com>
Date: Tue, 17 Dec 2024 19:43:48 +0800
Subject: [PATCH 2/3] =?UTF-8?q?=E8=81=8A=E5=A4=A9=E6=8E=A5=E5=8F=A3OK?=
=?UTF-8?q?=EF=BC=8C=E4=BD=86=E6=98=AF=E8=BF=98=E4=B8=8D=E8=83=BD=E5=AE=9E?=
=?UTF-8?q?=E6=97=B6=E9=80=9A=E4=BF=A1=E3=80=82=E6=BB=9A=E5=8A=A8=E6=9D=A1?=
=?UTF-8?q?=E8=87=AA=E5=8A=A8=E5=88=92=E5=88=B0=E6=9C=80=E5=BA=95=E9=83=A8?=
=?UTF-8?q?=E5=8F=AF=E8=83=BD=E6=BB=91=E4=B8=8D=E6=9C=80=E5=BA=95=E9=83=A8?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/views/chat/ChatList.vue | 26 +++++----
src/views/chat/HonneyBtn.vue | 1 +
src/views/chat/chat.vue | 105 ++++++++++++++++++++++++++++-------
vue.config.js | 5 ++
4 files changed, 107 insertions(+), 30 deletions(-)
diff --git a/src/views/chat/ChatList.vue b/src/views/chat/ChatList.vue
index bd6a11ac..90c3607d 100644
--- a/src/views/chat/ChatList.vue
+++ b/src/views/chat/ChatList.vue
@@ -1,9 +1,10 @@
@@ -37,7 +38,10 @@ export default{
return this.items.slice(this.start,this.end)
},
barHeight(){
- return this.one_height * (this.items.length-this.start-this.shownum+1) + 'px'
+ if((this.items.length-this.start-this.shownum+1) <= 0)
+ return 0 + 'px'
+ else
+ return this.one_height * (this.items.length-this.start-this.shownum+1) + 'px'
},
listTop(){
// console.log(this.items,this.shownum,this.one_height)
@@ -49,24 +53,24 @@ export default{
const top = e.target.scrollTop
this.start = Math.floor(top / this.one_height)
this.end = this.start + this.shownum
+
+ // e.target.scrollTop = e.target.scrollHeight
+ // this.end = this.items.length
+ // this.start = this.end - this.shownum
},
chatWithHandle(){
- console.log(1)
if(this.status == true){
+ let scrollElem = this.$refs.scrollDiv
+ scrollElem.scrollTop = scrollElem.scrollHeight
+ console.log(scrollElem.scrollHeight,scrollElem.scrollTop)
this.end = this.items.length
- // console.log(this.end)
this.start = this.end - this.shownum
- if(this.start < 0 ){
+ if(this.start<0)
this.start = 0
- }else{
- let scrollElem = this.$refs.scrollDiv
- scrollElem.scrollTo({top: scrollElem
- ,behavior: 'smooth'})
- console.log(1)
- }
}
}
},
+ expose: ['chatWithHandle'],
watch:{
status(){
console.log(1)
diff --git a/src/views/chat/HonneyBtn.vue b/src/views/chat/HonneyBtn.vue
index 3a2f8343..00e86e54 100644
--- a/src/views/chat/HonneyBtn.vue
+++ b/src/views/chat/HonneyBtn.vue
@@ -21,6 +21,7 @@ export default{
props:{
Status:Boolean,
cnt:String,
+ userId1: Number,
ReviseStatus2Father: Function
// Status2:String
},
diff --git a/src/views/chat/chat.vue b/src/views/chat/chat.vue
index 6254a114..8e8e8fae 100644
--- a/src/views/chat/chat.vue
+++ b/src/views/chat/chat.vue
@@ -19,13 +19,14 @@
{{ item.chatHistory[item.chatHistory.length - 1].time.split(' ')[1] }}
00:00
+
-
+
@@ -51,7 +52,7 @@
他的主页
@@ -87,13 +88,12 @@ import ChatCard from './ChatCard.vue';
import ChatList from './ChatList.vue';
import {getToken,getUserId} from '@/token/auth'
import axios from 'axios';
-
export default {
name: 'chatIndex', // 添加组件名称
data(){
return{
searchName: '',
- new_msg_nums: 1,
+ new_msg_nums: 0,
chatWith:'',
userInfo:{
id: Number(),
@@ -184,7 +184,34 @@ export default {
ChatList
},
methods:{
+ async revise_honneyBtn_status(userId1,userId2,status){
+ //向后端发送是出于好友状态还是黑名单状态
+ try{
+ const response = await axios.post('/relationships',{
+ userId1: userId1,
+ userId2: userId2,
+ status: status
+ },{
+ headers:{Authorization : 'Bearer '+getToken()}
+ })
+ console.log(response.data)
+ }catch(error){
+ alert('好友状态修改失败',error)
+ }
+ },
+ async revise_reading(senderId,receiverId){
+ //向后端传输信息标记是否已读(一个axios
+ try{
+ const response = await axios.post(`/messages/mark-as-read/${senderId}/${receiverId}`,{},{
+ headers:{Authorization : 'Bearer '+getToken()}
+ })
+ console.log(response.data)
+ }catch(error){
+ alert('消息已读失败',error)
+ }
+ },
async save_chat_message(senderId,receiverId,content){
+ //向后端发送消息(一个axios
try{
const response = await axios.post('/messages/send',{
senderId: senderId,
@@ -199,6 +226,7 @@ export default {
}
},
async get_friendsInfoList(){
+ //向后端获取好友列表和聊天记录(两个axios
try{
// const tempt_chat = {name:'',content:'',time:''}
const UserId = getUserId()
@@ -212,19 +240,19 @@ export default {
for(let i = 0;i< data.length;i++)
{
- let tempt_data = {id:Number(),name:'',icon:'/icon/UserIcon.png',position:'DEFAULT',birth:'',concern_status:false,black_status:false,beeing_friends_time: 0,
+ let tempt_data = {id:Number(),name:'',icon:'/icon/UserIcon.png',position:'DEFAULT',birth:'',concern_status:false,black_status:false,beeing_friends_time: 0,unreading_num: 0,
chatHistory:[]}
// {name:'我',content:'you are',time:'2024-11-24 22:24'},
let response2
if(data[i].userId1 == UserId){
tempt_data.id = data[i].userId2
- response2 = await axios.get(`/messages/chat?userId1=${UserId}&userId2=${data[i].userId2}`,{
+ response2 = await axios.get(`/messages/chat/${UserId}/${data[i].userId2}`,{
headers:{Authorization : token}
})
}else if(data[i].userId2 == UserId){
tempt_data.id = data[i].userId1
- response2 = await axios.get(`/messages/chat?userId1=${UserId}&userId2=${data[i].userId1}`,{
+ response2 = await axios.get(`/messages/chat/${UserId}/${data[i].userId1}`,{
headers:{Authorization : token}
})
}
@@ -246,11 +274,16 @@ export default {
tempt_chat.time = chat_history[j].timestamp.replace('T',' ')
// console.log(tempt_chat)
tempt_data.chatHistory.push(tempt_chat)
+
+ if(chat_history[j].read == false && chat_history[j].receiverId == UserId){
+ tempt_data.unreading_num += 1
+ }
}
}
tempt_data.name = data[i].otherUserNickname
tempt_data.birth = data[i].otherUserBirthday
+ tempt_data.position = data[i].otherUserAddress
tempt_data.beeing_friends_time = data[i].daysSinceCreated
if(data[i].status == 'friend'){
tempt_data.concern_status = true
@@ -263,6 +296,7 @@ export default {
tempt_data.black_status = false
}
this.friendsInfoList.push(tempt_data)
+ this.new_msg_nums += tempt_data.unreading_num
this.userInfo.name = data[i].myNickname
}
@@ -273,34 +307,67 @@ export default {
}
},
clickFriendList(item){
+ //更新chatWith
let who = item.name
if(this.chatWith != who){
this.sendingMsg = ''
}
this.chatWith = item.name
// console.log(this.chatWith)
-
+ //更新是否已读
+ this.revise_reading(this.userInfo.id,item.id)
+ this.new_msg_nums -= item.unreading_num
+ item.unreading_num = 0
+ //将列表下拉到最下面
+ this.$nextTick(() =>{
+ console.log(this.$refs.chatHandle)
+ this.$refs.chatHandle.chatWithHandle()
+ })
+ },
+ cliTreeBtn(){
+ this.$router.push('/main/familyTree')
},
sendMsg(){
- const dayjs = require('dayjs')
- const formattedTime = dayjs().format('YYYY-MM-DD HH:mm');
- console.log(formattedTime)
- let i = 0
- for(i=0;i{
+ console.log(this.$refs.chatHandle)
+ this.$refs.chatHandle.chatWithHandle()
+ })
}
- this.save_chat_message(this.userInfo.id,this.friendsInfoList[i].id,this.sendingMsg)
- this.sendingMsg = ''
},
concernStatusRevise(data){
this.getFriendObject.concern_status = data
+ // console.log(this.userInfo.id,this.getFriendObject.id)
+ if(data == true){
+ this.revise_honneyBtn_status(this.userInfo.id,this.getFriendObject.id,'friend')
+ this.getFriendObject.black_status = false
+ }else if(this.getFriendObject.black_status == false && this.getFriendObject.concern_status == false){
+ this.revise_honneyBtn_status(this.userInfo.id,this.getFriendObject.id,'normal')
+ }
+
},
blackStatusRevise(data){
this.getFriendObject.black_status = data
+ if(data == true){
+ this.revise_honneyBtn_status(this.userInfo.id,this.getFriendObject.id,'black')
+ this.getFriendObject.concern_status = false
+ }else if(this.getFriendObject.black_status == false && this.getFriendObject.concern_status == false){
+ this.revise_honneyBtn_status(this.userInfo.id,this.getFriendObject.id,'normal')
+ }
+
},
historyContentHandle(content){
let char_sizeof = 0
diff --git a/vue.config.js b/vue.config.js
index 7c5a56ff..ca3e7031 100644
--- a/vue.config.js
+++ b/vue.config.js
@@ -24,6 +24,11 @@ module.exports = defineConfig({
'/messages/send':{
target : 'https://911fb0525ms3.vicp.fun/loveforest/api',
changeOrigin : true
+ },
+ //新消息是否被已读的接口
+ '/messages/mark-as-read':{
+ target : 'https://911fb0525ms3.vicp.fun/loveforest/api',
+ changeOrigin : true
}
}
},
From 415a44db30a62f6c282bcb3fb30a6d571def8419 Mon Sep 17 00:00:00 2001
From: QMZ <1164250597@qq.com>
Date: Tue, 17 Dec 2024 20:49:06 +0800
Subject: [PATCH 3/3] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E5=AE=8C=E5=96=84?=
=?UTF-8?q?=E5=B8=96=E5=AD=90=E4=BB=A5=E5=8F=8A=E8=AF=84=E8=AE=BA=E5=88=A0?=
=?UTF-8?q?=E9=99=A4=E5=8A=9F=E8=83=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
src/assets/css/community/community.css | 26 +---
src/utils/axiosConfig.js | 1 +
src/views/community/PostCard.vue | 192 ++++++++++++++++++++++---
src/views/community/Postform.vue | 6 +-
src/views/community/trends.vue | 79 +++++-----
5 files changed, 223 insertions(+), 81 deletions(-)
diff --git a/src/assets/css/community/community.css b/src/assets/css/community/community.css
index 9cb0a82d..96cd3f10 100644
--- a/src/assets/css/community/community.css
+++ b/src/assets/css/community/community.css
@@ -1,35 +1,17 @@
-/* 设置进入和离开的过渡效果 */
+/* 离开动画 */
.post-list .fade-leave-active {
transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
}
-.post-list .fade-enter-active {
- transition: opacity 0.5s ease-in-out, transform 0.5s ease-in-out;
-}
-
-/* 元素进入时,缩放并渐变 */
-.post-list .fade-leave-to /* .fade-leave-active in Vue 2.x */ {
- opacity: 0;
- transform: scale(0.5); /* 初始状态为缩小 */
-}
-.post-list .fade-enter{
+.post-list .fade-leave-to /* 离开完成后状态 */
+{
opacity: 0;
- transform: scale(0.5); /* 初始状态为缩小 */
+ transform: translateX(100%) scale(0.5); /* 离开时从右边滑出并缩小 */
}
-/* 元素进入时恢复到原尺寸 */
-.post-list .fade-enter-to {
- opacity: 1;
- transform: scale(1); /* 变大恢复正常尺寸 */
-}
-/* 元素离开时,继续保持缩小状态 */
-.post-list .fade-leave-to {
- opacity: 0;
- transform: scale(0.5); /* 离开时缩小 */
-}
diff --git a/src/utils/axiosConfig.js b/src/utils/axiosConfig.js
index c0dfc6da..ed4c0d2b 100644
--- a/src/utils/axiosConfig.js
+++ b/src/utils/axiosConfig.js
@@ -6,6 +6,7 @@ import {getToken} from '@/token/auth' // 注意这里使用了解构赋值来导
const service = axios.create({
// baseURL: 'http://47.122.59.26:8080/api', // 配置基础URL 如果服务器域名发生变化统一可以去.env文件修改
// baseURL: 'http://10.205.10.22:8081/loveforest/api/',
+ // baseURL: 'http://10.133.13.52:8082/loveforest',
timeout: 5000, // 请求超时时间
});
diff --git a/src/views/community/PostCard.vue b/src/views/community/PostCard.vue
index f9fecb2d..28fd35b1 100644
--- a/src/views/community/PostCard.vue
+++ b/src/views/community/PostCard.vue
@@ -1,4 +1,5 @@
+
+
+
+
{{ timestamp }}
+
+
+
+
+
+
+
+
+
+
+
+
+
家族故事
@@ -51,7 +72,8 @@
{{ comment.userid}}: {{ comment.content }}
+{{ comment.userid}}: {{ comment.content }}