mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 13:49:19 +08:00
feat: 新增授权管理
This commit is contained in:
@@ -21,6 +21,14 @@ export async function getInitFingerprintApi() {
|
||||
}
|
||||
|
||||
export async function activateLicenseApi(data: LicenseDTO.ActivateLicense) {
|
||||
return requestClient.post<LicenseVO.LicenseSummary>(
|
||||
'/system/license/activate',
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
/** @deprecated 初始化向导用,后端若未实现可忽略 */
|
||||
export async function activateInitLicenseApi(data: LicenseDTO.ActivateLicense) {
|
||||
return baseRequestClient.post<LicenseVO.LicenseSummary>(
|
||||
'/init/activate',
|
||||
data,
|
||||
|
||||
@@ -24,6 +24,7 @@ export namespace LicenseVO {
|
||||
edition?: string;
|
||||
machineFingerprint?: string;
|
||||
features?: string[];
|
||||
maxCompanies?: number;
|
||||
issuedAt?: string;
|
||||
expiresAt?: string;
|
||||
daysRemaining?: number;
|
||||
|
||||
@@ -65,14 +65,26 @@ const routes: RouteRecordRaw[] = [
|
||||
},
|
||||
{
|
||||
name: 'SystemLicense',
|
||||
path: '/platform-admin/license',
|
||||
component: () => import('#/views/system/license/LicenseInfo.vue'),
|
||||
path: '/system/settings/license',
|
||||
component: () => import('#/views/system/license/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:key-round',
|
||||
title: 'License 管理',
|
||||
title: '授权管理',
|
||||
requiresAuth: true,
|
||||
},
|
||||
},
|
||||
// 兼容旧路径
|
||||
{
|
||||
name: 'SystemLicenseLegacy',
|
||||
path: '/platform-admin/license',
|
||||
component: () => import('#/views/system/license/index.vue'),
|
||||
meta: {
|
||||
icon: 'lucide:key-round',
|
||||
title: '授权管理',
|
||||
requiresAuth: true,
|
||||
hideInMenu: true,
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
export default routes;
|
||||
|
||||
@@ -9,7 +9,7 @@ import { LOGIN_PATH } from '@vben/constants';
|
||||
import { Button, Form, Input, message, Typography } from 'ant-design-vue';
|
||||
|
||||
import {
|
||||
activateLicenseApi,
|
||||
activateInitLicenseApi,
|
||||
getInitFingerprintApi,
|
||||
} from '#/api/system/license';
|
||||
import { resetInitStatusCache } from '#/router/guard';
|
||||
@@ -45,7 +45,7 @@ async function handleActivate() {
|
||||
submitting.value = true;
|
||||
const hide = message.loading('正在激活 License...', 0);
|
||||
try {
|
||||
await activateLicenseApi({ licenseKey: licenseKey.value.trim() });
|
||||
await activateInitLicenseApi({ licenseKey: licenseKey.value.trim() });
|
||||
resetInitStatusCache();
|
||||
message.success('系统初始化完成,请登录');
|
||||
await router.replace(LOGIN_PATH);
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
<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 {
|
||||
activateLicenseApi,
|
||||
getLicenseInfoApi,
|
||||
getSystemFingerprintApi,
|
||||
} from '#/api/system/license';
|
||||
|
||||
import FingerprintDisplay from '#/views/init/components/FingerprintDisplay.vue';
|
||||
|
||||
defineOptions({ name: 'SystemLicensePage' });
|
||||
|
||||
const loading = ref(false);
|
||||
const fingerprintLoading = ref(false);
|
||||
const submitting = ref(false);
|
||||
const license = ref<LicenseVO.LicenseSummary | null>(null);
|
||||
const fingerprint = ref<LicenseVO.Fingerprint | null>(null);
|
||||
const licenseKey = 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: '开发模式(未强制校验)' };
|
||||
if (status === 'inactive') return { color: 'default', text: '未激活' };
|
||||
return { color: 'default', text: status || '未知' };
|
||||
});
|
||||
|
||||
const editionLabel: Record<string, string> = {
|
||||
trial: '试用版',
|
||||
enterprise: '企业版',
|
||||
unlimited: '无限版',
|
||||
};
|
||||
|
||||
const hasLicense = computed(() =>
|
||||
Boolean(license.value?.companyName || license.value?.edition),
|
||||
);
|
||||
|
||||
async function loadLicense() {
|
||||
loading.value = true;
|
||||
try {
|
||||
license.value = await getLicenseInfoApi();
|
||||
} catch (error: any) {
|
||||
license.value = { status: 'inactive', features: [] };
|
||||
message.error(error?.message || '获取授权信息失败');
|
||||
} finally {
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function loadFingerprint() {
|
||||
fingerprintLoading.value = true;
|
||||
try {
|
||||
fingerprint.value = await getSystemFingerprintApi();
|
||||
} catch (error: any) {
|
||||
fingerprint.value = null;
|
||||
message.error(error?.message || '获取机器指纹失败');
|
||||
} finally {
|
||||
fingerprintLoading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
async function handleActivate() {
|
||||
if (!licenseKey.value.trim()) {
|
||||
message.warning('请输入 License Key');
|
||||
return;
|
||||
}
|
||||
submitting.value = true;
|
||||
const hide = message.loading('正在提交授权...', 0);
|
||||
try {
|
||||
license.value = await activateLicenseApi({
|
||||
licenseKey: licenseKey.value.trim(),
|
||||
});
|
||||
licenseKey.value = '';
|
||||
message.success('授权提交成功');
|
||||
} finally {
|
||||
hide();
|
||||
submitting.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function formatDate(value?: string) {
|
||||
return value ? dayjs(value).format('YYYY-MM-DD HH:mm') : '-';
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
loadLicense();
|
||||
loadFingerprint();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page title="授权管理" description="查看机器指纹,激活或更新 License">
|
||||
<div class="grid gap-4 lg:grid-cols-2">
|
||||
<Card title="机器指纹" :loading="fingerprintLoading">
|
||||
<FingerprintDisplay
|
||||
v-if="fingerprint"
|
||||
:fingerprint="fingerprint.fingerprint"
|
||||
:hostname="fingerprint.hostname"
|
||||
:machine-id="fingerprint.machineId"
|
||||
/>
|
||||
<Typography.Text v-else type="secondary">
|
||||
暂无指纹信息
|
||||
</Typography.Text>
|
||||
<Button class="mt-4" size="small" @click="loadFingerprint">
|
||||
刷新指纹
|
||||
</Button>
|
||||
</Card>
|
||||
|
||||
<Card :title="hasLicense ? '更新授权' : '激活授权'">
|
||||
<Typography.Paragraph type="secondary" class="text-sm">
|
||||
将上方机器指纹提供给运营方,获取 License 后粘贴到下方完成激活或续期。
|
||||
</Typography.Paragraph>
|
||||
<Form layout="vertical" @finish="handleActivate">
|
||||
<Form.Item label="License Key" required>
|
||||
<Input.TextArea
|
||||
v-model:value="licenseKey"
|
||||
:rows="6"
|
||||
placeholder="粘贴运营方签发的 License JWT"
|
||||
class="font-mono text-xs"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Button type="primary" html-type="submit" :loading="submitting">
|
||||
{{ hasLicense ? '更新 License' : '激活 License' }}
|
||||
</Button>
|
||||
</Form>
|
||||
</Card>
|
||||
</div>
|
||||
|
||||
<Card class="mt-4" title="当前授权信息" :loading="loading">
|
||||
<template v-if="hasLicense">
|
||||
<Descriptions :column="2" 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="公司上限">
|
||||
{{ license?.maxCompanies ?? '-' }}
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="授权指纹" :span="2">
|
||||
<Typography.Text code class="text-xs break-all">
|
||||
{{ license?.machineFingerprint || '-' }}
|
||||
</Typography.Text>
|
||||
</Descriptions.Item>
|
||||
<Descriptions.Item label="授权功能" :span="2">
|
||||
<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?.status === 'dev-disabled'
|
||||
? '当前为开发模式,尚未强制校验 License。仍可在此激活以便生产切换。'
|
||||
: '尚未激活 License,请先获取机器指纹并完成授权。'
|
||||
}}
|
||||
</Typography.Text>
|
||||
<Button class="mt-4" size="small" @click="loadLicense">刷新</Button>
|
||||
</Card>
|
||||
</Page>
|
||||
</template>
|
||||
Reference in New Issue
Block a user