diff --git a/jiuyi2/api/news.js b/jiuyi2/api/news.js index a5f24aa7..aa47cc72 100644 --- a/jiuyi2/api/news.js +++ b/jiuyi2/api/news.js @@ -130,6 +130,7 @@ export const news = { method: 'POST', data: param.data, query: param.query, + load: true, }) }, @@ -139,7 +140,7 @@ export const news = { url: `/user/getRedPacketInfo`, method: 'GET', query: param.query, - load: 1, + load: true, }) }, @@ -150,6 +151,7 @@ export const news = { method: 'POST', data: param.data, query: param.query, + load: true, }) }, @@ -219,7 +221,7 @@ export const news = { }) }, - + // 客服发消息 sendCusomterService(param) { return util.request({ diff --git a/jiuyi2/common/js/config.js b/jiuyi2/common/js/config.js index 407ed9f4..36cfa819 100644 --- a/jiuyi2/common/js/config.js +++ b/jiuyi2/common/js/config.js @@ -7,7 +7,6 @@ const config = { // #endif // #ifndef H5 host: 'http://91f.xyz:8080', - // host: 'http://762c9b48.r24.cpolar.top', // #endif // 是否vivo显示 showVivo: true, diff --git a/jiuyi2/common/js/util.js b/jiuyi2/common/js/util.js index 0397dd18..8aaf8051 100644 --- a/jiuyi2/common/js/util.js +++ b/jiuyi2/common/js/util.js @@ -134,7 +134,7 @@ const util = { reject(res) }, complete(rs) { - console.log('upload complete', rs) + // console.log('upload complete', rs) } }) }) @@ -213,7 +213,7 @@ const util = { responseType: params.responseType || 'text', // 请求成功返回 success: res => { - // console.log('request success', url, res, params.data ? params.data : '') + console.log('request success', url, res, params.data ? params.data : '') // 关闭加载效果 if (params.load) { uni.hideLoading() @@ -602,6 +602,7 @@ const util = { count: obj.type == 1 ? 1 : count - obj.value.length, sourceType: obj.sourceType || ['album', 'camera'], success: (rs) => { + console.log('rs', rs) // 遍历图片返回列表 rs.tempFiles.forEach(item => { // 限制大小 @@ -615,6 +616,7 @@ const util = { file: item.path, mode: 'img', success(res) { + console.log('upload res', res) if (res.code === 200) { uni.getImageInfo({ src: item.path, @@ -625,6 +627,7 @@ const util = { width: imageInfo.width, height: imageInfo .height, + size: item.size, }); }, }) diff --git a/jiuyi2/components/news/msgList.vue b/jiuyi2/components/news/msgList.vue index afda702e..c264247c 100644 --- a/jiuyi2/components/news/msgList.vue +++ b/jiuyi2/components/news/msgList.vue @@ -114,8 +114,11 @@ res.forEach(item => { let obj = {} obj.type = item.type; - obj.chatText = item.lastMessage.messageForShow; + // 处理最近一条消息 + obj.chatText = item.lastMessage.messageForShow + if (obj.chatText == "[自定义消息]") obj.chatText = item.lastMessage.payload.description || '[自定义消息]' obj.MsgTime = handleDate(item.lastMessage.lastTime); + // obj.unreadCount = item.unreadCount; if (item.type == 'C2C') { diff --git a/jiuyi2/pages/news/chat/chat.vue b/jiuyi2/pages/news/chat/chat.vue index 8040fe60..2222ee76 100644 --- a/jiuyi2/pages/news/chat/chat.vue +++ b/jiuyi2/pages/news/chat/chat.vue @@ -149,24 +149,28 @@ uni.offKeyboardHeightChange(() => {}) // #endif videoContext.value.stop() + // 移除监听消息 + removeListener() }) // 开启监听消息 function addListener() { let onMessageReceived = function(event) { console.log('TencentCloudChat.EVENT.MESSAGE_RECEIVED', event) - setTimeout(() => { - // 获取历史记录 - getHistory({ - msgId: '', - limit: 1, - }) - }, 200) + // + list.messageList.push(...event.data) } uni.$chat.on(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived); } + // 移除监听消息 + function removeListener() { + let onMessageReceived = function(event) {} + + uni.$chat.off(TencentCloudChat.EVENT.MESSAGE_RECEIVED, onMessageReceived); + } + // 监听内容滚动 function onContentScroll(ev) { if (ev.scrollTop == 50) getMoreHistroy() @@ -177,18 +181,26 @@ // 点击发送 function handleSend() { + // + if (!content.value) { + util.alert('消息不能为空') + return + } + // 取消聚焦 inputFocus.value = false + // 创建文本消息 + let message = uni.$chat.createTextMessage({ + to: msg.id, + conversationType: msg.type, + payload: { + text: content.value + }, + }) + // 发送消息 sendMsg({ - query: { - formId: userinfo.value.id, - toUserId: msg.id, - msgType: TencentCloudChat.TYPES.MSG_TEXT, - }, - data: { - text: content.value - }, + message, success: () => { // 清空已发送的消息 content.value = '' @@ -202,7 +214,9 @@ * @param {Object} message 消息对象 */ function handlePlusSend(message) { - sendMsg(message) + sendMsg({ + message + }) } /** @@ -210,22 +224,13 @@ * @param {Object} param */ function sendMsg(param) { - // - let request = api.news.sendUserMsg - // - if (msg.type == 'GROUP') request = api.news.sendGroupMsg - // if (msg.isCustomer) request = api.news.sendCusomterService - + console.log('sendMsg', param.message) // 发送消息 - request({ - query: param.query, - data: param.data, - }).then((rs) => { - if (rs.code == 200) { - // getHistory({ - // msgId: '', - // limit: 1, - // }) + uni.$chat.sendMessage(param.message).then((rs) => { + console.log('send success', rs) + if (rs.code == 0) { + // + list.messageList.push(rs.data.message) param.success ? param.success() : '' return } @@ -240,14 +245,14 @@ /** * 打开红包详情 - * @param {Object} ev + * @param {Object} event 默认事件 */ - function handleRedPacket(ev) { - messageItem.value = ev + function handleRedPacket(event) { + console.log('event', event) api.news.getRedPacketInfo({ query: { // 红包id - redPacketId: ev.callbackData.callback_json[0].businessId + redPacketId: event.formatData.id, } }).then(rs => { if (rs.code == 200) { @@ -310,10 +315,9 @@ // 获取更多消息记录 function getMoreHistroy() { - // 获取第一条消息记录 - if (list.total <= list.data.length) return + // if(list.isCompleted) return getHistory({ - msgId: list.data[0].id + msgId: list.messageList[0].ID }) } @@ -558,15 +562,15 @@ + - diff --git a/jiuyi2/pages/news/chat/components/news-temp/index.vue b/jiuyi2/pages/news/chat/components/news-temp/index.vue index 7b72d1f7..0916a2b7 100644 --- a/jiuyi2/pages/news/chat/components/news-temp/index.vue +++ b/jiuyi2/pages/news/chat/components/news-temp/index.vue @@ -11,6 +11,9 @@ computed, defineEmits, } from 'vue' + // 工具库 + import util from '@/common/js/util'; + import NewsAudio from '@/static/audio.png' import JyCommodityInformation from '@/components/public/jy-commodity-information' const props = defineProps({ @@ -30,7 +33,11 @@ const store = useStore() const emit = defineEmits(['openRedBag', 'viewVideo']) // 格式化 - const formatData = computed(() => props.item) + const formatData = computed(() => { + let result = props.item.payload.data || '' + if (result) result = JSON.parse(result) + return result + }) //音频 const innerAudioContext = uni.createInnerAudioContext(); // 播放语音 @@ -41,10 +48,7 @@ }) } // 用户信息 - const userinfo = computed(() => { - let result = store.state.userinfo - return result - }) + const userinfo = computed(() => store.state.userinfo) // 拨打电话 function handleCall() { @@ -58,20 +62,34 @@ // 开红包 function handleOpenRedBag() { - emit('openRedBag', props.item) + emit('openRedBag', { + item: props.item, + formatData: formatData.value, + }) } // 看视频 function handleViewVideo(item) { emit('viewVideo', item) } + + /** + * 看图片 + * @param {Object} urls 图片路径数组 + */ + function handleViewImage(urls) { + uni.previewImage({ + urls, + }) + } \ No newline at end of file diff --git a/jiuyi2/vite.config.js b/jiuyi2/vite.config.js index 00b70465..fc5535df 100644 --- a/jiuyi2/vite.config.js +++ b/jiuyi2/vite.config.js @@ -4,7 +4,6 @@ import { import uni from '@dcloudio/vite-plugin-uni'; let target = 'http://91f.xyz:8080' -// let target = 'http://762c9b48.r24.cpolar.top' export default defineConfig({ plugins: [uni()],