queryForm.js 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175
  1. //let cookie = require('jquery.cookie');
  2. const query = function getQueryForm(data) {
  3. {
  4. this.el = data.el || '#from_div';
  5. this.form = data.form;
  6. this.method = data.method || 'get';
  7. this.url = data.url || getPathname();
  8. this.condition = data.condition;
  9. this.paginations = [50, 100, 200, 500] || data.paginations;
  10. this.keydownfun = data.keydownfun || undefined;
  11. this.selectChange = data.selectChange || undefined;
  12. this.searchClick = data.searchClick || undefined;
  13. this.selectfun = data.selectfun || undefined;
  14. this._onsubmit = data._onsubmit || true;
  15. this.keydownSearch = data.keydownSearch || true;
  16. this.selectChangeSearch = data.selectChangeSearch || true;
  17. this.tip = data.tip || '';
  18. this.nextPage = nextPage();
  19. this.pervPage = pervPage();
  20. // 提交表单
  21. this.onsubmit = function () {
  22. saveSearchOnCookie();
  23. let form = $("<form method=" + _this.method + " ></form>");
  24. for (const key in _data) {
  25. let map = _data[key];
  26. if (["string", "number"].includes(fetchJsType(map.value)) && map.value !== '') {
  27. form.append("<input name='" + key + "' value='" + map.value + "'>")
  28. } else if ('array' === fetchJsType(map.value)) {
  29. map.value.forEach(function (value) {
  30. form.append("<input type='checkbox' name='" + key + "' value='" + value + "' checked='checked' >");
  31. })
  32. }
  33. }
  34. if (_this.method !== 'get') {
  35. form.append("<input type='hidden' name='_token' value='" + $('meta[name="csrf-token"]').attr('content') + "'>");
  36. form.append("<input type='hidden' name='_method' value='" + _this.method + "'>");
  37. form.attr('action', _this.url);
  38. }
  39. _hidden_div.html('');
  40. _hidden_div.append(form);
  41. form.submit();
  42. }
  43. }
  44. let _this = this;
  45. let _parentNode = null;
  46. let _data = {};
  47. let _form = [];
  48. let _table = null;
  49. let _clearBtn = null;
  50. let _pagination = null;
  51. let _baseData = data;
  52. let _searchBtn = null;
  53. let _hidden_div = null;
  54. let _parentNode_top = null;
  55. let _page = '';
  56. this.init = function () {
  57. _parentNode = $(_this.el);
  58. _form = $("<div ></div>");
  59. _table = $("<table class='table table-sm table-bordered m-0 position-static' style='background: rgb(255, 255, 255);'></table>");
  60. fillTable();
  61. switchData();
  62. addHiedDiv();
  63. rendererSearchForm();
  64. visibleClearBtn();
  65. parentNodeFloat();
  66. inputKeyDown();
  67. selectChange();
  68. createTip();
  69. $('[data-toggle="tooltip"]').tooltip({'trigger': 'hover'})
  70. }
  71. // form fixed
  72. function parentNodeFloat() {
  73. _parentNode_top = _parentNode.offset().top;
  74. let height = _parentNode.height();
  75. window.onscroll = function () {
  76. let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
  77. if (scrollTop > _parentNode_top) {
  78. _form.addClass('fixed-top');
  79. _parentNode.height(height);
  80. } else {
  81. _form.removeClass('fixed-top');
  82. }
  83. }
  84. }
  85. // add hide div (on submit form )
  86. function addHiedDiv() {
  87. _parentNode.append(_form.append(_table));
  88. _hidden_div = $('<div></div>');
  89. _hidden_div.hide();
  90. $("body").append(_hidden_div);
  91. }
  92. // fill table
  93. function fillTable() {
  94. _table.html('');
  95. _table.append(crateClearBtn());
  96. _table.append(createPagination());
  97. _baseData.condition.forEach(function (conditions, index, arrays) {
  98. let tr = $("<tr></tr>");
  99. conditions.forEach(function (condition, index, array) {
  100. let td = $("<td style='width: 260px'></td>");
  101. if ([null, '', undefined].includes(condition.type) && ![null, undefined].includes(condition.name)) {
  102. condition.type = 'input';
  103. }
  104. if (['dataTime_dataTime', 'input_input'].includes(condition.type)) {
  105. td = $("<td style='width: 330px'</td>")
  106. } else if (['select_multiple_select', 'time', 'dataTime_select'].includes(condition.type)) {
  107. td = $("<td style='width: 280px'</td>");
  108. } else if (['time', 'dataTime_select'].includes(condition.type)) {
  109. td = $("<td style='width: 320px'</td>");
  110. }
  111. td.append(createModule(condition));
  112. tr.append(td);
  113. })
  114. _table.append(tr);
  115. if (arrays.length === index + 1) {
  116. let td = $("<td ></td>");
  117. tr.append(td.append(createSearchBt()));
  118. }
  119. })
  120. $.cookie.raw = true;
  121. $.cookie.json = true;
  122. setTableWidth();
  123. }
  124. function setTableWidth() {
  125. let max_width = 0;
  126. _baseData.condition.forEach(function (conditions, xindex, xarrays) {
  127. let _width = 0;
  128. conditions.forEach(function (condition, index, array) {
  129. if (['input', 'select', 'dataTime', 'input_select'].includes(condition.type)) {
  130. _width += 260;
  131. } else if (['dataTime_DataTime', 'input_input'].includes(condition.type)) {
  132. _width += 330;
  133. } else if (['select_multiple_select','search_select'].includes(condition.type)) {
  134. _width += 280;
  135. } else if (['check'].includes(condition.type)) {
  136. _width += 260;
  137. } else if (['time', 'dataTime_select'].includes(condition.type)) {
  138. _width += 320;
  139. } else if ([undefined, null, ''].includes(condition)) {
  140. _width += 260;
  141. }
  142. if (index === array.length - 1 && xindex === xarrays.length - 1) {
  143. _width += 260;
  144. }
  145. if (max_width < _width) {
  146. max_width = _width;
  147. }
  148. })
  149. })
  150. _parentNode.css('min-width', 1920 - 30)
  151. _parentNode.css('max-width', (max_width || window.screen.availWidth) - 30);
  152. _table.css('width', max_width + 'px');
  153. }
  154. // 清空过滤条件按钮
  155. function crateClearBtn() {
  156. let label = $("<label class='col-form-label col-sm-2 p-0'></label>");
  157. _clearBtn = $("<span class='btn btn-warning text-dark invisible'>清除过滤条件</span>");
  158. _clearBtn.click(function () {
  159. clearData();
  160. visibleClearBtn();
  161. })
  162. let tr = $("<tr ><td colspan='10' style='height: 45px'></td></tr>");
  163. tr.find('td').append(label);
  164. label.append(_clearBtn);
  165. return tr;
  166. }
  167. // create SearchBtn
  168. function createSearchBt() {
  169. _searchBtn = $("<span class='btn btn-sm btn-outline-dark ml-1' >按条件搜索</span>");
  170. let div = $("<div class='form-inline'></div>");
  171. div.append(_searchBtn);
  172. _searchBtn.click(function () {
  173. if (controlJsType(_this.searchClick, 'fun')) {
  174. _this.searchClick();
  175. }
  176. if (_this._onsubmit) {
  177. _this.onsubmit();
  178. }
  179. _this.onsubmit();
  180. })
  181. return div;
  182. }
  183. // create _pagination
  184. function createPagination() {
  185. _pagination = $("<select id='paginate' name='paginate' class='form-control form-control-sm' style='vertical-align: middle; max-width: 150px;'></select>");
  186. let tr = $("<tr ><td colspan='10'><div class='col p-0' style='height: 100%'></div></td></tr>");
  187. tr.find('div').append(_pagination);
  188. _this.paginations.forEach(function (map) {
  189. let option = $("<option value='" + map + "'>每页显示" + map + "</option>");
  190. _pagination.append(option);
  191. })
  192. _pagination.change(function () {
  193. let dom = {name: 'paginate', type: 'select', value: _pagination.val(), mold: 'select'};
  194. _data['paginate'] = dom;
  195. modifyData(dom);
  196. _data['paginate'] = dom;
  197. _this.onsubmit();
  198. })
  199. return tr;
  200. }
  201. // create Tip
  202. function createTip() {
  203. let data = fetchCookie();
  204. let search = window.location.search;
  205. if (!data || !search) {
  206. return;
  207. }
  208. let cookies = JSON.parse(data);
  209. if (!cookies['success_tip']) {
  210. return;
  211. }
  212. if (!cookies['success_tip'] && !!_this.tip) {
  213. cookies['success_tip'].value = _this.tip;
  214. cookies['success_tip'].count = 1;
  215. _data['page'].value = _page;
  216. saveCookie(cookies);
  217. set_dataOnCookie();
  218. _this.onsubmit();
  219. // 重定向
  220. } else if (!cookies['success_tip'] && cookies['success_tip'].count === 1) {
  221. let tip = $("<div class='alert alert-success h1'></div>")
  222. let tipdiv = $("<div style='max-width: " + window.screen.availWidth + "px'>" + cookies['success_tip'].value + "</div>").append(tip);
  223. _form.append(tipdiv);
  224. cookies['success_tip'] = '';
  225. saveCookie(cookies);
  226. }
  227. }
  228. // 数据清空
  229. function clearData() {
  230. saveCookie({});
  231. window.location.href = _this.url;
  232. }
  233. // 存cookie
  234. function saveCookie(data) {
  235. $.cookie(getPathname(), data, {expires: 1});
  236. }
  237. // 取cookie
  238. function fetchCookie() {
  239. return $.cookie(getPathname());
  240. }
  241. // 获取路径
  242. function getPathname() {
  243. return window.location.pathname;
  244. }
  245. // 获取js对象类型types.call
  246. function fetchJsType(JsObj) {
  247. let types = Object.prototype.toString;
  248. let obj = types.call(JsObj);
  249. return (obj === "[object Number]" && 'number')
  250. || (obj === "[object Boolean]" && 'boolean')
  251. || (obj === "[object String]" && 'string')
  252. || (obj === "[object Array]" && 'array')
  253. || (obj === "[object Function]" && 'fun')
  254. || (obj === "[object Object]" && 'object')
  255. || (obj === "[object Null]" && 'null')
  256. || (obj === "[object Undefined]" && 'undefined');
  257. }
  258. // 判断js类型
  259. function controlJsType(JsObj, type) {
  260. if (fetchJsType(type) === 'array') {
  261. return type.includes(fetchJsType(JsObj));
  262. } else if (fetchJsType(type) === 'string') {
  263. return fetchJsType(JsObj) === type;
  264. } else {
  265. return JsObj === type;
  266. }
  267. }
  268. // create Module
  269. function createModule(condition) {
  270. let type = condition.type;
  271. return (['input', '', null].includes(type) && getInput(condition))
  272. || (type === "select" && getSelect(condition))
  273. || (type === "search_select" && getSearchSelect(condition))
  274. || (type === "input_select" && getInputSelect(condition))
  275. || (type === "dataTime" && getDataTime(condition))
  276. || (type === "time" && getTime(condition))
  277. || (type === "input_input" && getInputInput(condition))
  278. || (type === "dataTime_dataTime" && getDataTimeDataTime(condition))
  279. || (type === "dataTime_select" && getDataTimeSelect(condition))
  280. || (type === "select_multiple_select" && getSelectMultipleSelect(condition))
  281. || (type === "checkbox" && getCheckBox(condition));
  282. }
  283. // input
  284. function getInput(condition) {
  285. let input = $("<input name='" + condition.name + "' class='form-control form-control-sm' style='vertical-align: middle; max-width: 200px;' placeholder='" + condition.placeholder + "' data-toggle='tooltip' data-placement='top' >");
  286. input.attr('title', condition.tip === undefined ? '' : condition.tip);
  287. input.on('input', function () {
  288. let dom = {name: condition.name, type: 'input', value: this.value, mold: 'input'}
  289. modifyData(dom)
  290. });
  291. return input;
  292. }
  293. // select
  294. function getSelect(condition) {
  295. let select = $("<select name='" + condition.name + "' class='form-control form-control-sm' style='max-width: 200px;' data-toggle='tooltip' data-placement='top'></select>")
  296. select.attr('title', condition.tip === undefined ? '' : condition.tip);
  297. let tip = $("<option value class='text-secondary'>" + condition.placeholder + "</option>")
  298. select.append(tip);
  299. condition.data.forEach(function (map) {
  300. let option = $("<option value='" + map.name + "' class='text-secondary'>" + map.value + "</option>")
  301. select.append(option);
  302. })
  303. select.on('change', function () {
  304. let dom = {name: condition.name, type: 'select', value: this.value, mold: 'select'}
  305. modifyData(dom)
  306. })
  307. return select;
  308. }
  309. // search_select
  310. function getSearchSelect(condition) {
  311. let div = $("<div class='form-inline'></div>");
  312. let input = $("<input class='form-control form-control-sm' placeholder='" + condition.placeholder[0] + "' style='width: 70px;' autocomplete='off' data-toggle='tooltip' data-placement='top'>");
  313. input.attr('title', controlJsType(condition.tip[0], 'undefined') ? '输入关键词快速定位下拉列表,回车确定' : condition.tip[0]);
  314. let select = $("<select class='form-control form-control-sm ml-2' name='" + condition.name + "' style='min-width: 120px;max-width: 150px;' data-toggle='tooltip' data-placement='top' data-toggle='tooltip' data-placement='top'></select>");
  315. select.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  316. let placeholder = '';
  317. if (controlJsType(condition.placeholder, 'array') && !['', undefined, null].includes(condition.placeholder[1])) {
  318. placeholder = condition.placeholder[1];
  319. }
  320. fillSelectOption(select, condition.data, placeholder);
  321. input.bind('input propertychange', function () {
  322. let value = this.value;
  323. let data = condition.data.filter(function (map) {
  324. return map.value.includes(value);
  325. })
  326. fillSelectOption(select, data || condition.data);
  327. select.val(_data[condition.name].select);
  328. })
  329. select.change(function () {
  330. let dom = {name: condition.name, type: 'input_select', value: this.value, mold: 'select'};
  331. modifyData(dom);
  332. })
  333. return div.append(input).append(select);
  334. }
  335. // input_select
  336. function getInputSelect(condition) {
  337. let div = $("<div class='form-inline'></div>");
  338. let input = $("<input class='form-control form-control-sm' name='" + condition.name[0] + "' placeholder='" + condition.placeholder[0] + "' autocomplete='off' style='max-width: 100px;' data-toggle='tooltip' data-placement='top' >");
  339. input.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  340. let select = $("<select class='form-control form-control-sm ml-2' name='" + condition.name[1] + "' style='max-width: 200px;' title='" + condition.tip[1] + "''>");
  341. fillSelectOption(select, condition.data);
  342. input.bind('input propertychange', function () {
  343. let dom = {name: this.name, type: 'input_select_longtext', value: this.value, mold: 'input'};
  344. modifyData(dom);
  345. })
  346. select.change(function () {
  347. let dom = {name: this.name, type: 'input_select_longtext', value: this.value, mold: 'select'};
  348. modifyData(dom);
  349. })
  350. return div.append(input).append(select);
  351. }
  352. // datTime
  353. function getDataTime(condition) {
  354. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='max-width: 200px' data-toggle='tooltip' data-placement='top' title='" + condition.tip + "' style='width: 200px'>");
  355. dataTime.attr('title', controlJsType(condition.tip, 'undefined') ? '' : condition.tip);
  356. dataTime.bind('input propertychange', function () {
  357. let dom = {name: condition.name, type: 'dataTime', value: this.value, mold: 'dataTime'};
  358. modifyData(dom);
  359. })
  360. return dataTime;
  361. }
  362. // time
  363. function getTime(condition) {
  364. let div = $("<div class='form-inline'></div>");
  365. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name + "' style='width:150px' data-toggle='tooltip' data-placement='top' >");
  366. dataTime.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  367. let min = $("<input id='" + condition.name + "_min' class='form-control form-control-sm ml-2' style='max-width: 100px;' placeholder='00:00' data-toggle='tooltip' data-placement='top' >");
  368. min.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  369. dataTime.bind('input propertychange', function () {
  370. let value = this.value !== '' ? this.value + ' ' + ([null, undefined, ''].includes(min.value) ? '00:00' : min.value) : '';
  371. let dom = {name: condition.name, type: 'time', value: value, mold: 'time'};
  372. modifyData(dom);
  373. })
  374. min.bind('input propertychange', function () {
  375. verifyTime(this);
  376. })
  377. min.bind('input propertychange', function () {
  378. if (['null', 'undefined', ''].includes(dataTime.val())) {
  379. return;
  380. }
  381. let value = ['null', 'undefined', ''].includes(dataTime.val()) ? '' : dataTime + ' ' + min.val();
  382. // let value = dataTime.value !== '' ? dataTime.value + ' ' + (min.value === '' ? '00:00' : min. value) : '';
  383. let dom = {name: condition.name, type: 'time', value: value, mold: 'time'};
  384. modifyData(dom);
  385. })
  386. return div.append(dataTime).append(min);
  387. }
  388. // input_input
  389. function getInputInput(condition) {
  390. let div = $("<div class='form-inline'></div>");
  391. let input1 = $("<input name='" + condition.name[0] + "' class='form-control form-control-sm' style='vertical-align: middle; max-width: 150px;' placeholder='" + condition.placeholder[0] + "' data-toggle='tooltip' data-placement='top' title='" + condition.tip[0] + "'>");
  392. input1.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  393. let input2 = $("<input name='" + condition.name[1] + "' class='form-control form-control-sm ml-2' style='vertical-align: middle; max-width: 150px;' placeholder='" + condition.placeholder[1] + "' data-toggle='tooltip' data-placement='top' title='" + condition.tip[1] + "'>");
  394. input2.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  395. input1.bind('input propertychange', function () {
  396. let dom = {name: this.name, type: 'input_input', value: this.value, mold: 'input'};
  397. modifyData(dom);
  398. })
  399. input2.bind('input propertychange', function () {
  400. let dom = {name: this.name, type: 'input_input', value: this.value, mold: 'input'};
  401. modifyData(dom);
  402. })
  403. return div.append(input1).append(input2);
  404. }
  405. // dataTime_dataTime
  406. function getDataTimeDataTime(condition) {
  407. let div = $("<div class='form-inline'></div>");
  408. let dataTime1 = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='width: 150px' data-toggle='tooltip' data-placement='top' >");
  409. dataTime1.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  410. let dataTime2 = $("<input type='date' class='form-control form-control-sm ml-2' name='" + condition.name[1] + "' style='width: 150px;' data-toggle='tooltip' data-placement='top' >");
  411. dataTime2.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  412. dataTime1.bind('input propertychange', function () {
  413. let dom = {name: this.name, type: 'dataTime_dataTime', value: this.value, mold: 'dataTime'};
  414. modifyData(dom);
  415. })
  416. dataTime2.bind('input propertychange', function () {
  417. let dom = {name: this.name, type: 'dataTime_dataTime', value: this.value, mold: 'dataTime'};
  418. modifyData(dom);
  419. })
  420. return div.append(dataTime1).append(dataTime2);
  421. }
  422. // dataTime_select
  423. function getDataTimeSelect(condition) {
  424. let div = $("<div class='form-inline'></div>");
  425. let dataTime = $("<input type='date' class='form-control form-control-sm' name='" + condition.name[0] + "' style='max-width: 150px;' data-toggle='tooltip' data-placement='top' >");
  426. dataTime.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  427. let select = $("<select name='" + condition.name[1] + "' class='form-control form-control-sm ' data-toggle='tooltip' data-placement='top' style='max-width: 75px'></select>");
  428. select.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  429. fillSelectOption(select, condition.data)
  430. dataTime.bind('input propertychange', function () {
  431. let dom = {name: this.name, type: 'dataTime_select', value: this.value, mold: 'dataTime'};
  432. modifyData(dom);
  433. })
  434. select.change(function () {
  435. let dom = {name: this.name, type: 'dataTime_select', value: this.value, mold: 'select'};
  436. modifyData(dom);
  437. })
  438. return div.append(dataTime).append(select);
  439. }
  440. // select_multiple_select
  441. function getSelectMultipleSelect(condition) {
  442. let div = $("<div class='form-inline' style='position: relative'></div>");
  443. let select = $("<select class='form-control form-control-sm' name='" + condition.name + "_sel' id='" + condition.name + "_sel' style='vertical-align: middle; width: 100px;' data-toggle='tooltip' data-placement='top' ></select>");
  444. let label = $("<label id='" + condition.name + "_lab' style='vertical-align: middle; width: 100px' >(多选)</label>").hide();
  445. let select_div = $("<div ></div>");
  446. select.attr('title', controlJsType(condition.tip[0], 'undefined') ? '' : condition.tip[0]);
  447. let placeholder = controlJsType(condition.placeholder[0], 'undefined') ? '' : condition.placeholder[0];
  448. fillSelectOption(select, condition.data, placeholder);
  449. let input = $("<input name='" + condition.name + "_tip' class='form-control form-control-sm ml-2' style='max-width: 150px' data-toggle='tooltip' data-placement='top'>");
  450. input.attr('title', controlJsType(condition.tip[1], 'undefined') ? '' : condition.tip[1]);
  451. input.attr('placeholder', controlJsType(condition.placeholder[1], 'undefined') ? '' : condition.placeholder[1])
  452. let ul_div = $("<div class='pl-0' style='position: absolute;left: 100px;top:25px; max-height: 150px; overflow-y: scroll; border: 1px solid rgb(221, 221, 221); border-radius: 5px; text-align: center; transform: scale(0.9);z-index:1' tabindex='1'></div>");
  453. let ul = $("<ul name='" + condition.name + "' class='list-group pl-0 m-0 p-0 bg-white' style='list-style-type: none;width: 150px;top:35px; z-index: 100' ></ul>");
  454. select_div.append(input).append(ul_div.append(ul));
  455. div.append(select).append(label).append(select_div);
  456. fillMultipleSelectOption(ul, condition.data, condition.name);
  457. input.bind('input propertychange', function () {
  458. let value = this.value;
  459. if (value === '') {
  460. fillMultipleSelectOption(ul, _data[condition.name].data, condition.name);
  461. redenerUl(ul);
  462. return;
  463. }
  464. let select = _data[condition.name].select;
  465. if ([undefined, null, ''].includes(select)) {
  466. select = [];
  467. }
  468. let select_data = _data[condition.name].data.filter(function (map) {
  469. return map.value.includes(value) || select.includes(map.name);
  470. })
  471. fillMultipleSelectOption(ul, select_data, condition.name);
  472. redenerUl(ul);
  473. })
  474. select.change(function () {
  475. let dom = {
  476. name: condition.name,
  477. type: 'select_multiple_select',
  478. value: [this.value]
  479. }
  480. modifyData(dom);
  481. redenerUl(ul);
  482. })
  483. input.focus(function () {
  484. ul_div.show();
  485. })
  486. input.blur(function () {
  487. setTimeout(function () {
  488. if (!select_div.is(':focus')) {
  489. ul_div.hide();
  490. }
  491. }, 1000);
  492. })
  493. select_div.focus(function () {
  494. ul_div.show();
  495. })
  496. select_div.blur(function () {
  497. ul_div.hide();
  498. })
  499. ul_div.blur(function () {
  500. ul_div.hide();
  501. })
  502. ul_div.hide();
  503. return div;
  504. }
  505. // checkbox
  506. function getCheckBox(condition) {
  507. let div1 = $("<div class='form-inline'></div>")
  508. condition.data.forEach(function (map, index) {
  509. let div = $('<div class="custom-control custom-control-inline custom-checkbox"></div>');
  510. let checkbox = $("<input type='checkbox' name='" + condition.name + "' class='custom-control-input' id='" + condition.name + index + "' value='" + map.name + "' >");
  511. let label = $("<label class='custom-control-label' for='" + condition.name + index + "'>" + map.value + "</label>")
  512. div1.append(div.append(checkbox).append(label));
  513. checkbox.click(function () {
  514. let value = [];
  515. $.each($("input:checkbox[name='" + condition.name + "']:checked"), function () {
  516. value.push($(this).val());
  517. })
  518. let dom = {name: condition.name, type: 'checkbox', value: value, mold: 'check'};
  519. modifyData(dom);
  520. });
  521. })
  522. return div1;
  523. }
  524. // fill select
  525. function fillSelectOption(select, data, placeholder = '') {
  526. select.html('');
  527. if (![undefined, null].includes(placeholder)) {
  528. let option = $("<option value></option>");
  529. if ('' === placeholder) {
  530. option = $("<option value>" + '全部' + placeholder + "</option>");
  531. } else {
  532. option = $("<option value>" + placeholder + "</option>");
  533. }
  534. select.append(option);
  535. }
  536. data.forEach(function (map) {
  537. let option = $("<option value='" + map.name + "'>" + map.value + "</optio>");
  538. select.append(option);
  539. })
  540. if (data !== undefined) {
  541. }
  542. }
  543. // fill multiple select ul
  544. function fillMultipleSelectOption(ul, data, name) {
  545. ul.html('');
  546. data.forEach(function (map) {
  547. let span = $("<span style='cursor:default'>" + map.value + "</span>");
  548. let li = $("<li class='list-group-item pt-0 pb-0' value='" + map.name + "'></li>");
  549. li.append(span);
  550. ul.append(li);
  551. li.click(function () {
  552. let value = li.attr('value');
  553. let dom_data = _data[name].value;
  554. if (controlJsType(dom_data, ['undefined', 'null', 'string'])) {
  555. dom_data = [dom_data];
  556. }
  557. if (dom_data.includes(value)) {
  558. dom_data.splice(dom_data.indexOf(value), 1);
  559. } else {
  560. dom_data.push(value);
  561. dom_data = arrDuplicate(dom_data);
  562. }
  563. let dom = {
  564. name: ul.attr('name'),
  565. type: 'select_multiple_select',
  566. value: dom_data,
  567. select: dom_data,
  568. mold: 'select_multiple_select'
  569. };
  570. modifyData(dom);
  571. redenerUl(ul);
  572. isMultiple(name);
  573. _this.onsubmit();
  574. })
  575. })
  576. }
  577. function isMultiple(name) {
  578. let label = $('#' + name + '_lab');
  579. let select = $('#' + name + '_sel');
  580. let dom_data = _data[name].value;
  581. if (dom_data.length === 1 ) {
  582. select.show();
  583. select.val(dom_data[0]);
  584. label.hide();
  585. }else if(controlJsType(dom_data,'string')){
  586. select.show();
  587. select.val(dom_data);
  588. label.hide();
  589. } else if (dom_data.length >= 2) {
  590. select.hide();
  591. label.show();
  592. }
  593. }
  594. // modify _data
  595. function modifyData(dom) {
  596. _data[dom.name].mold = dom.mold;
  597. _data[dom.name].value = dom.value;
  598. _data[dom.name].select = dom.value;
  599. redenerSearchFormOnData(dom.name, dom.value, dom.mold);
  600. }
  601. // save search on cookie
  602. function saveSearchOnCookie() {
  603. let saveData = {};
  604. for (const key in _data) {
  605. if (!['', null, undefined].includes(_data[key].value)) {
  606. if (controlJsType(_data[key].value, 'array') && _data[key].value.length === 0) {
  607. console.log(key);
  608. continue;
  609. }
  610. saveData[key] = {
  611. value: _data[key].value,
  612. mold: _data[key].mold,
  613. }
  614. }
  615. }
  616. if (!_this.page) {
  617. saveData['page'] = _this.page;
  618. }
  619. saveCookie(saveData);
  620. }
  621. // hour_minute
  622. function verifyTime(time) {
  623. setTimeout(function () {
  624. time.value = time.value.replace(':', ':');
  625. time.value = time.value.replace(/[a-zA-Z]/, '');
  626. time.value = time.value.replace(/[^\d^\:]/, '');
  627. time.value = time.value.replace(/\:\:/, ':');
  628. time.value = time.value.replace(/^([\d]{1})([\s]{1})/, "$1:");
  629. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\s]{1})/, "$1$2:");
  630. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3");
  631. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})(.*?)/, "$1$2$3$4");
  632. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})([\d]{1})/, "$1$2:$3$4");
  633. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\d]{1})([\d]{1})([\s\S]{1})/, "$1$2:$3$4");
  634. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([\D]{1,99})/, "$1$2:");
  635. time.value = time.value.replace(/^([\d]{1})([\d]{1})([\d]{1})\./, "$1:$2$3");
  636. time.value = time.value.replace(/^([\d]{1})\.([\d]{1})([\d]{1})/, "$1:$2$3");
  637. time.value = time.value.replace(/^([\d]{1})([\d]{2})([\S\s]{1,99})/, "$1$2:$3");
  638. time.value = time.value.replace(/^([\d]{1}):([\d]{2})([\S\s]{1,99})/, "$1:$2");
  639. time.value = time.value.replace(/^([\d])/, "$1");
  640. time.value = time.value.replace(/^([1])([\d]{1})/, "$1$2");
  641. time.value = time.value.replace(/^([3-9])([\d]{1})/, "2$2");
  642. time.value = time.value.replace(/^([2-9]{1})([4-9]{1})/, "$13");
  643. time.value = time.value.replace(/^([\d]{1})([\d]{1}):([6-9]{1})/, "$1$2:5");
  644. time.value = time.value.replace(/^([\d]{1})([\d]{1})$/, "$1$2:");
  645. }, 10);
  646. }
  647. // array duplicate
  648. function arrDuplicate(arr) {
  649. let res = [];
  650. let obj = {};
  651. for (let i = 0; i < arr.length; i++) {
  652. if ([undefined, null, ''].includes(arr[i])) {
  653. continue;
  654. }
  655. if (!obj[arr[i]]) {
  656. obj[arr[i]] = 1;
  657. res.push(arr[i]);
  658. }
  659. }
  660. return res;
  661. }
  662. // get search data
  663. this.getSearchData = function (type = 'array') {
  664. let data = {};
  665. if (type === 'array') {
  666. for (let key in _data) {
  667. if (_data[key].value !== undefined && _data[key].value !== '') {
  668. data[key] = _data[key].value
  669. }
  670. }
  671. } else if (type === 'string') {
  672. data = '';
  673. for (let key in _data) {
  674. if (![undefined, null, ''].includes(_data[key].value)) {
  675. let value = _data[key].value;
  676. if (controlJsType(value, 'string')) {
  677. data = data + "&" + key + "=" + value;
  678. } else if (controlJsType(value, 'array')) {
  679. value.forEach(function (val) {
  680. data = data + "&" + key + "=" + val;
  681. });
  682. }
  683. }
  684. }
  685. }
  686. return data;
  687. }
  688. // renderer input
  689. function rendererSearchFormOnInput(key, value, mold) {
  690. if ([undefined, null, ''].includes(value)) {
  691. $(_form).find("input[name='" + key + "']").val('');
  692. $(_form).find("input[name='" + key + "']").removeClass('bg-warning');
  693. } else {
  694. $(_form).find("input[name='" + key + "']").val(value);
  695. $(_form).find("input[name='" + key + "']").addClass('bg-warning');
  696. }
  697. }
  698. // renderer select
  699. function rendererSearchFormOnSelect(key, value, mold) {
  700. if ([undefined, null, ''].includes(value)) {
  701. $(_form).find("select[name='" + key + "']").val('').removeClass('bg-warning');
  702. if (key === 'paginate') {
  703. $(_form).find("select[name='" + key + "']").val(_this.paginations[0]).removeClass('bg-warning');
  704. }
  705. } else {
  706. $(_form).find("select[name='" + key + "']").val(value);
  707. console.log(value === _this.paginations[0]);
  708. if (key === 'paginate' && value == _this.paginations[0]) {
  709. return;
  710. }
  711. $(_form).find("select[name='" + key + "']").addClass('bg-warning');
  712. }
  713. }
  714. // renderer check
  715. function rendererSearchFormOnCheck(key, value, mold) {
  716. if ([undefined, null, ''].includes(value)) {
  717. $(_form).find("input[name='" + key + "']").prop("checked", false).removeClass('bg-warning');
  718. } else {
  719. if (controlJsType(value, 'array')) {
  720. value.forEach(function (_value) {
  721. $(_form).find("input[name='" + key + "'][value='" + _value + "']").prop("checked", true).addClass('bg-warning');
  722. })
  723. } else if (controlJsType(value, 'string')) {
  724. $(_form).find("input[name='" + key + "'][value='" + value + "']").prop("checked", true).addClass('bg-warning');
  725. }
  726. }
  727. }
  728. // redener multiple select input
  729. function rendererSearchFormOnMultipleSelect(key, value, mold) {
  730. let ul = $(_form).find("ul[name='" + key + "']");
  731. if ([undefined, null, ''].includes(value) || (controlJsType(value, 'array') && value.length === 0)) {
  732. $(_form).find("input[name='" + key + "_tip']").removeClass('bg-warning');
  733. ul.addClass('bg-warning');
  734. } else if (!!value) {
  735. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  736. ul.addClass('bg-warning');
  737. } else if (controlJsType(value, 'array') && value.length >= 1) {
  738. $(_form).find("input[name='" + key + "_tip']").addClass('bg-warning');
  739. ul.addClass('bg-warning');
  740. }
  741. redenerUl(ul);
  742. }
  743. // redener multiple select ul
  744. function redenerUl(ul) {
  745. let name = ul.attr('name');
  746. let select = _data[name].select;
  747. if ([null, undefined].includes(select)) {
  748. _data[name].select = [];
  749. select = [];
  750. }
  751. let lis = ul.find('li');
  752. if ([null, undefined, ''].includes(lis)) {
  753. return;
  754. } else {
  755. lis.get().forEach(function (dom) {
  756. if (select.includes($(dom).attr('value'))) {
  757. dom.style.backgroundColor = "#4AA0E6";
  758. $(dom).addClass('active');
  759. } else {
  760. dom.style.backgroundColor = "#FFFFFF";
  761. $(dom).removeClass('active');
  762. }
  763. })
  764. isMultiple(name);
  765. }
  766. }
  767. function rendererSearchFormOnTime(key, value, mold) {
  768. if ([undefined, null, ''].includes(value)) {
  769. $(_form).find("input[name='+key+']").val(value.substring(0, 10)).addClass('bg-warning');
  770. if (value.length > 11 + 5) {
  771. $(_form).find("input[name='" + key + "_tim']").val(value.substring(11, 5));
  772. }
  773. } else {
  774. $(_form).find("input[name='+key+']").val("").removeClass('bg-warning');
  775. $(_form).find("input[name='" + key + "_tim']").val("");
  776. }
  777. }
  778. function visibleClearBtn() {
  779. let bool = false;
  780. for (const key in _data) {
  781. if (key === 'paginate') {
  782. if ((key === 'paginate' && _data[key].value !== _this.paginations[0])) {
  783. bool = true;
  784. }
  785. } else {
  786. if (![undefined, null, ''].includes(_data[key].value)) {
  787. bool = true;
  788. }
  789. }
  790. }
  791. if (bool) {
  792. _clearBtn.addClass('visible').removeClass('invisible');
  793. } else {
  794. _clearBtn.addClass('invisible').removeClass('visible');
  795. }
  796. }
  797. function inputKeyDown() {
  798. $(_form).find('input').keydown(function (e) {
  799. if (e.keyCode === 13) {
  800. if (_this.keydownSearch) {
  801. _this.onsubmit()
  802. }
  803. if (controlJsType(_this.keydownfun, 'fun')) {
  804. _this.keydownfun();
  805. }
  806. }
  807. });
  808. $(_form).find("input[type='date']").change(function (e) {
  809. if (_this.keydownSearch) {
  810. _this.onsubmit()
  811. }
  812. if (controlJsType(_this.keydownfun, 'fun')) {
  813. _this.keydownfun();
  814. }
  815. });
  816. }
  817. function selectChange() {
  818. $(_form).find('select').change(function () {
  819. _this.onsubmit();
  820. })
  821. }
  822. function redenerSearchFormOnData(key, value, mold) {
  823. if (mold === 'input') {
  824. rendererSearchFormOnInput(key, value, mold);
  825. } else if (mold === 'select') {
  826. rendererSearchFormOnSelect(key, value, mold);
  827. } else if (mold === 'check') {
  828. rendererSearchFormOnCheck(key, value, mold);
  829. } else if (mold === 'select_multiple_select') {
  830. rendererSearchFormOnMultipleSelect(key, value, mold);
  831. } else if (mold === 'time') {
  832. rendererSearchFormOnTime(key, value, mold);
  833. }
  834. }
  835. // 数据转换
  836. function switchData() {
  837. _this.condition.forEach(function (conditions) {
  838. conditions.forEach(function (condition) {
  839. if (['input', 'select', 'dataTime', 'search_select', 'time', 'select_multiple_select'].includes(condition.type)) {
  840. if (!condition.select) {
  841. condition.select = '';
  842. }
  843. let data = {
  844. name: condition.name,
  845. type: condition.type,
  846. value: condition.value,
  847. select: condition.select,
  848. mold: ['input', 'dataTime'].includes(condition.type) ? 'input' : condition.type
  849. }
  850. if (condition.type === 'search_select') {
  851. data.mold = 'select';
  852. }
  853. _data[condition.name] = data;
  854. } else if (['dataTime_dataTime', 'input_input', 'input_select', 'dataTime_select'].includes(condition.type)) {
  855. let types = condition.type.split("_");
  856. if (!condition.select) {
  857. condition.select = ['', ''];
  858. }
  859. if (!condition.value) {
  860. condition.value = ['', ''];
  861. }
  862. condition.name.forEach(function (_name, index) {
  863. let data = {
  864. name: _name,
  865. type: types[index],
  866. value: condition.value[index],
  867. select: condition.select[index],
  868. mold: ['input', 'dataTime'].includes(types[index]) ? 'input' : types[index]
  869. }
  870. _data[_name] = data;
  871. })
  872. }
  873. })
  874. })
  875. }
  876. // redererSearchForm on cookie
  877. function rendererSearchForm() {
  878. let url = document.referrer;
  879. let partt = /(Edit\/)|(\/eidt)|(eidt\/)/i;
  880. if (url.search(partt) > 0) {
  881. rendererOptionOnCookie();
  882. } else {
  883. rendererOptionOnUrl();
  884. }
  885. }
  886. function rendererOptionOnCookie() {
  887. console.log('rendererSearchFromOnCookie');
  888. let data = fetchCookie();
  889. if (data === undefined) {
  890. return;
  891. }
  892. data = JSON.parse(data);
  893. for (let key in data) {
  894. _data[key].value = data[key].value;
  895. _data[key].mold = data[key].mold;
  896. _data[key].select = data[key].select;
  897. }
  898. rendererSearchFormOn_data();
  899. }
  900. function rendererOptionOnUrl() {
  901. if (!window.location.search) {
  902. return;
  903. }
  904. searchOptionToUrlsearch();
  905. rendererSearchFormOn_data();
  906. }
  907. function rendererSearchFormOn_data() {
  908. console.log('rendererSearchFormOn_data', _data);
  909. for (let key in _data) {
  910. let value = _data[key].value, type = _data[key].type, mold = _data[key].mold;
  911. _data[key].select = value;
  912. if (['input', 'dataTime'].includes(mold)) {
  913. rendererSearchFormOnInput(key, value, mold);
  914. } else if (['select'].includes(mold)) {
  915. rendererSearchFormOnSelect(key, value, mold);
  916. } else if (['checkbox'].includes(mold)) {
  917. rendererSearchFormOnCheck(key, value, mold);
  918. } else if (['select_multiple_select'].includes(mold)) {
  919. if (controlJsType(value, ['array', 'string'])) {
  920. let ul = $(_form).find("ul[name='" + key + "']");
  921. redenerUl(ul);
  922. rendererSearchFormOnMultipleSelect(key, value, mold);
  923. }
  924. } else if (['time'].includes(type) && value !== undefined) {
  925. $(_form).find("input[name='" + key + "']").val(value.substr(0, 10));
  926. $(_form).find("input[id='" + key + "_min']").val(value.substr(11, value.length));
  927. }
  928. /* if (['input', 'dataTime', 'input_input', 'dataTime_dataTime'].includes(type)) {
  929. rendererSearchFormOnInput(key,value,mold);
  930. } else if (['select', 'input_select', 'dataTime_select'].includes(type)) {
  931. if (mold === 'select') {
  932. rendererSearchFormOnSelect(key,value,mold)
  933. } else if (mold === 'input') {
  934. rendererSearchFormOnInput(key,value,mold);
  935. } else if (mold === 'dataTime') {
  936. rendererSearchFormOnInput(key,value,mold);
  937. }
  938. } else if (['input_select_text'].includes(type)) {
  939. if (mold === 'input') {
  940. rendererSearchFormOnInput(key,value,mold);
  941. } else if (mold === 'select') {
  942. rendererSearchFormOnSelect(key,value,mold)
  943. }
  944. } else if (['checkbox'].includes(type)) {
  945. if (controlJsType(value, 'array')) {
  946. value.forEach(function (map) {
  947. $(_form).find("input[type='checkbox'][name='" + key + "'][value='" + map + "']").attr("checked", true);
  948. })
  949. }
  950. } else if (['select_multiple_select'].includes(type)) {
  951. if (controlJsType(value, ['array','string']) ) {
  952. let ul = $(_form).find("ul[name='" + key + "']");
  953. redenerUl(ul);
  954. rendererSearchFormOnMultipleSelect(key,value,mold);
  955. }
  956. } else if (['time'].includes(type) && value !== undefined) {
  957. $(_form).find("input[name='"+key+"']").val(value.substr(0,10));
  958. $(_form).find("input[id='"+key+"_min']").val(value.substr(11,value.length));
  959. }*/
  960. }
  961. if ([undefined, null, ''].includes(data['paginate'])) {
  962. return;
  963. }
  964. if ([undefined, null, ''].includes(data['paginate'].value)) {
  965. $(_form).find("select[name='paginate']").val(_this.paginations[0]);
  966. } else {
  967. $(_form).find("select[name='paginate']").val(data['paginate'].value);
  968. }
  969. }
  970. // url path on search form option renderer
  971. function searchOptionToUrlsearch() {
  972. let data = window.location.search;
  973. data = decodeURIComponent(data);
  974. if (!!data) {
  975. data = (data.substr(1)).split('&');
  976. data = convertArrayToObj(data);
  977. for (const key in data) {
  978. if (key === 'paginate') {
  979. _data[key] = {
  980. name: key,
  981. value: data[key],
  982. type: 'select',
  983. mold: 'select'
  984. }
  985. } else if (key === 'page') {
  986. _page = data[key];
  987. } else {
  988. _data[key].value = data[key];
  989. }
  990. console.log('key', key, typeof key);
  991. }
  992. }
  993. }
  994. // cookie -> data
  995. function set_dataOnCookie() {
  996. let data = fetchCookie();
  997. data = JSON.parse(data);
  998. if (!data) {
  999. return;
  1000. }
  1001. for (const key in data) {
  1002. if (!!data[key]) {
  1003. _data[key].value = data[key].value;
  1004. }
  1005. }
  1006. }
  1007. // array - > object
  1008. function convertArrayToObj(arr) {
  1009. if (!arr || !controlJsType(arr, 'array')) {
  1010. return {};
  1011. } else if (controlJsType(arr, 'array') && arr.length > 0) {
  1012. let data = {};
  1013. arr.forEach(function (map) {
  1014. let arr = map.split('='), key = arr[0], value = arr[1];
  1015. if (!data[key]) {
  1016. data[key] = value;
  1017. } else {
  1018. if (controlJsType(data[key], 'string')) {
  1019. data[key] = [data[key], value];
  1020. } else if (controlJsType(data[key], 'array')) {
  1021. data[key].push(value);
  1022. }
  1023. }
  1024. })
  1025. return data;
  1026. }
  1027. }
  1028. // paginate
  1029. function pervPage() {
  1030. let obj = getSearchObj();
  1031. if(!!obj['page'] && obj['page']>1){
  1032. obj['page'] = obj['page']-1;
  1033. }
  1034. return getSearchUri(obj);
  1035. }
  1036. function nextPage() {
  1037. let obj = getSearchObj();
  1038. if(!!obj['page'] ){
  1039. obj['page'] = obj['page']+1;
  1040. }else{
  1041. obj['page'] = 2;
  1042. }
  1043. if(!obj['paginate']){
  1044. obj['paginate'] = 50;
  1045. }
  1046. return getSearchUri(obj);
  1047. }
  1048. function getSearchObj() {
  1049. let data = window.location.search;
  1050. data = decodeURIComponent(data);
  1051. if(!data){
  1052. return {};
  1053. }
  1054. let saveData = {};
  1055. data = data.substr(1).split('&');
  1056. data.forEach(function (map) {
  1057. let arr = map.split('&'),key = arr[0],value = arr[1];
  1058. if(!!value){
  1059. if (!saveData[key]) {
  1060. saveData[key] = value;
  1061. } else {
  1062. if (controlJsType(data[key], 'string')) {
  1063. saveData[key] = [saveData[key] , value];
  1064. } else if (controlJsType(data[key], 'array')) {
  1065. saveData[key].push(value);
  1066. }
  1067. }
  1068. }
  1069. })
  1070. return saveData;
  1071. }
  1072. function getSearchUri(obj){
  1073. let string = "?";
  1074. for (const key in obj) {
  1075. if(controlJsType(obj[key],'string')){
  1076. string+= key + "=" + obj[key]+'&';
  1077. }else if( controlJsType(obj[key],'array')&&obj[key].length > 0){
  1078. obj[key].forEach(function(value){
  1079. string+=key + "=" + value+'&';
  1080. })
  1081. }
  1082. }
  1083. return string;
  1084. }
  1085. };
  1086. //module.exports = query;