-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathindex.tsx
More file actions
201 lines (190 loc) · 5.88 KB
/
index.tsx
File metadata and controls
201 lines (190 loc) · 5.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
import React, { useState } from 'react';
import { LangType, ThemeType } from '@/constants';
import i18n, { currentLang } from '@/i18n';
import classnames from 'classnames';
import themeDarkImg from '@/assets/img/theme-dark.png';
import themeLightImg from '@/assets/img/theme-light.png';
import themeAutoImg from '@/assets/img/theme-auto.png';
import { Select } from 'antd';
import Iconfont from '@/components/Iconfont';
import { setLang as setLangLocalStorage } from '@/utils/localStorage';
import { useTheme } from '@/hooks/useTheme';
import styles from './index.less';
const themeList = [
{
code: ThemeType.Light,
name: i18n('setting.text.light'),
img: themeLightImg,
},
{
code: ThemeType.Dark,
name: i18n('setting.text.dark'),
img: themeDarkImg,
},
{
code: ThemeType.DarkDimmed,
name: i18n('setting.text.dark2'),
img: themeDarkImg
},
{
code: ThemeType.FollowOs,
name: i18n('setting.text.followOS'),
img: themeAutoImg,
},
// {
// code: 'eyeshield',
// name: '护眼',
// img: 'https://img.alicdn.com/imgextra/i1/O1CN01KGCqY21uJpuFjEQW2_!!6000000006017-2-tps-181-135.png'
// },
];
const languageOptions = [
{ value: LangType.ZH_CN, label: '简体中文' },
{ value: LangType.EN_US, label: 'English' },
{ value: LangType.TR_TR, label: 'Turkish' },
{ value: LangType.JA_JP, label: '日本語' },
{ value: LangType.ES_ES, label: 'Spanish' },
]
const colorList = [
{
code: 'golden-purple',
name: i18n('setting.label.violet'),
color: '#9373ee',
},
{
code: 'polar-blue',
name: i18n('setting.label.blue'),
color: '#1a90ff',
},
{
code: 'blue2',
name: i18n('setting.label.violet'),
color: '#00c3ee',
},
{
code: 'polar-green',
name: i18n('setting.label.green'),
color: '#039e74',
},
{
code: 'gold',
name: i18n('setting.label.violet'),
color: '#9a7d56',
},
{
code: 'silver',
name: i18n('setting.label.violet'),
color: '#8e8374',
},
{
code: 'red',
name: i18n('setting.label.violet'),
color: '#fd6874',
},
{
code: 'orange',
name: i18n('setting.label.violet'),
color: '#fa8c16',
},
];
// baseBody 基础设置
export default function BaseSetting() {
const [appTheme, setAppTheme] = useTheme();
const [currentTheme, setCurrentTheme] = useState<ThemeType>(appTheme.backgroundColor);
const [currentPrimaryColor, setCurrentPrimaryColor] = useState(localStorage.getItem('primary-color'));
const changePrimaryColor = (item: any) => {
const html = document.documentElement;
html.setAttribute('primary-color', item.code);
localStorage.setItem('primary-color', item.code);
setCurrentPrimaryColor(item.code);
setAppTheme({
...appTheme,
primaryColor: item.code,
});
};
function changeLang(e: any) {
setLangLocalStorage(e);
//切换语言时,需要设置cookie,用来改变后台服务的Locale
const date = new Date('2030-12-30 12:30:00').toUTCString();
document.cookie = `CHAT2DB.LOCALE=${e};Expires=${date}`;
location.reload();
}
function handleChangeTheme(backgroundColor: any) {
setAppTheme({
...appTheme,
backgroundColor,
});
setCurrentTheme(backgroundColor);
}
// const changeSqlEditorFontSize = (e: any) => {
// }
return (
<>
<div className={styles.title}>{i18n('setting.title.backgroundColor')}</div>
<ul className={styles.backgroundList}>
{themeList.map((t) => {
return (
<div key={t.code} className={styles.themeItemBox}>
<div
className={classnames({ [styles.current]: currentTheme == t.code }, styles.themeImg)}
onClick={handleChangeTheme.bind(null, t.code)}
style={{ backgroundImage: `url(${t.img})` }}
/>
<div className={styles.themeName}>{t.name}</div>
</div>
);
})}
</ul>
<div className={styles.title}>{i18n('setting.title.language')}</div>
<div className={styles.langBox}>
{/* <Radio.Group onChange={changeLang} value={currentLang}>
<Radio value={LangType.ZH_CN}>简体中文</Radio>
<Radio value={LangType.EN_US}>English</Radio>
<Radio value={LangType.TR_TR}>Turkish</Radio>
<Radio value={LangType.ES_ES}>Spanish</Radio>
</Radio.Group> */}
<Select
style={{ width: 120 }}
onChange={changeLang}
value={currentLang}
options={languageOptions}
/>
</div>
<div className={styles.title}>{i18n('setting.title.themeColor')}</div>
<ul className={styles.primaryColorList}>
{colorList.map((item) => {
return (
<div key={item.code} className={styles.themeColorItem}>
<div
className={styles.colorLump}
key={item.code}
onClick={changePrimaryColor.bind(null, item)}
style={{ backgroundColor: item.color }}
>
{currentPrimaryColor == item.code && <Iconfont code="" />}
</div>
{/* <div className={styles.colorName}>{item.name}</div> */}
</div>
);
})}
{/* <ColorPicker placement='bottomLeft' onChange={setCustomColor}>
<div className={classnames(styles.themeColorItem, styles.customColorItem) }>
<div
className={styles.colorLump}
onClick={()=>{}}
>
自定义
</div>
</div>
</ColorPicker> */}
</ul>
{/* <div className={styles.title}>{i18n('setting.title.sqlEditorFontSize')}</div>
<div className={styles.sqlEditorFontSize}>
<Radio.Group onChange={changeSqlEditorFontSize}>
<Radio value={12}>12</Radio>
<Radio value={14}>14</Radio>
<Radio value={16}>16</Radio>
</Radio.Group>
</div> */}
</>
);
}