feat(admin): 授权应用管理页——前台显示开关+按功能试用时长;补注册AI无痕改字(付费数15→16)
This commit is contained in:
1 parent
6690d1c5c4
commit
cb588071bd
9 files changed
+337
-25
No files matched your search
@@ -3,6 +3,9 @@ import {
|
||||
BUY_URL,
|
||||
PROTECTED_TOOLS,
|
||||
TRIAL_MS,
|
||||
ensureToolCfg,
|
||||
toolVisible,
|
||||
trialMsOf,
|
||||
activateCard,
|
||||
checkAuth,
|
||||
deactivateLicense,
|
||||
@@ -24,6 +27,7 @@ function goBuy(): void {
|
||||
|
||||
const displayName = computed(() => PROTECTED_TOOLS[props.path] ?? '');
|
||||
const protectedTool = computed(() => !!PROTECTED_TOOLS[props.path]);
|
||||
const paidCount = computed(() => Object.keys(PROTECTED_TOOLS).filter(toolVisible).length);
|
||||
|
||||
const now = ref(Date.now());
|
||||
const showCardInput = ref(false);
|
||||
@@ -33,8 +37,10 @@ const activateMsg = ref('');
|
||||
const copied = ref(false);
|
||||
let timer: ReturnType<typeof setInterval> | undefined;
|
||||
|
||||
const remaining = computed(() => (protectedTool.value ? remainingMs(props.path, now.value) : TRIAL_MS));
|
||||
const trialUsed = computed(() => protectedTool.value && remaining.value < TRIAL_MS);
|
||||
const limitMs = computed(() => trialMsOf(props.path) * 60 * 1000);
|
||||
const limitMin = computed(() => Math.round(limitMs.value / 60000));
|
||||
const remaining = computed(() => (protectedTool.value ? remainingMs(props.path, now.value) : limitMs.value));
|
||||
const trialUsed = computed(() => protectedTool.value && remaining.value < limitMs.value);
|
||||
const expired = computed(() => protectedTool.value && !licenseState.authorized && remaining.value <= 0);
|
||||
|
||||
const mmss = computed(() => {
|
||||
@@ -88,7 +94,7 @@ async function revokeLicense() {
|
||||
const r = await deactivateLicense();
|
||||
revokeMsg.value = r.msg;
|
||||
if (r.ok) {
|
||||
startTrial(props.path); // 回到试用:从现在起重新计 30 分钟
|
||||
startTrial(props.path); // 回到试用:按后台配置时长重新计时
|
||||
now.value = Date.now();
|
||||
}
|
||||
setTimeout(() => (revokeMsg.value = ''), 5000);
|
||||
@@ -109,6 +115,7 @@ function copyMachine() {
|
||||
|
||||
/** 每次进入受控功能页时检查授权并启动该功能的独立试用计时 */
|
||||
async function init() {
|
||||
ensureToolCfg(true); // 后台刷新显示开关/试用时长配置(异步,不阻断)
|
||||
activateMsg.value = '';
|
||||
showCardInput.value = false;
|
||||
if (!protectedTool.value) return;
|
||||
@@ -160,16 +167,16 @@ onUnmounted(() => {
|
||||
{{ displayName }} · 今日免费 <b>{{ mmss }}</b>({{ resetTag }})
|
||||
</template>
|
||||
<template v-else>
|
||||
{{ displayName }} · 今日免费 30 分钟({{ resetTag }})
|
||||
{{ displayName }} · 今日免费 {{ limitMin }} 分钟({{ resetTag }})
|
||||
</template>
|
||||
|
||||
<template v-if="!licenseState.authorized">
|
||||
<a
|
||||
:href="BUY_URL"
|
||||
class="lg-buy"
|
||||
title="买断制授权,不按次不按月;一次激活,13 个高级功能全部解锁,授权跟随账号、换电脑可恢复"
|
||||
:title="`买断制授权,不按次不按月;一次激活,${paidCount} 个高级功能全部解锁,授权跟随账号、换电脑可恢复`"
|
||||
@click.prevent="goBuy"
|
||||
>永久解锁 13 个功能</a>
|
||||
>永久解锁 {{ paidCount }} 个功能</a>
|
||||
<a href="javascript:;" class="lg-link" @click="showCardInput = !showCardInput">卡密</a>
|
||||
</template>
|
||||
</div>
|
||||
@@ -202,7 +209,7 @@ onUnmounted(() => {
|
||||
🔒 {{ displayName }} 今日免费试用已用完
|
||||
</div>
|
||||
<p class="lg-modal-desc">
|
||||
该功能今日 30 分钟免费试用已用完<template v-if="resetHint">,{{ resetHint }} 可再试</template>。购买授权后全部功能立即解锁,或输入卡密激活。
|
||||
该功能今日 {{ limitMin }} 分钟免费试用已用完<template v-if="resetHint">,{{ resetHint }} 可再试</template>。购买授权后全部功能立即解锁,或输入卡密激活。
|
||||
</p>
|
||||
|
||||
<div class="lg-modal-actions">
|
||||
|
||||
@@ -18,12 +18,67 @@ export const PROTECTED_TOOLS: Record<string, string> = {
|
||||
'/text-to-image': '文字生成图片',
|
||||
'/ai-image-lab': 'AI图片实验室',
|
||||
'/copywriting': '文案工具箱',
|
||||
'/ai-text-edit': 'AI 无痕改字',
|
||||
'/ai-gen': 'AI 生图',
|
||||
'/face-swap': 'AI换脸',
|
||||
'/poster-maker': 'AI海报生成',
|
||||
};
|
||||
|
||||
export const TRIAL_MS = 30 * 60 * 1000; // 每个功能每天免费 30 分钟
|
||||
export const TRIAL_MS = 30 * 60 * 1000; // 每个功能每天免费 30 分钟(管理后台可按功能覆盖)
|
||||
|
||||
// ====== 授权应用配置(管理后台「授权应用」页:前台显示开关 + 每日试用时长) ======
|
||||
const TOOL_CFG_KEY = 'it-tools-tool-cfg';
|
||||
export const toolCfg = reactive({
|
||||
loaded: false,
|
||||
visible: {} as Record<string, boolean>,
|
||||
trial_minutes: {} as Record<string, number>,
|
||||
});
|
||||
|
||||
function applyToolCfg(j: any): void {
|
||||
if (!j || typeof j !== 'object') return;
|
||||
toolCfg.visible = { ...(j.visible || {}) };
|
||||
toolCfg.trial_minutes = { ...(j.trial_minutes || {}) };
|
||||
toolCfg.loaded = true;
|
||||
}
|
||||
|
||||
/** 拉取管理后台配置;失败静默(回落缓存或默认值),不阻断功能 */
|
||||
export function ensureToolCfg(force = false): void {
|
||||
if (toolCfg.loaded && !force) return;
|
||||
fetch('/relay/tool-config')
|
||||
.then(r => r.json())
|
||||
.then((j) => {
|
||||
if (j?.code === 200) {
|
||||
applyToolCfg(j.data);
|
||||
try { localStorage.setItem(TOOL_CFG_KEY, JSON.stringify(j.data)); } catch { /* ignore */ }
|
||||
}
|
||||
})
|
||||
.catch(() => { /* 静默:网络失败用缓存/默认 */ });
|
||||
}
|
||||
|
||||
// 页面加载即用缓存兜底 + 后台刷新(SPA 模块顶层执行)
|
||||
try {
|
||||
const cached = JSON.parse(localStorage.getItem(TOOL_CFG_KEY) ?? 'null');
|
||||
if (cached) applyToolCfg(cached);
|
||||
} catch { /* ignore */ }
|
||||
if (typeof window !== 'undefined') ensureToolCfg(true);
|
||||
|
||||
/** path → relay 侧标识(配置/X-Tool key;仅 AI图片实验室两头不同名) */
|
||||
function slugOf(path: string): string {
|
||||
const s = path.replace(/^\/+/, '');
|
||||
return s === 'ai-image-lab' ? 'ai-image-tools' : s;
|
||||
}
|
||||
|
||||
/** 管理后台开关:该路径前台是否显示(未配置=显示) */
|
||||
export function toolVisible(path: string): boolean {
|
||||
return toolCfg.visible[slugOf(path)] !== false;
|
||||
}
|
||||
|
||||
/** 管理后台配置:该功能每日免费试用时长(分钟;未配置=默认 30) */
|
||||
export function trialMsOf(path: string): number {
|
||||
const n = toolCfg.trial_minutes[slugOf(path)];
|
||||
return typeof n === 'number' && n >= 1 ? n : TRIAL_MS / 60000;
|
||||
}
|
||||
|
||||
const DAY_MS = 24 * 60 * 60 * 1000;
|
||||
const TZ_OFFSET_MS = 8 * 60 * 60 * 1000; // 北京时间 UTC+8 —— 重置对齐自然日 0 点
|
||||
|
||||
@@ -78,12 +133,13 @@ export function startTrial(path: string): void {
|
||||
|
||||
export function remainingMs(path: string, now: number): number {
|
||||
const start = getTrialStart(path);
|
||||
const limit = trialMsOf(path) * 60 * 1000; // 管理后台可按功能覆盖试用时长
|
||||
if (start === null) {
|
||||
return TRIAL_MS; // 尚未开始计时
|
||||
return limit; // 尚未开始计时
|
||||
}
|
||||
// 起点不早于今天 0 点:昨天的起点在跨天后自动失效
|
||||
const s = Math.max(start, todayStartOf(now));
|
||||
return Math.max(0, TRIAL_MS - (now - s));
|
||||
return Math.max(0, limit - (now - s));
|
||||
}
|
||||
|
||||
/** 下一次重置时刻(恒为次日 00:00 北京时间);未开始计时返回 null */
|
||||
|
||||
Reference in new issue
Block a user