1
1
import React , { useEffect , useState } from 'react' ;
2
2
import configService from '@/service/config' ;
3
3
import { AIType } from '@/typings/ai' ;
4
- import { Alert , Button , Form , Input , Radio , RadioChangeEvent } from 'antd' ;
4
+ import { Alert , Button , Flex , Form , Input , Radio , RadioChangeEvent } from 'antd' ;
5
5
import i18n from '@/i18n' ;
6
6
import { IAiConfig } from '@/typings/setting' ;
7
7
import { IRole } from '@/typings/user' ;
8
8
import { AIFormConfig , AITypeName } from './aiTypeConfig' ;
9
9
import styles from './index.less' ;
10
- import { useUserStore } from '@/store/user'
10
+ import { useUserStore } from '@/store/user' ;
11
+ import { getLinkBasedOnTimezone } from '@/utils/timezone' ;
11
12
12
13
interface IProps {
13
14
handleApplyAiConfig : ( aiConfig : IAiConfig ) => void ;
@@ -21,11 +22,11 @@ function capitalizeFirstLetter(string) {
21
22
// openAI 的设置项
22
23
export default function SettingAI ( props : IProps ) {
23
24
const [ aiConfig , setAiConfig ] = useState < IAiConfig > ( ) ;
24
- const { userInfo } = useUserStore ( state => {
25
+ const { userInfo } = useUserStore ( ( state ) => {
25
26
return {
26
- userInfo : state . curUser
27
- }
28
- } )
27
+ userInfo : state . curUser ,
28
+ } ;
29
+ } ) ;
29
30
30
31
useEffect ( ( ) => {
31
32
setAiConfig ( props . aiConfig ) ;
@@ -65,6 +66,57 @@ export default function SettingAI(props: IProps) {
65
66
}
66
67
} ;
67
68
69
+ const renderAIConfig = ( ) => {
70
+ if ( aiConfig ?. aiSqlSource === AIType . CHAT2DBAI ) {
71
+ return (
72
+ < Flex justify = "center" >
73
+ < Button
74
+ type = "primary"
75
+ onClick = { ( ) => {
76
+ const link = getLinkBasedOnTimezone ( ) ;
77
+ window . open ( link , '_blank' ) ;
78
+ } }
79
+ >
80
+ { i18n ( 'setting.chat2db.ai.button' ) }
81
+ </ Button >
82
+ </ Flex >
83
+ ) ;
84
+ }
85
+ return (
86
+ < >
87
+ < Form layout = "vertical" >
88
+ { Object . keys ( AIFormConfig [ aiConfig ?. aiSqlSource ] ) . map ( ( key : string ) => (
89
+ < Form . Item
90
+ key = { key }
91
+ required = { key === 'apiKey' || key === 'secretKey' }
92
+ label = { capitalizeFirstLetter ( key ) }
93
+ className = { styles . title }
94
+ >
95
+ < Input
96
+ autoComplete = "off"
97
+ value = { aiConfig [ key ] }
98
+ placeholder = { AIFormConfig [ aiConfig ?. aiSqlSource ] ?. [ key ] }
99
+ onChange = { ( e ) => {
100
+ setAiConfig ( { ...aiConfig , [ key ] : e . target . value } ) ;
101
+ } }
102
+ />
103
+ </ Form . Item >
104
+ ) ) }
105
+ </ Form >
106
+ { aiConfig . aiSqlSource === AIType . RESTAI && (
107
+ < div style = { { margin : '32px 0 ' , fontSize : '12px' , opacity : '0.5' } } > { `Tips: ${ i18n (
108
+ 'setting.tab.aiType.custom.tips' ,
109
+ ) } `} </ div >
110
+ ) }
111
+ < div className = { styles . bottomButton } >
112
+ < Button type = "primary" onClick = { handleApplyAiConfig } >
113
+ { i18n ( 'setting.button.apply' ) }
114
+ </ Button >
115
+ </ div >
116
+ </ >
117
+ ) ;
118
+ } ;
119
+
68
120
return (
69
121
< >
70
122
< div className = { styles . aiSqlSource } >
@@ -78,36 +130,7 @@ export default function SettingAI(props: IProps) {
78
130
</ Radio . Group >
79
131
</ div >
80
132
81
- < Form layout = "vertical" >
82
- { Object . keys ( AIFormConfig [ aiConfig ?. aiSqlSource ] ) . map ( ( key : string ) => (
83
- < Form . Item
84
- key = { key }
85
- required = { key === 'apiKey' || key === 'secretKey' }
86
- label = { capitalizeFirstLetter ( key ) }
87
- className = { styles . title }
88
- >
89
- < Input
90
- autoComplete = "off"
91
- value = { aiConfig [ key ] }
92
- placeholder = { AIFormConfig [ aiConfig ?. aiSqlSource ] ?. [ key ] }
93
- onChange = { ( e ) => {
94
- setAiConfig ( { ...aiConfig , [ key ] : e . target . value } ) ;
95
- } }
96
- />
97
- </ Form . Item >
98
- ) ) }
99
- </ Form >
100
-
101
- { aiConfig . aiSqlSource === AIType . RESTAI && (
102
- < div style = { { margin : '32px 0 ' , fontSize : '12px' , opacity : '0.5' } } > { `Tips: ${ i18n (
103
- 'setting.tab.aiType.custom.tips' ,
104
- ) } `} </ div >
105
- ) }
106
- < div className = { styles . bottomButton } >
107
- < Button type = "primary" onClick = { handleApplyAiConfig } >
108
- { i18n ( 'setting.button.apply' ) }
109
- </ Button >
110
- </ div >
133
+ { renderAIConfig ( ) }
111
134
112
135
{ /* {aiConfig?.aiSqlSource === AIType.CHAT2DBAI && !aiConfig.apiKey && <Popularize source="setting" />} */ }
113
136
</ >
0 commit comments