添加客服功能

This commit is contained in:
张成
2025-09-29 10:20:36 +08:00
parent 5ce229f092
commit 090a44fd6e
3 changed files with 112 additions and 6 deletions

View File

@@ -10,6 +10,13 @@ export interface EnvConfig {
timeout: number
enableLog: boolean
enableMock: boolean
// 客服配置
customerService: {
corpId: string
serviceUrl: string
phoneNumber?: string
email?: string
}
}
// 各环境配置
@@ -21,7 +28,14 @@ const envConfigs: Record<EnvType, EnvConfig> = {
// apiBaseURL: 'http://localhost:9098',
timeout: 15000,
enableLog: true,
enableMock: true
enableMock: true,
// 客服配置
customerService: {
corpId: 'ww51fc969e8b76af82', // 企业ID
serviceUrl: 'https://work.weixin.qq.com/kfid/kfc64085b93243c5c91',
phoneNumber: '400-888-8888',
email: 'service@light120.com'
}
},
@@ -31,7 +45,14 @@ const envConfigs: Record<EnvType, EnvConfig> = {
apiBaseURL: 'https://sit.light120.com',
timeout: 10000,
enableLog: false,
enableMock: false
enableMock: false,
// 客服配置
customerService: {
corpId: 'ww51fc969e8b76af82', // 企业ID
serviceUrl: 'https://work.weixin.qq.com/kfid/kfc64085b93243c5c91',
phoneNumber: '400-888-8888',
email: 'service@light120.com'
}
}
}
@@ -86,7 +107,7 @@ export const getEnvInfo = () => {
config,
taroEnv: Taro.getEnv(),
platform: Taro.getEnv() === Taro.ENV_TYPE.WEAPP ? '微信小程序' :
Taro.getEnv() === Taro.ENV_TYPE.H5 ? 'H5' :
Taro.getEnv() === Taro.ENV_TYPE.WEB ? 'Web' :
Taro.getEnv() === Taro.ENV_TYPE.RN ? 'React Native' : '未知'
}
}

View File

@@ -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'
});
}
}
}
});
};

View File

@@ -6,6 +6,7 @@ import { CommonPopup } from "@/components";
import httpService from "@/services/httpService";
import { withAuth } from "@/components";
import { PopupPicker } from "@/components/Picker/index";
import { handleCustomerService } from "@/services/userService";
// 交易记录类型
interface Transaction {
@@ -484,8 +485,8 @@ const WalletPage: React.FC = () => {
/>
<Text className="function_text"></Text>
</View>
{/* TODO 客服中心 */}
<View className="function_item" onClick={() => Taro.navigateTo({ url: "/user_pages/validPhone/index" })}>
{/* 客服中心 */}
<View className="function_item" onClick={handleCustomerService}>
<Image
className="function_icon"
src={require("@/static/wallet/custom-service.svg")}