跟新
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
import request from '@/utils/request'
|
||||
export type IdentityOperation = {
|
||||
kind: 'bind' | 'create_and_bind' | 'unbind' | 'rebind' | 'reconcile'
|
||||
user_id: number
|
||||
employee_id?: string
|
||||
expected_version?: number
|
||||
new_employee?: { username: string; display_name: string; email?: string }
|
||||
reason: string
|
||||
}
|
||||
const prefix = '/iam/v2'
|
||||
const opts = { isOpenRetry: false, ignoreCancelToken: true }
|
||||
export const iamGet = (path: string, params?: Record<string, unknown>): Promise<any> =>
|
||||
request.get({ url: prefix + path, params, withCredentials: true }, opts)
|
||||
export const iamPost = (
|
||||
path: string,
|
||||
params: Record<string, unknown> = {},
|
||||
key = crypto.randomUUID()
|
||||
): Promise<any> =>
|
||||
request.post(
|
||||
{ url: prefix + path, params, headers: { 'Idempotency-Key': key }, withCredentials: true },
|
||||
opts
|
||||
)
|
||||
export const identityError = (e: any): string =>
|
||||
({
|
||||
REAUTH_REQUIRED: '请先验证当前账号密码,或通过企业微信重新登录。',
|
||||
ACCOUNT_MISMATCH: '两端账号不一致,请确认身份后重新发起。',
|
||||
NOT_LINKED: '当前账号还未关联 IAM。',
|
||||
NOT_AUTHORIZED: 'IAM 尚未授予目标应用访问权限。',
|
||||
BINDING_CONFLICT: '关联已变更,请刷新后重新确认。',
|
||||
PROTECTED_ACCOUNT_REVIEW_REQUIRED: '敏感账号需要双侧近期管理员核验,请由统一身份平台审核。',
|
||||
SERVICE_UNAVAILABLE: '统一身份服务暂时不可用,状态未确认,请稍后重试。',
|
||||
FEATURE_DISABLED: 'IAM 关联管理尚未启用。',
|
||||
FORBIDDEN: '没有当前操作权限或目标超出数据范围。',
|
||||
TRANSACTION_EXPIRED: '验证已过期或已经使用,请重新发起。'
|
||||
})[e?.error?.code as string] ||
|
||||
e?.error?.code ||
|
||||
'操作未完成,请刷新状态后重试。'
|
||||
@@ -0,0 +1,33 @@
|
||||
<template>
|
||||
<el-button v-if="enabled" text :loading="busy" @click="launch">进入甄美 ERP ↗</el-button>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { ElMessage } from 'element-plus'
|
||||
import { iamGet, iamPost, identityError } from '@/api/iam-v2'
|
||||
const enabled = ref(false),
|
||||
busy = ref(false)
|
||||
onMounted(async () => {
|
||||
try {
|
||||
const status = await iamGet('/status')
|
||||
enabled.value = !!status.enabled && status.launch_enabled === true
|
||||
} catch {
|
||||
enabled.value = false
|
||||
}
|
||||
})
|
||||
async function launch() {
|
||||
const tab = window.open('about:blank', '_blank')
|
||||
if (tab) tab.opener = null
|
||||
busy.value = true
|
||||
try {
|
||||
const r = await iamPost('/launch/start')
|
||||
if (tab) tab.location.href = r.url
|
||||
else ElMessage.warning('请允许新标签页后再试。')
|
||||
} catch (e) {
|
||||
tab?.close()
|
||||
ElMessage.warning(identityError(e))
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
</script>
|
||||
@@ -0,0 +1,137 @@
|
||||
<template>
|
||||
<el-card v-if="status?.enabled || error" class="mt-4" shadow="never">
|
||||
<template #header
|
||||
><strong>统一身份 IAM</strong
|
||||
><el-button class="float-right" text @click="refresh">刷新状态</el-button></template
|
||||
>
|
||||
<el-alert v-if="error" :title="error" type="warning" :closable="false" class="mb-4" />
|
||||
<p>
|
||||
关联状态:<el-tag :type="linked ? 'success' : 'info'">{{
|
||||
linked ? '已关联' : status.binding?.state === 'revoked' ? '关联已撤销' : '未关联'
|
||||
}}</el-tag>
|
||||
</p>
|
||||
<p v-if="status.employee" class="my-3">
|
||||
IAM 员工:{{ status.employee.displayName }}({{ status.employee.username }})
|
||||
</p>
|
||||
<p class="my-3 text-gray-500">
|
||||
关联只确认同一人的身份,不会复制业务角色或自动授予其他平台权限。
|
||||
</p>
|
||||
<el-alert
|
||||
v-if="!linked && status.protected_account"
|
||||
class="mb-4"
|
||||
type="warning"
|
||||
:closable="false"
|
||||
title="此账号属于敏感账号,请由本地管理员在 IAM 关联管理发起单人中央复核,不使用个人自助绑定。"
|
||||
/>
|
||||
<div class="flex flex-wrap gap-3">
|
||||
<el-button @click="reauthVisible = true">验证当前身份</el-button>
|
||||
<el-button @click="wecomRelogin">企业微信重新登录</el-button>
|
||||
<el-button
|
||||
v-if="!linked && !status.protected_account && status.management_enabled"
|
||||
type="primary"
|
||||
:loading="busy"
|
||||
@click="navigate('/self-link/start')"
|
||||
>关联已有 IAM 账号</el-button
|
||||
>
|
||||
<el-button
|
||||
v-if="linked && status.management_enabled && status.employee?.passwordSetupPending"
|
||||
type="primary"
|
||||
:loading="busy"
|
||||
@click="navigate('/password-setup')"
|
||||
>设置 IAM 登录密码</el-button
|
||||
>
|
||||
<el-button v-if="linked && status.launch_enabled" :loading="busy" @click="launch">进入甄美 ERP ↗</el-button>
|
||||
</div>
|
||||
<el-dialog
|
||||
v-model="reauthVisible"
|
||||
title="验证当前 ZYT 身份"
|
||||
width="420px"
|
||||
:close-on-click-modal="false"
|
||||
>
|
||||
<el-form @submit.prevent="reauth"
|
||||
><el-form-item label="当前密码"
|
||||
><el-input
|
||||
v-model="password"
|
||||
type="password"
|
||||
show-password
|
||||
autocomplete="current-password"
|
||||
@keyup.enter="reauth" /></el-form-item
|
||||
></el-form>
|
||||
<p class="text-gray-500">
|
||||
仅验证当前账号,验证有效期 5 分钟。密码不会被保存或传给 IAM。
|
||||
</p>
|
||||
<template #footer
|
||||
><el-button @click="cancelReauth">取消</el-button
|
||||
><el-button type="primary" :loading="busy" @click="reauth"
|
||||
>验证</el-button
|
||||
></template
|
||||
>
|
||||
</el-dialog>
|
||||
</el-card>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from 'vue'
|
||||
import { iamGet, iamPost, identityError } from '@/api/iam-v2'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
const status = ref<any>({ enabled: false }),
|
||||
error = ref(''),
|
||||
busy = ref(false),
|
||||
reauthVisible = ref(false),
|
||||
password = ref('')
|
||||
const linked = computed(() => status.value?.binding?.state === 'verified')
|
||||
async function refresh() {
|
||||
try {
|
||||
status.value = await iamGet('/status')
|
||||
error.value = ''
|
||||
} catch (e) {
|
||||
error.value = identityError(e)
|
||||
}
|
||||
}
|
||||
function cancelReauth() {
|
||||
reauthVisible.value = false
|
||||
password.value = ''
|
||||
}
|
||||
async function reauth() {
|
||||
busy.value = true
|
||||
try {
|
||||
await iamPost('/reauth', { password: password.value })
|
||||
reauthVisible.value = false
|
||||
await refresh()
|
||||
} catch (e) {
|
||||
error.value = identityError(e)
|
||||
} finally {
|
||||
password.value = ''
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
async function navigate(path: string) {
|
||||
busy.value = true
|
||||
try {
|
||||
const r = await iamPost(path)
|
||||
window.location.assign(r.url)
|
||||
} catch (e) {
|
||||
error.value = identityError(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
async function launch() {
|
||||
const tab = window.open('about:blank', '_blank')
|
||||
if (tab) tab.opener = null
|
||||
busy.value = true
|
||||
try {
|
||||
const r = await iamPost('/launch/start')
|
||||
if (tab) tab.location.href = r.url
|
||||
else error.value = '请允许浏览器打开新标签页后再试。'
|
||||
} catch (e) {
|
||||
tab?.close()
|
||||
error.value = identityError(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
async function wecomRelogin() {
|
||||
await useUserStore().logout()
|
||||
}
|
||||
onMounted(refresh)
|
||||
</script>
|
||||
@@ -0,0 +1,93 @@
|
||||
<template>
|
||||
<main class="min-h-screen flex items-center justify-center bg-page p-6">
|
||||
<el-card class="w-full max-w-xl" shadow="never">
|
||||
<h1 class="text-xl font-semibold mb-4">统一身份进入甄养堂</h1>
|
||||
<p v-if="busy" class="text-gray-500">正在核验同一身份,请稍候…</p>
|
||||
<el-alert v-if="error" :title="error" type="warning" :closable="false" show-icon />
|
||||
<p class="text-gray-500 my-4">
|
||||
已有 ZYT 账号将进行一致性检查。系统不会自动替换当前已登录的人。
|
||||
</p>
|
||||
<div v-if="error" class="flex flex-wrap gap-3">
|
||||
<el-button v-if="restartUrl" type="primary" @click="back"
|
||||
>返回 IAM 重新发起</el-button
|
||||
>
|
||||
<el-button v-if="restartUrl" :loading="busy" @click="switchAccount"
|
||||
>退出当前 ZYT 身份并返回 IAM</el-button
|
||||
>
|
||||
<router-link to="/login"><el-button>使用原登录方式</el-button></router-link>
|
||||
</div>
|
||||
</el-card>
|
||||
</main>
|
||||
</template>
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { iamGet, iamPost, identityError } from '@/api/iam-v2'
|
||||
import useUserStore from '@/stores/modules/user'
|
||||
import { clearAuthInfo } from '@/utils/auth'
|
||||
import feedback from '@/utils/feedback'
|
||||
const route = useRoute(),
|
||||
router = useRouter(),
|
||||
store = useUserStore()
|
||||
const busy = ref(true),
|
||||
error = ref(''),
|
||||
restartUrl = ref('')
|
||||
let handled = false
|
||||
const text = (v: unknown) => (typeof v === 'string' ? v : '')
|
||||
function back() {
|
||||
if (restartUrl.value) window.location.assign(restartUrl.value)
|
||||
}
|
||||
async function switchAccount() {
|
||||
await feedback.confirm(
|
||||
'确认退出当前浏览器的 ZYT 身份?其他平台和其他浏览器不受影响。请回 IAM 重新发起。'
|
||||
)
|
||||
busy.value = true
|
||||
try {
|
||||
await iamPost('/launch/reset')
|
||||
clearAuthInfo()
|
||||
back()
|
||||
} catch (e) {
|
||||
error.value = identityError(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
}
|
||||
onMounted(async () => {
|
||||
if (handled) return
|
||||
handled = true
|
||||
const ticket = text(route.query.ticket),
|
||||
source = text(route.query.source),
|
||||
intent = text(route.query.intent),
|
||||
issue = text(route.query.iam_error)
|
||||
// Strip one-use material before any network/async work; never retain it in history.
|
||||
window.history.replaceState(window.history.state, '', window.location.pathname)
|
||||
try {
|
||||
const config = await iamGet('/launch/config', { source })
|
||||
restartUrl.value = config.restart_url || ''
|
||||
if (!config.enabled) throw { error: { code: 'FEATURE_DISABLED' } }
|
||||
if (issue) throw { error: { code: issue } }
|
||||
if (ticket) {
|
||||
const result = await store.iamLaunchLogin(ticket)
|
||||
await router.replace(
|
||||
result.is_paw === 0
|
||||
? '/change-password'
|
||||
: result.need_bind_work_wechat
|
||||
? '/bind-work-wechat'
|
||||
: '/'
|
||||
)
|
||||
} else {
|
||||
if (
|
||||
!['iam-admin', 'iam-portal'].includes(source) ||
|
||||
!/^[A-Za-z0-9_-]{32,256}$/.test(intent)
|
||||
)
|
||||
throw { error: { code: 'INVALID_REQUEST' } }
|
||||
const result = await iamPost('/launch/prepare', { source, intent })
|
||||
window.location.assign(result.url)
|
||||
}
|
||||
} catch (e) {
|
||||
error.value = identityError(e)
|
||||
} finally {
|
||||
busy.value = false
|
||||
}
|
||||
})
|
||||
</script>
|
||||
@@ -0,0 +1,723 @@
|
||||
<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="部门" min-width="140" show-overflow-tooltip>
|
||||
<template #default="{ row }">{{ departmentText(row) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="本地状态" width="110"
|
||||
><template #default="{ row }"
|
||||
><el-tag :type="isLocalDisabled(row) ? 'danger' : 'success'">{{
|
||||
isLocalDisabled(row) ? '停用' : 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="应用访问状态" width="130">
|
||||
<template #default="{ row }">
|
||||
<el-tag :type="applicationAccess(row).type">{{
|
||||
applicationAccess(row).text
|
||||
}}</el-tag>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="最近校验时间" min-width="190">
|
||||
<template #default="{ row }">{{ checkedAtText(row.iam?.checked_at) }}</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" min-width="210"
|
||||
><template #default="{ row }">
|
||||
<el-button
|
||||
link
|
||||
type="primary"
|
||||
:disabled="
|
||||
isLocalDisabled(row) ||
|
||||
(!!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="
|
||||
isLocalDisabled(row) ||
|
||||
(!!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="
|
||||
isLocalDisabled(row) ||
|
||||
(!!row.root && !reviewAllowed) ||
|
||||
!can('rebind')
|
||||
"
|
||||
>换绑</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item
|
||||
command="unbind"
|
||||
:disabled="
|
||||
isLocalDisabled(row) ||
|
||||
(!!row.root && !reviewAllowed) ||
|
||||
!can('unbind')
|
||||
"
|
||||
>解绑</el-dropdown-item
|
||||
>
|
||||
<el-dropdown-item command="audit">审计记录</el-dropdown-item>
|
||||
</el-dropdown-menu></template
|
||||
></el-dropdown
|
||||
>
|
||||
<div v-if="isLocalDisabled(row)" class="text-xs text-gray-500 mt-1">
|
||||
本地账号已停用,关联操作不可用;审计记录仍可查看。
|
||||
</div>
|
||||
</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="
|
||||
isLocalDisabled(selected) ||
|
||||
!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)
|
||||
)
|
||||
function isLocalDisabled(row: any): boolean {
|
||||
return row?.disable === true || row?.disable === 1 || row?.disable === '1'
|
||||
}
|
||||
function departmentText(row: any): string {
|
||||
if (!Array.isArray(row?.dept_names)) return '未知'
|
||||
if (row.dept_names.length === 0) return '未分配'
|
||||
if (!row.dept_names.every((name: unknown) => typeof name === 'string' && name.trim()))
|
||||
return '未知'
|
||||
return row.dept_names.map((name: string) => name.trim()).join('、')
|
||||
}
|
||||
function applicationAccess(row: any): {
|
||||
text: string
|
||||
type: 'success' | 'warning' | 'info' | 'danger'
|
||||
} {
|
||||
const iam = row?.iam
|
||||
const reason = iam?.access?.reason
|
||||
if (['SERVICE_UNAVAILABLE', 'STATUS_UNAVAILABLE'].includes(reason)) {
|
||||
return { text: '服务异常', type: 'warning' }
|
||||
}
|
||||
if (reason === 'NOT_AUTHORIZED') return { text: '未授权', type: 'warning' }
|
||||
if (reason === 'ACCOUNT_DISABLED') return { text: 'IAM账号停用', type: 'danger' }
|
||||
if (reason === 'BINDING_CONFLICT') return { text: '关联冲突', type: 'warning' }
|
||||
if (reason === 'ACCOUNT_MISMATCH') return { text: '身份不匹配', type: 'warning' }
|
||||
if (
|
||||
['unlinked', 'revoked'].includes(iam?.state) ||
|
||||
['NOT_LINKED', 'LOCAL_ACCOUNT_LINK_REQUIRED', 'BINDING_REVOKED'].includes(reason)
|
||||
) {
|
||||
return { text: '未关联', type: 'info' }
|
||||
}
|
||||
if (iam?.access?.allowed === false) return { text: '未授权', type: 'warning' }
|
||||
if (iam?.state === 'verified' && iam?.access?.allowed === true) {
|
||||
return { text: '已授权', type: 'success' }
|
||||
}
|
||||
return { text: '未知', type: 'info' }
|
||||
}
|
||||
function checkedAtText(value: unknown): string {
|
||||
if (value == null || value === '' || value === 0 || value === '0') return '未校验'
|
||||
const seconds = typeof value === 'number' || typeof value === 'string' ? Number(value) : NaN
|
||||
if (!Number.isInteger(seconds) || seconds <= 0 || seconds > 253402300799) return '未知'
|
||||
return new Date(seconds * 1000).toLocaleString('zh-CN', {
|
||||
timeZone: 'Asia/Shanghai',
|
||||
year: 'numeric',
|
||||
month: '2-digit',
|
||||
day: '2-digit',
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: false
|
||||
})
|
||||
}
|
||||
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 (isLocalDisabled(row)) {
|
||||
ElMessage.warning('本地账号已停用,请先启用账号后再维护关联。')
|
||||
return
|
||||
}
|
||||
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() {
|
||||
if (isLocalDisabled(selected.value)) {
|
||||
drawerError.value = '本地账号已停用,请先启用账号后再维护关联。'
|
||||
return
|
||||
}
|
||||
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>
|
||||
Reference in New Issue
Block a user