admin.js 43 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132
  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(files);
  838. if (files && files.length > 0) {
  839. callback.apply(this, [this, files, extra_params]);
  840. layer.close(index);
  841. } else {
  842. // return false;
  843. }
  844. }
  845. }
  846. })
  847. return;
  848. Wind.use("artDialog", "iframeTools", function () {
  849. art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
  850. title: dialog_title,
  851. id: new Date().getTime(),
  852. width: '600px',
  853. height: '350px',
  854. lock: true,
  855. fixed: true,
  856. background: "#CCCCCC",
  857. opacity: 0,
  858. ok: function () {
  859. if (typeof callback == 'function') {
  860. var iframewindow = this.iframe.contentWindow;
  861. var files = iframewindow.get_selected_files();
  862. console.log(files);
  863. if (files && files.length > 0) {
  864. callback.apply(this, [this, files, extra_params]);
  865. } else {
  866. return false;
  867. }
  868. }
  869. },
  870. cancel: true
  871. });
  872. });
  873. }
  874. /**
  875. * 单个文件上传
  876. * @param dialog_title 上传对话框标题
  877. * @param input_selector 图片容器
  878. * @param filetype 文件类型,image,video,audio,file
  879. * @param extra_params 额外参数,object
  880. * @param app 应用名,CMF的应用名
  881. */
  882. function uploadOne(dialog_title, input_selector, filetype, extra_params, app) {
  883. filetype = filetype ? filetype : 'file';
  884. openUploadDialog(dialog_title, function (dialog, files) {
  885. $(input_selector).val(files[0].filepath);
  886. $(input_selector + '-preview').attr('href', files[0].preview_url);
  887. $(input_selector + '-name').val(files[0].name);
  888. $(input_selector + '-name-text').text(files[0].name);
  889. }, extra_params, 0, filetype, app);
  890. }
  891. /**
  892. * 单个图片上传
  893. * @param dialog_title 上传对话框标题
  894. * @param input_selector 图片容器
  895. * @param extra_params 额外参数,object
  896. * @param app 应用名,CMF的应用名
  897. */
  898. function uploadOneImage(dialog_title, input_selector, extra_params, app) {
  899. openUploadDialog(dialog_title, function (dialog, files) {
  900. $(input_selector).val(files[0].filepath);
  901. $(input_selector + '-preview').attr('src', files[0].preview_url);
  902. $(input_selector + '-name').val(files[0].name);
  903. $(input_selector + '-name-text').text(files[0].name);
  904. }, extra_params, 0, 'image', app);
  905. }
  906. /**
  907. * 多图上传
  908. * @param dialog_title 上传对话框标题
  909. * @param container_selector 图片容器
  910. * @param item_tpl_wrapper_id 单个图片html模板容器id
  911. * @param extra_params 额外参数,object
  912. * @param app 应用名,CMF 的应用名
  913. */
  914. function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) {
  915. openUploadDialog(dialog_title, function (dialog, files) {
  916. var tpl = $('#' + item_tpl_wrapper_id).html();
  917. var html = '';
  918. $.each(files, function (i, item) {
  919. var itemtpl = tpl;
  920. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  921. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  922. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  923. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  924. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  925. html += itemtpl;
  926. });
  927. $(container_selector).append(html);
  928. }, extra_params, 1, 'image', app);
  929. }
  930. /**
  931. * 多文件上传
  932. * @param dialog_title 上传对话框标题
  933. * @param container_selector 图片容器
  934. * @param item_tpl_wrapper_id 单个图片html模板容器id
  935. * @param filetype 文件类型,image,video,audio,file
  936. * @param extra_params 额外参数,object
  937. * @param app 应用名,CMF 的应用名
  938. */
  939. function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app) {
  940. filetype = filetype ? filetype : 'file';
  941. openUploadDialog(dialog_title, function (dialog, files) {
  942. var tpl = $('#' + item_tpl_wrapper_id).html();
  943. var html = '';
  944. $.each(files, function (i, item) {
  945. var itemtpl = tpl;
  946. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  947. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  948. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  949. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  950. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  951. html += itemtpl;
  952. });
  953. $(container_selector).append(html);
  954. }, extra_params, 1, filetype, app);
  955. }
  956. /**
  957. * 查看图片对话框
  958. * @param img 图片地址
  959. */
  960. function imagePreviewDialog(img) {
  961. Wind.css('layer');
  962. Wind.use("layer", function () {
  963. layer.photos({
  964. photos: {
  965. "title": "", //相册标题
  966. "id": 'image_preview', //相册id
  967. "start": 0, //初始显示的图片序号,默认0
  968. "data": [ //相册包含的图片,数组格式
  969. {
  970. "alt": "",
  971. "pid": 666, //图片id
  972. "src": img, //原图地址
  973. "thumb": img //缩略图地址
  974. }
  975. ]
  976. } //格式见API文档手册页
  977. , anim: 5, //0-6的选择,指定弹出图片动画类型,默认随机
  978. shadeClose: true,
  979. // skin: 'layui-layer-nobg',
  980. shade: [0.5, '#000000'],
  981. shadeClose: true,
  982. })
  983. });
  984. }
  985. function artdialogAlert(msg) {
  986. Wind.css('artDialog');
  987. Wind.use("artDialog", function () {
  988. art.dialog({
  989. id: new Date().getTime(),
  990. icon: "error",
  991. fixed: true,
  992. lock: true,
  993. background: "#CCCCCC",
  994. opacity: 0,
  995. content: msg,
  996. ok: function () {
  997. return true;
  998. }
  999. });
  1000. });
  1001. }
  1002. function openIframeLayer(url, title, options) {
  1003. var params = {
  1004. type: 2,
  1005. title: title,
  1006. shadeClose: true,
  1007. // skin: 'layui-layer-nobg',
  1008. anim: -1,
  1009. shade: [0.001, '#000000'],
  1010. shadeClose: true,
  1011. area: ['95%', '90%'],
  1012. move: false,
  1013. content: url,
  1014. yes: function (index, layero) {
  1015. //do something
  1016. layer.close(index); //如果设定了yes回调,需进行手工关闭
  1017. }
  1018. };
  1019. params = options ? $.extend(params, options) : params;
  1020. Wind.css('layer');
  1021. Wind.use("layer", function () {
  1022. layer.open(params);
  1023. });
  1024. }