Skip to content

Commit 74d0ff6

Browse files
committed
Merge branch 'dev' of github.com:chat2db/Chat2DB into dev
2 parents 85e4b62 + e4e1757 commit 74d0ff6

23 files changed

Lines changed: 358 additions & 109 deletions

File tree

chat2db-client/.umirc.prod.desktop.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ const chainWebpack = (config: any, { webpack }: any) => {
1313
};
1414

1515
export default defineConfig({
16+
history: {
17+
type: 'hash',
18+
},
1619
publicPath: './',
1720
chainWebpack,
1821
define: {

chat2db-client/.umirc.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ const chainWebpack = (config: any, { webpack }: any) => {
1616

1717
export default defineConfig({
1818
title: 'Chat2DB',
19-
history: {
20-
type: 'hash',
21-
},
2219
base: '/',
2320
publicPath: '/',
2421
hash: false,

chat2db-client/readme.md

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,30 +9,24 @@
99
目录结构 tree ./ -L 2 -I node_modules
1010

1111
## 启动项目
12-
强制使用yarn,因为环境变量、lock文件只维护了yarn,npm/pnpm可能会产生意想不到的bug
13-
node版本要求16以上
14-
`npm i -g yarn`
15-
`yarn`
16-
`yarn run build:web:prod`
17-
`cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front` (复制打包结果到指定目录。windows可能命令不一样,可以手动复制下)
18-
之后就可以启动后端了 `mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml`
19-
20-
启动前端项目调试
21-
`yarn run start:web`
22-
注意:因为electron包比较难下载,如果yarn时electron下载失败或超时,可以删除掉chat2db-client/package.json下的electron,再次yarn
23-
24-
## TS书写规范
25-
1. 所有的interface 与 type 必须已I开头
26-
`interface IState { name: string }` // good
27-
`interface State { name: string }` // bad
28-
29-
## 如何在js与css中使用颜色
30-
具体转换在 /theme/index.ts 中的 InjectThemeVar
31-
- js 在window._AppThemePack中去取 eg:`window._AppThemePack.controlItemBgActive` // good
32-
- css eg: `background: var(--control-item-bg-active)` // good
33-
- css `color: #fff` // bad
34-
35-
## 如何使用国际化
12+
13+
强制使用 yarn,因为环境变量、lock 文件只维护了 yarn,npm/pnpm 可能会产生意想不到的 bug node 版本要求 16 以上 `npm i -g yarn` `yarn` `yarn run build:web:prod` `cp -r dist ../chat2db-server/chat2db-server-start/src/main/resources/static/front` (复制打包结果到指定目录。windows 可能命令不一样,可以手动复制下) 之后就可以启动后端了 `mvn clean package -B '-Dmaven.test.skip=true' -f chat2db-server/pom.xml`
14+
15+
启动前端项目调试 `yarn run start:web` 注意:因为 electron 包比较难下载,如果 yarn 时 electron 下载失败或超时,可以删除掉 chat2db-client/package.json 下的 electron,再次 yarn
16+
17+
## TS 书写规范
18+
19+
1. 所有的 interface 与 type 必须已 I 开头 `interface IState { name: string }` // good `interface State { name: string }` // bad
20+
21+
## 如何在 js 与 css 中使用颜色
22+
23+
具体转换在 /theme/index.ts 中的 injectThemeVar
24+
25+
- js 在 window.\_AppThemePack 中去取 eg:`window._AppThemePack.controlItemBgActive` // good
26+
- css eg: `background: var(--control-item-bg-active)` // good
27+
- css `color: #fff` // bad
28+
29+
## 如何使用国际化
3630

3731
所有 key 参考格式为 `模块名称.文案类型.文案描述`。若文案包含可变部分,可使用 `{1}``{2}``{3}` 代替。
3832

chat2db-client/src/blocks/DatabaseTableEditor/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import lodash from 'lodash';
1414
interface IProps {
1515
dataSourceId: number;
1616
databaseName: string;
17-
schemaName: string | null;
17+
schemaName?: string | null;
1818
tableName?: string;
1919
databaseType: DatabaseTypeCode;
2020
changeTabDetails: (data: IWorkspaceTab) => void;

chat2db-client/src/blocks/EditTableData/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ interface IProps {
77
className?: string;
88
dataSourceId: number;
99
databaseName: string;
10-
schemaName: string | undefined;
10+
schemaName?: string | null;
1111
tableName?: string;
1212
databaseType: DatabaseTypeCode;
1313
}

chat2db-client/src/blocks/Setting/index.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,19 @@ function Setting(props: IProps) {
2828

2929
const [currentMenu, setCurrentMenu] = useState(0);
3030

31+
// 判断当前页面是否为登录页
32+
const loginPage = window.location.pathname === '/login';
33+
3134
useEffect(() => {
32-
if (isModalVisible) {
35+
if (isModalVisible && !loginPage) {
3336
getAiSystemConfig();
3437
}
3538
}, [isModalVisible]);
3639

3740
useEffect(() => {
38-
getAiSystemConfig();
41+
if (!loginPage) {
42+
getAiSystemConfig();
43+
}
3944
}, []);
4045

4146
const getAiSystemConfig = () => {
@@ -114,6 +119,9 @@ function Setting(props: IProps) {
114119
<div className={styles.menus}>
115120
<div className={classnames(styles.menusTitle)}>{i18n('setting.title.setting')}</div>
116121
{menusList.map((t, index) => {
122+
if (loginPage && index === 1) {
123+
return false;
124+
}
117125
return (
118126
<div
119127
key={index}

chat2db-client/src/components/TabsNew/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export interface ITabItem {
1010
key: number | string;
1111
popover?: string | React.ReactNode;
1212
children?: React.ReactNode;
13-
editableName?: boolean | undefined;
13+
editableName?: boolean;
1414
canClosed?: boolean;
1515
styles?: React.CSSProperties;
1616
}

chat2db-client/src/indexedDB/index.ts

Whitespace-only changes.
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
import { tableList } from './table';
2+
3+
// 创建数据库的方法
4+
export const createDB = (dbName: string, version: number) => {
5+
return new Promise((resolve, reject) => {
6+
const request = window.indexedDB.open(dbName, version);
7+
request.onerror = (event: any) => {
8+
reject(event.target.error);
9+
};
10+
request.onsuccess = (event: any) => {
11+
resolve(event.target.result);
12+
};
13+
request.onupgradeneeded = (event: any) => {
14+
const db = event.target.result; // 数据库对象
15+
// 创建存储库
16+
tableList.forEach((item: any) => {
17+
const { tableDetails } = item;
18+
const objectStore = db.createObjectStore(tableDetails.name, tableDetails.primaryKey);
19+
tableDetails.column.forEach((i: any) => {
20+
if (i.isIndex) {
21+
objectStore.createIndex(i.name, i.keyPath, i.options);
22+
}
23+
});
24+
});
25+
};
26+
});
27+
};
28+
29+
// 添加数据
30+
export const addData = (db: any, tableName: string, data: any) => {
31+
return new Promise((resolve, reject) => {
32+
const transaction = db.transaction(tableName, 'readwrite');
33+
const objectStore = transaction.objectStore(tableName);
34+
const request = objectStore.add(data);
35+
request.onsuccess = () => {
36+
resolve(true);
37+
};
38+
request.onerror = (error) => {
39+
reject(error);
40+
};
41+
});
42+
};
43+
44+
// 删除数据
45+
export const deleteData = (db: any, tableName: string, key: string) => {
46+
return new Promise((resolve, reject) => {
47+
const transaction = db.transaction(tableName, 'readwrite');
48+
const objectStore = transaction.objectStore(tableName);
49+
const request = objectStore.delete(key);
50+
request.onsuccess = () => {
51+
resolve(true);
52+
};
53+
request.onerror = () => {
54+
reject(false);
55+
};
56+
});
57+
};
58+
59+
// 修改数据
60+
export const updateData = (db: any, tableName: string, data: any) => {
61+
return new Promise((resolve, reject) => {
62+
const transaction = db.transaction(tableName, 'readwrite');
63+
const objectStore = transaction.objectStore(tableName);
64+
const request = objectStore.put(data);
65+
request.onsuccess = () => {
66+
resolve(true);
67+
};
68+
request.onerror = () => {
69+
reject(false);
70+
};
71+
});
72+
};
73+
74+
// 查询数据
75+
export const getData = (db: any, tableName: string, key: string) => {
76+
return new Promise((resolve, reject) => {
77+
const transaction = db.transaction(tableName, 'readwrite');
78+
const objectStore = transaction.objectStore(tableName);
79+
const request = objectStore.get(key);
80+
request.onsuccess = () => {
81+
resolve(request.result);
82+
};
83+
request.onerror = () => {
84+
reject(false);
85+
};
86+
});
87+
};
88+
89+
// 关闭数据库
90+
export const closeDB = (db: any) => {
91+
return new Promise((resolve) => {
92+
db.close();
93+
resolve(true);
94+
});
95+
};
96+
97+
export default {
98+
createDB,
99+
addData,
100+
deleteData,
101+
updateData,
102+
getData,
103+
closeDB,
104+
};
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
import { WorkspaceTabType } from '@/constants';
2+
3+
export interface IWorkspaceConsole {
4+
id: number; // Tab的id
5+
name: string; // 工作区tab的名称
6+
dataSourceId: number; // 数据源id
7+
dataSourceName: string; // 数据源名称
8+
databaseName: string; // 数据库名称
9+
schemaName?: string; // schema名称q
10+
databaseType: string; // 数据源类型
11+
ddl: string; // 数据源ddl
12+
workspaceTabType: WorkspaceTabType; // 操作类型
13+
userName?: string; // 用户名,用户的唯一id
14+
}
15+
16+
// 工作区console表
17+
export const workspaceConsoleTable = {
18+
name: 'workspaceConsoleTab',
19+
primaryKey: {
20+
keyPath: 'id',
21+
autoIncrement: true,
22+
},
23+
column: [
24+
{
25+
name: 'id',
26+
keyPath: 'id',
27+
isIndex: true,
28+
options: {
29+
unique: true,
30+
},
31+
},
32+
{
33+
name: 'userName',
34+
keyPath: 'userName',
35+
isIndex: true,
36+
options: {
37+
unique: false,
38+
},
39+
},
40+
{
41+
name: 'name',
42+
keyPath: 'name',
43+
isIndex: true,
44+
options: {
45+
unique: false,
46+
},
47+
},
48+
{
49+
name: 'dataSourceId',
50+
keyPath: 'dataSourceId',
51+
isIndex: true,
52+
options: {
53+
unique: false,
54+
},
55+
},
56+
{
57+
name: 'dataSourceName',
58+
keyPath: 'dataSourceName',
59+
isIndex: true,
60+
options: {
61+
unique: false,
62+
},
63+
},
64+
{
65+
name: 'databaseName',
66+
keyPath: 'databaseName',
67+
isIndex: true,
68+
options: {
69+
unique: false,
70+
},
71+
},
72+
{
73+
name: 'schemaName',
74+
keyPath: 'schemaName',
75+
isIndex: true,
76+
options: {
77+
unique: false,
78+
},
79+
},
80+
{
81+
name: 'databaseType',
82+
keyPath: 'databaseType',
83+
isIndex: true,
84+
options: {
85+
unique: false,
86+
},
87+
},
88+
{
89+
name: 'ddl',
90+
keyPath: 'ddl',
91+
options: {
92+
unique: false,
93+
},
94+
},
95+
{
96+
name: 'workspaceTabType',
97+
keyPath: 'workspaceTabType',
98+
isIndex: true,
99+
options: {
100+
unique: false,
101+
},
102+
},
103+
],
104+
}
105+
106+
export const tableList = [
107+
{
108+
tableDetails: workspaceConsoleTable,
109+
}
110+
]

0 commit comments

Comments
 (0)