Skip to content

Commit

Permalink
feat: Add link to Chat2DB Pro
Browse files Browse the repository at this point in the history
  • Loading branch information
JerryFan626 committed Apr 8, 2024
1 parent fe88143 commit 75517c7
Show file tree
Hide file tree
Showing 11 changed files with 137 additions and 59 deletions.
1 change: 1 addition & 0 deletions chat2db-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
95 changes: 59 additions & 36 deletions chat2db-client/src/blocks/Setting/AiSetting/index.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,11 +22,11 @@ function capitalizeFirstLetter(string) {
// openAI 的设置项
export default function SettingAI(props: IProps) {
const [aiConfig, setAiConfig] = useState<IAiConfig>();
const { userInfo } = useUserStore(state => {
const { userInfo } = useUserStore((state) => {
return {
userInfo: state.curUser
}
})
userInfo: state.curUser,
};
});

useEffect(() => {
setAiConfig(props.aiConfig);
Expand Down Expand Up @@ -65,6 +66,57 @@ export default function SettingAI(props: IProps) {
}
};

const renderAIConfig = () => {
if (aiConfig?.aiSqlSource === AIType.CHAT2DBAI) {
return (
<Flex justify="center">
<Button
type="primary"
onClick={() => {
const link = getLinkBasedOnTimezone();
window.open(link, '_blank');
}}
>
{i18n('setting.chat2db.ai.button')}
</Button>
</Flex>
);
}
return (
<>
<Form layout="vertical">
{Object.keys(AIFormConfig[aiConfig?.aiSqlSource]).map((key: string) => (
<Form.Item
key={key}
required={key === 'apiKey' || key === 'secretKey'}
label={capitalizeFirstLetter(key)}
className={styles.title}
>
<Input
autoComplete="off"
value={aiConfig[key]}
placeholder={AIFormConfig[aiConfig?.aiSqlSource]?.[key]}
onChange={(e) => {
setAiConfig({ ...aiConfig, [key]: e.target.value });
}}
/>
</Form.Item>
))}
</Form>
{aiConfig.aiSqlSource === AIType.RESTAI && (
<div style={{ margin: '32px 0 ', fontSize: '12px', opacity: '0.5' }}>{`Tips: ${i18n(
'setting.tab.aiType.custom.tips',
)}`}</div>
)}
<div className={styles.bottomButton}>
<Button type="primary" onClick={handleApplyAiConfig}>
{i18n('setting.button.apply')}
</Button>
</div>
</>
);
};

return (
<>
<div className={styles.aiSqlSource}>
Expand All @@ -78,36 +130,7 @@ export default function SettingAI(props: IProps) {
</Radio.Group>
</div>

<Form layout="vertical">
{Object.keys(AIFormConfig[aiConfig?.aiSqlSource]).map((key: string) => (
<Form.Item
key={key}
required={key === 'apiKey' || key === 'secretKey'}
label={capitalizeFirstLetter(key)}
className={styles.title}
>
<Input
autoComplete="off"
value={aiConfig[key]}
placeholder={AIFormConfig[aiConfig?.aiSqlSource]?.[key]}
onChange={(e) => {
setAiConfig({ ...aiConfig, [key]: e.target.value });
}}
/>
</Form.Item>
))}
</Form>

{aiConfig.aiSqlSource === AIType.RESTAI && (
<div style={{ margin: '32px 0 ', fontSize: '12px', opacity: '0.5' }}>{`Tips: ${i18n(
'setting.tab.aiType.custom.tips',
)}`}</div>
)}
<div className={styles.bottomButton}>
<Button type="primary" onClick={handleApplyAiConfig}>
{i18n('setting.button.apply')}
</Button>
</div>
{renderAIConfig()}

{/* {aiConfig?.aiSqlSource === AIType.CHAT2DBAI && !aiConfig.apiKey && <Popularize source="setting" />} */}
</>
Expand Down
2 changes: 1 addition & 1 deletion chat2db-client/src/blocks/Setting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 5 additions & 2 deletions chat2db-client/src/i18n/en-us/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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',
};
16 changes: 11 additions & 5 deletions chat2db-client/src/i18n/ja-jp/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,21 @@ 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': '現在の環境',
'setting.text.currentVersion': '現在のバージョン',
'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キーを取得します',
Expand All @@ -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へ行く',
};
19 changes: 11 additions & 8 deletions chat2db-client/src/i18n/tr-tr/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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`,
};
5 changes: 3 additions & 2 deletions chat2db-client/src/i18n/zh-cn/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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': '当前环境',
Expand Down Expand Up @@ -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',
};
10 changes: 10 additions & 0 deletions chat2db-client/src/pages/main/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 15 additions & 5 deletions chat2db-client/src/pages/main/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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[] = [
{
Expand Down Expand Up @@ -188,7 +189,7 @@ function MainPage() {
return (
<div className={styles.page}>
<div className={styles.layoutLeft}>
{(isMac === void 0) && <BrandLogo size={38} className={styles.brandLogo} />}
{isMac === void 0 && <BrandLogo size={38} className={styles.brandLogo} />}
<ul className={styles.navList}>
{navConfig.map((item) => {
return (
Expand All @@ -206,9 +207,18 @@ function MainPage() {
})}
</ul>
<div className={styles.footer}>
<Tooltip placement="right" title="个人中心">
{userInfo?.roleCode !== IRole.DESKTOP ? renderUser() : null}
<Tooltip placement="right" title={i18n('setting.title.goto.chat2db.pro')}>
<RocketIcon
className={styles.rocketIcon}
onClick={() => {
const link = getLinkBasedOnTimezone();
window.open(link, '_blank');
}}
/>
</Tooltip>
{/* <Tooltip placement="right" title="个人中心">
{userInfo?.roleCode !== IRole.DESKTOP ? renderUser() : null}
</Tooltip> */}
<Setting className={styles.setIcon} />
</div>
</div>
Expand Down
16 changes: 16 additions & 0 deletions chat2db-client/src/utils/timezone.ts
Original file line number Diff line number Diff line change
@@ -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;
}
}
5 changes: 5 additions & 0 deletions chat2db-client/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 75517c7

Please sign in to comment.