添加客服功能
This commit is contained in:
@@ -3,6 +3,7 @@ import { API_CONFIG } from '@/config/api';
|
||||
import httpService, { ApiResponse } from './httpService';
|
||||
import uploadFiles from './uploadFiles';
|
||||
import Taro from '@tarojs/taro';
|
||||
import getCurrentConfig from '@/config/env';
|
||||
|
||||
|
||||
// 用户详情接口
|
||||
@@ -603,3 +604,86 @@ export const get_user_info = (): any | null => {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
// 客服中心处理函数
|
||||
export const handleCustomerService = async (): Promise<void> => {
|
||||
try {
|
||||
// 获取当前环境的客服配置
|
||||
const config = getCurrentConfig;
|
||||
const { customerService } = config;
|
||||
|
||||
console.log('打开客服中心,配置信息:', customerService);
|
||||
|
||||
// 使用微信官方客服能力
|
||||
await Taro.openCustomerServiceChat({
|
||||
extInfo: {
|
||||
url: customerService.serviceUrl
|
||||
},
|
||||
corpId: customerService.corpId,
|
||||
success: (res) => {
|
||||
console.log('打开客服成功:', res);
|
||||
},
|
||||
fail: (error) => {
|
||||
console.error('打开客服失败:', error);
|
||||
// 如果官方客服不可用,显示备用联系方式
|
||||
showCustomerServiceFallback(customerService);
|
||||
}
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('客服功能异常:', error);
|
||||
// 备用方案:显示联系信息
|
||||
showCustomerServiceFallback();
|
||||
}
|
||||
};
|
||||
|
||||
// 客服备用方案
|
||||
const showCustomerServiceFallback = (customerInfo?: any) => {
|
||||
const options = ['拨打客服电话', '复制邮箱地址'];
|
||||
|
||||
// 如果没有客服信息,只显示通用提示
|
||||
if (!customerInfo?.phoneNumber && !customerInfo?.email) {
|
||||
Taro.showModal({
|
||||
title: '联系客服',
|
||||
content: '如需帮助,请通过其他方式联系我们',
|
||||
showCancel: false
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
Taro.showActionSheet({
|
||||
itemList: options,
|
||||
success: async (res) => {
|
||||
if (res.tapIndex === 0 && customerInfo?.phoneNumber) {
|
||||
// 拨打客服电话
|
||||
try {
|
||||
await Taro.makePhoneCall({
|
||||
phoneNumber: customerInfo.phoneNumber
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('拨打电话失败:', error);
|
||||
Taro.showToast({
|
||||
title: '拨打电话失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
} else if (res.tapIndex === 1 && customerInfo?.email) {
|
||||
// 复制邮箱地址
|
||||
try {
|
||||
await Taro.setClipboardData({
|
||||
data: customerInfo.email
|
||||
});
|
||||
Taro.showToast({
|
||||
title: '邮箱地址已复制',
|
||||
icon: 'success'
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('复制邮箱失败:', error);
|
||||
Taro.showToast({
|
||||
title: '复制失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user