c6206787da
项目结构: - backend/ Python FastAPI 后端 - uni-app/ uni-app跨端前端 - docs/ 设计文档 - docker-compose.yml Docker编排 - nginx/scripts/systemd 运维配置 已完成功能: - 用户认证 (JWT) - 智能翻译 + 回复建议 - 营销素材生成 - 客户管理 + 沉默检测 - 报价单管理 - 产品库管理 - 汇率换算 - 推送通知 (uni-push) - WhatsApp Webhook框架 - Celery定时任务
101 lines
2.3 KiB
JavaScript
101 lines
2.3 KiB
JavaScript
const { translateApi } = require('../../utils/api');
|
|
|
|
Page({
|
|
data: {
|
|
tab: 'translate',
|
|
sourceText: '',
|
|
translatedText: '',
|
|
targetLang: 'en',
|
|
langOptions: [
|
|
{ value: 'en', label: 'English' },
|
|
{ value: 'zh', label: '中文' },
|
|
{ value: 'es', label: 'Español' },
|
|
{ value: 'fr', label: 'Français' },
|
|
{ value: 'de', label: 'Deutsch' },
|
|
{ value: 'ja', label: '日本語' },
|
|
{ value: 'pt', label: 'Português' },
|
|
],
|
|
replyInquiry: '',
|
|
replySuggestions: [],
|
|
loading: false,
|
|
},
|
|
|
|
onLoad() {},
|
|
|
|
switchTab(e) {
|
|
const tab = e.currentTarget.dataset.tab;
|
|
this.setData({ tab });
|
|
},
|
|
|
|
onSourceInput(e) {
|
|
this.setData({ sourceText: e.detail.value });
|
|
},
|
|
|
|
onReplyInput(e) {
|
|
this.setData({ replyInquiry: e.detail.value });
|
|
},
|
|
|
|
onLangChange(e) {
|
|
this.setData({ targetLang: e.detail.value });
|
|
},
|
|
|
|
async doTranslate() {
|
|
if (!this.data.sourceText.trim()) {
|
|
wx.showToast({ title: '请输入要翻译的内容', icon: 'none' });
|
|
return;
|
|
}
|
|
|
|
this.setData({ loading: true });
|
|
try {
|
|
const result = await translateApi.translate(
|
|
this.data.sourceText,
|
|
this.data.targetLang
|
|
);
|
|
this.setData({
|
|
translatedText: result.translated_text,
|
|
loading: false,
|
|
});
|
|
} catch (err) {
|
|
wx.showToast({ title: err.message || '翻译失败', icon: 'none' });
|
|
this.setData({ loading: false });
|
|
}
|
|
},
|
|
|
|
async doGetReply() {
|
|
if (!this.data.replyInquiry.trim()) {
|
|
wx.showToast({ title: '请输入客户询盘内容', icon: 'none' });
|
|
return;
|
|
}
|
|
|
|
this.setData({ loading: true });
|
|
try {
|
|
const result = await translateApi.getReply(this.data.replyInquiry);
|
|
this.setData({
|
|
replySuggestions: result.suggestions,
|
|
loading: false,
|
|
});
|
|
} catch (err) {
|
|
wx.showToast({ title: err.message || '生成回复失败', icon: 'none' });
|
|
this.setData({ loading: false });
|
|
}
|
|
},
|
|
|
|
copyText(e) {
|
|
const text = e.currentTarget.dataset.text;
|
|
wx.setClipboardData({
|
|
data: text,
|
|
success: () => {
|
|
wx.showToast({ title: '已复制', icon: 'success' });
|
|
},
|
|
});
|
|
},
|
|
|
|
clearInput() {
|
|
this.setData({
|
|
sourceText: '',
|
|
translatedText: '',
|
|
replyInquiry: '',
|
|
replySuggestions: [],
|
|
});
|
|
},
|
|
}); |