2025-10-16 20:01:57 +08:00
|
|
|
<template>
|
|
|
|
|
<div class="activation-page">
|
2025-10-22 15:40:21 +08:00
|
|
|
<a-card v-if="hiddenKeys" style="margin-bottom: 10px;" title="RSA密钥配置">
|
2025-10-16 20:01:57 +08:00
|
|
|
<a-row :gutter="16">
|
|
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-alert
|
|
|
|
|
message="注意:请妥善保管私钥,不要泄露给他人"
|
|
|
|
|
show-icon
|
|
|
|
|
style="margin-bottom: 16px;"
|
2025-10-22 15:40:21 +08:00
|
|
|
type="warning"
|
2025-10-16 20:01:57 +08:00
|
|
|
/>
|
|
|
|
|
</a-col>
|
|
|
|
|
|
|
|
|
|
<a-col :span="12">
|
|
|
|
|
<a-form-item label="RSA公钥">
|
|
|
|
|
<a-textarea
|
|
|
|
|
v-model:value="rsaKeys.publicKey"
|
2025-10-20 09:08:24 +08:00
|
|
|
:readonly="readonly"
|
2025-10-22 15:40:21 +08:00
|
|
|
:rows="5"
|
2025-10-16 20:01:57 +08:00
|
|
|
placeholder="RSA公钥内容"
|
2025-10-20 09:08:24 +08:00
|
|
|
@blur="readonly = true"
|
|
|
|
|
@focus="readonly = false"
|
2025-10-16 20:01:57 +08:00
|
|
|
/>
|
|
|
|
|
<a-button
|
2025-10-22 15:40:21 +08:00
|
|
|
:disabled="!rsaKeys.publicKey"
|
2025-10-16 20:01:57 +08:00
|
|
|
ghost
|
|
|
|
|
size="small"
|
|
|
|
|
style="margin-top: 8px;"
|
2025-10-22 15:40:21 +08:00
|
|
|
type="primary"
|
|
|
|
|
@click="copyToClipboard(rsaKeys.publicKey)"
|
2025-10-16 20:01:57 +08:00
|
|
|
>
|
|
|
|
|
复制公钥
|
|
|
|
|
</a-button>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
|
|
|
|
|
<a-col :span="12">
|
|
|
|
|
<a-form-item label="RSA私钥">
|
|
|
|
|
<a-textarea
|
|
|
|
|
v-model:value="rsaKeys.privateKey"
|
2025-10-20 09:08:24 +08:00
|
|
|
:readonly="readonly"
|
2025-10-22 15:40:21 +08:00
|
|
|
:rows="5"
|
2025-10-16 20:01:57 +08:00
|
|
|
placeholder="RSA私钥内容"
|
2025-10-20 09:08:24 +08:00
|
|
|
@blur="readonly = true"
|
|
|
|
|
@focus="readonly = false"
|
2025-10-16 20:01:57 +08:00
|
|
|
/>
|
|
|
|
|
<a-button
|
2025-10-22 15:40:21 +08:00
|
|
|
:disabled="!rsaKeys.privateKey"
|
2025-10-16 20:01:57 +08:00
|
|
|
ghost
|
|
|
|
|
size="small"
|
|
|
|
|
style="margin-top: 8px;"
|
2025-10-22 15:40:21 +08:00
|
|
|
type="primary"
|
|
|
|
|
@click="copyToClipboard(rsaKeys.privateKey)"
|
2025-10-16 20:01:57 +08:00
|
|
|
>
|
|
|
|
|
复制私钥
|
|
|
|
|
</a-button>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</a-card>
|
|
|
|
|
<a-card title="设备激活">
|
|
|
|
|
<a-row :gutter="16">
|
2025-10-22 15:40:21 +08:00
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-divider orientation="left" orientation-margin="0px">激活模块</a-divider>
|
|
|
|
|
<a-form layout="inline" :label-col="labelCol">
|
|
|
|
|
<a-form-item label="模拟式模块">
|
|
|
|
|
<a-switch v-model:checked="activationForm.simulate.permanently"/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
<a-form-item label="数字式模块">
|
|
|
|
|
<a-switch v-model:checked="activationForm.digital.permanently"/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
<a-form-item label="比对式模块">
|
|
|
|
|
<a-switch v-model:checked="activationForm.contrast.permanently"/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-form>
|
|
|
|
|
</a-col>
|
2025-10-16 20:01:57 +08:00
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-divider orientation="left" orientation-margin="0px">设备申请码</a-divider>
|
|
|
|
|
<a-form-item>
|
|
|
|
|
<a-textarea
|
2025-10-22 15:40:21 +08:00
|
|
|
v-model:value="activationForm.applicationCode"
|
2025-10-16 20:01:57 +08:00
|
|
|
:rows="3"
|
2025-10-22 15:40:21 +08:00
|
|
|
allow-clear
|
2025-10-16 20:01:57 +08:00
|
|
|
placeholder="请输入设备申请码"
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
|
|
|
|
|
<a-col :span="24">
|
2025-10-22 15:40:21 +08:00
|
|
|
<a-divider orientation="left" orientation-margin="0px">设备激活码</a-divider>
|
2025-10-16 20:01:57 +08:00
|
|
|
<a-form-item>
|
|
|
|
|
<a-textarea
|
2025-10-22 15:40:21 +08:00
|
|
|
v-model:value="activationCode"
|
2025-10-16 20:01:57 +08:00
|
|
|
:rows="3"
|
|
|
|
|
placeholder="生成的激活码将显示在这里"
|
|
|
|
|
readonly
|
|
|
|
|
/>
|
|
|
|
|
</a-form-item>
|
|
|
|
|
</a-col>
|
|
|
|
|
|
|
|
|
|
<a-col :span="24">
|
|
|
|
|
<a-space>
|
|
|
|
|
<a-button
|
2025-10-22 15:40:21 +08:00
|
|
|
:disabled="!activationForm.applicationCode.trim()"
|
|
|
|
|
:loading="generating"
|
2025-10-16 20:01:57 +08:00
|
|
|
type="primary"
|
|
|
|
|
@click="generateActivationCode"
|
|
|
|
|
>
|
|
|
|
|
生成激活码
|
|
|
|
|
</a-button>
|
|
|
|
|
|
|
|
|
|
<a-button
|
2025-10-22 15:40:21 +08:00
|
|
|
:disabled="!activationCode"
|
|
|
|
|
@click="copyToClipboard(activationCode)"
|
2025-10-16 20:01:57 +08:00
|
|
|
>
|
|
|
|
|
复制激活码
|
|
|
|
|
</a-button>
|
|
|
|
|
</a-space>
|
|
|
|
|
</a-col>
|
|
|
|
|
</a-row>
|
|
|
|
|
</a-card>
|
|
|
|
|
</div>
|
|
|
|
|
</template>
|
2025-10-22 15:40:21 +08:00
|
|
|
<script lang="ts" setup>
|
2025-10-16 20:01:57 +08:00
|
|
|
import {ref} from 'vue'
|
|
|
|
|
import {message} from 'ant-design-vue'
|
|
|
|
|
import rsa from '@/utils/rsa'
|
|
|
|
|
import {Activate} from "@/views/activate/index";
|
|
|
|
|
|
2025-10-20 09:08:24 +08:00
|
|
|
const RSA_CAN_EDIT = import.meta.env.VITE_RSA_CAN_EDIT === 'true'
|
2025-10-16 20:01:57 +08:00
|
|
|
const rsaKeys = ref({
|
|
|
|
|
publicKey: rsa.publicKey,
|
|
|
|
|
privateKey: rsa.privateKey
|
|
|
|
|
})
|
2025-10-20 09:08:24 +08:00
|
|
|
const hiddenKeys = ref(RSA_CAN_EDIT)
|
|
|
|
|
const readonly = ref(true)
|
2025-10-16 20:01:57 +08:00
|
|
|
const activationForm = ref({
|
2025-10-22 15:40:21 +08:00
|
|
|
applicationCode: '',
|
|
|
|
|
simulate: {permanently: false},
|
|
|
|
|
digital: {permanently: false},
|
|
|
|
|
contrast: {permanently: false},
|
2025-10-16 20:01:57 +08:00
|
|
|
})
|
2025-10-22 15:40:21 +08:00
|
|
|
const activationCode = ref('')
|
2025-10-16 20:01:57 +08:00
|
|
|
const generating = ref(false)
|
2025-10-22 15:40:21 +08:00
|
|
|
const labelCol = { style: { width: '120px' } }
|
2025-10-16 20:01:57 +08:00
|
|
|
|
|
|
|
|
// 生成激活码
|
|
|
|
|
const generateActivationCode = () => {
|
2025-10-20 09:08:24 +08:00
|
|
|
if (!rsaKeys.value.publicKey || !rsaKeys.value.privateKey) {
|
|
|
|
|
message.error('请先配置RSA密钥')
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
if (!activationForm.value.applicationCode.trim()) {
|
2025-10-16 20:01:57 +08:00
|
|
|
message.error('请输入设备申请码')
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
let simulate = activationForm.value.simulate as Activate.ActivateModule
|
|
|
|
|
let digital = activationForm.value.digital as Activate.ActivateModule
|
|
|
|
|
let contrast = activationForm.value.contrast as Activate.ActivateModule
|
|
|
|
|
if (!simulate.permanently && !digital.permanently && !contrast.permanently) {
|
|
|
|
|
message.error('请至少选择一种激活模块')
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-10-16 20:01:57 +08:00
|
|
|
generating.value = true
|
2025-10-22 15:40:21 +08:00
|
|
|
let applicationCodePlaintext
|
2025-10-16 20:01:57 +08:00
|
|
|
try {
|
2025-10-22 15:40:21 +08:00
|
|
|
const applicationCode = rsa.decrypt(activationForm.value.applicationCode)
|
|
|
|
|
applicationCodePlaintext = JSON.parse(applicationCode)
|
2025-10-16 20:01:57 +08:00
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
if (!applicationCodePlaintext) {
|
2025-10-16 20:01:57 +08:00
|
|
|
generating.value = false
|
|
|
|
|
message.error('无效的设备申请码')
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
if (!applicationCodePlaintext.macAddress) {
|
2025-10-16 20:01:57 +08:00
|
|
|
message.error('无效的设备申请码')
|
|
|
|
|
return
|
|
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
let activationCodePlaintext: Activate.ActivationCodePlaintext = {
|
|
|
|
|
macAddress:'',
|
|
|
|
|
simulate: {permanently: 0},
|
|
|
|
|
digital: {permanently: 0},
|
|
|
|
|
contrast: {permanently: 0}
|
2025-10-16 20:01:57 +08:00
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
activationCodePlaintext.macAddress = applicationCodePlaintext.macAddress
|
|
|
|
|
if (simulate.permanently) {
|
|
|
|
|
activationCodePlaintext.simulate = {
|
|
|
|
|
permanently: 1
|
|
|
|
|
}
|
2025-10-16 20:01:57 +08:00
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
if (digital.permanently) {
|
|
|
|
|
activationCodePlaintext.digital = {
|
|
|
|
|
permanently: 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (contrast.permanently) {
|
|
|
|
|
activationCodePlaintext.contrast = {
|
|
|
|
|
permanently: 1
|
|
|
|
|
}
|
2025-10-16 20:01:57 +08:00
|
|
|
}
|
|
|
|
|
const data = JSON.stringify(activationCodePlaintext)
|
2025-10-22 15:40:21 +08:00
|
|
|
// message.info(data)
|
2025-10-16 20:01:57 +08:00
|
|
|
try {
|
|
|
|
|
setTimeout(() => {
|
2025-10-22 15:40:21 +08:00
|
|
|
activationCode.value = rsa.encrypt(data)
|
2025-10-16 20:01:57 +08:00
|
|
|
generating.value = false
|
|
|
|
|
}, 1000)
|
|
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
console.error(e)
|
|
|
|
|
generating.value = false
|
|
|
|
|
message.error('生成激活码失败')
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 复制到剪贴板
|
|
|
|
|
const copyToClipboard = (text: string) => {
|
|
|
|
|
if (!text) {
|
|
|
|
|
message.warning('没有内容可复制')
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
navigator.clipboard.writeText(text).then(() => {
|
|
|
|
|
message.success('复制成功')
|
|
|
|
|
}).catch(() => {
|
|
|
|
|
message.error('复制失败')
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
</script>
|
2025-10-22 15:40:21 +08:00
|
|
|
<style lang="less" scoped>
|
2025-10-16 20:01:57 +08:00
|
|
|
.activation-page {
|
2025-10-22 15:40:21 +08:00
|
|
|
height: 100%;
|
|
|
|
|
background-color: #fff;
|
|
|
|
|
border-radius: 8px;
|
2025-10-16 20:01:57 +08:00
|
|
|
:deep(textarea) {
|
|
|
|
|
font-family: consolas, monospace;
|
|
|
|
|
resize: none;
|
|
|
|
|
}
|
2025-10-22 15:40:21 +08:00
|
|
|
|
2025-10-16 20:01:57 +08:00
|
|
|
:deep(.ant-form-item-label) {
|
|
|
|
|
font-weight: bold;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-22 15:40:21 +08:00
|
|
|
:deep(.ant-card-body) {
|
|
|
|
|
padding: 18px;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-16 20:01:57 +08:00
|
|
|
:deep(.ant-card) {
|
|
|
|
|
border-radius: 8px;
|
|
|
|
|
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|