mirror of
https://github.com/whyour/qinglong.git
synced 2025-05-23 23:06:06 +08:00
修复表格滚动样式和交互
This commit is contained in:
parent
632514d36e
commit
d6ebd2699e
|
@ -0,0 +1,3 @@
|
||||||
|
.ant-table-pagination.ant-pagination {
|
||||||
|
margin-bottom: 0;
|
||||||
|
}
|
|
@ -34,6 +34,8 @@ import CronModal from './modal';
|
||||||
import CronLogModal from './logModal';
|
import CronLogModal from './logModal';
|
||||||
import cron_parser from 'cron-parser';
|
import cron_parser from 'cron-parser';
|
||||||
import { diffTime } from '@/utils/date';
|
import { diffTime } from '@/utils/date';
|
||||||
|
import { getTableScroll } from '@/utils/index';
|
||||||
|
import './index.less';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
@ -66,7 +68,7 @@ enum OperationPath {
|
||||||
}
|
}
|
||||||
|
|
||||||
const Crontab = ({ headerStyle, isPhone }: any) => {
|
const Crontab = ({ headerStyle, isPhone }: any) => {
|
||||||
const columns = [
|
const columns: any = [
|
||||||
{
|
{
|
||||||
title: '任务名',
|
title: '任务名',
|
||||||
dataIndex: 'name',
|
dataIndex: 'name',
|
||||||
|
@ -324,6 +326,7 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
|
||||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [pageSize, setPageSize] = useState(20);
|
const [pageSize, setPageSize] = useState(20);
|
||||||
|
const [tableScrollHeight, setTableScrollHeight] = useState<number>();
|
||||||
|
|
||||||
const getCrons = () => {
|
const getCrons = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
@ -673,6 +676,12 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
|
||||||
|
|
||||||
const onSelectChange = (selectedIds: any[]) => {
|
const onSelectChange = (selectedIds: any[]) => {
|
||||||
setSelectedRowIds(selectedIds);
|
setSelectedRowIds(selectedIds);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (selectedRowIds.length === 0 || selectedIds.length === 0) {
|
||||||
|
setTableScrollHeight(getTableScroll());
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
|
@ -754,6 +763,7 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPageSize(parseInt(localStorage.getItem('pageSize') || '20'));
|
setPageSize(parseInt(localStorage.getItem('pageSize') || '20'));
|
||||||
|
setTableScrollHeight(getTableScroll());
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
@ -839,7 +849,7 @@ const Crontab = ({ headerStyle, isPhone }: any) => {
|
||||||
dataSource={value}
|
dataSource={value}
|
||||||
rowKey="_id"
|
rowKey="_id"
|
||||||
size="middle"
|
size="middle"
|
||||||
scroll={{ x: 1000 }}
|
scroll={{ x: 1000, y: tableScrollHeight }}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
rowSelection={rowSelection}
|
rowSelection={rowSelection}
|
||||||
rowClassName={getRowClassName}
|
rowClassName={getRowClassName}
|
||||||
|
|
16
src/pages/env/index.tsx
vendored
16
src/pages/env/index.tsx
vendored
|
@ -25,6 +25,7 @@ import EditNameModal from './editNameModal';
|
||||||
import { DndProvider, useDrag, useDrop } from 'react-dnd';
|
import { DndProvider, useDrag, useDrop } from 'react-dnd';
|
||||||
import { HTML5Backend } from 'react-dnd-html5-backend';
|
import { HTML5Backend } from 'react-dnd-html5-backend';
|
||||||
import './index.less';
|
import './index.less';
|
||||||
|
import { getTableScroll } from '@/utils/index';
|
||||||
|
|
||||||
const { Text } = Typography;
|
const { Text } = Typography;
|
||||||
const { Search } = Input;
|
const { Search } = Input;
|
||||||
|
@ -96,7 +97,7 @@ const DragableBodyRow = ({
|
||||||
};
|
};
|
||||||
|
|
||||||
const Env = ({ headerStyle, isPhone, theme }: any) => {
|
const Env = ({ headerStyle, isPhone, theme }: any) => {
|
||||||
const columns = [
|
const columns: any = [
|
||||||
{
|
{
|
||||||
title: '序号',
|
title: '序号',
|
||||||
align: 'center' as const,
|
align: 'center' as const,
|
||||||
|
@ -205,6 +206,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
|
||||||
const [editedEnv, setEditedEnv] = useState();
|
const [editedEnv, setEditedEnv] = useState();
|
||||||
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
const [selectedRowIds, setSelectedRowIds] = useState<string[]>([]);
|
||||||
const [searchText, setSearchText] = useState('');
|
const [searchText, setSearchText] = useState('');
|
||||||
|
const [tableScrollHeight, setTableScrollHeight] = useState<number>();
|
||||||
|
|
||||||
const getEnvs = () => {
|
const getEnvs = () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
@ -361,6 +363,12 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
|
||||||
|
|
||||||
const onSelectChange = (selectedIds: any[]) => {
|
const onSelectChange = (selectedIds: any[]) => {
|
||||||
setSelectedRowIds(selectedIds);
|
setSelectedRowIds(selectedIds);
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
if (selectedRowIds.length === 0 || selectedIds.length === 0) {
|
||||||
|
setTableScrollHeight(getTableScroll({ extraHeight: 40 }));
|
||||||
|
}
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const rowSelection = {
|
const rowSelection = {
|
||||||
|
@ -426,6 +434,10 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
|
||||||
getEnvs();
|
getEnvs();
|
||||||
}, [searchText]);
|
}, [searchText]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setTableScrollHeight(getTableScroll({ extraHeight: 40 }));
|
||||||
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PageContainer
|
<PageContainer
|
||||||
className="ql-container-wrapper env-wrapper"
|
className="ql-container-wrapper env-wrapper"
|
||||||
|
@ -490,7 +502,7 @@ const Env = ({ headerStyle, isPhone, theme }: any) => {
|
||||||
dataSource={value}
|
dataSource={value}
|
||||||
rowKey="_id"
|
rowKey="_id"
|
||||||
size="middle"
|
size="middle"
|
||||||
scroll={{ x: 768 }}
|
scroll={{ x: 768, y: tableScrollHeight }}
|
||||||
components={components}
|
components={components}
|
||||||
loading={loading}
|
loading={loading}
|
||||||
onRow={(record: any, index: number) => {
|
onRow={(record: any, index: number) => {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { useState, useEffect, useMemo } from 'react';
|
import { useState, useEffect, useMemo } from 'react';
|
||||||
import browserType from './browser';
|
import browserType from './index';
|
||||||
|
|
||||||
export const useCtx = () => {
|
export const useCtx = () => {
|
||||||
const [width, setWidth] = useState('100%');
|
const [width, setWidth] = useState('100%');
|
||||||
|
|
|
@ -170,3 +170,38 @@ export default function browserType() {
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取第一个表格的可视化高度
|
||||||
|
* @param {*} extraHeight 额外的高度(表格底部的内容高度 Number类型,默认为74)
|
||||||
|
* @param {*} id 当前页面中有多个table时需要制定table的id
|
||||||
|
*/
|
||||||
|
export function getTableScroll({
|
||||||
|
extraHeight,
|
||||||
|
id,
|
||||||
|
}: { extraHeight?: number; id?: string } = {}) {
|
||||||
|
if (typeof extraHeight == 'undefined') {
|
||||||
|
// 默认底部分页64 + 边距10
|
||||||
|
extraHeight = 80;
|
||||||
|
}
|
||||||
|
let tHeader = null;
|
||||||
|
if (id) {
|
||||||
|
tHeader = document.getElementById(id)
|
||||||
|
? document
|
||||||
|
.getElementById(id)!
|
||||||
|
.getElementsByClassName('ant-table-thead')[0]
|
||||||
|
: null;
|
||||||
|
} else {
|
||||||
|
tHeader = document.getElementsByClassName('ant-table-thead')[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
//表格内容距离顶部的距离
|
||||||
|
let tHeaderBottom = 0;
|
||||||
|
if (tHeader) {
|
||||||
|
tHeaderBottom = tHeader.getBoundingClientRect().bottom;
|
||||||
|
}
|
||||||
|
|
||||||
|
//窗体高度-表格内容顶部的高度-表格内容底部的高度
|
||||||
|
let height = document.body.clientHeight - tHeaderBottom - extraHeight;
|
||||||
|
return height;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user