Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions ui/src/views/VIEW_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,8 @@ System 资源管理与共享资源已注册共用知识库详情路由,
基础表单 `KnowledgeBaseForm` 内部根据资源范围选择完整模型 API,不接收外部 `modelApi`;
Workspace 普通与共享资源均使用 Workspace 模型选项接口,System 资源管理使用 System 模型接口,
System 共享使用系统共享模型接口。
System 暂无前端 Sync API 模块,定时同步页仍展示设置及日志布局,不发送 Workspace 请求。
四种范围的定时同步查询和日志均使用各自现有 Sync API;Workspace 普通和 System 两种范围支持保存,
Workspace 共享只读,不发送保存请求,不回退 Workspace 接口。
library 的接口调整已撤回,文档和标签沿用原有调用方式,System library API 适配尚未实施。
路由结构及来源配置见 `src/router/ROUTE_README.md`。

Expand Down Expand Up @@ -1411,14 +1412,16 @@ chat 装配函数通过 `disabled` 禁用输入框与附件。
上下文只维护共享详情数据、更新能力及多个子页面共用的接口。仅由单个子页面使用的接口,
在该页面内部按资源范围选择,不为单页接口增加 context 配置或转发 getter。
定时同步接口属于定时同步页自身职责;未提供对应范围接口时,不回退到 Workspace,
也不为 Workspace 共享只读资源增加写接口。当前 `sync` 尚保留在详情上下文,后续调整时按此规则收回定时同步页。
也不为 Workspace 共享只读资源增加写接口。同步接口由 `useKnowledgeSyncContext` 提供给定时同步页,
按现有四套 Sync API 的真实方法集合装配,不扩展接口。

`provideKnowledgeDetailContext` 在详情入口装配并提供上下文,`useKnowledgeDetailContext` 供子页读取。
基础设置和文档策略通过 `useKnowledgeSettingContext` 获取可管理范围的完整 Knowledge API 类型,
该设置上下文的 `resourceApi` 仅提供 `knowledge`;定时同步从普通详情上下文读取 `sync`,不重复暴露。
该设置上下文的 `resourceApi` 仅提供 `knowledge`;定时同步通过 `useKnowledgeSyncContext` 读取当前
`resourceApi.sync` 及可保存范围的 `requestSettingApi`。Workspace 共享只查询设置和日志,表单只读且不显示保存。
不在页面用方法是否存在判断可写能力;上下文边界排除 Workspace 共享只读范围,
共享设置路由已注册,API 上下文仍保留原有只读边界,写接口接入暂缓。
上下文按响应式 `resourceScope` 选择完整 Knowledge、Sync API 对象,
上下文按响应式 `resourceScope` 选择各范围现有完整 Knowledge、Sync API 对象,
统一通过响应式 `resourceApi.knowledge / sync` 提供接口,脚本调用不需要 `.value`;
详情查询与保存使用同一个完整 Knowledge API 对象,不存在的设置模块保持 undefined。
返回列表路由独立提供;不要在 setup 时解构 `resourceApi` 内的具体 API,以免固定为旧范围的对象。
Expand All @@ -1429,5 +1432,5 @@ library 下的文档、标签与迁移组件保留原有调用方式,不装配
System 飞书专用保存方法尚未提供,基础设置沿该范围现有 `putKnowledge` 协议;Workspace 飞书保留专用方法。

四套知识库详情菜单及来源导航已统一,`useKnowledgeNavigationContext` 仅维护路由名称与参数,
不配置 API。各范围接口存在差异,API 模块和原有详情接口上下文保持原实现;
后续按每套真实接口分别接入,不将菜单完整度视为接口接入完成。
不配置 API。各范围接口存在差异,API 模块保持原实现;本轮仅补齐 sync 的范围装配与消费,
其他模块后续按每套真实接口分别接入,不将菜单完整度视为接口接入完成。
22 changes: 18 additions & 4 deletions ui/src/views/knowledge-detail/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@ import SharedKnowledgeApi from '@/api/admin/workspace/shared/knowledge/knowledge
import SystemResourceKnowledgeApi from '@/api/admin/system/resource-management/knowledge/knowledge'
import SystemSharedKnowledgeApi from '@/api/admin/system/shared-resources/knowledge/knowledge'
import SyncApi from '@/api/admin/workspace/knowledge/sync'
import SharedSyncApi from '@/api/admin/workspace/shared/knowledge/sync'
import SystemResourceSyncApi from '@/api/admin/system/resource-management/knowledge/sync'
import SystemSharedSyncApi from '@/api/admin/system/shared-resources/knowledge/sync'
import type { KnowledgeDetail } from '@/api/types'
import type { ResourceScope } from '@/router/admin/types'

interface KnowledgeResourceApi {
readonly knowledge: typeof KnowledgeApi | typeof SharedKnowledgeApi | typeof SystemResourceKnowledgeApi | typeof SystemSharedKnowledgeApi
readonly sync?: typeof SyncApi
readonly sync: typeof SyncApi | typeof SharedSyncApi | typeof SystemResourceSyncApi | typeof SystemSharedSyncApi
}

interface KnowledgeResourceConfig {
Expand All @@ -26,15 +29,15 @@ const resourceConfigs = {
listRouteName: 'workspace-knowledge-list',
},
'workspace-shared': {
resourceApi: { knowledge: SharedKnowledgeApi },
resourceApi: { knowledge: SharedKnowledgeApi, sync: SharedSyncApi },
listRouteName: 'workspace-knowledge-list',
},
'system-resource': {
resourceApi: { knowledge: SystemResourceKnowledgeApi },
resourceApi: { knowledge: SystemResourceKnowledgeApi, sync: SystemResourceSyncApi },
listRouteName: 'system-resource-knowledge',
},
'system-shared': {
resourceApi: { knowledge: SystemSharedKnowledgeApi },
resourceApi: { knowledge: SystemSharedKnowledgeApi, sync: SystemSharedSyncApi },
listRouteName: 'system-shared-knowledge',
},
} satisfies Record<ResourceScope, KnowledgeResourceConfig>
Expand Down Expand Up @@ -91,6 +94,17 @@ export function useKnowledgeDetailContext() {
return context
}

/** 同步查询使用当前范围,保存仅提供给现有 API 支持写入的三个范围。 */
export function useKnowledgeSyncContext() {
const context = useKnowledgeDetailContext()
const requestSettingApi = computed(() => {
const scope = context.resourceScope.value
if (!scope || scope === 'workspace-shared') return undefined
return resourceConfigs[scope].resourceApi.sync
})
return { ...context, requestSettingApi }
}

/** 设置页只属于可管理范围,在上下文边界排除 Workspace 共享只读资源。 */
export function useKnowledgeSettingContext() {
const context = useKnowledgeDetailContext()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
<script setup lang="ts">
import { onMounted, ref } from 'vue'
import { ref, watch } from 'vue'
import type SyncApi from '@/api/admin/workspace/knowledge/sync'
import type SharedSyncApi from '@/api/admin/workspace/shared/knowledge/sync'
import type SystemResourceSyncApi from '@/api/admin/system/resource-management/knowledge/sync'
import type SystemSharedSyncApi from '@/api/admin/system/shared-resources/knowledge/sync'
import { KNOWLEDGE_SYNC_STATUS, KNOWLEDGE_SYNC_TYPE } from '@/api/enums'
import type { KnowledgeSyncLog, KnowledgeSyncStatus } from '@/api/types'
import type { StatusLabelOptions } from '@/components/global/mk-status-label/types'
import { KNOWLEDGE_SYNC_OPTIONS } from '@/constants/knowledge'
import { datetimeFormat } from '@/utils/time'

defineOptions({ name: 'KnowledgeSyncLogTable' })
const props = defineProps<{ knowledgeId: string; api?: typeof SyncApi }>()
const props = defineProps<{
knowledgeId: string
api: typeof SyncApi | typeof SharedSyncApi | typeof SystemResourceSyncApi | typeof SystemSharedSyncApi
}>()

// 进入日志页签时挂载查询,翻页由表格事件重新查询。
const loading = ref(false)
Expand All @@ -34,7 +40,6 @@ function getSyncContent(log: KnowledgeSyncLog) {
return `共${log.total_count}个文档 (${counts.join(',')})`
}
function loadSyncLogs() {
if (!props.api) return
if (loading.value) return
loading.value = true
return props.api
Expand All @@ -50,9 +55,15 @@ function loadSyncLogs() {
})
}

onMounted(() => {
void loadSyncLogs()
})
watch(
[() => props.knowledgeId, () => props.api],
() => {
syncLogs.value = []
paginationConfig.value = { currentPage: 1, pageSize: 10, total: 0 }
void loadSyncLogs()
},
{ immediate: true },
)
</script>

<template>
Expand Down
30 changes: 20 additions & 10 deletions ui/src/views/knowledge-detail/setting/scheduled-sync/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import { SCHEDULE_OPTION } from '@/constants/schedule'
import { KNOWLEDGE_SYNC_OPTIONS } from '@/constants/knowledge'
import type { ResourceDetailPageProps } from '@/layout/ResourceDetailLayout.vue'
import { MsgSuccess } from '@/utils/message'
import { useKnowledgeDetailContext } from '../../context'
import { useKnowledgeSyncContext } from '../../context'
import SyncLogTable from './components/SyncLogTable.vue'

defineOptions({ name: 'KnowledgeScheduledSyncView' })

defineProps<ResourceDetailPageProps>()

// 回填后台配置,草稿与详情中的配置独立。
const { knowledge, replaceKnowledgeDetail, resourceApi } = useKnowledgeDetailContext()
const { knowledge, replaceKnowledgeDetail, resourceApi, requestSettingApi, resourceScope } = useKnowledgeSyncContext()
const activeTab = ref('settings')
const loading = ref(false)
const saving = ref(false)
Expand Down Expand Up @@ -106,7 +106,8 @@ const rules: FormRules<SyncSettingDraft> = {
}

function handleSave() {
if (!resourceApi.sync) return
const requestApi = requestSettingApi.value
if (!requestApi) return
const detail = knowledge.value
const form = formRef.value
if (saving.value || loading.value || !settingLoaded.value || !detail || !form) return
Expand All @@ -116,7 +117,7 @@ function handleSave() {
.then(() => {
if (!syncSetting.value.schedule_type) return
const setting: KnowledgeSyncSetting = { ...cloneDeep(syncSetting.value), schedule_type: syncSetting.value.schedule_type }
return resourceApi.sync?.putKnowledgeSyncSetting(detail.id, setting).then((savedSetting) => {
return requestApi.putKnowledgeSyncSetting(detail.id, setting).then((savedSetting) => {
syncSetting.value = cloneDeep(savedSetting)
replaceKnowledgeDetail({ ...detail, meta: { ...detail.meta, sync_setting: savedSetting } })
MsgSuccess('保存成功')
Expand All @@ -129,8 +130,6 @@ function handleSave() {
}

function loadSyncSetting(knowledgeId: string) {
// TODO 补了接口就可以了
if (!resourceApi.sync) return Promise.resolve()
loading.value = true
settingLoaded.value = false
return resourceApi.sync
Expand All @@ -147,9 +146,10 @@ function loadSyncSetting(knowledgeId: string) {
}

watch(
() => knowledge.value?.id,
(knowledgeId) => {
[() => knowledge.value?.id, resourceScope],
([knowledgeId]) => {
activeTab.value = 'settings'
settingLoaded.value = false
syncSetting.value = createDefaultSyncSetting()
presetScheduleType.value = undefined
formRef.value?.clearValidate()
Expand All @@ -166,7 +166,15 @@ watch(
<el-tab-pane label="同步日志" name="logs" />
</el-tabs>
<div v-show="activeTab === 'settings'" v-loading="loading || saving" class="min-h-40">
<el-form ref="formRef" :model="syncSetting" :rules="rules" class="max-w-200 pb-6" label-position="top" @submit.prevent>
<el-form
ref="formRef"
:model="syncSetting"
:rules="rules"
class="max-w-200 pb-6"
label-position="top"
:disabled="!requestSettingApi"
@submit.prevent
>
<el-form-item>
<template #label>
<span>
Expand Down Expand Up @@ -212,7 +220,9 @@ watch(
</el-form-item>
</div>
<!-- 保存定时同步设置 -->
<el-button type="primary" class="mt-4" :loading="saving" :disabled="!settingLoaded" @click="handleSave">保存</el-button>
<el-button v-if="requestSettingApi" type="primary" class="mt-4" :loading="saving" :disabled="!settingLoaded" @click="handleSave">
保存
</el-button>
</el-form>
</div>
<SyncLogTable v-if="activeTab === 'logs' && knowledge" :api="resourceApi.sync" :knowledge-id="knowledge.id" />
Expand Down
Loading