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
1 change: 1 addition & 0 deletions ui/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ OSS 文件接口。前端业务接口需要可用的后端服务。
默认构建分别输出 `dist/admin/index.html` 和 `dist/chat/index.html`,HTML 由构建插件统一重命名。
静态资源使用相对路径(`base: './'`);部署时仍需为 History 路由配置对应入口回退,
并由部署服务转发 API 和文件请求。Vite 的开发代理不会随静态构建产物部署。
外置语言包由部署服务提供,目录和索引格式见[外置语言包](src/locales/LOCALE_README.md#外置语言包)。

## 界面语言

Expand Down
9 changes: 8 additions & 1 deletion ui/src/layout/ResourceDetailLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function navigateToDetailMenu(detailMenuItem: LayoutMenuItem) {
</script>

<template>
<MkViewLayout :loading="props.loading" title="">
<MkViewLayout class="resource-detail-layout" :loading="props.loading" title="">
<template #aside="{ Header }">
<component :is="Header">
<div class="flex-align-center min-w-0 gap-2">
Expand Down Expand Up @@ -74,3 +74,10 @@ function navigateToDetailMenu(detailMenuItem: LayoutMenuItem) {
</template>
</MkViewLayout>
</template>

<style scoped>
/* 让有独立滚动区的详情子页使用正文滚动容器的可用高度。 */
.resource-detail-layout :deep(main > .el-scrollbar > .el-scrollbar__wrap > .el-scrollbar__view:has(> .mk-scrollbar-fill-height)) {
height: 100%;
}
</style>

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is syntactically valid, but there are several fragility/compatibility concerns:

  1. :has() browser support

    • :has() is not supported in older browser versions. If the project still supports older Safari/Firefox/enterprise browsers, this layout rule will silently fail.
    • PostCSS/autoprefixer generally won’t transpile :has(). Use a fallback or avoid :has() if support is required.
  2. Tight coupling to Element Plus / MkViewLayout internal DOM

    • This selector depends on the exact DOM chain:
      main > .el-scrollbar > .el-scrollbar__wrap > .el-scrollbar__view.
    • Any internal change in MkViewLayout or Element Plus can break it silently.
    • Prefer exposing a prop/class from MkViewLayout or applying a dedicated class to the scrollbar view instead of piercing internal implementation details.
  3. Assumption that class="resource-detail-layout" lands on the expected root

    • This works only if MkViewLayout has a single root element and normal attribute fallthrough.
    • If it uses a fragment root, inheritAttrs: false, or redirects attrs, the selector may not match.
  4. height: 100% may be ineffective

    • height: 100% only resolves correctly if the parent chain has a definite height.
    • In flex layouts, you often need flex: 1; min-height: 0; rather than only height: 100%.
    • Verify this does not create nested scrollbars or clip content.
  5. :has(> .mk-scrollbar-fill-height) is direct-child-only

    • If an extra wrapper is introduced around .mk-scrollbar-fill-height, the rule stops applying.
    • Confirm this strict relationship is intentional.
  6. Potentially broad selector

    • .resource-detail-layout :deep(main > ...) can match nested main elements under the layout.
    • If nested layouts are possible, consider a tighter selector or a dedicated class for the target scrollbar view.

Suggested improvement: avoid :has() and internal DOM coupling by having MkViewLayout support a “fill height” class/prop, or by placing a semantic class directly on the scrollbar view. If keeping the current approach, add a browser-support fallback and document that the selector depends on Element Plus internals.

Minor: the CSS comment is in Chinese; consider matching the project’s comment-language convention.

37 changes: 19 additions & 18 deletions ui/src/locales/LOCALE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,24 +228,25 @@ Vue 组件显式导入 `useI18n`,使用 `useI18n({ useScope: 'global' })`;

## 语言状态

Admin 和 Chat 各自在独立页面调用 `createAppI18n` 创建实例并连接自己的 User Store。模块导出的 `t` 来自当前页面创建的实例。
Store 是语言状态来源,通过 setLanguage 更新,不能直接修改 Vue I18n 的 locale。
App.vue 通过当前 locale 配置 Element Plus,并注册 Day.js 的 zh-cn、zh-tw 日期语言包;
英文使用内置 en。日期组件按当前 Element Plus 语言读取日期文案,不修改时区及原始值。
初始化同时维护 html.lang。Markdown 编辑器与预览读取当前应用的 locale,繁体映射为 zh-TW,
语言包在入口通过 configureMarkdownEditor 注册,不跟随语言切换重复初始化或重建编辑器。

Admin 使用 MaxKB-locale,初始化按本地缓存、浏览器语言、默认中文选择,加载账号后继续采用账号语言。
Chat(单应用与门户)不读写浏览器语言缓存,初始化使用浏览器语言。
加载当前对话用户档案后,优先应用账号 language;档案未提供语言时保留当前语言。
Chat 入口调用 `createAppI18n(user, null)`,不监听浏览器语言缓存变化。
英语变体归一为 en-US;zh-Hant、zh-TW、zh-HK、zh-MO 归一为 zh-Hant,
显式 zh-Hans 优先使用简体;其他语言按上述外置包注册与回退规则解析。Element Plus 的繁体映射为 zh-tw。
Admin 跨标签页同步 MaxKB-locale 的变化。请求头复用原请求层的 user.language。
登录前的语言选择在 Admin 保存到浏览器缓存,在 Chat 仅更新当前内存状态;头部菜单调用当前账号语言接口,
成功后同步 Store 和用户档案,Admin 同时更新本地偏好,不刷新页面。Admin 和 Chat 后续加载账号时继续采用已保存的账号语言。

`src/main.ts`、`src/chat.ts` 的 import、样式、初始化和插件注册顺序始终保持,新增国际化内容也不得重排。
每个入口以自己的 User Store 创建 createAppI18n 实例,模块导出的 t 属于当前入口。
语言只通过 Store.setLanguage 更新,不直接修改 Vue I18n.locale;初始化和切换同时更新 html.lang。

| 行为 | Admin | Chat(单应用/门户) |
| ------------ | ------------------------------------ | ----------------------------------------- |
| 初始语言 | MaxKB-locale → 浏览器语言 → 默认中文 | 浏览器语言,不读写语言缓存 |
| 加载用户档案 | 使用账号 language | 有 language 则使用,否则保留当前语言 |
| 登录前选择 | 写入本地缓存 | 只更新内存 |
| 账号菜单保存 | 接口成功后同步 Store、档案和缓存 | 接口成功后同步 Store 和档案 |
| 跨标签页 | 监听 MaxKB-locale | createAppI18n(user, null),不监听语言缓存 |

保存语言不刷新页面,后续档案加载继续采用账号语言;请求头沿用 user.language。
英语变体归 en-US,zh-Hant/TW/HK/MO 归 zh-Hant,显式 zh-Hans 优先简体;
其余语言按[外置包规则](#外置语言包)解析和回退。

App.vue 按 locale 配置 Element Plus;Day.js 使用 zh-cn/zh-tw 和内置 en,不改变时区或数据值。
Markdown 语言包由入口 configureMarkdownEditor 注册,繁体映射 zh-TW;切换语言只更新属性,不重建编辑器。
外置语言缺少编辑器语言包时回退默认语言。
入口 import、样式、初始化和插件注册顺序遵循 [AGENTS.md](../../AGENTS.md#import-顺序),不得因国际化重排。

## 公共能力与资源组件

Expand Down
4 changes: 3 additions & 1 deletion ui/src/router/ROUTE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,9 @@ Workspace 共享覆盖 resourceScope,保留 Workspace scope 及知识库 activ
设置只用 detailMenuVisible 控制菜单类型,不添加类型访问守卫。资料库 View 的目录是 library/tags,URL 仍为 tag。

分段地址在各来源详情后追加 `/document/:documentId`,路由名为 `<resourceScope>-knowledge-paragraph`。
与详情容器同级挂载,使用自身分段目录;配置 hidden 和 resourceDetailRoot,返回对应文档列表并保留 query。
与详情容器同级挂载,使用自身分段目录,并配置 hidden 和 resourceDetailRoot。
文档列表打开分段成功后临时保存分页。分段页返回时优先使用原列表地址,直接打开分段页时按资源范围进入对应列表并透传业务 query。
列表在首次查询前一次性读取并清空从分段返回的分页快照。刷新或从其他页面进入时使用默认分页。
全屏画布直接访问时检查真实知识库类型,非工作流返回转换页;返回导航集中在 workflow/knowledge/navigation.ts。
菜单与路由存在不代表该范围全部 API 已支持,真实接口边界见 API 文档。

Expand Down
27 changes: 10 additions & 17 deletions ui/src/styles/STYLE_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,21 +180,14 @@ CSS 自定义属性同样按变量名排序。嵌套选择器、伪类和媒体
| `flex-column` | Flex 布局,纵向排列,等价于 `flex flex-col` |
| `flex-wrap` | 横向排列,自动换行,行间距为 8px |

普通布局中的 `flex items-center` 统一使用 `flex-align-center`;间距、尺寸继续组合原子类。
该工具类仅设置 `display: flex` 和 `align-items: center`,不设置方向、主轴对齐或间距;
`inline-flex items-center` 保留原写法,不替换为块级 Flex 布局。
仅在布局语义与工具类完全一致时使用。需要覆盖排列方向或对齐方式的响应式布局继续组合 Tailwind
原子类,不为少量差异继续增加相似工具类。

静态纵向 Flex 布局中的 `flex flex-col` 统一使用 `flex-column`,仅设置 `display: flex`
和 `flex-direction: column`;`gap-*`、`flex-1`、`min-h-0` 等按实际需要单独组合。
动态或响应式切换方向继续使用内置 `flex-col`,不改变该类仅设置排列方向的含义;
双轴居中的纵向布局继续使用 `flex-col-center`。

子元素自然按块级纵向排列、仅需要上下间距时,优先使用 `space-y-*`,不额外引入 Flex。
`space-y-*` 通过直接子元素的外边距提供间距,不负责换行、拉伸或剩余高度分配;
有 `flex-1`、`self-*`、滚动高度约束、行内子元素或子元素外边距依赖时,不直接替换
`flex-column gap-*`。条件显隐和第三方组件场景需检查实际渲染结构及间距。
静态横向居中用 flex-align-center(仅设置 display、align-items),静态纵向布局用 flex-column
(仅设置 display、flex-direction);尺寸、间距和剩余空间另行组合。inline-flex 保留原写法,
响应式或动态切换方向/对齐时继续使用原子类,双轴居中的纵向布局用 flex-col-center。
不为少量差异新增相似工具类。

自然块级排列仅需上下间距时用 space-y-_;它只通过直属子元素的 margin 提供间距,不负责
换行、拉伸或剩余高度。有 flex-1、self-_、滚动高度、行内元素或子项 margin 依赖时,
不直接替换 flex-column gap-\*;条件显隐和第三方组件须检查实际 DOM。

## 常用卡片样式

Expand Down Expand Up @@ -276,8 +269,8 @@ CSS 自定义属性同样按变量名排序。嵌套选择器、伪类和媒体

组件内需要展示滚动条时优先使用 Element Plus 的 `el-scrollbar`,保持滚动条样式和交互一致。

页面有独立的内部滚动区时,可在 `MkViewLayout` 正文的根元素上添加 `mk-scrollbar-fill-height`。
该元素须是 `el-scrollbar` 内容层的直接子元素,由 `app.scss` 将内容层高度约束为可用高度。
资源详情子页有独立的内部滚动区时,可在子页根元素添加 `mk-scrollbar-fill-height`。
该元素须是正文 `el-scrollbar` 内容层的直接子元素,由 `ResourceDetailLayout` 将内容层高度约束为可用高度。

`el-textarea` 保留原生文本域滚动,由 `element-plus.scss` 统一对齐 `el-scrollbar` 的外观:
Chromium/Safari 使用 6px 滚动条、4px 圆角滑块和透明轨道,滑块复用 Element Plus 滚动条
Expand Down
5 changes: 0 additions & 5 deletions ui/src/styles/app.scss
Original file line number Diff line number Diff line change
Expand Up @@ -493,11 +493,6 @@ h6 {
}

/* scrollbar */
// 让内部有独立滚动区的页面使用外层滚动容器的可用高度。
.el-scrollbar__view:has(> .mk-scrollbar-fill-height) {
height: 100%;
}

// 让一些组件内部滚动条 不会限制在padding内,滚动条贴在最右侧
.mk-scrollbar-right {
&.el-scrollbar {
Expand Down
23 changes: 3 additions & 20 deletions ui/src/utils/UTILS_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,9 @@ MkTable 的服务端排序列声明 `sortable` 即可,由组件统一转换为
不要在业务代码中直接初始化 SortableJS 或重复实现 DOM 还原和数组移动。目录树继续使用
`@he-tree/vue` 的树形拖拽协议。

```ts
import { ref } from 'vue'
import { useSortable } from '@/utils/use-sortable'

const rowContainer = ref<HTMLElement>()
const taskRows = ref([
{ id: 'a', name: '任务 A' },
{ id: 'b', name: '任务 B' },
])
const sortDisabled = ref(false)

useSortable(rowContainer, taskRows, () => ({
handle: '.task-drag-handle',
draggable: '> .task-row',
disabled: sortDisabled.value,
onReorder: ({ oldIndex, newIndex, data }) => {
// data 已经完成排序,可在这里保存新顺序,不要再次 splice。
},
}))
```
调用 useSortable(container, rows, options):container 为容器 Ref 或 getter,rows 为列表 Ref,
options 中用 handle/draggable 指定手柄和行,disabled 控制禁用,onReorder 保存新顺序。
库已更新数组,回调不得再次 splice。

容器的直属可拖动元素应与数组逐项对应,Vue 渲染使用稳定业务 ID 作为 `key`;添加按钮等
操作元素放在行容器之外。容器参数支持模板 Ref 或返回 HTMLElement 的 getter,适配 `v-if`
Expand Down
6 changes: 4 additions & 2 deletions ui/src/views/document-detail/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import ProblemApi from '@/api/admin/workspace/knowledge/problem'
import SharedDocumentApi from '@/api/admin/workspace/shared/knowledge/document'
import SharedParagraphApi from '@/api/admin/workspace/shared/knowledge/paragraph'
import SharedProblemApi from '@/api/admin/workspace/shared/knowledge/problem'
import { getDocumentListReturnLocation } from '@/views/knowledge-detail/library/document/pagination-return'

const resourceConfigs = {
workspace: { document: DocumentApi, paragraph: ParagraphApi, problem: ProblemApi },
Expand Down Expand Up @@ -53,15 +54,16 @@ function createDocumentDetailContext() {
function handleBack() {
const scope = route.meta.resourceScope
if (!scope) throw new Error('Document detail resource scope is unavailable')
void router.push({
const documentList = {
name: `${scope}-knowledge-document-list`,
params: {
...(scope === 'workspace' || scope === 'workspace-shared' ? { workspaceId: route.params.workspaceId } : {}),
knowledgeId: String(route.params.knowledgeId ?? ''),
type: route.params.type,
},
query: route.query,
})
}
void router.push(getDocumentListReturnLocation(router) ?? documentList)
}

return { resourceApi, handleBack }
Expand Down
16 changes: 14 additions & 2 deletions ui/src/views/knowledge-detail/library/document/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import ButtonExecutionRecord from './components/ButtonExecutionRecord.vue'
import DocumentStatus from './components/DocumentStatus.vue'
import DocumentTags from './components/DocumentTags.vue'
import ButtonImportDocument from './import-document/ButtonImportDocument.vue'
import { saveDocumentPagination, takeDocumentPagination } from './pagination-return'
import { DOCUMENT_STATUS_FILTER_OPTIONS, DOCUMENT_STATUS_OPTIONS } from './status'
import ButtonUploadDocument from './upload-document/ButtonUploadDocument.vue'
import { DOCUMENT_HIT_HANDLING_LABELS } from '@/constants/document'
Expand Down Expand Up @@ -85,10 +86,15 @@ const { knowledge, resourceApi, routeNames, routeParams } = useKnowledgeDetailCo
/* 文档分段入口:选择列与行内操作继续处理自身交互。 */
function handleOpenParagraph(document: DocumentItem, column?: TableColumnCtx<DocumentItem> | null) {
if (loading.value || operationLoading.value || column?.type === 'selection') return
void router.push({
const listLocation = route.fullPath
const { currentPage, pageSize } = paginationConfig.value
const detailLocation = {
name: routeNames.value.paragraph,
params: { ...routeParams.value, type: knowledgeType.value, documentId: document.id },
query: route.query,
}
void router.push(detailLocation).then((failure) => {
if (!failure) saveDocumentPagination(router, listLocation, detailLocation, { currentPage, pageSize })
})
}

Expand Down Expand Up @@ -146,7 +152,13 @@ function handleCreateDocument(name: string) {
/* 文档筛选与分页查询 */
const loading = ref(false)
const documentData = ref<DocumentItem[]>([])
const paginationConfig = ref({ currentPage: 1, pageSize: 20, total: 0 })
const savedPagination = takeDocumentPagination(router)
const paginationConfig = ref({
currentPage: savedPagination?.currentPage ?? 1,
pageSize: savedPagination?.pageSize ?? 20,
total: 0,
})

const documentQuery = ref<Dict<unknown>>({})
const orderBy = ref<string>()
const creatorOptions = ref<OptionItem<string>[]>([])

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The diff is generally reasonable, but there are several things to check/fix. I’m assuming pagination-return handles router/history-state storage correctly; without its implementation, some risks below are conditional.

Potential issues

  1. Unhandled promise rejection

    void router.push(detailLocation).then((failure) => {
      if (!failure) saveDocumentPagination(...)
    })

    There is no .catch(). If router.push rejects unexpectedly, or saveDocumentPagination throws inside .then, this becomes an unhandled rejection. Prefer async/await with try/catch, or add .catch().

  2. Saved pagination is not validated

    currentPage: savedPagination?.currentPage ?? 1,
    pageSize: savedPagination?.pageSize ?? 20,

    The saved values come from browser history/storage and can be stale or invalid. Validate:

    • currentPage is an integer >= 1
    • pageSize is one of the allowed page-size options
    • after total is loaded, clamp currentPage to the last valid page and refetch if needed

    Otherwise users can land on an empty page after deleting documents or changing filters.

  3. Restored page can exceed the actual total
    total is reset to 0, and the saved currentPage is applied before data is loaded. If the saved page no longer exists, the table may render empty. After fetch, do something like:

    const maxPage = Math.max(1, Math.ceil(total / pageSize))
    if (currentPage > maxPage) currentPage = maxPage
  4. Location key normalization
    detailLocation is passed to both router.push and saveDocumentPagination. Vue Router may normalize query/params. If pagination-return does not resolve the location itself, use the resolved path for the storage key:

    const detailFullPath = router.resolve(detailLocation).fullPath

    Otherwise the saved key may not exactly match the route later read by takeDocumentPagination.

  5. Sharing route.query by reference

    query: route.query

    It is safer to clone it:

    query: { ...route.query }

    This avoids accidental coupling to the reactive route object.

  6. KeepAlive / component reuse

    const savedPagination = takeDocumentPagination(router)

    This runs only during setup(). If the list component is kept alive or reused when returning from the detail page, the saved pagination will not be consumed. In that case, move restoration into onActivated() or a route watcher.

  7. Scoping of saved pagination
    Make sure saveDocumentPagination / takeDocumentPagination are scoped by knowledge base / resource / list route. Otherwise pagination from one document list could leak into another.

  8. void router.push(...).then(...) is misleading
    It works, but the void makes it look like errors are intentionally ignored. A clearer form would be:

    router.push(detailLocation)
      .then((failure) => { ... })
      .catch((error) => { ... })

    or better:

    async function handleOpenParagraph(...) {
      ...
      try {
        const failure = await router.push(detailLocation)
        if (failure) return
        saveDocumentPagination(router, listLocation, detailLocation, { currentPage, pageSize })
      } catch (error) {
        // log/handle
      }
    }

Minor note

handleOpenParagraph references paginationConfig before its declaration, but since the function is only called after setup completes, this is not a runtime TDZ issue. It is still slightly harder to read; declaring paginationConfig earlier might be cleaner.

Recommended fix summary

  • Add error handling around router.push and saveDocumentPagination.
  • Validate/normalize restored currentPage and pageSize.
  • Clamp the restored page after total is known.
  • Ensure the saved detail-location key is resolved/normalized consistently.
  • Clone route.query.
  • Use onActivated/route watcher if the list page can be kept alive.
  • Ensure pagination storage is scoped to the correct knowledge/resource list.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/** 分段页返回原文档列表时一次性恢复分页。 */
import type { RouteLocationNormalized, RouteLocationRaw, Router } from 'vue-router'

interface DocumentPagination {
currentPage: number
pageSize: number
}

const documentPagination = new WeakMap<RouteLocationNormalized, { listLocation: string; pagination: DocumentPagination }>()

/** 进入分段成功后记录分页,只在本次分段导航返回原列表时交给列表。 */
export function saveDocumentPagination(router: Router, listLocation: string, detailLocation: RouteLocationRaw, pagination: DocumentPagination) {
const detail = router.currentRoute.value
if (detail.fullPath !== router.resolve(detailLocation).fullPath) return

const snapshot = { listLocation, pagination }
documentPagination.set(detail, snapshot)
const stopTracking = router.afterEach((to, from, failure) => {
if (failure || from !== detail) return
stopTracking()
documentPagination.delete(detail)
if (to.fullPath === listLocation) documentPagination.set(to, snapshot)
})
}

/** 读取当前分段页对应的原列表地址。 */
export function getDocumentListReturnLocation(router: Router) {
return documentPagination.get(router.currentRoute.value)?.listLocation
}

/** 读取本次返回的分页并立即清空。 */
export function takeDocumentPagination(router: Router) {
const list = router.currentRoute.value
const snapshot = documentPagination.get(list)
documentPagination.delete(list)
return snapshot?.pagination
}
Loading