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
@@ -4,7 +4,7 @@ import { useThemeVars } from 'naive-ui';
|
||||
import { RouterLink, useRoute, useRouter } from 'vue-router';
|
||||
import MenuIconItem from './MenuIconItem.vue';
|
||||
import type { Tool, ToolCategory } from '@/tools/tools.types';
|
||||
import { PROTECTED_TOOLS } from '@/tools/license/license';
|
||||
import { PROTECTED_TOOLS, toolVisible } from '@/tools/license/license';
|
||||
|
||||
const props = withDefaults(defineProps<{ toolsByCategory?: ToolCategory[]; favoriteCategory?: ToolCategory | null }>(), { toolsByCategory: () => [], favoriteCategory: null });
|
||||
const { toolsByCategory } = toRefs(props);
|
||||
@@ -75,6 +75,7 @@ const menuOptions = computed(() => {
|
||||
.map(({ name, components }) => ({
|
||||
name,
|
||||
components: components.filter((tool) => {
|
||||
if (!toolVisible(tool.path)) return false; // 管理后台关闭显示的应用:菜单隐藏
|
||||
if (tool.path in PROTECTED_TOOLS) {
|
||||
if (!paidPaths.has(tool.path)) {
|
||||
paidPaths.add(tool.path);
|
||||
@@ -99,8 +100,9 @@ const menuOptions = computed(() => {
|
||||
|
||||
const options = [];
|
||||
// favorites first, shown as-is (user shortcuts must stay visible)
|
||||
if (props.favoriteCategory && props.favoriteCategory.components.length > 0) {
|
||||
options.push(toOption(props.favoriteCategory.name, props.favoriteCategory.components));
|
||||
const favComps = (props.favoriteCategory?.components ?? []).filter(t => toolVisible(t.path));
|
||||
if (props.favoriteCategory && favComps.length > 0) {
|
||||
options.push(toOption(props.favoriteCategory.name, favComps));
|
||||
}
|
||||
if (paidTools.length > 0) {
|
||||
options.push(toOption(PAID_GROUP_NAME, paidTools));
|
||||
|
||||
+122
-2
@@ -519,12 +519,77 @@ function recoMove(i: number, d: -1 | 1) {
|
||||
reco.value.splice(j, 0, it);
|
||||
}
|
||||
|
||||
const tab = ref<'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback'>('overview');
|
||||
// ============ 授权应用(前台显示开关 + 每日试用时长) ============
|
||||
/** relay PROTECTED_TOOLS 全量 18 项:中文名与入口类型(page=有前台页面可隐藏;api=纯服务端门禁) */
|
||||
const TOOL_META: Record<string, { name: string; kind: 'page' | 'api' }> = {
|
||||
translator: { name: '在线翻译', kind: 'page' },
|
||||
'image-ocr': { name: '图片OCR文字识别', kind: 'page' },
|
||||
'pdf-ocr': { name: 'PDF文字识别', kind: 'page' },
|
||||
'ai-retouch': { name: 'AI修图', kind: 'page' },
|
||||
'doc-convert': { name: '文档格式转换', kind: 'page' },
|
||||
'image-tools': { name: '图片工具', kind: 'page' },
|
||||
'pdf-tools': { name: 'PDF工具', kind: 'page' },
|
||||
'video-tools': { name: '视频工具', kind: 'page' },
|
||||
'audio-tools': { name: '音频工具', kind: 'page' },
|
||||
'text-to-image': { name: '文字生成图片', kind: 'page' },
|
||||
'ai-image-tools': { name: 'AI图片实验室', kind: 'page' },
|
||||
copywriting: { name: '文案工具箱', kind: 'page' },
|
||||
'screenshot-qa': { name: '截图问答', kind: 'api' },
|
||||
'video-subtitle': { name: '视频字幕提取', kind: 'api' },
|
||||
'ai-gen': { name: 'AI 生图', kind: 'page' },
|
||||
'ai-text-edit': { name: 'AI 无痕改字', kind: 'page' },
|
||||
'face-swap': { name: 'AI换脸', kind: 'page' },
|
||||
'poster-maker': { name: 'AI海报生成', kind: 'page' },
|
||||
};
|
||||
const toolsList = ref<{ slug: string; visible: boolean; trial_minutes: number }[]>([]);
|
||||
const toolsDefaultTrial = ref(30);
|
||||
const toolsSaving = ref(false);
|
||||
const toolsMsg = ref('');
|
||||
|
||||
async function loadTools() {
|
||||
toolsMsg.value = '';
|
||||
try {
|
||||
const b = await api('/admin/tools');
|
||||
if (b?.code === 200) {
|
||||
toolsList.value = b.data.tools;
|
||||
toolsDefaultTrial.value = b.data.default_trial;
|
||||
} else {
|
||||
toolsMsg.value = b?.message || '加载失败';
|
||||
}
|
||||
} catch (e: any) {
|
||||
toolsMsg.value = e?.message || '加载失败';
|
||||
}
|
||||
}
|
||||
|
||||
async function saveTools() {
|
||||
toolsSaving.value = true;
|
||||
toolsMsg.value = '';
|
||||
try {
|
||||
const body: Record<string, { visible: boolean; trial_minutes: number }> = {};
|
||||
for (const t of toolsList.value) {
|
||||
const m = Math.min(1440, Math.max(1, Math.round(Number(t.trial_minutes) || toolsDefaultTrial.value)));
|
||||
body[t.slug] = { visible: t.visible, trial_minutes: m };
|
||||
}
|
||||
const b = await api('/admin/tools', { method: 'POST', body: JSON.stringify({ tools: body }) });
|
||||
if (b?.code === 200) {
|
||||
toolsMsg.value = '已保存,前台页面刷新后生效';
|
||||
await loadTools();
|
||||
} else {
|
||||
toolsMsg.value = b?.message || '保存失败';
|
||||
}
|
||||
} catch (e: any) {
|
||||
toolsMsg.value = e?.message || '保存失败';
|
||||
} finally {
|
||||
toolsSaving.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
const tab = ref<'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback' | 'tools'>('overview');
|
||||
|
||||
// 在线人数 30s 自动刷新(切走用量页签即停)
|
||||
let usageTimer: ReturnType<typeof setInterval> | null = null;
|
||||
|
||||
function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback') {
|
||||
function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'reco' | 'feedback' | 'tools') {
|
||||
if (usageTimer) {
|
||||
clearInterval(usageTimer);
|
||||
usageTimer = null;
|
||||
@@ -543,6 +608,9 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'rec
|
||||
if (id === 'mcp') {
|
||||
loadMcpUsage();
|
||||
}
|
||||
if (id === 'tools') {
|
||||
loadTools();
|
||||
}
|
||||
if (id === 'storage') {
|
||||
loadStorage();
|
||||
}
|
||||
@@ -580,6 +648,7 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'rec
|
||||
<div class="adm-nav">
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'overview' }" @click="switchTab('overview')">📊 总览与用户</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'files' }" @click="switchTab('files')">📁 文件管理</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'tools' }" @click="switchTab('tools')">🧩 授权应用</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'usage' }" @click="switchTab('usage')">📈 使用统计</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'mcp' }" @click="switchTab('mcp')">🤖 MCP 调用</div>
|
||||
<div class="adm-nav-item" :class="{ active: tab === 'storage' }" @click="switchTab('storage')">💾 存储设置</div>
|
||||
@@ -717,6 +786,45 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'rec
|
||||
</template>
|
||||
|
||||
<!-- storage -->
|
||||
<!-- tools(授权应用:显示开关 + 试用时长) -->
|
||||
<template v-if="tab === 'tools'">
|
||||
<h3 class="adm-h3">🧩 授权应用管理 <span class="adm-sub">控制前台是否显示 + 每个功能每日免费试用时长(分钟),保存后前台刷新生效</span></h3>
|
||||
<div class="adm-card">
|
||||
<div class="adm-toolbar">
|
||||
<span class="adm-sub">共 {{ toolsList.length }} 个授权应用 · 默认试用 {{ toolsDefaultTrial }} 分钟/天</span>
|
||||
<div class="adm-actions">
|
||||
<span v-if="toolsMsg" class="adm-ok">{{ toolsMsg }}</span>
|
||||
<button class="adm-btn adm-btn-sm" :disabled="toolsSaving" @click="saveTools">{{ toolsSaving ? '保存中…' : '保存全部' }}</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="adm-tools-scroll">
|
||||
<table class="adm-table adm-tools-table">
|
||||
<thead>
|
||||
<tr><th>应用</th><th>标识</th><th>入口</th><th>前台显示</th><th>每日免费试用(分钟)</th></tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="t in toolsList" :key="t.slug">
|
||||
<td class="adm-tool-name">{{ TOOL_META[t.slug]?.name || t.slug }}</td>
|
||||
<td><code class="adm-slug">{{ t.slug }}</code></td>
|
||||
<td>{{ TOOL_META[t.slug]?.kind === 'page' ? '页面' : 'API' }}</td>
|
||||
<td>
|
||||
<label class="adm-switch" :class="{ off: !t.visible }">
|
||||
<input type="checkbox" v-model="t.visible" :disabled="TOOL_META[t.slug]?.kind !== 'page'">
|
||||
<span class="adm-switch-txt">{{ t.visible ? '显示' : '隐藏' }}</span>
|
||||
</label>
|
||||
</td>
|
||||
<td>
|
||||
<input type="number" class="adm-input adm-num" min="1" max="1440" v-model.number="t.trial_minutes">
|
||||
<span class="adm-sub">1-1440</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="adm-sub" style="margin-top:8px">「入口=API」的条目没有前台页面(仅服务端门禁),显示开关不适用;试用时长对其门禁生效。隐藏的应用从菜单、收藏、定价与首页推荐同步消失(直连地址仍可用)。</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template v-if="tab === 'storage'">
|
||||
<h3 class="adm-h3">💾 文件存储设置 <span class="adm-sub">用户上传文件与云端数据的实际存放位置</span></h3>
|
||||
<div class="adm-storage-info" v-if="storage">
|
||||
@@ -1646,4 +1754,16 @@ function switchTab(id: 'overview' | 'files' | 'usage' | 'mcp' | 'storage' | 'rec
|
||||
font-weight: 700;
|
||||
}
|
||||
}
|
||||
|
||||
/* ===== 授权应用管理(窄视口内滚,min-width+nowrap 防错行) ===== */
|
||||
.adm-tools-scroll { overflow-x: auto; }
|
||||
.adm-tools-table { min-width: 560px; }
|
||||
.adm-tools-table th { white-space: nowrap; }
|
||||
.adm-tool-name { white-space: nowrap; font-weight: 600; }
|
||||
.adm-slug { font-size: 12px; opacity: .75; }
|
||||
.adm-num { width: 92px; }
|
||||
.adm-switch { display: inline-flex; align-items: center; gap: 6px; cursor: pointer; user-select: none; }
|
||||
.adm-switch input { width: 16px; height: 16px; cursor: pointer; }
|
||||
.adm-switch.off { opacity: .6; }
|
||||
.adm-switch-txt { font-size: 13px; }
|
||||
</style>
|
||||
@@ -1,9 +1,10 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { AUTH_BASE, getMachineId, licenseState, checkAuth, PROTECTED_TOOLS } from '@/tools/license/license';
|
||||
import { computed } from 'vue';
|
||||
import { AUTH_BASE, getMachineId, licenseState, checkAuth, PROTECTED_TOOLS, toolVisible } from '@/tools/license/license';
|
||||
|
||||
/** 授权功能数量:与 pricing/侧栏同源(license.ts PROTECTED_TOOLS),新授权应用上线自动 +1 */
|
||||
const paidCount = Object.keys(PROTECTED_TOOLS).length;
|
||||
const paidCount = computed(() => Object.keys(PROTECTED_TOOLS).filter(toolVisible).length);
|
||||
|
||||
useHead({ title: '购买卡密 - IT-TOOLS-PRO' });
|
||||
|
||||
@@ -124,7 +125,7 @@ async function refreshAuth(): Promise<void> {
|
||||
authMsg.value = '正在核验授权…';
|
||||
try {
|
||||
const ok = await checkAuth();
|
||||
authMsg.value = ok ? `授权已生效,${paidCount} 个高级功能已解锁` : '卡密已发放,授权暂未刷新,请点击下方重新核验';
|
||||
authMsg.value = ok ? `授权已生效,${paidCount.value} 个高级功能已解锁` : '卡密已发放,授权暂未刷新,请点击下方重新核验';
|
||||
} catch {
|
||||
authMsg.value = '授权核验失败,请稍后重试';
|
||||
}
|
||||
|
||||
@@ -7,10 +7,12 @@ import ColoredCard from '../components/ColoredCard.vue';
|
||||
import ToolCard from '../components/ToolCard.vue';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import { useRecentTools } from '@/composable/recent-tools';
|
||||
import { toolVisible } from '@/tools/license/license';
|
||||
|
||||
// 近期新功能亮点(手动维护,新工具上线时加一条)
|
||||
// ★铁规则:每完成一批新功能/新工具,必须在这里最前面加条目(新→旧),否则首页看不到
|
||||
const NEW_FEATURES = [
|
||||
{ path: '/admin', icon: '🧩', name: '授权应用管理', desc: '管理后台新增「授权应用」页:每个授权应用可控制前台是否显示、可修改每日免费试用时长(分钟),保存后前台刷新即生效' },
|
||||
{ path: '/qrcode-generator', icon: '🕘', name: '草稿找回历史版本', desc: '右下角自动保存条新增「找回」按钮,列出该工具近 20 份保存历史(时间精确到秒),点任意一条立即恢复成那一版继续编辑' },
|
||||
{ path: '/admin', icon: '📁', name: '后台文件管理', desc: '默认聚合所有用户文件与AI生成图片,每页50条自动分页显示总记录数,图片100×100缩略图、其他文件显示类型,全部支持单独下载' },
|
||||
{ path: '/ai-gen', icon: '🗂️', name: '图片历史铁规则', desc: '所有生图功能右侧 50×50 缩略图历史竖排、点击看大图,按登录账号/机器码只看本人的,生成即保存到后台指定目录,全部功能历史最多显示100条' },
|
||||
@@ -42,6 +44,8 @@ const { recentTools } = useRecentTools();
|
||||
|
||||
// 近期新功能:静态清单(新开发功能上线时手动加一条)
|
||||
const newFeatures = ref<any[]>(NEW_FEATURES);
|
||||
/** 管理后台关闭显示的条目不出现在首页推荐 */
|
||||
const visibleNewFeatures = computed(() => newFeatures.value.filter(f => toolVisible(f.path)));
|
||||
|
||||
// 精选推荐:管理后台配置(/relay/reco),独立区块置顶显示;为空则隐藏该区块
|
||||
const recoList = ref<any[]>([]);
|
||||
@@ -287,11 +291,11 @@ function onUpdateFavoriteTools() {
|
||||
<!-- 近期新功能 -->
|
||||
<div class="nf-block">
|
||||
<div class="nf-head">
|
||||
<span class="nf-title">🆕 近期新功能 <em class="nf-count">{{ newFeatures.length }}</em></span>
|
||||
<span class="nf-title">🆕 近期新功能 <em class="nf-count">{{ visibleNewFeatures.length }}</em></span>
|
||||
<span class="nf-sub">持续更新中,登录后数据云端同步、授权跟随账号</span>
|
||||
</div>
|
||||
<div class="nf-grid">
|
||||
<RouterLink v-for="f in newFeatures" :key="f.path" :to="f.path" class="nf-card">
|
||||
<RouterLink v-for="f in visibleNewFeatures" :key="f.path" :to="f.path" class="nf-card">
|
||||
<span class="nf-icon">{{ f.icon }}</span>
|
||||
<span class="nf-body">
|
||||
<span class="nf-name">{{ f.name }} <em class="nf-badge">新</em></span>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { PROTECTED_TOOLS, getMachineId } from '@/tools/license/license';
|
||||
import { PROTECTED_TOOLS, getMachineId, toolVisible } from '@/tools/license/license';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
|
||||
useHead({ title: '授权应用 - IT-TOOLS-PRO' });
|
||||
@@ -41,7 +41,7 @@ const MARKETING: Record<string, { icon: string; points: string[] }> = {
|
||||
|
||||
/** 授权功能清单 = license.ts 的 PROTECTED_TOOLS(唯一权威源),本页零手工维护 */
|
||||
const toolStore = useToolStore();
|
||||
const paidFeatures = computed<Feature[]>(() => Object.keys(PROTECTED_TOOLS).map((path) => {
|
||||
const paidFeatures = computed<Feature[]>(() => Object.keys(PROTECTED_TOOLS).filter(toolVisible).map((path) => {
|
||||
const tool = toolStore.tools.find(t => t.path === path);
|
||||
const m = MARKETING[path];
|
||||
return {
|
||||
|
||||
@@ -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