客服模块优化

This commit is contained in:
赵毅 2025-09-25 11:42:52 +08:00
parent dbae8b4a5a
commit c5d4eba244
5 changed files with 65 additions and 55 deletions

View File

@ -40,11 +40,10 @@ export default {
isLoading: false,
page_num: 1,
page_size: 10,
itemObj: {},
};
},
onLoad() {
// 加载聊天记录列表
this.loadChattingRecords();
},
onShow() {
// 页面显示时重新加载聊天记录
@ -62,7 +61,7 @@ export default {
page_num: this.page_num,
page_size: this.page_size,
}).then((res) => {
this.recordsList = res.msg_list
this.recordsList = res.msg_list.filter(item => item.client_id_one !== item.client_id_two)
})
} catch (error) {
console.error('加载聊天记录失败', error);
@ -104,29 +103,24 @@ export default {
// 跳转到聊天页面
goToChatPage(record) {
const params = {
mch_id: record.mch_id,
console.log("🚀 ~ goToChatPage ~ record:", record)
if (record.client_id_two == uni.getStorageSync('openId')) {
this.itemObj = {
...record.one,
bind_id: record.id
}
request(apiArr.csGetMchContactList, "POST", params).then((res) => {
if (res.rows && res.rows.length > 0) {
res.rows.map(item => {
item.employee_image = picUrl + item.employee_image;
})
const itemObj = res.rows.find(item => item.employee_mobile === record.two.account)
} else {
this.itemObj = {
...record.one,
bind_id: record.id
}
}
console.log("🚀 ~ goToChatPage ~ itemObj:", this.itemObj)
// 跳转到聊天页面
uni.navigateTo({
url: '/packages/customerService/index/index?item=' + JSON.stringify(itemObj)
url: '/packages/customerService/index/index?item=' + JSON.stringify(this.itemObj)
});
} else {
console.log("没有获取到客服列表数据");
uni.showToast({
title: '该客服不存在',
icon: 'none'
})
}
})
}
}
};

View File

@ -47,7 +47,7 @@ packages/customerService/index/index<template>
@confirm="sendMessage" @input="handleInput" auto-height hold-keyboard="true"
enable-keyboard-accessory-view="true" cursor-spacing="10" maxlength="500" @focus="onInputFocus"
@blur="onInputBlur"></textarea>
<button :disabled="!canSend || !client || !isConnected" class="send-btn" @tap="sendMessage">
<button :disabled="inputMessage.trim() === ''" class="send-btn" @tap="sendMessage">
发送
</button>
</view>
@ -112,7 +112,8 @@ export default {
// 获取聊天对象信息
if (options.item) {
this.chatTarget = JSON.parse(options.item)
this.chatTarget.title = `客服${this.chatTarget.employee_name}`
console.log("🚀 ~ onLoad ~ this.chatTarget:", this.chatTarget)
this.chatTarget.title = this.chatTarget.employee_name ? `客服${this.chatTarget.employee_name}` : `客服${this.chatTarget.real_name}`
}
// 初始化MQTT连接
this.initChat()
@ -214,12 +215,18 @@ export default {
// 获取MQTT连接配置
async getMqttConfig() {
console.log("🚀 ~ onLoad ~ this.chatTarget.open_id:", this.chatTarget.open_id)
if (this.chatTarget.open_id) {
this.mqttConfig.clientId = uni.getStorageSync('openId') // 登录人的open_id
this.chatTarget.openId = this.chatTarget.open_id // 接收方的open_id
this.mqttConfig.bind_id = this.chatTarget.bind_id
} else {
try {
// 如果没有已创建的实例或clientId,则通过API获取
return new Promise((resolve, reject) => {
const params = {
worker_id: this.chatTarget.id || '',
open_id: this.selfClientId || ''
open_id: this.selfClientId || '',
}
request(apiArr.csGetToClientId, 'POST', params).then((res) => {
console.log('聊天列表:', res)
@ -242,6 +249,7 @@ export default {
console.error('获取MQTT配置失败', error)
throw error
}
}
},
// MQTT断开连接回调
@ -337,8 +345,8 @@ export default {
// 按照用户提供的格式构建发送消息
const msgData = {
bind_id: this.mqttConfig.bind_id, // 聊天列表的ID,这里暂时固定为1
send_client: this.mqttConfig.clientId, // 消息发送方open_id
receive_client: this.chatTarget.openId, // 消息接收方open_id
send_client: this.selfClientId, // 消息发送方open_id
receive_client: this.mqttConfig.clientId, // 消息接收方open_id
type: 1, // 消息类型,1表示文字消息
content: content, // 消息内容
receive_read_status: 2 // 接收方阅读状态

View File

@ -120,6 +120,7 @@ export default {
uni.removeStorageSync('is_deal');
uni.removeStorageSync('is_dev');
uni.removeStorageSync('is_shop');
uni.removeStorageSync('is_merchant');
uni.removeStorageSync('is_worker');
uni.removeStorageSync('shopId');
uni.removeStorageSync('order_dispatch_permission');
@ -147,6 +148,7 @@ export default {
uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop);
uni.setStorageSync('is_merchant', loginRes.is_merchant);
uni.setStorageSync('is_worker', loginRes.is_worker);

View File

@ -78,6 +78,7 @@ export default {
uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop);
uni.setStorageSync('is_merchant', loginRes.is_merchant);
uni.setStorageSync('is_worker', loginRes.is_worker);
@ -148,6 +149,7 @@ export default {
uni.removeStorageSync('is_deal');
uni.removeStorageSync('is_dev');
uni.removeStorageSync('is_shop');
uni.removeStorageSync('is_merchant');
uni.removeStorageSync('is_worker');
uni.removeStorageSync('shopId');
uni.removeStorageSync('order_dispatch_permission');
@ -197,6 +199,7 @@ export default {
uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop);
uni.setStorageSync('is_merchant', loginRes.is_merchant);
uni.setStorageSync('is_worker', loginRes.is_worker);
// 获取用户信息

View File

@ -113,7 +113,7 @@
</u-grid>
</view>
</view>
<view class="main margin20" v-if="isShop">
<view class="main margin20" v-if="isMerchant">
<view class="main_title">商家端</view>
<view class="item1 padding_bottom0">
<u-grid col="4" :border="false">
@ -246,6 +246,7 @@ export default {
],
userInfo: {},
isShop: uni.getStorageSync('is_shop'),
isMerchant: uni.getStorageSync('is_merchant'),
}
},
@ -269,6 +270,7 @@ export default {
uni.removeStorageSync('is_deal');
uni.removeStorageSync('is_dev');
uni.removeStorageSync('is_shop');
uni.removeStorageSync('is_merchant');
uni.removeStorageSync('is_worker');
uni.removeStorageSync('shopId');
uni.removeStorageSync('order_dispatch_permission');
@ -296,6 +298,7 @@ export default {
uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop);
uni.setStorageSync('is_merchant', loginRes.is_merchant);
uni.setStorageSync('is_worker', loginRes.is_worker);