Skip to content

Commit

Permalink
fix:Scroll bar width Auto-save bug
Browse files Browse the repository at this point in the history
  • Loading branch information
shanhexi committed Oct 19, 2023
1 parent 27cbf8b commit 6fe3f96
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
32 changes: 14 additions & 18 deletions chat2db-client/src/components/Console/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import configService from '@/service/config';
// import NewEditor from './NewMonacoEditor';
import styles from './index.less';
import indexedDB from '@/indexedDB';
import { isEmpty } from 'lodash';

enum IPromptType {
NL_2_SQL = 'NL_2_SQL',
Expand Down Expand Up @@ -135,18 +134,7 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
}));

useEffect(() => {
indexedDB
.getDataByCursor('chat2db', 'workspaceConsoleDDL', {
consoleId: executeParams.consoleId!,
userId: getCookie('CHAT2DB.USER_ID'),
})
.then((res: any) => {
const value = res?.[0]?.ddl || '';
if (value) {
editorRef?.current?.setValue(value, 'reset');
initializeSuccessful.current = true;
}
});

}, []);

useEffect(() => {
Expand All @@ -166,7 +154,19 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
}
} else {
// 活跃时自动保存
timingAutoSave();
indexedDB
.getDataByCursor('chat2db', 'workspaceConsoleDDL', {
consoleId: executeParams.consoleId!,
userId: getCookie('CHAT2DB.USER_ID'),
})
.then((res: any) => {
const value = res?.[0]?.ddl || '';
if (value) {
editorRef?.current?.setValue(value, 'reset');
initializeSuccessful.current = true;
timingAutoSave();
}
});
}
return () => {
if (timerRef.current) {
Expand All @@ -176,10 +176,6 @@ function Console(props: IProps, ref: ForwardedRef<IConsoleRef>) {
}, [isActive]);

function timingAutoSave() {
// 如果没有初始化那就不自动保存
if (!initializeSuccessful.current) {
return;
}
timerRef.current = setInterval(() => {
indexedDB.updateData('chat2db', 'workspaceConsoleDDL', {
consoleId: executeParams.consoleId!,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@
.art-table-row{
height: 32px;
}
.art-table-header {
background: transparent !important;
}
.art-table-body-scroll{
padding-right: 6px;
}
.art-table-header-cell{
padding: 0px 4px;
}
Expand Down
19 changes: 19 additions & 0 deletions chat2db-client/src/components/SearchResult/TableBox/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,25 @@ export default function TableBox(props: ITableProps) {
});
}, [queryResultData]);

// 判断art-table-body是否出现了滚动条
// useEffect(() => {
// const tableBody = document.querySelector('.art-table-body');
// const tableHeader = document.querySelector('.art-table-header');
// if (!tableBody) {
// return;
// }
// const tableBodyHeight = tableBody.clientHeight;
// const tableBoxHeight = tableBoxRef.current?.clientHeight || 0;
// if(!tableHeader){
// return;
// }
// if (tableBodyHeight > tableBoxHeight) {
// tableHeader.classList.add('art-table-body-scroll');
// } else {
// tableHeader.classList.remove('art-table-body-scroll');
// }
// }, [tableData]);

useEffect(() => {
// 每次dataList变化,都需要重新计算tableData
if (!columns?.length) {
Expand Down
4 changes: 2 additions & 2 deletions chat2db-client/src/styles/global.less
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ input:-webkit-autofill {
}

::-webkit-scrollbar {
width: 4px;
height: 4px;
width: 6px;
height: 6px;
}


Expand Down

0 comments on commit 6fe3f96

Please sign in to comment.