PageSourceSearch

https://www.dianxiaomi.com/static/js/common/comTextarea.js?v=jn108.80

js dianxiaomi.com collected 2026-09-24 21:39:50 UTC 14,600 bytes, 258 lines download raw bytes

1/***
2 <%--文本域搜索--%>
3 <script src="<%=basePath%>/static/js/common/comTextarea.js?v=<%=componentsVersionNum%>"></script>
4 <link rel="stylesheet" href="<%=basePath%>/static/css/stylesheet/comTextarea.css?v=<%=componentsVersionNum%>" />
5 *
6 * 调用方式:MULTI_SEARCH.init(showArr, isAll,option); // 引入textarea,showArr=数组,需要展示多个搜索节点的搜索类型;isAll=all,如果等于all则当前所以搜索类型都展示多个搜索按钮;option则为初始化注册选项,可选填
7 * 1、在需要注册页面中的搜索input输入框添加class batchSearchType,外层的tr/div加class searchTr
8 * 注意searchTr必须添加在和搜索类型外层节点平级,因为要通过searchTr节点找到上一个兄弟节点,在找这个兄弟节点下的搜索类型子节点
9 * 注意boxClassName为searchTr类名节点上的id字符串名称,用来解决一个页面多个搜索注册导致冲突的问题,如果一个页面只用了一次这个插件,可以不用传,但是如果有多个的话需要传入参数到option里面:参数可参考:{boxClassName: '#listSearchTr'}
10 *
11 * 2、在切换搜索类型的方法中要调用 MULTI_SEARCH.closeText()方法,用来确认当前切换的搜索类型是否需要展示多个搜索按钮
12 *
13 * 3、如遮挡了精确模糊搜索下拉框 在select上添加自定义属性 uid="productSearchType"
14 * (由于个别布局会使icon位置偏离,在注册时自行修改位置即可 常出现的情况eq: $('.openSearchIcon').css('left','') || $('.openSearchIcon').addClass('left15');;)
15 ***/
16
17
18var MULTI_SEARCH = (function($,W,D){
19    var //searchInitType = false, //注册状态
20        TextareaStr = {
21            openSearchIcon : '<span class="open-search-icon openSearchIcon" title="点此展开,支持多个搜索">',
22            closeSearchIcon : '<span class="close-search-icon closeSearchIcon" title="点此收è
22µ·">',
23            textareaHtml : '<textarea class="textarea-search textareaSearch" placeholder="多个搜索请用回车换行(无需逗号结尾)"></textarea>'
24        },
25        spaceWrap = false, // 多个搜索词是否支持空格隔开
26        chineseComma = false, // 中文逗号隔开
27        commIsAll = '', //保存是否全部支持展示多个搜索按钮,如果等于all则是
28        boxClassName = null, //放在searchTr节点上的id字符串名称,用来解决一个页面多个搜索注册导致冲突的问题
29        commShowArr = []; //保存支持展示多个搜索按钮的搜索类型文案
30        // NoShowArr = ['标题', '全球产品标题','供货商','商品名称','异常处理号','规则名称','产品标题','物流商单号','买家账号','收件人','1688商品名称','货架位','任务编号','循环计划','入库编号','异常处理单号','关联营销名称', '库存商品名称', '货品名称','备注']; //请勿自行添加
31
32    $(D).off('click', '.openSearchIcon')
33        .on('click', '.openSearchIcon', function(){
34            updateBoxClassName(this);
35            MULTI_SEARCH.openText(); // 打开文本域
36        });
37
38    $(D).off('click', '.closeSearchIcon')
39        .on('click', '.closeSearchIcon', function(){
40            updateBoxClassName(this);
41            MULTI_SEARCH.closeText(); // 取消文本域
42        });
43
44    $(D).off('blur', '.textareaSearch')
45        .on('blur', '.textareaSearch', function(){
46            updateBoxClassName(this);
47            acquireVal(); // 失去焦点事件
48        });
49
50    //点击其他位置多个搜索消失
51    // D.onmouseup = function (e) {
52    //     if(searchInitType){
53    //         if($(e.target).hasClass('textareaSearch') || $(e.target).closest('.btnsss').length || $(e.target).hasClass('openSearchIcon')) return;
54    //         MULTI_SEARCH.closeText();
55    //     }
56    // };
57
58    //textarea失去焦点
59    var acquireVal = function () {
60        var textareaVal = boxClassName ? $(boxClassName).find('.textareaSearch').val() : $('.textareaSearch').val(),
61            $classSearchType = boxClassName ? $(boxClassName).find('.batchSearchType') : $('.batchSearchType'),
62            $idSearchType = $("#batchSearchType");
63        if(textareaVal.indexOf(',\n') !== -1){
64            textareaVal = textareaVal.replace(/,\n/g,',');
65        }
66        if(textareaVal.indexOf('\n') !== -1){
67            textareaVal = textareaVal.replace(/\n/g,',');
68        }
69        textareaVal = textareaVal.replace(/,+/g,',');
70        if($classSearchType.length){
71            $classSearchType.val(textareaVal);
72        }else{
73            $idSearchType.val(textareaVal);
74        }
75    };
76
77    //更新外部节点类名
78    var updateBoxClassName = function (obj) {
79        if (boxClassName && $(obj).closest('.searchTr').attr('id')) {
80            boxClassName = '#' + $(obj).closest('.searchTr').attr('id');
81        } else {
82            boxClassName = null;
83        }
84    };
85
86    return{
87        /**
88         * 注册多选搜索插件
89         * showArr : 默认 [], 当前切换的搜索类型显示多个搜索,如果不传默认所有搜索类型都展示多个搜索 ['SKU', '产品Id', ...]
90         * isAll: 默认为空,是否全部搜索类型都展示多个搜索按钮,如果等于all则是全部 ('all')
91         * option: 初始化注册选项
92         *      @option.spaceWrap: 默认false, 是否支持空格隔开 Boolean
93         *      @option.chineseComma: 默认false, 是否支持中文逗号隔开 Boolean
94         *      @option.placeholder: 默认(多个搜索请用回车换行(无需逗号结尾)), 文本域为空的提示文字
95         *      @option.boxClassName: 默认为空, 页面多处使用此插件时需要都传入此参数,用于区分 String (需要在.searchTr节点上加一个id用于区分不同的组件)
96        * */
97        init: function(showArr, isAll, option){
98            boxClassName = (option && option.boxClassName) ? option.boxClassName : null;
99            var $batchSearchType = boxClassName ? $(boxClassName).find('.batchSearchType') : $('.batchSearchType'),
100                $tr = $batchSearchType.closest('.searchTr'),
101                $myjActive = $tr.prev().find('.myj-active:visible'),
102                $tabActive = $tr.prev().find('.tab-active:visible'),
103                $inActive = $tr.prev().find('.in-active:visible'),
104                $selectActive = $tr.prev().find('option:selected'),
105                $active,
106                text;
107
108            if($myjActive.length){
109                $active = $myjActive;
110            }else if($tabActive.length){
111                $active = $tabActive;
112            }else if ($inActive.length) {
113                $active = $inActive;
114            } else {
115                $active = $selectActive;
116            }
117
118            text = $.trim($active.text());
119            $batchSearchType.parent().addClass('relative');
120            if (!$batchSearchType.next('.openSearchIcon').length) $batchSearchType.after(TextareaStr.openSearchIcon);//如果节点不存在才插入
121            if (!showArr) showArr = [];
122            commShowArr = showArr;
123            commIsAll = isAll;
124
125            var $openSearchIcon = boxClassName ? $(boxClassName).find('.openSearchIcon') : $('.openSearchIcon');
126            if (commIsAll === 'all') { //如果等于all则把多个搜索显示
127                $batchSearchType.addClass('p-left30');
128                $openSearchIcon.removeClass('hide');
129            } else if (commShowArr.length && commShowArr.indexOf(text) !== -1){
130                //如果数组有值且存在,则显示多个搜索
131                $batchSearchType.addClass('p-left30');
132                $openSearchIcon.removeClass('hide');
133            } else { //如果没传isAll,text也不在commShowArr数组当中,则当前的搜索类型不展示多个搜索
134                $batchSearchType.removeClass('p-left30');
135                $openSearchIcon.addClass('hide');
136            }
137
138            //设置状态
139            // searchInitType = true;
140
141            // 空格隔开
142            spaceWrap = option && !!option.spaceWrap;
143            // 中文逗号隔开
144            chineseComma = option && !!option.chineseComma;
145            // 默认placeholder
146            if (option && (option.placeholder || option.placeholder === '')) {
147                TextareaStr.textareaHtml = '<textarea class="textarea-search textareaSearch" placeholder="' + option.placeholder + '"></textarea>';
148            }
149        },
150        // 设置文本域提示文字 text:提示文字 isShow是否打开文本域
151        setPlaceholder: function(text, isShow) {
152            var $closeSearchIcon = boxClassName ? $(boxClassName).find('.closeSearchIcon') : $('.closeSearchIcon');
153            if(!$closeSearchIcon.length) { //如果节点不存在
154                TextareaStr.textareaHtml = '<textarea class="textarea-search textareaSearch" placeholder="' + text + '"></textarea>';
155            } else {
156                boxClassName ? $(boxClassName).find('.textareaSearch').attr('placeholder', text) : $('.textareaSearch').attr('placeholder', text);
157            }
158            if (!!isShow)MULTI_SEARCH.openText(); // 打开文本域;
159        },
160        // 设置是否支持空格隔开 hasSpaceWrap:Boolean  isShow:是否打开文本域
161        setSpaceWrap: function(hasSpaceWrap, isShow) {
162            spaceWrap = !!hasSpaceWrap;
163            if (!!isShow)MULTI_SEARCH.openText(); // 打开文本域;
164        },
165        // 打开文本域
166        openText : function () {
167            var $batchSearchType =  boxClassName ? $(boxClassName).find('.batchSearchType') : $('.batchSearchType'),
168                $openSearchIcon = boxClassName ? $(boxClassName).find('.openSearchIcon') : $('.openSearchIcon'),
169                $closeSearchIcon = boxClassName ? $(boxClassName).find('.closeSearchIcon') : $('.closeSearchIcon'),
170                $textareaSearch = boxClassName ? $(boxClassName).find('.textareaSearch') : $('.textareaSearch'),
171                regRules = chineseComma ? /[,,]/g :  /,/g,
172                val = $batchSearchType.val().replace(regRules, '\n'),
173                $select = $openSearchIcon.parent().find('select[uid="productSearchType"]'),
174                createWidth = +$batchSearchType[0].offsetWidth,
175                selectWidth = $select.length ? +$select[0].offsetWidth : 0,
176                positionLeft = $batchSearchType[0].offsetLeft,
177                positionTop = $batchSearchType[0].offsetTop;
178            if (spaceWrap) {
179                val = val.replace(/\s+/g, '\n');
180            }
181            if(!$closeSearchIcon.length){ //如果节点不存在
182                $openSearchIcon.after(TextareaStr.textareaHtml); //插入文本域
183                $openSearchIcon.after(TextareaStr.closeSearchIcon); //插入关闭搜索按钮节点
184                $textareaSearch = boxClassName ? $(boxClassName).find('.textareaSearch') : $('.textareaSearch'); //重新赋值文本域节点
185                $textareaSearch.css({
186                    'top': positionTop + 'px',
187                    'left': positionLeft + 'px'
188                }).val(val);
189                $closeSearchIcon.css({
190                    'top': (positionTop + 7) + 'px',
191                    'left': (positionLeft + 8) + 'px'
192                });
193            }else{
194                $closeSearchIcon.removeClass('hide');
195                $textareaSearch.removeClass('hide').val(val);
196            }
197            if($select.length && $select.is(':visible')){
198                $textareaSearch.css('width', createWidth - selectWidth);
199            }else{
200                $textareaSearch.css('width', createWidth);
201            }
202            $openSearchIcon.addClass('hide');
203        },
204         // 取消文本域
205         closeText : function () {
206             var $batchSearchType = boxClassName ? $(boxClassName).find('.batchSearchType') : $('.batchSearchType'),
207                 $closeSearchIcon = boxClassName ? $(boxClassName).find('.closeSearchIcon') : $('.closeSearchIcon'),
208                 $openSearchIcon = boxClassName ? $(boxClassName).find('.openSearchIcon') : $('.openSearchIcon'),
209                 $textareaSearch = boxClassName ? $(boxClassName).find('.textareaSearch') : $('.textareaSearch'),
210                 $tr = $batchSearchType.closest('.searchTr'),
211                 $myjActive = $tr.prev().find('.myj-active:visible'),
212                 $tabActive = $tr.prev().find('.tab-active:visible'),
213                 $inActive = $tr.prev().find('.in-active:visible'),
214                 $selectActive = $tr.prev().find('option:selected'),
215                 $active,
216                 text;
217
218             if($myjActive.length){
219                 $active = $myjActive;
220             }else if($tabActive.length){
221                 $active = $tabActive;
222             } else if ($inActive.length) {
223                 $active = $inActive;
224             } else {
225                 $active = $selectActive;
226             }
227             text = $.trim($active.text());
228             $textareaSearch.addClass('hide');
229             $closeSearchIcon.addClass('hide');
230
231             if (commIsAll === 'all') { //如果等于all则把多个搜索显示
232                 $batchSearchType.addClass('p-left30');
233                 $openSearchIcon.removeClass('hide');
234             } else if (commShowArr.length && commShowArr.indexOf(text) !== -1){
235                 //如果数组有值且存在,则显示多个搜索
236                 $batchSearchType.addClass('p-left30');
237                 $openSearchIcon.removeClass('hide');
238             } else { //如果没传isAll,text也不在commShowArr数组当中,则当前的搜索类型不展示多个搜索
239                 $batchSearchType.removeClass('p-left30');
240                 $openSearchIcon.addClass('hide');
241             }
242
243             //设置状态
244             // searchInitType = false;
245         },
246        // 强制隐藏文本域
247        forceCloseText: function () {
248            var $openSearchIcon = boxClassName ? $(boxClassName).find('.openSearchIcon') : $('.openSearchIcon'),
249                $textareaSearch = boxClassName ? $(boxClassName).find('.textareaSearch') : $('.textareaSearch'),
250                $closeSearchIcon = boxClassName ? $(boxClassName).find('.closeSearchIcon') : $('.closeSearchIcon'),
251                $batchSearchType = boxClassName ? $(boxClassName).find('.batchSearchType') : $('.batchSearchType');
252            $textareaSearch.addClass('hide');
253            $closeSearchIcon.addClass('hide');
254            $batchSearchType.removeClass('p-left30');
255            $openSearchIcon.addClass('hide');
256        }
257    }
258})(jQuery,window,document);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.