优化支付功能

This commit is contained in:
2026-09-16 14:28:07 +08:00
parent ac14452cae
commit 605c2a569f
19 changed files with 1020 additions and 479 deletions
+10 -2
View File
@@ -10,6 +10,7 @@
"dependencies": {
"@element-plus/icons-vue": "^2.3.2",
"@turbodocx/html-to-docx": "^1.22.2",
"@types/qrcode": "^1.5.6",
"@umoteam/editor": "^10.2.1",
"axios": "^1.13.1",
"chart": "^0.1.2",
@@ -2455,7 +2456,6 @@
"version": "24.10.14",
"resolved": "https://registry.npmmirror.com/@types/node/-/node-24.10.14.tgz",
"integrity": "sha512-OowOUbD1lBCOFIPOZ8xnMIhgqA4sCutMiYOmPHL1PTLt5+y1XA+g2+yC9OOyz8p+deMZqPZLxfMjYIfrKsPeFg==",
"dev": true,
"license": "MIT",
"dependencies": {
"undici-types": "~7.16.0"
@@ -2467,6 +2467,15 @@
"integrity": "sha512-VWDCbrLeVXJM9fihYodcLiIv0ku+AlOa/TQ1SvYOaBuyrSKgEcro95LJyIsJ4vSo6BXIxOKxiJAat04CmST9Fw==",
"license": "MIT"
},
"node_modules/@types/qrcode": {
"version": "1.5.6",
"resolved": "https://registry.npmmirror.com/@types/qrcode/-/qrcode-1.5.6.tgz",
"integrity": "sha512-te7NQcV2BOvdj2b1hCAHzAoMNuj65kNBMz0KBaxM6c3VGBOhU0dURQKOtH8CFNI/dsKkwlv32p26qYQTWoB5bw==",
"license": "MIT",
"dependencies": {
"@types/node": "*"
}
},
"node_modules/@types/raf": {
"version": "3.4.3",
"resolved": "https://registry.npmmirror.com/@types/raf/-/raf-3.4.3.tgz",
@@ -8193,7 +8202,6 @@
"version": "7.16.0",
"resolved": "https://registry.npmmirror.com/undici-types/-/undici-types-7.16.0.tgz",
"integrity": "sha512-Zz+aZWSj8LE6zoxD+xrjh4VfkIG8Ya6LvYkZqtUQGJPZjYl53ypCaUwWqo7eI0x66KBGeRo+mlBEkMSeSZ38Nw==",
"dev": true,
"license": "MIT"
},
"node_modules/unimport": {
+1
View File
@@ -11,6 +11,7 @@
"dependencies": {
"@element-plus/icons-vue": "^2.3.2",
"@turbodocx/html-to-docx": "^1.22.2",
"@types/qrcode": "^1.5.6",
"@umoteam/editor": "^10.2.1",
"axios": "^1.13.1",
"chart": "^0.1.2",
+30
View File
@@ -54,3 +54,33 @@ export function getPaymentChannels() {
method: "get",
});
}
/*************************************************
* 租户端「套餐购买」相关接口
*************************************************/
/** 可购买套餐列表(仅启用的套餐) */
export function getPackageList(params) {
return request({
url: "/backend/package/list",
method: "get",
params,
});
}
/** 按套餐编码取详情 */
export function getPackageDetailByCode(code) {
return request({
url: `/backend/package/detail/${code}`,
method: "get",
});
}
/** 套餐下单(channel 为空表示线下/待平台开通) */
export function createPackageOrder(data) {
return request({
url: "/backend/package/order/create",
method: "post",
data,
});
}
+2
View File
@@ -59,6 +59,7 @@ function nestedMenuToRoute(menu, layoutAbsPath) {
title: menu.title,
icon: menu.icon,
id: menu.id,
code: menu.code || menu.module_code,
componentPath: menu.component_path,
};
@@ -142,6 +143,7 @@ export function convertMenusToRoutes(menus, parentPath = '') {
title: menu.title,
icon: menu.icon,
id: menu.id,
code: menu.code || menu.module_code,
componentPath: menu.component_path,
};
+7
View File
@@ -164,6 +164,13 @@ const staticRoutes = [
component: () => import("@/views/product/index.vue"),
meta: { requiresAuth: true, title: "产品购买", isStandalone: true }
},
// 套餐购买列表页:独立于 Main 框架展示
{
path: "/packages",
name: "PackageList",
component: () => import("@/views/package/list.vue"),
meta: { requiresAuth: true, title: "套餐购买", isStandalone: true }
},
{
path: "/:pathMatch(.*)*",
name: "NotFound",
+14 -31
View File
@@ -89,7 +89,7 @@
<template v-else>
<div class="card-locked">
<el-icon class="lock-icon"><Lock /></el-icon>
<p class="lock-tip">请购买套餐后使用</p>
<p class="lock-tip">请购买后使用</p>
</div>
</template>
</div>
@@ -99,9 +99,9 @@
type="primary"
link
class="buy-btn"
@click.stop="handleBuyPackage(module)"
@click.stop="handleBuyProduct(module)"
>
购买套餐
购买
</el-button>
</template>
</div>
@@ -134,7 +134,7 @@
<template v-else>
<div class="card-locked">
<el-icon class="lock-icon"><Lock /></el-icon>
<p class="lock-tip">请购买套餐后使用</p>
<p class="lock-tip">请购买后使用</p>
</div>
</template>
</div>
@@ -144,9 +144,9 @@
type="primary"
link
class="buy-btn"
@click.stop="handleBuyPackage(module)"
@click.stop="handleBuyProduct(module)"
>
购买套餐
购买
</el-button>
</template>
</div>
@@ -179,7 +179,7 @@
<template v-else>
<div class="card-locked">
<el-icon class="lock-icon"><Lock /></el-icon>
<p class="lock-tip">请购买套餐后使用</p>
<p class="lock-tip">请购买后使用</p>
</div>
</template>
</div>
@@ -189,9 +189,9 @@
type="primary"
link
class="buy-btn"
@click.stop="handleBuyPackage(module)"
@click.stop="handleBuyProduct(module)"
>
购买套餐
购买
</el-button>
</template>
</div>
@@ -227,7 +227,6 @@ import {
Moon,
OfficeBuilding,
Lock,
Lock,
} from "@element-plus/icons-vue";
import { getTenantList } from "@/api/modules";
@@ -346,27 +345,11 @@ const tenantName = computed(() => authStore.user?.tenant_name || "");
// 当前租户生效套餐名称(用于未开通提示)
const packageName = ref("");
// 套餐购买链接(平台端配置,为空时点击「购买」仅提示联系管理员)
const purchaseUrl = ref("");
// 套餐未开通模块:不跳转,提示购买套餐后使用
function showLockedTip(module: ModuleItem) {
const pkg = packageName.value ? `「${packageName.value}」` : "当前";
ElMessageBox.alert(
`${pkg}套餐未包含「${module.name}」功能模块,请购买或升级套餐后使用。如有疑问请联系平台管理员。`,
"功能未开通",
{
confirmButtonText: "我知道了",
type: "warning",
customClass: "module-locked-tip"
}
).catch(() => {});
}
// 处理导航跳转
function handleNavigate(module: ModuleItem) {
if (module.enabled === false) {
ElMessage.warning(`「${module.name}」暂未开通,请先购买对应套餐`);
ElMessage.warning(`「${module.name}」暂未开通,请先购买对应功能`);
return;
}
@@ -378,10 +361,10 @@ function handleNavigate(module: ModuleItem) {
if (targetPath) router.push(targetPath);
}
// 未开通功能 → 引导购买套餐
function handleBuyPackage(module: ModuleItem) {
ElMessage.info(`购买「${module.name}」套餐功能 —— 请联系管理员或前往平台套餐中心`);
// TODO: 未来接入购买页面后 router.push(...) 到对应套餐购买界面
// 未开通功能 → 跳转单品购买详情页(对应平台的产品定价配置)
function handleBuyProduct(module: ModuleItem) {
const code = module.code || module.path.replace(/^\/+/, "").replace(/\//g, "-");
router.push(`/product/${code}`);
}
// 刷新菜单
+32 -4
View File
@@ -6,9 +6,10 @@
</div>
<div class="locked-message">功能未开通</div>
<div class="locked-desc">
当前套餐未包含<template v-if="moduleName">「{{ moduleName }}」</template>功能模块,请联系管理员升级套餐后使用。
当前未开通<template v-if="moduleName">「{{ moduleName }}」</template>功能,请购买或联系管理员开通后使用。
</div>
<div class="locked-actions">
<a href="javascript:void(0)" class="buy-package-btn" @click.prevent="goBuyProduct">立即购买</a>
<a href="javascript:void(0)" class="back-home-btn" @click.prevent="backToHome">返回首页</a>
</div>
</div>
@@ -27,6 +28,15 @@ const moduleName = computed(() => route.meta?.title || "");
const backToHome = () => {
router.push("/home");
};
const goBuyProduct = () => {
const code = route.meta?.code || route.path.replace(/^\/+/, "").split("/")[0] || "";
if (code) {
router.push(`/product/${code}`);
} else {
router.push("/home");
}
};
</script>
<style scoped>
@@ -77,19 +87,37 @@ const backToHome = () => {
}
.locked-actions {
display: flex;
gap: 12px;
justify-content: center;
flex-wrap: wrap;
margin-bottom: 4px;
}
.buy-package-btn,
.back-home-btn {
display: inline-block;
background: linear-gradient(90deg, #3973ff 0%, #6a82fb 100%);
color: #fff;
padding: 10px 36px;
border-radius: 24px;
font-size: 15px;
text-decoration: none;
font-weight: 500;
transition: opacity 0.2s;
transition: opacity 0.2s, transform 0.2s;
}
.buy-package-btn {
background: linear-gradient(90deg, #f56c6c 0%, #f78979 100%);
color: #fff;
}
.buy-package-btn:hover {
opacity: 0.9;
transform: translateY(-1px);
}
.back-home-btn {
background: linear-gradient(90deg, #3973ff 0%, #6a82fb 100%);
color: #fff;
}
.back-home-btn:hover {
+472
View File
@@ -0,0 +1,472 @@
<template>
<div class="package-list-page">
<!-- 顶部栏 -->
<div class="page-top">
<div class="toolbar">
<div class="toolbar-left">
<el-button link class="back-btn" @click="goHome">
<el-icon><ArrowLeft /></el-icon>
返回
</el-button>
<span v-if="tenantName" class="tenant-name">
<el-icon><OfficeBuilding /></el-icon>
{{ tenantName }}
</span>
</div>
<div class="toolbar-right">
<el-button link @click="ordersVisible = true">我的订单</el-button>
</div>
</div>
</div>
<div class="page-body">
<el-skeleton v-if="loading" :rows="6" animated />
<div v-else class="package-grid">
<el-card
v-for="pkg in packages"
:key="pkg.id"
class="package-card"
shadow="hover"
>
<div class="card-header">
<div class="header-main">
<h3 class="package-name">{{ pkg.name }}</h3>
<el-tag size="small" type="info" effect="plain">{{ pkg.code }}</el-tag>
</div>
<div class="package-price">
<span class="price-symbol">¥</span>
<span class="price-value">{{ Number(pkg.price || 0).toFixed(2) }}</span>
<span class="price-unit">/ {{ durationText(pkg.duration_days) }}</span>
</div>
</div>
<div class="card-divider"></div>
<!-- 功能模块 -->
<div v-if="pkg.modules && pkg.modules.length > 0" class="package-features">
<span class="feature-label">包含功能:</span>
<el-tag
v-for="m in pkg.modules"
:key="m.module_code"
size="small"
effect="plain"
class="feature-tag"
>
{{ m.module_name || m.module_code }}
</el-tag>
</div>
<!-- 用户数配额 -->
<div class="package-quota">
<el-icon :size="14"><User /></el-icon>
<span>用户数上限:{{ pkg.user_quota || 20 }} 人</span>
<el-tooltip
v-if="pkg.extra_user_price"
content="超出上限后,按单价增购"
placement="top"
>
<el-icon :size="14" class="extra-price-icon"><InfoFilled /></el-icon>
</el-tooltip>
</div>
<!-- 备注 -->
<p v-if="pkg.remark" class="package-remark">{{ pkg.remark }}</p>
<!-- 购买按钮 -->
<div class="card-footer">
<el-button
type="primary"
size="large"
:loading="buyingIds[pkg.id]"
@click="handleBuy(pkg)"
class="buy-btn"
>
立即购买
</el-button>
</div>
</el-card>
</div>
<div v-if="!loading && packages.length === 0" class="empty-state">
<el-icon :size="64"><Box /></el-icon>
<p class="empty-text">暂无可购买套餐</p>
<p class="empty-tip">请联系平台管理员配置套餐后购买</p>
<el-button type="primary" @click="goHome">返回首页</el-button>
</div>
</div>
<!-- 我的订单 -->
<el-dialog v-model="ordersVisible" title="我的订单" width="720px">
<el-table :data="myOrders" size="small" v-loading="ordersLoading">
<el-table-column prop="order_no" label="订单号" min-width="160" show-overflow-tooltip />
<el-table-column prop="product_name" label="套餐" min-width="160" show-overflow-tooltip />
<el-table-column label="金额" width="100" align="center">
<template #default="{ row }">¥{{ Number(row.amount || 0).toFixed(2) }}</template>
</el-table-column>
<el-table-column label="状态" width="100" align="center">
<template #default="{ row }">
<el-tag :type="orderStatusType(row.status)" size="small">
{{ orderStatusText(row.status) }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="create_time" label="下单时间" width="170" align="center" />
</el-table>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { computed, onMounted, ref } from "vue";
import { useRouter } from "vue-router";
import { ElMessage } from "element-plus";
import { ArrowLeft, OfficeBuilding, Box, User, InfoFilled } from "@element-plus/icons-vue";
import { useAuthStore } from "@/stores/auth";
import {
getPackageList,
createPackageOrder,
getProductOrderStatus,
getMyProductOrders,
getPaymentChannels,
} from "@/api/product";
const router = useRouter();
const authStore = useAuthStore();
const loading = ref(false);
const packages = ref<any[]>([]);
const buyingIds = ref<Record<string, boolean>>({});
const ordersVisible = ref(false);
const myOrders = ref<any[]>([]);
const ordersLoading = ref(false);
const tenantName = computed(() => authStore.user?.tenant_name || "");
const durationText = (days: number) => {
if (!days) return "年";
if (days === 365) return "年";
if (days === 30) return "月";
if (days === 90) return "季";
return `${days}天`;
};
const orderStatusText = (s: string) =>
({ pending: "待支付", paid: "已支付", activated: "已开通", closed: "已关闭" }[s] || s);
const orderStatusType = (s: string) =>
({ pending: "warning", paid: "primary", activated: "success", closed: "info" }[s] || "info");
const goHome = () => router.push("/home");
const loadPackages = async () => {
loading.value = true;
try {
const res = await getPackageList();
packages.value = res.code === 200 && res.data ? res.data.list || [] : [];
} catch {
packages.value = [];
} finally {
loading.value = false;
}
};
const loadMyOrders = async () => {
ordersLoading.value = true;
try {
const res = await getMyProductOrders();
if (res.code === 200) myOrders.value = res.data?.list || [];
} catch {
myOrders.value = [];
} finally {
ordersLoading.value = false;
}
};
const handleBuy = async (pkg: any) => {
buyingIds.value[pkg.id] = true;
try {
// 先获取可用支付渠道
const channelRes = await getPaymentChannels();
const channels = channelRes.code === 200 ? channelRes.data?.list || [] : [];
const channel = channels.length > 0 ? channels[0].channel : "";
const res = await createPackageOrder({
package_code: pkg.code,
channel,
pay_type: "",
});
if (res.code !== 200) {
ElMessage.error(res.msg || "下单失败");
return;
}
const orderNo = res.data?.order_no || "";
const payParams = res.data?.pay_params || null;
const offline = res.data?.offline === true;
if (offline) {
ElMessage.success("购买申请已提交,请等待平台确认开通");
loadMyOrders();
return;
}
// 在线支付:复用产品购买的支付弹窗逻辑
// 这里简单跳转到产品购买页的支付流程,或直接展示支付二维码
// 为简化,直接用 orderNo 轮询状态
ElMessage.success("下单成功,请完成支付");
startPolling(orderNo);
} catch (e: any) {
ElMessage.error(e?.message || "下单失败");
} finally {
buyingIds.value[pkg.id] = false;
}
};
let pollTimer: any = null;
const startPolling = (orderNo: string) => {
if (pollTimer) clearInterval(pollTimer);
pollTimer = setInterval(() => {
checkOrder(orderNo, true);
}, 5000);
// 立即检查一次
checkOrder(orderNo, true);
};
const stopPolling = () => {
if (pollTimer) {
clearInterval(pollTimer);
pollTimer = null;
}
};
const checkOrder = async (orderNo: string, silent = false) => {
try {
const res = await getProductOrderStatus(orderNo);
if (res.code === 200 && res.data) {
const status = res.data.status;
if (status === "activated") {
stopPolling();
ElMessage.success("购买成功,套餐已开通");
loadMyOrders();
return;
}
if (status === "paid") {
if (!silent) ElMessage.info("已支付,等待平台开通…");
return;
}
if (!silent) ElMessage.info("尚未检测到支付成功,请确认已完成支付");
}
} catch {
if (!silent) ElMessage.error("查询订单失败");
}
};
watch(ordersVisible, (v) => {
if (v) loadMyOrders();
});
onMounted(() => {
loadPackages();
});
import { watch } from "vue";
</script>
<style scoped lang="less">
.package-list-page {
min-height: 100vh;
background: #f5f7fa;
display: flex;
flex-direction: column;
}
.page-top {
background: #fff;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
position: sticky;
top: 0;
z-index: 100;
.toolbar {
max-width: 1200px;
margin: 0 auto;
padding: 10px 24px;
display: flex;
align-items: center;
justify-content: space-between;
.toolbar-left {
display: flex;
align-items: center;
gap: 12px;
.tenant-name {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 14px;
color: #606266;
}
}
}
}
.page-body {
flex: 1;
width: 100%;
max-width: 1200px;
margin: 0 auto;
padding: 24px;
}
.package-grid {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
gap: 20px;
}
.package-card {
display: flex;
flex-direction: column;
height: 100%;
transition: transform 0.2s, box-shadow 0.2s;
&:hover {
transform: translateY(-4px);
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.1);
}
.card-header {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 16px;
padding-bottom: 12px;
border-bottom: 1px solid #ebeef5;
.header-main {
flex: 1;
min-width: 0;
.package-name {
margin: 0 0 8px;
font-size: 18px;
font-weight: 600;
color: #1a1a2e;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
}
.package-price {
display: flex;
align-items: baseline;
gap: 2px;
flex-shrink: 0;
padding-top: 4px;
.price-symbol {
font-size: 16px;
color: #f56c6c;
}
.price-value {
font-size: 28px;
font-weight: 700;
color: #f56c6c;
}
.price-unit {
font-size: 13px;
color: #909399;
margin-left: -4px;
}
}
}
.card-divider {
margin: 0 -20px 12px;
border-bottom: 1px solid #f0f0f0;
}
.package-features {
display: flex;
flex-wrap: wrap;
align-items: center;
gap: 6px;
margin-bottom: 10px;
.feature-label {
font-size: 12px;
color: #909399;
}
.feature-tag {
white-space: nowrap;
}
}
.package-quota {
display: inline-flex;
align-items: center;
gap: 4px;
font-size: 13px;
color: #606266;
margin-bottom: 10px;
.extra-price-icon {
color: #909399;
cursor: help;
}
}
.package-remark {
font-size: 12px;
color: #909399;
line-height: 1.6;
margin: 0 0 16px;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
.card-footer {
margin-top: auto;
padding-top: 12px;
border-top: 1px solid #ebeef5;
.buy-btn {
width: 100%;
}
}
}
.empty-state {
text-align: center;
padding: 80px 20px;
color: #c0c4cc;
.empty-text {
font-size: 18px;
color: #606266;
}
.empty-tip {
font-size: 14px;
color: #909399;
margin-bottom: 20px;
}
}
@media (max-width: 768px) {
.page-body {
padding: 16px 12px;
}
.package-grid {
grid-template-columns: 1fr;
}
}
</style>