Files
yhy-mager/frontend/src/views/InstanceProvisionPanel.vue
xiewenjun 9ba8053b5b
Some checks failed
Check / delivery-static (push) Has been cancelled
Check / api (push) Has been cancelled
Check / web (push) Has been cancelled
feat: retain encrypted instance credentials and reissue v2 certificates
Co-Authored-By: Craft Agent <agents-noreply@craft.do>
2026-10-12 11:41:02 +08:00

62 lines
4.6 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import { getLicense, provisionLicenseInstance, getInstanceCredentials } from '../api'
import { downloadLicenseFile } from '../license-file'
const props = defineProps<{licenseId:number;hasInstance:boolean;ready:boolean}>()
const emit = defineEmits<{created:[]}>()
const busy = ref(false), error = ref('')
const exportError = ref(''), baseURL = ref('https://license.yihuiyong.cn')
function exportFile() {
if (!credentials.value) return
exportError.value = ''
try { downloadLicenseFile(credentials.value, baseURL.value) }
catch (e) { exportError.value = e instanceof Error ? e.message : '导出失败,请重试' }
}
const credentials = ref<{instance_id:string;license_key:string;secret:string}|null>(null)
const retained = ref(false)
async function viewCredentials() {
if(busy.value || !props.ready) return
try { await ElMessageBox.confirm('此操作将显示完整激活密钥并记录审计事件,请确保当前屏幕环境安全。','查看客户端激活凭据') } catch { return }
busy.value=true;error.value=''
try { credentials.value=(await getInstanceCredentials(props.licenseId)).data.data;retained.value=true }
catch(e) { error.value=e instanceof Error?e.message:'读取凭据失败' }
finally { busy.value=false }
}
async function create() {
if(busy.value || props.hasInstance || !props.ready || credentials.value || error.value) return
try { await ElMessageBox.confirm('每条授权只能绑定一个实例。配置凭据加密存储后可重复查看;未配置时仅首次返回,请安全保存并交付。确认创建?','创建客户端实例') } catch { return }
busy.value=true;error.value=''
try {
const license=(await getLicense(props.licenseId)).data.data
const response=(await provisionLicenseInstance(props.licenseId)).data
const result=response.data
retained.value=response.credentials_retained===true
credentials.value={instance_id:result.instance_id,license_key:license.license_key,secret:result.secret}
emit('created')
} catch(e) { error.value=(e instanceof Error?e.message:'创建失败')+'。若请求超时,请先刷新实例列表确认是否已创建;已保留凭据的实例可通过查看入口获取,请勿反复创建。' }
finally { busy.value=false }
}
</script>
<template>
<section class="data-section">
<h3>客户端激活凭据</h3>
<p>授权码就是授权密钥(license_key)。实例 ID 和激活密钥(secret)由平台创建实例时生成,每条授权仅绑定一个实例。</p>
<el-button v-if="!credentials&&!hasInstance" type="primary" :loading="busy" :disabled="!ready||hasInstance||!!error" @click="create">创建实例并获取激活凭据</el-button>
<el-button v-if="hasInstance&&!credentials" type="primary" :loading="busy" :disabled="!ready" @click="viewCredentials">查看客户端激活凭据</el-button>
<p v-if="hasInstance&&!credentials" class="subheading">已加密保留的凭据可重复查看及下载。旧实例仅存哈希,无法恢复;此类实例需使用原始交付文件,或冻结旧实例、撤销旧授权后重新签发。</p>
<p v-if="error" class="error" role="alert">{{error}}</p>
<template v-if="credentials">
<p role="status">请安全保存和交付下列凭据。{{retained?'凭据已加密保留,可再次查看。':'未加密保留,关闭后无法再次获取。'}}</p>
<dl class="license-detail"><dt>实例 ID(instance_id)</dt><dd class="license-code">{{credentials.instance_id}}</dd><dt>授权码(license_key)</dt><dd class="license-code">{{credentials.license_key}}</dd><dt>激活密钥(secret)</dt><dd class="license-code">{{credentials.secret}}</dd></dl>
<label for="license-export-base-url">授权文件中的授权中心地址</label>
<el-input id="license-export-base-url" v-model="baseURL" placeholder="https://license.yihuiyong.cn" />
<el-button type="primary" @click="exportFile">导出授权文件</el-button>
<p v-if="exportError" class="error" role="alert">{{ exportError }}</p>
<el-button @click="credentials=null">隐藏凭据</el-button>
<p>导出的 .license.json 含激活密钥,请安全交付。客户端需支持本文件格式,导入后在线激活并获取运行租约;文件本身不代表授权有效。已加密保留的凭据可重新查看并导出。</p>
<p>默认授权中心:https://license.yihuiyong.cn;私有部署填写实际 HTTPS 根地址。客户端激活后仍需安全保存密钥用于心跳和下载;不要放入日志、截图或普通工单。生产验签公钥应由开发团队预置。</p>
</template>
</section>
</template>