客服模块优化
This commit is contained in:
parent
dbae8b4a5a
commit
c5d4eba244
@ -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)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -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)
|
||||||
// 如果没有已创建的实例或clientId,则通过API获取
|
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) => {
|
// 如果没有已创建的实例或clientId,则通过API获取
|
||||||
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, // 聊天列表的ID,这里暂时固定为1
|
bind_id: this.mqttConfig.bind_id, // 聊天列表的ID,这里暂时固定为1
|
||||||
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 // 接收方阅读状态
|
||||||
|
|||||||
@ -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);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -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);
|
||||||
|
|
||||||
// 获取用户信息
|
// 获取用户信息
|
||||||
|
|||||||
@ -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);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user