Files
crawler-plugin/frontend-vue/src/pages/brand/components/BrandApiSecretSettingsButton.vue
T
huangzd1997 c059dee0c8 feat(密钥): 用户 API 密钥服务端化——V115 按账号绑定存储 + 后台密钥管理页 + 桌面端全站拦截与配置引导
- 新增 usersecret 模块:外观专利/货源查询密钥从本地 localStorage 迁移至 biz_user_api_secret(AES 加密、按 uid 绑定)
- 后台「密钥管理」页:脱敏展示、立即检测、清空;每日 04:30 分布式锁定时巡检
- 桌面端:密钥设置面板走服务端、未配齐引导 /setup-secrets、代理余量展示
- 删除专利汇令牌全链路与密钥保留时长选择器
2026-09-13 10:03:59 +08:00

239 lines
5.1 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.
<template>
<div class="secret-settings-entry">
<button type="button" class="secret-settings-trigger" :class="{ 'variant-topbar': variant === 'topbar' }" @click="dialogVisible = true">
<span class="secret-settings-icon" aria-hidden="true">◎</span>
<span>密钥设置</span>
</button>
<el-dialog
v-model="dialogVisible"
width="620px"
class="secret-settings-dialog"
:append-to-body="true"
:close-on-click-modal="!saving"
:close-on-press-escape="!saving"
:show-close="!saving"
>
<template #header>
<div class="dialog-header">
<div class="dialog-title">密钥设置</div>
<div class="dialog-subtitle">密钥保存在服务端并绑定当前账号,换设备登录后自动同步;代理设置保存在当前客户端。</div>
</div>
</template>
<ApiSecretSettingsPanel ref="panelRef" />
<template #footer>
<div class="dialog-footer">
<button
type="button"
class="footer-btn footer-btn-ghost"
:disabled="saving"
@click="dialogVisible = false"
>
取消
</button>
<button
type="button"
class="footer-btn footer-btn-primary"
:disabled="saving"
@click="save"
>
{{ saving ? '保存中...' : '保存' }}
</button>
</div>
</template>
</el-dialog>
</div>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import ApiSecretSettingsPanel from '@/shared/components/ApiSecretSettingsPanel.vue'
withDefaults(
defineProps<{
/** topbar=顶栏纯文字样式(对齐主程序);默认=现有胶囊按钮 */
variant?: 'topbar'
}>(),
{
variant: undefined,
},
)
const dialogVisible = ref(false)
const saving = ref(false)
const panelRef = ref<InstanceType<typeof ApiSecretSettingsPanel> | null>(null)
// 每次打开弹窗重新拉取服务端密钥状态(组件可能被 el-dialog 复用不会重新挂载)
watch(dialogVisible, (visible) => {
if (visible) void panelRef.value?.reload()
})
async function save() {
if (saving.value) return
const panel = panelRef.value
if (!panel) return
saving.value = true
try {
const ok = await panel.saveAll()
if (ok) {
dialogVisible.value = false
console.log('[api-secret] 密钥设置已保存')
}
} finally {
saving.value = false
}
}
</script>
<style scoped>
.secret-settings-entry {
display: flex;
align-items: center;
justify-content: flex-end;
}
.secret-settings-trigger {
display: inline-flex;
align-items: center;
gap: 8px;
height: 38px;
padding: 0 14px;
border: 1px solid #3c4a58;
border-radius: 10px;
background: linear-gradient(180deg, #2b3239 0%, #242a31 100%);
color: #e7edf4;
font-size: 13px;
font-weight: 700;
cursor: pointer;
}
.secret-settings-trigger:hover {
border-color: #4c647d;
}
/* topbar 变体:纯文字「🔑 密钥设置」,hover 整块变 CARD2(对齐主程序顶栏) */
.secret-settings-trigger.variant-topbar {
height: auto;
padding: 6px 12px;
border: 0;
border-radius: 0;
background: transparent;
color: #c8d2e2;
font-size: 14px;
font-weight: 400;
transition: background 0.12s ease, color 0.12s ease;
}
.secret-settings-trigger.variant-topbar:hover {
background: #343f55;
color: #f5f8fc;
}
.secret-settings-trigger.variant-topbar .secret-settings-icon {
color: #c8d2e2;
font-size: 15px;
}
.secret-settings-icon {
color: #8dc4ff;
font-size: 14px;
line-height: 1;
}
:global(.secret-settings-dialog) {
--el-dialog-bg-color: #171b20;
--el-dialog-padding-primary: 20px;
overflow: hidden;
border: 1px solid #2c3540;
border-radius: 14px;
background: #171b20;
box-shadow: 0 24px 70px rgba(0, 0, 0, .52);
}
:global(.secret-settings-dialog .el-dialog__header) {
padding: 22px 22px 12px;
margin: 0;
background: #171b20;
}
:global(.secret-settings-dialog .el-dialog__body) {
padding: 12px 22px 16px;
background: #171b20;
}
:global(.secret-settings-dialog .el-dialog__footer) {
padding: 0 22px 22px;
background: #171b20;
}
:global(.secret-settings-dialog .el-dialog__headerbtn) {
top: 18px;
right: 18px;
}
:global(.secret-settings-dialog .el-dialog__close) {
color: #8793a0;
}
:global(.secret-settings-dialog .el-dialog__close:hover) {
color: #d8e3ee;
}
.dialog-header {
display: flex;
flex-direction: column;
gap: 4px;
}
.dialog-title {
color: #f5f7fa;
font-size: 16px;
font-weight: 700;
}
.dialog-subtitle {
color: #8f9aa7;
font-size: 12px;
line-height: 1.5;
}
.dialog-footer {
display: flex;
justify-content: flex-end;
gap: 10px;
}
.footer-btn {
min-width: 76px;
height: 38px;
padding: 0 18px;
border-radius: 10px;
border: 1px solid transparent;
font-size: 13px;
font-weight: 700;
cursor: pointer;
}
.footer-btn:disabled {
cursor: not-allowed;
opacity: .58;
}
.footer-btn-ghost {
border-color: #3a4653;
background: #232a31;
color: #d9e2eb;
}
.footer-btn-primary {
background: #4f8fda;
color: #fff;
}
.footer-btn-primary:hover {
background: #67a6ed;
}
</style>