diff --git a/src/biz/Settings.tsx b/src/biz/Settings.tsx index 09db334..e3c481b 100644 --- a/src/biz/Settings.tsx +++ b/src/biz/Settings.tsx @@ -63,12 +63,14 @@ const Settings = () => { const {value: summarizeFloatValue, onChange: setSummarizeFloatValue} = useEventChecked(envData.summarizeFloat) const [apiKeyValue, { onChange: onChangeApiKeyValue }] = useEventTarget({initialValue: envData.apiKey??''}) const [serverUrlValue, setServerUrlValue] = useState(envData.serverUrl) + const [geminiApiKeyValue, { onChange: onChangeGeminiApiKeyValue }] = useEventTarget({initialValue: envData.geminiApiKey??''}) const [languageValue, { onChange: onChangeLanguageValue }] = useEventTarget({initialValue: envData.language??LANGUAGE_DEFAULT}) const [modelValue, { onChange: onChangeModelValue }] = useEventTarget({initialValue: envData.model??MODEL_DEFAULT}) const [summarizeLanguageValue, { onChange: onChangeSummarizeLanguageValue }] = useEventTarget({initialValue: envData.summarizeLanguage??SUMMARIZE_LANGUAGE_DEFAULT}) const [hideOnDisableAutoTranslateValue, setHideOnDisableAutoTranslateValue] = useState(envData.hideOnDisableAutoTranslate) const [themeValue, setThemeValue] = useState(envData.theme) const [fontSizeValue, setFontSizeValue] = useState(envData.fontSize) + const [aiTypeValue, setAiTypeValue] = useState(envData.aiType) const [transDisplayValue, setTransDisplayValue] = useState(envData.transDisplay) const [wordsValue, setWordsValue] = useState(envData.words??WORDS_DEFAULT) const [fetchAmountValue, setFetchAmountValue] = useState(envData.fetchAmount??TRANSLATE_FETCH_DEFAULT) @@ -99,9 +101,11 @@ const Settings = () => { const onSave = useCallback(() => { dispatch(setEnvData({ autoExpand: autoExpandValue, + aiType: aiTypeValue, apiKey: apiKeyValue, serverUrl: serverUrlValue, model: modelValue, + geminiApiKey: geminiApiKeyValue, translateEnable: translateEnableValue, language: languageValue, hideOnDisableAutoTranslate: hideOnDisableAutoTranslateValue, @@ -119,7 +123,7 @@ const Settings = () => { })) dispatch(setPage(PAGE_MAIN)) toast.success('保存成功') - }, [dispatch, autoExpandValue, apiKeyValue, serverUrlValue, modelValue, translateEnableValue, languageValue, hideOnDisableAutoTranslateValue, themeValue, transDisplayValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, wordsValue, fetchAmountValue, fontSizeValue, promptsValue, searchEnabledValue, cnSearchEnabledValue]) + }, [dispatch, aiTypeValue, geminiApiKeyValue, autoExpandValue, apiKeyValue, serverUrlValue, modelValue, translateEnableValue, languageValue, hideOnDisableAutoTranslateValue, themeValue, transDisplayValue, summarizeEnableValue, summarizeFloatValue, summarizeLanguageValue, wordsValue, fetchAmountValue, fontSizeValue, promptsValue, searchEnabledValue, cnSearchEnabledValue]) const onCancel = useCallback(() => { dispatch(setPage(PAGE_MAIN)) @@ -165,6 +169,14 @@ const Settings = () => { setFontSizeValue('large') }, []) + const onSelOpenai = useCallback(() => { + setAiTypeValue('openai') + }, []) + + const onSelGemini = useCallback(() => { + setAiTypeValue('gemini') + }, []) + return
@@ -187,8 +199,15 @@ const Settings = () => {
+ +
+ + +
+
-
+ + {(!aiTypeValue || aiTypeValue === 'openai') &&
@@ -239,7 +258,44 @@ const Settings = () => { }}/> )} } -
+
} + + {aiTypeValue === 'gemini' &&
+ + + +
+ {moreFold?'点击查看说明':'点击折叠说明'} +
+ {!moreFold &&
+ +
} +
+ {promptsFold?'点击查看提示词':'点击折叠提示词'} +
+ {!promptsFold &&
+ {PROMPT_TYPES.map((item, idx) => +
{item.name}
+
{ + setPromptsValue({ + ...promptsValue, + // @ts-expect-error + [item.type]: PROMPT_DEFAULTS[item.type]??'' + }) + }}>点击填充默认
+
} htmlFor={`prompt-${item.type}`}> +