fix(auth): 重构登录认证,并支持跳转到关联服务如图纸标注
This commit is contained in:
1 parent
ce1fd59f61
commit
affe139bf9
51 files changed
+1939
-132
No files matched your search
@@ -1,54 +1,63 @@
|
||||
<!--
|
||||
features/sso/components/ExternalSystemLinks.vue
|
||||
用途:在 HXOPS 已登录页面展示已配置产品内平级服务入口。
|
||||
依赖:SSO 应用目录 API、lucide-vue-next。
|
||||
逻辑:点击后先打开 HXOPS 同源 launch 页以继承当前登录态,再由 launch 页跳平级服务生成签名 state。
|
||||
用途:在 HXOPS 已登录页面展示关联服务与产品内 SSO 平级服务入口。
|
||||
依赖:linked-nav.store、lucide-vue-next。
|
||||
逻辑:读 Pinia 缓存即时渲染;未缓存时触发一次预取。工作台可通过 buttonClass/iconClass 对齐 ws-nav-btn。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue';
|
||||
import { computed, onMounted } from 'vue';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ExternalLink } from 'lucide-vue-next';
|
||||
import { listSsoApplications, type SsoApplication } from '../api/sso.api';
|
||||
import { useLinkedNavStore } from '../stores/linked-nav.store';
|
||||
|
||||
withDefaults(defineProps<{
|
||||
const props = withDefaults(defineProps<{
|
||||
compact?: boolean;
|
||||
showLabel?: boolean;
|
||||
/** 覆盖按钮样式(如工作台 ws-nav-btn),未传时用紧凑/默认样式 */
|
||||
buttonClass?: string;
|
||||
/** 覆盖图标尺寸类,未传时随 compact 变化 */
|
||||
iconClass?: string;
|
||||
}>(), {
|
||||
compact: false,
|
||||
showLabel: true,
|
||||
buttonClass: '',
|
||||
iconClass: '',
|
||||
});
|
||||
|
||||
const applications = ref<SsoApplication[]>([]);
|
||||
const linkedNav = useLinkedNavStore();
|
||||
const { items } = storeToRefs(linkedNav);
|
||||
|
||||
/** 加载已启用应用;目录不可用时隐藏入口,不阻断 HXOPS 主业务。 */
|
||||
async function loadApplications(): Promise<void> {
|
||||
try {
|
||||
applications.value = await listSsoApplications();
|
||||
} catch (error) {
|
||||
console.warn('[sso] failed to load peer services', error);
|
||||
/**
|
||||
* 解析按钮 class。
|
||||
* 核心逻辑:外部传入优先;compact 默认与 Chat 底栏图标按钮一致(无额外 36px 盒子,避免错位)。
|
||||
*/
|
||||
const resolvedButtonClass = computed(() => {
|
||||
if (props.buttonClass) return props.buttonClass;
|
||||
if (props.compact) {
|
||||
return 'inline-flex items-center justify-center transition-colors hover:text-secondary';
|
||||
}
|
||||
}
|
||||
return 'inline-flex items-center justify-center gap-2 rounded-xl px-3 py-2 text-sm text-muted transition-colors hover:bg-surface-soft hover:text-secondary min-h-9';
|
||||
});
|
||||
|
||||
/** 在新标签先打开同源中转页,确保非 remember 登录态也可继承到新标签。 */
|
||||
function openApplication(application: SsoApplication): void {
|
||||
window.open(`/sso/launch?app=${encodeURIComponent(application.key)}`, '_blank');
|
||||
}
|
||||
/** 解析图标 class:默认 16px,与 Chat 底栏 Moon/Briefcase 一致。 */
|
||||
const resolvedIconClass = computed(() => props.iconClass || 'h-4 w-4 shrink-0');
|
||||
|
||||
onMounted(() => {
|
||||
void loadApplications();
|
||||
// 已缓存则立即展示;未缓存时补一次预取(登录后 App 通常已预取)。
|
||||
void linkedNav.ensureLoaded();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<template v-for="application in applications" :key="application.key">
|
||||
<template v-for="entry in items" :key="entry.key">
|
||||
<button
|
||||
type="button"
|
||||
class="inline-flex items-center justify-center gap-2 rounded-xl text-muted transition-colors hover:bg-surface-soft hover:text-secondary"
|
||||
:class="compact ? 'h-9 w-9' : 'min-h-9 px-3 py-2 text-sm'"
|
||||
:title="application.display_name"
|
||||
@click="openApplication(application)"
|
||||
:class="resolvedButtonClass"
|
||||
:title="entry.display_name"
|
||||
@click="linkedNav.openItem(entry)"
|
||||
>
|
||||
<ExternalLink class="h-4 w-4 shrink-0" />
|
||||
<span v-if="showLabel && !compact" class="truncate">{{ application.display_name }}</span>
|
||||
<ExternalLink :class="resolvedIconClass" />
|
||||
<span v-if="showLabel && !compact" class="truncate">{{ entry.display_name }}</span>
|
||||
</button>
|
||||
</template>
|
||||
</template>
|
||||
Reference in new issue
Block a user