e7f9a6580a
Polish the role-aware UI surfaces wired up in #1303 so role / tenant context is discoverable from the main shell rather than buried in a hover-only switcher or the settings drawer. UserMenu sidebar trigger: - Replace username + email with `tenant name / username · role-icon role-name` so the active tenant + current role are always visible at the bottom of the sidebar; long usernames elide before the role label. - Single-tenant users keep the old username + email layout. UserMenu dropdown: - Promote the tenant switcher to a clickable header row at the top of the dropdown (tenant name + swap icon, role caption underneath). - Drop the standalone "Switch tenant" submenu entry — the header row hosts the same hover panel. - Switcher panel rows now lead the role label with a role icon (owner / admin / contributor / viewer) and surface the home tenant via a small home dot on the avatar instead of a separate badge, so the right-edge "current" badge column lines up across rows. Settings: - Add SECTION_MIN_ROLE so settings nav entries are gated by the same role matrix the backend enforces (chathistory + ollama + websearch + vectorstore + parser + storage + mcp → admin; api → owner; rest → viewer). UserMenu quickNav uses the same map. - Render a role-denied empty state when a user deep-links into a section their role can't reach. - Split account info (id / username / email / created_at) out of the owner-only API Info page into a new viewer-accessible UserProfile section. Composable: - New useRoleLabel composable centralises role → label and role → icon mapping (consumed by UserMenu trigger / dropdown / switcher panel). - useHomeTenant derives the home tenant id from `user.tenant_id` (the immutable signup-time field), not `tenant.id` which now reflects the active tenant after a switch. Lists: - KnowledgeBaseList / AgentList default the sidebar selection to "all" for viewers (who typically own nothing) so the empty "Mine" state no longer hides the shared content they actually have access to; contributor+ keeps "Mine" as the default. i18n: - Tenant role labels: 拥有者/贡献者/查看者 → 所有者/编辑/访客 (all four locales updated, plus new userProfile / roleDenied / homeBadge keys). The org-vs-tenant scope question raised during review is intentionally out of scope here — that needs an RFC before any UI/backend changes.
211 lines
4.8 KiB
Vue
211 lines
4.8 KiB
Vue
<template>
|
|
<div class="user-profile">
|
|
<div class="section-header">
|
|
<h2>{{ $t('userProfile.title') }}</h2>
|
|
<p class="section-description">{{ $t('userProfile.description') }}</p>
|
|
</div>
|
|
|
|
<!-- Loading -->
|
|
<div v-if="loading" class="loading-inline">
|
|
<t-loading size="small" />
|
|
<span>{{ $t('tenant.loadingInfo') }}</span>
|
|
</div>
|
|
|
|
<!-- Error -->
|
|
<div v-else-if="error" class="error-inline">
|
|
<t-alert theme="error" :message="error">
|
|
<template #operation>
|
|
<t-button size="small" @click="loadInfo">{{ $t('tenant.retry') }}</t-button>
|
|
</template>
|
|
</t-alert>
|
|
</div>
|
|
|
|
<!-- Content -->
|
|
<div v-else class="settings-group">
|
|
<!-- 用户 ID -->
|
|
<div class="setting-row">
|
|
<div class="setting-info">
|
|
<label>{{ $t('tenant.api.userIdLabel') }}</label>
|
|
<p class="desc">{{ $t('tenant.api.userIdDescription') }}</p>
|
|
</div>
|
|
<div class="setting-control">
|
|
<span class="info-value">{{ userInfo?.id || '-' }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 用户名 -->
|
|
<div class="setting-row">
|
|
<div class="setting-info">
|
|
<label>{{ $t('tenant.api.usernameLabel') }}</label>
|
|
<p class="desc">{{ $t('tenant.api.usernameDescription') }}</p>
|
|
</div>
|
|
<div class="setting-control">
|
|
<span class="info-value">{{ userInfo?.username || '-' }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 邮箱 -->
|
|
<div class="setting-row">
|
|
<div class="setting-info">
|
|
<label>{{ $t('tenant.api.emailLabel') }}</label>
|
|
<p class="desc">{{ $t('tenant.api.emailDescription') }}</p>
|
|
</div>
|
|
<div class="setting-control">
|
|
<span class="info-value">{{ userInfo?.email || '-' }}</span>
|
|
</div>
|
|
</div>
|
|
|
|
<!-- 注册时间 -->
|
|
<div class="setting-row">
|
|
<div class="setting-info">
|
|
<label>{{ $t('tenant.api.createdAtLabel') }}</label>
|
|
<p class="desc">{{ $t('tenant.api.createdAtDescription') }}</p>
|
|
</div>
|
|
<div class="setting-control">
|
|
<span class="info-value">{{ formatDate(userInfo?.created_at) }}</span>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup lang="ts">
|
|
import { ref, onMounted } from 'vue'
|
|
import { getCurrentUser, type UserInfo } from '@/api/auth'
|
|
import { useI18n } from 'vue-i18n'
|
|
|
|
const { t, locale } = useI18n()
|
|
|
|
const userInfo = ref<UserInfo | null>(null)
|
|
const loading = ref(true)
|
|
const error = ref('')
|
|
|
|
const loadInfo = async () => {
|
|
try {
|
|
loading.value = true
|
|
error.value = ''
|
|
const resp = await getCurrentUser()
|
|
if ((resp as any).success && resp.data) {
|
|
userInfo.value = resp.data.user
|
|
} else {
|
|
error.value = resp.message || t('tenant.messages.fetchFailed')
|
|
}
|
|
} catch (err: any) {
|
|
error.value = err?.message || t('tenant.messages.networkError')
|
|
} finally {
|
|
loading.value = false
|
|
}
|
|
}
|
|
|
|
const formatDate = (dateStr: string | undefined) => {
|
|
if (!dateStr) return t('tenant.unknown')
|
|
try {
|
|
const d = new Date(dateStr)
|
|
const fmt = new Intl.DateTimeFormat(locale.value || 'zh-CN', {
|
|
year: 'numeric',
|
|
month: '2-digit',
|
|
day: '2-digit',
|
|
hour: '2-digit',
|
|
minute: '2-digit',
|
|
})
|
|
return fmt.format(d)
|
|
} catch {
|
|
return t('tenant.formatError')
|
|
}
|
|
}
|
|
|
|
onMounted(loadInfo)
|
|
</script>
|
|
|
|
<style lang="less" scoped>
|
|
.user-profile {
|
|
width: 100%;
|
|
}
|
|
|
|
.section-header {
|
|
margin-bottom: 32px;
|
|
|
|
h2 {
|
|
font-size: 20px;
|
|
font-weight: 600;
|
|
color: var(--td-text-color-primary);
|
|
margin: 0 0 8px 0;
|
|
}
|
|
|
|
.section-description {
|
|
font-size: 14px;
|
|
color: var(--td-text-color-secondary);
|
|
margin: 0;
|
|
line-height: 1.5;
|
|
}
|
|
}
|
|
|
|
.loading-inline {
|
|
display: flex;
|
|
align-items: center;
|
|
gap: 12px;
|
|
padding: 40px 0;
|
|
justify-content: center;
|
|
color: var(--td-text-color-secondary);
|
|
font-size: 14px;
|
|
}
|
|
|
|
.error-inline {
|
|
padding: 20px 0;
|
|
}
|
|
|
|
.settings-group {
|
|
display: flex;
|
|
flex-direction: column;
|
|
gap: 0;
|
|
}
|
|
|
|
.setting-row {
|
|
display: flex;
|
|
align-items: flex-start;
|
|
justify-content: space-between;
|
|
padding: 20px 0;
|
|
border-bottom: 1px solid var(--td-component-stroke);
|
|
|
|
&:last-child {
|
|
border-bottom: none;
|
|
}
|
|
}
|
|
|
|
.setting-info {
|
|
flex: 1;
|
|
max-width: 65%;
|
|
padding-right: 24px;
|
|
|
|
label {
|
|
font-size: 15px;
|
|
font-weight: 500;
|
|
color: var(--td-text-color-primary);
|
|
display: block;
|
|
margin-bottom: 4px;
|
|
}
|
|
|
|
.desc {
|
|
font-size: 13px;
|
|
color: var(--td-text-color-secondary);
|
|
margin: 0;
|
|
line-height: 1.5;
|
|
}
|
|
}
|
|
|
|
.setting-control {
|
|
flex-shrink: 0;
|
|
min-width: 280px;
|
|
display: flex;
|
|
justify-content: flex-end;
|
|
align-items: flex-start;
|
|
|
|
.info-value {
|
|
font-size: 14px;
|
|
color: var(--td-text-color-primary);
|
|
text-align: right;
|
|
word-break: break-word;
|
|
}
|
|
}
|
|
</style>
|