refactor: 完善版 P-2 前端分包与 P-3 揭示 userKey 加固
- admin vite 配置 manualChunks 拆分 naive/echarts/vendor,index chunk 从 1652KB 降到 69KB - 揭示 userKey 改为 POST 接口(写操作日志、防缓存)+ 前端二次确认,GET 仅返回掩码 - 更新问题清单待完善项状态与项目记忆
This commit is contained in:
@@ -137,7 +137,8 @@ export const settingsApi = {
|
||||
tianheRegister: () => post<{ userId: string; userKey: string; address: string }>('/settings/tianhe/register', {}),
|
||||
tianheVerify: (data: { userId: string; userKey: string }) =>
|
||||
post<{ userId: string; address: string }>('/settings/tianhe/verify', data),
|
||||
tianheIdentity: () => get<{ userId: string; userKey: string; address: string }>('/settings/tianhe/identity'),
|
||||
tianheIdentity: () => get<{ userId: string; address: string; userKeyMasked: string }>('/settings/tianhe/identity'),
|
||||
tianheReveal: () => post<{ userId: string; userKey: string; address: string }>('/settings/tianhe/identity/reveal', {}),
|
||||
};
|
||||
|
||||
export const storageApi = {
|
||||
|
||||
@@ -554,6 +554,8 @@
|
||||
"tianheManualEntry": "Manual Entry",
|
||||
"tianheReveal": "Reveal",
|
||||
"tianheHide": "Hide",
|
||||
"tianheRevealConfirmTitle": "Reveal User Key",
|
||||
"tianheRevealConfirmContent": "The User Key is the sole credential for the platform custodial wallet. Revealing it will be recorded in the operation log. Make sure your environment is secure before continuing.",
|
||||
"tianheCopy": "Copy",
|
||||
"tianheCopied": "User Key copied",
|
||||
"tianheIdentityHint": "The User Key is the only credential to open the platform custodial wallet. TiChain does not store it and it cannot be recovered. Keep the User ID and User Key offline; after reinstalling or migrating, use Manual Entry to continue with the same on-chain identity.",
|
||||
|
||||
@@ -554,6 +554,8 @@
|
||||
"tianheManualEntry": "手动录入",
|
||||
"tianheReveal": "揭示",
|
||||
"tianheHide": "隐藏",
|
||||
"tianheRevealConfirmTitle": "揭示 User Key",
|
||||
"tianheRevealConfirmContent": "User Key 是平台托管钱包的唯一凭据,揭示操作将被记入操作日志。请确认当前环境安全后再继续。",
|
||||
"tianheCopy": "复制",
|
||||
"tianheCopied": "User Key 已复制",
|
||||
"tianheIdentityHint": "User Key 是打开平台托管钱包的唯一凭据,天河链不留存、无法找回。请务必离线保存 User ID 与 User Key;重装或迁移系统后可通过「手动录入」继续使用同一链上身份。",
|
||||
|
||||
@@ -139,11 +139,11 @@
|
||||
<div class="setting-row">
|
||||
<n-form-item label="User Key">
|
||||
<div class="identity-key">
|
||||
<span class="identity-value mono">{{ identity.userKey ? (revealKey ? identity.userKey : maskKey(identity.userKey)) : '-' }}</span>
|
||||
<n-button v-if="identity.userKey" size="tiny" quaternary @click="revealKey = !revealKey">
|
||||
<span class="identity-value mono">{{ identityKeyDisplay }}</span>
|
||||
<n-button v-if="identity.userKeyMasked" size="tiny" quaternary @click="revealUserKey">
|
||||
{{ revealKey ? t('pages.settings.tianheHide') : t('pages.settings.tianheReveal') }}
|
||||
</n-button>
|
||||
<n-button v-if="identity.userKey" size="tiny" quaternary @click="copyUserKey">{{ t('pages.settings.tianheCopy') }}</n-button>
|
||||
<n-button v-if="identity.userKeyMasked" size="tiny" quaternary @click="copyUserKey">{{ t('pages.settings.tianheCopy') }}</n-button>
|
||||
</div>
|
||||
</n-form-item>
|
||||
</div>
|
||||
@@ -259,7 +259,7 @@ const registeringIdentity = ref(false);
|
||||
const verifyingIdentity = ref(false);
|
||||
const revealKey = ref(false);
|
||||
const manualEntryVisible = ref(false);
|
||||
const identity = reactive({ userId: '', userKey: '', address: '' });
|
||||
const identity = reactive({ userId: '', userKey: '', userKeyMasked: '', address: '' });
|
||||
const manualEntry = reactive({ userId: '', userKey: '' });
|
||||
const TIANHE_TEST_URL = 'https://test.api.tichain.tianhecloud.com';
|
||||
const TIANHE_PRODUCTION_URL = 'https://api.tichain.tianhecloud.com';
|
||||
@@ -357,20 +357,42 @@ async function loadIdentity() {
|
||||
try {
|
||||
const res = await settingsApi.tianheIdentity();
|
||||
identity.userId = res.userId || '';
|
||||
identity.userKey = res.userKey || '';
|
||||
identity.userKeyMasked = res.userKeyMasked || '';
|
||||
identity.userKey = '';
|
||||
identity.address = res.address || '';
|
||||
revealKey.value = false;
|
||||
} catch {
|
||||
// 身份信息读取失败不阻塞设置页
|
||||
}
|
||||
}
|
||||
|
||||
function maskKey(value: string): string {
|
||||
if (!value || value.length <= 8) return '******';
|
||||
return `${value.slice(0, 4)}******${value.slice(-4)}`;
|
||||
// 揭示明文 userKey:二次确认后经 POST 接口获取(写操作日志、避免缓存)
|
||||
async function revealUserKey() {
|
||||
if (revealKey.value) {
|
||||
revealKey.value = false;
|
||||
return;
|
||||
}
|
||||
dialog.warning({
|
||||
title: t('pages.settings.tianheRevealConfirmTitle'),
|
||||
content: t('pages.settings.tianheRevealConfirmContent'),
|
||||
positiveText: t('common.action.confirm'),
|
||||
negativeText: t('common.action.cancel'),
|
||||
onPositiveClick: async () => {
|
||||
const res = await settingsApi.tianheReveal();
|
||||
identity.userKey = res.userKey || '';
|
||||
revealKey.value = true;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async function copyUserKey() {
|
||||
await navigator.clipboard.writeText(identity.userKey);
|
||||
let key = identity.userKey;
|
||||
if (!key) {
|
||||
const res = await settingsApi.tianheReveal();
|
||||
key = res.userKey || '';
|
||||
identity.userKey = key;
|
||||
}
|
||||
await navigator.clipboard.writeText(key);
|
||||
message.success(t('pages.settings.tianheCopied'));
|
||||
}
|
||||
|
||||
@@ -382,6 +404,7 @@ async function registerIdentity() {
|
||||
const res = await settingsApi.tianheRegister();
|
||||
identity.userId = res.userId;
|
||||
identity.userKey = res.userKey;
|
||||
identity.userKeyMasked = res.userKey ? `${res.userKey.slice(0, 3)}******${res.userKey.slice(-3)}` : '';
|
||||
identity.address = res.address;
|
||||
revealKey.value = true;
|
||||
dialog.warning({
|
||||
@@ -399,8 +422,10 @@ async function verifyIdentity() {
|
||||
try {
|
||||
const res = await settingsApi.tianheVerify({ userId: manualEntry.userId, userKey: manualEntry.userKey });
|
||||
identity.userId = res.userId;
|
||||
identity.userKey = manualEntry.userKey;
|
||||
identity.userKey = '';
|
||||
identity.userKeyMasked = manualEntry.userKey ? `${manualEntry.userKey.slice(0, 3)}******${manualEntry.userKey.slice(-3)}` : '';
|
||||
identity.address = res.address;
|
||||
revealKey.value = false;
|
||||
manualEntry.userId = '';
|
||||
manualEntry.userKey = '';
|
||||
manualEntryVisible.value = false;
|
||||
@@ -493,6 +518,10 @@ onMounted(async () => {
|
||||
});
|
||||
|
||||
const currentIconUrl = computed(() => resolveAppIcon(form.appIconFiles[0]?.url || form.appIconFiles[0]?.key));
|
||||
const identityKeyDisplay = computed(() => {
|
||||
if (!identity.userKeyMasked) return '-';
|
||||
return revealKey.value && identity.userKey ? identity.userKey : identity.userKeyMasked;
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -60,4 +60,16 @@ export default defineConfig({
|
||||
'/uploads': { target: 'http://localhost:3000', changeOrigin: true },
|
||||
},
|
||||
},
|
||||
build: {
|
||||
// 拆分体积较大的第三方库,避免单一 index chunk 过大、拖慢首屏
|
||||
rollupOptions: {
|
||||
output: {
|
||||
manualChunks: {
|
||||
naive: ['naive-ui'],
|
||||
echarts: ['echarts'],
|
||||
vendor: ['vue', 'vue-router', 'pinia', 'vue-i18n', 'axios', 'dayjs'],
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
@@ -56,7 +56,16 @@ export class SettingsController {
|
||||
@ApiBearerAuth()
|
||||
@Roles(RoleType.SUPER_ADMIN)
|
||||
@Get('tianhe/identity')
|
||||
@ApiOperation({ summary: '揭示天河链链上身份明文(userId/userKey/钱包地址),供管理员离线备份' })
|
||||
@ApiOperation({ summary: '读取天河链链上身份(userId + 钱包地址,userKey 掩码),用于设置页展示' })
|
||||
async getTianheIdentity() {
|
||||
const { userId, userKey, address } = await this.blockchain.revealTianheUserKey();
|
||||
return { userId, address, userKeyMasked: this.settingsService.maskSecretPublic(userKey) };
|
||||
}
|
||||
|
||||
@ApiBearerAuth()
|
||||
@Roles(RoleType.SUPER_ADMIN)
|
||||
@Post('tianhe/identity/reveal')
|
||||
@ApiOperation({ summary: '揭示天河链 userKey 明文(供离线备份);用 POST 以便写入操作日志、避免缓存' })
|
||||
revealTianheIdentity() {
|
||||
return this.blockchain.revealTianheUserKey();
|
||||
}
|
||||
|
||||
@@ -127,6 +127,11 @@ export class SettingsService {
|
||||
return `${value.slice(0, 3)}******${value.slice(-3)}`;
|
||||
}
|
||||
|
||||
// 对外暴露的掩码工具(供控制器展示 userKey 掩码,不返回明文)
|
||||
maskSecretPublic(value: string): string {
|
||||
return this.maskSecret(value);
|
||||
}
|
||||
|
||||
isMaskedSecret(value?: string | null): boolean {
|
||||
return typeof value === 'string' && /^\*+$|^.{1,8}\*{3,}.{1,8}$/.test(value);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user