本文档涵盖了 Dify Web 应用程序的前端开发架构、技术和模式。它侧重于基于 Next.js 的 React 应用程序,该应用程序提供了管理应用程序、数据集、工作流和对话的用户界面。
有关后端 API 开发的信息,请参阅后端开发。有关整体系统架构的详细信息,请参阅系统架构。
Dify 的前端建立在现代的、基于 React 的技术栈之上。
来源:web/pnpm-lock.yaml209-530 web/next.config.js22-67
来源:web/app/(commonLayout)/app/(appDetailLayout)/layout.tsx1-32 web/next.config.js22-67
前端使用了一个全面的基础组件库,提供了可复用的 UI 元素。
日期/时间选择器系统展示了高级组件组合。
核心类型和架构
ViewType 枚举管理不同的选择器状态(日期、年月份、时间)。Period 枚举处理上午/下午的选择。关键组件
DatePicker - 主要日期选择组件,可选时间选择。TimePicker - 独立的日期选择组件。Calendar - 基于网格的日期选择界面。PortalToFollowElem - 弹出式覆盖层的定位系统。来源:web/app/components/base/date-and-time-picker/types.ts1-106 web/app/components/base/date-and-time-picker/date-picker/index.tsx29-309
前端包含复杂的内容渲染功能。
Markdown 中的表单渲染
SVG 图库系统
来源:web/app/components/base/markdown-blocks/form.tsx32-238 web/app/components/base/svg-gallery/index.tsx6-78
前端采用多层样式设计。
Markdown 样式展示了复杂的 CSS 架构。
主题集成
组件特定样式
来源:web/styles/markdown.scss1-1045
聊天系统展示了复杂的状态管理模式。
基于上下文的架构
useChatContext 为组件提供聊天功能。数据流
来源:web/app/components/workflow/panel/chat-record/index.tsx49-138 web/app/components/base/markdown-blocks/form.tsx32-70
Next.js 配置展示了生产级别的设置。
关键配置特性
开发与生产
前端包含全面的 i18n 支持。
实现细节
i18next 与 React 集成,实现动态翻译。使用模式
useTranslation)。来源:web/app/components/header/maintenance-notice.tsx4-36 web/app/components/base/date-and-time-picker/hooks.ts7-49
前端使用复杂的 Portal 系统来处理模态框和覆盖层。
PortalToFollowElem 系统
使用示例
来源:web/app/components/app/configuration/config-vision/param-config.tsx15-42 web/app/components/base/date-and-time-picker/date-picker/index.tsx200-306
配置界面的标准化面板布局。
FeaturePanel 组件
来源:web/app/components/app/configuration/base/feature-panel/index.tsx16-48
前端通过以下方式实现响应式设计:
基于 Tailwind 的响应式设计
组件级别的响应式设计