feat(membership): enforce tenant subscription plans with blocked UI

Add configurable membership plans (free/plus/pro) synced to DB on boot, a
subscription guard middleware that blocks tenant endpoints on expired or
missing plans, and a MembershipBlockedView that surfaces the reason so
the admin can contact the tenant owner. Quota and brand-library reads now
honor the active plan's policy JSON and expired subscriptions.
This commit is contained in:
2026-04-18 20:56:05 +08:00
parent 9ec9314aea
commit 63667ed2d1
28 changed files with 1738 additions and 80 deletions
+16
View File
@@ -95,6 +95,22 @@ const enUS = {
defaultTestAccount: "Default account",
defaultTestPassword: "Default password",
},
membershipBlocked: {
eyebrow: "Access Paused",
title: "This tenant plan is unavailable",
reasonTrialExpired: "The free trial's 3-day page access window has ended. All business pages are now locked. Please contact an administrator to reactivate trial access.",
reasonRequired: "This tenant does not have an active plan. All business pages are now locked. Please contact an administrator.",
reasonInactive: "This tenant plan has expired or been disabled. All business pages are now locked. Please contact an administrator to restore access.",
plan: "Current Plan",
expiredAt: "Expired At",
articleLimit: "Article Limit",
companyLimit: "Company Limit",
contactAdmin: "Once the administrator reactivates access, refresh this page to continue.",
logout: "Log out",
refresh: "Check again",
refreshing: "Checking…",
stillBlocked: "Access is still blocked. Please contact your administrator before checking again.",
},
shell: {
localeLabel: "Language",
quotaTitle: "Plan & Quota",
+16
View File
@@ -95,6 +95,22 @@ const zhCN = {
defaultTestAccount: "默认测试账号",
defaultTestPassword: "默认测试密码",
},
membershipBlocked: {
eyebrow: "访问已暂停",
title: "当前租户套餐不可用",
reasonTrialExpired: "免费试用的 3 天页面可访问期已经结束,当前业务页面已全部关闭,请联系管理员重新开通试用权限。",
reasonRequired: "当前租户尚未开通有效套餐,业务页面已全部关闭,请联系管理员处理。",
reasonInactive: "当前租户套餐已失效或已停用,业务页面已全部关闭,请联系管理员恢复访问。",
plan: "当前套餐",
expiredAt: "到期时间",
articleLimit: "文章额度",
companyLimit: "公司数量",
contactAdmin: "管理员重新开通后,刷新页面即可恢复访问。",
logout: "退出登录",
refresh: "重新检查",
refreshing: "检查中…",
stillBlocked: "账户仍处于受限状态,请先联系管理员后再重试。",
},
shell: {
localeLabel: "语言",
quotaTitle: "套餐与额度",
+3
View File
@@ -12,6 +12,9 @@ const errorMessageMap: Record<string, string> = {
tenant_scope_missing: "租户上下文缺失",
query_failed: "数据读取失败",
quota_insufficient: "生成额度不足",
trial_plan_expired: "免费试用已到期,请联系管理员开通",
subscription_required: "当前租户尚未开通有效套餐,请联系管理员",
subscription_inactive: "当前租户套餐已失效,请联系管理员",
llm_unavailable: "生成服务不可用",
analyze_context_required: "请先填写品牌或模板上下文信息",
title_context_required: "请先确认品牌、关键词或竞品信息",
+19
View File
@@ -15,6 +15,14 @@ const router = createRouter({
descriptionKey: "route.login.description",
},
},
{
path: "/membership-blocked",
name: "membership-blocked",
component: () => import("@/views/MembershipBlockedView.vue"),
meta: {
requiresAuth: true,
},
},
{
path: "/",
component: () => import("@/layouts/AppShell.vue"),
@@ -223,11 +231,22 @@ router.beforeEach(async (to) => {
};
}
if (authStore.isAuthenticated && authStore.isMembershipBlocked && to.name !== "membership-blocked") {
return { name: "membership-blocked" };
}
if (to.name === "membership-blocked" && authStore.isAuthenticated && !authStore.isMembershipBlocked) {
return { name: "workspace" };
}
if (to.meta.requiresKol && !authStore.isActiveKol) {
return { name: "workspace" };
}
if (to.name === "login" && authStore.isAuthenticated) {
if (authStore.isMembershipBlocked) {
return { name: "membership-blocked" };
}
return { name: "workspace" };
}
+4
View File
@@ -65,6 +65,8 @@ export const useAuthStore = defineStore("auth", () => {
}
const isAuthenticated = computed(() => Boolean(accessToken.value && user.value));
const membership = computed(() => user.value?.membership ?? null);
const isMembershipBlocked = computed(() => Boolean(membership.value?.blocked));
const kolProfile = computed(() => user.value?.kol_profile ?? null);
const isActiveKol = computed(() => kolProfile.value?.status === "active");
@@ -74,6 +76,8 @@ export const useAuthStore = defineStore("auth", () => {
user,
initialized,
isAuthenticated,
membership,
isMembershipBlocked,
kolProfile,
isActiveKol,
bootstrap,
@@ -0,0 +1,318 @@
<script setup lang="ts">
import { LockOutlined, LogoutOutlined, ReloadOutlined } from "@ant-design/icons-vue";
import { computed, ref } from "vue";
import { useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { useAuthStore } from "@/stores/auth";
const authStore = useAuthStore();
const router = useRouter();
const { t, locale } = useI18n();
const membership = computed(() => authStore.membership);
const isRefreshing = ref(false);
const stillBlocked = ref(false);
const blockedReasonText = computed(() => {
switch (membership.value?.blocked_reason) {
case "trial_plan_expired":
return t("membershipBlocked.reasonTrialExpired");
case "subscription_required":
return t("membershipBlocked.reasonRequired");
default:
return t("membershipBlocked.reasonInactive");
}
});
const planName = computed(() => membership.value?.plan_name || membership.value?.plan_code || "--");
const articleLimit = computed(() => membership.value?.article_generation_limit ?? 0);
const companyLimit = computed(() => membership.value?.company_limit ?? 0);
const expiryText = computed(() => {
const value = membership.value?.end_at;
if (!value) {
return "--";
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return value;
}
return new Intl.DateTimeFormat(locale.value, {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
minute: "2-digit",
}).format(date);
});
async function handleLogout(): Promise<void> {
await authStore.logout();
await router.replace("/login");
}
async function handleRefresh(): Promise<void> {
if (isRefreshing.value) {
return;
}
isRefreshing.value = true;
stillBlocked.value = false;
try {
await authStore.bootstrap();
if (!authStore.isMembershipBlocked) {
await router.replace("/workspace");
} else {
stillBlocked.value = true;
}
} finally {
isRefreshing.value = false;
}
}
</script>
<template>
<main class="membership-blocked-page">
<section
class="membership-blocked-card"
role="alert"
aria-labelledby="membership-blocked-title"
aria-describedby="membership-blocked-description"
>
<div class="membership-blocked-badge" aria-hidden="true">
<LockOutlined />
</div>
<header class="membership-blocked-copy">
<p class="membership-blocked-eyebrow">{{ t("membershipBlocked.eyebrow") }}</p>
<h1 id="membership-blocked-title">{{ t("membershipBlocked.title") }}</h1>
<p id="membership-blocked-description" class="membership-blocked-description">
{{ blockedReasonText }}
</p>
</header>
<dl class="membership-blocked-grid">
<div class="membership-blocked-item">
<dt>{{ t("membershipBlocked.plan") }}</dt>
<dd>{{ planName }}</dd>
</div>
<div class="membership-blocked-item">
<dt>{{ t("membershipBlocked.expiredAt") }}</dt>
<dd>{{ expiryText }}</dd>
</div>
<div class="membership-blocked-item">
<dt>{{ t("membershipBlocked.articleLimit") }}</dt>
<dd>{{ articleLimit }}</dd>
</div>
<div class="membership-blocked-item">
<dt>{{ t("membershipBlocked.companyLimit") }}</dt>
<dd>{{ companyLimit }}</dd>
</div>
</dl>
<p class="membership-blocked-note">
{{ t("membershipBlocked.contactAdmin") }}
</p>
<p
v-if="stillBlocked"
class="membership-blocked-still"
role="status"
aria-live="polite"
>
{{ t("membershipBlocked.stillBlocked") }}
</p>
<div class="membership-blocked-actions">
<button class="secondary" type="button" @click="handleLogout">
<LogoutOutlined aria-hidden="true" />
{{ t("membershipBlocked.logout") }}
</button>
<button
class="primary"
type="button"
:disabled="isRefreshing"
:aria-busy="isRefreshing"
@click="handleRefresh"
>
<ReloadOutlined aria-hidden="true" :spin="isRefreshing" />
{{ isRefreshing ? t("membershipBlocked.refreshing") : t("membershipBlocked.refresh") }}
</button>
</div>
</section>
</main>
</template>
<style scoped>
.membership-blocked-page {
min-height: 100vh;
display: grid;
place-items: center;
padding: 32px 20px;
background:
radial-gradient(circle at top left, rgba(255, 205, 120, 0.28), transparent 30%),
radial-gradient(circle at bottom right, rgba(19, 94, 204, 0.14), transparent 34%),
linear-gradient(180deg, #fffaf0 0%, #f6f8fb 100%);
}
.membership-blocked-card {
width: min(720px, 100%);
padding: 36px;
border-radius: 28px;
background: rgba(255, 255, 255, 0.92);
border: 1px solid rgba(25, 45, 80, 0.08);
box-shadow: 0 24px 70px rgba(15, 32, 64, 0.12);
backdrop-filter: blur(18px);
}
.membership-blocked-badge {
width: 56px;
height: 56px;
display: inline-flex;
align-items: center;
justify-content: center;
border-radius: 18px;
background: linear-gradient(135deg, #ffb347 0%, #ff7f50 100%);
color: #fff;
font-size: 22px;
box-shadow: 0 14px 28px rgba(255, 127, 80, 0.25);
}
.membership-blocked-copy {
margin-top: 18px;
}
.membership-blocked-eyebrow {
margin: 0 0 10px;
font-size: 12px;
font-weight: 700;
letter-spacing: 0.14em;
text-transform: uppercase;
color: #c7642c;
}
.membership-blocked-copy h1 {
margin: 0;
font-size: clamp(30px, 5vw, 40px);
line-height: 1.08;
color: #172033;
}
.membership-blocked-description {
margin: 14px 0 0;
font-size: 16px;
line-height: 1.7;
color: #4f596d;
}
.membership-blocked-grid {
margin: 28px 0 0;
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 14px;
}
.membership-blocked-item {
margin: 0;
padding: 16px 18px;
border-radius: 18px;
background: #f7f9fc;
border: 1px solid rgba(23, 32, 51, 0.06);
}
.membership-blocked-item dt {
display: block;
margin: 0 0 8px;
font-size: 12px;
color: #6b7384;
}
.membership-blocked-item dd {
margin: 0;
color: #172033;
font-size: 18px;
font-weight: 700;
}
.membership-blocked-still {
margin: 16px 0 0;
padding: 12px 16px;
border-radius: 12px;
background: rgba(255, 127, 80, 0.12);
color: #b14a1a;
font-size: 14px;
}
.membership-blocked-actions button[disabled] {
opacity: 0.6;
cursor: not-allowed;
}
.membership-blocked-actions button[disabled]:hover {
transform: none;
}
.membership-blocked-note {
margin-top: 22px;
padding: 16px 18px;
border-radius: 18px;
background: linear-gradient(135deg, rgba(23, 92, 255, 0.08), rgba(255, 179, 71, 0.12));
color: #1f3558;
line-height: 1.7;
}
.membership-blocked-actions {
margin-top: 24px;
display: flex;
justify-content: flex-end;
gap: 12px;
}
.membership-blocked-actions button {
height: 46px;
border-radius: 14px;
border: none;
padding: 0 18px;
display: inline-flex;
align-items: center;
gap: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: transform 0.2s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}
.membership-blocked-actions button:hover {
transform: translateY(-1px);
}
.membership-blocked-actions .primary {
color: #fff;
background: linear-gradient(135deg, #135ecc 0%, #0f7ad8 100%);
box-shadow: 0 14px 28px rgba(19, 94, 204, 0.2);
}
.membership-blocked-actions .secondary {
color: #27334a;
background: #edf1f7;
}
@media (max-width: 640px) {
.membership-blocked-card {
padding: 24px;
border-radius: 22px;
}
.membership-blocked-grid {
grid-template-columns: 1fr;
}
.membership-blocked-actions {
flex-direction: column-reverse;
}
.membership-blocked-actions button {
width: 100%;
justify-content: center;
}
}
</style>