update:添加激活模块选择
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
<template>
|
||||
<div class="activation-page">
|
||||
<a-card v-if="hiddenKeys" title="RSA密钥配置" style="margin-bottom: 20px;">
|
||||
<a-card v-if="hiddenKeys" style="margin-bottom: 10px;" title="RSA密钥配置">
|
||||
<a-row :gutter="16">
|
||||
<a-col :span="24">
|
||||
<a-alert
|
||||
message="注意:请妥善保管私钥,不要泄露给他人"
|
||||
type="warning"
|
||||
show-icon
|
||||
style="margin-bottom: 16px;"
|
||||
type="warning"
|
||||
/>
|
||||
</a-col>
|
||||
|
||||
@@ -15,19 +15,19 @@
|
||||
<a-form-item label="RSA公钥">
|
||||
<a-textarea
|
||||
v-model:value="rsaKeys.publicKey"
|
||||
:rows="5"
|
||||
:readonly="readonly"
|
||||
:rows="5"
|
||||
placeholder="RSA公钥内容"
|
||||
@blur="readonly = true"
|
||||
@focus="readonly = false"
|
||||
/>
|
||||
<a-button
|
||||
type="primary"
|
||||
:disabled="!rsaKeys.publicKey"
|
||||
ghost
|
||||
size="small"
|
||||
@click="copyToClipboard(rsaKeys.publicKey)"
|
||||
:disabled="!rsaKeys.publicKey"
|
||||
style="margin-top: 8px;"
|
||||
type="primary"
|
||||
@click="copyToClipboard(rsaKeys.publicKey)"
|
||||
>
|
||||
复制公钥
|
||||
</a-button>
|
||||
@@ -38,19 +38,19 @@
|
||||
<a-form-item label="RSA私钥">
|
||||
<a-textarea
|
||||
v-model:value="rsaKeys.privateKey"
|
||||
:rows="5"
|
||||
:readonly="readonly"
|
||||
:rows="5"
|
||||
placeholder="RSA私钥内容"
|
||||
@blur="readonly = true"
|
||||
@focus="readonly = false"
|
||||
/>
|
||||
<a-button
|
||||
type="primary"
|
||||
:disabled="!rsaKeys.privateKey"
|
||||
ghost
|
||||
size="small"
|
||||
@click="copyToClipboard(rsaKeys.privateKey)"
|
||||
:disabled="!rsaKeys.privateKey"
|
||||
style="margin-top: 8px;"
|
||||
type="primary"
|
||||
@click="copyToClipboard(rsaKeys.privateKey)"
|
||||
>
|
||||
复制私钥
|
||||
</a-button>
|
||||
@@ -58,25 +58,39 @@
|
||||
</a-col>
|
||||
</a-row>
|
||||
</a-card>
|
||||
|
||||
<a-card title="设备激活">
|
||||
<a-row :gutter="16">
|
||||
<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>
|
||||
<a-col :span="24">
|
||||
<a-divider orientation="left" orientation-margin="0px">设备申请码</a-divider>
|
||||
<a-form-item>
|
||||
<a-textarea
|
||||
v-model:value="activationForm.requestCode"
|
||||
v-model:value="activationForm.applicationCode"
|
||||
:rows="3"
|
||||
allow-clear
|
||||
placeholder="请输入设备申请码"
|
||||
/>
|
||||
</a-form-item>
|
||||
</a-col>
|
||||
|
||||
<a-col :span="24">
|
||||
<a-divider orientation="left" orientation-margin="0px">设备申请码</a-divider>
|
||||
<a-divider orientation="left" orientation-margin="0px">设备激活码</a-divider>
|
||||
<a-form-item>
|
||||
<a-textarea
|
||||
v-model:value="activationForm.activationCode"
|
||||
v-model:value="activationCode"
|
||||
:rows="3"
|
||||
placeholder="生成的激活码将显示在这里"
|
||||
readonly
|
||||
@@ -87,17 +101,17 @@
|
||||
<a-col :span="24">
|
||||
<a-space>
|
||||
<a-button
|
||||
:disabled="!activationForm.applicationCode.trim()"
|
||||
:loading="generating"
|
||||
type="primary"
|
||||
@click="generateActivationCode"
|
||||
:loading="generating"
|
||||
:disabled="!activationForm.requestCode.trim()"
|
||||
>
|
||||
生成激活码
|
||||
</a-button>
|
||||
|
||||
<a-button
|
||||
@click="copyToClipboard(activationForm.activationCode)"
|
||||
:disabled="!activationForm.activationCode"
|
||||
:disabled="!activationCode"
|
||||
@click="copyToClipboard(activationCode)"
|
||||
>
|
||||
复制激活码
|
||||
</a-button>
|
||||
@@ -107,7 +121,7 @@
|
||||
</a-card>
|
||||
</div>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
<script lang="ts" setup>
|
||||
import {ref} from 'vue'
|
||||
import {message} from 'ant-design-vue'
|
||||
import rsa from '@/utils/rsa'
|
||||
@@ -121,12 +135,14 @@ const rsaKeys = ref({
|
||||
const hiddenKeys = ref(RSA_CAN_EDIT)
|
||||
const readonly = ref(true)
|
||||
const activationForm = ref({
|
||||
requestCode: '',
|
||||
activationCode: ''
|
||||
applicationCode: '',
|
||||
simulate: {permanently: false},
|
||||
digital: {permanently: false},
|
||||
contrast: {permanently: false},
|
||||
})
|
||||
|
||||
const activationCode = ref('')
|
||||
const generating = ref(false)
|
||||
|
||||
const labelCol = { style: { width: '120px' } }
|
||||
|
||||
// 生成激活码
|
||||
const generateActivationCode = () => {
|
||||
@@ -134,44 +150,61 @@ const generateActivationCode = () => {
|
||||
message.error('请先配置RSA密钥')
|
||||
return
|
||||
}
|
||||
if (!activationForm.value.requestCode.trim()) {
|
||||
if (!activationForm.value.applicationCode.trim()) {
|
||||
message.error('请输入设备申请码')
|
||||
return
|
||||
}
|
||||
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
|
||||
}
|
||||
generating.value = true
|
||||
let activationCodePlaintext
|
||||
let applicationCodePlaintext
|
||||
try {
|
||||
const plaintext = rsa.decrypt(activationForm.value.requestCode)
|
||||
activationCodePlaintext = JSON.parse(plaintext) as Activate.ActivationCodePlaintext
|
||||
const applicationCode = rsa.decrypt(activationForm.value.applicationCode)
|
||||
applicationCodePlaintext = JSON.parse(applicationCode)
|
||||
} catch (e) {
|
||||
console.error(e)
|
||||
}
|
||||
if (!activationCodePlaintext) {
|
||||
if (!applicationCodePlaintext) {
|
||||
generating.value = false
|
||||
message.error('无效的设备申请码')
|
||||
return
|
||||
}
|
||||
const contrast = activationCodePlaintext.contrast
|
||||
const digital = activationCodePlaintext.digital
|
||||
const simulate = activationCodePlaintext.simulate
|
||||
if (!contrast && !digital && !simulate) {
|
||||
generating.value = false
|
||||
if (!applicationCodePlaintext.macAddress) {
|
||||
message.error('无效的设备申请码')
|
||||
return
|
||||
}
|
||||
if (contrast.apply === 1) {
|
||||
activationCodePlaintext.contrast.permanently = 1
|
||||
let activationCodePlaintext: Activate.ActivationCodePlaintext = {
|
||||
macAddress:'',
|
||||
simulate: {permanently: 0},
|
||||
digital: {permanently: 0},
|
||||
contrast: {permanently: 0}
|
||||
}
|
||||
if (digital.apply === 1) {
|
||||
activationCodePlaintext.digital.permanently = 1
|
||||
activationCodePlaintext.macAddress = applicationCodePlaintext.macAddress
|
||||
if (simulate.permanently) {
|
||||
activationCodePlaintext.simulate = {
|
||||
permanently: 1
|
||||
}
|
||||
}
|
||||
if (simulate.apply === 1) {
|
||||
activationCodePlaintext.simulate.permanently = 1
|
||||
if (digital.permanently) {
|
||||
activationCodePlaintext.digital = {
|
||||
permanently: 1
|
||||
}
|
||||
}
|
||||
if (contrast.permanently) {
|
||||
activationCodePlaintext.contrast = {
|
||||
permanently: 1
|
||||
}
|
||||
}
|
||||
const data = JSON.stringify(activationCodePlaintext)
|
||||
// message.info(data)
|
||||
try {
|
||||
setTimeout(() => {
|
||||
activationForm.value.activationCode = rsa.encrypt(data)
|
||||
activationCode.value = rsa.encrypt(data)
|
||||
generating.value = false
|
||||
}, 1000)
|
||||
|
||||
@@ -197,16 +230,24 @@ const copyToClipboard = (text: string) => {
|
||||
})
|
||||
}
|
||||
</script>
|
||||
<style scoped lang="less">
|
||||
<style lang="less" scoped>
|
||||
.activation-page {
|
||||
height: 100%;
|
||||
background-color: #fff;
|
||||
border-radius: 8px;
|
||||
:deep(textarea) {
|
||||
font-family: consolas, monospace;
|
||||
resize: none;
|
||||
}
|
||||
|
||||
:deep(.ant-form-item-label) {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
:deep(.ant-card-body) {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
:deep(.ant-card) {
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
|
||||
|
||||
Reference in New Issue
Block a user