admin.js 43 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133
  1. ;(function () {
  2. //全局ajax处理
  3. $.ajaxSetup({
  4. complete: function (jqXHR) {
  5. },
  6. data: {},
  7. error: function (jqXHR, textStatus, errorThrown) {
  8. //请求失败处理
  9. }
  10. });
  11. if ($.browser && $.browser.msie) {
  12. //ie 都不缓存
  13. $.ajaxSetup({
  14. cache: false
  15. });
  16. }
  17. //不支持placeholder浏览器下对placeholder进行处理
  18. if (document.createElement('input').placeholder !== '') {
  19. $('[placeholder]').focus(function () {
  20. var input = $(this);
  21. if (input.val() == input.attr('placeholder')) {
  22. input.val('');
  23. input.removeClass('placeholder');
  24. }
  25. }).blur(function () {
  26. var input = $(this);
  27. if (input.val() == '' || input.val() == input.attr('placeholder')) {
  28. input.addClass('placeholder');
  29. input.val(input.attr('placeholder'));
  30. }
  31. }).blur().parents('form').submit(function () {
  32. $(this).find('[placeholder]').each(function () {
  33. var input = $(this);
  34. if (input.val() == input.attr('placeholder')) {
  35. input.val('');
  36. }
  37. });
  38. });
  39. }
  40. // 所有加了dialog类名的a链接,自动弹出它的href
  41. if ($('a.js-dialog').length) {
  42. Wind.css('artDialog');
  43. Wind.use('artDialog', 'iframeTools', function () {
  44. $('.js-dialog').on('click', function (e) {
  45. e.preventDefault();
  46. var $this = $(this);
  47. art.dialog.open($(this).prop('href'), {
  48. close: function () {
  49. $this.focus(); // 关闭时让触发弹窗的元素获取焦点
  50. return true;
  51. },
  52. title: $this.prop('title')
  53. });
  54. }).attr('role', 'button');
  55. });
  56. }
  57. // 所有的ajax form提交,由于大多业务逻辑都是一样的,故统一处理
  58. var ajaxForm_list = $('form.js-ajax-form');
  59. if (ajaxForm_list.length) {
  60. Wind.css('artDialog');
  61. Wind.use('ajaxForm', 'artDialog', 'noty', 'validate', function () {
  62. var $btn;
  63. $('button.js-ajax-submit').on('click', function (e) {
  64. var btn = $(this), form = btn.parents('form.js-ajax-form');
  65. $btn = btn;
  66. if (btn.data("loading")) {
  67. return;
  68. }
  69. //批量操作 判断选项
  70. if (btn.data('subcheck')) {
  71. btn.parent().find('span').remove();
  72. if (form.find('input.js-check:checked').length) {
  73. btn.data('subcheck', false);
  74. } else {
  75. $('<span class="tips_error">请至少选择一项</span>').appendTo(btn.parent()).fadeIn('fast');
  76. return false;
  77. }
  78. }
  79. var msg = btn.data('msg');
  80. if (msg) {
  81. art.dialog({
  82. id: 'warning',
  83. icon: 'warning',
  84. content: btn.data('msg'),
  85. cancelVal: '关闭',
  86. cancel: function () {
  87. //btn.data('subcheck', false);
  88. //btn.click();
  89. },
  90. ok: function () {
  91. btn.data('msg', false);
  92. btn.click();
  93. }
  94. });
  95. return false;
  96. }
  97. //ie处理placeholder提交问题
  98. if ($.browser && $.browser.msie) {
  99. form.find('[placeholder]').each(function () {
  100. var input = $(this);
  101. if (input.val() == input.attr('placeholder')) {
  102. input.val('');
  103. }
  104. });
  105. }
  106. });
  107. ajaxForm_list.each(function () {
  108. $(this).validate({
  109. //是否在获取焦点时验证
  110. //onfocusout : false,
  111. //是否在敲击键盘时验证
  112. //onkeyup : false,
  113. //当鼠标点击时验证
  114. //onclick : false,
  115. //给未通过验证的元素加效果,闪烁等
  116. highlight: function (element, errorClass, validClass) {
  117. if (element.type === "radio") {
  118. this.findByName(element.name).addClass(errorClass).removeClass(validClass);
  119. } else {
  120. var $element = $(element);
  121. $element.addClass(errorClass).removeClass(validClass);
  122. $element.parent().addClass("has-error");//bootstrap3表单
  123. $element.parents('.control-group').addClass("error");//bootstrap2表单
  124. }
  125. },
  126. unhighlight: function (element, errorClass, validClass) {
  127. if (element.type === "radio") {
  128. this.findByName(element.name).removeClass(errorClass).addClass(validClass);
  129. } else {
  130. var $element = $(element);
  131. $element.removeClass(errorClass).addClass(validClass);
  132. $element.parent().removeClass("has-error");//bootstrap3表单
  133. $element.parents('.control-group').removeClass("error");//bootstrap2表单
  134. }
  135. },
  136. showErrors: function (errorMap, errorArr) {
  137. var i, elements, error;
  138. for (i = 0; this.errorList[i]; i++) {
  139. error = this.errorList[i];
  140. if (this.settings.highlight) {
  141. this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass);
  142. }
  143. //this.showLabel( error.element, error.message );
  144. }
  145. if (this.errorList.length) {
  146. //this.toShow = this.toShow.add( this.containers );
  147. }
  148. if (this.settings.success) {
  149. for (i = 0; this.successList[i]; i++) {
  150. //this.showLabel( this.successList[ i ] );
  151. }
  152. }
  153. if (this.settings.unhighlight) {
  154. for (i = 0, elements = this.validElements(); elements[i]; i++) {
  155. this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
  156. }
  157. }
  158. this.toHide = this.toHide.not(this.toShow);
  159. this.hideErrors();
  160. this.addWrapper(this.toShow).show();
  161. },
  162. submitHandler: function (form) {
  163. var $form = $(form);
  164. $form.ajaxSubmit({
  165. url: $btn.data('action') ? $btn.data('action') : $form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
  166. dataType: 'json',
  167. beforeSubmit: function (arr, $form, options) {
  168. $btn.data("loading", true);
  169. var text = $btn.text();
  170. //按钮文案、状态修改
  171. $btn.text(text + '...').prop('disabled', true).addClass('disabled');
  172. },
  173. success: function (data, statusText, xhr, $form) {
  174. function _refresh() {
  175. if (data.url) {
  176. //返回带跳转地址
  177. window.location.href = data.url;
  178. } else {
  179. if (data.code == 1) {
  180. //刷新当前页
  181. reloadPage(window);
  182. }
  183. }
  184. }
  185. var text = $btn.text();
  186. //按钮文案、状态修改
  187. $btn.removeClass('disabled').prop('disabled', false).text(text.replace('...', '')).parent().find('span').remove();
  188. if (data.code == 1) {
  189. if ($btn.data('success')) {
  190. var successCallback = $btn.data('success');
  191. window[successCallback](data, statusText, xhr, $form);
  192. return;
  193. }
  194. noty({
  195. text: data.msg,
  196. type: 'success',
  197. layout: 'topCenter',
  198. modal: true,
  199. // animation: {
  200. // open: 'animated bounceInDown', // Animate.css class names
  201. // close: 'animated bounceOutUp', // Animate.css class names
  202. // },
  203. timeout: 800,
  204. callback: {
  205. afterClose: function () {
  206. if ($btn.data('refresh') == undefined || $btn.data('refresh')) {
  207. if ($btn.data('success_refresh')) {
  208. var successRefreshCallback = $btn.data('success_refresh');
  209. window[successRefreshCallback](data, statusText, xhr, $form);
  210. return;
  211. } else {
  212. _refresh();
  213. }
  214. }
  215. }
  216. }
  217. }).show();
  218. $(window).focus();
  219. } else if (data.code == 0) {
  220. var $verify_img = $form.find(".verify_img");
  221. if ($verify_img.length) {
  222. $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random());
  223. }
  224. var $verify_input = $form.find("[name='verify']");
  225. $verify_input.val("");
  226. //$('<span class="tips_error">' + data.msg + '</span>').appendTo($btn.parent()).fadeIn('fast');
  227. $btn.removeProp('disabled').removeClass('disabled');
  228. noty({
  229. text: data.msg,
  230. type: 'error',
  231. layout: 'topCenter',
  232. modal: true,
  233. // animation: {
  234. // open: 'animated bounceInDown', // Animate.css class names
  235. // close: 'animated bounceOutUp', // Animate.css class names
  236. // },
  237. timeout: 800,
  238. callback: {
  239. afterClose: function () {
  240. _refresh();
  241. }
  242. }
  243. }).show();
  244. $(window).focus();
  245. }
  246. },
  247. error: function (xhr, e, statusText) {
  248. art.dialog({
  249. id: 'warning',
  250. icon: 'warning',
  251. content: statusText,
  252. cancelVal: '关闭',
  253. cancel: function () {
  254. reloadPage(window);
  255. },
  256. ok: function () {
  257. reloadPage(window);
  258. }
  259. });
  260. },
  261. complete: function () {
  262. $btn.data("loading", false);
  263. }
  264. });
  265. }
  266. });
  267. });
  268. });
  269. }
  270. //dialog弹窗内的关闭方法
  271. $('#js-dialog-close').on('click', function (e) {
  272. e.preventDefault();
  273. try {
  274. art.dialog.close();
  275. } catch (err) {
  276. Wind.css('artDialog');
  277. Wind.use('artDialog', 'iframeTools', function () {
  278. art.dialog.close();
  279. });
  280. }
  281. ;
  282. });
  283. //所有的删除操作,删除数据后刷新页面
  284. if ($('a.js-ajax-delete').length) {
  285. Wind.css('artDialog');
  286. Wind.use('artDialog', 'noty', function () {
  287. $('body').on('click', '.js-ajax-delete', function (e) {
  288. e.preventDefault();
  289. var $_this = this,
  290. $this = $($_this),
  291. href = $this.data('href'),
  292. refresh = $this.data('refresh'),
  293. msg = $this.data('msg');
  294. href = href ? href : $this.attr('href');
  295. art.dialog({
  296. title: false,
  297. icon: 'question',
  298. content: msg ? msg : '确定要删除吗?',
  299. follow: $_this,
  300. close: function () {
  301. $_this.focus(); //关闭时让触发弹窗的元素获取焦点
  302. return true;
  303. },
  304. okVal: "确定",
  305. ok: function () {
  306. $.ajax({
  307. url: href,
  308. type: 'post',
  309. dataType: 'JSON',
  310. success: function (data) {
  311. if (data.code == '1') {
  312. noty({
  313. text: data.msg,
  314. type: 'success',
  315. layout: 'topCenter',
  316. modal: true,
  317. // animation: {
  318. // open: 'animated bounceInDown', // Animate.css class names
  319. // close: 'animated bounceOutUp', // Animate.css class names
  320. // },
  321. timeout: 800,
  322. callback: {
  323. afterClose: function () {
  324. if (refresh == undefined || refresh) {
  325. if (data.url) {
  326. //返回带跳转地址
  327. window.location.href = data.url;
  328. } else {
  329. //刷新当前页
  330. reloadPage(window);
  331. }
  332. }
  333. }
  334. }
  335. }).show();
  336. } else if (data.code == '0') {
  337. //art.dialog.alert(data.info);
  338. //alert(data.info);//暂时处理方案
  339. art.dialog({
  340. content: data.msg,
  341. icon: 'warning',
  342. ok: function () {
  343. this.title(data.msg);
  344. return true;
  345. }
  346. });
  347. }
  348. }
  349. })
  350. },
  351. cancelVal: '关闭',
  352. cancel: true
  353. });
  354. });
  355. });
  356. }
  357. Wind.use('artDialog', 'noty', function () {
  358. $('body').on('click', '.js-ajax-dialog-btn', function (e) {
  359. e.preventDefault();
  360. var $_this = this,
  361. $this = $($_this),
  362. href = $this.data('href'),
  363. refresh = $this.data('refresh'),
  364. msg = $this.data('msg'),
  365. waitMsg = $this.data('wait-msg');
  366. href = href ? href : $this.attr('href');
  367. if (!msg) {
  368. msg = "您确定要进行此操作吗?";
  369. }
  370. art.dialog({
  371. title: false,
  372. icon: 'question',
  373. content: msg,
  374. follow: $_this,
  375. close: function () {
  376. $_this.focus(); //关闭时让触发弹窗的元素获取焦点
  377. return true;
  378. },
  379. ok: function () {
  380. var waitNoty;
  381. if (waitMsg) {
  382. waitNoty = noty({
  383. text: waitMsg,
  384. type: 'information',
  385. layout: 'topCenter',
  386. modal: true,
  387. // animation: {
  388. // open: 'animated bounceInDown', // Animate.css class names
  389. // close: 'animated bounceOutUp', // Animate.css class names
  390. // },
  391. timeout: false
  392. });
  393. }
  394. $.ajax({
  395. url: href,
  396. type: 'post',
  397. dataType: 'JSON',
  398. success: function (data) {
  399. if (waitNoty) {
  400. waitNoty.close();
  401. }
  402. if (data.code == 1) {
  403. noty({
  404. text: data.msg,
  405. type: 'success',
  406. layout: 'topCenter',
  407. modal: true,
  408. // animation: {
  409. // open: 'animated bounceInDown', // Animate.css class names
  410. // close: 'animated bounceOutUp', // Animate.css class names
  411. // },
  412. timeout: 800,
  413. callback: {
  414. afterClose: function () {
  415. if (refresh == undefined || refresh) {
  416. if (data.url) {
  417. //返回带跳转地址
  418. window.location.href = data.url;
  419. } else {
  420. //刷新当前页
  421. reloadPage(window);
  422. }
  423. }
  424. }
  425. }
  426. });
  427. } else if (data.code == 0) {
  428. //art.dialog.alert(data.info);
  429. art.dialog({
  430. content: data.msg,
  431. icon: 'warning',
  432. ok: function () {
  433. this.title(data.msg);
  434. return true;
  435. }
  436. });
  437. }
  438. },
  439. error: function () {
  440. if (waitNoty) {
  441. waitNoty.close();
  442. }
  443. }
  444. })
  445. },
  446. cancelVal: '关闭',
  447. cancel: true
  448. });
  449. });
  450. });
  451. if ($('a.js-ajax-btn').length) {
  452. Wind.use('noty', function () {
  453. $('.js-ajax-btn').on('click', function (e) {
  454. e.preventDefault();
  455. var $_this = this,
  456. $this = $($_this),
  457. href = $this.data('href'),
  458. msg = $this.data('msg');
  459. refresh = $this.data('refresh');
  460. href = href ? href : $this.attr('href');
  461. refresh = refresh == undefined ? 1 : refresh;
  462. $.ajax({
  463. url: href,
  464. type: 'post',
  465. dataType: 'JSON',
  466. success: function (data) {
  467. if (data.code == 1) {
  468. noty({
  469. text: data.msg,
  470. type: 'success',
  471. layout: 'center',
  472. callback: {
  473. afterClose: function () {
  474. if (data.url) {
  475. location.href = data.url;
  476. return;
  477. }
  478. if (refresh || refresh == undefined) {
  479. reloadPage(window);
  480. }
  481. }
  482. }
  483. });
  484. } else if (data.code == 0) {
  485. noty({
  486. text: data.msg,
  487. type: 'error',
  488. layout: 'center',
  489. callback: {
  490. afterClose: function () {
  491. if (data.url) {
  492. location.href = data.url;
  493. }
  494. }
  495. }
  496. });
  497. }
  498. }
  499. });
  500. });
  501. });
  502. }
  503. /*复选框全选(支持多个,纵横双控全选)。
  504. *实例:版块编辑-权限相关(双控),验证机制-验证策略(单控)
  505. *说明:
  506. * "js-check"的"data-xid"对应其左侧"js-check-all"的"data-checklist";
  507. * "js-check"的"data-yid"对应其上方"js-check-all"的"data-checklist";
  508. * 全选框的"data-direction"代表其控制的全选方向(x或y);
  509. * "js-check-wrap"同一块全选操作区域的父标签class,多个调用考虑
  510. */
  511. if ($('.js-check-wrap').length) {
  512. var total_check_all = $('input.js-check-all');
  513. //遍历所有全选框
  514. $.each(total_check_all, function () {
  515. var check_all = $(this),
  516. check_items;
  517. //分组各纵横项
  518. var check_all_direction = check_all.data('direction');
  519. check_items = $('input.js-check[data-' + check_all_direction + 'id="' + check_all.data('checklist') + '"]').not(":disabled");
  520. if ($('.js-check-all').is(':checked')) {
  521. check_items.prop('checked', true);
  522. }
  523. //点击全选框
  524. check_all.change(function (e) {
  525. var check_wrap = check_all.parents('.js-check-wrap'); //当前操作区域所有复选框的父标签(重用考虑)
  526. if ($(this).prop('checked')) {
  527. //全选状态
  528. check_items.prop('checked', true);
  529. //所有项都被选中
  530. if (check_wrap.find('input.js-check').length === check_wrap.find('input.js-check:checked').length) {
  531. check_wrap.find(total_check_all).prop('checked', true);
  532. }
  533. } else {
  534. //非全选状态
  535. check_items.removeProp('checked');
  536. check_wrap.find(total_check_all).removeProp('checked');
  537. //另一方向的全选框取消全选状态
  538. var direction_invert = check_all_direction === 'x' ? 'y' : 'x';
  539. check_wrap.find($('input.js-check-all[data-direction="' + direction_invert + '"]')).removeProp('checked');
  540. }
  541. });
  542. //点击非全选时判断是否全部勾选
  543. check_items.change(function () {
  544. if ($(this).prop('checked')) {
  545. if (check_items.filter(':checked').length === check_items.length) {
  546. //已选择和未选择的复选框数相等
  547. check_all.prop('checked', true);
  548. }
  549. } else {
  550. check_all.removeProp('checked');
  551. }
  552. });
  553. });
  554. }
  555. //日期选择器
  556. var dateInput = $("input.js-date");
  557. if (dateInput.length) {
  558. Wind.use('datePicker', function () {
  559. dateInput.datePicker();
  560. });
  561. }
  562. //日期+时间选择器
  563. var dateTimeInput = $("input.js-datetime");
  564. if (dateTimeInput.length) {
  565. Wind.use('datePicker', function () {
  566. dateTimeInput.datePicker({
  567. time: true
  568. });
  569. });
  570. }
  571. var yearInput = $("input.js-year");
  572. if (yearInput.length) {
  573. Wind.use('datePicker', function () {
  574. yearInput.datePicker({
  575. startView: 'decade',
  576. minView: 'decade',
  577. format: 'yyyy',
  578. autoclose: true
  579. });
  580. });
  581. }
  582. // bootstrap年选择器
  583. var bootstrapYearInput = $("input.js-bootstrap-year")
  584. if (bootstrapYearInput.length) {
  585. Wind.css('bootstrapDatetimePicker');
  586. Wind.use('bootstrapDatetimePicker', function () {
  587. bootstrapYearInput.datetimepicker({
  588. language: 'zh-CN',
  589. format: 'yyyy',
  590. minView: 'decade',
  591. startView: 'decade',
  592. todayBtn: 1,
  593. autoclose: true
  594. });
  595. });
  596. }
  597. // bootstrap日期选择器
  598. var bootstrapDateInput = $("input.js-bootstrap-date")
  599. if (bootstrapDateInput.length) {
  600. Wind.css('bootstrapDatetimePicker');
  601. Wind.use('bootstrapDatetimePicker', function () {
  602. bootstrapDateInput.datetimepicker({
  603. language: 'zh-CN',
  604. format: 'yyyy-mm-dd',
  605. minView: 'month',
  606. todayBtn: 1,
  607. autoclose: true
  608. });
  609. });
  610. }
  611. // bootstrap年月份选择器
  612. var bootstrapYearMonthInput = $("input.js-bootstrap-year-month");
  613. if (bootstrapYearMonthInput.length) {
  614. Wind.css('bootstrapDatetimePicker');
  615. Wind.use('bootstrapDatetimePicker', function () {
  616. bootstrapYearMonthInput.datetimepicker({
  617. language: 'zh-CN',
  618. format: 'yyyy-mm',
  619. minView: 'year',
  620. startView: 'decade',
  621. todayBtn: 1,
  622. autoclose: true
  623. });
  624. });
  625. }
  626. // bootstrap日期选择器日期+时间选择器
  627. var bootstrapDateTimeInput = $("input.js-bootstrap-datetime");
  628. if (bootstrapDateTimeInput.length) {
  629. Wind.css('bootstrapDatetimePicker');
  630. Wind.use('bootstrapDatetimePicker', function () {
  631. bootstrapDateTimeInput.datetimepicker({
  632. language: 'zh-CN',
  633. format: 'yyyy-mm-dd hh:ii',
  634. todayBtn: 1,
  635. autoclose: true
  636. });
  637. });
  638. }
  639. //tab
  640. var tabs_nav = $('ul.js-tabs-nav');
  641. if (tabs_nav.length) {
  642. Wind.use('tabs', function () {
  643. tabs_nav.tabs('.js-tabs-content > div');
  644. });
  645. }
  646. //地址联动
  647. var $js_address_select = $('.js-address-select');
  648. if ($js_address_select.length > 0) {
  649. $('.js-address-province-select,.js-address-city-select').change(function () {
  650. var $this = $(this);
  651. var id = $this.val();
  652. var $child_area_select;
  653. var $this_js_address_select = $this.parents('.js-address-select');
  654. if ($this.is('.js-address-province-select')) {
  655. $child_area_select = $this_js_address_select.find('.js-address-city-select');
  656. $this_js_address_select.find('.js-address-district-select').hide();
  657. } else {
  658. $child_area_select = $this_js_address_select.find('.js-address-district-select');
  659. }
  660. var empty_option = '<option class="js-address-empty-option" value="">' + $child_area_select.find('.js-address-empty-option').text() + '</option>';
  661. $child_area_select.html(empty_option);
  662. var child_area_html = $this.data('childarea' + id);
  663. if (child_area_html) {
  664. $child_area_select.show();
  665. $child_area_select.html(child_area_html);
  666. return;
  667. }
  668. $.ajax({
  669. url: $this_js_address_select.data('url'),
  670. type: 'POST',
  671. dataType: 'JSON',
  672. data: {id: id},
  673. success: function (data) {
  674. if (data.code == 1) {
  675. if (data.data.areas.length > 0) {
  676. var html = [empty_option];
  677. $.each(data.data.areas, function (i, area) {
  678. var area_html = '<option value="[id]">[name]</option>';
  679. area_html = area_html.replace('[name]', area.name);
  680. area_html = area_html.replace('[id]', area.id);
  681. html.push(area_html);
  682. });
  683. html = html.join('', html);
  684. $this.data('childarea' + id, html);
  685. $child_area_select.html(html);
  686. $child_area_select.show();
  687. } else {
  688. $child_area_select.hide();
  689. }
  690. }
  691. },
  692. error: function () {
  693. },
  694. complete: function () {
  695. }
  696. });
  697. });
  698. }
  699. //地址联动end
  700. })();
  701. //重新刷新页面,使用location.reload()有可能导致重新提交
  702. function reloadPage(win) {
  703. var location = win.location;
  704. location.href = location.pathname + location.search;
  705. }
  706. /**
  707. * 页面跳转
  708. * @param url 要打开的页面地址
  709. */
  710. function redirect(url) {
  711. location.href = url;
  712. }
  713. /**
  714. * 读取cookie
  715. * @param name
  716. * @returns
  717. */
  718. function getCookie(name) {
  719. var cookieValue = null;
  720. if (document.cookie && document.cookie != '') {
  721. var cookies = document.cookie.split(';');
  722. for (var i = 0; i < cookies.length; i++) {
  723. var cookie = jQuery.trim(cookies[i]);
  724. // Does this cookie string begin with the name we want?
  725. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  726. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  727. break;
  728. }
  729. }
  730. }
  731. return cookieValue;
  732. }
  733. /**
  734. * 设置cookie
  735. */
  736. function setCookie(name, value, options) {
  737. options = options || {};
  738. if (value === null) {
  739. value = '';
  740. options.expires = -1;
  741. }
  742. var expires = '';
  743. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  744. var date;
  745. if (typeof options.expires == 'number') {
  746. date = new Date();
  747. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  748. } else {
  749. date = options.expires;
  750. }
  751. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  752. }
  753. var path = options.path ? '; path=' + options.path : '';
  754. var domain = options.domain ? '; domain=' + options.domain : '';
  755. var secure = options.secure ? '; secure' : '';
  756. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  757. }
  758. /**
  759. * 打开iframe式的窗口对话框
  760. * @param url
  761. * @param title
  762. * @param options
  763. */
  764. function openIframeDialog(url, title, options) {
  765. Wind.css('artDialog');
  766. var params = {
  767. title: title,
  768. lock: true,
  769. opacity: 0,
  770. width: "95%",
  771. height: '90%'
  772. };
  773. params = options ? $.extend(params, options) : params;
  774. Wind.use('artDialog', 'iframeTools', function () {
  775. art.dialog.open(url, params);
  776. });
  777. }
  778. /**
  779. * 打开地图对话框
  780. *
  781. * @param url
  782. * @param title
  783. * @param options
  784. * @param callback
  785. */
  786. function openMapDialog(url, title, options, callback) {
  787. Wind.css('artDialog');
  788. var params = {
  789. title: title,
  790. lock: true,
  791. opacity: 0,
  792. width: "95%",
  793. height: 400,
  794. ok: function () {
  795. if (callback) {
  796. var d = this.iframe.contentWindow;
  797. var lng = $("#lng_input", d.document).val();
  798. var lat = $("#lat_input", d.document).val();
  799. var address = {};
  800. address.address = $("#address_input", d.document).val();
  801. address.province = $("#province_input", d.document).val();
  802. address.city = $("#city_input", d.document).val();
  803. address.district = $("#district_input", d.document).val();
  804. callback.apply(this, [lng, lat, address]);
  805. }
  806. }
  807. };
  808. params = options ? $.extend(params, options) : params;
  809. Wind.use('artDialog', 'iframeTools', function () {
  810. art.dialog.open(url, params);
  811. });
  812. }
  813. /**
  814. * 打开文件上传对话框
  815. * @param dialog_title 对话框标题
  816. * @param callback 回调方法,参数有(当前dialog对象,选择的文件数组,你设置的extra_params)
  817. * @param extra_params 额外参数,object
  818. * @param multi 是否可以多选
  819. * @param filetype 文件类型,image,video,audio,file
  820. * @param app 应用名,CMF的应用名
  821. */
  822. function openUploadDialog(dialog_title, callback, extra_params, multi, filetype, app) {
  823. Wind.css('artDialog');
  824. multi = multi ? 1 : 0;
  825. filetype = filetype ? filetype : 'image';
  826. app = app ? app : GV.APP;
  827. var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app;
  828. openIframeLayer(GV.ROOT + 'user/Asset/webuploader?' + params, dialog_title, {
  829. btn: ['确定'],
  830. area: ['600px', '450px'],
  831. yes: function (index, layero) {
  832. if (typeof callback == 'function') {
  833. var body = layer.getChildFrame('body', index);
  834. //得到iframe页的窗口对象,执行iframe页的方法:iframeWin.method();
  835. var iframeWin = window[layero.find('iframe')[0]['name']];
  836. var files = iframeWin.get_selected_files();
  837. console.log("openUploadDialog");
  838. console.log(files);
  839. if (files && files.length > 0) {
  840. callback.apply(this, [this, files, extra_params]);
  841. layer.close(index);
  842. } else {
  843. // return false;
  844. }
  845. }
  846. }
  847. })
  848. return;
  849. Wind.use("artDialog", "iframeTools", function () {
  850. art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
  851. title: dialog_title,
  852. id: new Date().getTime(),
  853. width: '600px',
  854. height: '350px',
  855. lock: true,
  856. fixed: true,
  857. background: "#CCCCCC",
  858. opacity: 0,
  859. ok: function () {
  860. if (typeof callback == 'function') {
  861. var iframewindow = this.iframe.contentWindow;
  862. var files = iframewindow.get_selected_files();
  863. console.log(files);
  864. if (files && files.length > 0) {
  865. callback.apply(this, [this, files, extra_params]);
  866. } else {
  867. return false;
  868. }
  869. }
  870. },
  871. cancel: true
  872. });
  873. });
  874. }
  875. /**
  876. * 单个文件上传
  877. * @param dialog_title 上传对话框标题
  878. * @param input_selector 图片容器
  879. * @param filetype 文件类型,image,video,audio,file
  880. * @param extra_params 额外参数,object
  881. * @param app 应用名,CMF的应用名
  882. */
  883. function uploadOne(dialog_title, input_selector, filetype, extra_params, app) {
  884. filetype = filetype ? filetype : 'file';
  885. openUploadDialog(dialog_title, function (dialog, files) {
  886. $(input_selector).val(files[0].filepath);
  887. $(input_selector + '-preview').attr('href', files[0].preview_url);
  888. $(input_selector + '-name').val(files[0].name);
  889. $(input_selector + '-name-text').text(files[0].name);
  890. }, extra_params, 0, filetype, app);
  891. }
  892. /**
  893. * 单个图片上传
  894. * @param dialog_title 上传对话框标题
  895. * @param input_selector 图片容器
  896. * @param extra_params 额外参数,object
  897. * @param app 应用名,CMF的应用名
  898. */
  899. function uploadOneImage(dialog_title, input_selector, extra_params, app) {
  900. openUploadDialog(dialog_title, function (dialog, files) {
  901. $(input_selector).val(files[0].filepath);
  902. $(input_selector + '-preview').attr('src', files[0].preview_url);
  903. $(input_selector + '-name').val(files[0].name);
  904. $(input_selector + '-name-text').text(files[0].name);
  905. }, extra_params, 0, 'image', app);
  906. }
  907. /**
  908. * 多图上传
  909. * @param dialog_title 上传对话框标题
  910. * @param container_selector 图片容器
  911. * @param item_tpl_wrapper_id 单个图片html模板容器id
  912. * @param extra_params 额外参数,object
  913. * @param app 应用名,CMF 的应用名
  914. */
  915. function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) {
  916. openUploadDialog(dialog_title, function (dialog, files) {
  917. var tpl = $('#' + item_tpl_wrapper_id).html();
  918. var html = '';
  919. $.each(files, function (i, item) {
  920. var itemtpl = tpl;
  921. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  922. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  923. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  924. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  925. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  926. html += itemtpl;
  927. });
  928. $(container_selector).append(html);
  929. }, extra_params, 1, 'image', app);
  930. }
  931. /**
  932. * 多文件上传
  933. * @param dialog_title 上传对话框标题
  934. * @param container_selector 图片容器
  935. * @param item_tpl_wrapper_id 单个图片html模板容器id
  936. * @param filetype 文件类型,image,video,audio,file
  937. * @param extra_params 额外参数,object
  938. * @param app 应用名,CMF 的应用名
  939. */
  940. function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app) {
  941. filetype = filetype ? filetype : 'file';
  942. openUploadDialog(dialog_title, function (dialog, files) {
  943. var tpl = $('#' + item_tpl_wrapper_id).html();
  944. var html = '';
  945. $.each(files, function (i, item) {
  946. var itemtpl = tpl;
  947. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  948. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  949. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  950. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  951. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  952. html += itemtpl;
  953. });
  954. $(container_selector).append(html);
  955. }, extra_params, 1, filetype, app);
  956. }
  957. /**
  958. * 查看图片对话框
  959. * @param img 图片地址
  960. */
  961. function imagePreviewDialog(img) {
  962. Wind.css('layer');
  963. Wind.use("layer", function () {
  964. layer.photos({
  965. photos: {
  966. "title": "", //相册标题
  967. "id": 'image_preview', //相册id
  968. "start": 0, //初始显示的图片序号,默认0
  969. "data": [ //相册包含的图片,数组格式
  970. {
  971. "alt": "",
  972. "pid": 666, //图片id
  973. "src": img, //原图地址
  974. "thumb": img //缩略图地址
  975. }
  976. ]
  977. } //格式见API文档手册页
  978. , anim: 5, //0-6的选择,指定弹出图片动画类型,默认随机
  979. shadeClose: true,
  980. // skin: 'layui-layer-nobg',
  981. shade: [0.5, '#000000'],
  982. shadeClose: true,
  983. })
  984. });
  985. }
  986. function artdialogAlert(msg) {
  987. Wind.css('artDialog');
  988. Wind.use("artDialog", function () {
  989. art.dialog({
  990. id: new Date().getTime(),
  991. icon: "error",
  992. fixed: true,
  993. lock: true,
  994. background: "#CCCCCC",
  995. opacity: 0,
  996. content: msg,
  997. ok: function () {
  998. return true;
  999. }
  1000. });
  1001. });
  1002. }
  1003. function openIframeLayer(url, title, options) {
  1004. var params = {
  1005. type: 2,
  1006. title: title,
  1007. shadeClose: true,
  1008. // skin: 'layui-layer-nobg',
  1009. anim: -1,
  1010. shade: [0.001, '#000000'],
  1011. shadeClose: true,
  1012. area: ['95%', '90%'],
  1013. move: false,
  1014. content: url,
  1015. yes: function (index, layero) {
  1016. //do something
  1017. layer.close(index); //如果设定了yes回调,需进行手工关闭
  1018. }
  1019. };
  1020. params = options ? $.extend(params, options) : params;
  1021. Wind.css('layer');
  1022. Wind.use("layer", function () {
  1023. layer.open(params);
  1024. });
  1025. }