1 | import "core-js/modules/es6.function.name";
|
2 | import _extends from "@babel/runtime/helpers/extends";
|
3 | import "core-js/modules/es6.object.assign";
|
4 | import "core-js/modules/es6.regexp.match";
|
5 |
|
6 |
|
7 | import React from 'react';
|
8 | import ToolTip from '@beisen-platform/tool-tip';
|
9 | import Loading from '@beisen-platform/loading';
|
10 | import Tree from '@beisen-platform/tree';
|
11 | import { decode } from '@beisen-platform/common-func';
|
12 | import { addResizeListener, removeResizeListener } from './resize-event';
|
13 | export function getBtnData(bsStyle, bsSize, title, func) {
|
14 | var ret = {
|
15 | bsStyle: bsStyle || 'default',
|
16 | bsSize: bsSize || 'default',
|
17 | active: true,
|
18 | title: title || '确认',
|
19 | onClick: func || function (val) {}
|
20 | };
|
21 | return ret;
|
22 | }
|
23 | export function getSearchData(searchValue, active, placeholder) {
|
24 | var ret = {
|
25 | "placeholder": "请搜索"
|
26 |
|
27 | ,
|
28 | "value": searchValue || ''
|
29 | ,
|
30 | "active": active ? active : false
|
31 | ,
|
32 | "hidden": false
|
33 | ,
|
34 | "readonly": false
|
35 | ,
|
36 | "disabled": false
|
37 | ,
|
38 | useInputPlaceHolder: placeholder,
|
39 | "onClick": function onClick(val) {},
|
40 | "onBlur": function onBlur(val) {},
|
41 | "onFocus": function onFocus(val) {}
|
42 | };
|
43 | return ret;
|
44 | }
|
45 | export function getCommonInputData(isActive, placeholder, _defaultValue, disabled, errorStatus, errorMsg, resultsData, _itemClose, onChange, addClass, removeClass) {
|
46 | var ret = {
|
47 | "status": "show",
|
48 | "isActive": isActive
|
49 | ,
|
50 | "placeHolder": placeholder
|
51 | ,
|
52 | "defaultValue": _defaultValue
|
53 | ,
|
54 | "readonly": disabled || ''
|
55 | ,
|
56 | "errorStatus": errorStatus
|
57 | ,
|
58 | "errorMsg": errorMsg
|
59 | ,
|
60 | "selectDate": resultsData,
|
61 | 'istips': false,
|
62 | 'hasInput': true
|
63 | ,
|
64 | handlerClick: function handlerClick() {},
|
65 | itemClose: function itemClose(event, item, index) {
|
66 | _itemClose(event, item, index);
|
67 | }
|
68 | ,
|
69 | inputChange: function inputChange(event, status, value) {
|
70 | onChange(event);
|
71 | }
|
72 | ,
|
73 | inputClick: function inputClick(event, status, value) {
|
74 | addClass(event);
|
75 | }
|
76 | ,
|
77 | inputBlur: function inputBlur(event, status, value) {
|
78 | removeClass(event);
|
79 | }
|
80 |
|
81 | };
|
82 | return ret;
|
83 | }
|
84 | export function getSysVersion() {
|
85 |
|
86 | var Sys = {};
|
87 | var ua = navigator.userAgent.toLowerCase();
|
88 | var s;
|
89 | (s = ua.match(/rv:([\d.]+)\) like gecko/)) ? Sys.ie = s[1] : (s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] : (s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] : (s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] : (s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] : (s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
|
90 |
|
91 | return Sys;
|
92 | }
|
93 | export function getElByClass(classN) {
|
94 | return document.getElementsByClassName(classN)[0];
|
95 | }
|
96 | export function setMaskStyle() {
|
97 | var mask = getElByClass('AutoTree-mask');
|
98 |
|
99 | if (mask != undefined) {
|
100 | mask.style.height = window.innerHeight + 'px';
|
101 | mask.style.width = window.innerWidth + 'px';
|
102 | }
|
103 | }
|
104 | export function setRealNode(event) {
|
105 | var node = event.target;
|
106 | var toLowerCase = node.tagName.toLowerCase();
|
107 | if (toLowerCase !== 'li' && toLowerCase !== 'span' && toLowerCase !== 'em' && node.className !== 'autoTree_ItemName' && node.className !== 'autoTree_ParentName') return;
|
108 |
|
109 | if (toLowerCase == 'span' || toLowerCase == 'em') {
|
110 | node = node.parentNode;
|
111 | }
|
112 |
|
113 | if (node.className == 'autoTree_ParentName') node = node.previousSibling;
|
114 | if (node.className == 'auto-tree__item ') node = node.firstChild;
|
115 | var nodeId = node.getAttribute('data-index');
|
116 | if (nodeId == null) node = node.parentNode;
|
117 | return node;
|
118 | }
|
119 | export function renderTree(self, temp, offset, treeItemClick, ul_Content, itemClick, searchChange, searchCom, showPanel) {
|
120 | var _self$props = self.props,
|
121 | treeData = _self$props.treeData,
|
122 | autoTreeData = _self$props.autoTreeData,
|
123 | isFetching = _self$props.isFetching,
|
124 | componentId = _self$props.componentId,
|
125 | showDropDown = _self$props.showDropDown;
|
126 | var _self$state = self.state,
|
127 | inputValue = _self$state.inputValue,
|
128 | isFocus = _self$state.isFocus,
|
129 | searchValue = _self$state.searchValue;
|
130 | var _tar = self.refs.autoForm_ref.refs.autoTreeInput;
|
131 | var autoTreeSum = autoTreeData ? autoTreeData : [];
|
132 | var assignTreeData = Object.assign({}, treeData, {
|
133 | style: {
|
134 | "height": "315px"
|
135 | }
|
136 | });
|
137 | var AutoDom = isFetching ? React.createElement("div", {
|
138 | style: {
|
139 | "maxHeight": '310px',
|
140 | 'overflowY': 'scroll',
|
141 | backgroundColor: "#FFF",
|
142 | height: '310px'
|
143 | }
|
144 | }, React.createElement(Loading, {
|
145 | type: "small"
|
146 | })) : searchChange ? (inputValue.length > 0 || searchValue.length > 0) && autoTreeSum.length > 0 ? React.createElement("div", null, showPanel ? React.createElement("div", {
|
147 | className: "auto-result-container-search"
|
148 | }, React.createElement("ul", {
|
149 | className: "auto-result",
|
150 | onClick: itemClick
|
151 | }, ul_Content)) : '', searchCom) : (inputValue.length > 0 || searchValue.length > 0) && autoTreeSum.length == 0 ? React.createElement("div", {
|
152 | className: "empty-con error_page"
|
153 | }) : React.createElement("div", null, showPanel ? React.createElement(Tree, _extends({}, assignTreeData, {
|
154 | onClick: treeItemClick
|
155 | })) : '', searchCom) : React.createElement("div", null, showPanel ? React.createElement(Tree, _extends({}, assignTreeData, {
|
156 | onClick: treeItemClick
|
157 | })) : '', searchCom);
|
158 | var treeLength = treeData.treeData ? treeData.treeData.length : 0;
|
159 | var treeDOM = document.getElementsByClassName('base-tree-component')[0];
|
160 | var treeHeight = showDropDown ? 361 : 310;
|
161 | var height = isFetching ? 310 : treeHeight;
|
162 | if (!showPanel && showDropDown) height = 51;
|
163 |
|
164 | self.CommonMount.renderDom('autotree__tree-panel',
|
165 | AutoDom,
|
166 | _tar,
|
167 | [_tar,
|
168 | {
|
169 |
|
170 | width: 340,
|
171 |
|
172 | height: height
|
173 | }], false,
|
174 | 0,
|
175 | false,
|
176 | 100
|
177 | , 30);
|
178 | }
|
179 | export function renderAutoUl(self, temp, offset) {
|
180 | var _self$state2 = self.state,
|
181 | isFocus = _self$state2.isFocus,
|
182 | inputValue = _self$state2.inputValue,
|
183 | isShow = _self$state2.isShow,
|
184 | showTree = _self$state2.showTree,
|
185 | style = _self$state2.style,
|
186 | status = _self$state2.status,
|
187 | autoTreeItems = _self$state2.autoTreeItems,
|
188 | hasClick = _self$state2.hasClick,
|
189 | single = _self$state2.single;
|
190 | var _self$props2 = self.props,
|
191 | autoTreeData = _self$props2.autoTreeData,
|
192 | sync = _self$props2.sync,
|
193 | componentId = _self$props2.componentId,
|
194 | isFetching = _self$props2.isFetching;
|
195 | if (!isFocus && showTree == false) self['domState' + componentId] = false;
|
196 | var autoResultHeight, tempPadding, showAutoUl, findAllText, ulChild, tempStyle, ulStyle, autoLi, li_ItemHeight, tempPopStyle, findAll_style;
|
197 | autoResultHeight = setResult_Height(autoTreeItems, inputValue, isFocus, hasClick, autoTreeData, sync, componentId);
|
198 | autoLi = self.returnAutoLi(true);
|
199 |
|
200 | if (status == 'edit') {
|
201 | ulChild = autoLi.length == 0 && inputValue.length >= 0 ? React.createElement("div", {
|
202 | className: "findNothing empty-con"
|
203 | }) : autoLi;
|
204 | tempStyle = inputValue.length == 0 && autoLi.length == 0 ? '' : React.createElement("div", {
|
205 | className: "findAll",
|
206 | onClick: self.findAll,
|
207 | style: {
|
208 | 'position': 'absolute',
|
209 | 'bottom': '0',
|
210 | 'right': '15px'
|
211 | }
|
212 | }, React.createElement("label", null, "\u5168\u90E8\u67E5\u627E"));
|
213 | ulStyle = tempStyle == '' ? {
|
214 | 'padding': '0 0 0 0'
|
215 | } : {
|
216 | 'maxHeight': '280px'
|
217 | };
|
218 |
|
219 | if (tempStyle == '') {
|
220 | ulStyle = {
|
221 | 'padding': '0 0 0 0'
|
222 | };
|
223 | } else if (self.renderParents_Node) {
|
224 | ulStyle = {
|
225 | 'maxHeight': '280px'
|
226 | };
|
227 | } else {
|
228 | ulStyle = {
|
229 | 'maxHeight': '250px'
|
230 | };
|
231 | }
|
232 |
|
233 | findAll_style = self.renderParents_Node ? {} : {
|
234 | 'bottom': '50px'
|
235 | };
|
236 | findAllText = inputValue.length >= 0 && autoLi.length == 0 && isFocus == true ? React.createElement("div", {
|
237 | style: findAll_style,
|
238 | className: "findAll-null"
|
239 | }, React.createElement("label", {
|
240 | onClick: self.findAll
|
241 | }, "\u201C\u67E5\u627E\u5168\u90E8\u201D")) : tempStyle;
|
242 | showAutoUl = isShow ? React.createElement("ul", {
|
243 | className: "auto-result",
|
244 | style: ulStyle,
|
245 | onClick: self.itemClick
|
246 | }, ulChild) : '';
|
247 | }
|
248 |
|
249 |
|
250 | li_ItemHeight = self.renderParents_Node ? '280px' : '250px';
|
251 | tempPadding = isShow ? '44px' : '0';
|
252 | tempPopStyle = autoLi.length > 0 ? {
|
253 | 'maxHeight': li_ItemHeight,
|
254 | 'paddingBottom': tempPadding,
|
255 | 'lineHeight': '34px'
|
256 | } : {
|
257 | 'maxHeight': '280px'
|
258 | };
|
259 |
|
260 | var _tar;
|
261 |
|
262 | if (status == 'search' && single) {
|
263 | _tar = getElByClass('autoTree-search-input');
|
264 | } else if (status == 'edit' && !single) {
|
265 | _tar = self.refs.autoForm_ref.refs.autoTree_commonInput;
|
266 | } else if (status == 'edit' && single) {
|
267 | _tar = self.refs.autoForm_ref.refs.autoTreeInput;
|
268 | }
|
269 |
|
270 | var tempFecthing = isFetching ? React.createElement("div", {
|
271 | style: {
|
272 | "maxHeight": '250px',
|
273 | 'overflowY': 'scroll',
|
274 | backgroundColor: "#FFF",
|
275 | height: '200px'
|
276 | }
|
277 | }, React.createElement(Loading, {
|
278 | type: "small"
|
279 | })) : React.createElement("div", {
|
280 | style: {
|
281 | width: _tar.clientWidth
|
282 | }
|
283 | }, showAutoUl, isShow ? findAllText : '');
|
284 | var AutoDom = status == 'edit' ? React.createElement("div", {
|
285 | className: status == 'edit' ? 'auto-result-container' : 'auto-result-container-search',
|
286 | style: tempPopStyle
|
287 | }, tempFecthing) : '';
|
288 |
|
289 | if (!showTree) {
|
290 | self.CommonMount.renderDom('mount-box',
|
291 | AutoDom,
|
292 | _tar,
|
293 | [_tar,
|
294 | {
|
295 |
|
296 | width: _tar.clientWidth,
|
297 |
|
298 | height: autoResultHeight
|
299 | }]);
|
300 | }
|
301 |
|
302 | resetPosition(status, showTree, inputValue, autoTreeItems, componentId, autoTreeData, sync);
|
303 | }
|
304 |
|
305 | export function setResult_Height(autoTreeItems, inputValue, isFocus, hasClick, autoTreeData, sync, componentId) {
|
306 | var autoResultHeight;
|
307 | var sessionData = JSON.parse(sessionStorage.getItem('search' + componentId));
|
308 | var dataResult = sync ? autoTreeItems : autoTreeData;
|
309 | var tempBool = (dataResult == undefined || dataResult.length == 0) && isFocus == true && sessionData != null && sessionData.length > 0 && hasClick == true || inputValue == '' && isFocus == true && sessionData != null && sessionData.length > 0 && hasClick == false;
|
310 |
|
311 |
|
312 | var tempResult = dataResult != undefined ? tempBool ? sessionData : dataResult : sessionData;
|
313 | var maxLength, itemHeight;
|
314 |
|
315 | if (tempResult.length > 0) {
|
316 | maxLength = tempResult[0].pname ? 5 : 8;
|
317 | itemHeight = tempResult[0].pname ? 54 : 30;
|
318 | }
|
319 |
|
320 | if (tempResult.length == 0) {
|
321 | autoResultHeight = 259;
|
322 | } else if (tempResult.length > maxLength) {
|
323 | autoResultHeight = tempResult[0].pname ? 320 : 290;
|
324 | } else {
|
325 | autoResultHeight = tempResult.length * itemHeight + 56;
|
326 | }
|
327 |
|
328 |
|
329 | return autoResultHeight;
|
330 | }
|
331 |
|
332 | export function resetPosition(status, showTree, inputValue, autoTreeItems, componentId, autoTreeData, sync) {
|
333 | var windowH = window.innerHeight;
|
334 | var windowW = window.innerWidth;
|
335 | var popAutoResult = getElByClass('pop-auto-result');
|
336 |
|
337 | var searchContainer = getElByClass('searchContainer');
|
338 | var autoResultContainer = getElByClass('auto-result-container');
|
339 |
|
340 | if (status == 'edit' && autoResultContainer != undefined && searchContainer != undefined) {
|
341 | autoResultContainer.style.left = (windowW - autoResultContainer.offsetWidth) * 0.5 + 'px';
|
342 | autoResultContainer.style.top = (windowH - autoResultContainer.offsetHeight - 50) * 0.5 + 'px';
|
343 | autoResultContainer.display = 'block';
|
344 | } else if (status == 'search' && searchContainer != undefined) {
|
345 | searchContainer.style.left = (windowW - searchContainer.offsetWidth) * 0.5 + 'px';
|
346 | searchContainer.style.top = (windowH - searchContainer.offsetHeight) * 0.5 + 'px';
|
347 | }
|
348 | }
|
349 | export function getSelectedData(func, dropDownData) {
|
350 | var ret = {
|
351 | defaultValue: dropDownData.defaultValue || "本级别及所有下级",
|
352 | inputItems: [{
|
353 | "value": 0,
|
354 | "text": "本级别",
|
355 | "isChecked": true
|
356 | }, {
|
357 | "value": 4,
|
358 | "text": "本级别及所有下级",
|
359 | "isChecked": false
|
360 | }],
|
361 | itemClickCallback: function itemClickCallback(event, target, val) {
|
362 | func(event, target, val);
|
363 | }
|
364 | };
|
365 | return ret;
|
366 | }
|
367 | export function pushLi(autoLi, itemClass, holdon_class, i, id, text, sideTip, hiddenTip, index, beforeText, searchContent, searchText, renderParents_Node, pname, props) {
|
368 | var resultText = index == -1 ? text : React.createElement("span", null, beforeText, searchContent, searchText);
|
369 | var status = props.status,
|
370 | single = props.single;
|
371 |
|
372 | if (status == 'edit' && !single) {
|
373 | autoLi.push(React.createElement("li", {
|
374 | className: itemClass,
|
375 | id: holdon_class,
|
376 | key: i,
|
377 | "data-index": id
|
378 | }, React.createElement("div", {
|
379 | className: "autoTree_ItemName",
|
380 | "data-index": id
|
381 | }, React.createElement(ToolTip, {
|
382 | title: text,
|
383 | side: sideTip,
|
384 | hidden: hiddenTip
|
385 | }, React.createElement("span", {
|
386 | "data-index": id
|
387 | }, resultText))), renderParents_Node == true ? React.createElement("div", {
|
388 | className: "autoTree_ParentName",
|
389 | "data-index": id
|
390 | }, React.createElement(ToolTip, {
|
391 | title: pname ? pname : '-无-',
|
392 | side: sideTip,
|
393 | hidden: hiddenTip
|
394 | }, React.createElement("span", {
|
395 | "data-index": id
|
396 | }, pname ? pname : '-无-'))) : ''));
|
397 | } else {
|
398 | autoLi.push(React.createElement("li", {
|
399 | className: itemClass,
|
400 | id: holdon_class,
|
401 | key: i,
|
402 | "data-index": id
|
403 | }, React.createElement("div", {
|
404 | className: "autoTree_ItemName",
|
405 | "data-index": id
|
406 | }, React.createElement(ToolTip, {
|
407 | title: text,
|
408 | side: sideTip,
|
409 | hidden: hiddenTip
|
410 | }, React.createElement("span", {
|
411 | "data-index": id
|
412 | }, resultText)), renderParents_Node == true ? React.createElement(ToolTip, {
|
413 | title: pname ? pname : '-无-',
|
414 | side: sideTip,
|
415 | hidden: hiddenTip
|
416 | }, React.createElement("span", {
|
417 | className: "auto-tree__item-pname",
|
418 | "data-index": id
|
419 | }, '(' + (pname ? pname : '-无-') + ')')) : '')));
|
420 | }
|
421 | }
|
422 | export function getText(index, text, valueLength, autoLi, itemClass, holdon_class, i, sideTip, hiddenTip, renderParents_Node, item, props) {
|
423 | var searchContent, searchText, beforeText;
|
424 |
|
425 | if (index != -1) {
|
426 | beforeText = index == 0 ? '' : text.substring(0, index);
|
427 | var subValue = text.substring(index, index == 0 ? valueLength : valueLength + index);
|
428 | searchContent = React.createElement("em", null, subValue);
|
429 | searchText = text.substring(index == 0 ? valueLength : valueLength + index, text.length);
|
430 | }
|
431 |
|
432 | pushLi(autoLi, itemClass, holdon_class, i, item.id, text, sideTip, hiddenTip, index, beforeText, searchContent, searchText, renderParents_Node, decode(item.pname), props);
|
433 | }
|
434 | export function getHightLightData(holdOn_index, item, value, autoLi, i, renderParents_Node, sideTip, hiddenTip, props) {
|
435 | var text;
|
436 | text = decode(item.name);
|
437 | var itemClass = renderParents_Node ? "auto-tree__item " : "auto-tree__item_notShow ";
|
438 | var holdon_class = i == holdOn_index ? 'li-hold-on' : '';
|
439 |
|
440 | var index = text.indexOf(value);
|
441 | var valueLength = value.length;
|
442 | getText(index, text, valueLength, autoLi, itemClass, holdon_class, i, sideTip, hiddenTip, renderParents_Node, item, props);
|
443 | return autoLi;
|
444 | } |
\ | No newline at end of file |