Skip to content

Commit 827db41

Browse files
committed
fix:some bug
1 parent 3a373b7 commit 827db41

13 files changed

Lines changed: 85 additions & 70 deletions

File tree

chat2db-client/src/blocks/AppTitleBar/index.less

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
@import '../../styles/var.less';
22

33
.appTitleBar {
4+
background-color: var(--color-primary-bg);
5+
-webkit-app-region: drag;
6+
-webkit-user-select: none;
47
border-bottom: 1px solid var(--color-border);
58
display: flex;
69
justify-content: space-between;
@@ -12,11 +15,18 @@
1215
align-items: center;
1316
justify-content: space-between;
1417
padding: 0px 10px;
18+
height: 100%;
1519
.appName {
1620
flex: 1;
1721
text-align: center;
1822
font-weight: bold;
1923
}
24+
.rightSlot,.leftSlot{
25+
height: 100%;
26+
display: flex;
27+
align-items: center;
28+
-webkit-app-region: no-drag;
29+
}
2030
}
2131
.spacer {
2232
width: 126px;
@@ -27,6 +37,7 @@
2737
height: 100%;
2838
flex-shrink: 0;
2939
width: 126px;
40+
-webkit-app-region: no-drag;
3041
.windowsCloseBarItem {
3142
width: 42px;
3243
height: 100%;

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import styles from './index.less';
33
import classnames from 'classnames';
44
import { useCommonStore } from '@/store/common';
55
import Iconfont from '@/components/Iconfont';
6+
import BrandLogo from '@/components/BrandLogo';
67

78
interface IProps {
89
className?: string;
@@ -18,8 +19,8 @@ export default memo<IProps>((props) => {
1819
};
1920
});
2021

21-
const isWin = useMemo(() => {
22-
return window.electronApi?.getPlatform().isWin;
22+
const isMac = useMemo(() => {
23+
return window.electronApi?.getPlatform().isMac;
2324
}, []);
2425

2526
// const isWin = true;
@@ -48,14 +49,16 @@ export default memo<IProps>((props) => {
4849
return (
4950
<div className={classnames(styles.appTitleBar, className)} onDoubleClick={handleDoubleClick}>
5051
<div className={styles.appTitleBarGlobal}>
51-
<div className={classnames({ [styles.windowsSpacer]: isWin })} />
52+
<div className={classnames({ [styles.windowsSpacer]: (!isMac && isMac !== void 0) }, styles.leftSlot)}>
53+
{(!isMac && isMac !== void 0) && <BrandLogo size={20} className={styles.brandLogo} />}
54+
</div>
5255
<div className={styles.appName}>Chat2DB Community</div>
53-
<div>{appTitleBarRightComponent}</div>
56+
<div className={styles.rightSlot}>{appTitleBarRightComponent}</div>
5457
</div>
55-
{isWin && (
58+
{(!isMac && isMac !== void 0) && (
5659
<div className={styles.windowsCloseBar}>
5760
<div className={styles.windowsCloseBarItem} onClick={handelMinimizeWindow}>
58-
<Iconfont code="&#xe671;" />
61+
<Iconfont size={16} code="&#xe671;" />
5962
</div>
6063
<div className={styles.windowsCloseBarItem} onClick={handelMaximize}>
6164
{isMaximized ? <Iconfont code="&#xe66e;" /> : <Iconfont code="&#xe66b;" />}

chat2db-client/src/components/ConsoleEditor/components/SelectBoundInfo/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ const SelectBoundInfo = memo((props: IProps) => {
9191
setSchemaList([]);
9292
setDatabaseNameList([]);
9393
getDatabaseList();
94-
} else {
95-
setSchemaList([]);
96-
getSchemaList();
9794
}
9895
}, [boundInfo.dataSourceId, isActive]);
9996

@@ -103,6 +100,7 @@ const SelectBoundInfo = memo((props: IProps) => {
103100
return;
104101
}
105102
if (supportSchema) {
103+
setSchemaList([]);
106104
getSchemaList();
107105
}
108106
if (!supportSchema && boundInfo.databaseName) {

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ if (__ENV__ === 'local') {
99
/* 在线链接服务仅供平台体验和调试使用,平台不承诺服务的稳定性,企业客户需下载字体包自行发布使用并做好备份。 */
1010
@font-face {
1111
font-family: 'iconfont'; /* Project id 3633546 */
12-
src: url('//at.alicdn.com/t/c/font_3633546_ahqjb5vaa0m.woff2?t=1704776615855') format('woff2'),
13-
url('//at.alicdn.com/t/c/font_3633546_ahqjb5vaa0m.woff?t=1704776615855') format('woff'),
14-
url('//at.alicdn.com/t/c/font_3633546_ahqjb5vaa0m.ttf?t=1704776615855') format('truetype');
12+
src: url('//at.alicdn.com/t/c/font_3633546_wtvchggsz6n.woff2?t=1704785517485') format('woff2'),
13+
url('//at.alicdn.com/t/c/font_3633546_wtvchggsz6n.woff?t=1704785517485') format('woff'),
14+
url('//at.alicdn.com/t/c/font_3633546_wtvchggsz6n.ttf?t=1704785517485') format('truetype');
1515
}
1616
`;
1717
const style = document.createElement('style');

chat2db-client/src/hooks/usePollRequestService.ts

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import { useState, useEffect, useRef } from 'react';
22

33
interface IProps {
4-
/** 最大请求次数 */
4+
/** Maximum number of requests */
55
maxAttempts?: number;
6-
/** 请求间隔时间ms */
6+
/** Request interval ms */
77
interval?: number;
8-
/** 请求服务 */
8+
/** demand service */
99
loopService: (...rest) => Promise<boolean>;
1010
}
1111

@@ -15,45 +15,40 @@ export enum ServiceStatus {
1515
FAILURE = 'FAILURE',
1616
}
1717

18-
let intervalId: NodeJS.Timeout;
19-
2018
/**
21-
* 轮询请求后端服务
19+
* Polling request back-end service
2220
*/
2321
const usePollRequestService = ({ maxAttempts = 200, interval = 200, loopService }: IProps) => {
2422
const [serviceStatus, setServiceStatus] = useState<ServiceStatus>(ServiceStatus.PENDING);
2523
const [restart, setRestart] = useState(false);
2624
const attempts = useRef(0);
2725

2826
const serviceFn = async () => {
29-
// 第一次请求失败,启动服务
27+
// The first request fails. Start the service
3028
if (attempts.current === 1 && ServiceStatus.SUCCESS !== serviceStatus) {
3129
window.electronApi?.startServerForSpawn();
3230
}
3331
if (attempts.current >= maxAttempts) {
3432
setServiceStatus(ServiceStatus.FAILURE);
35-
clearInterval(intervalId);
3633
return;
3734
}
38-
try {
39-
attempts.current = attempts.current + 1;
40-
await loopService();
41-
setServiceStatus(ServiceStatus.SUCCESS);
42-
clearInterval(intervalId);
43-
} catch (error) {
44-
// setAttempts(attempts + 1);
45-
}
35+
attempts.current = attempts.current + 1;
36+
loopService().then((res) => {
37+
if (res) {
38+
setServiceStatus(ServiceStatus.SUCCESS);
39+
}
40+
})
41+
.catch(() => {
42+
setTimeout(serviceFn, interval);
43+
});
44+
4645
};
4746

4847
useEffect(() => {
4948
serviceFn();
50-
if (serviceStatus !== ServiceStatus.SUCCESS) {
51-
intervalId = setInterval(serviceFn, interval);
52-
}
53-
return () => clearInterval(intervalId);
5449
}, [maxAttempts, interval, restart]);
5550

56-
// 新增加的重置函数
51+
// Newly added reset function
5752
const restartPolling = () => {
5853
setServiceStatus(ServiceStatus.PENDING);
5954
attempts.current = 0;

chat2db-client/src/layouts/GlobalLayout/index.less

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,6 @@
2828
height: 100vh;
2929
display: flex;
3030
flex-direction: column;
31-
.appTitleBar {
32-
height: 30px;
33-
background-color: var(--color-primary-bg);
34-
display: flex;
35-
align-items: center;
36-
-webkit-app-region: drag;
37-
-webkit-user-select: none;
38-
}
3931
.appBody {
4032
flex: 1;
4133
position: relative;

chat2db-client/src/pages/main/connection/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import useClickAndDoubleClick from '@/hooks/useClickAndDoubleClick';
2424
import { useConnectionStore, getConnectionList } from '@/pages/main/store/connection';
2525
import { setMainPageActiveTab } from '@/pages/main/store/main';
2626
import { setCurrentConnectionDetails } from '@/pages/main/workspace/store/common';
27+
import { getOpenConsoleList } from '@/pages/main/workspace/store/console';
2728

2829
import styles from './index.less';
2930

@@ -75,7 +76,10 @@ const ConnectionsPage = () => {
7576
// 禁止冒泡到menuItem
7677
e.domEvent?.stopPropagation?.();
7778
connectionService.remove({ id: t.id }).then(() => {
78-
getConnectionList();
79+
getConnectionList().then(() => {
80+
// 连接删除后需要更新下 consoleList
81+
getOpenConsoleList();
82+
});
7983
if (connectionActiveId === t.id) {
8084
setConnectionActiveId(null);
8185
setConnectionDetail(null);

chat2db-client/src/pages/main/index.less

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
flex-direction: column;
1515
justify-content: space-between;
1616
align-items: center;
17-
width: 68px;
17+
width: 52px;
18+
padding-top: 20px;
1819
background-color: var(--color-bg-subtle);
1920
border-right: 1px solid var(--color-border-secondary);
2021
user-select: none;
@@ -35,7 +36,7 @@
3536
.brandLogo {
3637
flex-shrink: 0;
3738
overflow: hidden;
38-
margin: 20px auto;
39+
margin-bottom: 20px;
3940
cursor: pointer;
4041
}
4142

chat2db-client/src/pages/main/index.tsx

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useEffect, useState } from 'react';
1+
import React, { useEffect, useMemo, useState } from 'react';
22
import { useNavigate } from 'react-router-dom';
33
import { Dropdown, Tooltip } from 'antd';
44
import classnames from 'classnames';
@@ -33,6 +33,7 @@ import Setting from '@/blocks/Setting';
3333
import styles from './index.less';
3434
import { useUpdateEffect } from '@/hooks';
3535

36+
3637
const initNavConfig: INavItem[] = [
3738
{
3839
key: 'workspace',
@@ -70,27 +71,31 @@ const initNavConfig: INavItem[] = [
7071

7172
function MainPage() {
7273
const navigate = useNavigate();
73-
const { userInfo } = useUserStore(state => {
74+
const { userInfo } = useUserStore((state) => {
7475
return {
75-
userInfo: state.curUser
76-
}
76+
userInfo: state.curUser,
77+
};
7778
});
7879
const [navConfig, setNavConfig] = useState<INavItem[]>(initNavConfig);
7980
const mainPageActiveTab = useMainStore((state) => state.mainPageActiveTab);
8081
const [activeNavKey, setActiveNavKey] = useState<string>(
8182
__ENV__ === 'desktop' ? mainPageActiveTab : window.location.pathname.split('/')[1] || mainPageActiveTab,
8283
);
8384

85+
const isMac = useMemo(() => {
86+
return window.electronApi?.getPlatform().isMac;
87+
}, []);
88+
8489
// 当页面在workspace时,显示自定义布局
8590
useEffect(() => {
86-
if(mainPageActiveTab === 'workspace'){
91+
if (mainPageActiveTab === 'workspace') {
8792
setAppTitleBarRightComponent(<CustomLayout />);
88-
}else{
93+
} else {
8994
setAppTitleBarRightComponent(false);
9095
}
9196
return () => {
9297
setAppTitleBarRightComponent(false);
93-
}
98+
};
9499
}, [mainPageActiveTab]);
95100

96101
useEffect(() => {
@@ -183,7 +188,7 @@ function MainPage() {
183188
return (
184189
<div className={styles.page}>
185190
<div className={styles.layoutLeft}>
186-
<BrandLogo size={40} onClick={() => {}} className={styles.brandLogo} />
191+
{(isMac || isMac === void 0) && <BrandLogo size={40} className={styles.brandLogo} />}
187192
<ul className={styles.navList}>
188193
{navConfig.map((item) => {
189194
return (

chat2db-client/src/pages/main/store/connection/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import connectionService from '@/service/connection';
88

99
import { setCurrentConnectionDetails } from '@/pages/main/workspace/store/common';
1010
import { useWorkspaceStore } from '@/pages/main/workspace/store';
11-
import { getOpenConsoleList } from '@/pages/main/workspace/store/console';
1211

1312
export interface IConnectionStore {
1413
connectionList: IConnectionListItem[] | null;
@@ -46,8 +45,6 @@ export const getConnectionList: () => Promise<IConnectionListItem[]> = () => {
4645
const connectionList = res?.data || [];
4746
useConnectionStore.setState({ connectionList });
4847
resolve(connectionList);
49-
// 连接删除后需要更新下 consoleList
50-
getOpenConsoleList();
5148

5249
// 如果连接列表为空,则设置当前连接为空
5350
if (connectionList.length === 0) {

0 commit comments

Comments
 (0)