admin.js 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076
  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. console.log(files);
  811. if (files && files.length > 0) {
  812. callback.apply(this, [this, files, extra_params]);
  813. } else {
  814. return false;
  815. }
  816. }
  817. },
  818. cancel: true
  819. });
  820. });
  821. }
  822. /**
  823. * 单个文件上传
  824. * @param dialog_title 上传对话框标题
  825. * @param input_selector 图片容器
  826. * @param filetype 文件类型,image,video,audio,file
  827. * @param extra_params 额外参数,object
  828. * @param app 应用名,CMF的应用名
  829. */
  830. function uploadOne(dialog_title, input_selector, filetype, extra_params, app) {
  831. filetype = filetype ? filetype : 'file';
  832. openUploadDialog(dialog_title, function (dialog, files) {
  833. $(input_selector).val(files[0].filepath);
  834. $(input_selector + '-preview').attr('href', files[0].preview_url);
  835. $(input_selector + '-name').val(files[0].name);
  836. $(input_selector + '-name-text').text(files[0].name);
  837. }, extra_params, 0, filetype, app);
  838. }
  839. /**
  840. * 单个图片上传
  841. * @param dialog_title 上传对话框标题
  842. * @param input_selector 图片容器
  843. * @param extra_params 额外参数,object
  844. * @param app 应用名,CMF的应用名
  845. */
  846. function uploadOneImage(dialog_title, input_selector, extra_params, app) {
  847. openUploadDialog(dialog_title, function (dialog, files) {
  848. $(input_selector).val(files[0].filepath);
  849. $(input_selector + '-preview').attr('src', files[0].preview_url);
  850. $(input_selector + '-name').val(files[0].name);
  851. $(input_selector + '-name-text').text(files[0].name);
  852. }, extra_params, 0, 'image', app);
  853. }
  854. /**
  855. * 多图上传
  856. * @param dialog_title 上传对话框标题
  857. * @param container_selector 图片容器
  858. * @param item_tpl_wrapper_id 单个图片html模板容器id
  859. * @param extra_params 额外参数,object
  860. * @param app 应用名,CMF 的应用名
  861. */
  862. function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) {
  863. openUploadDialog(dialog_title, function (dialog, files) {
  864. var tpl = $('#' + item_tpl_wrapper_id).html();
  865. var html = '';
  866. $.each(files, function (i, item) {
  867. var itemtpl = tpl;
  868. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  869. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  870. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  871. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  872. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  873. html += itemtpl;
  874. });
  875. $(container_selector).append(html);
  876. }, extra_params, 1, 'image', app);
  877. }
  878. /**
  879. * 多文件上传
  880. * @param dialog_title 上传对话框标题
  881. * @param container_selector 图片容器
  882. * @param item_tpl_wrapper_id 单个图片html模板容器id
  883. * @param filetype 文件类型,image,video,audio,file
  884. * @param extra_params 额外参数,object
  885. * @param app 应用名,CMF 的应用名
  886. */
  887. function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app) {
  888. filetype = filetype ? filetype : 'file';
  889. openUploadDialog(dialog_title, function (dialog, files) {
  890. var tpl = $('#' + item_tpl_wrapper_id).html();
  891. var html = '';
  892. $.each(files, function (i, item) {
  893. var itemtpl = tpl;
  894. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  895. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  896. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  897. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  898. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  899. html += itemtpl;
  900. });
  901. $(container_selector).append(html);
  902. }, extra_params, 1, filetype, app);
  903. }
  904. /**
  905. * 查看图片对话框
  906. * @param img 图片地址
  907. */
  908. function imagePreviewDialog(img) {
  909. Wind.css('layer');
  910. Wind.use("layer", function () {
  911. layer.photos({
  912. photos: {
  913. "title": "", //相册标题
  914. "id": 'image_preview', //相册id
  915. "start": 0, //初始显示的图片序号,默认0
  916. "data": [ //相册包含的图片,数组格式
  917. {
  918. "alt": "",
  919. "pid": 666, //图片id
  920. "src": img, //原图地址
  921. "thumb": img //缩略图地址
  922. }
  923. ]
  924. } //格式见API文档手册页
  925. , anim: 5, //0-6的选择,指定弹出图片动画类型,默认随机
  926. shadeClose: true,
  927. // skin: 'layui-layer-nobg',
  928. shade: [0.5, '#000000'],
  929. shadeClose: true,
  930. })
  931. });
  932. }
  933. function artdialogAlert(msg) {
  934. Wind.css('artDialog');
  935. Wind.use("artDialog", function () {
  936. art.dialog({
  937. id: new Date().getTime(),
  938. icon: "error",
  939. fixed: true,
  940. lock: true,
  941. background: "#CCCCCC",
  942. opacity: 0,
  943. content: msg,
  944. ok: function () {
  945. return true;
  946. }
  947. });
  948. });
  949. }
  950. function openIframeLayer(url, title, options) {
  951. var params = {
  952. type: 2,
  953. title: title,
  954. shadeClose: true,
  955. // skin: 'layui-layer-nobg',
  956. anim: -1,
  957. shade: [0.001, '#000000'],
  958. shadeClose: true,
  959. area: ['95%', '90%'],
  960. move: false,
  961. content: url,
  962. yes: function (index, layero) {
  963. //do something
  964. layer.close(index); //如果设定了yes回调,需进行手工关闭
  965. }
  966. };
  967. params = options ? $.extend(params, options) : params;
  968. Wind.css('layer');
  969. Wind.use("layer", function () {
  970. layer.open(params);
  971. });
  972. }