637 lines
26 KiB
Vue
637 lines
26 KiB
Vue
<template>
|
||
<div class="identity-management">
|
||
<el-card shadow="never">
|
||
<div class="flex items-center justify-between mb-4">
|
||
<div>
|
||
<h2 class="text-xl font-semibold">IAM 关联管理</h2>
|
||
<p class="text-gray-500 mt-2">
|
||
保留历史本地账号、业务角色与数据;只管理统一身份关联。
|
||
</p>
|
||
</div>
|
||
<el-button @click="reauthVisible = true">验证管理员身份</el-button>
|
||
</div>
|
||
<el-alert
|
||
v-if="error"
|
||
:title="error"
|
||
type="warning"
|
||
show-icon
|
||
:closable="false"
|
||
class="mb-4"
|
||
/>
|
||
<el-alert
|
||
v-if="!enabled"
|
||
title="IAM v2 尚未启用,原有业务与登录方式保持不变。"
|
||
type="info"
|
||
:closable="false"
|
||
/>
|
||
<el-form v-if="enabled" inline class="mt-4" @submit.prevent="reload">
|
||
<el-form-item label="本地账号"
|
||
><el-input
|
||
v-model="query.q"
|
||
placeholder="账号或姓名"
|
||
clearable
|
||
@keyup.enter="reload"
|
||
/></el-form-item>
|
||
<el-form-item label="关联状态"
|
||
><el-select v-model="query.state" clearable class="!w-40"
|
||
><el-option
|
||
v-for="(label, key) in states"
|
||
:key="key"
|
||
:label="label"
|
||
:value="key" /></el-select
|
||
></el-form-item>
|
||
<el-form-item
|
||
><el-button type="primary" @click="reload">查询</el-button
|
||
><el-button :disabled="!can('batch')" @click="batchVisible = true"
|
||
>批量预检</el-button
|
||
></el-form-item
|
||
>
|
||
</el-form>
|
||
<el-table v-if="enabled" v-loading="loading" :data="rows" row-key="id">
|
||
<el-table-column prop="id" label="ID" width="70" />
|
||
<el-table-column prop="account" label="本地账号" min-width="140" />
|
||
<el-table-column prop="name" label="姓名" min-width="120" />
|
||
<el-table-column label="本地状态" width="110"
|
||
><template #default="{ row }"
|
||
><el-tag :type="row.disable ? 'danger' : 'success'">{{
|
||
row.disable ? '停用' : row.root ? '敏感账号' : '正常'
|
||
}}</el-tag></template
|
||
></el-table-column
|
||
>
|
||
<el-table-column label="IAM 员工" min-width="180"
|
||
><template #default="{ row }"
|
||
>{{ row.iam.employee?.displayName || '—' }}
|
||
<div class="text-xs text-gray-500">
|
||
{{ row.iam.employee?.username }}
|
||
</div></template
|
||
></el-table-column
|
||
>
|
||
<el-table-column label="关联状态" width="130"
|
||
><template #default="{ row }"
|
||
><el-tag :type="row.iam.state === 'verified' ? 'success' : 'info'">{{
|
||
states[row.iam.state] || row.iam.state
|
||
}}</el-tag>
|
||
<div class="text-xs">
|
||
版本 {{ row.iam.binding?.version ?? '—' }}
|
||
</div></template
|
||
></el-table-column
|
||
>
|
||
<el-table-column label="操作" min-width="210"
|
||
><template #default="{ row }">
|
||
<el-button
|
||
link
|
||
type="primary"
|
||
:disabled="
|
||
(!!row.root && !reviewAllowed) ||
|
||
row.iam.state === 'verified' ||
|
||
!can(row.iam.state === 'revoked' ? 'rebind' : 'bind')
|
||
"
|
||
@click="open(row, 'bind')"
|
||
>关联</el-button
|
||
>
|
||
<el-button
|
||
link
|
||
type="primary"
|
||
:disabled="
|
||
(!!row.root && !reviewAllowed) ||
|
||
row.iam.state === 'verified' ||
|
||
!can('create') ||
|
||
(row.iam.state === 'revoked' && !can('rebind'))
|
||
"
|
||
@click="open(row, 'create_and_bind')"
|
||
>创建并关联</el-button
|
||
>
|
||
<el-dropdown @command="(kind: string) => more(row, kind)"
|
||
><el-button link>更多</el-button
|
||
><template #dropdown
|
||
><el-dropdown-menu>
|
||
<el-dropdown-item
|
||
command="rebind"
|
||
:disabled="(!!row.root && !reviewAllowed) || !can('rebind')"
|
||
>换绑</el-dropdown-item
|
||
>
|
||
<el-dropdown-item
|
||
command="unbind"
|
||
:disabled="(!!row.root && !reviewAllowed) || !can('unbind')"
|
||
>解绑</el-dropdown-item
|
||
>
|
||
<el-dropdown-item command="audit">审计记录</el-dropdown-item>
|
||
</el-dropdown-menu></template
|
||
></el-dropdown
|
||
>
|
||
</template></el-table-column
|
||
>
|
||
</el-table>
|
||
<el-pagination
|
||
v-if="enabled"
|
||
class="mt-4 justify-end"
|
||
layout="total, prev, pager, next"
|
||
:total="total"
|
||
v-model:current-page="query.page"
|
||
:page-size="20"
|
||
@current-change="load"
|
||
/>
|
||
</el-card>
|
||
<el-drawer
|
||
v-model="drawer"
|
||
:title="titles[operation.kind]"
|
||
size="min(680px, 94vw)"
|
||
:close-on-click-modal="false"
|
||
>
|
||
<el-steps :active="step" finish-status="success" align-center
|
||
><el-step title="核对本地账号" /><el-step title="核对 IAM 身份" /><el-step
|
||
title="确认变更"
|
||
/></el-steps>
|
||
<section class="mt-8">
|
||
<template v-if="step === 0"
|
||
><h3 class="text-lg mb-4">{{ selected?.name }} · {{ selected?.account }}</h3>
|
||
<p>本地 ID:{{ selected?.id }}</p>
|
||
<p class="my-3">
|
||
当前关联:{{ selected?.iam.employee?.displayName || '未关联' }}(版本
|
||
{{ selected?.iam.binding?.version ?? '无' }})
|
||
</p>
|
||
<el-alert
|
||
title="本次操作不改变本地密码、角色、部门或历史数据;人员同名不代表同一身份。"
|
||
type="info"
|
||
:closable="false"
|
||
/></template>
|
||
<template v-if="step === 1">
|
||
<el-form v-if="operation.kind === 'create_and_bind'" label-position="top"
|
||
><el-form-item label="IAM 登录名"
|
||
><el-input
|
||
v-model="newEmployee.username"
|
||
maxlength="64" /></el-form-item
|
||
><el-form-item label="姓名"
|
||
><el-input
|
||
v-model="newEmployee.display_name"
|
||
maxlength="100" /></el-form-item
|
||
><el-form-item label="邮箱(可选)"
|
||
><el-input v-model="newEmployee.email" /></el-form-item
|
||
><el-alert
|
||
title="使用正常员工开户流程,默认应用授权遵循 IAM 当前策略。不会生成共享初始密码;本人首次使用需设置 IAM 密码。"
|
||
type="info"
|
||
:closable="false"
|
||
/></el-form>
|
||
<template v-else-if="operation.kind !== 'unbind'"
|
||
><el-input
|
||
v-model="identityQuery"
|
||
placeholder="搜索 IAM 登录名或姓名"
|
||
@keyup.enter="searchIdentities"
|
||
><template #append
|
||
><el-button @click="searchIdentities">搜索</el-button></template
|
||
></el-input
|
||
><el-table
|
||
class="mt-4"
|
||
:data="identities"
|
||
highlight-current-row
|
||
@current-change="choose"
|
||
><el-table-column label="选择" width="70"
|
||
><template #default="{ row }"
|
||
><el-radio
|
||
:model-value="operation.employee_id"
|
||
:value="row.id"
|
||
@change="choose(row)"
|
||
><span /></el-radio></template></el-table-column
|
||
><el-table-column prop="username" label="IAM 登录名" /><el-table-column
|
||
prop="displayName"
|
||
label="姓名" /><el-table-column
|
||
prop="status"
|
||
label="状态" /></el-table
|
||
></template>
|
||
<el-alert
|
||
v-else
|
||
title="解绑后跨平台快捷登录停止,相关来源/业务会话撤销,历史数据和本地账号保留。自动开户不会恢复已撤销关联。"
|
||
type="warning"
|
||
:closable="false"
|
||
/>
|
||
</template>
|
||
<template v-if="step === 2"
|
||
><el-descriptions :column="1" border
|
||
><el-descriptions-item label="本地账号"
|
||
>{{ selected?.account }} #{{ selected?.id }}</el-descriptions-item
|
||
><el-descriptions-item label="变更类型">{{
|
||
titles[operation.kind]
|
||
}}</el-descriptions-item
|
||
><el-descriptions-item label="原 IAM 员工">{{
|
||
selected?.iam.employee?.username || '无'
|
||
}}</el-descriptions-item
|
||
><el-descriptions-item label="目标 IAM 员工">{{
|
||
operation.kind === 'unbind'
|
||
? '解除关联'
|
||
: operation.kind === 'create_and_bind'
|
||
? newEmployee.username
|
||
: chosenIdentity?.username
|
||
}}</el-descriptions-item
|
||
><el-descriptions-item label="预期版本">{{
|
||
operation.expected_version ?? '首次关联'
|
||
}}</el-descriptions-item></el-descriptions
|
||
><el-input
|
||
class="mt-4"
|
||
v-model="operation.reason"
|
||
:disabled="!!submittedPayload"
|
||
type="textarea"
|
||
:rows="3"
|
||
maxlength="500"
|
||
placeholder="必填:核对方式和变更原因,将写入审计记录"
|
||
/><el-checkbox class="mt-4" v-model="confirmed"
|
||
>我已核对本地账号与 IAM 员工为同一人,理解会话撤销影响</el-checkbox
|
||
></template
|
||
>
|
||
<el-alert
|
||
v-if="drawerError"
|
||
class="mt-4"
|
||
:title="drawerError"
|
||
type="error"
|
||
:closable="false"
|
||
/>
|
||
<el-alert
|
||
v-if="result"
|
||
class="mt-4"
|
||
:title="`操作 ${result.id}:${result.status}${result.error?.code ? ' · ' + identityError(result) : ''}`"
|
||
:type="result.status === 'succeeded' ? 'success' : 'warning'"
|
||
:closable="false"
|
||
/>
|
||
<div v-if="result?.reviewUrl" class="mt-4">
|
||
<a
|
||
:href="result.reviewUrl"
|
||
target="_blank"
|
||
rel="noopener noreferrer"
|
||
class="text-primary"
|
||
>中央复核 ↗</a
|
||
>
|
||
<p class="text-gray-500 mt-2">
|
||
由中央管理员完成近期验证并批准后,重试原操作;原目标、版本和原因保持不变。
|
||
</p>
|
||
</div>
|
||
<el-button
|
||
v-if="result && result.status !== 'succeeded'"
|
||
class="mt-4"
|
||
@click="refreshOperation"
|
||
>查询同一操作状态</el-button
|
||
>
|
||
</section>
|
||
<template #footer
|
||
><el-button @click="drawer = false">关闭</el-button
|
||
><el-button v-if="step > 0" :disabled="!!submittedPayload" @click="step--"
|
||
>上一步</el-button
|
||
><el-button
|
||
v-if="step < 2"
|
||
type="primary"
|
||
:disabled="step === 1 && !validIdentity"
|
||
@click="step++"
|
||
>下一步</el-button
|
||
><el-button
|
||
v-else
|
||
type="primary"
|
||
:loading="busy"
|
||
:disabled="
|
||
!confirmed || !operation.reason.trim() || result?.status === 'succeeded'
|
||
"
|
||
@click="submit"
|
||
>{{
|
||
result?.reviewUrl
|
||
? '完成中央复核后重试原操作'
|
||
: '确认' + titles[operation.kind]
|
||
}}</el-button
|
||
></template
|
||
>
|
||
</el-drawer>
|
||
<el-dialog v-model="reauthVisible" title="近期管理员身份验证" width="420px"
|
||
><el-input
|
||
v-model="password"
|
||
type="password"
|
||
show-password
|
||
placeholder="当前 ZYT 账号密码"
|
||
autocomplete="current-password"
|
||
@keyup.enter="reauth"
|
||
/>
|
||
<p class="mt-4 text-gray-500">
|
||
有效期 5 分钟。敏感目标还需中央管理员审核,此处不会越过审核。
|
||
</p>
|
||
<template #footer
|
||
><el-button type="primary" :loading="busy" @click="reauth"
|
||
>验证</el-button
|
||
></template
|
||
></el-dialog
|
||
>
|
||
<el-drawer v-model="auditVisible" title="关联审计" size="min(760px, 94vw)"
|
||
><el-table :data="audits"
|
||
><el-table-column prop="occurredAt" label="时间" min-width="170" /><el-table-column
|
||
prop="action"
|
||
label="操作" /><el-table-column label="操作人"
|
||
><template #default="{ row }">{{
|
||
typeof row.actor === 'string' ? row.actor : JSON.stringify(row.actor)
|
||
}}</template></el-table-column
|
||
><el-table-column prop="reason" label="原因" /></el-table
|
||
></el-drawer>
|
||
<el-dialog
|
||
v-model="batchVisible"
|
||
title="批量预检与确认"
|
||
width="min(920px, 94vw)"
|
||
:close-on-click-modal="false"
|
||
>
|
||
<el-alert
|
||
title="先预检,不会创建账号或修改绑定。仅选择 ready 项后显式确认;敏感账号与冲突项跳过。每批最多 100 条。"
|
||
type="info"
|
||
:closable="false"
|
||
/>
|
||
<el-input
|
||
v-model="batchText"
|
||
class="mt-4"
|
||
type="textarea"
|
||
:rows="7"
|
||
placeholder='[{"kind":"bind","user_id":42,"employee_id":"员工ID","reason":"核对后历史关联"}]'
|
||
/>
|
||
<el-button class="mt-4" :loading="busy" @click="preflight">只读预检</el-button>
|
||
<el-table
|
||
v-if="preview"
|
||
class="mt-4"
|
||
:data="preview.items"
|
||
@selection-change="(items: any[]) => (selectedIndexes = items.map((x) => x.index))"
|
||
><el-table-column
|
||
type="selection"
|
||
:selectable="(row: any) => row.status === 'ready'" /><el-table-column
|
||
prop="externalAccountId"
|
||
label="本地 ID" /><el-table-column prop="status" label="状态" /><el-table-column
|
||
prop="message"
|
||
label="结果"
|
||
/></el-table>
|
||
<el-checkbox v-if="preview" v-model="batchConfirmed" class="mt-4"
|
||
>确认仅执行已选择项目({{ selectedIndexes.length }} 条)</el-checkbox
|
||
>
|
||
<section v-if="job" class="mt-4">
|
||
<h3>任务 {{ job.id }} · {{ job.status }}</h3>
|
||
<el-table :data="job.items"
|
||
><el-table-column prop="externalAccountId" label="本地账号" /><el-table-column
|
||
prop="status"
|
||
label="状态"
|
||
/><el-table-column label="结果"
|
||
><template #default="{ row }">{{
|
||
row.error?.message || row.error?.code || '—'
|
||
}}</template></el-table-column
|
||
></el-table
|
||
><el-button @click="refreshJob">刷新任务</el-button
|
||
><el-button
|
||
:disabled="
|
||
!job.items?.some((x: any) => ['failed', 'pending'].includes(x.status))
|
||
"
|
||
@click="retryJob"
|
||
>只重试失败/待处理项</el-button
|
||
>
|
||
</section>
|
||
<template #footer
|
||
><el-button @click="batchVisible = false">关闭</el-button
|
||
><el-button
|
||
type="primary"
|
||
:loading="busy"
|
||
:disabled="
|
||
!preview?.previewId || !batchConfirmed || !selectedIndexes.length || !!job
|
||
"
|
||
@click="submitBatch"
|
||
>确认执行</el-button
|
||
></template
|
||
>
|
||
</el-dialog>
|
||
</div>
|
||
</template>
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, reactive, ref } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import { iamGet, iamPost, identityError, type IdentityOperation } from '@/api/iam-v2'
|
||
const states: Record<string, string> = {
|
||
verified: '已关联',
|
||
unlinked: '未关联',
|
||
revoked: '已撤销',
|
||
pending: '待确认',
|
||
conflict: '冲突',
|
||
unknown: '待核验'
|
||
}
|
||
const titles: Record<string, string> = {
|
||
bind: '关联',
|
||
create_and_bind: '创建并关联',
|
||
rebind: '换绑',
|
||
unbind: '解绑',
|
||
reconcile: '对账'
|
||
}
|
||
const enabled = ref(false),
|
||
reviewAllowed = ref(false),
|
||
managementEnabled = ref(false),
|
||
caps = ref<string[]>([]),
|
||
rows = ref<any[]>([]),
|
||
total = ref(0),
|
||
loading = ref(false),
|
||
busy = ref(false),
|
||
error = ref('')
|
||
const query = reactive({ q: '', state: '', page: 1, pageSize: 20 })
|
||
const drawer = ref(false),
|
||
step = ref(0),
|
||
selected = ref<any>(null),
|
||
identities = ref<any[]>([]),
|
||
identityQuery = ref(''),
|
||
chosenIdentity = ref<any>(null),
|
||
confirmed = ref(false),
|
||
drawerError = ref(''),
|
||
result = ref<any>(null)
|
||
const submittedPayload = ref<Record<string, unknown> | null>(null)
|
||
const operation = reactive<IdentityOperation>({ kind: 'bind', user_id: 0, reason: '' }),
|
||
newEmployee = reactive({ username: '', display_name: '', email: '' })
|
||
let operationKey = crypto.randomUUID(),
|
||
batchKey = crypto.randomUUID()
|
||
const reauthVisible = ref(false),
|
||
password = ref(''),
|
||
auditVisible = ref(false),
|
||
audits = ref<any[]>([])
|
||
const batchVisible = ref(false),
|
||
batchText = ref(''),
|
||
preview = ref<any>(null),
|
||
selectedIndexes = ref<number[]>([]),
|
||
batchConfirmed = ref(false),
|
||
job = ref<any>(null)
|
||
const can = (c: string) => caps.value.includes(c) && (c === 'read' || managementEnabled.value)
|
||
const validIdentity = computed(
|
||
() =>
|
||
operation.kind === 'unbind' ||
|
||
(operation.kind === 'create_and_bind'
|
||
? !!newEmployee.username.trim() && !!newEmployee.display_name.trim()
|
||
: !!operation.employee_id)
|
||
)
|
||
async function load() {
|
||
loading.value = true
|
||
try {
|
||
const r = await iamGet('/accounts', query)
|
||
rows.value = r.items
|
||
total.value = r.total
|
||
error.value = ''
|
||
} catch (e) {
|
||
error.value = identityError(e)
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
function reload() {
|
||
query.page = 1
|
||
void load()
|
||
}
|
||
function open(row: any, kind: IdentityOperation['kind']) {
|
||
if (kind === 'bind' && row.iam.state === 'revoked') kind = 'rebind'
|
||
selected.value = row
|
||
Object.assign(operation, {
|
||
kind,
|
||
user_id: row.id,
|
||
employee_id: undefined,
|
||
expected_version: row.iam.binding?.version,
|
||
reason: ''
|
||
})
|
||
Object.assign(newEmployee, { username: '', display_name: row.name, email: '' })
|
||
drawer.value = true
|
||
step.value = 0
|
||
confirmed.value = false
|
||
drawerError.value = ''
|
||
result.value = null
|
||
submittedPayload.value = null
|
||
chosenIdentity.value = null
|
||
identities.value = []
|
||
operationKey = crypto.randomUUID()
|
||
}
|
||
async function more(row: any, kind: string) {
|
||
if (kind === 'audit') {
|
||
try {
|
||
audits.value = (await iamGet(`/accounts/${row.id}/audit`)).items
|
||
auditVisible.value = true
|
||
} catch (e) {
|
||
error.value = identityError(e)
|
||
}
|
||
} else open(row, kind as IdentityOperation['kind'])
|
||
}
|
||
async function searchIdentities() {
|
||
try {
|
||
identities.value = (
|
||
await iamGet('/identities', { q: identityQuery.value, page: 1, pageSize: 20 })
|
||
).items
|
||
} catch (e) {
|
||
drawerError.value = identityError(e)
|
||
}
|
||
}
|
||
function choose(row: any) {
|
||
if (row?.status === 'active') {
|
||
chosenIdentity.value = row
|
||
operation.employee_id = row.id
|
||
}
|
||
}
|
||
async function submit() {
|
||
busy.value = true
|
||
try {
|
||
if (!submittedPayload.value) {
|
||
submittedPayload.value = JSON.parse(
|
||
JSON.stringify({
|
||
...operation,
|
||
...(operation.kind === 'create_and_bind'
|
||
? { new_employee: { ...newEmployee } }
|
||
: {})
|
||
})
|
||
)
|
||
}
|
||
result.value = await iamPost('/operations', submittedPayload.value!, operationKey)
|
||
drawerError.value = ''
|
||
await load()
|
||
} catch (e) {
|
||
drawerError.value = identityError(e)
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
async function refreshOperation() {
|
||
try {
|
||
result.value = await iamGet(`/operations/${result.value.id}`)
|
||
await load()
|
||
} catch (e) {
|
||
drawerError.value = identityError(e)
|
||
}
|
||
}
|
||
async function reauth() {
|
||
busy.value = true
|
||
try {
|
||
await iamPost('/reauth', { password: password.value })
|
||
reauthVisible.value = false
|
||
ElMessage.success('身份已验证,有效期 5 分钟')
|
||
await load()
|
||
} catch (e) {
|
||
error.value = identityError(e)
|
||
} finally {
|
||
password.value = ''
|
||
busy.value = false
|
||
}
|
||
}
|
||
async function preflight() {
|
||
busy.value = true
|
||
preview.value = null
|
||
job.value = null
|
||
batchConfirmed.value = false
|
||
selectedIndexes.value = []
|
||
try {
|
||
const items = JSON.parse(batchText.value)
|
||
if (!Array.isArray(items) || items.length < 1 || items.length > 100) throw Error('input')
|
||
preview.value = await iamPost('/batch/preflight', { items })
|
||
batchKey = crypto.randomUUID()
|
||
} catch (e) {
|
||
error.value = e instanceof SyntaxError ? '批量输入必须是 JSON 数组。' : identityError(e)
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
async function submitBatch() {
|
||
busy.value = true
|
||
try {
|
||
job.value = await iamPost(
|
||
'/batch',
|
||
{ preview_id: preview.value.previewId, indexes: selectedIndexes.value },
|
||
batchKey
|
||
)
|
||
await load()
|
||
} catch (e) {
|
||
error.value = identityError(e)
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
async function refreshJob() {
|
||
try {
|
||
job.value = await iamGet(`/jobs/${job.value.id}`)
|
||
await load()
|
||
} catch (e) {
|
||
error.value = identityError(e)
|
||
}
|
||
}
|
||
async function retryJob() {
|
||
busy.value = true
|
||
try {
|
||
job.value = await iamPost(`/jobs/${job.value.id}/retry`)
|
||
await load()
|
||
} catch (e) {
|
||
error.value = identityError(e)
|
||
} finally {
|
||
busy.value = false
|
||
}
|
||
}
|
||
onMounted(async () => {
|
||
try {
|
||
const s = await iamGet('/status')
|
||
enabled.value = s.enabled
|
||
caps.value = s.management_capabilities || []
|
||
reviewAllowed.value = s.protected_review_operator === true
|
||
managementEnabled.value = s.management_enabled === true
|
||
if (enabled.value && can('read')) await load()
|
||
} catch (e) {
|
||
error.value = identityError(e)
|
||
}
|
||
})
|
||
</script>
|
||
<style scoped>
|
||
.identity-management p {
|
||
line-height: 1.7;
|
||
}
|
||
.identity-management :deep(.el-steps) {
|
||
margin-bottom: 24px;
|
||
}
|
||
</style>
|