mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 14:29:19 +08:00
feat: 新增license
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
import type { LicenseDTO, LicenseVO } from './types';
|
||||
|
||||
import { baseRequestClient, requestClient } from '#/api/request';
|
||||
|
||||
/** 初始化相关 API(无需登录) */
|
||||
|
||||
export async function getInitStatusApi() {
|
||||
return baseRequestClient.get<LicenseVO.InitStatus>('/init/status');
|
||||
}
|
||||
|
||||
export async function createInitAdminApi(data: LicenseDTO.InitAdmin) {
|
||||
return baseRequestClient.post<void>('/init/admin', data);
|
||||
}
|
||||
|
||||
export async function saveInitCompanyApi(data: LicenseDTO.InitCompany) {
|
||||
return baseRequestClient.post<void>('/init/company', data);
|
||||
}
|
||||
|
||||
export async function getInitFingerprintApi() {
|
||||
return baseRequestClient.get<LicenseVO.Fingerprint>('/init/fingerprint');
|
||||
}
|
||||
|
||||
export async function activateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
||||
return baseRequestClient.post<LicenseVO.LicenseSummary>(
|
||||
'/init/activate',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** 已登录用户的 License 管理 API */
|
||||
|
||||
export async function getLicenseInfoApi() {
|
||||
return requestClient.get<LicenseVO.LicenseSummary>('/system/license');
|
||||
}
|
||||
|
||||
export async function updateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
||||
return requestClient.put<LicenseVO.LicenseSummary>('/system/license', data);
|
||||
}
|
||||
|
||||
export async function getSystemFingerprintApi() {
|
||||
return requestClient.get<LicenseVO.Fingerprint>('/system/fingerprint');
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './apis';
|
||||
export * from './types';
|
||||
@@ -0,0 +1,2 @@
|
||||
export * from './types.dto';
|
||||
export * from './types.vo';
|
||||
@@ -0,0 +1,21 @@
|
||||
/**
|
||||
* License 模块 — 请求 DTO
|
||||
*/
|
||||
export namespace LicenseDTO {
|
||||
export interface InitAdmin {
|
||||
loginCode: string;
|
||||
phone?: string;
|
||||
password: string;
|
||||
realName: string;
|
||||
}
|
||||
|
||||
export interface InitCompany {
|
||||
companyName: string;
|
||||
contactPhone?: string;
|
||||
contactEmail?: string;
|
||||
}
|
||||
|
||||
export interface ActivateLicense {
|
||||
licenseKey: string;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
/**
|
||||
* License 模块 — 响应 VO
|
||||
*/
|
||||
export namespace LicenseVO {
|
||||
/** 初始化状态 */
|
||||
export interface InitStatus {
|
||||
initialized: boolean;
|
||||
currentStep: number;
|
||||
adminCreated: boolean;
|
||||
companySaved: boolean;
|
||||
licenseActivated: boolean;
|
||||
}
|
||||
|
||||
/** 机器指纹 */
|
||||
export interface Fingerprint {
|
||||
fingerprint: string;
|
||||
machineId: string;
|
||||
hostname: string;
|
||||
}
|
||||
|
||||
/** License 摘要 */
|
||||
export interface LicenseSummary {
|
||||
companyName?: string;
|
||||
edition?: string;
|
||||
machineFingerprint?: string;
|
||||
features?: string[];
|
||||
issuedAt?: string;
|
||||
expiresAt?: string;
|
||||
daysRemaining?: number;
|
||||
status?: string;
|
||||
}
|
||||
}
|
||||
@@ -5,11 +5,45 @@ import { preferences } from '@vben/preferences';
|
||||
import { useAccessStore, useUserStore } from '@vben/stores';
|
||||
import { startProgress, stopProgress } from '@vben/utils';
|
||||
|
||||
import { accessRoutes, coreRouteNames } from '#/router/routes';
|
||||
import { getInitStatusApi } from '#/api/system/license';
|
||||
import { INIT_PATH, accessRoutes, coreRouteNames } from '#/router/routes';
|
||||
import { useAuthStore } from '#/store';
|
||||
|
||||
import { generateAccess } from './access';
|
||||
|
||||
/** 缓存初始化状态,避免每次路由切换都请求 */
|
||||
let initStatusCache: { checked: boolean; initialized: boolean } = {
|
||||
checked: false,
|
||||
initialized: true,
|
||||
};
|
||||
|
||||
/** 初始化完成后清除缓存(激活成功后可由页面调用) */
|
||||
export function resetInitStatusCache() {
|
||||
initStatusCache = { checked: false, initialized: true };
|
||||
}
|
||||
|
||||
async function ensureInitialized(toPath: string): Promise<boolean | { path: string; replace: boolean }> {
|
||||
if (toPath === INIT_PATH || toPath.startsWith(`${INIT_PATH}/`)) {
|
||||
return true;
|
||||
}
|
||||
if (!initStatusCache.checked) {
|
||||
try {
|
||||
const status = await getInitStatusApi();
|
||||
initStatusCache = {
|
||||
checked: true,
|
||||
initialized: status.initialized,
|
||||
};
|
||||
} catch {
|
||||
// 后端不可达时不阻断(本地纯前端开发)
|
||||
initStatusCache = { checked: true, initialized: true };
|
||||
}
|
||||
}
|
||||
if (!initStatusCache.initialized) {
|
||||
return { path: INIT_PATH, replace: true };
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通用守卫配置
|
||||
* @param router
|
||||
@@ -50,6 +84,12 @@ function setupAccessGuard(router: Router) {
|
||||
const userStore = useUserStore();
|
||||
const authStore = useAuthStore();
|
||||
|
||||
// 未初始化则强制进入初始化向导(Init 路由本身跳过)
|
||||
const initCheck = await ensureInitialized(to.path);
|
||||
if (initCheck !== true) {
|
||||
return initCheck;
|
||||
}
|
||||
|
||||
// 基本路由,这些路由不需要进入权限拦截
|
||||
if (coreRouteNames.includes(to.name as string)) {
|
||||
if (to.path === LOGIN_PATH && accessStore.accessToken) {
|
||||
|
||||
@@ -20,6 +20,9 @@ const fallbackNotFoundRoute: RouteRecordRaw = {
|
||||
path: '/:path(.*)*',
|
||||
};
|
||||
|
||||
/** 系统初始化路径(未初始化时强制跳转) */
|
||||
export const INIT_PATH = '/init';
|
||||
|
||||
/** 基本路由,这些路由是必须存在的 */
|
||||
const coreRoutes: RouteRecordRaw[] = [
|
||||
/**
|
||||
@@ -38,6 +41,17 @@ const coreRoutes: RouteRecordRaw[] = [
|
||||
redirect: preferences.app.defaultHomePath,
|
||||
children: [],
|
||||
},
|
||||
{
|
||||
name: 'Init',
|
||||
path: INIT_PATH,
|
||||
component: () => import('#/views/init/InitWizard.vue'),
|
||||
meta: {
|
||||
hideInBreadcrumb: true,
|
||||
hideInMenu: true,
|
||||
hideInTab: true,
|
||||
title: '系统初始化',
|
||||
},
|
||||
},
|
||||
{
|
||||
component: AuthPageLayout,
|
||||
meta: {
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { RouteRecordRaw } from 'vue-router';
|
||||
|
||||
import { mergeRouteModules, traverseTreeValues } from '@vben/utils';
|
||||
|
||||
import { coreRoutes, fallbackNotFoundRoute } from './core';
|
||||
import { coreRoutes, fallbackNotFoundRoute, INIT_PATH } from './core';
|
||||
|
||||
const dynamicRouteFiles = import.meta.glob('./modules/**/*.ts', {
|
||||
eager: true,
|
||||
@@ -41,4 +41,4 @@ const routes: RouteRecordRaw[] = [
|
||||
|
||||
/** 有权限校验的路由列表,包含动态路由 */
|
||||
const accessRoutes = [...dynamicRoutes];
|
||||
export { accessRoutes, coreRouteNames, routes };
|
||||
export { accessRoutes, coreRouteNames, INIT_PATH, routes };
|
||||
|
||||
@@ -63,6 +63,16 @@ const routes: RouteRecordRaw[] = [
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: 'SystemLicense',
|
||||
path: '/platform-admin/license',
|
||||
component: () => import('#/views/system/license/LicenseInfo.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:key-round',
|
||||
title: 'License 管理',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
<script setup lang="ts">
|
||||
import type { LicenseDTO } from '#/api/system/license';
|
||||
|
||||
import { reactive, ref } from 'vue';
|
||||
|
||||
import { Button, Form, Input, message } from 'ant-design-vue';
|
||||
|
||||
import { createInitAdminApi } from '#/api/system/license';
|
||||
|
||||
defineOptions({ name: 'InitStepAdmin' });
|
||||
|
||||
const emit = defineEmits<{
|
||||
next: [];
|
||||
}>();
|
||||
|
||||
const submitting = ref(false);
|
||||
|
||||
const formState = reactive<LicenseDTO.InitAdmin>({
|
||||
loginCode: '',
|
||||
phone: '',
|
||||
password: '',
|
||||
realName: '',
|
||||
});
|
||||
|
||||
const rules = {
|
||||
loginCode: [{ required: true, message: '请输入登录账号' }],
|
||||
password: [{ required: true, message: '请输入密码' }],
|
||||
realName: [{ required: true, message: '请输入姓名' }],
|
||||
};
|
||||
|
||||
async function handleSubmit() {
|
||||
submitting.value = true;
|
||||
const hide = message.loading('正在创建超级管理员...', 0);
|
||||
try {
|
||||
await createInitAdminApi({
|
||||
...formState,
|
||||
phone: formState.phone || undefined,
|
||||
});
|
||||
message.success('超级管理员创建成功');
|
||||
emit('next');
|
||||
} finally {
|
||||
hide();
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Form
|
||||
layout="vertical"
|
||||
:model="formState"
|
||||
:rules="rules"
|
||||
@finish="handleSubmit"
|
||||
>
|
||||
<Form.Item label="登录账号" name="loginCode">
|
||||
<Input
|
||||
v-model:value="formState.loginCode"
|
||||
placeholder="超级管理员登录账号"
|
||||
autocomplete="username"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="手机号码" name="phone">
|
||||
<Input
|
||||
v-model:value="formState.phone"
|
||||
placeholder="选填"
|
||||
autocomplete="tel"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item label="姓名" name="realName">
|
||||
<Input v-model:value="formState.realName" placeholder="管理员姓名" />
|
||||
</Form.Item>
|
||||
<Form.Item label="登录密码" name="password">
|
||||
<Input.Password
|
||||
v-model:value="formState.password"
|
||||
placeholder="设置登录密码"
|
||||
autocomplete="new-password"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<Button type="primary" html-type="submit" :loading="submitting" block>
|
||||
下一步
|
||||
</Button>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,77 @@
|
||||
<script setup lang="ts">
|
||||
import type { LicenseDTO } from '#/api/system/license';
|
||||
|
||||
import { reactive, ref } from 'vue';
|
||||
|
||||
import { Button, Form, Input, message } from 'ant-design-vue';
|
||||
|
||||
import { saveInitCompanyApi } from '#/api/system/license';
|
||||
|
||||
defineOptions({ name: 'InitStepCompany' });
|
||||
|
||||
const emit = defineEmits<{
|
||||
back: [];
|
||||
next: [];
|
||||
}>();
|
||||
|
||||
const submitting = ref(false);
|
||||
|
||||
const formState = reactive<LicenseDTO.InitCompany>({
|
||||
companyName: '',
|
||||
contactPhone: '',
|
||||
contactEmail: '',
|
||||
});
|
||||
|
||||
const rules = {
|
||||
companyName: [{ required: true, message: '请输入公司名称' }],
|
||||
};
|
||||
|
||||
async function handleSubmit() {
|
||||
submitting.value = true;
|
||||
const hide = message.loading('正在保存公司信息...', 0);
|
||||
try {
|
||||
await saveInitCompanyApi({
|
||||
...formState,
|
||||
contactPhone: formState.contactPhone || undefined,
|
||||
contactEmail: formState.contactEmail || undefined,
|
||||
});
|
||||
message.success('公司信息保存成功');
|
||||
emit('next');
|
||||
} finally {
|
||||
hide();
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Form
|
||||
layout="vertical"
|
||||
:model="formState"
|
||||
:rules="rules"
|
||||
@finish="handleSubmit"
|
||||
>
|
||||
<Form.Item label="公司名称" name="companyName">
|
||||
<Input v-model:value="formState.companyName" placeholder="公司全称" />
|
||||
</Form.Item>
|
||||
<Form.Item label="联系电话" name="contactPhone">
|
||||
<Input v-model:value="formState.contactPhone" placeholder="选填" />
|
||||
</Form.Item>
|
||||
<Form.Item label="联系邮箱" name="contactEmail">
|
||||
<Input v-model:value="formState.contactEmail" placeholder="选填" />
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<div class="flex gap-3">
|
||||
<Button class="flex-1" @click="emit('back')">上一步</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
class="flex-1"
|
||||
:loading="submitting"
|
||||
>
|
||||
下一步
|
||||
</Button>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</template>
|
||||
@@ -0,0 +1,103 @@
|
||||
<script setup lang="ts">
|
||||
import type { LicenseVO } from '#/api/system/license';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
|
||||
import { Button, Form, Input, message, Typography } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
activateLicenseApi,
|
||||
getInitFingerprintApi,
|
||||
} from '#/api/system/license';
|
||||
import { resetInitStatusCache } from '#/router/guard';
|
||||
|
||||
import FingerprintDisplay from './components/FingerprintDisplay.vue';
|
||||
|
||||
defineOptions({ name: 'InitStepLicense' });
|
||||
|
||||
const emit = defineEmits<{
|
||||
back: [];
|
||||
}>();
|
||||
|
||||
const router = useRouter();
|
||||
const submitting = ref(false);
|
||||
const fingerprintLoading = ref(false);
|
||||
const fingerprint = ref<LicenseVO.Fingerprint | null>(null);
|
||||
const licenseKey = ref('');
|
||||
|
||||
async function loadFingerprint() {
|
||||
fingerprintLoading.value = true;
|
||||
try {
|
||||
fingerprint.value = await getInitFingerprintApi();
|
||||
} finally {
|
||||
fingerprintLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleActivate() {
|
||||
if (!licenseKey.value.trim()) {
|
||||
message.warning('请输入 License Key');
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
const hide = message.loading('正在激活 License...', 0);
|
||||
try {
|
||||
await activateLicenseApi({ licenseKey: licenseKey.value.trim() });
|
||||
resetInitStatusCache();
|
||||
message.success('系统初始化完成,请登录');
|
||||
await router.replace(LOGIN_PATH);
|
||||
} finally {
|
||||
hide();
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadFingerprint();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="space-y-4">
|
||||
<Typography.Paragraph type="secondary" class="!mb-0 text-sm">
|
||||
将机器指纹提供给运营方,获取 License Key 后粘贴到下方完成激活。
|
||||
</Typography.Paragraph>
|
||||
|
||||
<div v-if="fingerprintLoading" class="py-6 text-center text-gray-400">
|
||||
正在获取机器指纹...
|
||||
</div>
|
||||
<FingerprintDisplay
|
||||
v-else-if="fingerprint"
|
||||
:fingerprint="fingerprint.fingerprint"
|
||||
:hostname="fingerprint.hostname"
|
||||
:machine-id="fingerprint.machineId"
|
||||
/>
|
||||
|
||||
<Form layout="vertical" @finish="handleActivate">
|
||||
<Form.Item label="License Key" required>
|
||||
<Input.TextArea
|
||||
v-model:value="licenseKey"
|
||||
:rows="4"
|
||||
placeholder="粘贴运营方签发的 License JWT"
|
||||
class="font-mono text-xs"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
<div class="flex gap-3">
|
||||
<Button class="flex-1" @click="emit('back')">上一步</Button>
|
||||
<Button
|
||||
type="primary"
|
||||
html-type="submit"
|
||||
class="flex-1"
|
||||
:loading="submitting"
|
||||
>
|
||||
激活并完成
|
||||
</Button>
|
||||
</div>
|
||||
</Form.Item>
|
||||
</Form>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,91 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
import { LOGIN_PATH } from '@vben/constants';
|
||||
import { preferences } from '@vben/preferences';
|
||||
|
||||
import { Card, Spin, Steps, Typography } from 'ant-design-vue';
|
||||
|
||||
import { getInitStatusApi } from '#/api/system/license';
|
||||
|
||||
import InitStepAdmin from './InitStepAdmin.vue';
|
||||
import InitStepCompany from './InitStepCompany.vue';
|
||||
import InitStepLicense from './InitStepLicense.vue';
|
||||
|
||||
defineOptions({ name: 'InitWizard' });
|
||||
|
||||
const router = useRouter();
|
||||
const currentStep = ref(0);
|
||||
const statusLoading = ref(true);
|
||||
|
||||
const stepItems = [
|
||||
{ title: '超级管理员' },
|
||||
{ title: '公司信息' },
|
||||
{ title: 'License 激活' },
|
||||
];
|
||||
|
||||
async function loadStatus() {
|
||||
statusLoading.value = true;
|
||||
try {
|
||||
const status = await getInitStatusApi();
|
||||
if (status.initialized) {
|
||||
await router.replace(LOGIN_PATH);
|
||||
return;
|
||||
}
|
||||
// 根据后端进度定位到对应步骤
|
||||
if (status.licenseActivated || status.currentStep >= 3) {
|
||||
currentStep.value = 2;
|
||||
} else if (status.companySaved || status.currentStep >= 2) {
|
||||
currentStep.value = 2;
|
||||
} else if (status.adminCreated || status.currentStep >= 1) {
|
||||
currentStep.value = 1;
|
||||
} else {
|
||||
currentStep.value = 0;
|
||||
}
|
||||
} finally {
|
||||
statusLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function goNext() {
|
||||
currentStep.value = Math.min(currentStep.value + 1, 2);
|
||||
}
|
||||
|
||||
function goBack() {
|
||||
currentStep.value = Math.max(currentStep.value - 1, 0);
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadStatus();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
class="flex min-h-screen flex-col items-center justify-center bg-gradient-to-b from-background to-muted/30 px-4 py-10"
|
||||
>
|
||||
<div class="mb-8 text-center">
|
||||
<Typography.Title :level="3" class="!mb-1">
|
||||
{{ preferences.app.name }} 系统初始化
|
||||
</Typography.Title>
|
||||
<Typography.Text type="secondary">
|
||||
首次部署请按步骤完成配置
|
||||
</Typography.Text>
|
||||
</div>
|
||||
|
||||
<Card class="w-full max-w-lg shadow-sm">
|
||||
<Steps :current="currentStep" :items="stepItems" class="mb-8" />
|
||||
|
||||
<Spin :spinning="statusLoading">
|
||||
<InitStepAdmin v-if="currentStep === 0" @next="goNext" />
|
||||
<InitStepCompany
|
||||
v-else-if="currentStep === 1"
|
||||
@back="goBack"
|
||||
@next="goNext"
|
||||
/>
|
||||
<InitStepLicense v-else @back="goBack" />
|
||||
</Spin>
|
||||
</Card>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,56 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { createIconifyIcon } from '@vben/icons';
|
||||
|
||||
import { Button, Input, message, Space, Typography } from 'ant-design-vue';
|
||||
|
||||
defineOptions({ name: 'FingerprintDisplay' });
|
||||
|
||||
const props = defineProps<{
|
||||
fingerprint: string;
|
||||
hostname?: string;
|
||||
machineId?: string;
|
||||
}>();
|
||||
|
||||
const CopyIcon = createIconifyIcon('lucide:copy');
|
||||
|
||||
const copying = ref(false);
|
||||
|
||||
async function copyFingerprint() {
|
||||
if (!props.fingerprint) return;
|
||||
copying.value = true;
|
||||
try {
|
||||
await navigator.clipboard.writeText(props.fingerprint);
|
||||
message.success('机器指纹已复制');
|
||||
} catch {
|
||||
message.error('复制失败,请手动选择复制');
|
||||
} finally {
|
||||
copying.value = false;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="rounded-lg border border-dashed border-primary/30 bg-primary/5 p-4">
|
||||
<Typography.Text type="secondary" class="mb-2 block text-sm">
|
||||
请将以下机器指纹发送给运营方签发 License
|
||||
</Typography.Text>
|
||||
<Input :value="fingerprint" readonly class="font-mono text-xs" />
|
||||
<Space class="mt-3" wrap>
|
||||
<Button
|
||||
type="primary"
|
||||
ghost
|
||||
size="small"
|
||||
:loading="copying"
|
||||
@click="copyFingerprint"
|
||||
>
|
||||
<CopyIcon class="mr-1 size-4" />
|
||||
复制指纹
|
||||
</Button>
|
||||
<Typography.Text v-if="hostname" type="secondary" class="text-xs">
|
||||
主机名:{{ hostname }}
|
||||
</Typography.Text>
|
||||
</Space>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
import type { LicenseVO } from '#/api/system/license';
|
||||
|
||||
import { onMounted, ref } from 'vue';
|
||||
|
||||
import { Card, Spin } from 'ant-design-vue';
|
||||
|
||||
import { getSystemFingerprintApi } from '#/api/system/license';
|
||||
|
||||
import FingerprintDisplay from '#/views/init/components/FingerprintDisplay.vue';
|
||||
|
||||
defineOptions({ name: 'FingerprintInfo' });
|
||||
|
||||
const loading = ref(false);
|
||||
const fingerprint = ref<LicenseVO.Fingerprint | null>(null);
|
||||
|
||||
async function load() {
|
||||
loading.value = true;
|
||||
try {
|
||||
fingerprint.value = await getSystemFingerprintApi();
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
load();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Card title="机器指纹" :bordered="false">
|
||||
<Spin :spinning="loading">
|
||||
<FingerprintDisplay
|
||||
v-if="fingerprint"
|
||||
:fingerprint="fingerprint.fingerprint"
|
||||
:hostname="fingerprint.hostname"
|
||||
:machine-id="fingerprint.machineId"
|
||||
/>
|
||||
<div v-else-if="!loading" class="text-gray-400">暂无指纹信息</div>
|
||||
</Spin>
|
||||
<p class="mt-4 text-sm text-gray-500">
|
||||
迁机或重新签发 License 时,请将新环境的机器指纹提供给运营方。
|
||||
</p>
|
||||
</Card>
|
||||
</template>
|
||||
@@ -0,0 +1,160 @@
|
||||
<script setup lang="ts">
|
||||
import type { LicenseVO } from '#/api/system/license';
|
||||
|
||||
import { computed, onMounted, ref } from 'vue';
|
||||
|
||||
import { Page } from '@vben/common-ui';
|
||||
|
||||
import {
|
||||
Button,
|
||||
Card,
|
||||
Descriptions,
|
||||
Form,
|
||||
Input,
|
||||
message,
|
||||
Space,
|
||||
Tag,
|
||||
Typography,
|
||||
} from 'ant-design-vue';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
import {
|
||||
getLicenseInfoApi,
|
||||
updateLicenseApi,
|
||||
} from '#/api/system/license';
|
||||
|
||||
import FingerprintInfo from './FingerprintInfo.vue';
|
||||
|
||||
defineOptions({ name: 'LicenseInfo' });
|
||||
|
||||
const loading = ref(false);
|
||||
const updating = ref(false);
|
||||
const license = ref<LicenseVO.LicenseSummary | null>(null);
|
||||
const renewKey = ref('');
|
||||
|
||||
const statusTag = computed(() => {
|
||||
const status = license.value?.status;
|
||||
if (status === 'active') return { color: 'success', text: '有效' };
|
||||
if (status === 'expiring') return { color: 'warning', text: '即将过期' };
|
||||
if (status === 'expired') return { color: 'error', text: '已过期' };
|
||||
if (status === 'dev-disabled') return { color: 'default', text: '开发模式' };
|
||||
return { color: 'default', text: status || '未知' };
|
||||
});
|
||||
|
||||
const editionLabel: Record<string, string> = {
|
||||
trial: '试用版',
|
||||
enterprise: '企业版',
|
||||
unlimited: '无限版',
|
||||
};
|
||||
|
||||
async function loadLicense() {
|
||||
loading.value = true;
|
||||
try {
|
||||
license.value = await getLicenseInfoApi();
|
||||
} catch (error: any) {
|
||||
license.value = null;
|
||||
if (!error?.message?.includes('无有效')) {
|
||||
message.error(error?.message || '获取 License 信息失败');
|
||||
}
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleRenew() {
|
||||
if (!renewKey.value.trim()) {
|
||||
message.warning('请输入新的 License Key');
|
||||
return;
|
||||
}
|
||||
updating.value = true;
|
||||
const hide = message.loading('正在更新 License...', 0);
|
||||
try {
|
||||
license.value = await updateLicenseApi({ licenseKey: renewKey.value.trim() });
|
||||
renewKey.value = '';
|
||||
message.success('License 更新成功');
|
||||
} finally {
|
||||
hide();
|
||||
updating.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(value?: string) {
|
||||
return value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-';
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadLicense();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="License 管理" description="查看授权信息与续期更新">
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<Card title="授权信息" :loading="loading">
|
||||
<template v-if="license">
|
||||
<Descriptions :column="1" bordered size="small">
|
||||
<Descriptions.Item label="状态">
|
||||
<Tag :color="statusTag.color">{{ statusTag.text }}</Tag>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="授权公司">
|
||||
{{ license.companyName || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="版本">
|
||||
{{ editionLabel[license.edition || ''] || license.edition || '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="机器指纹">
|
||||
<Typography.Text code class="text-xs break-all">
|
||||
{{ license.machineFingerprint || '-' }}
|
||||
</Typography.Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="授权功能">
|
||||
<Space wrap>
|
||||
<Tag v-for="f in license.features" :key="f">{{ f }}</Tag>
|
||||
<span v-if="!license.features?.length">-</span>
|
||||
</Space>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="签发时间">
|
||||
{{ formatDate(license.issuedAt) }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="过期时间">
|
||||
{{ formatDate(license.expiresAt) }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item
|
||||
v-if="license.daysRemaining != null"
|
||||
label="剩余天数"
|
||||
>
|
||||
{{ license.daysRemaining }} 天
|
||||
</Descriptions.Item>
|
||||
</Descriptions>
|
||||
</template>
|
||||
<Typography.Text v-else type="secondary">
|
||||
暂无有效 License(本地开发可能未启用校验)
|
||||
</Typography.Text>
|
||||
<Button class="mt-4" size="small" @click="loadLicense">刷新</Button>
|
||||
</Card>
|
||||
|
||||
<Card title="续期 / 更新 License">
|
||||
<Typography.Paragraph type="secondary" class="text-sm">
|
||||
运营方签发新 License 后,将完整 JWT 粘贴到下方并提交。
|
||||
</Typography.Paragraph>
|
||||
<Form layout="vertical" @finish="handleRenew">
|
||||
<Form.Item label="新 License Key" required>
|
||||
<Input.TextArea
|
||||
v-model:value="renewKey"
|
||||
:rows="5"
|
||||
placeholder="粘贴新的 License JWT"
|
||||
class="font-mono text-xs"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Button type="primary" html-type="submit" :loading="updating">
|
||||
更新 License
|
||||
</Button>
|
||||
</Form>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<FingerprintInfo />
|
||||
</div>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user