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定时任务
This commit is contained in:
@@ -0,0 +1,96 @@
|
||||
const app = getApp();
|
||||
|
||||
const request = (url, method = 'GET', data = {}) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const header = {
|
||||
'Content-Type': 'application/json',
|
||||
...app.getAuthHeader(),
|
||||
};
|
||||
|
||||
wx.request({
|
||||
url: `${app.globalData.baseUrl}${url}`,
|
||||
method,
|
||||
data,
|
||||
header,
|
||||
success: (res) => {
|
||||
if (res.statusCode === 200) {
|
||||
resolve(res.data);
|
||||
} else if (res.statusCode === 401) {
|
||||
app.clearToken();
|
||||
wx.redirectTo({ url: '/pages/login/login' });
|
||||
reject(new Error('Unauthorized'));
|
||||
} else {
|
||||
reject(new Error(res.data?.detail || 'Request failed'));
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
reject(err);
|
||||
},
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
export const authApi = {
|
||||
login: (phone, password) => request('/auth/login', 'POST', { username: phone, password }),
|
||||
register: (phone, password, username) => request('/auth/register', 'POST', { phone, password, username }),
|
||||
getUserInfo: () => request('/auth/me'),
|
||||
};
|
||||
|
||||
export const translateApi = {
|
||||
translate: (text, targetLang, sourceLang = 'auto') =>
|
||||
request('/translate', 'POST', { text, target_lang: targetLang, source_lang: sourceLang }),
|
||||
getReply: (inquiry, tone = 'professional', count = 3) =>
|
||||
request('/translate/reply', 'POST', { inquiry, tone, count }),
|
||||
extract: (text, type = 'auto') =>
|
||||
request('/translate/extract', 'POST', { text, extract_type: type }),
|
||||
};
|
||||
|
||||
export const customerApi = {
|
||||
list: (page = 1, size = 20, status) => {
|
||||
const params = new URLSearchParams({ page, size });
|
||||
if (status) params.append('status', status);
|
||||
return request(`/customers?${params.toString()}`);
|
||||
},
|
||||
get: (id) => request(`/customers/${id}`),
|
||||
create: (data) => request('/customers', 'POST', data),
|
||||
update: (id, data) => request(`/customers/${id}`, 'PATCH', data),
|
||||
delete: (id) => request(`/customers/${id}`, 'DELETE'),
|
||||
getSilent: (days = 3) => request(`/customers/silent?days=${days}`),
|
||||
getConversation: (id, page = 1, size = 50) =>
|
||||
request(`/customers/${id}/conversation?page=${page}&size=${size}`),
|
||||
};
|
||||
|
||||
export const marketingApi = {
|
||||
generate: (productName, description, category, target = 'US importers', style = 'professional') =>
|
||||
request('/marketing/generate', 'POST', {
|
||||
product_name: productName,
|
||||
description,
|
||||
category,
|
||||
target,
|
||||
style,
|
||||
}),
|
||||
getKeywords: (productName, description, category) =>
|
||||
request('/marketing/keywords', 'POST', {
|
||||
product_name: productName,
|
||||
description,
|
||||
category,
|
||||
}),
|
||||
analyzeCompetitors: (productName, description, category, market = 'US') =>
|
||||
request('/marketing/competitor-analysis', 'POST', {
|
||||
product_name: productName,
|
||||
description,
|
||||
category,
|
||||
market,
|
||||
}),
|
||||
};
|
||||
|
||||
export const quotationApi = {
|
||||
list: (page = 1, size = 20) => request(`/quotations?page=${page}&size=${size}`),
|
||||
get: (id) => request(`/quotations/${id}`),
|
||||
create: (data) => request('/quotations', 'POST', data),
|
||||
updateStatus: (id, status) => request(`/quotations/${id}/status`, 'PATCH', { status }),
|
||||
};
|
||||
|
||||
export const whatsappApi = {
|
||||
send: (to, text) => request('/whatsapp/send', 'POST', { to, text }),
|
||||
};
|
||||
Reference in New Issue
Block a user