refactor: 替换硬编码文本为多语言配置
替换了项目中所有硬编码的提示文案,将其统一迁移到多语言语言包中,包括授权、自定义页面、HTTP请求、分享、客服等模块的提示文本,提升项目的国际化可维护性
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
import IMAGE_CONFIG from './image-config.js';
|
||||
import Platform from './platform.js';
|
||||
import lang from './lang.js';
|
||||
|
||||
export class CustomerService {
|
||||
constructor(vueInstance, externalConfig = null) {
|
||||
@@ -100,16 +101,16 @@ export class CustomerService {
|
||||
|
||||
if (!config || !config.type) {
|
||||
result.isValid = false;
|
||||
result.errors.push('客服类型未配置');
|
||||
result.errors.push(lang('customerService.typeNotConfigured'));
|
||||
return result;
|
||||
}
|
||||
|
||||
if (config.type === 'wxwork') {
|
||||
if (!wxworkConfig || !wxworkConfig.enable) {
|
||||
result.warnings.push('企业微信未启用');
|
||||
result.warnings.push(lang('customerService.wxworkNotEnabled'));
|
||||
}
|
||||
if (!wxworkConfig.contact_url) {
|
||||
result.warnings.push('企业微信活码链接未配置');
|
||||
result.warnings.push(lang('customerService.wxworkContactUrlNotConfigured'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,12 +139,12 @@ export class CustomerService {
|
||||
// #ifdef H5
|
||||
window.location.href = aiChatUrl;
|
||||
// #endif
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('跳转 AI智能客服异常:', e);
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,7 +224,7 @@ export class CustomerService {
|
||||
// 检查是否有企业微信配置
|
||||
if (!config.wxwork_url && !config.corpid) {
|
||||
console.error('企业微信配置不完整,缺少 wxwork_url 或 corpid');
|
||||
uni.showToast({ title: '企业微信配置不完整', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.wxworkConfigIncomplete'), icon: 'none' });
|
||||
this.fallbackToPhoneCall();
|
||||
return;
|
||||
}
|
||||
@@ -267,12 +268,12 @@ export class CustomerService {
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('【跳转第三方小程序失败】', err);
|
||||
uni.showToast({ title: '跳转失败,请稍后重试', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.thirdMiniAppFailed'), icon: 'none' });
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
// #ifdef H5
|
||||
uni.showToast({ title: '第三方小程序客服仅在微信小程序中可用', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.thirdMiniAppOnlyInWechat'), icon: 'none' });
|
||||
// #endif
|
||||
return;
|
||||
}
|
||||
@@ -286,7 +287,7 @@ export class CustomerService {
|
||||
uni.setClipboardData({
|
||||
data: config.third_url,
|
||||
success: () => {
|
||||
uni.showToast({ title: '链接已复制,请在浏览器打开', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.linkCopiedOpenBrowser'), icon: 'none' });
|
||||
}
|
||||
});
|
||||
// #endif
|
||||
@@ -352,7 +353,7 @@ export class CustomerService {
|
||||
// #endif
|
||||
// #ifdef MP
|
||||
uni.setClipboardData({ data: serviceUrl });
|
||||
uni.showToast({ title: '客服链接已复制', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.linkCopied'), icon: 'none' });
|
||||
// #endif
|
||||
return;
|
||||
}
|
||||
@@ -380,11 +381,11 @@ export class CustomerService {
|
||||
if (res.code === 0 && res.data?.mobile) {
|
||||
uni.makePhoneCall({ phoneNumber: res.data.mobile });
|
||||
} else {
|
||||
uni.showToast({ title: '暂无客服电话', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.noPhone'), icon: 'none' });
|
||||
}
|
||||
},
|
||||
fail: () => {
|
||||
uni.showToast({ title: '获取客服电话失败', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.getPhoneFailed'), icon: 'none' });
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -392,23 +393,23 @@ export class CustomerService {
|
||||
showNoServicePopup() {
|
||||
const siteInfo = this.vm.$store.state.siteInfo || {};
|
||||
const message = siteInfo?.site_tel
|
||||
? `请联系客服,客服电话是 ${siteInfo.site_tel}`
|
||||
: '抱歉,商家暂无客服,请线下联系';
|
||||
uni.showModal({ title: '联系客服', content: message, showCancel: false });
|
||||
? lang('customerService.contactPhone', { phone: siteInfo.site_tel })
|
||||
: lang('customerService.noServiceOffline');
|
||||
uni.showModal({ title: lang('customerService.contactCustomerService'), content: message, showCancel: false });
|
||||
}
|
||||
|
||||
showConfigErrorPopup(errors) {
|
||||
uni.showModal({
|
||||
title: '客服配置错误',
|
||||
content: `配置有误:\n${errors.join('\n')}`,
|
||||
title: lang('customerService.configError'),
|
||||
content: lang('customerService.configErrorMsg', { errors: errors.join('\n') }),
|
||||
showCancel: false
|
||||
});
|
||||
}
|
||||
|
||||
fallbackToOriginalService() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '无法直接添加企业微信,是否使用其他方式联系客服?',
|
||||
title: lang('common.tip'),
|
||||
content: lang('customerService.cannotAddWxwork'),
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.openWxworkService(true);
|
||||
@@ -419,8 +420,8 @@ export class CustomerService {
|
||||
|
||||
fallbackToPhoneCall() {
|
||||
uni.showModal({
|
||||
title: '提示',
|
||||
content: '在线客服不可用,是否拨打电话联系客服?',
|
||||
title: lang('common.tip'),
|
||||
content: lang('customerService.onlineServiceUnavailable'),
|
||||
success: (res) => {
|
||||
if (res.confirm) this.makePhoneCall();
|
||||
}
|
||||
@@ -567,12 +568,12 @@ export class CustomerService {
|
||||
// #ifdef H5
|
||||
window.location.href = aiChatUrl;
|
||||
// #endif
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('跳转 AI智能客服异常:', e);
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -580,7 +581,7 @@ export class CustomerService {
|
||||
* 打开客服选择对话框(预留方法)
|
||||
*/
|
||||
openCustomerSelectPopupDialog() {
|
||||
uni.showToast({ title: '客服选择功能开发中', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.developing'), icon: 'none' });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -610,7 +611,7 @@ export class CustomerService {
|
||||
if (qyweixinUrl) {
|
||||
window.location.href = qyweixinUrl;
|
||||
} else {
|
||||
uni.showToast({ title: '企业微信客服未配置', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.wxworkNotConfigured'), icon: 'none' });
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -629,7 +630,7 @@ export class CustomerService {
|
||||
|
||||
if (!validation.isValid) {
|
||||
console.error('客服配置无效:', validation.errors);
|
||||
uni.showToast({ title: '客服暂不可用', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.unavailable'), icon: 'none' });
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -646,7 +647,7 @@ export class CustomerService {
|
||||
// #ifdef MP-WEIXIN
|
||||
if (!wxworkConfig?.enable || !wxworkConfig?.contact_url) {
|
||||
console.warn('企业微信配置不完整,使用原生客服');
|
||||
uni.showToast({ title: '企业微信配置不完整', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.wxworkConfigIncomplete'), icon: 'none' });
|
||||
}
|
||||
// #endif
|
||||
|
||||
@@ -667,7 +668,7 @@ export class CustomerService {
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('客服处理失败:', error);
|
||||
uni.showToast({ title: '打开客服失败', icon: 'none' });
|
||||
uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user