refactor: 替换硬编码文本为多语言配置

替换了项目中所有硬编码的提示文案,将其统一迁移到多语言语言包中,包括授权、自定义页面、HTTP请求、分享、客服等模块的提示文本,提升项目的国际化可维护性
This commit is contained in:
2026-06-23 08:36:55 +08:00
parent 6c7f7d4837
commit 750ed2dac7
7 changed files with 123 additions and 53 deletions

View File

@@ -30,7 +30,7 @@ export default {
typeof callback == 'function' && callback(this.authInfo); typeof callback == 'function' && callback(this.authInfo);
} else { } else {
this.$util.showToast({ this.$util.showToast({
title: res.message ? res.message : '小程序配置错误' title: res.message ? res.message : this.$lang('auth.configError')
}); });
} }
} }
@@ -67,7 +67,7 @@ export default {
typeof callback == 'function' && callback(this.authInfo); typeof callback == 'function' && callback(this.authInfo);
} else { } else {
this.$util.showToast({ this.$util.showToast({
title: res.message ? res.message : '小程序配置错误' title: res.message ? res.message : this.$lang('auth.configError')
}); });
} }
} }

View File

@@ -4,6 +4,7 @@
*/ */
import IMAGE_CONFIG from './image-config.js'; import IMAGE_CONFIG from './image-config.js';
import Platform from './platform.js'; import Platform from './platform.js';
import lang from './lang.js';
export class CustomerService { export class CustomerService {
constructor(vueInstance, externalConfig = null) { constructor(vueInstance, externalConfig = null) {
@@ -100,16 +101,16 @@ export class CustomerService {
if (!config || !config.type) { if (!config || !config.type) {
result.isValid = false; result.isValid = false;
result.errors.push('客服类型未配置'); result.errors.push(lang('customerService.typeNotConfigured'));
return result; return result;
} }
if (config.type === 'wxwork') { if (config.type === 'wxwork') {
if (!wxworkConfig || !wxworkConfig.enable) { if (!wxworkConfig || !wxworkConfig.enable) {
result.warnings.push('企业微信未启用'); result.warnings.push(lang('customerService.wxworkNotEnabled'));
} }
if (!wxworkConfig.contact_url) { if (!wxworkConfig.contact_url) {
result.warnings.push('企业微信活码链接未配置'); result.warnings.push(lang('customerService.wxworkContactUrlNotConfigured'));
} }
} }
@@ -138,12 +139,12 @@ export class CustomerService {
// #ifdef H5 // #ifdef H5
window.location.href = aiChatUrl; window.location.href = aiChatUrl;
// #endif // #endif
uni.showToast({ title: '打开客服失败', icon: 'none' }); uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
} }
}); });
} catch (e) { } catch (e) {
console.error('跳转 AI智能客服异常:', 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) { if (!config.wxwork_url && !config.corpid) {
console.error('企业微信配置不完整,缺少 wxwork_url 或 corpid'); console.error('企业微信配置不完整,缺少 wxwork_url 或 corpid');
uni.showToast({ title: '企业微信配置不完整', icon: 'none' }); uni.showToast({ title: lang('customerService.wxworkConfigIncomplete'), icon: 'none' });
this.fallbackToPhoneCall(); this.fallbackToPhoneCall();
return; return;
} }
@@ -267,12 +268,12 @@ export class CustomerService {
}, },
fail: (err) => { fail: (err) => {
console.error('【跳转第三方小程序失败】', err); console.error('【跳转第三方小程序失败】', err);
uni.showToast({ title: '跳转失败,请稍后重试', icon: 'none' }); uni.showToast({ title: lang('customerService.thirdMiniAppFailed'), icon: 'none' });
} }
}); });
// #endif // #endif
// #ifdef H5 // #ifdef H5
uni.showToast({ title: '第三方小程序客服仅在微信小程序中可用', icon: 'none' }); uni.showToast({ title: lang('customerService.thirdMiniAppOnlyInWechat'), icon: 'none' });
// #endif // #endif
return; return;
} }
@@ -286,7 +287,7 @@ export class CustomerService {
uni.setClipboardData({ uni.setClipboardData({
data: config.third_url, data: config.third_url,
success: () => { success: () => {
uni.showToast({ title: '链接已复制,请在浏览器打开', icon: 'none' }); uni.showToast({ title: lang('customerService.linkCopiedOpenBrowser'), icon: 'none' });
} }
}); });
// #endif // #endif
@@ -352,7 +353,7 @@ export class CustomerService {
// #endif // #endif
// #ifdef MP // #ifdef MP
uni.setClipboardData({ data: serviceUrl }); uni.setClipboardData({ data: serviceUrl });
uni.showToast({ title: '客服链接已复制', icon: 'none' }); uni.showToast({ title: lang('customerService.linkCopied'), icon: 'none' });
// #endif // #endif
return; return;
} }
@@ -380,11 +381,11 @@ export class CustomerService {
if (res.code === 0 && res.data?.mobile) { if (res.code === 0 && res.data?.mobile) {
uni.makePhoneCall({ phoneNumber: res.data.mobile }); uni.makePhoneCall({ phoneNumber: res.data.mobile });
} else { } else {
uni.showToast({ title: '暂无客服电话', icon: 'none' }); uni.showToast({ title: lang('customerService.noPhone'), icon: 'none' });
} }
}, },
fail: () => { fail: () => {
uni.showToast({ title: '获取客服电话失败', icon: 'none' }); uni.showToast({ title: lang('customerService.getPhoneFailed'), icon: 'none' });
} }
}); });
} }
@@ -392,23 +393,23 @@ export class CustomerService {
showNoServicePopup() { showNoServicePopup() {
const siteInfo = this.vm.$store.state.siteInfo || {}; const siteInfo = this.vm.$store.state.siteInfo || {};
const message = siteInfo?.site_tel const message = siteInfo?.site_tel
? `请联系客服,客服电话是 ${siteInfo.site_tel}` ? lang('customerService.contactPhone', { phone: siteInfo.site_tel })
: '抱歉,商家暂无客服,请线下联系'; : lang('customerService.noServiceOffline');
uni.showModal({ title: '联系客服', content: message, showCancel: false }); uni.showModal({ title: lang('customerService.contactCustomerService'), content: message, showCancel: false });
} }
showConfigErrorPopup(errors) { showConfigErrorPopup(errors) {
uni.showModal({ uni.showModal({
title: '客服配置错误', title: lang('customerService.configError'),
content: `配置有误:\n${errors.join('\n')}`, content: lang('customerService.configErrorMsg', { errors: errors.join('\n') }),
showCancel: false showCancel: false
}); });
} }
fallbackToOriginalService() { fallbackToOriginalService() {
uni.showModal({ uni.showModal({
title: '提示', title: lang('common.tip'),
content: '无法直接添加企业微信,是否使用其他方式联系客服?', content: lang('customerService.cannotAddWxwork'),
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
this.openWxworkService(true); this.openWxworkService(true);
@@ -419,8 +420,8 @@ export class CustomerService {
fallbackToPhoneCall() { fallbackToPhoneCall() {
uni.showModal({ uni.showModal({
title: '提示', title: lang('common.tip'),
content: '在线客服不可用,是否拨打电话联系客服?', content: lang('customerService.onlineServiceUnavailable'),
success: (res) => { success: (res) => {
if (res.confirm) this.makePhoneCall(); if (res.confirm) this.makePhoneCall();
} }
@@ -567,12 +568,12 @@ export class CustomerService {
// #ifdef H5 // #ifdef H5
window.location.href = aiChatUrl; window.location.href = aiChatUrl;
// #endif // #endif
uni.showToast({ title: '打开客服失败', icon: 'none' }); uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
} }
}); });
} catch (e) { } catch (e) {
console.error('跳转 AI智能客服异常:', 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() { openCustomerSelectPopupDialog() {
uni.showToast({ title: '客服选择功能开发中', icon: 'none' }); uni.showToast({ title: lang('customerService.developing'), icon: 'none' });
} }
/** /**
@@ -610,7 +611,7 @@ export class CustomerService {
if (qyweixinUrl) { if (qyweixinUrl) {
window.location.href = qyweixinUrl; window.location.href = qyweixinUrl;
} else { } else {
uni.showToast({ title: '企业微信客服未配置', icon: 'none' }); uni.showToast({ title: lang('customerService.wxworkNotConfigured'), icon: 'none' });
} }
} }
} else { } else {
@@ -629,7 +630,7 @@ export class CustomerService {
if (!validation.isValid) { if (!validation.isValid) {
console.error('客服配置无效:', validation.errors); console.error('客服配置无效:', validation.errors);
uni.showToast({ title: '客服暂不可用', icon: 'none' }); uni.showToast({ title: lang('customerService.unavailable'), icon: 'none' });
return; return;
} }
@@ -646,7 +647,7 @@ export class CustomerService {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
if (!wxworkConfig?.enable || !wxworkConfig?.contact_url) { if (!wxworkConfig?.enable || !wxworkConfig?.contact_url) {
console.warn('企业微信配置不完整,使用原生客服'); console.warn('企业微信配置不完整,使用原生客服');
uni.showToast({ title: '企业微信配置不完整', icon: 'none' }); uni.showToast({ title: lang('customerService.wxworkConfigIncomplete'), icon: 'none' });
} }
// #endif // #endif
@@ -667,7 +668,7 @@ export class CustomerService {
}); });
} catch (error) { } catch (error) {
console.error('客服处理失败:', error); console.error('客服处理失败:', error);
uni.showToast({ title: '打开客服失败', icon: 'none' }); uni.showToast({ title: lang('customerService.openFailed'), icon: 'none' });
} }
} }
} }

View File

@@ -326,7 +326,7 @@ export default {
} }
this.$util.showToast({ this.$util.showToast({
title: '未配置自定义页面数据' title: this.$lang('diy.noCustomPageData')
}); });
this.diyData = {}; this.diyData = {};
return; return;
@@ -560,7 +560,7 @@ export default {
if (res.code == 0 && res.data) { if (res.code == 0 && res.data) {
this.currentPosition = res.data.formatted_addresses.recommend; // 结合知名地点形成的描述性地址,更具人性化特点 this.currentPosition = res.data.formatted_addresses.recommend; // 结合知名地点形成的描述性地址,更具人性化特点
} else { } else {
this.currentPosition = '未获取到定位'; this.currentPosition = this.$lang('diy.locationNotObtained');
} }
} }
}); });
@@ -572,7 +572,7 @@ export default {
this.nearestStore = this.defaultStoreInfo; this.nearestStore = this.defaultStoreInfo;
this.nearestStore.show_address = this.nearestStore.full_address.replace(/,/g, ' ') + ' ' + this.nearestStore.address; this.nearestStore.show_address = this.nearestStore.full_address.replace(/,/g, ' ') + ' ' + this.nearestStore.address;
} }
if (this.currentPosition == '') this.currentPosition = '未获取到定位'; if (this.currentPosition == '') this.currentPosition = this.$lang('diy.locationNotObtained');
this.openChooseStorePopup(); this.openChooseStorePopup();
} }
}, },

View File

@@ -2,6 +2,7 @@ import Config from './config.js'
import Util from './util.js' import Util from './util.js'
import store from '@/store/index.js' import store from '@/store/index.js'
import Platform from './platform.js' import Platform from './platform.js'
import lang from './lang.js'
const { appType, appTypeName } = Platform.getPlatformInfo(); const { appType, appTypeName } = Platform.getPlatformInfo();
@@ -9,7 +10,7 @@ export default {
sendRequest(params) { sendRequest(params) {
if (!Config.baseUrl) { if (!Config.baseUrl) {
uni.showToast({ uni.showToast({
title: '未配置请求域名', title: lang('http.domainNotConfigured'),
'icon': 'none', 'icon': 'none',
duration: 10000 duration: 10000
}); });
@@ -77,7 +78,7 @@ export default {
fail: (res) => { fail: (res) => {
if (res.errMsg && res.errMsg == 'request:fail url not in domain list') { if (res.errMsg && res.errMsg == 'request:fail url not in domain list') {
uni.showToast({ uni.showToast({
title: Config.baseUrl + '不在request 合法域名列表中', title: lang('http.domainNotInList', { domain: Config.baseUrl }),
'icon': 'none', 'icon': 'none',
duration: 10000 duration: 10000
}); });
@@ -88,7 +89,7 @@ export default {
complete: (res) => { complete: (res) => {
if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200, 500].indexOf(res.statusCode) == -1)) { if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200, 500].indexOf(res.statusCode) == -1)) {
uni.showToast({ uni.showToast({
title: Config.baseUrl + '请求失败', title: lang('http.requestFailed', { domain: Config.baseUrl }),
'icon': 'none', 'icon': 'none',
duration: 10000 duration: 10000
}); });
@@ -134,7 +135,7 @@ export default {
fail: (res) => { fail: (res) => {
if (res.errMsg && res.errMsg == 'request:fail url not in domain list') { if (res.errMsg && res.errMsg == 'request:fail url not in domain list') {
uni.showToast({ uni.showToast({
title: Config.baseUrl + '不在request 合法域名列表中', title: lang('http.domainNotInList', { domain: Config.baseUrl }),
'icon': 'none', 'icon': 'none',
duration: 10000 duration: 10000
}); });
@@ -145,7 +146,7 @@ export default {
complete: (res) => { complete: (res) => {
if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200, 500].indexOf(res.statusCode) == -1)) { if ((res.errMsg && res.errMsg != "request:ok") || (res.statusCode && [200, 500].indexOf(res.statusCode) == -1)) {
uni.showToast({ uni.showToast({
title: Config.baseUrl + '请求失败', title: lang('http.requestFailed', { domain: Config.baseUrl }),
'icon': 'none', 'icon': 'none',
duration: 10000 duration: 10000
}); });

View File

@@ -1,4 +1,6 @@
// 文件分享工具函数 // 文件分享工具函数
import lang from './lang.js';
export default { export default {
/** /**
* 生成文件预览链接 * 生成文件预览链接
@@ -30,7 +32,7 @@ export default {
* @param {string} title - 分享标题,默认使用文件名 * @param {string} title - 分享标题,默认使用文件名
* @param {string} desc - 分享描述,默认使用固定文案 * @param {string} desc - 分享描述,默认使用固定文案
*/ */
shareFile(file, title = file.name, desc = '查看企业文件:' + file.name) { shareFile(file, title = file.name, desc = lang('share.filePreview') + file.name) {
// 生成文件预览链接 // 生成文件预览链接
const filePreviewUrl = this.generateFilePreviewUrl(file); const filePreviewUrl = this.generateFilePreviewUrl(file);
@@ -44,17 +46,17 @@ export default {
url: filePreviewUrl url: filePreviewUrl
}).catch(err => { }).catch(err => {
console.error('分享失败:', err); console.error('分享失败:', err);
uni.showToast({ title: '分享失败', icon: 'none' }); uni.showToast({ title: lang('share.failed'), icon: 'none' });
}); });
} else { } else {
// 不支持 Web Share API 的浏览器 // 不支持 Web Share API 的浏览器
uni.setClipboardData({ uni.setClipboardData({
data: filePreviewUrl, data: filePreviewUrl,
success: () => { success: () => {
uni.showToast({ title: '链接已复制,请粘贴分享', icon: 'success' }); uni.showToast({ title: lang('share.linkCopied'), icon: 'success' });
}, },
fail: () => { fail: () => {
uni.showToast({ title: '复制失败', icon: 'none' }); uni.showToast({ title: lang('common.copyFailed'), icon: 'none' });
} }
}); });
} }
@@ -63,7 +65,7 @@ export default {
// #ifdef MP-WEIXIN // #ifdef MP-WEIXIN
// 微信小程序分享 // 微信小程序分享
uni.showActionSheet({ uni.showActionSheet({
itemList: ['发送给朋友', '分享到朋友圈'], itemList: [lang('share.sendToFriend'), lang('share.sendToMoments')],
success: (res) => { success: (res) => {
if (res.tapIndex === 0) { if (res.tapIndex === 0) {
// 发送给朋友 // 发送给朋友
@@ -71,10 +73,10 @@ export default {
title: title, title: title,
path: filePreviewUrl, path: filePreviewUrl,
success: () => { success: () => {
uni.showToast({ title: '分享成功', icon: 'success' }); uni.showToast({ title: lang('share.success'), icon: 'success' });
}, },
fail: () => { fail: () => {
uni.showToast({ title: '分享失败', icon: 'none' }); uni.showToast({ title: lang('share.failed'), icon: 'none' });
} }
}); });
} else if (res.tapIndex === 1) { } else if (res.tapIndex === 1) {
@@ -83,10 +85,10 @@ export default {
title: desc, title: desc,
path: filePreviewUrl, path: filePreviewUrl,
success: () => { success: () => {
uni.showToast({ title: '分享成功', icon: 'success' }); uni.showToast({ title: lang('share.success'), icon: 'success' });
}, },
fail: () => { fail: () => {
uni.showToast({ title: '分享失败', icon: 'none' }); uni.showToast({ title: lang('share.failed'), icon: 'none' });
} }
}); });
} }

View File

@@ -2,6 +2,7 @@ import Config from './config.js'
import store from '@/store/index.js' import store from '@/store/index.js'
import Http from './http.js' import Http from './http.js'
import Platform from './platform.js' import Platform from './platform.js'
import lang from './lang.js'
import { import {
Weixin Weixin
} from 'common/js/wx-jssdk.js'; } from 'common/js/wx-jssdk.js';
@@ -668,7 +669,7 @@ export default {
tMonth = doHandleMonth(tMonth + 1); tMonth = doHandleMonth(tMonth + 1);
tDate = doHandleMonth(tDate); tDate = doHandleMonth(tDate);
const week = ['周日', '周一', '周二', '周三', '周四', '周五', '周六'] const week = [lang('common.sunday'), lang('common.monday'), lang('common.tuesday'), lang('common.wednesday'), lang('common.thursday'), lang('common.friday'), lang('common.saturday')]
return { return {
't': time, 't': time,
'y': tYear, 'y': tYear,
@@ -705,7 +706,7 @@ export default {
var _data = data; var _data = data;
var imgs = []; var imgs = [];
uni.showLoading({ uni.showLoading({
title: '图片上传中' title: lang('common.uploading')
}) })
for (var i = 0; i < tempFilePaths.length; i++) { for (var i = 0; i < tempFilePaths.length; i++) {
var path = await _self.upload_file_server(tempFilePaths[i], _data, params.path, var path = await _self.upload_file_server(tempFilePaths[i], _data, params.path,
@@ -714,7 +715,7 @@ export default {
if (imgs.length == tempFilePaths.length) { if (imgs.length == tempFilePaths.length) {
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
title: '上传成功', title: lang('common.uploadSuccess'),
icon: 'none' icon: 'none'
}) })
typeof callback == 'function' && callback(imgs); typeof callback == 'function' && callback(imgs);
@@ -724,7 +725,7 @@ export default {
fail: err => { fail: err => {
uni.hideLoading() uni.hideLoading()
uni.showToast({ uni.showToast({
title: '上传失败', title: lang('common.uploadFailed'),
icon: 'none' icon: 'none'
}) })
} }
@@ -775,7 +776,7 @@ export default {
oInput.style.display = 'none'; oInput.style.display = 'none';
uni.hideKeyboard(); uni.hideKeyboard();
this.showToast({ this.showToast({
title: '复制成功' title: lang('common.copySuccess')
}); });
typeof callback == 'function' && callback(); typeof callback == 'function' && callback();
@@ -1039,7 +1040,7 @@ export default {
}); });
} else { } else {
this.showToast({ this.showToast({
title: '抱歉,商家暂无客服,请线下联系', title: lang('common.noCustomerService'),
}) })
} }
} }

View File

@@ -40,11 +40,23 @@ export const lang = {
saveSuccess: "保存成功", saveSuccess: "保存成功",
saveFailed: "保存失败,请稍后重试", saveFailed: "保存失败,请稍后重试",
copySuccess: "复制成功", copySuccess: "复制成功",
copyFailed: "复制失败",
collapse: "收起", collapse: "收起",
expand: "展开", expand: "展开",
days: "天", days: "天",
buildVersion: "构建版本信息", buildVersion: "构建版本信息",
buildVersionDesc: "提交 ID: {commitId}\n构建时间: {buildTime}", buildVersionDesc: "提交 ID: {commitId}\n构建时间: {buildTime}",
sunday: "周日",
monday: "周一",
tuesday: "周二",
wednesday: "周三",
thursday: "周四",
friday: "周五",
saturday: "周六",
uploading: "图片上传中",
uploadSuccess: "上传成功",
uploadFailed: "上传失败",
noCustomerService: "抱歉,商家暂无客服,请线下联系",
}, },
//客服 //客服
@@ -2487,4 +2499,57 @@ export const lang = {
hoursAgo: "小时前", hoursAgo: "小时前",
daysAgo: "天前", daysAgo: "天前",
}, },
// 客服服务
customerService: {
typeNotConfigured: "客服类型未配置",
wxworkNotEnabled: "企业微信未启用",
wxworkContactUrlNotConfigured: "企业微信活码链接未配置",
openFailed: "打开客服失败",
wxworkConfigIncomplete: "企业微信配置不完整",
thirdMiniAppFailed: "跳转失败,请稍后重试",
thirdMiniAppOnlyInWechat: "第三方小程序客服仅在微信小程序中可用",
linkCopiedOpenBrowser: "链接已复制,请在浏览器打开",
linkCopied: "客服链接已复制",
noPhone: "暂无客服电话",
getPhoneFailed: "获取客服电话失败",
contactPhone: "请联系客服,客服电话是 {phone}",
noServiceOffline: "抱歉,商家暂无客服,请线下联系",
contactCustomerService: "联系客服",
configError: "客服配置错误",
configErrorMsg: "配置有误:\n{errors}",
cannotAddWxwork: "无法直接添加企业微信,是否使用其他方式联系客服?",
onlineServiceUnavailable: "在线客服不可用,是否拨打电话联系客服?",
developing: "客服选择功能开发中",
wxworkNotConfigured: "企业微信客服未配置",
unavailable: "客服暂不可用",
},
// 分享
share: {
filePreview: "查看企业文件:",
failed: "分享失败",
linkCopied: "链接已复制,请粘贴分享",
sendToFriend: "发送给朋友",
sendToMoments: "分享到朋友圈",
success: "分享成功",
},
// 授权
auth: {
configError: "小程序配置错误",
},
// 自定义页面
diy: {
noCustomPageData: "未配置自定义页面数据",
locationNotObtained: "未获取到定位",
},
// HTTP请求
http: {
domainNotConfigured: "未配置请求域名",
domainNotInList: "{domain}不在request合法域名列表中",
requestFailed: "{domain}请求失败",
},
}; };