util.tsx
3.51 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
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { Button, Image, message, Modal, Tooltip, Upload } from 'antd';
import { QxIcon } from '@/components';
import defaultImg from '@/components/default/default_cover.png';
const defaultIcon: Record<string, string> = {
form: 'icon-app-file-fill',
group: 'icon-app-folder-2-fill',
report: 'icon-app-performance-fill',
url: 'icon-app-share-forward-fill',
page: 'icon-app-tablicon-app-fill',
dataset: 'icon-app-presentation-2-fill',
datasetCube: 'icon-app-box-3-fill',
app: 'icon-app-grid-2-fill',
};
// 数据流 图标展示
export const getIcon = (icon: string, type?: string) => {
if ((icon as string)?.startsWith('http')) {
return (
<Image
className={'qx-data-flow__img'}
src={icon}
fallback={defaultImg}
preview={false}
width={'16px'}
height={'16px'}
style={{
width: '16px',
height: '16px',
borderRadius: '4px',
}}
alt=""
/>
);
} else {
return (
<QxIcon
className={'qx-data-flow__icon'}
type={icon || defaultIcon[type || 'form']}
/>
);
}
};
// 表格 Scroll 高度计算
export const useFlowTableScrollY = (
deps: {
columns: any[];
size?: 'small' | 'middle' | 'default';
tableBoxClassName?: string;
classNames?: string[]; // 表格DOM内嵌元素 列名 添加在此,
hasPagination?: boolean;
listProps?: any;
} = {
size: 'small',
tableBoxClassName: '',
classNames: [],
hasPagination: false,
columns: [],
listProps: {},
},
) => {
const itemHeaderHeight =
(deps?.size === 'middle' ? 48 : deps?.size === 'default' ? 56 : 40) + 1;
const TABLE_VIEW_LIST = deps?.tableBoxClassName || 'qx-data-flow-table';
let tableHeader = itemHeaderHeight;
const tableViewListDefaultHeight = 400;
const defaultPagePadding = 0;
const $ = (selectors: string) =>
document.querySelector<HTMLElement>(selectors);
const defaultScrollY = useMemo(
() => document.body.clientHeight,
[tableHeader],
);
const [scrollY, setScrollY] = useState<number>(defaultScrollY ?? 200);
const timer = useRef<NodeJS.Timer>();
const getScrollY = () => {
const tableViewList = $(`.${TABLE_VIEW_LIST}`);
const tableViewListClientHeight =
tableViewList?.clientHeight || tableViewListDefaultHeight;
// 分页大小 目前已经固定 所以直接用56px
const antPaginationHeight = deps?.hasPagination ? 56 : 0;
const _domHeightByClassName = (deps?.classNames || []).map(
(_v: string) => $(`.${_v}`)?.clientHeight ?? 0,
);
let result =
tableViewListClientHeight -
tableHeader -
defaultPagePadding -
antPaginationHeight;
if (!!_domHeightByClassName?.length) {
result = result - eval(_domHeightByClassName.join('+'));
}
if (tableViewList) {
tableViewList.style.overflowY = result < 200 ? 'auto' : 'hidden';
}
setScrollY(result < 100 ? 100 : result);
};
const observer = () => {
window.addEventListener('resize', getScrollY);
};
const removeObserver = () => {
if (timer.current) window.clearTimeout(timer.current);
window.removeEventListener('resize', getScrollY);
};
useEffect(() => {
observer();
return () => {
removeObserver();
};
}, [tableHeader]);
useEffect(() => {
if (deps) {
timer.current = setTimeout(() => {
getScrollY();
}, 100);
}
}, [JSON.stringify(deps)]);
return [scrollY, getScrollY];
};