dify改造升级适配

This commit is contained in:
2025-12-20 19:59:33 +08:00
parent 70533027f8
commit bac3a97720
8 changed files with 28 additions and 99 deletions

View File

@@ -31,6 +31,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
appChatListDataLoading, appChatListDataLoading,
chatShouldReloadKey, chatShouldReloadKey,
isMobile, isMobile,
isInstalledApp,
themeBuilder, themeBuilder,
sidebarCollapseState, sidebarCollapseState,
} = useChatWithHistoryContext() } = useChatWithHistoryContext()
@@ -49,7 +50,7 @@ const ChatWithHistory: FC<ChatWithHistoryProps> = ({
setShowSidePanel(false) setShowSidePanel(false)
}, [isSidebarCollapsed]) }, [isSidebarCollapsed])
useDocumentTitle(site?.title || 'Chat') useDocumentTitle(site?.title || 'Chat', isInstalledApp ? '智能体平台' : undefined)
return ( return (
<div className={cn( <div className={cn(

View File

@@ -16,10 +16,9 @@ import List from '@/app/components/base/chat/chat-with-history/sidebar/list'
import MenuDropdown from '@/app/components/share/text-generation/menu-dropdown' import MenuDropdown from '@/app/components/share/text-generation/menu-dropdown'
import Confirm from '@/app/components/base/confirm' import Confirm from '@/app/components/base/confirm'
import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal' import RenameModal from '@/app/components/base/chat/chat-with-history/sidebar/rename-modal'
import DifyLogo from '@/app/components/base/logo/dify-logo'
import type { ConversationItem } from '@/models/share' import type { ConversationItem } from '@/models/share'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useGlobalPublicStore } from '@/context/global-public-context'
type Props = { type Props = {
isPanel?: boolean isPanel?: boolean
@@ -47,7 +46,7 @@ const Sidebar = ({ isPanel, panelVisible }: Props) => {
isResponding, isResponding,
} = useChatWithHistoryContext() } = useChatWithHistoryContext()
const isSidebarCollapsed = sidebarCollapseState const isSidebarCollapsed = sidebarCollapseState
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const [showConfirm, setShowConfirm] = useState<ConversationItem | null>(null) const [showConfirm, setShowConfirm] = useState<ConversationItem | null>(null)
const [showRename, setShowRename] = useState<ConversationItem | null>(null) const [showRename, setShowRename] = useState<ConversationItem | null>(null)
@@ -145,23 +144,6 @@ const Sidebar = ({ isPanel, panelVisible }: Props) => {
data={appData?.site} data={appData?.site}
forceClose={isPanel && !panelVisible} forceClose={isPanel && !panelVisible}
/> />
{/* powered by */}
<div className='shrink-0'>
{!appData?.custom_config?.remove_webapp_brand && (
<div className={cn(
'flex shrink-0 items-center gap-1.5 px-1',
)}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{
systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
: appData?.custom_config?.replace_webapp_logo
? <img src={`${appData?.custom_config?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
}
</div>
)}
</div>
{!!showConfirm && ( {!!showConfirm && (
<Confirm <Confirm
title={t('share.chat.deleteConversation.title')} title={t('share.chat.deleteConversation.title')}

View File

@@ -11,9 +11,8 @@ import Tooltip from '@/app/components/base/tooltip'
import ActionButton from '@/app/components/base/action-button' import ActionButton from '@/app/components/base/action-button'
import Divider from '@/app/components/base/divider' import Divider from '@/app/components/base/divider'
import ViewFormDropdown from '@/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown' import ViewFormDropdown from '@/app/components/base/chat/embedded-chatbot/inputs-form/view-form-dropdown'
import DifyLogo from '@/app/components/base/logo/dify-logo'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { useGlobalPublicStore } from '@/context/global-public-context'
export type IHeaderProps = { export type IHeaderProps = {
isMobile?: boolean isMobile?: boolean
@@ -44,7 +43,7 @@ const Header: FC<IHeaderProps> = ({
const [parentOrigin, setParentOrigin] = useState('') const [parentOrigin, setParentOrigin] = useState('')
const [showToggleExpandButton, setShowToggleExpandButton] = useState(false) const [showToggleExpandButton, setShowToggleExpandButton] = useState(false)
const [expanded, setExpanded] = useState(false) const [expanded, setExpanded] = useState(false)
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const handleMessageReceived = useCallback((event: MessageEvent) => { const handleMessageReceived = useCallback((event: MessageEvent) => {
let currentParentOrigin = parentOrigin let currentParentOrigin = parentOrigin
@@ -81,23 +80,6 @@ const Header: FC<IHeaderProps> = ({
return ( return (
<div className='flex h-14 shrink-0 items-center justify-end p-3'> <div className='flex h-14 shrink-0 items-center justify-end p-3'>
<div className='flex items-center gap-1'> <div className='flex items-center gap-1'>
{/* powered by */}
<div className='shrink-0'>
{!appData?.custom_config?.remove_webapp_brand && (
<div className={cn(
'flex shrink-0 items-center gap-1.5 px-2',
)}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{
systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
: appData?.custom_config?.replace_webapp_logo
? <img src={`${appData?.custom_config?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
}
</div>
)}
</div>
{currentConversationId && ( {currentConversationId && (
<Divider type='vertical' className='h-3.5' /> <Divider type='vertical' className='h-3.5' />
)} )}

View File

@@ -2,7 +2,6 @@
import { import {
useEffect, useEffect,
} from 'react' } from 'react'
import { useTranslation } from 'react-i18next'
import { import {
EmbeddedChatbotContext, EmbeddedChatbotContext,
useEmbeddedChatbotContext, useEmbeddedChatbotContext,
@@ -16,10 +15,9 @@ import Loading from '@/app/components/base/loading'
import LogoHeader from '@/app/components/base/logo/logo-embedded-chat-header' import LogoHeader from '@/app/components/base/logo/logo-embedded-chat-header'
import Header from '@/app/components/base/chat/embedded-chatbot/header' import Header from '@/app/components/base/chat/embedded-chatbot/header'
import ChatWrapper from '@/app/components/base/chat/embedded-chatbot/chat-wrapper' import ChatWrapper from '@/app/components/base/chat/embedded-chatbot/chat-wrapper'
import DifyLogo from '@/app/components/base/logo/dify-logo'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import useDocumentTitle from '@/hooks/use-document-title' import useDocumentTitle from '@/hooks/use-document-title'
import { useGlobalPublicStore } from '@/context/global-public-context'
const Chatbot = () => { const Chatbot = () => {
const { const {
@@ -31,8 +29,6 @@ const Chatbot = () => {
handleNewConversation, handleNewConversation,
themeBuilder, themeBuilder,
} = useEmbeddedChatbotContext() } = useEmbeddedChatbotContext()
const { t } = useTranslation()
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const customConfig = appData?.custom_config const customConfig = appData?.custom_config
const site = appData?.site const site = appData?.site
@@ -71,25 +67,6 @@ const Chatbot = () => {
)} )}
</div> </div>
</div> </div>
{/* powered by */}
{isMobile && (
<div className='flex h-[60px] shrink-0 items-center pl-2'>
{!appData?.custom_config?.remove_webapp_brand && (
<div className={cn(
'flex shrink-0 items-center gap-1.5 px-2',
)}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{
systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
: appData?.custom_config?.replace_webapp_logo
? <img src={`${appData?.custom_config?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
}
</div>
)}
</div>
)}
</div> </div>
) )
} }

View File

@@ -37,7 +37,7 @@ const Datasets = ({
const observerRef = useRef<IntersectionObserver>(null) const observerRef = useRef<IntersectionObserver>(null)
useEffect(() => { useEffect(() => {
document.title = `${t('dataset.knowledge')} - Dify` document.title = `${t('dataset.knowledge')} - 智能体平台`
}, [t]) }, [t])
useEffect(() => { useEffect(() => {

View File

@@ -35,10 +35,9 @@ import Toast from '@/app/components/base/toast'
import type { VisionFile, VisionSettings } from '@/types/app' import type { VisionFile, VisionSettings } from '@/types/app'
import { Resolution, TransferMethod } from '@/types/app' import { Resolution, TransferMethod } from '@/types/app'
import { useAppFavicon } from '@/hooks/use-app-favicon' import { useAppFavicon } from '@/hooks/use-app-favicon'
import DifyLogo from '@/app/components/base/logo/dify-logo'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'
import { AccessMode } from '@/models/access-control' import { AccessMode } from '@/models/access-control'
import { useGlobalPublicStore } from '@/context/global-public-context'
import useDocumentTitle from '@/hooks/use-document-title' import useDocumentTitle from '@/hooks/use-document-title'
import { useWebAppStore } from '@/context/web-app-context' import { useWebAppStore } from '@/context/web-app-context'
@@ -90,7 +89,7 @@ const TextGeneration: FC<IMainProps> = ({
doSetInputs(newInputs) doSetInputs(newInputs)
inputsRef.current = newInputs inputsRef.current = newInputs
}, []) }, [])
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const [appId, setAppId] = useState<string>('') const [appId, setAppId] = useState<string>('')
const [siteInfo, setSiteInfo] = useState<SiteInfo | null>(null) const [siteInfo, setSiteInfo] = useState<SiteInfo | null>(null)
const [customConfig, setCustomConfig] = useState<Record<string, any> | null>(null) const [customConfig, setCustomConfig] = useState<Record<string, any> | null>(null)
@@ -397,7 +396,7 @@ const TextGeneration: FC<IMainProps> = ({
}, [appData, appParams, fetchSavedMessage, isWorkflow]) }, [appData, appParams, fetchSavedMessage, isWorkflow])
// Can Use metadata(https://beta.nextjs.org/docs/api-reference/metadata) to set title. But it only works in server side client. // Can Use metadata(https://beta.nextjs.org/docs/api-reference/metadata) to set title. But it only works in server side client.
useDocumentTitle(siteInfo?.title || t('share.generation.title')) useDocumentTitle(siteInfo?.title || t('share.generation.title'), isInstalledApp ? '智能体平台' : undefined)
useAppFavicon({ useAppFavicon({
enable: !isInstalledApp, enable: !isInstalledApp,
@@ -594,23 +593,6 @@ const TextGeneration: FC<IMainProps> = ({
/> />
)} )}
</div> </div>
{/* powered by */}
{!customConfig?.remove_webapp_brand && (
<div className={cn(
'flex shrink-0 items-center gap-1.5 bg-components-panel-bg py-3',
isPC ? 'px-8' : 'px-4',
!isPC && resultExisted && 'rounded-b-2xl border-b-[0.5px] border-divider-regular',
)}>
<div className='system-2xs-medium-uppercase text-text-tertiary'>{t('share.chat.poweredBy')}</div>
{
systemFeatures.branding.enabled && systemFeatures.branding.workspace_logo
? <img src={systemFeatures.branding.workspace_logo} alt='logo' className='block h-5 w-auto' />
: customConfig?.replace_webapp_logo
? <img src={`${customConfig?.replace_webapp_logo}`} alt='logo' className='block h-5 w-auto' />
: <DifyLogo size='small' />
}
</div>
)}
</div> </div>
{/* Result */} {/* Result */}
<div className={cn( <div className={cn(

View File

@@ -63,18 +63,18 @@ describe('use default branding', () => {
* Test title format with page title and default branding * Test title format with page title and default branding
* Format: "[page] - Dify" * Format: "[page] - Dify"
*/ */
it('document title should be test-Dify if set title', () => { it('document title should be test-智能体平台 if set title', () => {
renderHook(() => useDocumentTitle('test')) renderHook(() => useDocumentTitle('test'))
expect(document.title).toBe('test - Dify') expect(document.title).toBe('test - 智能体平台')
}) })
/** /**
* Test title with only default branding (no page title) * Test title with only default branding (no page title)
* Format: "Dify" * Format: "Dify"
*/ */
it('document title should be Dify if not set title', () => { it('document title should be 智能体平台 if not set title', () => {
renderHook(() => useDocumentTitle('')) renderHook(() => useDocumentTitle(''))
expect(document.title).toBe('Dify') expect(document.title).toBe('智能体平台')
}) })
}) })

View File

@@ -4,22 +4,27 @@ import { useFavicon, useTitle } from 'ahooks'
import { basePath } from '@/utils/var' import { basePath } from '@/utils/var'
import { useEffect } from 'react' import { useEffect } from 'react'
export default function useDocumentTitle(title: string) { export default function useDocumentTitle(title: string, brandOverride?: string) {
const isPending = useGlobalPublicStore(s => s.isGlobalPending) const isPending = useGlobalPublicStore(s => s.isGlobalPending)
const systemFeatures = useGlobalPublicStore(s => s.systemFeatures) const systemFeatures = useGlobalPublicStore(s => s.systemFeatures)
const prefix = title ? `${title} - ` : '' const prefix = title ? `${title} - ` : ''
let titleStr = '' let titleStr = ''
let favicon = '' let favicon = ''
if (isPending === false) { if (isPending === false) {
if (brandOverride) {
titleStr = `${prefix}${brandOverride}`
favicon = systemFeatures.branding.enabled ? systemFeatures.branding.favicon : `${basePath}/favicon.ico`
} else {
if (systemFeatures.branding.enabled) { if (systemFeatures.branding.enabled) {
titleStr = `${prefix}${systemFeatures.branding.application_title}` titleStr = `${prefix}${systemFeatures.branding.application_title}`
favicon = systemFeatures.branding.favicon favicon = systemFeatures.branding.favicon
} }
else { else {
titleStr = `${prefix}Dify` titleStr = `${prefix}智能体平台`
favicon = `${basePath}/favicon.ico` favicon = `${basePath}/favicon.ico`
} }
} }
}
useTitle(titleStr) useTitle(titleStr)
useEffect(() => { useEffect(() => {
let apple: HTMLLinkElement | null = null let apple: HTMLLinkElement | null = null