215 lines
8.3 KiB
Vue
215 lines
8.3 KiB
Vue
<template>
|
||
<section class="card p-5">
|
||
<div class="mb-4 flex items-start justify-between gap-3">
|
||
<div>
|
||
<h3 class="flex items-center gap-2 text-sm font-semibold text-gray-900 dark:text-white">
|
||
{{ t('hub.title') }}
|
||
<span v-if="status?.forced_off" class="badge badge-amber">{{ t('hub.forcedOff') }}</span>
|
||
<span v-else class="badge" :class="status?.enabled ? 'badge-success' : 'badge-gray'">
|
||
{{ status?.enabled ? t('hub.enabled') : t('hub.disabled') }}
|
||
</span>
|
||
</h3>
|
||
<p class="mt-1 text-xs leading-relaxed text-gray-400">{{ t('hub.hint') }}</p>
|
||
</div>
|
||
<div class="flex flex-shrink-0 items-center gap-2">
|
||
<button
|
||
v-if="authStore.can('system:setting')"
|
||
type="button"
|
||
class="btn btn-ghost btn-sm"
|
||
:disabled="probing"
|
||
@click="testConnection"
|
||
>
|
||
<Icon name="bolt" class="mr-1 h-4 w-4" :class="probing ? 'animate-spin' : ''" />
|
||
{{ probing ? t('hub.probing') : t('hub.testConnection') }}
|
||
</button>
|
||
</div>
|
||
</div>
|
||
|
||
<p
|
||
v-if="status?.forced_off"
|
||
class="mb-4 rounded-xl bg-amber-50 px-4 py-3 text-xs text-amber-700 dark:bg-amber-900/20 dark:text-amber-400"
|
||
>
|
||
{{ status.forced_off_reason }}
|
||
</p>
|
||
|
||
<div class="grid grid-cols-1 gap-3 sm:grid-cols-2 lg:grid-cols-3">
|
||
<div
|
||
v-for="row in rows"
|
||
:key="row.label"
|
||
class="rounded-xl border border-gray-200 px-4 py-3 dark:border-dark-600"
|
||
>
|
||
<p class="text-xs text-gray-400">{{ row.label }}</p>
|
||
<p class="mt-1 truncate text-sm font-medium text-gray-900 dark:text-dark-100" :title="row.tip || row.value">
|
||
{{ row.value }}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
<div v-if="probeResult" class="mt-4 space-y-1.5">
|
||
<p class="text-sm font-medium" :class="probeResult.ok ? 'text-emerald-600' : 'text-red-600'">
|
||
{{ probeResult.message }}
|
||
</p>
|
||
<p v-for="step in probeResult.steps" :key="step.name" class="flex items-start gap-2 text-xs text-gray-500 dark:text-dark-400">
|
||
<Icon
|
||
:name="step.ok ? 'checkCircle' : 'xCircle'"
|
||
class="mt-0.5 h-3.5 w-3.5 flex-shrink-0"
|
||
:class="step.ok ? 'text-emerald-500' : 'text-red-500'"
|
||
/>
|
||
<span>{{ step.name }}:{{ step.detail }}</span>
|
||
</p>
|
||
</div>
|
||
|
||
<div v-if="status?.enabled && authStore.can('org:person')" class="mt-4 flex flex-wrap items-center gap-3">
|
||
<HubSyncButton @synced="reload" />
|
||
</div>
|
||
<p v-else-if="status && !status.configured" class="mt-4 rounded-xl bg-amber-50 px-4 py-3 text-xs text-amber-700 dark:bg-amber-900/20 dark:text-amber-400">
|
||
{{ t('hub.notConfigured') }}
|
||
</p>
|
||
|
||
<p class="mt-4 text-[11px] leading-4 text-gray-400">
|
||
{{ t('hub.configFileHint') }}
|
||
<code class="rounded bg-gray-100 px-1.5 py-0.5 font-mono text-[11px] dark:bg-dark-700">
|
||
{{ status?.config_file || '--' }}
|
||
</code>
|
||
</p>
|
||
<p class="mt-1 text-[11px] leading-4 text-gray-400">{{ t('hub.configEditableHint') }}</p>
|
||
</section>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, onMounted, ref } from 'vue'
|
||
import { useI18n } from 'vue-i18n'
|
||
import Icon from '@/components/icons/Icon.vue'
|
||
import HubSyncButton from '@/components/oa/HubSyncButton.vue'
|
||
import { hubAPI } from '@/api'
|
||
import type { HubChangesStatus, HubProbe, HubSsoStatus, HubStatus } from '@/api/hub'
|
||
import { useAuthStore } from '@/stores/auth'
|
||
import { runAction } from '@/utils/oa'
|
||
|
||
const { t } = useI18n()
|
||
const authStore = useAuthStore()
|
||
|
||
const status = ref<HubStatus | null>(null)
|
||
const probeResult = ref<HubProbe | null>(null)
|
||
const probing = ref(false)
|
||
|
||
const rows = computed(() => {
|
||
const current = status.value
|
||
if (!current) return []
|
||
const run = current.last_run
|
||
return [
|
||
{ label: t('hub.loginMode'), value: loginModeLabel(current.login_mode) },
|
||
{ label: t('hub.baseUrl'), value: current.base_url || '--' },
|
||
// 九个接口路径都是配置项;这里摆最常排障的目录接口,悬停看全九个
|
||
{
|
||
label: t('hub.directoryPath'),
|
||
value: current.api_paths?.directory || '--',
|
||
tip: apiPathsTip(current),
|
||
},
|
||
{ label: t('hub.syncTime'), value: current.sync_enabled ? current.sync_time : t('hub.syncOff') },
|
||
{ label: t('hub.credential'), value: credentialLabel(current.credential, current.credential_label) },
|
||
{ label: t('hub.memberLimit'), value: String(current.member_limit) },
|
||
{ label: t('hub.lastSync'), value: run ? `${run.started_at}(${run.trigger_label})` : t('hub.never') },
|
||
{ label: t('hub.total'), value: String(current.total_users) },
|
||
{ label: t('hub.version'), value: String(current.permission_version) },
|
||
{ label: t('hub.autoProvision'), value: current.auto_provision ? t('common.yes') : t('common.no') },
|
||
// 免登与增量同步:登录与目录两条链路各自的"现在能不能用"
|
||
...(current.sso ? [ssoRow(current.sso)] : []),
|
||
...(current.changes ? [changesRow(current.changes)] : [])
|
||
]
|
||
})
|
||
|
||
// 免登通道:先说缺什么,再说没开,最后才是"能用 + 应用编码"
|
||
function ssoRow(sso: HubSsoStatus) {
|
||
let value: string
|
||
if (sso.missing.length) value = t('hub.ssoMissing', { items: sso.missing.join('、') })
|
||
else if (!sso.enabled) value = t('hub.ssoOff')
|
||
else value = t('hub.ssoActive', { code: sso.app_code || '--' })
|
||
return {
|
||
label: sso.only ? t('hub.ssoChannelOnly') : t('hub.ssoChannel'),
|
||
value,
|
||
// 回调地址摆在这儿是给管理员看的:Hub 上 launch_url / redirect_uris 要填的就是它,
|
||
// 后端回调那条走通了,门户送来的票据才不用经过浏览器脚本
|
||
tip: [
|
||
`${t('hub.ssoVerifyPath')}:${sso.verify_path}`,
|
||
`${t('hub.ssoPortal')}:${sso.portal_url || '--'}`,
|
||
`${t('hub.ssoCallback')}:${sso.callback_url || sso.callback_path || '--'}`,
|
||
`${t('hub.ssoCallbackAlias')}:${sso.alias_url || sso.alias_path || '--'}`
|
||
].join('\n')
|
||
}
|
||
}
|
||
|
||
// 增量同步:周期 + 游标走到哪、还差多少;上次报错挂在悬停提示里
|
||
function changesRow(changes: HubChangesStatus) {
|
||
if (!changes.enabled) return { label: t('hub.changes'), value: t('hub.changesOff') }
|
||
const cursor =
|
||
changes.cursor === null
|
||
? t('hub.changesUnaligned')
|
||
: `${changes.cursor}${changes.lag ? t('hub.changesLag', { value: changes.lag }) : t('hub.changesAligned')}`
|
||
return {
|
||
label: t('hub.changes'),
|
||
value: `${t('hub.changesEvery', { value: changes.interval_seconds })} · ${cursor}`,
|
||
tip: [
|
||
`${t('hub.changesPath')}:${changes.path}`,
|
||
`${t('hub.changesApplied')}:${changes.applied_total}`,
|
||
changes.poll_at ? `${t('hub.changesPollAt')}:${changes.poll_at}` : '',
|
||
changes.error ? `${t('hub.changesError')}:${changes.error}` : ''
|
||
]
|
||
.filter(Boolean)
|
||
.join('\n')
|
||
}
|
||
}
|
||
|
||
// 悬停提示:把当前在用的五个接口路径一次交代清楚,省得对着日志猜在打哪儿
|
||
function apiPathsTip(current: HubStatus): string {
|
||
const paths = current.api_paths
|
||
if (!paths) return ''
|
||
return [t('hub.apiPaths'), ...Object.values(paths)].join(' · ')
|
||
}
|
||
|
||
function loginModeLabel(mode: string): string {
|
||
if (mode === 'hub') return t('hub.modeHub')
|
||
if (mode === 'sso') return t('hub.modeSso')
|
||
if (mode === 'local') return t('hub.modeLocal')
|
||
return t('hub.modeHybrid')
|
||
}
|
||
|
||
// 后端把凭证方式连同中文说明一起返回(同步记录里也是同一套),本地只做兜底。
|
||
function credentialLabel(value: string, label?: string): string {
|
||
if (label) return label
|
||
if (value === 'directory_key') return t('hub.credentialDirectoryKey')
|
||
if (value === 'token') return t('hub.credentialToken')
|
||
if (value === 'account') return t('hub.credentialAccount')
|
||
if (value === 'anonymous') return t('hub.credentialAnonymous')
|
||
return t('hub.credentialNone')
|
||
}
|
||
|
||
async function reload() {
|
||
const data = await runAction(() => hubAPI.getStatus())
|
||
if (data) status.value = data
|
||
}
|
||
|
||
async function testConnection() {
|
||
probing.value = true
|
||
try {
|
||
probeResult.value = await hubAPI.probe()
|
||
} catch (error) {
|
||
probeResult.value = {
|
||
ok: false,
|
||
base_url: '',
|
||
login_enabled: false,
|
||
credential: '',
|
||
credential_label: '',
|
||
directory_needs_token: false,
|
||
member_limit: 0,
|
||
steps: [],
|
||
message: String((error as Error).message || error)
|
||
}
|
||
} finally {
|
||
probing.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(reload)
|
||
</script>
|