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,110 @@
|
||||
<script setup>
|
||||
import { onLaunch, onShow, onHide } from '@dcloudio/uni-app'
|
||||
import CustomTabbar from '@/components/tabbar/custom-tabbar.vue'
|
||||
import pushService from '@/utils/push.js'
|
||||
|
||||
onLaunch(() => {
|
||||
console.log('App Launch')
|
||||
const token = uni.getStorageSync('token')
|
||||
if (token) {
|
||||
uni.setStorageSync('hasLogin', true)
|
||||
initPush()
|
||||
}
|
||||
})
|
||||
|
||||
onShow(() => {
|
||||
console.log('App Show')
|
||||
checkSilentCustomers()
|
||||
})
|
||||
|
||||
onHide(() => {
|
||||
console.log('App Hide')
|
||||
})
|
||||
|
||||
async function initPush() {
|
||||
try {
|
||||
await pushService.init()
|
||||
|
||||
// 监听接收消息
|
||||
pushService.onMessage((msg) => {
|
||||
console.log('Received push message:', msg)
|
||||
showNotification(msg)
|
||||
})
|
||||
|
||||
// 监听点击消息
|
||||
pushService.onClick((payload) => {
|
||||
console.log('Push clicked:', payload)
|
||||
handlePushClick(payload)
|
||||
})
|
||||
} catch (err) {
|
||||
console.error('Push init failed:', err)
|
||||
}
|
||||
}
|
||||
|
||||
function showNotification(msg) {
|
||||
uni.showModal({
|
||||
title: msg.title,
|
||||
content: msg.content,
|
||||
showCancel: false,
|
||||
success: () => {
|
||||
if (msg.payload) {
|
||||
handlePushClick(msg.payload)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function handlePushClick(payload) {
|
||||
if (!payload) return
|
||||
|
||||
switch (payload.type) {
|
||||
case 'silent_customer':
|
||||
uni.switchTab({ url: '/pages/customers/customers' })
|
||||
break
|
||||
case 'quotation':
|
||||
uni.switchTab({ url: '/pages/quotation/quotation' })
|
||||
break
|
||||
case 'reply':
|
||||
uni.switchTab({ url: '/pages/translate/translate' })
|
||||
break
|
||||
default:
|
||||
uni.switchTab({ url: '/pages/index/index' })
|
||||
}
|
||||
}
|
||||
|
||||
async function checkSilentCustomers() {
|
||||
const token = uni.getStorageSync('token')
|
||||
if (!token) return
|
||||
|
||||
try {
|
||||
const { customerApi } = require('@/utils/api.js')
|
||||
const silentData = await customerApi.getSilent(3)
|
||||
|
||||
if (silentData.count > 0) {
|
||||
// 创建本地通知提醒
|
||||
pushService.createLocalNotification({
|
||||
title: '跟进提醒',
|
||||
content: `您有 ${silentData.count} 个客户已沉默3天以上`,
|
||||
payload: { type: 'silent_customer', count: silentData.count }
|
||||
})
|
||||
}
|
||||
} catch (err) {
|
||||
console.error('Check silent customers failed:', err)
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<view id="app">
|
||||
<router-view />
|
||||
<CustomTabbar />
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
@import '@/static/common.css';
|
||||
|
||||
#app {
|
||||
padding-bottom: 100rpx;
|
||||
}
|
||||
</style>
|
||||
Reference in New Issue
Block a user