From a95e8b2b73e1f8200e13a94d815e89bbabb90058 Mon Sep 17 00:00:00 2001 From: TradeMate Dev Date: Fri, 12 Jun 2026 11:00:22 +0800 Subject: [PATCH] feat: frontend credit system UI Admin: - New CreditManagement.vue (tabs: rates, packages, plans, user credits, consumptions, stats) - Sidebar menu + router entry - Full CRUD for credit packages and subscription plans - User credit balance adjustment - Consumption log viewer User: - Credits.vue replaces Upgrade.vue (package purchase, subscription, history tabs) - Credit balance display in topbar + dashboard header CTA card - Navigation restructured: discovery first - Profile redirects to /credits - Dashboard upgrade dialog simplified to redirect to /credits --- admin-frontend/src/api/index.js | 18 + admin-frontend/src/layouts/AdminLayout.vue | 4 + admin-frontend/src/router/index.js | 8 + admin-frontend/src/views/CreditManagement.vue | 395 ++++++++++++++++++ user-frontend/src/api/index.js | 12 + user-frontend/src/layouts/UserLayout.vue | 28 +- user-frontend/src/router/index.js | 6 +- user-frontend/src/views/Credits.vue | 227 ++++++++++ user-frontend/src/views/Profile.vue | 4 +- user-frontend/src/views/Workspace.vue | 23 +- 10 files changed, 714 insertions(+), 11 deletions(-) create mode 100644 admin-frontend/src/views/CreditManagement.vue create mode 100644 user-frontend/src/views/Credits.vue diff --git a/admin-frontend/src/api/index.js b/admin-frontend/src/api/index.js index 6e99454..4c3ee60 100644 --- a/admin-frontend/src/api/index.js +++ b/admin-frontend/src/api/index.js @@ -62,4 +62,22 @@ export function listPayments(params) { return http.get('/admin/payments', { para export function getPaymentStats() { return http.get('/admin/payments/stats') } export function adminRefund(order_no, reason = '') { return http.post('/admin/payments/refund', { order_no, reason }) } +export function listCreditPackages() { return http.get('/admin/credit-packages') } +export function createCreditPackage(data) { return http.post('/admin/credit-packages', data) } +export function updateCreditPackage(id, data) { return http.put(`/admin/credit-packages/${id}`, data) } +export function deleteCreditPackage(id) { return http.delete(`/admin/credit-packages/${id}`) } + +export function listSubscriptionPlans() { return http.get('/admin/subscription-plans') } +export function createSubscriptionPlan(data) { return http.post('/admin/subscription-plans', data) } +export function updateSubscriptionPlan(id, data) { return http.put(`/admin/subscription-plans/${id}`, data) } +export function deleteSubscriptionPlan(id) { return http.delete(`/admin/subscription-plans/${id}`) } + +export function listUserCredits(page = 1, size = 20) { return http.get('/admin/user-credits', { params: { page, size } }) } +export function adjustUserCredits(userId, credits, reason = '') { + return http.post('/admin/user-credits/adjust', { user_id: userId, credits, reason }) +} + +export function listCreditConsumptions(params) { return http.get('/admin/credit-consumptions', { params }) } +export function getCreditStats() { return http.get('/admin/credit-stats') } + export default http diff --git a/admin-frontend/src/layouts/AdminLayout.vue b/admin-frontend/src/layouts/AdminLayout.vue index 80c0cd5..4018144 100644 --- a/admin-frontend/src/layouts/AdminLayout.vue +++ b/admin-frontend/src/layouts/AdminLayout.vue @@ -30,6 +30,10 @@ 支付管理 + + + 信用管理 + 配置 diff --git a/admin-frontend/src/router/index.js b/admin-frontend/src/router/index.js index f75e118..af2e550 100644 --- a/admin-frontend/src/router/index.js +++ b/admin-frontend/src/router/index.js @@ -44,6 +44,14 @@ const routes = [ { path: '', name: 'Payments', component: () => import('@/views/Payments.vue'), meta: { title: '支付管理' } }, ] }, + { + path: '/credits', + component: AdminLayout, + meta: { requiresAuth: true }, + children: [ + { path: '', name: 'Credits', component: () => import('@/views/CreditManagement.vue'), meta: { title: '信用管理' } }, + ] + }, { path: '/config', component: AdminLayout, diff --git a/admin-frontend/src/views/CreditManagement.vue b/admin-frontend/src/views/CreditManagement.vue new file mode 100644 index 0000000..3fde87c --- /dev/null +++ b/admin-frontend/src/views/CreditManagement.vue @@ -0,0 +1,395 @@ + + + diff --git a/user-frontend/src/api/index.js b/user-frontend/src/api/index.js index d882bdb..34fbd88 100644 --- a/user-frontend/src/api/index.js +++ b/user-frontend/src/api/index.js @@ -119,4 +119,16 @@ export function getUsageStats() { return http.get('/usage/stats') } export function aiChat(message, history = []) { return http.post('/ai/chat', { message, history }) } export function aiQuickQuestions() { return http.get('/ai/quick-questions') } +export function getCreditBalance() { return http.get('/credits/balance') } +export function getCreditHistory(params) { return http.get('/credits/history', { params }) } +export function getCreditPackages() { return http.get('/credits/packages') } +export function getSubscriptionPlans() { return http.get('/credits/subscription-plans') } +export function purchaseCreditPackage(packageId, payType = 'alipay') { + return http.post('/credits/purchase', { package_id: packageId, pay_type: payType }) +} +export function subscribeCreditPlan(planId, payType = 'alipay') { + return http.post('/credits/subscribe', { plan_id: planId, pay_type: payType }) +} +export function cancelCreditSubscription() { return http.post('/credits/cancel-subscription') } + export default http diff --git a/user-frontend/src/layouts/UserLayout.vue b/user-frontend/src/layouts/UserLayout.vue index b1cdcec..bb25f1a 100644 --- a/user-frontend/src/layouts/UserLayout.vue +++ b/user-frontend/src/layouts/UserLayout.vue @@ -16,13 +16,13 @@ :collapse-transition="false" @select="showMobileMenu = false" > + 发现客户 工作台 - 智能翻译 客户管理 产品库 报价单 + 智能翻译 营销素材 - 挖掘新客 智能跟进 数据分析 团队协作 @@ -39,6 +39,10 @@ {{ route.meta.title }}
+ + + {{ creditBalance }} 次 + @@ -86,7 +90,7 @@ import { ref, computed, onMounted } from 'vue' import { useRoute, useRouter } from 'vue-router' import { useAuthStore } from '@/stores/auth' -import { getUnreadCount } from '@/api' +import { getUnreadCount, getCreditBalance } from '@/api' import AiAssistant from '@/components/AiAssistant.vue' const route = useRoute() @@ -95,6 +99,22 @@ const auth = useAuthStore() const collapsed = ref(false) const showMobileMenu = ref(false) const unread = ref(0) +const creditBalance = ref(null) + +async function loadCreditBalance() { + try { + const res = await getCreditBalance() + creditBalance.value = res.balance + } catch (e) { creditBalance.value = null } +} + +onMounted(async () => { + try { + const res = await getUnreadCount() + unread.value = res.count || res || 0 + } catch { /* ignore */ } + loadCreditBalance() +}) const beianInfo = computed(() => { const hostname = window.location.hostname @@ -143,6 +163,8 @@ function handleLogout() { .footer-links a:hover { color: #1890ff; } .gongan-link { display: inline-flex; align-items: center; gap: 4px; } .gongan-icon { height: 14px; vertical-align: middle; } +.credit-btn { display: flex; align-items: center; gap: 4px; color: #e6a23c !important; font-weight: 600; } +.credit-text { font-size: 13px; } @media (max-width: 768px) { .sidebar { position: fixed; left: -220px; top: 0; bottom: 0; z-index: 1000; transition: left 0.3s; } diff --git a/user-frontend/src/router/index.js b/user-frontend/src/router/index.js index cb882d5..88fe50d 100644 --- a/user-frontend/src/router/index.js +++ b/user-frontend/src/router/index.js @@ -56,7 +56,7 @@ const routes = [ component: () => import('@/layouts/UserLayout.vue'), meta: { requiresAuth: true }, children: [ - { path: '', name: 'Discovery', component: () => import('@/views/Discovery.vue'), meta: { title: '挖掘新客' } }, + { path: '', name: 'Discovery', component: () => import('@/views/Discovery.vue'), meta: { title: '发现客户' } }, ] }, { @@ -100,11 +100,11 @@ const routes = [ ] }, { - path: '/upgrade', + path: '/credits', component: () => import('@/layouts/UserLayout.vue'), meta: { requiresAuth: true }, children: [ - { path: '', name: 'Upgrade', component: () => import('@/views/Upgrade.vue'), meta: { title: '升级会员' } }, + { path: '', name: 'Credits', component: () => import('@/views/Credits.vue'), meta: { title: '购买次数' } }, ] }, { diff --git a/user-frontend/src/views/Credits.vue b/user-frontend/src/views/Credits.vue new file mode 100644 index 0000000..32dca24 --- /dev/null +++ b/user-frontend/src/views/Credits.vue @@ -0,0 +1,227 @@ + + + + + diff --git a/user-frontend/src/views/Profile.vue b/user-frontend/src/views/Profile.vue index 66022e3..ceab703 100644 --- a/user-frontend/src/views/Profile.vue +++ b/user-frontend/src/views/Profile.vue @@ -11,8 +11,8 @@
-