From 75517c74cabb1fa36dfe834977db8d993fe210be Mon Sep 17 00:00:00 2001 From: Jerry Fan Date: Mon, 8 Apr 2024 16:10:43 +0800 Subject: [PATCH] feat: Add link to Chat2DB Pro --- chat2db-client/package.json | 1 + .../src/blocks/Setting/AiSetting/index.tsx | 95 ++++++++++++------- chat2db-client/src/blocks/Setting/index.tsx | 2 +- chat2db-client/src/i18n/en-us/setting.ts | 7 +- chat2db-client/src/i18n/ja-jp/setting.ts | 16 +++- chat2db-client/src/i18n/tr-tr/setting.ts | 19 ++-- chat2db-client/src/i18n/zh-cn/setting.ts | 5 +- chat2db-client/src/pages/main/index.less | 10 ++ chat2db-client/src/pages/main/index.tsx | 20 +++- chat2db-client/src/utils/timezone.ts | 16 ++++ chat2db-client/yarn.lock | 5 + 11 files changed, 137 insertions(+), 59 deletions(-) create mode 100644 chat2db-client/src/utils/timezone.ts diff --git a/chat2db-client/package.json b/chat2db-client/package.json index b0b8afaa6..018056d7b 100644 --- a/chat2db-client/package.json +++ b/chat2db-client/package.json @@ -36,6 +36,7 @@ "event-source-polyfill": "^1.0.31", "highlight.js": "^11.9.0", "lodash": "^4.17.21", + "lucide-react": "^0.365.0", "markdown-it-link-attributes": "^4.0.1", "monaco-editor": "^0.44.0", "monaco-editor-esm-webpack-plugin": "^2.1.0", diff --git a/chat2db-client/src/blocks/Setting/AiSetting/index.tsx b/chat2db-client/src/blocks/Setting/AiSetting/index.tsx index fd84059df..d4b90b868 100644 --- a/chat2db-client/src/blocks/Setting/AiSetting/index.tsx +++ b/chat2db-client/src/blocks/Setting/AiSetting/index.tsx @@ -1,13 +1,14 @@ import React, { useEffect, useState } from 'react'; import configService from '@/service/config'; import { AIType } from '@/typings/ai'; -import { Alert, Button, Form, Input, Radio, RadioChangeEvent } from 'antd'; +import { Alert, Button, Flex, Form, Input, Radio, RadioChangeEvent } from 'antd'; import i18n from '@/i18n'; import { IAiConfig } from '@/typings/setting'; import { IRole } from '@/typings/user'; import { AIFormConfig, AITypeName } from './aiTypeConfig'; import styles from './index.less'; -import { useUserStore } from '@/store/user' +import { useUserStore } from '@/store/user'; +import { getLinkBasedOnTimezone } from '@/utils/timezone'; interface IProps { handleApplyAiConfig: (aiConfig: IAiConfig) => void; @@ -21,11 +22,11 @@ function capitalizeFirstLetter(string) { // openAI 的设置项 export default function SettingAI(props: IProps) { const [aiConfig, setAiConfig] = useState(); - const { userInfo } = useUserStore(state => { + const { userInfo } = useUserStore((state) => { return { - userInfo: state.curUser - } - }) + userInfo: state.curUser, + }; + }); useEffect(() => { setAiConfig(props.aiConfig); @@ -65,6 +66,57 @@ export default function SettingAI(props: IProps) { } }; + const renderAIConfig = () => { + if (aiConfig?.aiSqlSource === AIType.CHAT2DBAI) { + return ( + + + + ); + } + return ( + <> +
+ {Object.keys(AIFormConfig[aiConfig?.aiSqlSource]).map((key: string) => ( + + { + setAiConfig({ ...aiConfig, [key]: e.target.value }); + }} + /> + + ))} +
+ {aiConfig.aiSqlSource === AIType.RESTAI && ( +
{`Tips: ${i18n( + 'setting.tab.aiType.custom.tips', + )}`}
+ )} +
+ +
+ + ); + }; + return ( <>
@@ -78,36 +130,7 @@ export default function SettingAI(props: IProps) {
-
- {Object.keys(AIFormConfig[aiConfig?.aiSqlSource]).map((key: string) => ( - - { - setAiConfig({ ...aiConfig, [key]: e.target.value }); - }} - /> - - ))} -
- - {aiConfig.aiSqlSource === AIType.RESTAI && ( -
{`Tips: ${i18n( - 'setting.tab.aiType.custom.tips', - )}`}
- )} -
- -
+ {renderAIConfig()} {/* {aiConfig?.aiSqlSource === AIType.CHAT2DBAI && !aiConfig.apiKey && } */} diff --git a/chat2db-client/src/blocks/Setting/index.tsx b/chat2db-client/src/blocks/Setting/index.tsx index cc2bb7bb3..9cef5e3b8 100644 --- a/chat2db-client/src/blocks/Setting/index.tsx +++ b/chat2db-client/src/blocks/Setting/index.tsx @@ -4,7 +4,7 @@ import Iconfont from '@/components/Iconfont'; import { Modal, Tooltip } from 'antd'; import i18n from '@/i18n'; import BaseSetting from './BaseSetting'; -import AISetting from './AiSetting'; +import AISetting from './AISetting'; import ProxySetting from './ProxySetting'; import About from './About'; import styles from './index.less'; diff --git a/chat2db-client/src/i18n/en-us/setting.ts b/chat2db-client/src/i18n/en-us/setting.ts index 59cce6f72..afeabc384 100644 --- a/chat2db-client/src/i18n/en-us/setting.ts +++ b/chat2db-client/src/i18n/en-us/setting.ts @@ -21,7 +21,7 @@ export default { 'setting.tab.aiType.baichuan': 'BaiChuan AI', 'setting.tab.aiType.wenxin': 'WenXin AI', 'setting.tab.aiType.tongyiqianwen': 'TongYiQianWen AI', - 'setting.tab.aiType.custom.tips': "The API format is consistent with the OpenAI API format", + 'setting.tab.aiType.custom.tips': 'The API format is consistent with the OpenAI API format', 'setting.label.serviceAddress': 'Service Address', 'setting.button.apply': 'Apply', 'setting.text.currentEnv': 'Current Env', @@ -51,9 +51,12 @@ export default { 'setting.text.autoUpdate': 'The new version automatically downloads and installs updates', 'setting.text.manualUpdate': 'Only alert me when a new version is released', 'setting.button.iSee': 'I see', - 'setting.text.newEditionIsReady': 'New version to download completed, restart the software will install the new version', + 'setting.text.newEditionIsReady': + 'New version to download completed, restart the software will install the new version', 'setting.button.goToUpdate': 'Go to update', 'setting.text.UpdatedLatestVersion': 'Updated to the latest version {1}', 'setting.title.holdingService': 'Holding Service', 'setting.text.holdingService': 'Keep the service when exiting the application to speed up startup', + 'setting.chat2db.ai.button': 'Please visit Chat2DB Pro for more powerful AI features', + 'setting.title.goto.chat2db.pro': 'Go to Chat2DB Pro', }; diff --git a/chat2db-client/src/i18n/ja-jp/setting.ts b/chat2db-client/src/i18n/ja-jp/setting.ts index da6f376f6..6ce9f0169 100644 --- a/chat2db-client/src/i18n/ja-jp/setting.ts +++ b/chat2db-client/src/i18n/ja-jp/setting.ts @@ -21,7 +21,7 @@ export default { 'setting.tab.aiType.baichuan': '百川', 'setting.tab.aiType.wenxin': '文心一言', 'setting.tab.aiType.tongyiqianwen': '通義千問', - 'setting.tab.aiType.custom.tips': "インターフェース形式はOpenAIのものと互換性があります", + 'setting.tab.aiType.custom.tips': 'インターフェース形式はOpenAIのものと互換性があります', 'setting.label.serviceAddress': 'サービスアドレス', 'setting.button.apply': '適用', 'setting.text.currentEnv': '現在の環境', @@ -29,10 +29,13 @@ export default { 'setting.text.viewingUpdateLogs': '更新ログを見る', 'setting.label.isStreamOutput': 'ストリーム出力を行うか', 'setting.label.customAiUrl': 'カスタムAIのURL', - 'setting.placeholder.httpsProxy': '任意項目、OpenAIインターフェースをリクエストする際のHTTPプロキシを設定するためのもの{1}', - 'setting.placeholder.apiKey': 'OpenAIインターフェースを使用する場合は必須です。APIキーはOpenAI公式サイトで確認できます', + 'setting.placeholder.httpsProxy': + '任意項目、OpenAIインターフェースをリクエストする際のHTTPプロキシを設定するためのもの{1}', + 'setting.placeholder.apiKey': + 'OpenAIインターフェースを使用する場合は必須です。APIキーはOpenAI公式サイトで確認できます', 'setting.placeholder.chat2dbApiKey': 'Chat2DBが提供するAPIキーを使用します', - 'setting.placeholder.customUrl': 'カスタムAIを選択する場合は必須で、カスタムAIのRESTインターフェースのURLを設定します', + 'setting.placeholder.customUrl': + 'カスタムAIを選択する場合は必須で、カスタムAIのRESTインターフェースのURLを設定します', 'setting.placeholder.apiHost': '任意項目、デフォルト値はhttps://api.openai.com/', 'setting.message.urlTestError': 'インターフェースのテストに合格しません', 'setting.placeholder.azureOpenAIKey': 'AzureポータルからAzure OpenAIキーを取得します', @@ -51,9 +54,12 @@ export default { 'setting.text.autoUpdate': '新しいバージョンを自動でダウンロードしてインストールする', 'setting.text.manualUpdate': '新しいバージョンがリリースされたときにのみ通知する', 'setting.button.iSee': '了解しました', - 'setting.text.newEditionIsReady': '新しいバージョンがダウンロードされました。ソフトウェアを再起動すると新しいバージョンがインストールされます', + 'setting.text.newEditionIsReady': + '新しいバージョンがダウンロードされました。ソフトウェアを再起動すると新しいバージョンがインストールされます', 'setting.button.goToUpdate': '更新に進む', 'setting.text.UpdatedLatestVersion': '最新バージョン {1} に更新しました', 'setting.title.holdingService': 'サービスを維持', 'setting.text.holdingService': 'アプリケーションを終了してもサービスを維持し、起動速度を向上させます', + 'setting.chat2db.ai.button': 'より強力なAI機能を体験するために、Chat2DB Proをご利用ください', + 'setting.title.goto.chat2db.pro': 'Chat2DB Proへ行く', }; diff --git a/chat2db-client/src/i18n/tr-tr/setting.ts b/chat2db-client/src/i18n/tr-tr/setting.ts index 80b1ddfe9..4f3537541 100644 --- a/chat2db-client/src/i18n/tr-tr/setting.ts +++ b/chat2db-client/src/i18n/tr-tr/setting.ts @@ -21,22 +21,22 @@ export default { 'setting.tab.aiType.baichuan': 'BaiChuan AI', 'setting.tab.aiType.wenxin': 'WenXin AI', 'setting.tab.aiType.tongyiqianwen': 'TongYiQianWen AI', - 'setting.tab.aiType.custom.tips': "API formatı OpenAI API formatıyla uyumludur", + 'setting.tab.aiType.custom.tips': 'API formatı OpenAI API formatıyla uyumludur', 'setting.label.serviceAddress': 'Hizmet Adresi', 'setting.button.apply': 'Uygula', 'setting.text.currentEnv': 'Geçerli Ortam', 'setting.text.currentVersion': 'Geçerli Sürüm', 'setting.text.viewingUpdateLogs': 'Güncelleme Günlüklerini Görüntüleme', 'setting.label.isStreamOutput': 'Arayüzün çıktıyı akıtıp akıtmadığı', - 'setting.label.customAiUrl': 'Kullanıcı tanımlı arayüz URL\'si', + 'setting.label.customAiUrl': "Kullanıcı tanımlı arayüz URL'si", 'setting.placeholder.httpsProxy': 'Gerekli değil. OPENAI arayüzünü istemek için HTTP proxy {1} ayarlayın.', - 'setting.placeholder.apiKey': 'APIKEY\'i görüntülemek için OpenAI resmi web sitesine gidin', - 'setting.placeholder.chat2dbApiKey': 'Chat2DB tarafından sağlanan APIKEY\'i kullanın', - 'setting.placeholder.customUrl': 'AI REST arayüzünün URL\'si', + 'setting.placeholder.apiKey': "APIKEY'i görüntülemek için OpenAI resmi web sitesine gidin", + 'setting.placeholder.chat2dbApiKey': "Chat2DB tarafından sağlanan APIKEY'i kullanın", + 'setting.placeholder.customUrl': "AI REST arayüzünün URL'si", 'setting.placeholder.apiHost': 'Bu parametre zorunludur. Varsayılan değer https://api.openai.com/', 'setting.message.urlTestError': 'Arayüz testi başarısız oldu. İşlem', - 'setting.placeholder.azureOpenAIKey': 'Azure Portal\'dan Azure OpenAI anahtar kimlik bilgilerini alın', - 'setting.placeholder.azureEndpoint': 'Azure Portal\'dan Azure OpenAI uç noktasını alın', + 'setting.placeholder.azureOpenAIKey': "Azure Portal'dan Azure OpenAI anahtar kimlik bilgilerini alın", + 'setting.placeholder.azureEndpoint': "Azure Portal'dan Azure OpenAI uç noktasını alın", 'setting.placeholder.azureDeployment': 'Dağıtılan modelin dağıtım kimliği', 'setting.ai.tips': 'Lütfen oturum açın ve AI yapılandırmasını seçin', 'setting.ai.user.hidden': '"Ayarlar -> Özel AI" içinde ApiKey\'i ayarlamak için lütfen yönetici ile iletişime geçin', @@ -51,9 +51,12 @@ export default { 'setting.text.autoUpdate': 'Yeni sürüm otomatik olarak indirilir ve yükler', 'setting.text.manualUpdate': 'Yalnızca yeni bir sürüm yayınlandığında beni uyar', 'setting.button.iSee': 'Görüyorum', - 'setting.text.newEditionIsReady': 'Yeni sürüm indirme tamamlandı, yazılımı yeniden başlatarak yeni sürümü kurabilirsiniz', + 'setting.text.newEditionIsReady': + 'Yeni sürüm indirme tamamlandı, yazılımı yeniden başlatarak yeni sürümü kurabilirsiniz', 'setting.button.goToUpdate': 'Güncellemeye Git', 'setting.text.UpdatedLatestVersion': 'En son sürüme güncellendi {1}', 'setting.title.holdingService': 'Hizmeti Tutma', 'setting.text.holdingService': 'Uygulamadan çıkarken hizmeti tutarak başlangıcı hızlandırın', + 'setting.chat2db.ai.button': `Daha güçlü AI özellikleri için lütfen Chat2DB Pro'yu ziyaret edin`, + 'setting.title.goto.chat2db.pro': `Chat2DB Pro'ya Git`, }; diff --git a/chat2db-client/src/i18n/zh-cn/setting.ts b/chat2db-client/src/i18n/zh-cn/setting.ts index c4fa188aa..121a0007b 100644 --- a/chat2db-client/src/i18n/zh-cn/setting.ts +++ b/chat2db-client/src/i18n/zh-cn/setting.ts @@ -21,7 +21,7 @@ export default { 'setting.tab.aiType.baichuan': '百川', 'setting.tab.aiType.wenxin': '文心一言', 'setting.tab.aiType.tongyiqianwen': '通义千问', - 'setting.tab.aiType.custom.tips': "接口格式与OpenAI接口格式一致", + 'setting.tab.aiType.custom.tips': '接口格式与OpenAI接口格式一致', 'setting.label.serviceAddress': '服务地址', 'setting.button.apply': '应用', 'setting.text.currentEnv': '当前环境', @@ -56,5 +56,6 @@ export default { 'setting.text.UpdatedLatestVersion': '已更新到最新版本 {1}', 'setting.title.holdingService': '保持服务', 'setting.text.holdingService': '退出应用时保持服务,加快启动速度', - + 'setting.chat2db.ai.button': '请前往 Chat2DB Pro 体验更为强大的AI功能', + 'setting.title.goto.chat2db.pro': '前往Chat2DB Pro', }; diff --git a/chat2db-client/src/pages/main/index.less b/chat2db-client/src/pages/main/index.less index 9c3804e50..6596597ab 100644 --- a/chat2db-client/src/pages/main/index.less +++ b/chat2db-client/src/pages/main/index.less @@ -109,6 +109,16 @@ color: var(--color-primary); } } + .rocketIcon{ + font-size: 20px; + cursor: pointer; + color: var(--custom-color-icon); + cursor: pointer; + margin-bottom: 12px; + &:hover { + color: var(--color-primary); + } + } } .userDropdown { diff --git a/chat2db-client/src/pages/main/index.tsx b/chat2db-client/src/pages/main/index.tsx index c0e7853a3..11104dd4e 100644 --- a/chat2db-client/src/pages/main/index.tsx +++ b/chat2db-client/src/pages/main/index.tsx @@ -1,6 +1,6 @@ import React, { useEffect, useMemo, useState } from 'react'; import { useNavigate } from 'react-router-dom'; -import { Dropdown, Tooltip } from 'antd'; +import { Button, Dropdown, Tooltip } from 'antd'; import classnames from 'classnames'; import Iconfont from '@/components/Iconfont'; @@ -32,7 +32,8 @@ import Setting from '@/blocks/Setting'; import styles from './index.less'; import { useUpdateEffect } from '@/hooks'; - +import { getLinkBasedOnTimezone } from '@/utils/timezone'; +import { RocketIcon } from 'lucide-react'; const initNavConfig: INavItem[] = [ { @@ -188,7 +189,7 @@ function MainPage() { return (
- {(isMac === void 0) && } + {isMac === void 0 && }
    {navConfig.map((item) => { return ( @@ -206,9 +207,18 @@ function MainPage() { })}
- - {userInfo?.roleCode !== IRole.DESKTOP ? renderUser() : null} + + { + const link = getLinkBasedOnTimezone(); + window.open(link, '_blank'); + }} + /> + {/* + {userInfo?.roleCode !== IRole.DESKTOP ? renderUser() : null} + */}
diff --git a/chat2db-client/src/utils/timezone.ts b/chat2db-client/src/utils/timezone.ts new file mode 100644 index 000000000..98cb166dd --- /dev/null +++ b/chat2db-client/src/utils/timezone.ts @@ -0,0 +1,16 @@ +export function getLinkBasedOnTimezone(): string { + // 获取当前时区 + const timezone = new Intl.DateTimeFormat().resolvedOptions().timeZone; + + // 定义中国时区的链接和非中国时区的链接 + const chinaLink = "https://chat2db-ai.com"; + const nonChinaLink = "https://chat2db.ai"; + + // 判断时区是否为中国的时区,这里简化为检查是否为"Asia/Shanghai"或"Asia/Chongqing" + // 你也可以根据需要检查时区偏移是否为UTC+8 + if (timezone === "Asia/Shanghai" || timezone === "Asia/Chongqing") { + return chinaLink; + } else { + return nonChinaLink; + } +} diff --git a/chat2db-client/yarn.lock b/chat2db-client/yarn.lock index 11ad8c01f..73be1ce87 100644 --- a/chat2db-client/yarn.lock +++ b/chat2db-client/yarn.lock @@ -7441,6 +7441,11 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" +lucide-react@^0.365.0: + version "0.365.0" + resolved "https://registry.npmmirror.com/lucide-react/-/lucide-react-0.365.0.tgz#aa15b62e004bf35d557451f4b3aed2f6da5e2d84" + integrity sha512-sJYpPyyzGHI4B3pys+XSFnE4qtSWc68rFnDLxbNNKjkLST5XSx9DNn5+1Z3eFgFiw39PphNRiVBSVb+AL3oKwA== + make-dir@^2.1.0: version "2.1.0" resolved "https://registry.npmmirror.com/make-dir/-/make-dir-2.1.0.tgz#5f0310e18b8be898cc07009295a30ae41e91e6f5"