MenuSearchPopovor.js
8.26 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/* eslint-disable */
import React, { useCallback, useMemo, useRef, useState, useContext } from "react";
import { StarFilled } from "@ant-design/icons";
import * as commonServices from '@/services/services';
import { Modal, message } from 'antd-v4';
import { AutoComplete, Input } from "antd-v4";
import * as commonUtils from "@/utils/utils"; /* 通用方法 */
import config from '@/utils/config';
import * as commonFunc from "@/components/Common/commonFunc";
const MenuSearchPopovor = props => {
const { menuPanel, onSetMenuSearchPopoverVisible, onAddPane, app, dispatch, updateMenuPanel } = useMemo(
() => {
return props;
},
[]
);
const { modelCenter, kpiData } = app;
const popovorRef = useRef(null);
const handleTabClick = useCallback(option => {
const { data, type } = option;
if (type === 1) {
const record = data;
const newsId = record.sId;
const newKey = new Date().getTime().toString();
const route = record.sName;
const title = record.sMenuName;
const pane = {
title, route, formId: newsId, key: newKey, sModelsType: record.sModelType, fromKey: "1", sSrcModelsId: '1',
currentIndex: 0,
};
onAddPane(pane);
return;
} else if (type === 2) {
const record = data;
const newsId = record.sResultModelId;
const newKey = new Date().getTime().toString();
const route = record.sResultModelName;
const title = record.sResultModelMenuName;
const pane = {
title, route, formId: newsId, key: newKey, sModelsType: record.sResultModelType, fromKey: "1",
currentIndex: 0,
};
onAddPane(pane);
return
}
const paneKey = new Date().getTime().toString();
const formId = data.sId;
const route = data.sName;
const title = data.sMenuName;
const sModelsType = data.sModelType;
const { sProcName } = data;
for (const each of app.panes) {
/* 解决导航栏打开页签,Modal不消失问题 */
each.notCurrentPane = true;
}
const pane = {
title,
route,
formId,
key: paneKey,
sModelsType,
sProcName,
notCurrentPane: false
};
onAddPane(pane);
});
function getAddParameter(value, url) {
/* 增加常用操作 */
dispatch({ type: 'app/getAddParameter', payload: { value, url } });
}
function getDelParameter(value, url) {
/* 删除常用操作 */
dispatch({ type: 'app/getDelParameter', payload: { value, url } });
}
const handleStarClick = useCallback(async (e, data) => {
e.stopPropagation();
const { sId, sName, sMenuName, iCommonlyUsed } = data;
const value = { sFormId: sId, sFormUrl: sName, sFormName: sMenuName };
const { token } = props.app;
if (iCommonlyUsed === '0') {
const addUrl = `${config.server_host}parameter/addParameter?sModelsId=${sId}`;
getAddParameter(value, addUrl)
} else {
const delUrl = `${config.server_host}parameter/deleteParameter?sModelsId=${sId}`;
getDelParameter(value, delUrl)
}
onSetMenuSearchPopoverVisible(false)
// todo更新数据,重新渲染
setTimeout(() => {
const url = `${config.server_host}business/getBuMenu?sModelsId=100`;
dispatch({ type: 'menuPanel/getMenuPanel', payload: { url } });
}, 300);
});
const handleGetSearchInputOption = useCallback(() => {
const renderTitle = (title, title1) => (
<span>
{title1}
<span
style={{
float: "right"
}}
>
{title}
</span>
</span>
);
const renderItem = (title, data, bStar) => ({
value: title,
data: data,
label: (
<div
style={
{
display: "flex",
justifyContent: "space-between"
}
}
>
{title}
{
<span>
<StarFilled
style={{ color: bStar ? "#f6c136" : "#E6E6E6" }}
onClick={(event) => handleStarClick(event, data)}
/>
</span>
}
</div>
)
});
const options = [];
const commonlyUsedOption = [];
if (menuPanel.panelMenus) {
menuPanel.panelMenus.forEach(item => {
if (commonUtils.isNotEmptyArr(item.children)) {
item.children.forEach(item1 => {
if (commonUtils.isNotEmptyArr(item1.children)) {
const label = renderTitle(item.sMenuName, item1.sMenuName);
const temp = { label, options: [] };
const temp1 = { label, options: [] };
item1.children.forEach(item2 => {
const value = {
...item2,
parentMenu: item1,
grandParentMenu: item
};
if (item2.iCommonlyUsed === "1") {
temp1.options.push(renderItem(item2.sMenuName, value, true));
} else {
temp.options.push(renderItem(item2.sMenuName, value));
}
});
if (commonUtils.isNotEmptyArr(temp.options)) {
options.push(temp);
}
if (commonUtils.isNotEmptyArr(temp1.options)) {
commonlyUsedOption.push(temp1);
}
}
});
}
});
}
const columnWorkMatters = commonFunc.showMessage(app.commonConst, 'columnWorkMatters');
const columnContent = commonFunc.showMessage(app.commonConst, 'columnContent');
const { model = {} } = kpiData || modelCenter || {};
const modelOptions = [{ label: renderTitle('', columnWorkMatters), options: [] }, { label: renderTitle('', columnContent), options: [] }];
Object.keys(model).filter((_, index) => index === 0).forEach(key => {
const value = model[key];
value.forEach(item => {
const { sId, sMenuUnMemo, sResultModelId, sMenuWorkFruit } = item;
modelOptions[0].options.push({
label: sMenuUnMemo,
value: sId,
data: item,
type: 1
});
modelOptions[1].options.push({
label: sMenuWorkFruit,
value: `${sId},${sResultModelId}`,
data: item,
type: 2
});
});
});
return [...commonlyUsedOption, ...options, ...modelOptions];
}, [menuPanel.panelMenus]);
const searchTitle = commonFunc.showMessage(app.commonConst, 'btnSearch') || '搜索';
return (
<div ref={popovorRef}>
<AutoComplete
style={{ width: 250 }}
popupClassName="certain-category-search-dropdown"
options={handleGetSearchInputOption()}
autoFocus
defaultOpen
onBlur={() => {
onSetMenuSearchPopoverVisible(false);
}}
filterOption={(inputValue, option) => {
let result = false;
const { data, value } = option;
if (commonUtils.isNotEmptyObject(data)) {
const { sMenuName, parentMenu = {}, grandParentMenu = {}, sMenuUnMemo, sMenuWorkFruit } = data;
const { sMenuName: sMenuName1 } = parentMenu;
const { sMenuName: sMenuName2 } = grandParentMenu;
const bMenuWorkFruit = value.includes(',');
const result0 =
sMenuName && sMenuName.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
const result1 =
sMenuName1 && sMenuName1.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
const result2 =
sMenuName2 && sMenuName2.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
const result3 =
!bMenuWorkFruit && sMenuUnMemo && sMenuUnMemo.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
const result4 =
bMenuWorkFruit && sMenuWorkFruit && sMenuWorkFruit.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
result = result0 || result1 || result2 || result3 || result4;
}
return result;
}}
onSelect={(_, option) => {
// popovorRef.current.animate([{ width: '250px' }, { width: 0 }], {
// duration: 2000, iterations: 1
// });
handleTabClick(option);
onSetMenuSearchPopoverVisible(false);
}}
>
<Input.Search size="large" placeholder={searchTitle} />
</AutoComplete>
</div>
);
};
export default MenuSearchPopovor;