- 新增 /buy 支付页:读本机机器码、列本项目可售套餐、支付宝/微信/QQ钱包、优惠码选填; 拉起收银台后本页留守轮询,支付成功显示卡密并自动核验授权 - 购买入口改造:顶栏「永久解锁 13 个功能」、锁定弹窗「购买授权」、授权应用页 「前往购买卡密」三处统一跳转站内 /buy(原跳外部 auth.88531.cn/#/shop) - CardAuth 后端:订单支付完成时补发卡密写回订单(原带机器码下单只建授权不发卡) - CHANGELOG 新增 Version 2026.11.11-it-tools-pro
433 lines
11 KiB
Vue
433 lines
11 KiB
Vue
<script setup lang="ts">
|
||
import {
|
||
BUY_URL,
|
||
PROTECTED_TOOLS,
|
||
TRIAL_MS,
|
||
activateCard,
|
||
checkAuth,
|
||
deactivateLicense,
|
||
getMachineId,
|
||
licenseState,
|
||
remainingMs,
|
||
startTrial,
|
||
trialResetHint,
|
||
} from './license';
|
||
|
||
const props = defineProps<{ path: string }>();
|
||
|
||
const router = useRouter();
|
||
|
||
/** 跳转到站内支付页 /buy(未授权状态下所有购买入口统一走这里) */
|
||
function goBuy(): void {
|
||
router.push('/buy');
|
||
}
|
||
|
||
const displayName = computed(() => PROTECTED_TOOLS[props.path] ?? '');
|
||
const protectedTool = computed(() => !!PROTECTED_TOOLS[props.path]);
|
||
|
||
const now = ref(Date.now());
|
||
const showCardInput = ref(false);
|
||
const cardKey = ref('');
|
||
const contactQq = ref('');
|
||
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 expired = computed(() => protectedTool.value && !licenseState.authorized && remaining.value <= 0);
|
||
|
||
const mmss = computed(() => {
|
||
const s = Math.ceil(remaining.value / 1000);
|
||
const m = Math.floor(s / 60);
|
||
const sec = s % 60;
|
||
return `${String(m).padStart(2, '0')}:${String(sec).padStart(2, '0')}`;
|
||
});
|
||
|
||
const urgency = computed(() => {
|
||
if (remaining.value <= 5 * 60 * 1000) return 'danger';
|
||
if (remaining.value <= 15 * 60 * 1000) return 'warn';
|
||
return 'normal';
|
||
});
|
||
|
||
/** 本轮已用完时的下一轮重置时刻提示(如「明天 14:23」) */
|
||
const resetHint = computed(() => (protectedTool.value ? trialResetHint(props.path, now.value) : ''));
|
||
|
||
/** 浮条上的重置提示:重置恒为次日 0 点;临近耗尽时把具体时刻显出来 */
|
||
const resetTag = computed(() => {
|
||
if (remaining.value <= 5 * 60 * 1000 && resetHint.value) return `${resetHint.value} 重置`;
|
||
return '每日 0 点重置';
|
||
});
|
||
|
||
async function submitCard() {
|
||
if (licenseState.authorized
|
||
&& !window.confirm('将撤销本机当前授权并用新卡密激活,确定换卡?')) {
|
||
return;
|
||
}
|
||
const replacing = licenseState.authorized;
|
||
const r = await activateCard(cardKey.value, contactQq.value, replacing);
|
||
activateMsg.value = r.msg;
|
||
if (r.ok) {
|
||
showCardInput.value = false;
|
||
cardKey.value = '';
|
||
if (replacing) {
|
||
checkAuth(); // 换卡后刷新授权状态
|
||
}
|
||
}
|
||
}
|
||
|
||
const revokeMsg = ref('');
|
||
const revoking = ref(false);
|
||
|
||
async function revokeLicense() {
|
||
if (!window.confirm('确定撤销本机授权?撤销后本机回到免费试用状态,重新使用需再输入卡密激活。')) {
|
||
return;
|
||
}
|
||
revoking.value = true;
|
||
try {
|
||
const r = await deactivateLicense();
|
||
revokeMsg.value = r.msg;
|
||
if (r.ok) {
|
||
startTrial(props.path); // 回到试用:从现在起重新计 30 分钟
|
||
now.value = Date.now();
|
||
}
|
||
setTimeout(() => (revokeMsg.value = ''), 5000);
|
||
}
|
||
finally {
|
||
revoking.value = false;
|
||
}
|
||
}
|
||
|
||
function copyMachine() {
|
||
try {
|
||
navigator.clipboard?.writeText(getMachineId());
|
||
copied.value = true;
|
||
setTimeout(() => (copied.value = false), 1500);
|
||
}
|
||
catch { /* ignore */ }
|
||
}
|
||
|
||
/** 每次进入受控功能页时检查授权并启动该功能的独立试用计时 */
|
||
async function init() {
|
||
activateMsg.value = '';
|
||
showCardInput.value = false;
|
||
if (!protectedTool.value) return;
|
||
const ok = await checkAuth();
|
||
if (!ok) {
|
||
startTrial(props.path); // 未授权:开始/续计该功能 30 分钟免费时长
|
||
}
|
||
now.value = Date.now();
|
||
}
|
||
|
||
onMounted(() => {
|
||
init();
|
||
timer = setInterval(() => {
|
||
now.value = Date.now();
|
||
}, 1000);
|
||
// 登录/登出后重新检查授权:换电脑登录已授权账号后,立即解除未授权提示
|
||
window.addEventListener('it-tools-auth-changed', init);
|
||
});
|
||
|
||
onBeforeUnmount(() => {
|
||
window.removeEventListener('it-tools-auth-changed', init);
|
||
});
|
||
|
||
// 跨工具路由复用:路径变化时重新走授权检查
|
||
watch(() => props.path, init);
|
||
|
||
onUnmounted(() => {
|
||
if (timer) clearInterval(timer);
|
||
});
|
||
</script>
|
||
|
||
<template>
|
||
<template v-if="protectedTool">
|
||
<!-- ===== floating status bar (bottom-right, no layout impact) ===== -->
|
||
<div
|
||
v-if="!expired"
|
||
class="lg-float"
|
||
:class="{ ok: licenseState.authorized, warn: !licenseState.authorized && trialUsed && urgency === 'warn', danger: !licenseState.authorized && trialUsed && urgency === 'danger' }"
|
||
>
|
||
<span class="lg-dot" />
|
||
<template v-if="licenseState.authorized">
|
||
{{ displayName }} · 已授权
|
||
<a href="javascript:;" class="lg-link" @click="showCardInput = !showCardInput">换卡密</a>
|
||
<a href="javascript:;" class="lg-link" :class="{ disabled: revoking }" @click="revokeLicense">
|
||
{{ revoking ? '撤销中…' : '撤销' }}
|
||
</a>
|
||
</template>
|
||
<template v-else-if="trialUsed">
|
||
{{ displayName }} · 今日免费 <b>{{ mmss }}</b>({{ resetTag }})
|
||
</template>
|
||
<template v-else>
|
||
{{ displayName }} · 今日免费 30 分钟({{ resetTag }})
|
||
</template>
|
||
|
||
<template v-if="!licenseState.authorized">
|
||
<a
|
||
:href="BUY_URL"
|
||
class="lg-buy"
|
||
title="买断制授权,不按次不按月;一次激活,13 个高级功能全部解锁,授权跟随账号、换电脑可恢复"
|
||
@click.prevent="goBuy"
|
||
>永久解锁 13 个功能</a>
|
||
<a href="javascript:;" class="lg-link" @click="showCardInput = !showCardInput">卡密</a>
|
||
</template>
|
||
</div>
|
||
|
||
<!-- ===== inline card input ===== -->
|
||
<div v-if="showCardInput && !expired" class="lg-cardbar">
|
||
<input
|
||
v-model="cardKey"
|
||
class="lg-input"
|
||
placeholder="卡密,如 CA-XXXX-XXXX-XXXX"
|
||
@keyup.enter="submitCard"
|
||
>
|
||
<input
|
||
v-model="contactQq"
|
||
class="lg-input lg-input-qq"
|
||
placeholder="联系QQ(选填)"
|
||
@keyup.enter="submitCard"
|
||
>
|
||
<c-button size="small" type="primary" :disabled="licenseState.activating" @click="submitCard">
|
||
{{ licenseState.activating ? '激活中…' : '激活' }}
|
||
</c-button>
|
||
<span v-if="activateMsg" class="lg-msg" :class="{ err: !licenseState.activateSuccess }">{{ activateMsg }}</span>
|
||
<a href="javascript:;" class="lg-link" @click="showCardInput = false">收起</a>
|
||
</div>
|
||
|
||
<!-- ===== lock overlay when trial expired ===== -->
|
||
<div v-if="expired" class="lg-overlay">
|
||
<div class="lg-modal">
|
||
<div class="lg-modal-title">
|
||
🔒 {{ displayName }} 今日免费试用已用完
|
||
</div>
|
||
<p class="lg-modal-desc">
|
||
该功能今日 30 分钟免费试用已用完<template v-if="resetHint">,{{ resetHint }} 可再试</template>。购买授权后全部功能立即解锁,或输入卡密激活。
|
||
</p>
|
||
|
||
<div class="lg-modal-actions">
|
||
<c-button type="primary" @click="goBuy">
|
||
购买授权
|
||
</c-button>
|
||
<c-button @click="showCardInput = !showCardInput">
|
||
输入卡密
|
||
</c-button>
|
||
<c-button @click="router.push('/')">
|
||
返回免费功能
|
||
</c-button>
|
||
</div>
|
||
|
||
<div v-if="showCardInput" class="lg-modal-form">
|
||
<input
|
||
v-model="cardKey"
|
||
class="lg-input"
|
||
placeholder="卡密,如 CA-XXXX-XXXX-XXXX"
|
||
@keyup.enter="submitCard"
|
||
>
|
||
<input
|
||
v-model="contactQq"
|
||
class="lg-input"
|
||
placeholder="联系QQ(选填)"
|
||
@keyup.enter="submitCard"
|
||
>
|
||
<c-button type="primary" :disabled="licenseState.activating" @click="submitCard">
|
||
{{ licenseState.activating ? '激活中…' : '立即激活' }}
|
||
</c-button>
|
||
</div>
|
||
<div v-if="activateMsg" class="lg-msg modal-msg" :class="{ err: !licenseState.activateSuccess }">
|
||
{{ activateMsg }}
|
||
</div>
|
||
|
||
<div class="lg-modal-foot">
|
||
机器码:<code @click="copyMachine">{{ copied ? '已复制 ✓' : getMachineId() }}</code>
|
||
<div class="lg-hint">
|
||
购买时填 MACHINE:此机器码,支付后自动绑定;本工具集其他免费功能不受影响
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
</template>
|
||
|
||
<style lang="less" scoped>
|
||
.lg-float {
|
||
position: fixed;
|
||
right: 14px;
|
||
top: 70px;
|
||
bottom: auto;
|
||
z-index: 9998;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
font-size: 12.5px;
|
||
padding: 7px 14px;
|
||
border-radius: 999px;
|
||
background: rgba(30, 30, 30, 0.88);
|
||
color: #eee;
|
||
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.3);
|
||
backdrop-filter: blur(4px);
|
||
|
||
b {
|
||
font-variant-numeric: tabular-nums;
|
||
font-size: 13.5px;
|
||
}
|
||
|
||
.lg-dot {
|
||
width: 8px;
|
||
height: 8px;
|
||
border-radius: 50%;
|
||
background: #18a058;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
&.ok .lg-dot { background: #18a058; }
|
||
&.warn .lg-dot { background: #f0a000; }
|
||
&.danger .lg-dot { background: #d03050; animation: lgPulse 1s infinite; }
|
||
}
|
||
|
||
@keyframes lgPulse {
|
||
50% { opacity: 0.3; }
|
||
}
|
||
|
||
.lg-buy {
|
||
color: #63e6a0;
|
||
font-weight: 600;
|
||
text-decoration: none;
|
||
|
||
&:hover { text-decoration: underline; }
|
||
}
|
||
|
||
.lg-link {
|
||
color: #bbb;
|
||
text-decoration: underline;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.lg-cardbar {
|
||
position: fixed;
|
||
right: 14px;
|
||
bottom: 56px;
|
||
z-index: 9998;
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 8px;
|
||
padding: 10px 12px;
|
||
border-radius: 10px;
|
||
background: rgba(30, 30, 30, 0.94);
|
||
box-shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
|
||
backdrop-filter: blur(4px);
|
||
max-width: calc(100vw - 28px);
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.lg-input {
|
||
width: 220px;
|
||
height: 30px;
|
||
padding: 0 10px;
|
||
border: 1px solid rgba(255, 255, 255, 0.3);
|
||
border-radius: 4px;
|
||
background: rgba(255, 255, 255, 0.08);
|
||
color: #eee;
|
||
font-size: 13px;
|
||
outline: none;
|
||
|
||
&::placeholder { color: rgba(255, 255, 255, 0.45); }
|
||
&:focus { border-color: #18a058; }
|
||
}
|
||
|
||
.lg-input-qq {
|
||
width: 140px;
|
||
}
|
||
|
||
.lg-msg {
|
||
font-size: 12px;
|
||
color: #63e6a0;
|
||
|
||
&.err { color: #ff8fa0; }
|
||
}
|
||
|
||
.lg-overlay {
|
||
position: fixed;
|
||
inset: 0;
|
||
background: rgba(0, 0, 0, 0.62);
|
||
backdrop-filter: blur(3px);
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
z-index: 10000;
|
||
}
|
||
|
||
.lg-modal {
|
||
background: #fff;
|
||
color: #333;
|
||
border-radius: 12px;
|
||
padding: 28px 30px;
|
||
width: min(460px, calc(100vw - 32px));
|
||
box-shadow: 0 12px 48px rgba(0, 0, 0, 0.3);
|
||
text-align: center;
|
||
max-height: calc(100vh - 40px);
|
||
overflow-y: auto;
|
||
}
|
||
|
||
.lg-modal-title {
|
||
font-size: 17px;
|
||
font-weight: 700;
|
||
margin-bottom: 10px;
|
||
}
|
||
|
||
.lg-modal-desc {
|
||
font-size: 13.5px;
|
||
line-height: 1.7;
|
||
opacity: 0.75;
|
||
margin: 0 0 18px;
|
||
}
|
||
|
||
.lg-modal-actions {
|
||
display: flex;
|
||
gap: 12px;
|
||
justify-content: center;
|
||
margin-bottom: 14px;
|
||
}
|
||
|
||
.lg-modal-form {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
margin-bottom: 10px;
|
||
|
||
.lg-input {
|
||
width: 100%;
|
||
box-sizing: border-box;
|
||
border-color: rgba(128, 128, 128, 0.45);
|
||
background: #fff;
|
||
color: #333;
|
||
|
||
&::placeholder { color: rgba(128, 128, 128, 0.7); }
|
||
}
|
||
}
|
||
|
||
.modal-msg {
|
||
color: #18a058;
|
||
&.err { color: #d03050; }
|
||
}
|
||
|
||
.lg-modal-foot {
|
||
font-size: 12px;
|
||
opacity: 0.7;
|
||
margin-top: 10px;
|
||
line-height: 1.7;
|
||
|
||
code {
|
||
background: rgba(128, 128, 128, 0.12);
|
||
padding: 1px 6px;
|
||
border-radius: 4px;
|
||
cursor: pointer;
|
||
}
|
||
|
||
.lg-hint {
|
||
opacity: 0.8;
|
||
margin-top: 4px;
|
||
}
|
||
}
|
||
</style>
|