客服模块优化

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, isLoading: false,
page_num: 1, page_num: 1,
page_size: 10, page_size: 10,
itemObj: {},
}; };
}, },
onLoad() { onLoad() {
//
this.loadChattingRecords();
}, },
onShow() { onShow() {
// //
@ -62,7 +61,7 @@ export default {
page_num: this.page_num, page_num: this.page_num,
page_size: this.page_size, page_size: this.page_size,
}).then((res) => { }).then((res) => {
this.recordsList = res.msg_list this.recordsList = res.msg_list.filter(item => item.client_id_one !== item.client_id_two)
}) })
} catch (error) { } catch (error) {
console.error('加载聊天记录失败', error); console.error('加载聊天记录失败', error);
@ -104,29 +103,24 @@ export default {
// //
goToChatPage(record) { goToChatPage(record) {
const params = { console.log("🚀 ~ goToChatPage ~ record:", record)
mch_id: record.mch_id, if (record.client_id_two == uni.getStorageSync('openId')) {
} this.itemObj = {
...record.one,
request(apiArr.csGetMchContactList, "POST", params).then((res) => { bind_id: record.id
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)
//
uni.navigateTo({
url: '/packages/customerService/index/index?item=' + JSON.stringify(itemObj)
});
} else {
console.log("没有获取到客服列表数据");
uni.showToast({
title: '该客服不存在',
icon: 'none'
})
} }
}) } 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(this.itemObj)
});
} }
} }
}; };

View File

@ -47,7 +47,7 @@ packages/customerService/index/index<template>
@confirm="sendMessage" @input="handleInput" auto-height hold-keyboard="true" @confirm="sendMessage" @input="handleInput" auto-height hold-keyboard="true"
enable-keyboard-accessory-view="true" cursor-spacing="10" maxlength="500" @focus="onInputFocus" enable-keyboard-accessory-view="true" cursor-spacing="10" maxlength="500" @focus="onInputFocus"
@blur="onInputBlur"></textarea> @blur="onInputBlur"></textarea>
<button :disabled="!canSend || !client || !isConnected" class="send-btn" @tap="sendMessage"> <button :disabled="inputMessage.trim() === ''" class="send-btn" @tap="sendMessage">
发送 发送
</button> </button>
</view> </view>
@ -112,7 +112,8 @@ export default {
// //
if (options.item) { if (options.item) {
this.chatTarget = JSON.parse(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 // MQTT
this.initChat() this.initChat()
@ -214,33 +215,40 @@ export default {
// MQTT // MQTT
async getMqttConfig() { async getMqttConfig() {
try { console.log("🚀 ~ onLoad ~ this.chatTarget.open_id:", this.chatTarget.open_id)
// clientIdAPI if (this.chatTarget.open_id) {
return new Promise((resolve, reject) => { this.mqttConfig.clientId = uni.getStorageSync('openId') // open_id
const params = { this.chatTarget.openId = this.chatTarget.open_id // open_id
worker_id: this.chatTarget.id || '', this.mqttConfig.bind_id = this.chatTarget.bind_id
open_id: this.selfClientId || '' } else {
} try {
request(apiArr.csGetToClientId, 'POST', params).then((res) => { // clientIdAPI
console.log('聊天列表:', res) return new Promise((resolve, reject) => {
// const params = {
if (res && res.client_bind && res.client_bind.client_id_one && res.client_bind.client_id_two) { worker_id: this.chatTarget.id || '',
this.mqttConfig.clientId = res.client_bind.client_id_one // open_id open_id: this.selfClientId || '',
this.chatTarget.openId = res.client_bind.client_id_two // open_id
this.mqttConfig.bind_id = res.client_bind.id
resolve()
} else {
console.error('MQTT配置响应格式不正确:', res)
reject(new Error('未获取到有效的MQTT配置'))
} }
}).catch(error => { request(apiArr.csGetToClientId, 'POST', params).then((res) => {
console.error('获取MQTT配置失败', error) console.log('聊天列表:', res)
reject(error) //
if (res && res.client_bind && res.client_bind.client_id_one && res.client_bind.client_id_two) {
this.mqttConfig.clientId = res.client_bind.client_id_one // open_id
this.chatTarget.openId = res.client_bind.client_id_two // open_id
this.mqttConfig.bind_id = res.client_bind.id
resolve()
} else {
console.error('MQTT配置响应格式不正确:', res)
reject(new Error('未获取到有效的MQTT配置'))
}
}).catch(error => {
console.error('获取MQTT配置失败', error)
reject(error)
})
}) })
}) } catch (error) {
} catch (error) { console.error('获取MQTT配置失败', error)
console.error('获取MQTT配置失败', error) throw error
throw error }
} }
}, },
@ -337,8 +345,8 @@ export default {
// //
const msgData = { const msgData = {
bind_id: this.mqttConfig.bind_id, // ID1 bind_id: this.mqttConfig.bind_id, // ID1
send_client: this.mqttConfig.clientId, // open_id send_client: this.selfClientId, // open_id
receive_client: this.chatTarget.openId, // open_id receive_client: this.mqttConfig.clientId, // open_id
type: 1, // 1 type: 1, // 1
content: content, // content: content, //
receive_read_status: 2 // receive_read_status: 2 //

View File

@ -120,6 +120,7 @@ export default {
uni.removeStorageSync('is_deal'); uni.removeStorageSync('is_deal');
uni.removeStorageSync('is_dev'); uni.removeStorageSync('is_dev');
uni.removeStorageSync('is_shop'); uni.removeStorageSync('is_shop');
uni.removeStorageSync('is_merchant');
uni.removeStorageSync('is_worker'); uni.removeStorageSync('is_worker');
uni.removeStorageSync('shopId'); uni.removeStorageSync('shopId');
uni.removeStorageSync('order_dispatch_permission'); uni.removeStorageSync('order_dispatch_permission');
@ -147,6 +148,7 @@ export default {
uni.setStorageSync('is_deal', loginRes.is_deal); uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev); uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop); uni.setStorageSync('is_shop', loginRes.is_shop);
uni.setStorageSync('is_merchant', loginRes.is_merchant);
uni.setStorageSync('is_worker', loginRes.is_worker); 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_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev); uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop); uni.setStorageSync('is_shop', loginRes.is_shop);
uni.setStorageSync('is_merchant', loginRes.is_merchant);
uni.setStorageSync('is_worker', loginRes.is_worker); uni.setStorageSync('is_worker', loginRes.is_worker);
@ -148,6 +149,7 @@ export default {
uni.removeStorageSync('is_deal'); uni.removeStorageSync('is_deal');
uni.removeStorageSync('is_dev'); uni.removeStorageSync('is_dev');
uni.removeStorageSync('is_shop'); uni.removeStorageSync('is_shop');
uni.removeStorageSync('is_merchant');
uni.removeStorageSync('is_worker'); uni.removeStorageSync('is_worker');
uni.removeStorageSync('shopId'); uni.removeStorageSync('shopId');
uni.removeStorageSync('order_dispatch_permission'); uni.removeStorageSync('order_dispatch_permission');
@ -197,6 +199,7 @@ export default {
uni.setStorageSync('is_deal', loginRes.is_deal); uni.setStorageSync('is_deal', loginRes.is_deal);
uni.setStorageSync('is_dev', loginRes.is_dev); uni.setStorageSync('is_dev', loginRes.is_dev);
uni.setStorageSync('is_shop', loginRes.is_shop); uni.setStorageSync('is_shop', loginRes.is_shop);
uni.setStorageSync('is_merchant', loginRes.is_merchant);
uni.setStorageSync('is_worker', loginRes.is_worker); uni.setStorageSync('is_worker', loginRes.is_worker);
// //

View File

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