index.tsx
4.59 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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
* @Author: zhuqin zq627501913@163.com
* @Date: 2022-05-30 17:40:47
* @LastEditors: zhuqin zq627501913@163.com
* @LastEditTime: 2022-05-31 09:14:16
* @FilePath: \qx-apaas-fe\src\pages\app-view\custom\index.tsx
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
import React, { useEffect, useState } from 'react';
import { Empty } from 'antd';
import { Responsive, WidthProvider } from 'react-grid-layout';
import ItemComponent from './components/item-component';
import { useParams } from 'umi';
import {
queryCustomComponents,
getProcessInstance,
} from '@/pages/editor/custom/service';
import _ from 'lodash';
import './index.less';
const ResponsiveGridLayout = WidthProvider(Responsive);
const CustomList: React.FC = () => {
const [layouts, setLayouts] = useState<{ lg: any[] }>({ lg: [] });
const [compList, setCompList] = useState<any[]>([]);
const { appCode, customCode } = useParams<{
appCode: string;
customCode: string;
}>();
const [taskData, setTaskData] = useState<any>();
useEffect(() => {
// 临时处理
setTimeout(() => {
const myEvent = new Event('resize');
window.dispatchEvent(myEvent);
}, 200);
}, []);
const handleInit = (cards: any[]) => {
const _layouts: any = { lg: [] };
cards.forEach((item: any, index) => {
//item.config = JSON.parse(item.config) || {};
item.location = JSON.parse(item.location) || {};
_layouts.lg[index] = {};
_layouts.lg[index].w = item.location.col;
_layouts.lg[index].h = item.location.row;
_layouts.lg[index].x = item.location.sizeX;
_layouts.lg[index].y = item.location.sizeY;
_layouts.lg[index].i = item.code;
_layouts.lg[index].static = true;
});
setLayouts(_layouts);
setCompList(cards);
};
useEffect(() => {
if (document) {
if (document?.documentElement || document?.body) {
document.documentElement.scrollTop = document.body.scrollTop = 0;
}
if (document.getElementsByClassName('reset-scroll-top')?.[0]) {
// 找你自己框架主体样式
document.getElementsByClassName('reset-scroll-top')[0].scrollTop = 0;
}
}
queryCustomComponents(appCode, customCode)
.then((data) => {
if (data) {
const taskFlagArr = (data || []).filter(
(item: any) => item.widget === 'TASK',
);
if (taskFlagArr && !!taskFlagArr.length) {
getProcessInstance().then((taskRes) => {
if (!_.isEmpty(taskRes)) {
setTaskData(taskRes);
} else {
setTaskData({});
}
});
}
handleInit(data || []);
} else {
setCompList([]);
}
})
.catch(() => {
setCompList([]);
});
}, [appCode, customCode]);
return (
<>
{compList && compList.length > 0 ? (
<div
className={
'qx-chart-view app-view-cont qx-page__content reset-scroll-top'
}
style={{
height: '100%',
backgroundColor: '#f9f9f9',
}}
>
<ResponsiveGridLayout
className="qx-chart-view_layout"
// layouts={layouts}
breakpoints={{ lg: 1200 }}
cols={{ lg: 24 }}
rowHeight={10}
>
{compList.map((item, index) => {
return (
<div key={item.code} data-grid={layouts.lg[index]}>
<ItemComponent
component={item}
appCode={appCode}
customCode={customCode}
taskData={taskData}
/>
</div>
);
})}
</ResponsiveGridLayout>
</div>
) : (
<div
className={'qx-chart-view app-view-cont'}
style={{ height: '100%', backgroundColor: '#fff' }}
>
<Empty
image={require('/public/img/no_page.png')}
style={{
height: '100%',
paddingTop: '35.2vh',
paddingBottom: '35.2vh',
margin: '0',
backgroundColor: '#fff',
}}
imageStyle={{
height: 90,
}}
description={
<span style={{ fontSize: '14px', color: '#999' }}>
很抱歉,暂时没有内容,看看别的呢
</span>
}
/>
</div>
)}
</>
);
};
export default CustomList;