feat(密钥管理): 后台可代填并锁定用户代理设置,客户端只读并回填本地配置
代理是选配、不进 items 也不参与门禁,但客户端各任务链读的是本地 app.json 的
proxy_url,用户自填值与后台不一致时排查成本高。改法:
- 后台 PUT/DELETE /api/admin/user-secrets/{userId}/modules/{moduleKey} 代填/解锁,
写入后该行 source=admin;数据权限走 resolveVisibleUserIds,超管不限;
- 客户端 save/clear 命中锁定行时服务端直接拒绝并给出原因(只置灰挡不住直接调接口);
- 密钥包把代理单独放 proxy 字段下发(仍不进 items、不影响 complete 判定),
锁定时带 full 明文,客户端据此幂等地对齐本地配置;解锁 = 删除该行。
只开放代理代填:密钥模块要客户端提交任务时携带本地明文,代填会把用户卡死。
This commit is contained in:
@@ -9,6 +9,8 @@ export interface AdminUserSecretModule {
|
||||
/** 完整明文值:仅代理列有值(后端对密钥列不下发明文)。 */
|
||||
full: string
|
||||
exists: boolean
|
||||
/** 是否由后台代填并锁定:锁定时客户端不可修改或清空。 */
|
||||
locked: boolean
|
||||
checkStatus: string
|
||||
checkCode: string
|
||||
checkMessage: string
|
||||
@@ -90,3 +92,19 @@ export async function deleteUserSecret(userId: number): Promise<void> {
|
||||
const { data } = await http.delete(`/api/admin/user-secrets/${userId}`)
|
||||
unwrap<unknown>(data)
|
||||
}
|
||||
|
||||
/** 代填并锁定该用户某模块配置(当前仅代理):PUT /api/admin/user-secrets/{userId}/modules/{moduleKey} */
|
||||
export async function saveUserSecretModule(
|
||||
userId: number,
|
||||
moduleKey: string,
|
||||
value: string,
|
||||
): Promise<AdminUserSecretModule> {
|
||||
const { data } = await http.put(`/api/admin/user-secrets/${userId}/modules/${moduleKey}`, { value })
|
||||
return unwrap<AdminUserSecretModule>(data)
|
||||
}
|
||||
|
||||
/** 清空该用户某模块配置并解除锁定:DELETE /api/admin/user-secrets/{userId}/modules/{moduleKey} */
|
||||
export async function clearUserSecretModule(userId: number, moduleKey: string): Promise<void> {
|
||||
const { data } = await http.delete(`/api/admin/user-secrets/${userId}/modules/${moduleKey}`)
|
||||
unwrap<unknown>(data)
|
||||
}
|
||||
|
||||
@@ -5,8 +5,10 @@ import { formatDateTime } from '@/utils/datetime'
|
||||
import OldPagination from '@/components/OldPagination.vue'
|
||||
import {
|
||||
checkUserSecret,
|
||||
clearUserSecretModule,
|
||||
deleteUserSecret,
|
||||
fetchUserSecretList,
|
||||
saveUserSecretModule,
|
||||
type AdminUserSecretModule,
|
||||
type AdminUserSecretRow,
|
||||
type GroupOption,
|
||||
@@ -29,6 +31,8 @@ const groupFilter = ref<number | null>(null)
|
||||
const groupOptions = ref<GroupOption[]>([])
|
||||
/** 正在检测的行 userId,用于按钮 loading 态。 */
|
||||
const checkingId = ref<number | null>(null)
|
||||
/** 正在代填/解锁代理的行 userId,避免重复点击。 */
|
||||
const proxyBusyId = ref<number | null>(null)
|
||||
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(total.value / pageSize.value)))
|
||||
|
||||
@@ -77,11 +81,12 @@ function moduleStatusMeta(module: AdminUserSecretModule | undefined) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 单格悬停详情:完整值(代理为全量地址)+ 检测消息 + 检测时间 + 耗时。 */
|
||||
/** 单格悬停详情:完整值(代理为全量地址)+ 锁定说明 + 检测消息 + 检测时间 + 耗时。 */
|
||||
function moduleTooltip(module: AdminUserSecretModule | undefined) {
|
||||
if (!module || !module.exists) return '未配置'
|
||||
const parts: string[] = []
|
||||
if (module.full) parts.push(module.full)
|
||||
if (module.locked) parts.push('已由后台代填并锁定:客户端不可修改或清空')
|
||||
if (module.checkMessage) parts.push(module.checkMessage)
|
||||
if (module.checkedAt) parts.push(`检测时间:${formatDateTime(module.checkedAt)}`)
|
||||
if (module.checkLatencyMs != null) parts.push(`耗时:${module.checkLatencyMs}ms`)
|
||||
@@ -163,7 +168,7 @@ async function check(row: AdminUserSecretRow) {
|
||||
|
||||
async function remove(row: AdminUserSecretRow) {
|
||||
const who = row.username || `UID ${row.userId}`
|
||||
if (!window.confirm(`确定清空「${who}」的全部密钥与代理配置吗?清空后该用户需要重新配置。`)) return
|
||||
if (!window.confirm(`确定清空「${who}」的全部密钥与代理配置吗?后台锁定的代理会一并清除并解锁,该用户需要重新配置。`)) return
|
||||
try {
|
||||
await deleteUserSecret(row.userId)
|
||||
ElMessage.success('已清空')
|
||||
@@ -173,6 +178,47 @@ async function remove(row: AdminUserSecretRow) {
|
||||
}
|
||||
}
|
||||
|
||||
/** 代填并锁定代理:写入后客户端只能查看,修改/清空会被服务端拒绝。 */
|
||||
async function fillProxy(row: AdminUserSecretRow) {
|
||||
const who = row.username || `UID ${row.userId}`
|
||||
const value = window.prompt(
|
||||
`代填「${who}」的代理地址(保存后客户端不可修改或清空,如需变更先解锁):`,
|
||||
row.proxy?.full || '',
|
||||
)
|
||||
if (value == null) return
|
||||
const trimmed = value.trim()
|
||||
if (!trimmed) {
|
||||
ElMessage.warning('代理地址不能为空')
|
||||
return
|
||||
}
|
||||
proxyBusyId.value = row.userId
|
||||
try {
|
||||
await saveUserSecretModule(row.userId, 'proxy', trimmed)
|
||||
ElMessage.success(row.proxy?.locked ? '已更新锁定代理' : '已代填并锁定代理')
|
||||
load()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '代填失败')
|
||||
} finally {
|
||||
proxyBusyId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
/** 解锁代理:清空后台代填值,该用户恢复自行配置。 */
|
||||
async function unlockProxy(row: AdminUserSecretRow) {
|
||||
const who = row.username || `UID ${row.userId}`
|
||||
if (!window.confirm(`确定解除「${who}」的代理锁定吗?解锁后当前后台代理值会被清空,客户端恢复自行配置。`)) return
|
||||
proxyBusyId.value = row.userId
|
||||
try {
|
||||
await clearUserSecretModule(row.userId, 'proxy')
|
||||
ElMessage.success('已解锁')
|
||||
load()
|
||||
} catch (error) {
|
||||
ElMessage.error(error instanceof Error ? error.message : '解锁失败')
|
||||
} finally {
|
||||
proxyBusyId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
function changePage(next: number) {
|
||||
if (next < 1 || next > totalPages.value) return
|
||||
page.value = next
|
||||
@@ -235,7 +281,7 @@ onMounted(load)
|
||||
<th style="width: 130px">状态</th>
|
||||
<th style="width: 170px">创建时间</th>
|
||||
<th style="width: 170px">更新时间</th>
|
||||
<th style="width: 170px">操作</th>
|
||||
<th style="width: 250px">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
@@ -270,8 +316,17 @@ onMounted(load)
|
||||
<div class="module-cell module-cell--stack">
|
||||
<span v-if="row.proxy?.exists" class="mono-mask mono-full" :title="moduleTooltip(row.proxy)">{{ row.proxy.full || row.proxy.masked }}</span>
|
||||
<span v-else class="empty-value">未配置</span>
|
||||
<span class="wh-pill" :class="moduleStatusMeta(row.proxy).tone" :title="moduleTooltip(row.proxy)">
|
||||
{{ moduleStatusMeta(row.proxy).label }}
|
||||
<span class="module-cell-pills">
|
||||
<span class="wh-pill" :class="moduleStatusMeta(row.proxy).tone" :title="moduleTooltip(row.proxy)">
|
||||
{{ moduleStatusMeta(row.proxy).label }}
|
||||
</span>
|
||||
<span
|
||||
v-if="row.proxy?.locked"
|
||||
class="wh-pill is-locked"
|
||||
title="已由管理员代填并锁定:客户端不可修改或清空"
|
||||
>
|
||||
已锁定
|
||||
</span>
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
@@ -291,6 +346,23 @@ onMounted(load)
|
||||
>
|
||||
{{ checkingId === row.userId ? '检测中…' : '立即检测' }}
|
||||
</button>
|
||||
<button
|
||||
class="btn btn-sm btn-ghost"
|
||||
type="button"
|
||||
:disabled="proxyBusyId === row.userId"
|
||||
@click="fillProxy(row)"
|
||||
>
|
||||
{{ row.proxy?.locked ? '改代理' : '代填代理' }}
|
||||
</button>
|
||||
<button
|
||||
v-if="row.proxy?.locked"
|
||||
class="btn btn-sm btn-ghost"
|
||||
type="button"
|
||||
:disabled="proxyBusyId === row.userId"
|
||||
@click="unlockProxy(row)"
|
||||
>
|
||||
解锁
|
||||
</button>
|
||||
<button class="btn btn-sm btn-danger" type="button" @click="remove(row)">清空</button>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -525,6 +597,7 @@ h3 {
|
||||
.ops-cell {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.empty-tip {
|
||||
color: #8293a5;
|
||||
@@ -561,4 +634,15 @@ h3 {
|
||||
border-color: #d6dee6;
|
||||
color: #6b7d8f;
|
||||
}
|
||||
.wh-pill.is-locked {
|
||||
background: #f0ecfb;
|
||||
border-color: #d5caf0;
|
||||
color: #5b4a96;
|
||||
}
|
||||
.module-cell-pills {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user