fix: 聊天(已实现图文消息对话)

This commit is contained in:
2025-07-25 15:59:33 +08:00
parent 866d9ae083
commit 53c29e93a6
12 changed files with 539 additions and 306 deletions

88
request/api/http.js Normal file
View File

@@ -0,0 +1,88 @@
import http from './request'
const HttpUrlMap = [
'/oldApi',
'/newApi',
'/imApi',
'/xkApi',
]
/**
* GET请求Json
* @param url
* @param params
* @param type
* @returns {Promise<*>}
*/
export async function get(url, params, type = 0) {
return await http(HttpUrlMap[type] + url, {
method: 'GET',
data: params,
// 传输方式是json
headers: {
'Content-Type': 'application/json'
}
}, 1)
}
/**
* POST请求Json
* @param url
* @param params
* @param type
* @returns {Promise<*>}
*/
export async function post(url, params, type = 0) {
return await http(HttpUrlMap[type] + url, {
method: 'POST',
data: params,
// 传输方式是json
headers: {
'Content-Type': 'application/json'
}
}, 1)
}
/**
* 文件上传方法(仅支持 FormData 格式)
* @param {string} url - 接口路径
* @param {any} formData - 包含文件的 FormData 对象
* @param {int} [type=0] - 请求类型(用于映射 HttpUrlMap
* @returns {Promise<*>}
*/
export function uploadFile(url, formData, type = 3) {
const fullUrl = 'http://127.0.0.1:18001/api/mobile' + url;
console.log(fullUrl, 'sssssssssssss')
uni.uploadFile({
url: 'http://127.0.0.1:18001/api/mobile/chat-friends/upload-chat-file',
filePath: formData,
name: 'file',
header: {
"authorization": uni.getStorageSync('token')
},
formData,
success: (uploadFileRes) => {
return uploadFileRes;
},
fail: (res) => {
console.log(res, '上传失败')
}
})
// return;
// try {
// const response = await http(fullUrl, {
// method: 'POST',
// data: formData,
// // 注意:不手动设置 Content-Type浏览器会自动添加 multipart/form-data 和 boundary
// headers: {
// // 如果需要额外 headers如 token可在此添加
// // 'Authorization': 'Bearer xxx',
// },
// }, 1);
//
// return response;
// } catch (error) {
// console.error('File upload failed:', error);
// throw error; // 抛出错误供调用者处理
// }
}

View File

@@ -1,4 +1,5 @@
import http from './request'
import {get, post, uploadFile} from './http'
// 发信息
// export async function sendMsg(params) {
// let data = await http('/v1/im/message-send', params)
@@ -14,4 +15,32 @@ export async function sendToUserApi(params) {
'Content-Type': 'application/json'
}
}, 1)
}
/**
* 获取房间聊天记录
* @param params
* @returns {Promise<*>}
*/
export async function getMessagesByRoomIdApi(params) {
return await post('/chat-friends/messages-by-room-id', params, 3)
}
/**
* 获取聊天好友列表
* @param params
* @returns {Promise<*>}
*/
export async function getChatFriendsListApi(params) {
return await get('/chat-friends/list', params, 3)
}
/**
* 上传聊天文件
* @param params
* @returns {Promise<*>}
*/
export function upLoadChatFileApi(params) {
return console.log('aaaaaaaaaaaaaaaaaaa', uploadFile('/chat-friends/upload-chat-file', params))
return uploadFile('/chat-friends/upload-chat-file', params)
}

View File

@@ -29,7 +29,7 @@ function request(url, params, method = 0) {
}
if (url.split('/').indexOf('xkApi') !== -1) {
// baseURL = "https://api.xiaokang88.com/member"
baseURL = "https://127.0.0.1:18001/member"
baseURL = "http://127.0.0.1:18001/api/mobile"
}
url = url.replace('/oldApi', '');
url = url.replace('/newApi', '');