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