feat: add scoped tenant api keys
This commit is contained in:
@@ -58,7 +58,6 @@ const syncOIDCUserContext = async () => {
|
||||
authStore.setTenant({
|
||||
id: String(tenant.id) || '',
|
||||
name: tenant.name || '',
|
||||
api_key: tenant.api_key || '',
|
||||
owner_id: tenant.owner_id || user.id || '',
|
||||
description: tenant.description,
|
||||
status: tenant.status,
|
||||
|
||||
@@ -28,7 +28,6 @@ export interface LoginResponse {
|
||||
id: number
|
||||
name: string
|
||||
description: string
|
||||
api_key: string
|
||||
status: string
|
||||
business: string
|
||||
storage_quota: number
|
||||
@@ -43,7 +42,6 @@ export interface LoginResponse {
|
||||
id: number
|
||||
name: string
|
||||
description?: string
|
||||
api_key?: string
|
||||
status?: string
|
||||
business?: string
|
||||
storage_quota?: number
|
||||
@@ -88,7 +86,6 @@ export interface RegisterResponse {
|
||||
tenant: {
|
||||
id: string
|
||||
name: string
|
||||
api_key: string
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,7 +160,6 @@ export interface TenantInfo {
|
||||
id: string
|
||||
name: string
|
||||
description?: string
|
||||
api_key: string
|
||||
status?: string
|
||||
business?: string
|
||||
owner_id: string
|
||||
|
||||
@@ -8,7 +8,6 @@ export interface TenantInfo {
|
||||
id: number
|
||||
name: string
|
||||
description?: string
|
||||
api_key?: string
|
||||
status?: string
|
||||
business?: string
|
||||
storage_quota?: number
|
||||
@@ -49,6 +48,30 @@ export interface APIPrincipalTestToken {
|
||||
external_user_id: string
|
||||
}
|
||||
|
||||
export type TenantAPIKeyScope = 'read' | 'write' | 'admin'
|
||||
|
||||
export interface TenantAPIKey {
|
||||
id: number
|
||||
name: string
|
||||
api_key: string
|
||||
scopes: TenantAPIKeyScope[]
|
||||
knowledge_base_ids: string[]
|
||||
last_used_at?: string
|
||||
expires_at?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface CreatedTenantAPIKey extends TenantAPIKey {
|
||||
token?: string
|
||||
}
|
||||
|
||||
export interface CreateTenantAPIKeyPayload {
|
||||
name: string
|
||||
scopes: TenantAPIKeyScope[]
|
||||
knowledge_base_ids?: string[]
|
||||
expires_at_unix?: number
|
||||
}
|
||||
|
||||
// 搜索租户参数
|
||||
export interface SearchTenantsParams {
|
||||
keyword?: string
|
||||
@@ -146,6 +169,50 @@ export async function createAPIPrincipalTestToken(
|
||||
}
|
||||
}
|
||||
|
||||
export async function listTenantAPIKeys(
|
||||
tenantId: number,
|
||||
): Promise<{ success: boolean; data?: TenantAPIKey[]; message?: string }> {
|
||||
try {
|
||||
const response = await get(`/api/v1/tenants/${tenantId}/api-keys`)
|
||||
return response as unknown as { success: boolean; data?: TenantAPIKey[]; message?: string }
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || t('error.tenant.listApiKeysFailed'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function createTenantAPIKey(
|
||||
tenantId: number,
|
||||
payload: CreateTenantAPIKeyPayload,
|
||||
): Promise<{ success: boolean; data?: CreatedTenantAPIKey; message?: string }> {
|
||||
try {
|
||||
const response = await post(`/api/v1/tenants/${tenantId}/api-keys`, payload)
|
||||
return response as unknown as { success: boolean; data?: CreatedTenantAPIKey; message?: string }
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || t('error.tenant.createApiKeyFailed'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function deleteTenantAPIKey(
|
||||
tenantId: number,
|
||||
keyId: number,
|
||||
): Promise<{ success: boolean; message?: string }> {
|
||||
try {
|
||||
const response = await del(`/api/v1/tenants/${tenantId}/api-keys/${keyId}`)
|
||||
return response as unknown as { success: boolean; message?: string }
|
||||
} catch (error: any) {
|
||||
return {
|
||||
success: false,
|
||||
message: error.message || t('error.tenant.deleteApiKeyFailed'),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新租户信息(目前暴露名称、描述两个字段的编辑入口)。
|
||||
* 后端 `PUT /tenants/:id` 用指针字段区分"未传"和"显式空串",未传的列不会
|
||||
@@ -186,8 +253,8 @@ export async function deleteTenant(
|
||||
|
||||
/**
|
||||
* 创建新工作区(任意已登录用户均可调用)。
|
||||
* 后端会自动把调用者写成新租户的 Owner,并生成 api_key、默认 storage_quota
|
||||
* 等服务端字段,所以这里只暴露 name + description。
|
||||
* 后端会自动把调用者写成新租户的 Owner,并填充默认 storage_quota
|
||||
* 等服务端字段;API Key 由用户在集成页手动创建。
|
||||
* 路由:POST /api/v1/tenants(router 上不挂 g.CrossTenant(),自助场景使用)。
|
||||
*/
|
||||
export async function createTenant(
|
||||
|
||||
@@ -99,9 +99,9 @@
|
||||
<t-icon name="tools" class="menu-icon" />
|
||||
<span>{{ $t('settings.mcpService') }}</span>
|
||||
</div>
|
||||
<div v-if="canSeeQuickNav('api')" class="menu-item" @click="handleQuickNav('api')">
|
||||
<div v-if="canSeeQuickNav('integration-api')" class="menu-item" @click="handleQuickNav('integration-api')">
|
||||
<t-icon name="secured" class="menu-icon" />
|
||||
<span>{{ $t('settings.apiInfo') }}</span>
|
||||
<span>{{ $t('integrations.tabs.api') }}</span>
|
||||
</div>
|
||||
<div class="menu-divider"></div>
|
||||
<div class="menu-item" @click="handleSettings">
|
||||
@@ -257,7 +257,7 @@ const QUICKNAV_MIN_ROLE: Record<string, 'viewer' | 'contributor' | 'admin' | 'ow
|
||||
models: 'viewer',
|
||||
websearch: 'admin',
|
||||
mcp: 'admin',
|
||||
api: 'owner',
|
||||
'integration-api': 'owner',
|
||||
}
|
||||
const canSeeQuickNav = (key: string): boolean => {
|
||||
if (authStore.canAccessAllTenants) return true
|
||||
@@ -296,7 +296,11 @@ const toggleMenu = () => {
|
||||
const handleQuickNav = (section: string) => {
|
||||
menuVisible.value = false
|
||||
uiStore.openSettings()
|
||||
router.push('/platform/settings')
|
||||
if (section === 'integration-api') {
|
||||
router.push({ path: '/platform/settings', query: { section: 'integrations', tab: 'api' } })
|
||||
} else {
|
||||
router.push('/platform/settings')
|
||||
}
|
||||
|
||||
// 延迟一下,确保设置页面已经渲染
|
||||
setTimeout(() => {
|
||||
@@ -556,7 +560,6 @@ const loadUserInfo = async () => {
|
||||
authStore.setTenant({
|
||||
id: String(response.data.tenant.id),
|
||||
name: response.data.tenant.name,
|
||||
api_key: response.data.tenant.api_key || '',
|
||||
owner_id: user.id,
|
||||
created_at: response.data.tenant.created_at,
|
||||
updated_at: response.data.tenant.updated_at
|
||||
|
||||
@@ -85,7 +85,7 @@
|
||||
<div class="menu_item-box">
|
||||
<div class="menu_icon">
|
||||
<img class="icon"
|
||||
:src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'agent' ? agentIcon : item.icon == 'integration' ? integrationIcon : item.icon == 'organization' ? organizationIcon : item.icon == 'logout' ? logoutIcon : item.icon == 'setting' ? settingIcon : prefixIcon)"
|
||||
:src="getImgSrc(item.icon == 'zhishiku' ? knowledgeIcon : item.icon == 'agent' ? agentIcon : item.icon == 'organization' ? organizationIcon : item.icon == 'logout' ? logoutIcon : item.icon == 'setting' ? settingIcon : prefixIcon)"
|
||||
alt="">
|
||||
</div>
|
||||
<template v-if="!uiStore.sidebarCollapsed">
|
||||
@@ -94,15 +94,6 @@
|
||||
class="menu-pending-badge"
|
||||
:title="t('organization.settings.pendingJoinRequestsBadge')">{{
|
||||
orgStore.totalPendingJoinRequestCount }}</span>
|
||||
<span v-if="item.path === 'integrations'" class="integration-preview"
|
||||
aria-hidden="true">
|
||||
<span v-for="(preview, idx) in integrationPreviewItems" :key="preview.key"
|
||||
class="integration-preview__item" :style="{ zIndex: idx + 1 }">
|
||||
<t-icon v-if="preview.icon.type === 'icon'" :name="preview.icon.name"
|
||||
size="13px" />
|
||||
<span v-else class="integration-preview__emoji">{{ preview.icon.value }}</span>
|
||||
</span>
|
||||
</span>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
@@ -257,17 +248,8 @@ import UserMenu from '@/components/UserMenu.vue';
|
||||
import TenantSelector from '@/components/TenantSelector.vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { getSystemInfo } from '@/api/system';
|
||||
import { INTEGRATION_PREVIEW_ITEMS, INTEGRATION_TAB_MIN_ROLE } from '@/config/integrations';
|
||||
|
||||
const chatResources = useChatResourcesStore();
|
||||
const integrationPreviewItems = computed(() =>
|
||||
INTEGRATION_PREVIEW_ITEMS.filter((item) => {
|
||||
const min = INTEGRATION_TAB_MIN_ROLE[item.key];
|
||||
if (!min) return true;
|
||||
if (authStore.canAccessAllTenants) return true;
|
||||
return authStore.hasRole(min);
|
||||
}),
|
||||
);
|
||||
// Platform logos reused from IMChannelsOverviewPanel — keeps the session list
|
||||
// visually consistent with the channels admin view.
|
||||
import wecomLogo from '@/assets/img/im/wecom.svg';
|
||||
@@ -412,8 +394,6 @@ const isMenuItemActive = (itemPath: string): boolean => {
|
||||
currentRoute === 'knowledgeBaseSettings';
|
||||
case 'agents':
|
||||
return currentRoute === 'agentList';
|
||||
case 'integrations':
|
||||
return currentRoute === 'integrations';
|
||||
case 'organizations':
|
||||
return currentRoute === 'organizationList';
|
||||
case 'creatChat':
|
||||
@@ -444,13 +424,13 @@ const getIconActiveState = (itemPath: string) => {
|
||||
// 分离上下两部分菜单(使用 visibleMenuArr 以便 lite 模式过滤 logout)
|
||||
const topMenuItems = computed<MenuItem[]>(() => {
|
||||
return (visibleMenuArr.value as unknown as MenuItem[]).filter((item: MenuItem) =>
|
||||
item.path === 'knowledge-bases' || item.path === 'agents' || item.path === 'integrations' || item.path === 'organizations' || item.path === 'creatChat'
|
||||
item.path === 'knowledge-bases' || item.path === 'agents' || item.path === 'organizations' || item.path === 'creatChat'
|
||||
);
|
||||
});
|
||||
|
||||
const bottomMenuItems = computed<MenuItem[]>(() => {
|
||||
return (visibleMenuArr.value as unknown as MenuItem[]).filter((item: MenuItem) => {
|
||||
if (item.path === 'knowledge-bases' || item.path === 'agents' || item.path === 'integrations' || item.path === 'organizations' || item.path === 'creatChat') {
|
||||
if (item.path === 'knowledge-bases' || item.path === 'agents' || item.path === 'organizations' || item.path === 'creatChat') {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -1032,7 +1012,6 @@ let prefixIcon = ref('prefixIcon.svg');
|
||||
let logoutIcon = ref('logout.svg');
|
||||
let settingIcon = ref('setting.svg');
|
||||
let agentIcon = ref('agent.svg');
|
||||
let integrationIcon = ref('integration.svg');
|
||||
let organizationIcon = ref('organization.svg');
|
||||
let pathPrefix = ref(route.name)
|
||||
const getIcon = (path: string) => {
|
||||
@@ -1041,7 +1020,6 @@ const getIcon = (path: string) => {
|
||||
const creatChatActiveState = getIconActiveState('creatChat');
|
||||
const settingsActiveState = getIconActiveState('settings');
|
||||
const agentsActiveState = route.name === 'agentList';
|
||||
const integrationsActiveState = route.name === 'integrations';
|
||||
const organizationsActiveState = route.name === 'organizationList';
|
||||
|
||||
// 知识库图标:只在知识库页面显示绿色
|
||||
@@ -1050,8 +1028,6 @@ const getIcon = (path: string) => {
|
||||
// 智能体图标:只在智能体页面显示绿色
|
||||
agentIcon.value = agentsActiveState ? 'agent-green.svg' : 'agent.svg';
|
||||
|
||||
integrationIcon.value = integrationsActiveState ? 'integration-green.svg' : 'integration.svg';
|
||||
|
||||
// 组织图标:只在组织页面显示绿色
|
||||
organizationIcon.value = organizationsActiveState ? 'organization-green.svg' : 'organization.svg';
|
||||
|
||||
@@ -1076,8 +1052,6 @@ const handleMenuClick = async (path: string) => {
|
||||
}
|
||||
} else if (path === 'agents') {
|
||||
router.push('/platform/agents')
|
||||
} else if (path === 'integrations') {
|
||||
router.push('/platform/integrations')
|
||||
} else if (path === 'organizations') {
|
||||
// 组织菜单项:跳转到组织列表
|
||||
router.push('/platform/organizations')
|
||||
@@ -1906,48 +1880,6 @@ const onDragHandleMouseDown = (e: MouseEvent) => {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.integration-preview {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
margin-left: auto;
|
||||
flex-shrink: 0;
|
||||
width: 0;
|
||||
overflow: hidden;
|
||||
pointer-events: none;
|
||||
|
||||
.menu_item:hover & {
|
||||
width: auto;
|
||||
}
|
||||
|
||||
&__item {
|
||||
position: relative;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 22px;
|
||||
height: 22px;
|
||||
flex-shrink: 0;
|
||||
border-radius: 50%;
|
||||
background: var(--td-bg-color-container);
|
||||
border: 2px solid var(--td-bg-color-sidebar);
|
||||
box-sizing: border-box;
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
&:not(:first-child) {
|
||||
margin-left: -5px;
|
||||
}
|
||||
|
||||
:deep(.t-icon) {
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
|
||||
&__emoji {
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
}
|
||||
}
|
||||
|
||||
.menu_box {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
@@ -5756,12 +5756,43 @@ export default {
|
||||
baseUrl: 'API Base URL',
|
||||
baseUrlDesc: 'Use this base URL with REST API paths.',
|
||||
apiKey: 'Tenant API Key',
|
||||
apiKeyDesc: 'The API key is still tenant-level. User identity is supplied by the principal mode below.',
|
||||
apiKeyDesc: 'Create API keys with operation permissions and knowledge-base scope.',
|
||||
apiKeys: 'API Keys',
|
||||
apiKeysDesc: 'Create separate keys per integration and restrict operation permissions plus knowledge-base access.',
|
||||
createApiKey: 'Create API Key',
|
||||
createApiKeyDialogDesc: 'Set permissions and available knowledge bases.',
|
||||
noApiKeys: 'No API keys',
|
||||
apiKeyName: 'Name',
|
||||
apiKeyValue: 'API Key',
|
||||
apiKeyNamePlaceholder: 'Example: MCP read-only access',
|
||||
apiKeyNameRequired: 'Enter an API key name',
|
||||
toggleApiKeyVisible: 'Show or hide API key',
|
||||
apiKeyScopes: 'Permissions',
|
||||
apiKeyScopeRequired: 'Select at least one permission',
|
||||
apiKeyKnowledgeScope: 'Knowledge bases',
|
||||
apiKeyKnowledgeScopePlaceholder: 'Leave empty to allow all knowledge bases',
|
||||
scopeRead: 'Read',
|
||||
scopeWrite: 'Write',
|
||||
scopeAdmin: 'Admin',
|
||||
scopeReadDesc: 'Query, search, and chat without changing knowledge-base content.',
|
||||
scopeWriteDesc: 'Create, update, or delete knowledge-base content within the selected scope.',
|
||||
scopeAdminDesc: 'Manage tenant-level settings; API keys cannot manage API keys.',
|
||||
allKnowledgeBases: 'All knowledge bases',
|
||||
createdAt: 'Created',
|
||||
actions: 'Actions',
|
||||
deleteApiKey: 'Delete',
|
||||
deleteApiKeyConfirm: 'After deletion this API key is revoked immediately and deployed integrations using it will stop working.',
|
||||
deleteApiKeySuccess: 'API key deleted',
|
||||
deleteApiKeyFailed: 'Failed to delete API key',
|
||||
createApiKeyFailed: 'Failed to create API key',
|
||||
loadApiKeysFailed: 'Failed to load API keys',
|
||||
apiKeyCreated: 'API key created',
|
||||
apiKeyCreatedDesc: 'The API key has been created and can be viewed or copied from the list.',
|
||||
principalMode: 'User identity mode',
|
||||
principalModeDesc:
|
||||
'Choose how API requests identify the end user. This identity scopes both conversation sessions and MCP tool authorization per user, without reducing the API key\'s tenant-admin access.',
|
||||
'Choose how API requests identify the end user. This identity scopes both conversation sessions and MCP tool authorization per user.',
|
||||
principalScope:
|
||||
'End-user identity isolates conversation sessions and MCP tool authorization (OAuth) per user. The API key can still access all knowledge bases in the tenant; API permissions are not split per external user.',
|
||||
'End-user identity isolates sessions and MCP OAuth. Operation permissions and knowledge-base scope are controlled by API Keys above.',
|
||||
modeTenant: 'Tenant only',
|
||||
modeDirect: 'Direct user ID',
|
||||
modeSigned: 'Signed token',
|
||||
|
||||
@@ -5769,12 +5769,43 @@ export default {
|
||||
baseUrl: "API 地址",
|
||||
baseUrlDesc: "与 REST API 路径拼接使用。",
|
||||
apiKey: "租户 API Key",
|
||||
apiKeyDesc: "API Key 仍按租户级管理;终端用户身份由下方模式提供。",
|
||||
apiKeyDesc: "为集成创建带权限和知识库范围的 API Key。",
|
||||
apiKeys: "API Keys",
|
||||
apiKeysDesc: "为不同集成创建独立 Key,并限制操作权限与可访问知识库范围。",
|
||||
createApiKey: "创建 API Key",
|
||||
createApiKeyDialogDesc: "设置访问权限和可用知识库范围。",
|
||||
noApiKeys: "暂无 API Key",
|
||||
apiKeyName: "名称",
|
||||
apiKeyValue: "API Key",
|
||||
apiKeyNamePlaceholder: "例如:MCP 只读访问",
|
||||
apiKeyNameRequired: "请输入 API Key 名称",
|
||||
toggleApiKeyVisible: "显示或隐藏 API Key",
|
||||
apiKeyScopes: "权限",
|
||||
apiKeyScopeRequired: "请至少选择一个权限",
|
||||
apiKeyKnowledgeScope: "知识库范围",
|
||||
apiKeyKnowledgeScopePlaceholder: "留空表示允许访问全部知识库",
|
||||
scopeRead: "读取",
|
||||
scopeWrite: "写入",
|
||||
scopeAdmin: "管理",
|
||||
scopeReadDesc: "查询、检索和对话,不修改知识库内容。",
|
||||
scopeWriteDesc: "创建、更新或删除知识库内容,受知识库范围限制。",
|
||||
scopeAdminDesc: "管理租户级配置;不能用 API Key 管理 API Key。",
|
||||
allKnowledgeBases: "全部知识库",
|
||||
createdAt: "创建时间",
|
||||
actions: "操作",
|
||||
deleteApiKey: "删除",
|
||||
deleteApiKeyConfirm: "删除后该 API Key 会立即失效,已部署的集成将无法继续使用它。",
|
||||
deleteApiKeySuccess: "API Key 已删除",
|
||||
deleteApiKeyFailed: "删除 API Key 失败",
|
||||
createApiKeyFailed: "创建 API Key 失败",
|
||||
loadApiKeysFailed: "加载 API Key 列表失败",
|
||||
apiKeyCreated: "API Key 已创建",
|
||||
apiKeyCreatedDesc: "API Key 已创建,可在列表中查看或复制。",
|
||||
principalMode: "用户身份模式",
|
||||
principalModeDesc:
|
||||
"配置 API 请求如何识别终端用户。该身份会同时用于区分不同用户的对话 Session 与 MCP 工具授权,不会改变 API Key 的租户管理员权限。",
|
||||
"配置 API 请求如何识别终端用户。该身份会同时用于区分不同用户的对话 Session 与 MCP 工具授权。",
|
||||
principalScope:
|
||||
"按终端用户隔离对话 Session 与 MCP 工具授权(OAuth);API Key 仍可访问租户内全部知识库等资源,权限范围不按外部用户拆分。",
|
||||
"终端用户身份负责隔离 Session 与 MCP OAuth;API Key 自身的操作权限和知识库范围由上方 API Keys 管理。",
|
||||
modeTenant: "仅租户",
|
||||
modeDirect: "直接传用户 ID",
|
||||
modeSigned: "签名 Token",
|
||||
|
||||
@@ -130,8 +130,13 @@ const router = createRouter({
|
||||
},
|
||||
{
|
||||
path: "integrations",
|
||||
name: "integrations",
|
||||
component: () => import("../views/platform/RoutePlaceholder.vue"),
|
||||
redirect: (to) => ({
|
||||
path: "/platform/settings",
|
||||
query: {
|
||||
...to.query,
|
||||
section: "integrations",
|
||||
},
|
||||
}),
|
||||
meta: { requiresInit: true, requiresAuth: true }
|
||||
},
|
||||
{
|
||||
@@ -203,7 +208,6 @@ function persistLoginResponse(authStore: ReturnType<typeof useAuthStore>, respon
|
||||
authStore.setTenant({
|
||||
id: String(response.tenant.id) || '',
|
||||
name: response.tenant.name || '',
|
||||
api_key: response.tenant.api_key || '',
|
||||
owner_id: response.user.id || '',
|
||||
created_at: response.tenant.created_at || new Date().toISOString(),
|
||||
updated_at: response.tenant.updated_at || new Date().toISOString()
|
||||
@@ -238,7 +242,6 @@ async function hydrateSessionFromToken(authStore: ReturnType<typeof useAuthStore
|
||||
authStore.setTenant({
|
||||
id: String(tenant.id) || '',
|
||||
name: tenant.name || '',
|
||||
api_key: tenant.api_key || '',
|
||||
owner_id: tenant.owner_id || user.id || '',
|
||||
description: tenant.description,
|
||||
status: tenant.status,
|
||||
|
||||
@@ -59,7 +59,7 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
})
|
||||
|
||||
const hasValidTenant = computed(() => {
|
||||
return !!tenant.value && !!tenant.value.api_key
|
||||
return !!tenant.value && !!tenant.value.id
|
||||
})
|
||||
|
||||
const currentTenantId = computed(() => {
|
||||
@@ -342,7 +342,6 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
setTenant({
|
||||
id: String(tenantSnapshot.id) || '',
|
||||
name: tenantSnapshot.name || '',
|
||||
api_key: tenantSnapshot.api_key || '',
|
||||
owner_id: tenantSnapshot.owner_id || u.id || '',
|
||||
description: tenantSnapshot.description,
|
||||
status: tenantSnapshot.status,
|
||||
@@ -545,4 +544,4 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
logout,
|
||||
initFromStorage
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@@ -28,7 +28,6 @@ export const useMenuStore = defineStore('menuStore', () => {
|
||||
},
|
||||
{ title: '', titleKey: 'menu.knowledgeBase', icon: 'zhishiku', path: 'knowledge-bases' },
|
||||
{ title: '', titleKey: 'menu.agents', icon: 'agent', path: 'agents' },
|
||||
{ title: '', titleKey: 'menu.integrations', icon: 'integration', path: 'integrations' },
|
||||
{ title: '', titleKey: 'menu.organizations', icon: 'organization', path: 'organizations' },
|
||||
{ title: '', titleKey: 'menu.settings', icon: 'setting', path: 'settings' },
|
||||
{ title: '', titleKey: 'menu.logout', icon: 'logout', path: 'logout' }
|
||||
|
||||
@@ -2183,7 +2183,7 @@ function gotoIntegrations(tab: 'im' | 'embed') {
|
||||
const agentId = editorAgent.value?.id;
|
||||
if (!agentId) return;
|
||||
handleClose();
|
||||
router.push({ path: '/platform/integrations', query: { agentId, tab } });
|
||||
router.push({ path: '/platform/settings', query: { section: 'integrations', agentId, tab } });
|
||||
}
|
||||
|
||||
const filteredIntentPlaceholders = computed(() => {
|
||||
|
||||
@@ -1144,8 +1144,8 @@ const checkAndOpenEditModal = () => {
|
||||
if (editId && (section === 'im' || section === 'embed' || section === 'integrations')) {
|
||||
const tab = section === 'embed' ? 'embed' : 'im'
|
||||
router.replace({
|
||||
path: '/platform/integrations',
|
||||
query: { tab, agentId: editId },
|
||||
path: '/platform/settings',
|
||||
query: { section: 'integrations', tab, agentId: editId },
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@@ -553,7 +553,6 @@ const persistLoginResponse = async (response: any) => {
|
||||
authStore.setTenant({
|
||||
id: String(activeTenant.id) || '',
|
||||
name: activeTenant.name || '',
|
||||
api_key: activeTenant.api_key || '',
|
||||
owner_id: response.user.id || '',
|
||||
created_at: activeTenant.created_at || new Date().toISOString(),
|
||||
updated_at: activeTenant.updated_at || new Date().toISOString()
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -119,8 +119,8 @@ const openChromeStore = () => {
|
||||
}
|
||||
|
||||
const openApiSettings = () => {
|
||||
router.push('/platform/knowledge-bases')
|
||||
uiStore.openSettings('api')
|
||||
router.push({ path: '/platform/settings', query: { section: 'integrations', tab: 'api' } })
|
||||
uiStore.openSettings('integration-api')
|
||||
}
|
||||
|
||||
const copyApiUrl = async () => {
|
||||
|
||||
@@ -141,8 +141,8 @@ const openClawHub = () => {
|
||||
}
|
||||
|
||||
const openApiSettings = () => {
|
||||
router.push('/platform/knowledge-bases')
|
||||
uiStore.openSettings('api')
|
||||
router.push({ path: '/platform/settings', query: { section: 'integrations', tab: 'api' } })
|
||||
uiStore.openSettings('integration-api')
|
||||
}
|
||||
|
||||
const copyText = async (text: string, successKey: string) => {
|
||||
|
||||
@@ -0,0 +1,127 @@
|
||||
<template>
|
||||
<div class="integrations-settings">
|
||||
<div class="integrations-settings__body" :class="{ 'integrations-settings__body--landing': isLandingSection }">
|
||||
<div v-if="tab === 'im'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('agentEditor.im.title') }}</h2>
|
||||
<p class="section-description">
|
||||
{{ $t('agentEditor.im.description') }}
|
||||
<a
|
||||
href="https://github.com/Tencent/WeKnora/blob/main/docs/IM%E9%9B%86%E6%88%90%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3.md"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="doc-link"
|
||||
>
|
||||
{{ $t('agentEditor.im.docLink') }}
|
||||
<t-icon name="link" class="link-icon" />
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<IMChannelPanel v-model:filter-agent-id="filterAgentId" />
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'embed'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('agentEditor.embed.title') }}</h2>
|
||||
<p class="section-description">{{ $t('agentEditor.embed.description') }}</p>
|
||||
</div>
|
||||
<AgentEmbedChannelPanel v-model:filter-agent-id="filterAgentId" />
|
||||
</div>
|
||||
|
||||
<div v-if="tab === 'api'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('integrations.api.title') }}</h2>
|
||||
<p class="section-description">{{ $t('integrations.api.subtitle') }}</p>
|
||||
</div>
|
||||
<ApiIntegrationSettings />
|
||||
</div>
|
||||
|
||||
<ChromeExtensionLanding v-if="tab === 'chrome'" />
|
||||
<ClawSkillLanding v-if="tab === 'claw'" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue'
|
||||
import { useRoute } from 'vue-router'
|
||||
import IMChannelPanel from '@/components/IMChannelPanel.vue'
|
||||
import AgentEmbedChannelPanel from '@/components/AgentEmbedChannelPanel.vue'
|
||||
import ApiIntegrationSettings from '@/views/integrations/ApiIntegrationSettings.vue'
|
||||
import ChromeExtensionLanding from '@/views/integrations/ChromeExtensionLanding.vue'
|
||||
import ClawSkillLanding from '@/views/integrations/ClawSkillLanding.vue'
|
||||
import type { IntegrationTab } from '@/config/integrations'
|
||||
|
||||
const filterAgentId = ref('')
|
||||
|
||||
const props = defineProps<{
|
||||
tab: IntegrationTab
|
||||
}>()
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const isLandingSection = computed(
|
||||
() => props.tab === 'chrome' || props.tab === 'claw',
|
||||
)
|
||||
|
||||
function applyAgentFilterFromRoute() {
|
||||
filterAgentId.value = (route.query.agentId as string) || ''
|
||||
}
|
||||
|
||||
watch(
|
||||
() => route.query.agentId,
|
||||
applyAgentFilterFromRoute,
|
||||
{ immediate: true },
|
||||
)
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.integrations-settings {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.integrations-settings__body {
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.integrations-settings__body--landing {
|
||||
max-width: 760px;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 18px;
|
||||
|
||||
h2 {
|
||||
margin: 0 0 6px;
|
||||
color: var(--td-text-color-primary);
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
line-height: 1.35;
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
margin: 0;
|
||||
color: var(--td-text-color-secondary);
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
margin-left: 6px;
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.link-icon {
|
||||
font-size: 13px;
|
||||
}
|
||||
</style>
|
||||
@@ -1,394 +0,0 @@
|
||||
<template>
|
||||
<Teleport to="body">
|
||||
<Transition name="modal">
|
||||
<div v-if="visible" class="settings-overlay" @click.self="handleClose">
|
||||
<div class="settings-modal">
|
||||
<div class="settings-container">
|
||||
<div class="settings-sidebar">
|
||||
<div class="sidebar-header">
|
||||
<h2 class="sidebar-title">{{ $t('integrations.title') }}</h2>
|
||||
<p class="sidebar-subtitle">{{ $t('integrations.subtitle') }}</p>
|
||||
</div>
|
||||
<div class="settings-nav">
|
||||
<div
|
||||
v-for="item in navItems"
|
||||
:key="item.key"
|
||||
:class="['nav-item', { active: currentSection === item.key }]"
|
||||
@click="currentSection = item.key"
|
||||
>
|
||||
<span v-if="item.emoji" class="nav-emoji" role="img" :aria-label="item.label">{{ item.emoji }}</span>
|
||||
<t-icon v-else :name="item.icon" class="nav-icon" />
|
||||
<span class="nav-label">{{ item.label }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="settings-content">
|
||||
<button class="close-btn" @click="handleClose" :aria-label="$t('common.close')">
|
||||
<svg width="20" height="20" viewBox="0 0 20 20" fill="currentColor">
|
||||
<path d="M15 5L5 15M5 5L15 15" stroke="currentColor" stroke-width="2" stroke-linecap="round" />
|
||||
</svg>
|
||||
</button>
|
||||
<div class="content-wrapper" :class="{ 'content-wrapper--landing': isLandingSection }">
|
||||
<div v-if="currentSection === 'im'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('agentEditor.im.title') }}</h2>
|
||||
<p class="section-description">
|
||||
{{ $t('agentEditor.im.description') }}
|
||||
<a
|
||||
href="https://github.com/Tencent/WeKnora/blob/main/docs/IM%E9%9B%86%E6%88%90%E5%BC%80%E5%8F%91%E6%96%87%E6%A1%A3.md"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
class="doc-link"
|
||||
>
|
||||
{{ $t('agentEditor.im.docLink') }}
|
||||
<t-icon name="link" class="link-icon" />
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
<IMChannelPanel v-model:filter-agent-id="filterAgentId" />
|
||||
</div>
|
||||
|
||||
<div v-if="currentSection === 'embed'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('agentEditor.embed.title') }}</h2>
|
||||
<p class="section-description">{{ $t('agentEditor.embed.description') }}</p>
|
||||
</div>
|
||||
<AgentEmbedChannelPanel v-model:filter-agent-id="filterAgentId" />
|
||||
</div>
|
||||
|
||||
<div v-if="currentSection === 'api'" class="section">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('integrations.api.title') }}</h2>
|
||||
<p class="section-description">{{ $t('integrations.api.subtitle') }}</p>
|
||||
</div>
|
||||
<ApiIntegrationSettings />
|
||||
</div>
|
||||
<ChromeExtensionLanding v-if="currentSection === 'chrome'" />
|
||||
<ClawSkillLanding v-if="currentSection === 'claw'" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</Transition>
|
||||
</Teleport>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from 'vue';
|
||||
import { useRoute, useRouter } from 'vue-router';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import IMChannelPanel from '@/components/IMChannelPanel.vue';
|
||||
import AgentEmbedChannelPanel from '@/components/AgentEmbedChannelPanel.vue';
|
||||
import ApiIntegrationSettings from '@/views/integrations/ApiIntegrationSettings.vue';
|
||||
import ChromeExtensionLanding from '@/views/integrations/ChromeExtensionLanding.vue';
|
||||
import ClawSkillLanding from '@/views/integrations/ClawSkillLanding.vue';
|
||||
import {
|
||||
INTEGRATION_PREVIEW_ITEMS,
|
||||
INTEGRATION_TAB_MIN_ROLE,
|
||||
INTEGRATION_TABS,
|
||||
type IntegrationTab,
|
||||
} from '@/config/integrations';
|
||||
import { useAuthStore } from '@/stores/auth';
|
||||
|
||||
const { t } = useI18n();
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const authStore = useAuthStore();
|
||||
|
||||
const currentSection = ref<IntegrationTab>('im');
|
||||
const filterAgentId = ref('');
|
||||
|
||||
const visible = computed(() => route.name === 'integrations');
|
||||
|
||||
const isLandingSection = computed(
|
||||
() => currentSection.value === 'chrome' || currentSection.value === 'claw',
|
||||
);
|
||||
|
||||
function canSeeTab(tab: IntegrationTab): boolean {
|
||||
const min = INTEGRATION_TAB_MIN_ROLE[tab];
|
||||
if (!min) return true;
|
||||
if (authStore.canAccessAllTenants) return true;
|
||||
return authStore.hasRole(min);
|
||||
}
|
||||
|
||||
const navItems = computed(() =>
|
||||
INTEGRATION_PREVIEW_ITEMS
|
||||
.filter((item) => canSeeTab(item.key))
|
||||
.map((item) => ({
|
||||
key: item.key,
|
||||
icon: item.icon.type === 'icon' ? item.icon.name : '',
|
||||
emoji: item.icon.type === 'emoji' ? item.icon.value : undefined,
|
||||
label: t(`integrations.tabs.${item.key}`),
|
||||
})),
|
||||
);
|
||||
|
||||
function applyRouteQuery() {
|
||||
const tab = route.query.tab as string;
|
||||
if (INTEGRATION_TABS.includes(tab as IntegrationTab) && canSeeTab(tab as IntegrationTab)) {
|
||||
currentSection.value = tab as IntegrationTab;
|
||||
} else if (INTEGRATION_TABS.includes(tab as IntegrationTab)) {
|
||||
currentSection.value = navItems.value[0]?.key ?? 'im';
|
||||
if (visible.value) syncRouteQuery();
|
||||
} else if (navItems.value.length > 0 && !canSeeTab(currentSection.value)) {
|
||||
currentSection.value = navItems.value[0].key;
|
||||
if (visible.value) syncRouteQuery();
|
||||
}
|
||||
filterAgentId.value = (route.query.agentId as string) || '';
|
||||
}
|
||||
|
||||
function syncRouteQuery() {
|
||||
const query: Record<string, string> = { tab: currentSection.value };
|
||||
if (filterAgentId.value) {
|
||||
query.agentId = filterAgentId.value;
|
||||
}
|
||||
router.replace({ path: route.path, query });
|
||||
}
|
||||
|
||||
function handleClose() {
|
||||
if (route.name !== 'integrations') return;
|
||||
if (window.history.length > 1) {
|
||||
router.back();
|
||||
} else {
|
||||
router.push('/platform/knowledge-bases');
|
||||
}
|
||||
}
|
||||
|
||||
watch(visible, (open) => {
|
||||
if (open) applyRouteQuery();
|
||||
});
|
||||
|
||||
watch(currentSection, () => {
|
||||
if (visible.value) syncRouteQuery();
|
||||
});
|
||||
|
||||
watch(filterAgentId, () => {
|
||||
if (visible.value) syncRouteQuery();
|
||||
});
|
||||
|
||||
watch(
|
||||
() => [route.query.tab, route.query.agentId],
|
||||
() => {
|
||||
if (visible.value) applyRouteQuery();
|
||||
},
|
||||
);
|
||||
</script>
|
||||
|
||||
<style scoped lang="less">
|
||||
.settings-overlay {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
background: rgba(0, 0, 0, 0.5);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 1000;
|
||||
backdrop-filter: blur(4px);
|
||||
}
|
||||
|
||||
.settings-modal {
|
||||
position: relative;
|
||||
width: 90vw;
|
||||
max-width: 1100px;
|
||||
height: 85vh;
|
||||
max-height: 750px;
|
||||
background: var(--td-bg-color-container);
|
||||
border-radius: 12px;
|
||||
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.settings-content {
|
||||
position: relative;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.close-btn {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: none;
|
||||
background: var(--td-bg-color-container);
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
color: var(--td-text-color-secondary);
|
||||
transition: all 0.2s ease;
|
||||
z-index: 10;
|
||||
box-shadow: 0 0 0 1px var(--td-component-stroke);
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
flex: 1;
|
||||
overflow-y: auto;
|
||||
padding: 24px 28px 28px;
|
||||
|
||||
&--landing {
|
||||
padding-right: 52px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
}
|
||||
|
||||
.settings-container {
|
||||
display: flex;
|
||||
height: 100%;
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.settings-sidebar {
|
||||
width: 208px;
|
||||
background-color: var(--td-bg-color-settings-modal);
|
||||
border-right: 1px solid var(--td-component-stroke);
|
||||
flex-shrink: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.sidebar-header {
|
||||
padding: 16px 14px 12px;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.sidebar-title {
|
||||
margin: 0;
|
||||
font-size: 16px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
|
||||
.sidebar-subtitle {
|
||||
margin: 6px 0 0;
|
||||
font-size: 12px;
|
||||
line-height: 1.45;
|
||||
color: var(--td-text-color-placeholder);
|
||||
}
|
||||
|
||||
.settings-nav {
|
||||
flex: 1;
|
||||
padding: 8px;
|
||||
overflow-y: auto;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
.nav-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 6px 12px;
|
||||
margin-bottom: 2px;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: all 0.2s ease;
|
||||
font-size: 14px;
|
||||
color: var(--td-text-color-primary);
|
||||
|
||||
&:hover {
|
||||
background: var(--td-bg-color-container-hover);
|
||||
}
|
||||
|
||||
&.active {
|
||||
background: var(--td-bg-color-secondarycontainer);
|
||||
color: var(--td-brand-color);
|
||||
font-weight: 500;
|
||||
|
||||
.nav-icon {
|
||||
color: var(--td-brand-color);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.nav-icon {
|
||||
margin-right: 8px;
|
||||
font-size: 16px;
|
||||
color: var(--td-text-color-secondary);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.nav-emoji {
|
||||
margin-right: 8px;
|
||||
font-size: 15px;
|
||||
line-height: 1;
|
||||
flex-shrink: 0;
|
||||
width: 16px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.section-header {
|
||||
margin-bottom: 20px;
|
||||
|
||||
h2 {
|
||||
margin: 0 0 8px;
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
}
|
||||
}
|
||||
|
||||
.section-description {
|
||||
margin: 0;
|
||||
font-size: 13px;
|
||||
line-height: 1.6;
|
||||
color: var(--td-text-color-secondary);
|
||||
|
||||
.doc-link {
|
||||
color: var(--td-brand-color);
|
||||
text-decoration: none;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.link-icon {
|
||||
font-size: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-enter-active,
|
||||
.modal-leave-active {
|
||||
transition: opacity 0.2s ease;
|
||||
|
||||
.settings-modal {
|
||||
transition: transform 0.2s ease, opacity 0.2s ease;
|
||||
}
|
||||
}
|
||||
|
||||
.modal-enter-from,
|
||||
.modal-leave-to {
|
||||
opacity: 0;
|
||||
|
||||
.settings-modal {
|
||||
transform: scale(0.98);
|
||||
opacity: 0;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -10,7 +10,6 @@
|
||||
</div>
|
||||
<!-- 全局设置模态框,供所有 platform 子路由使用 -->
|
||||
<Settings />
|
||||
<IntegrationsModal />
|
||||
<!-- 全局命令面板 (⌘K),随 platform 路由存活 -->
|
||||
<GlobalCommandPalette />
|
||||
<!-- 全局右上角"待处理邀请"铃铛。固定定位,z-index 低于抽屉,业务页面
|
||||
@@ -27,7 +26,6 @@ import { useRoute, useRouter } from 'vue-router'
|
||||
import useKnowledgeBase from '@/hooks/useKnowledgeBase'
|
||||
import UploadMask from '@/components/upload-mask.vue'
|
||||
import Settings from '@/views/settings/Settings.vue'
|
||||
import IntegrationsModal from '@/views/integrations/IntegrationsModal.vue'
|
||||
import GlobalCommandPalette from '@/components/GlobalCommandPalette.vue'
|
||||
import GlobalInvitationBell from '@/components/GlobalInvitationBell.vue'
|
||||
import NewUserGuide from '@/components/NewUserGuide.vue'
|
||||
|
||||
@@ -1,666 +0,0 @@
|
||||
<template>
|
||||
<div class="api-info">
|
||||
<div class="section-header">
|
||||
<h2>{{ $t('tenant.api.title') }}</h2>
|
||||
<p class="section-description">{{ $t('tenant.api.description') }}</p>
|
||||
</div>
|
||||
|
||||
<!-- Loading state -->
|
||||
<div v-if="loading" class="loading-inline">
|
||||
<t-loading size="small" />
|
||||
<span>{{ $t('tenant.loadingInfo') }}</span>
|
||||
</div>
|
||||
|
||||
<!-- Error state -->
|
||||
<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">
|
||||
<!-- API Key -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.keyLabel') }}</label>
|
||||
<p class="desc">{{ $t('tenant.api.keyDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="api-key-control">
|
||||
<t-input
|
||||
v-model="displayApiKey"
|
||||
readonly
|
||||
type="text"
|
||||
class="mono-text-input"
|
||||
style="width: 100%;"
|
||||
/>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="showApiKey = !showApiKey"
|
||||
>
|
||||
<t-icon :name="showApiKey ? 'browse-off' : 'browse'" />
|
||||
</t-button>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="copyApiKey"
|
||||
:title="$t('tenant.api.copyTitle')"
|
||||
>
|
||||
<t-icon name="file-copy" />
|
||||
</t-button>
|
||||
<t-button
|
||||
v-if="authStore.hasRole('owner')"
|
||||
size="small"
|
||||
variant="text"
|
||||
theme="danger"
|
||||
:loading="resetting"
|
||||
:title="$t('tenant.api.resetTitle')"
|
||||
@click="confirmResetApiKey"
|
||||
>
|
||||
<t-icon name="refresh" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- API base URL -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.urlLabel') }}</label>
|
||||
<p class="desc">{{ $t('tenant.api.urlDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="api-key-control">
|
||||
<t-input
|
||||
:model-value="apiBaseUrlDisplay"
|
||||
readonly
|
||||
type="text"
|
||||
class="mono-text-input"
|
||||
style="width: 100%;"
|
||||
/>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="copyApiUrl"
|
||||
:title="$t('tenant.api.copyUrlTitle')"
|
||||
>
|
||||
<t-icon name="file-copy" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Desktop (Wails): fixed local API port + optional LAN/public listen -->
|
||||
<template v-if="showDesktopPortSetting || showDesktopBindPublicSetting">
|
||||
<div v-if="showDesktopPortSetting" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.desktopPortLabel') }}</label>
|
||||
<p class="desc">{{ $t('tenant.api.desktopPortDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="api-key-control">
|
||||
<div class="desktop-port-input-wrap">
|
||||
<t-input-number
|
||||
v-model="desktopPortInput"
|
||||
:min="0"
|
||||
:max="65535"
|
||||
theme="normal"
|
||||
/>
|
||||
</div>
|
||||
<t-button size="small" variant="text" @click="saveDesktopPort">
|
||||
{{ $t('tenant.api.desktopPortSave') }}
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showDesktopBindPublicSetting" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.desktopBindPublicLabel') }}</label>
|
||||
<p class="desc">{{ $t('tenant.api.desktopBindPublicDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control desktop-bind-public-control">
|
||||
<t-switch v-model="desktopBindPublicInput" @change="onDesktopBindPublicChange" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="wailsApiLanBaseURL" class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.lanUrlLabel') }}</label>
|
||||
<p class="desc">{{ $t('tenant.api.lanUrlDescription') }}</p>
|
||||
</div>
|
||||
<div class="setting-control">
|
||||
<div class="api-key-control">
|
||||
<t-input
|
||||
:model-value="wailsApiLanBaseURL"
|
||||
readonly
|
||||
type="text"
|
||||
class="mono-text-input"
|
||||
style="width: 100%;"
|
||||
/>
|
||||
<t-button
|
||||
size="small"
|
||||
variant="text"
|
||||
@click="copyLanApiUrl"
|
||||
:title="$t('tenant.api.lanUrlCopyTitle')"
|
||||
>
|
||||
<t-icon name="file-copy" />
|
||||
</t-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="showLanUrlUnavailableHint" class="setting-row lan-url-hint-row">
|
||||
<t-alert theme="warning" :message="$t('tenant.api.lanUrlUnavailable')" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- API docs -->
|
||||
<div class="setting-row">
|
||||
<div class="setting-info">
|
||||
<label>{{ $t('tenant.api.docLabel') }}</label>
|
||||
<p class="desc">
|
||||
{{ $t('tenant.api.docDescription') }}
|
||||
<a @click="openApiDoc" class="doc-link">
|
||||
{{ $t('tenant.api.openDoc') }}
|
||||
<t-icon name="link" class="link-icon" />
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 用户信息原本嵌在这一页底部,但 api 信息页是 owner-only(要看
|
||||
api key + reset),把用户基本信息(id / 用户名 / 邮箱 / 注册
|
||||
时间)也卡在这里意味着 viewer / contributor 看不到自己的账户
|
||||
信息。已拆到独立的 UserProfile.vue(settings 里 viewer 可见)。 -->
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted } from 'vue'
|
||||
import { getCurrentUser, type TenantInfo } from '@/api/auth'
|
||||
import { resetTenantApiKey } from '@/api/tenant'
|
||||
import { getApiBaseUrl } from '@/utils/api-base'
|
||||
import { DialogPlugin, MessagePlugin } from 'tdesign-vue-next'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import { useAuthStore } from '@/stores/auth'
|
||||
|
||||
const { t } = useI18n()
|
||||
const authStore = useAuthStore()
|
||||
|
||||
// Reactive state
|
||||
const tenantInfo = ref<TenantInfo | null>(null)
|
||||
const loading = ref(true)
|
||||
const error = ref('')
|
||||
const showApiKey = ref(false)
|
||||
const resetting = ref(false)
|
||||
/** WeKnora Lite (Wails): real API origin is loopback + dynamic port, not window.location.origin */
|
||||
const wailsApiBaseURL = ref<string | null>(null)
|
||||
const showDesktopPortSetting = ref(false)
|
||||
const showDesktopBindPublicSetting = ref(false)
|
||||
const desktopPortInput = ref<number | undefined>(0)
|
||||
const desktopBindPublicInput = ref(false)
|
||||
const wailsApiLanBaseURL = ref<string | null>(null)
|
||||
const desktopListenPublicActive = ref(false)
|
||||
|
||||
// Computed
|
||||
const displayApiKey = computed(() => {
|
||||
if (!tenantInfo.value?.api_key) return ''
|
||||
if (showApiKey.value) {
|
||||
return tenantInfo.value.api_key
|
||||
}
|
||||
let masked = ''
|
||||
for (let i = 0; i < tenantInfo.value.api_key.length; i++) {
|
||||
masked += '•'
|
||||
}
|
||||
return masked
|
||||
})
|
||||
|
||||
const showLanUrlUnavailableHint = computed(
|
||||
() =>
|
||||
showDesktopBindPublicSetting.value &&
|
||||
desktopListenPublicActive.value &&
|
||||
!wailsApiLanBaseURL.value
|
||||
)
|
||||
|
||||
const apiBaseUrlDisplay = computed(() => {
|
||||
if (wailsApiBaseURL.value) {
|
||||
return wailsApiBaseURL.value
|
||||
}
|
||||
const configured = getApiBaseUrl().trim().replace(/\/$/, '')
|
||||
let origin = typeof window !== 'undefined' ? window.location.origin : ''
|
||||
if (!origin || origin === 'null') {
|
||||
origin = ''
|
||||
}
|
||||
const base = configured || origin
|
||||
return `${base}/api/v1`
|
||||
})
|
||||
|
||||
type WeKnoraDesktopWindow = Window & {
|
||||
__WEKNORA_API_BASE__?: string
|
||||
__WEKNORA_API_LAN_BASE__?: string
|
||||
go?: {
|
||||
main?: {
|
||||
App?: {
|
||||
GetAPIBaseURL?: () => Promise<string> | string
|
||||
GetAPILanBaseURL?: () => Promise<string> | string
|
||||
GetDesktopHTTPPortSetting?: () => Promise<number> | number
|
||||
GetDesktopHTTPBindPublicSetting?: () => Promise<boolean> | boolean
|
||||
GetDesktopListenPublicActive?: () => Promise<boolean> | boolean
|
||||
SetDesktopHTTPPortSetting?: (port: number) => Promise<void> | void
|
||||
SetDesktopHTTPBindPublicSetting?: (v: boolean) => Promise<void> | void
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function tryLoadWailsApiBaseURL() {
|
||||
const win = window as WeKnoraDesktopWindow
|
||||
for (let i = 0; i < 40; i++) {
|
||||
const injected = win.__WEKNORA_API_BASE__
|
||||
if (typeof injected === 'string' && injected.trim()) {
|
||||
wailsApiBaseURL.value = injected.trim().replace(/\/$/, '')
|
||||
await tryLoadWailsLanHints(win)
|
||||
return
|
||||
}
|
||||
const fn = win.go?.main?.App?.GetAPIBaseURL
|
||||
if (typeof fn === 'function') {
|
||||
try {
|
||||
const raw = await Promise.resolve(fn())
|
||||
if (typeof raw === 'string' && raw.trim()) {
|
||||
wailsApiBaseURL.value = raw.trim().replace(/\/$/, '')
|
||||
}
|
||||
} catch {
|
||||
/* binding error */
|
||||
}
|
||||
await tryLoadWailsLanHints(win)
|
||||
return
|
||||
}
|
||||
await new Promise((r) => setTimeout(r, 50))
|
||||
}
|
||||
await tryLoadWailsLanHints(win)
|
||||
}
|
||||
|
||||
async function tryLoadWailsLanHints(win: WeKnoraDesktopWindow) {
|
||||
const injectedLan = win.__WEKNORA_API_LAN_BASE__
|
||||
if (typeof injectedLan === 'string' && injectedLan.trim()) {
|
||||
wailsApiLanBaseURL.value = injectedLan.trim().replace(/\/$/, '')
|
||||
}
|
||||
const fnLan = win.go?.main?.App?.GetAPILanBaseURL
|
||||
if (typeof fnLan === 'function' && !wailsApiLanBaseURL.value) {
|
||||
try {
|
||||
const raw = await Promise.resolve(fnLan())
|
||||
if (typeof raw === 'string' && raw.trim()) {
|
||||
wailsApiLanBaseURL.value = raw.trim().replace(/\/$/, '')
|
||||
}
|
||||
} catch {
|
||||
/* binding error */
|
||||
}
|
||||
}
|
||||
const fnAct = win.go?.main?.App?.GetDesktopListenPublicActive
|
||||
if (typeof fnAct === 'function') {
|
||||
try {
|
||||
desktopListenPublicActive.value = !!(await Promise.resolve(fnAct()))
|
||||
} catch {
|
||||
desktopListenPublicActive.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function desktopPortBindingsAvailable(win: WeKnoraDesktopWindow) {
|
||||
const app = win.go?.main?.App
|
||||
return typeof app?.GetDesktopHTTPPortSetting === 'function' && typeof app?.SetDesktopHTTPPortSetting === 'function'
|
||||
}
|
||||
|
||||
function desktopBindPublicBindingsAvailable(win: WeKnoraDesktopWindow) {
|
||||
const app = win.go?.main?.App
|
||||
return (
|
||||
typeof app?.GetDesktopHTTPBindPublicSetting === 'function' &&
|
||||
typeof app?.SetDesktopHTTPBindPublicSetting === 'function'
|
||||
)
|
||||
}
|
||||
|
||||
async function loadDesktopApiPrefs() {
|
||||
const win = window as WeKnoraDesktopWindow
|
||||
if (desktopPortBindingsAvailable(win)) {
|
||||
showDesktopPortSetting.value = true
|
||||
try {
|
||||
const p = await Promise.resolve(win.go!.main!.App!.GetDesktopHTTPPortSetting!())
|
||||
desktopPortInput.value = typeof p === 'number' ? p : 0
|
||||
} catch {
|
||||
desktopPortInput.value = 0
|
||||
}
|
||||
}
|
||||
if (desktopBindPublicBindingsAvailable(win)) {
|
||||
showDesktopBindPublicSetting.value = true
|
||||
try {
|
||||
const b = await Promise.resolve(win.go!.main!.App!.GetDesktopHTTPBindPublicSetting!())
|
||||
desktopBindPublicInput.value = !!b
|
||||
} catch {
|
||||
desktopBindPublicInput.value = false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const onDesktopBindPublicChange = async (value: boolean) => {
|
||||
const v = value === true
|
||||
const win = window as WeKnoraDesktopWindow
|
||||
const fn = win.go?.main?.App?.SetDesktopHTTPBindPublicSetting
|
||||
if (typeof fn !== 'function') return
|
||||
try {
|
||||
await Promise.resolve(fn(v))
|
||||
MessagePlugin.success(t('tenant.api.desktopBindPublicSaved'))
|
||||
} catch (err: unknown) {
|
||||
MessagePlugin.error(err instanceof Error ? err.message : t('tenant.api.desktopBindPublicSaveFailed'))
|
||||
desktopBindPublicInput.value = !v
|
||||
}
|
||||
}
|
||||
|
||||
const saveDesktopPort = async () => {
|
||||
const v = desktopPortInput.value
|
||||
const port = typeof v === 'number' && !Number.isNaN(v) ? Math.floor(v) : 0
|
||||
if (port < 0 || port > 65535) {
|
||||
MessagePlugin.warning(t('tenant.api.desktopPortInvalid'))
|
||||
return
|
||||
}
|
||||
const win = window as WeKnoraDesktopWindow
|
||||
const fn = win.go?.main?.App?.SetDesktopHTTPPortSetting
|
||||
if (typeof fn !== 'function') return
|
||||
try {
|
||||
await Promise.resolve(fn(port))
|
||||
MessagePlugin.success(t('tenant.api.desktopPortSaved'))
|
||||
} catch (err: unknown) {
|
||||
MessagePlugin.error(err instanceof Error ? err.message : t('tenant.api.desktopPortSaveFailed'))
|
||||
}
|
||||
}
|
||||
|
||||
// Methods
|
||||
const loadInfo = async () => {
|
||||
try {
|
||||
loading.value = true
|
||||
error.value = ''
|
||||
|
||||
const userResponse = await getCurrentUser()
|
||||
|
||||
if ((userResponse as any).success && userResponse.data) {
|
||||
tenantInfo.value = userResponse.data.tenant ?? null
|
||||
} else {
|
||||
error.value = userResponse.message || t('tenant.messages.fetchFailed')
|
||||
}
|
||||
} catch (err: any) {
|
||||
error.value = err?.message || t('tenant.messages.networkError')
|
||||
} finally {
|
||||
loading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const openApiDoc = () => {
|
||||
window.open('https://github.com/Tencent/WeKnora/blob/main/docs/api/README.md', '_blank')
|
||||
}
|
||||
|
||||
const fallbackCopyText = (text: string) => {
|
||||
const textArea = document.createElement('textarea')
|
||||
textArea.value = text
|
||||
textArea.style.position = 'fixed'
|
||||
textArea.style.opacity = '0'
|
||||
document.body.appendChild(textArea)
|
||||
textArea.select()
|
||||
document.execCommand('copy')
|
||||
document.body.removeChild(textArea)
|
||||
}
|
||||
|
||||
const confirmResetApiKey = () => {
|
||||
if (!tenantInfo.value?.id) {
|
||||
MessagePlugin.warning(t('tenant.api.noKey'))
|
||||
return
|
||||
}
|
||||
const dialog = DialogPlugin.confirm({
|
||||
header: t('tenant.api.resetConfirmTitle'),
|
||||
body: t('tenant.api.resetConfirmBody'),
|
||||
confirmBtn: { content: t('tenant.api.resetConfirmOk'), theme: 'danger' },
|
||||
cancelBtn: t('tenant.api.resetConfirmCancel'),
|
||||
onConfirm: async () => {
|
||||
await performResetApiKey()
|
||||
dialog.destroy()
|
||||
},
|
||||
onClose: () => dialog.destroy(),
|
||||
})
|
||||
}
|
||||
|
||||
const performResetApiKey = async () => {
|
||||
if (!tenantInfo.value?.id) return
|
||||
resetting.value = true
|
||||
try {
|
||||
const resp = await resetTenantApiKey(tenantInfo.value.id)
|
||||
if (resp.success && resp.data?.api_key) {
|
||||
tenantInfo.value = { ...tenantInfo.value, api_key: resp.data.api_key }
|
||||
showApiKey.value = true
|
||||
MessagePlugin.success(t('tenant.api.resetSuccess'))
|
||||
} else {
|
||||
MessagePlugin.error(resp.message || t('tenant.api.resetFailed'))
|
||||
}
|
||||
} catch (err: any) {
|
||||
MessagePlugin.error(err?.message || t('tenant.api.resetFailed'))
|
||||
} finally {
|
||||
resetting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const copyApiKey = async () => {
|
||||
if (!tenantInfo.value?.api_key) {
|
||||
MessagePlugin.warning(t('tenant.api.noKey'))
|
||||
return
|
||||
}
|
||||
|
||||
try {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(tenantInfo.value.api_key)
|
||||
} else {
|
||||
fallbackCopyText(tenantInfo.value.api_key)
|
||||
}
|
||||
MessagePlugin.success(t('tenant.api.copySuccess'))
|
||||
} catch (err) {
|
||||
fallbackCopyText(tenantInfo.value.api_key)
|
||||
MessagePlugin.success(t('tenant.api.copySuccess'))
|
||||
}
|
||||
}
|
||||
|
||||
const copyLanApiUrl = async () => {
|
||||
const text = wailsApiLanBaseURL.value
|
||||
if (!text) return
|
||||
try {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(text)
|
||||
} else {
|
||||
fallbackCopyText(text)
|
||||
}
|
||||
MessagePlugin.success(t('tenant.api.lanUrlCopySuccess'))
|
||||
} catch {
|
||||
fallbackCopyText(text)
|
||||
MessagePlugin.success(t('tenant.api.lanUrlCopySuccess'))
|
||||
}
|
||||
}
|
||||
|
||||
const copyApiUrl = async () => {
|
||||
const text = apiBaseUrlDisplay.value
|
||||
try {
|
||||
if (navigator.clipboard && navigator.clipboard.writeText) {
|
||||
await navigator.clipboard.writeText(text)
|
||||
} else {
|
||||
fallbackCopyText(text)
|
||||
}
|
||||
MessagePlugin.success(t('tenant.api.urlCopySuccess'))
|
||||
} catch {
|
||||
fallbackCopyText(text)
|
||||
MessagePlugin.success(t('tenant.api.urlCopySuccess'))
|
||||
}
|
||||
}
|
||||
|
||||
// Lifecycle
|
||||
onMounted(async () => {
|
||||
await tryLoadWailsApiBaseURL()
|
||||
await loadDesktopApiPrefs()
|
||||
loadInfo()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.api-info {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
// TDesign's <t-input> forwards `style=""` to its wrapper but applies
|
||||
// `font: var(--td-font-body-medium)` (a shorthand) to the real <input>
|
||||
// inside, which silently resets font-family. Reach into the inner input
|
||||
// explicitly so the code font actually takes effect for API keys, URLs,
|
||||
// etc. Scoped via `.mono-text-input` so this only applies where we opt in.
|
||||
.mono-text-input :deep(input) {
|
||||
font-family: var(--app-font-family-mono);
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
|
||||
.doc-link {
|
||||
cursor: pointer;
|
||||
}
|
||||
}
|
||||
|
||||
.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;
|
||||
}
|
||||
}
|
||||
|
||||
.api-key-control {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.info-section-title {
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
color: var(--td-text-color-primary);
|
||||
margin-top: 24px;
|
||||
margin-bottom: 12px;
|
||||
|
||||
&:first-child {
|
||||
margin-top: 0;
|
||||
}
|
||||
}
|
||||
|
||||
/* 与 API Key / API 地址 行一致:输入区占满 flex 剩余宽度,文案按钮贴右 */
|
||||
.desktop-port-input-wrap {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
|
||||
:deep(.t-input-number) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(.t-input__wrap) {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
:deep(input) {
|
||||
font-family: var(--app-font-family-mono);
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.desktop-bind-public-control {
|
||||
padding-top: 4px;
|
||||
}
|
||||
|
||||
.lan-url-hint-row {
|
||||
padding-top: 0;
|
||||
border-bottom: 1px solid var(--td-component-stroke);
|
||||
|
||||
:deep(.t-alert) {
|
||||
width: 100%;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -44,6 +44,7 @@
|
||||
<path d="M4.5 5.5L6.5 12.5L9 7.5L11.5 12.5L13.5 5.5" stroke="currentColor" stroke-width="1.3"
|
||||
stroke-linecap="round" stroke-linejoin="round" fill="none" />
|
||||
</svg>
|
||||
<span v-else-if="item.emoji" class="nav-icon nav-icon-emoji">{{ item.emoji }}</span>
|
||||
<t-icon v-else :name="item.icon" class="nav-icon" />
|
||||
<span class="nav-label">{{ item.label }}</span>
|
||||
<t-icon v-if="item.children && item.children.length > 0"
|
||||
@@ -70,7 +71,7 @@
|
||||
<div class="settings-content">
|
||||
<div class="content-wrapper" :class="{
|
||||
'content-wrapper--wide': currentSection === 'members',
|
||||
'content-wrapper--full': currentSection === 'system-global',
|
||||
'content-wrapper--full': currentSection === 'system-global' || isIntegrationSection(currentSection),
|
||||
}">
|
||||
<!-- 角色不允许访问当前 section(deep-link 进来 / 跨租户切换后角色降级)—— 优先于具体 section 渲染。
|
||||
正常导航走 navItems filter 不会到这里,但 watch(navItems) 的 fallback 会在角色降级
|
||||
@@ -139,7 +140,6 @@
|
||||
</div>
|
||||
|
||||
<!-- 用户信息(账户基础信息:ID / 用户名 / 邮箱 / 注册时间)。
|
||||
从 ApiInfo.vue 拆出来,原页面挂的是 owner-only 入口,
|
||||
用户的基本信息不该跟 owner 权限绑定。 -->
|
||||
<div v-if="currentSection === 'userprofile'" class="section">
|
||||
<UserProfile />
|
||||
@@ -155,9 +155,9 @@
|
||||
<TenantMembers />
|
||||
</div>
|
||||
|
||||
<!-- API 信息 -->
|
||||
<div v-if="currentSection === 'api'" class="section">
|
||||
<ApiInfo />
|
||||
<!-- 发布集成 -->
|
||||
<div v-if="isIntegrationSection(currentSection)" class="section">
|
||||
<IntegrationSettingsSection :tab="integrationTabFromSection(currentSection)" />
|
||||
</div>
|
||||
|
||||
<!-- MCP 服务 -->
|
||||
@@ -182,7 +182,6 @@ import { useAuthStore } from '@/stores/auth'
|
||||
import { useI18n } from 'vue-i18n'
|
||||
import SystemInfo from './SystemInfo.vue'
|
||||
import TenantInfo from './TenantInfo.vue'
|
||||
import ApiInfo from './ApiInfo.vue'
|
||||
import UserProfile from './UserProfile.vue'
|
||||
import GeneralSettings from './GeneralSettings.vue'
|
||||
import ModelSettings from './ModelSettings.vue'
|
||||
@@ -196,6 +195,13 @@ import StorageEngineSettings from './StorageEngineSettings.vue'
|
||||
import WeKnoraCloudSettings from './WeKnoraCloudSettings.vue'
|
||||
import TenantMembers from './TenantMembers.vue'
|
||||
import SystemSettings from '@/views/system/SystemSettings.vue'
|
||||
import IntegrationSettingsSection from '@/views/integrations/IntegrationSettingsSection.vue'
|
||||
import {
|
||||
INTEGRATION_PREVIEW_ITEMS,
|
||||
INTEGRATION_TAB_MIN_ROLE,
|
||||
INTEGRATION_TABS,
|
||||
type IntegrationTab,
|
||||
} from '@/config/integrations'
|
||||
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
@@ -211,6 +217,7 @@ type NavItem = {
|
||||
key: string
|
||||
icon: string
|
||||
label: string
|
||||
emoji?: string
|
||||
children?: Array<{ key: string; label: string }>
|
||||
}
|
||||
|
||||
@@ -250,12 +257,45 @@ const SECTION_MIN_ROLE: Record<string, RoleKey> = {
|
||||
userprofile: 'viewer',
|
||||
tenant: 'viewer',
|
||||
members: 'viewer',
|
||||
api: 'owner',
|
||||
}
|
||||
|
||||
const SYSTEM_ADMIN_SECTIONS = new Set(['system-global'])
|
||||
const INTEGRATION_SECTION_PREFIX = 'integration-'
|
||||
|
||||
const integrationSectionKey = (tab: IntegrationTab) => `${INTEGRATION_SECTION_PREFIX}${tab}`
|
||||
|
||||
const integrationTabFromSection = (section: string): IntegrationTab => {
|
||||
const raw = section.startsWith(INTEGRATION_SECTION_PREFIX)
|
||||
? section.slice(INTEGRATION_SECTION_PREFIX.length)
|
||||
: section
|
||||
if (INTEGRATION_TABS.includes(raw as IntegrationTab)) {
|
||||
return raw as IntegrationTab
|
||||
}
|
||||
return 'im'
|
||||
}
|
||||
|
||||
const isIntegrationSection = (section: string) => {
|
||||
return section.startsWith(INTEGRATION_SECTION_PREFIX) &&
|
||||
INTEGRATION_TABS.includes(integrationTabFromSection(section))
|
||||
}
|
||||
|
||||
const normalizeSettingsSection = (section: string) => {
|
||||
if (section === 'api') {
|
||||
return integrationSectionKey('api')
|
||||
}
|
||||
if (section === 'integrations') {
|
||||
return integrationSectionKey(integrationTabFromSection((route.query.tab as string) || 'im'))
|
||||
}
|
||||
return section
|
||||
}
|
||||
|
||||
const canSeeSection = (key: string): boolean => {
|
||||
if (isIntegrationSection(key)) {
|
||||
const min = INTEGRATION_TAB_MIN_ROLE[integrationTabFromSection(key)]
|
||||
if (!min) return true
|
||||
if (authStore.canAccessAllTenants) return true
|
||||
return authStore.hasRole(min)
|
||||
}
|
||||
if (SYSTEM_ADMIN_SECTIONS.has(key)) {
|
||||
return authStore.isSystemAdmin
|
||||
}
|
||||
@@ -270,6 +310,12 @@ const navItems = computed(() => {
|
||||
// 一律走 SECTION_MIN_ROLE 表,避免 ad-hoc isAdmin/isOwner 散落在多处。
|
||||
// 服务端在每条路由上仍以 g.Viewer/Admin/Owner 为准,这里只决定 UI 是
|
||||
// 否露入口;改动入口规则请同步更新 SECTION_MIN_ROLE 注释里的对照路由。
|
||||
const integrationItems: NavItem[] = INTEGRATION_PREVIEW_ITEMS.map((item) => ({
|
||||
key: integrationSectionKey(item.key),
|
||||
icon: item.icon.type === 'icon' ? item.icon.name : 'integration',
|
||||
emoji: item.icon.type === 'emoji' ? item.icon.value : undefined,
|
||||
label: t(`integrations.tabs.${item.key}`),
|
||||
}))
|
||||
const all: NavItem[] = [
|
||||
{ key: 'general', icon: 'setting', label: t('general.title') },
|
||||
{ key: 'ollama', icon: 'server', label: 'Ollama' },
|
||||
@@ -286,7 +332,7 @@ const navItems = computed(() => {
|
||||
{ key: 'userprofile', icon: 'user', label: t('userProfile.title') },
|
||||
{ key: 'tenant', icon: 'user-circle', label: t('settings.tenantInfo') },
|
||||
{ key: 'members', icon: 'usergroup', label: t('tenantMember.title') },
|
||||
{ key: 'api', icon: 'secured', label: t('settings.apiInfo') },
|
||||
...integrationItems,
|
||||
]
|
||||
// currentTenantRole 为空表示「membership 还没加载」—— 比起渲染整套
|
||||
// viewer 入口然后角色一返回又消失,先卡住不渲染更稳,跟原先 members
|
||||
@@ -300,15 +346,15 @@ const navItems = computed(() => {
|
||||
const navGroups = computed<NavGroup[]>(() => {
|
||||
const itemMap = new Map(navItems.value.map((item) => [item.key, item]))
|
||||
const pickItems = (keys: string[]) => keys.map((key) => itemMap.get(key)).filter(Boolean) as NavItem[]
|
||||
// 分组:账户 → 空间 → 模型 → 数据与扩展 → 平台(文案见 i18n settings.navGroups)
|
||||
// 关键调整:把个人偏好(general)和个人凭证(api)收进「账户」;
|
||||
// 分组:账户 → 空间 → 模型 → 发布集成 → 数据与扩展 → 平台(文案见 i18n settings.navGroups)
|
||||
// 关键调整:把个人偏好(general)和用户信息收进「账户」;
|
||||
// 把空间内功能开关(chathistory)从「平台」挪到「空间」;
|
||||
// 把检索引擎和外部集成合并为「数据与扩展」,避免两个 2~3 项的窄分组。
|
||||
return [
|
||||
{
|
||||
key: 'account',
|
||||
label: t('settings.navGroups.account'),
|
||||
items: pickItems(['general', 'userprofile', 'api']),
|
||||
items: pickItems(['general', 'userprofile']),
|
||||
},
|
||||
{
|
||||
key: 'workspace',
|
||||
@@ -320,10 +366,27 @@ const navGroups = computed<NavGroup[]>(() => {
|
||||
label: t('settings.navGroups.modelsRuntime'),
|
||||
items: pickItems(['models', 'ollama', 'weknoracloud']),
|
||||
},
|
||||
{
|
||||
key: 'integrations',
|
||||
label: t('integrations.title'),
|
||||
items: pickItems([
|
||||
integrationSectionKey('im'),
|
||||
integrationSectionKey('embed'),
|
||||
integrationSectionKey('api'),
|
||||
integrationSectionKey('chrome'),
|
||||
integrationSectionKey('claw'),
|
||||
]),
|
||||
},
|
||||
{
|
||||
key: 'data_extensions',
|
||||
label: t('settings.navGroups.dataExtensions'),
|
||||
items: pickItems(['vectorstore', 'parser', 'storage', 'websearch', 'mcp']),
|
||||
items: pickItems([
|
||||
'vectorstore',
|
||||
'parser',
|
||||
'storage',
|
||||
'websearch',
|
||||
'mcp',
|
||||
]),
|
||||
},
|
||||
{
|
||||
key: 'platform',
|
||||
@@ -350,6 +413,16 @@ const handleNavClick = (item: any) => {
|
||||
|
||||
// 切换到对应页面
|
||||
currentSection.value = item.key
|
||||
if (isIntegrationSection(item.key) && route.path === '/platform/settings') {
|
||||
router.replace({
|
||||
path: '/platform/settings',
|
||||
query: {
|
||||
...route.query,
|
||||
section: 'integrations',
|
||||
tab: integrationTabFromSection(item.key),
|
||||
},
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// 子菜单点击处理
|
||||
@@ -388,8 +461,9 @@ const handleClose = () => {
|
||||
// 监听初始导航设置
|
||||
watch(() => uiStore.settingsInitialSection, (section) => {
|
||||
if (section && visible.value) {
|
||||
currentSection.value = section
|
||||
const navItem = (navItems.value as any[]).find((item) => item.key === section)
|
||||
const normalizedSection = normalizeSettingsSection(section)
|
||||
currentSection.value = normalizedSection
|
||||
const navItem = (navItems.value as any[]).find((item) => item.key === normalizedSection)
|
||||
if (navItem && navItem.children && navItem.children.length > 0) {
|
||||
if (!expandedMenus.value.includes(section)) {
|
||||
expandedMenus.value.push(section)
|
||||
@@ -413,7 +487,7 @@ watch(
|
||||
() => [visible.value, route.query.section],
|
||||
([isVisible, section]) => {
|
||||
if (!isVisible || typeof section !== 'string') return
|
||||
currentSection.value = section
|
||||
currentSection.value = normalizeSettingsSection(section)
|
||||
currentSubSection.value = ''
|
||||
},
|
||||
{ immediate: true },
|
||||
@@ -439,9 +513,10 @@ const handleEscape = (e: KeyboardEvent) => {
|
||||
const handleSettingsNav = (e: CustomEvent) => {
|
||||
const { section, subsection } = e.detail
|
||||
if (section) {
|
||||
currentSection.value = section
|
||||
const normalizedSection = normalizeSettingsSection(section)
|
||||
currentSection.value = normalizedSection
|
||||
// 如果有子菜单,自动展开
|
||||
const navItem = (navItems.value as any[]).find((item: any) => item.key === section)
|
||||
const navItem = (navItems.value as any[]).find((item: any) => item.key === normalizedSection)
|
||||
if (navItem && navItem.children && navItem.children.length > 0) {
|
||||
if (!expandedMenus.value.includes(section)) {
|
||||
expandedMenus.value.push(section)
|
||||
@@ -601,6 +676,11 @@ onUnmounted(() => {
|
||||
color: inherit;
|
||||
}
|
||||
|
||||
.nav-icon-emoji {
|
||||
font-size: 14px;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.nav-label {
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user