MenuSearchPopovor.js
5.81 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
/* 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';
import { AutoComplete, Input } from "antd";
import * as commonUtils from "@/utils/utils"; /* 通用方法 */
import * as config from '@/utils/config';
const MenuSearchPopovor = props => {
const { menuPanel, onSetMenuSearchPopoverVisible, onAddPane, app, dispatch, updateMenuPanel } = useMemo(
() => {
return props;
},
[]
);
const popovorRef = useRef(null);
const handleTabClick = useCallback(e => {
const paneKey = new Date().getTime().toString();
const formId = e.sId;
const route = e.sName;
const title = e.sMenuName;
const sModelsType = e.sModelType;
const { sProcName } = e;
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);
}
}
});
}
});
}
return [...commonlyUsedOption, ...options];
}, [menuPanel.panelMenus]);
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 } = option;
if (commonUtils.isNotEmptyObject(data)) {
const { sMenuName, parentMenu, grandParentMenu } = data;
const { sMenuName: sMenuName1 } = parentMenu;
const { sMenuName: sMenuName2 } = grandParentMenu;
const result0 =
sMenuName.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
const result1 =
sMenuName1.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
const result2 =
sMenuName2.toUpperCase().indexOf(inputValue.toUpperCase()) !== -1;
result = result0 || result1 || result2;
}
return result;
}}
onSelect={(_, option) => {
// popovorRef.current.animate([{ width: '250px' }, { width: 0 }], {
// duration: 2000, iterations: 1
// });
handleTabClick(option.data);
onSetMenuSearchPopoverVisible(false);
}}
>
<Input.Search size="large" placeholder="搜索" />
</AutoComplete>
</div>
);
};
export default MenuSearchPopovor;