admin.js 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075
  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. $.getJSON(href).done(function (data) {
  307. if (data.code == '1') {
  308. noty({
  309. text: data.msg,
  310. type: 'success',
  311. layout: 'topCenter',
  312. modal: true,
  313. // animation: {
  314. // open: 'animated bounceInDown', // Animate.css class names
  315. // close: 'animated bounceOutUp', // Animate.css class names
  316. // },
  317. timeout: 800,
  318. callback: {
  319. afterClose: function () {
  320. if (refresh == undefined || refresh) {
  321. if (data.url) {
  322. //返回带跳转地址
  323. window.location.href = data.url;
  324. } else {
  325. //刷新当前页
  326. reloadPage(window);
  327. }
  328. }
  329. }
  330. }
  331. }).show();
  332. } else if (data.code == '0') {
  333. //art.dialog.alert(data.info);
  334. //alert(data.info);//暂时处理方案
  335. art.dialog({
  336. content: data.msg,
  337. icon: 'warning',
  338. ok: function () {
  339. this.title(data.msg);
  340. return true;
  341. }
  342. });
  343. }
  344. });
  345. },
  346. cancelVal: '关闭',
  347. cancel: true
  348. });
  349. });
  350. });
  351. }
  352. if ($('a.js-ajax-dialog-btn').length) {
  353. Wind.use('artDialog', 'noty', function () {
  354. $('.js-ajax-dialog-btn').on('click', function (e) {
  355. e.preventDefault();
  356. var $_this = this,
  357. $this = $($_this),
  358. href = $this.data('href'),
  359. refresh = $this.data('refresh'),
  360. msg = $this.data('msg');
  361. href = href ? href : $this.attr('href');
  362. if (!msg) {
  363. msg = "您确定要进行此操作吗?";
  364. }
  365. art.dialog({
  366. title: false,
  367. icon: 'question',
  368. content: msg,
  369. follow: $_this,
  370. close: function () {
  371. $_this.focus(); //关闭时让触发弹窗的元素获取焦点
  372. return true;
  373. },
  374. ok: function () {
  375. $.ajax({
  376. url: href,
  377. type: 'post',
  378. success: function (data) {
  379. if (data.code == 1) {
  380. noty({
  381. text: data.msg,
  382. type: 'success',
  383. layout: 'topCenter',
  384. modal: true,
  385. // animation: {
  386. // open: 'animated bounceInDown', // Animate.css class names
  387. // close: 'animated bounceOutUp', // Animate.css class names
  388. // },
  389. timeout: 800,
  390. callback: {
  391. afterClose: function () {
  392. if (refresh == undefined || refresh) {
  393. if (data.url) {
  394. //返回带跳转地址
  395. window.location.href = data.url;
  396. } else {
  397. //刷新当前页
  398. reloadPage(window);
  399. }
  400. }
  401. }
  402. }
  403. }).show();
  404. } else if (data.code == 0) {
  405. //art.dialog.alert(data.info);
  406. art.dialog({
  407. content: data.msg,
  408. icon: 'warning',
  409. ok: function () {
  410. this.title(data.msg);
  411. return true;
  412. }
  413. });
  414. }
  415. }
  416. })
  417. },
  418. cancelVal: '关闭',
  419. cancel: true
  420. });
  421. });
  422. });
  423. }
  424. if ($('a.js-ajax-btn').length) {
  425. Wind.use('noty', function () {
  426. $('.js-ajax-btn').on('click', function (e) {
  427. e.preventDefault();
  428. var $_this = this,
  429. $this = $($_this),
  430. href = $this.data('href'),
  431. msg = $this.data('msg');
  432. refresh = $this.data('refresh');
  433. href = href ? href : $this.attr('href');
  434. refresh = refresh == undefined ? 1 : refresh;
  435. $.getJSON(href).done(function (data) {
  436. if (data.code == 1) {
  437. noty({
  438. text: data.msg,
  439. type: 'success',
  440. layout: 'center',
  441. callback: {
  442. afterClose: function () {
  443. if (data.url) {
  444. location.href = data.url;
  445. return;
  446. }
  447. if (refresh || refresh == undefined) {
  448. reloadPage(window);
  449. }
  450. }
  451. }
  452. });
  453. } else if (data.code == 0) {
  454. noty({
  455. text: data.msg,
  456. type: 'error',
  457. layout: 'center',
  458. callback: {
  459. afterClose: function () {
  460. if (data.url) {
  461. location.href = data.url;
  462. }
  463. }
  464. }
  465. });
  466. }
  467. });
  468. });
  469. });
  470. }
  471. /*复选框全选(支持多个,纵横双控全选)。
  472. *实例:版块编辑-权限相关(双控),验证机制-验证策略(单控)
  473. *说明:
  474. * "js-check"的"data-xid"对应其左侧"js-check-all"的"data-checklist";
  475. * "js-check"的"data-yid"对应其上方"js-check-all"的"data-checklist";
  476. * 全选框的"data-direction"代表其控制的全选方向(x或y);
  477. * "js-check-wrap"同一块全选操作区域的父标签class,多个调用考虑
  478. */
  479. if ($('.js-check-wrap').length) {
  480. var total_check_all = $('input.js-check-all');
  481. //遍历所有全选框
  482. $.each(total_check_all, function () {
  483. var check_all = $(this),
  484. check_items;
  485. //分组各纵横项
  486. var check_all_direction = check_all.data('direction');
  487. check_items = $('input.js-check[data-' + check_all_direction + 'id="' + check_all.data('checklist') + '"]').not(":disabled");
  488. if($('.js-check-all').is(':checked')) {
  489. check_items.prop('checked', true);
  490. }
  491. //点击全选框
  492. check_all.change(function (e) {
  493. var check_wrap = check_all.parents('.js-check-wrap'); //当前操作区域所有复选框的父标签(重用考虑)
  494. if ($(this).prop('checked')) {
  495. //全选状态
  496. check_items.prop('checked', true);
  497. //所有项都被选中
  498. if (check_wrap.find('input.js-check').length === check_wrap.find('input.js-check:checked').length) {
  499. check_wrap.find(total_check_all).prop('checked', true);
  500. }
  501. } else {
  502. //非全选状态
  503. check_items.removeProp('checked');
  504. check_wrap.find(total_check_all).removeProp('checked');
  505. //另一方向的全选框取消全选状态
  506. var direction_invert = check_all_direction === 'x' ? 'y' : 'x';
  507. check_wrap.find($('input.js-check-all[data-direction="' + direction_invert + '"]')).removeProp('checked');
  508. }
  509. });
  510. //点击非全选时判断是否全部勾选
  511. check_items.change(function () {
  512. if ($(this).prop('checked')) {
  513. if (check_items.filter(':checked').length === check_items.length) {
  514. //已选择和未选择的复选框数相等
  515. check_all.prop('checked', true);
  516. }
  517. } else {
  518. check_all.removeProp('checked');
  519. }
  520. });
  521. });
  522. }
  523. //日期选择器
  524. var dateInput = $("input.js-date");
  525. if (dateInput.length) {
  526. Wind.use('datePicker', function () {
  527. dateInput.datePicker();
  528. });
  529. }
  530. //日期+时间选择器
  531. var dateTimeInput = $("input.js-datetime");
  532. if (dateTimeInput.length) {
  533. Wind.use('datePicker', function () {
  534. dateTimeInput.datePicker({
  535. time: true
  536. });
  537. });
  538. }
  539. var yearInput = $("input.js-year");
  540. if (yearInput.length) {
  541. Wind.use('datePicker', function () {
  542. yearInput.datePicker({
  543. startView: 'decade',
  544. minView: 'decade',
  545. format: 'yyyy',
  546. autoclose: true
  547. });
  548. });
  549. }
  550. // bootstrap年选择器
  551. var bootstrapYearInput = $("input.js-bootstrap-year")
  552. if (bootstrapYearInput.length) {
  553. Wind.css('bootstrapDatetimePicker');
  554. Wind.use('bootstrapDatetimePicker', function () {
  555. bootstrapYearInput.datetimepicker({
  556. language: 'zh-CN',
  557. format: 'yyyy',
  558. minView: 'decade',
  559. startView: 'decade',
  560. todayBtn: 1,
  561. autoclose: true
  562. });
  563. });
  564. }
  565. // bootstrap日期选择器
  566. var bootstrapDateInput = $("input.js-bootstrap-date")
  567. if (bootstrapDateInput.length) {
  568. Wind.css('bootstrapDatetimePicker');
  569. Wind.use('bootstrapDatetimePicker', function () {
  570. bootstrapDateInput.datetimepicker({
  571. language: 'zh-CN',
  572. format: 'yyyy-mm-dd',
  573. minView: 'month',
  574. todayBtn: 1,
  575. autoclose: true
  576. });
  577. });
  578. }
  579. // bootstrap年月份选择器
  580. var bootstrapYearMonthInput = $("input.js-bootstrap-year-month");
  581. if (bootstrapYearMonthInput.length) {
  582. Wind.css('bootstrapDatetimePicker');
  583. Wind.use('bootstrapDatetimePicker', function () {
  584. bootstrapYearMonthInput.datetimepicker({
  585. language: 'zh-CN',
  586. format: 'yyyy-mm',
  587. minView: 'year',
  588. startView: 'decade',
  589. todayBtn: 1,
  590. autoclose: true
  591. });
  592. });
  593. }
  594. // bootstrap日期选择器日期+时间选择器
  595. var bootstrapDateTimeInput = $("input.js-bootstrap-datetime");
  596. if (bootstrapDateTimeInput.length) {
  597. Wind.css('bootstrapDatetimePicker');
  598. Wind.use('bootstrapDatetimePicker', function () {
  599. bootstrapDateTimeInput.datetimepicker({
  600. language: 'zh-CN',
  601. format: 'yyyy-mm-dd hh:ii',
  602. todayBtn: 1,
  603. autoclose: true
  604. });
  605. });
  606. }
  607. //tab
  608. var tabs_nav = $('ul.js-tabs-nav');
  609. if (tabs_nav.length) {
  610. Wind.use('tabs', function () {
  611. tabs_nav.tabs('.js-tabs-content > div');
  612. });
  613. }
  614. //地址联动
  615. var $js_address_select = $('.js-address-select');
  616. if ($js_address_select.length > 0) {
  617. $('.js-address-province-select,.js-address-city-select').change(function () {
  618. var $this = $(this);
  619. var id = $this.val();
  620. var $child_area_select;
  621. var $this_js_address_select = $this.parents('.js-address-select');
  622. if ($this.is('.js-address-province-select')) {
  623. $child_area_select = $this_js_address_select.find('.js-address-city-select');
  624. $this_js_address_select.find('.js-address-district-select').hide();
  625. } else {
  626. $child_area_select = $this_js_address_select.find('.js-address-district-select');
  627. }
  628. var empty_option = '<option class="js-address-empty-option" value="">' + $child_area_select.find('.js-address-empty-option').text() + '</option>';
  629. $child_area_select.html(empty_option);
  630. var child_area_html = $this.data('childarea' + id);
  631. if (child_area_html) {
  632. $child_area_select.show();
  633. $child_area_select.html(child_area_html);
  634. return;
  635. }
  636. $.ajax({
  637. url: $this_js_address_select.data('url'),
  638. type: 'POST',
  639. dataType: 'JSON',
  640. data: {id: id},
  641. success: function (data) {
  642. if (data.code == 1) {
  643. if (data.data.areas.length > 0) {
  644. var html = [empty_option];
  645. $.each(data.data.areas, function (i, area) {
  646. var area_html = '<option value="[id]">[name]</option>';
  647. area_html = area_html.replace('[name]', area.name);
  648. area_html = area_html.replace('[id]', area.id);
  649. html.push(area_html);
  650. });
  651. html = html.join('', html);
  652. $this.data('childarea' + id, html);
  653. $child_area_select.html(html);
  654. $child_area_select.show();
  655. } else {
  656. $child_area_select.hide();
  657. }
  658. }
  659. },
  660. error: function () {
  661. },
  662. complete: function () {
  663. }
  664. });
  665. });
  666. }
  667. //地址联动end
  668. })();
  669. //重新刷新页面,使用location.reload()有可能导致重新提交
  670. function reloadPage(win) {
  671. var location = win.location;
  672. location.href = location.pathname + location.search;
  673. }
  674. /**
  675. * 页面跳转
  676. * @param url 要打开的页面地址
  677. */
  678. function redirect(url) {
  679. location.href = url;
  680. }
  681. /**
  682. * 读取cookie
  683. * @param name
  684. * @returns
  685. */
  686. function getCookie(name) {
  687. var cookieValue = null;
  688. if (document.cookie && document.cookie != '') {
  689. var cookies = document.cookie.split(';');
  690. for (var i = 0; i < cookies.length; i++) {
  691. var cookie = jQuery.trim(cookies[i]);
  692. // Does this cookie string begin with the name we want?
  693. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  694. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  695. break;
  696. }
  697. }
  698. }
  699. return cookieValue;
  700. }
  701. /**
  702. * 设置cookie
  703. */
  704. function setCookie(name, value, options) {
  705. options = options || {};
  706. if (value === null) {
  707. value = '';
  708. options.expires = -1;
  709. }
  710. var expires = '';
  711. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  712. var date;
  713. if (typeof options.expires == 'number') {
  714. date = new Date();
  715. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  716. } else {
  717. date = options.expires;
  718. }
  719. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  720. }
  721. var path = options.path ? '; path=' + options.path : '';
  722. var domain = options.domain ? '; domain=' + options.domain : '';
  723. var secure = options.secure ? '; secure' : '';
  724. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  725. }
  726. /**
  727. * 打开iframe式的窗口对话框
  728. * @param url
  729. * @param title
  730. * @param options
  731. */
  732. function openIframeDialog(url, title, options) {
  733. Wind.css('artDialog');
  734. var params = {
  735. title: title,
  736. lock: true,
  737. opacity: 0,
  738. width: "95%",
  739. height: '90%'
  740. };
  741. params = options ? $.extend(params, options) : params;
  742. Wind.use('artDialog', 'iframeTools', function () {
  743. art.dialog.open(url, params);
  744. });
  745. }
  746. /**
  747. * 打开地图对话框
  748. *
  749. * @param url
  750. * @param title
  751. * @param options
  752. * @param callback
  753. */
  754. function openMapDialog(url, title, options, callback) {
  755. Wind.css('artDialog');
  756. var params = {
  757. title: title,
  758. lock: true,
  759. opacity: 0,
  760. width: "95%",
  761. height: 400,
  762. ok: function () {
  763. if (callback) {
  764. var d = this.iframe.contentWindow;
  765. var lng = $("#lng_input", d.document).val();
  766. var lat = $("#lat_input", d.document).val();
  767. var address = {};
  768. address.address = $("#address_input", d.document).val();
  769. address.province = $("#province_input", d.document).val();
  770. address.city = $("#city_input", d.document).val();
  771. address.district = $("#district_input", d.document).val();
  772. callback.apply(this, [lng, lat, address]);
  773. }
  774. }
  775. };
  776. params = options ? $.extend(params, options) : params;
  777. Wind.use('artDialog', 'iframeTools', function () {
  778. art.dialog.open(url, params);
  779. });
  780. }
  781. /**
  782. * 打开文件上传对话框
  783. * @param dialog_title 对话框标题
  784. * @param callback 回调方法,参数有(当前dialog对象,选择的文件数组,你设置的extra_params)
  785. * @param extra_params 额外参数,object
  786. * @param multi 是否可以多选
  787. * @param filetype 文件类型,image,video,audio,file
  788. * @param app 应用名,CMF的应用名
  789. */
  790. function openUploadDialog(dialog_title, callback, extra_params, multi, filetype, app) {
  791. Wind.css('artDialog');
  792. multi = multi ? 1 : 0;
  793. filetype = filetype ? filetype : 'image';
  794. app = app ? app : GV.APP;
  795. var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app;
  796. Wind.use("artDialog", "iframeTools", function () {
  797. art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
  798. title: dialog_title,
  799. id: new Date().getTime(),
  800. width: '600px',
  801. height: '350px',
  802. lock: true,
  803. fixed: true,
  804. background: "#CCCCCC",
  805. opacity: 0,
  806. ok: function () {
  807. if (typeof callback == 'function') {
  808. var iframewindow = this.iframe.contentWindow;
  809. var files = iframewindow.get_selected_files();
  810. if (files && files.length > 0) {
  811. callback.apply(this, [this, files, extra_params]);
  812. } else {
  813. return false;
  814. }
  815. }
  816. },
  817. cancel: true
  818. });
  819. });
  820. }
  821. /**
  822. * 单个文件上传
  823. * @param dialog_title 上传对话框标题
  824. * @param input_selector 图片容器
  825. * @param filetype 文件类型,image,video,audio,file
  826. * @param extra_params 额外参数,object
  827. * @param app 应用名,CMF的应用名
  828. */
  829. function uploadOne(dialog_title, input_selector, filetype, extra_params, app) {
  830. filetype = filetype ? filetype : 'file';
  831. openUploadDialog(dialog_title, function (dialog, files) {
  832. $(input_selector).val(files[0].filepath);
  833. $(input_selector + '-preview').attr('href', files[0].preview_url);
  834. $(input_selector + '-name').val(files[0].name);
  835. $(input_selector + '-name-text').text(files[0].name);
  836. }, extra_params, 0, filetype, app);
  837. }
  838. /**
  839. * 单个图片上传
  840. * @param dialog_title 上传对话框标题
  841. * @param input_selector 图片容器
  842. * @param extra_params 额外参数,object
  843. * @param app 应用名,CMF的应用名
  844. */
  845. function uploadOneImage(dialog_title, input_selector, extra_params, app) {
  846. openUploadDialog(dialog_title, function (dialog, files) {
  847. $(input_selector).val(files[0].filepath);
  848. $(input_selector + '-preview').attr('src', files[0].preview_url);
  849. $(input_selector + '-name').val(files[0].name);
  850. $(input_selector + '-name-text').text(files[0].name);
  851. }, extra_params, 0, 'image', app);
  852. }
  853. /**
  854. * 多图上传
  855. * @param dialog_title 上传对话框标题
  856. * @param container_selector 图片容器
  857. * @param item_tpl_wrapper_id 单个图片html模板容器id
  858. * @param extra_params 额外参数,object
  859. * @param app 应用名,CMF 的应用名
  860. */
  861. function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) {
  862. openUploadDialog(dialog_title, function (dialog, files) {
  863. var tpl = $('#' + item_tpl_wrapper_id).html();
  864. var html = '';
  865. $.each(files, function (i, item) {
  866. var itemtpl = tpl;
  867. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  868. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  869. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  870. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  871. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  872. html += itemtpl;
  873. });
  874. $(container_selector).append(html);
  875. }, extra_params, 1, 'image', app);
  876. }
  877. /**
  878. * 多文件上传
  879. * @param dialog_title 上传对话框标题
  880. * @param container_selector 图片容器
  881. * @param item_tpl_wrapper_id 单个图片html模板容器id
  882. * @param filetype 文件类型,image,video,audio,file
  883. * @param extra_params 额外参数,object
  884. * @param app 应用名,CMF 的应用名
  885. */
  886. function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app) {
  887. filetype = filetype ? filetype : 'file';
  888. openUploadDialog(dialog_title, function (dialog, files) {
  889. var tpl = $('#' + item_tpl_wrapper_id).html();
  890. var html = '';
  891. $.each(files, function (i, item) {
  892. var itemtpl = tpl;
  893. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  894. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  895. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  896. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  897. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  898. html += itemtpl;
  899. });
  900. $(container_selector).append(html);
  901. }, extra_params, 1, filetype, app);
  902. }
  903. /**
  904. * 查看图片对话框
  905. * @param img 图片地址
  906. */
  907. function imagePreviewDialog(img) {
  908. Wind.css('layer');
  909. Wind.use("layer", function () {
  910. layer.photos({
  911. photos: {
  912. "title": "", //相册标题
  913. "id": 'image_preview', //相册id
  914. "start": 0, //初始显示的图片序号,默认0
  915. "data": [ //相册包含的图片,数组格式
  916. {
  917. "alt": "",
  918. "pid": 666, //图片id
  919. "src": img, //原图地址
  920. "thumb": img //缩略图地址
  921. }
  922. ]
  923. } //格式见API文档手册页
  924. , anim: 5, //0-6的选择,指定弹出图片动画类型,默认随机
  925. shadeClose: true,
  926. // skin: 'layui-layer-nobg',
  927. shade: [0.5, '#000000'],
  928. shadeClose: true,
  929. })
  930. });
  931. }
  932. function artdialogAlert(msg) {
  933. Wind.css('artDialog');
  934. Wind.use("artDialog", function () {
  935. art.dialog({
  936. id: new Date().getTime(),
  937. icon: "error",
  938. fixed: true,
  939. lock: true,
  940. background: "#CCCCCC",
  941. opacity: 0,
  942. content: msg,
  943. ok: function () {
  944. return true;
  945. }
  946. });
  947. });
  948. }
  949. function openIframeLayer(url, title, options) {
  950. var params = {
  951. type: 2,
  952. title: title,
  953. shadeClose: true,
  954. // skin: 'layui-layer-nobg',
  955. anim: -1,
  956. shade: [0.001, '#000000'],
  957. shadeClose: true,
  958. area: ['95%', '90%'],
  959. move: false,
  960. content: url,
  961. yes: function (index, layero) {
  962. //do something
  963. layer.close(index); //如果设定了yes回调,需进行手工关闭
  964. }
  965. };
  966. params = options ? $.extend(params, options) : params;
  967. Wind.css('layer');
  968. Wind.use("layer", function () {
  969. layer.open(params);
  970. });
  971. }