diff --git a/src/frontend/src/components/bs-comp/chatComponent/SourceEntry.tsx b/src/frontend/src/components/bs-comp/chatComponent/SourceEntry.tsx index f3a81adc8..bb2091ae2 100644 --- a/src/frontend/src/components/bs-comp/chatComponent/SourceEntry.tsx +++ b/src/frontend/src/components/bs-comp/chatComponent/SourceEntry.tsx @@ -25,7 +25,7 @@ export default function SourceEntry({ extra, end, source, className = '', onSour {(() => { switch (source) { case SourceType.FILE: - return {t('chat.source')}; + return {t('chat.source')}; case SourceType.NO_PERMISSION: return

{t('chat.noAccess')}

; case SourceType.LINK: diff --git a/src/frontend/src/contexts/locationContext.tsx b/src/frontend/src/contexts/locationContext.tsx index 95bb0a0aa..64f818b52 100644 --- a/src/frontend/src/contexts/locationContext.tsx +++ b/src/frontend/src/contexts/locationContext.tsx @@ -30,6 +30,7 @@ type locationContextType = { extraComponent: any; setExtraComponent: (newState: any) => void; appConfig: any; + reloadConfig: () => void }; //initial value for location context @@ -48,7 +49,8 @@ const initialValue = { setExtraNavigation: () => { }, extraComponent: <>, setExtraComponent: () => { }, - appConfig: { libAccepts: [] } + appConfig: { libAccepts: [] }, + reloadConfig: () => { } }; export const locationContext = createContext(initialValue); @@ -65,8 +67,7 @@ export function LocationProvider({ children }: { children: ReactNode }) { libAccepts: [] }) - // 获取系统配置 - useEffect(() => { + const loadConfig = () => { getAppConfig().then(res => { setAppConfig({ isDev: res.env === 'dev', @@ -80,6 +81,11 @@ export function LocationProvider({ children }: { children: ReactNode }) { chatPrompt: !!res.application_usage_tips }) }) + } + + // 获取系统配置 + useEffect(() => { + loadConfig() }, []) return ( @@ -95,7 +101,8 @@ export function LocationProvider({ children }: { children: ReactNode }) { setExtraNavigation, extraComponent, setExtraComponent, - appConfig + appConfig, + reloadConfig: loadConfig }} > {children} diff --git a/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx b/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx index bbe390ffa..114a66c56 100644 --- a/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx +++ b/src/frontend/src/pages/ChatAppPage/components/ResouceModal.tsx @@ -50,11 +50,36 @@ const Anwser = ({ id, msg, onInit, onAdd }) => { // let timer = null -const ResultPanne = ({ chatId, words, data, onClose, onAdd, children }: { chatId: string, words: string[], data: any, onClose: any, onAdd: any, children: any }) => { +const ResultPanne = ({ chatId, words, data, onClose, onAdd, children, closeDialog }: { chatId: string, words: string[], data: any, onClose: any, onAdd: any, children: any, closeDialog: () => void }) => { const { t } = useTranslation() const [editCustomKey, setEditCustomKey] = useState(false) const inputRef = useRef(null) + // 移动端 + const [collapse, setCollapse] = useState(true) + const [isMobile, setIsMobile] = useState(true) + const [width, setWidth] = useState(window.innerWidth); + const [height, setHeight] = useState(window.innerHeight); + const checkIsMobile = () => { + if (width < 640) { + setIsMobile(true) + } else { + setIsMobile(false) + } + } + useEffect(() => { + const handleResize = () => { + setWidth(window.innerWidth); + setHeight(window.innerHeight); + }; + window.addEventListener("resize", handleResize); + checkIsMobile() + return () => { + window.removeEventListener("resize", handleResize); + } + }, [width]) + // 移动端 e + const handleAddKeyword = (str: string) => { setEditCustomKey(false) if (!str) return @@ -88,71 +113,86 @@ const ResultPanne = ({ chatId, words, data, onClose, onAdd, children }: { chatId setTimeout(() => document.getElementById('taginput')?.focus(), 0); } - return
- {/* left */} -
- {/* label */} - {/* 中英 */} -
- {t('chat.filterLabel')} - - - - - - -

{t('chat.tooltipText')}

-
-
-
+ return
+ { + isMobile &&
+ {!collapse && { setCollapse(true) }} className="">收起} + {collapse && { setCollapse(false) }} className="">展开}
-
- {words.map((str, i) =>
{str} onClose(i)}>x
)} - { - editCustomKey ?
{ - if (event.key === "Enter" && !event.shiftKey) { - handleAddKeyword(inputRef.current.value); - } - }} - onBlur={() => { - handleAddKeyword(inputRef.current.value); - }}>
: -
{t('chat.addCustomLabel')}
- } + } + { + isMobile &&
+ 关闭
- {/* files */} -
-

{t('chat.sourceDocumentsLabel')}

- {files.map(_file => - _file.right ?
setFile(_file)} className={`group rounded-xl bg-[#fff] dark:bg-[#303134] hover-bg-gray-200 flex items-center px-4 mb-2 relative min-h-16 cursor-pointer ${file?.id === _file.id && 'bg-gray-200'}`}> -

{_file.fileName}

- - {_file.score} -
: -
-

是真的马赛克.msk

+ } + {/* left */} + { + (!isMobile || !collapse) &&
+ {/* label */} + {/* 中英 */} +
+
+ {t('chat.filterLabel')} + + + + + + +

{t('chat.tooltipText')}

+
+
+
+
+
+
+ {words.map((str, i) =>
{str} onClose(i)}>x
)} + { + editCustomKey ?
{ + if (event.key === "Enter" && !event.shiftKey) { + handleAddKeyword(inputRef.current.value); + } + }} + onBlur={() => { + handleAddKeyword(inputRef.current.value); + }}>
: +
{t('chat.addCustomLabel')}
+ } +
+ {/* files */} +
+

{t('chat.sourceDocumentsLabel')}

+ {files.map(_file => + _file.right ?
setFile(_file)} className={`group rounded-xl bg-[#fff] dark:bg-[#303134] hover-bg-gray-200 flex items-center px-4 mb-2 relative min-h-16 cursor-pointer ${file?.id === _file.id && 'bg-gray-200'}`}> +

{_file.fileName}

+ {_file.score} -
- )} - {!files.length &&

{t('chat.noMatchedFilesMessage')}

} +
: +
+

是真的马赛克.msk

+ {_file.score} +
+ )} + {!files.length &&

{t('chat.noMatchedFilesMessage')}

} +
-
+ } {/* file pane */} {file && children(file)}
@@ -190,7 +230,7 @@ const ResouceModal = forwardRef((props, ref) => { */} {open &&
- + setOpen(false)}> { (file) => file.fileUrl ? : diff --git a/src/frontend/src/pages/SystemPage/components/Config.tsx b/src/frontend/src/pages/SystemPage/components/Config.tsx index ff4c5e742..387230d23 100644 --- a/src/frontend/src/pages/SystemPage/components/Config.tsx +++ b/src/frontend/src/pages/SystemPage/components/Config.tsx @@ -2,12 +2,15 @@ import { useContext, useEffect, useRef, useState } from "react"; import AceEditor from "react-ace"; import { useTranslation } from "react-i18next"; import { Button } from "../../../components/bs-ui/button"; -import { alertContext } from "../../../contexts/alertContext"; import { getSysConfigApi, setSysConfigApi } from "../../../controllers/API/user"; import { captureAndAlertRequestErrorHoc } from "../../../controllers/request"; +import { locationContext } from "@/contexts/locationContext"; +import { useToast } from "@/components/bs-ui/toast/use-toast"; export default function Config() { - const { setErrorData, setSuccessData } = useContext(alertContext); + const { toast, message } = useToast() + const { reloadConfig } = useContext(locationContext) + const [config, setConfig] = useState('') const { t } = useTranslation() @@ -21,15 +24,23 @@ export default function Config() { const handleSave = () => { if (validataRef.current.length) { - return setErrorData({ + return toast({ + variant: 'error', title: `yaml${t('formatError')}`, - list: validataRef.current.map(el => el.text), - }); + description: validataRef.current.map(el => el.text) + }) } captureAndAlertRequestErrorHoc(setSysConfigApi({ data: codeRef.current }).then(res => { - setSuccessData({ title: t('success') }) + message({ + variant: 'success', + title: t('prompt'), + description: t('success') + }) setConfig(codeRef.current) + + // 更新配置信息 + reloadConfig() })) }