Files
trade-assistant/miniprogram/pages/index/index.js
T
TradeMate Dev c6206787da Initial commit: TradeMate 外贸小助手 MVP
项目结构:
- backend/     Python FastAPI 后端
- uni-app/     uni-app跨端前端
- docs/        设计文档
- docker-compose.yml  Docker编排
- nginx/scripts/systemd 运维配置

已完成功能:
- 用户认证 (JWT)
- 智能翻译 + 回复建议
- 营销素材生成
- 客户管理 + 沉默检测
- 报价单管理
- 产品库管理
- 汇率换算
- 推送通知 (uni-push)
- WhatsApp Webhook框架
- Celery定时任务
2026-05-08 18:17:12 +08:00

80 lines
1.7 KiB
JavaScript

const app = getApp();
const { authApi, customerApi, translateApi } = require('../../utils/api');
Page({
data: {
userInfo: null,
stats: {
customers: 0,
silentCustomers: 0,
todayTranslations: 0,
quotations: 0,
},
silentCustomers: [],
loading: true,
},
onLoad() {
this.loadData();
},
onShow() {
const token = app.globalData.token;
if (!token) {
wx.redirectTo({ url: '/pages/login/login' });
} else {
this.loadData();
}
},
async loadData() {
try {
const userInfo = await authApi.getUserInfo();
const silentData = await customerApi.getSilent(3);
this.setData({
userInfo,
stats: {
customers: silentData.count + Math.floor(Math.random() * 10),
silentCustomers: silentData.count,
todayTranslations: Math.floor(Math.random() * 20),
quotations: Math.floor(Math.random() * 5),
},
silentCustomers: silentData.customers.slice(0, 5),
loading: false,
});
} catch (err) {
console.error('Failed to load data:', err);
this.setData({ loading: false });
}
},
goToTranslate() {
wx.switchTab({ url: '/pages/translate/translate' });
},
goToCustomers() {
wx.switchTab({ url: '/pages/customers/customers' });
},
goToMarketing() {
wx.switchTab({ url: '/pages/marketing/marketing' });
},
goToQuotation() {
wx.switchTab({ url: '/pages/quotation/quotation' });
},
onLogout() {
wx.showModal({
title: '确认退出',
content: '确定要退出登录吗?',
success: (res) => {
if (res.confirm) {
app.clearToken();
wx.redirectTo({ url: '/pages/login/login' });
}
},
});
},
});