frontend.js 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366
  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.use('artDialog', 'iframeTools', function () {
  43. $('.js-dialog').on('click', function (e) {
  44. e.preventDefault();
  45. var $_this = this,
  46. _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.use('ajaxForm', 'noty', 'validate', function () {
  61. //var form = btn.parents('form.js-ajax-form');
  62. var $btn;
  63. $('button.js-ajax-submit').on('click', function (e) {
  64. //e.preventDefault();
  65. /*var btn = $(this).find('button.js-ajax-submit'),
  66. form = $(this);*/
  67. var btn = $(this), form = btn.parents('form.js-ajax-form');
  68. $btn = btn;
  69. if (btn.data("loading")) {
  70. return false;
  71. }
  72. //批量操作 判断选项
  73. if (btn.data('subcheck')) {
  74. btn.parent().find('span').remove();
  75. if (form.find('input.js-check:checked').length) {
  76. var msg = btn.data('msg');
  77. if (msg) {
  78. noty({
  79. text: msg,
  80. type: 'confirm',
  81. layout: "center",
  82. timeout: false,
  83. modal: true,
  84. buttons: [
  85. {
  86. addClass: 'btn btn-primary',
  87. text: '确定',
  88. onClick: function ($noty) {
  89. $noty.close();
  90. btn.data('subcheck', false);
  91. btn.click();
  92. }
  93. },
  94. {
  95. addClass: 'btn btn-danger',
  96. text: '取消',
  97. onClick: function ($noty) {
  98. $noty.close();
  99. }
  100. }
  101. ]
  102. });
  103. } else {
  104. btn.data('subcheck', false);
  105. btn.click();
  106. }
  107. } else {
  108. noty({
  109. text: "请至少选择一项",
  110. type: 'error',
  111. layout: 'center'
  112. });
  113. }
  114. return false;
  115. }
  116. //ie处理placeholder提交问题
  117. if ($.browser && $.browser.msie) {
  118. form.find('[placeholder]').each(function () {
  119. var input = $(this);
  120. if (input.val() == input.attr('placeholder')) {
  121. input.val('');
  122. }
  123. });
  124. }
  125. });
  126. ajaxForm_list.each(function () {
  127. $(this).validate({
  128. //是否在获取焦点时验证
  129. //onfocusout : false,
  130. //是否在敲击键盘时验证
  131. //onkeyup : false,
  132. //当鼠标点击时验证
  133. //onclick : false,
  134. //给未通过验证的元素加效果,闪烁等
  135. highlight: function (element, errorClass, validClass) {
  136. if (element.type === "radio") {
  137. this.findByName(element.name).addClass(errorClass).removeClass(validClass);
  138. } else {
  139. var $element = $(element);
  140. $element.addClass(errorClass).removeClass(validClass);
  141. $element.parent().addClass("has-error");//bootstrap3表单
  142. $element.parents('.control-group').addClass("error");//bootstrap2表单
  143. }
  144. },
  145. unhighlight: function (element, errorClass, validClass) {
  146. if (element.type === "radio") {
  147. this.findByName(element.name).removeClass(errorClass).addClass(validClass);
  148. } else {
  149. var $element = $(element);
  150. $element.removeClass(errorClass).addClass(validClass);
  151. $element.parent().removeClass("has-error");//bootstrap3表单
  152. $element.parents('.control-group').removeClass("error");//bootstrap2表单
  153. }
  154. },
  155. showErrors: function (errorMap, errorArr) {
  156. var i, elements, error;
  157. for (i = 0; this.errorList[i]; i++) {
  158. error = this.errorList[i];
  159. if (this.settings.highlight) {
  160. this.settings.highlight.call(this, error.element, this.settings.errorClass, this.settings.validClass);
  161. }
  162. //this.showLabel( error.element, error.message );
  163. }
  164. if (this.errorList.length) {
  165. //this.toShow = this.toShow.add( this.containers );
  166. }
  167. if (this.settings.success) {
  168. for (i = 0; this.successList[i]; i++) {
  169. //this.showLabel( this.successList[ i ] );
  170. }
  171. }
  172. if (this.settings.unhighlight) {
  173. for (i = 0, elements = this.validElements(); elements[i]; i++) {
  174. this.settings.unhighlight.call(this, elements[i], this.settings.errorClass, this.settings.validClass);
  175. }
  176. }
  177. this.toHide = this.toHide.not(this.toShow);
  178. this.hideErrors();
  179. this.addWrapper(this.toShow).show();
  180. },
  181. submitHandler: function (form) {
  182. var $form = $(form);
  183. if(!$btn){
  184. $btn=$form.find('button.js-ajax-submit');
  185. }
  186. $form.ajaxSubmit({
  187. url: $btn && $btn.data('action') ? $btn.data('action') : $form.attr('action'), //按钮上是否自定义提交地址(多按钮情况)
  188. dataType: 'json',
  189. beforeSubmit: function (arr, $form, options) {
  190. if($btn){
  191. $btn.data("loading", true);
  192. var text = $btn.text();
  193. //按钮文案、状态修改
  194. $btn.text(text + '...').prop('disabled', true).addClass('disabled');
  195. }
  196. },
  197. success: function (data, statusText, xhr, $form) {
  198. function _refresh() {
  199. if (data.url) {
  200. if (window.parent.art) {
  201. //iframe弹出页
  202. window.parent.location.href = data.url;
  203. } else {
  204. window.location.href = data.url;
  205. }
  206. } else {
  207. if (data.code == 1) {
  208. var wait = $btn.data("wait");
  209. if (window.parent.art) {
  210. reloadPage(window.parent);
  211. } else {
  212. //刷新当前页
  213. reloadPage(window);
  214. }
  215. }
  216. }
  217. }
  218. var text = $btn.text();
  219. //按钮文案、状态修改
  220. $btn.removeClass('disabled').prop('disabled', false).text(text.replace('...', '')).parent().find('span').remove();
  221. if (data.code == 1) {
  222. if ($btn.data('success')) {
  223. var successCallback = $btn.data('success');
  224. window[successCallback](data, statusText, xhr, $form);
  225. return;
  226. }
  227. noty({
  228. text: data.msg,
  229. type: 'success',
  230. layout: 'center',
  231. modal: true,
  232. callback: {
  233. afterClose: function () {
  234. _refresh();
  235. }
  236. }
  237. });
  238. } else if (data.code == 0) {
  239. if ($btn.data('error')) {
  240. var errorCallback = $btn.data('error');
  241. window[errorCallback](data, statusText, xhr, $form);
  242. return;
  243. }
  244. var $verify_img = $form.find(".verify_img");
  245. if ($verify_img.length) {
  246. $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random());
  247. }
  248. var $verify_input = $form.find("[name='verify']");
  249. $verify_input.val("");
  250. noty({
  251. text: data.msg,
  252. type: 'error',
  253. layout: 'center',
  254. callback: {
  255. afterClose: function () {
  256. _refresh();
  257. }
  258. }
  259. });
  260. }
  261. },
  262. error: function (xhr, e, statusText) {
  263. noty({
  264. text: statusText,
  265. type: 'error',
  266. layout: 'center',
  267. callback: {
  268. // afterClose: function () {
  269. // if (window.parent.art) {
  270. // reloadPage(window.parent);
  271. // } else {
  272. // //刷新当前页
  273. // reloadPage(window);
  274. // }
  275. // }
  276. }
  277. });
  278. },
  279. complete: function () {
  280. $btn.data("loading", false);
  281. }
  282. });
  283. }
  284. });
  285. });
  286. });
  287. }
  288. //dialog弹窗内的关闭方法
  289. $('#js-dialog-close').on('click', function (e) {
  290. e.preventDefault();
  291. try {
  292. art.dialog.close();
  293. } catch (err) {
  294. Wind.use('artDialog', 'iframeTools', function () {
  295. art.dialog.close();
  296. });
  297. }
  298. ;
  299. });
  300. //所有的删除操作,删除数据后刷新页面
  301. if ($('a.js-ajax-delete').length) {
  302. Wind.use('noty', function () {
  303. $('.js-ajax-delete').on('click', function (e) {
  304. e.preventDefault();
  305. var $_this = this,
  306. $this = $($_this),
  307. href = $this.data('href'),
  308. refresh = $this.data('refresh'),
  309. msg = $this.data('msg');
  310. okBtnText = $this.data('ok-btn');
  311. cancelBtnText = $this.data('cancel-btn');
  312. href = href ? href : $this.attr('href');
  313. noty({
  314. text: msg ? msg : '确定要删除吗?',
  315. type: 'confirm',
  316. layout: "center",
  317. timeout: false,
  318. modal: true,
  319. buttons: [
  320. {
  321. addClass: 'btn btn-primary',
  322. text: okBtnText ? okBtnText : '确定',
  323. onClick: function ($noty) {
  324. $noty.close();
  325. $.getJSON(href).done(function (data) {
  326. if (data.code == 1) {
  327. if (data.url) {
  328. location.href = data.url;
  329. } else if (refresh || refresh == undefined) {
  330. reloadPage(window);
  331. }
  332. } else if (data.code == 0) {
  333. noty({
  334. text: data.msg,
  335. type: 'error',
  336. layout: 'center',
  337. callback: {
  338. afterClose: function () {
  339. if (data.url) {
  340. location.href = data.url;
  341. }
  342. }
  343. }
  344. });
  345. }
  346. });
  347. }
  348. },
  349. {
  350. addClass: 'btn btn-danger',
  351. text: cancelBtnText ? cancelBtnText : '取消',
  352. onClick: function ($noty) {
  353. $noty.close();
  354. }
  355. }
  356. ]
  357. });
  358. });
  359. });
  360. }
  361. if ($('a.js-ajax-dialog-btn').length) {
  362. Wind.use('noty', function () {
  363. $('.js-ajax-dialog-btn').on('click', function (e) {
  364. e.preventDefault();
  365. var $_this = this,
  366. $this = $($_this),
  367. href = $this.data('href'),
  368. refresh = $this.data('refresh'),
  369. msg = $this.data('msg');
  370. href = href ? href : $this.attr('href');
  371. noty({
  372. text: msg,
  373. type: 'confirm',
  374. layout: "center",
  375. timeout: false,
  376. modal: true,
  377. buttons: [
  378. {
  379. addClass: 'btn btn-primary',
  380. text: '确定',
  381. onClick: function ($noty) {
  382. $noty.close();
  383. $.getJSON(href).done(function (data) {
  384. if (data.code == 1) {
  385. if (data.url) {
  386. location.href = data.url;
  387. } else if (refresh || refresh == undefined) {
  388. reloadPage(window);
  389. }
  390. } else if (data.code == 0) {
  391. noty({
  392. text: data.msg,
  393. type: 'error',
  394. layout: 'center',
  395. callback: {
  396. afterClose: function () {
  397. if (data.url) {
  398. location.href = data.url;
  399. }
  400. }
  401. }
  402. });
  403. }
  404. });
  405. }
  406. },
  407. {
  408. addClass: 'btn btn-danger',
  409. text: '取消',
  410. onClick: function ($noty) {
  411. $noty.close();
  412. }
  413. }
  414. ]
  415. });
  416. });
  417. });
  418. }
  419. if ($('a.js-ajax-btn').length) {
  420. Wind.use('noty', function () {
  421. $('.js-ajax-btn').on('click', function (e) {
  422. e.preventDefault();
  423. var $_this = this,
  424. $this = $($_this),
  425. href = $this.data('href'),
  426. msg = $this.data('msg');
  427. refresh = $this.data('refresh');
  428. href = href ? href : $this.attr('href');
  429. refresh = refresh == undefined ? 1 : refresh;
  430. $.getJSON(href).done(function (data) {
  431. if (data.code == 1) {
  432. noty({
  433. text: data.msg,
  434. type: 'success',
  435. layout: 'center',
  436. callback: {
  437. afterClose: function () {
  438. if (data.url) {
  439. location.href = data.url;
  440. return;
  441. }
  442. if (refresh || refresh == undefined) {
  443. reloadPage(window);
  444. }
  445. }
  446. }
  447. });
  448. } else if (data.code == 0) {
  449. noty({
  450. text: data.msg,
  451. type: 'error',
  452. layout: 'center',
  453. callback: {
  454. afterClose: function () {
  455. if (data.url) {
  456. location.href = data.url;
  457. }
  458. }
  459. }
  460. });
  461. }
  462. });
  463. });
  464. });
  465. }
  466. //所有的请求刷新操作
  467. var ajax_refresh = $('a.js-ajax-refresh'),
  468. refresh_lock = false;
  469. if (ajax_refresh.length) {
  470. ajax_refresh.on('click', function (e) {
  471. e.preventDefault();
  472. if (refresh_lock) {
  473. return false;
  474. }
  475. refresh_lock = true;
  476. $.post(this.href, function (data) {
  477. refresh_lock = false;
  478. if (data.code == 1) {
  479. if (data.url) {
  480. location.href = data.url;
  481. } else {
  482. reloadPage(window);
  483. }
  484. } else if (data.code == 0) {
  485. Wind.art.dialog.alert(data.msg);
  486. }
  487. }, 'json');
  488. });
  489. }
  490. //短信验证码
  491. var $js_get_mobile_code = $('.js-get-mobile-code');
  492. if ($js_get_mobile_code.length > 0) {
  493. Wind.use('noty', function () {
  494. $js_get_mobile_code.on('click', function () {
  495. var $this = $(this);
  496. if ($this.data('loading')) return;
  497. if ($this.data('sending')) return;
  498. var $mobile_input = $($this.data('mobile-input'));
  499. var mobile = $mobile_input.val();
  500. if (mobile == '') {
  501. $mobile_input.focus();
  502. return;
  503. }
  504. var $form = $this.parents('form');
  505. var $captchaInput = $("input[name='captcha']", $form);
  506. var $captchaIdInput = $("input[name='_captcha_id']", $form);
  507. var captcha = $captchaInput.val();
  508. var captchaId = $captchaIdInput.val();
  509. if (!captcha) {
  510. $captchaInput.focus();
  511. return;
  512. }
  513. $this.data('loading', true);
  514. $this.data('sending', true);
  515. var url = $this.data('url');
  516. var init_secode_left = parseInt($this.data('init-second-left'));
  517. init_secode_left = init_secode_left > 0 ? init_secode_left : 60;
  518. var init_text = $this.text();
  519. $this.data('second-left', init_secode_left);
  520. var wait_msg = $this.data('wait-msg');
  521. var codeType = $this.data('type');
  522. $.ajax({
  523. url: url,
  524. type: 'POST',
  525. dataType: 'json',
  526. data: {username: mobile, captcha: captcha, captcha_id: captchaId, type: codeType},
  527. success: function (data) {
  528. if (data.code == 1) {
  529. noty({
  530. text: data.msg,
  531. type: 'success',
  532. layout: 'center'
  533. });
  534. $this.text(wait_msg.replace('[second]', init_secode_left));
  535. var mtimer = setInterval(function () {
  536. if (init_secode_left > 0) {
  537. init_secode_left--;
  538. $this.text(wait_msg.replace('[second]', init_secode_left));
  539. } else {
  540. clearInterval(mtimer);
  541. $this.text(init_text);
  542. $this.data('sending', false);
  543. }
  544. }, 1000);
  545. } else {
  546. $captchaInput.val('');
  547. var $verify_img = $form.find(".verify_img");
  548. if ($verify_img.length) {
  549. $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random());
  550. }
  551. noty({
  552. text: data.msg,
  553. type: 'error',
  554. layout: 'center'
  555. });
  556. $this.data('sending', false);
  557. }
  558. },
  559. error: function () {
  560. $this.data('sending', false);
  561. },
  562. complete: function () {
  563. $this.data('loading', false);
  564. }
  565. });
  566. });
  567. });
  568. }
  569. //邮件验证码
  570. var $js_get_email_code = $('.js-get-email-code');
  571. if ($js_get_email_code.length > 0) {
  572. Wind.use('noty', function () {
  573. $js_get_email_code.on('click', function () {
  574. var $this = $(this);
  575. if ($this.data('loading')) return;
  576. if ($this.data('sending')) return;
  577. var $email_input = $($this.data('email-input'));
  578. var email = $email_input.val();
  579. if (email == '') {
  580. $email_input.focus();
  581. return;
  582. }
  583. var $form = $this.parents('form');
  584. var $captchaInput = $("input[name='captcha']", $form);
  585. var $captchaIdInput = $("input[name='_captcha_id']", $form);
  586. var captcha = $captchaInput.val();
  587. var captchaId = $captchaIdInput.val();
  588. if (!captcha) {
  589. $captchaInput.focus();
  590. return;
  591. }
  592. $this.data('loading', true);
  593. $this.data('sending', true);
  594. var url = $this.data('url');
  595. var init_secode_left = parseInt($this.data('init-second-left'));
  596. init_secode_left = init_secode_left > 0 ? init_secode_left : 60;
  597. var init_text = $this.text();
  598. $this.data('second-left', init_secode_left);
  599. var wait_msg = $this.data('wait-msg');
  600. var codeType = $this.data('type');
  601. $.ajax({
  602. url: url,
  603. type: 'POST',
  604. dataType: 'json',
  605. data: {username: email, captcha: captcha, captcha_id: captchaId, type: codeType},
  606. success: function (data) {
  607. if (data.code == 1) {
  608. noty({
  609. text: data.msg,
  610. type: 'success',
  611. layout: 'center'
  612. });
  613. $this.text(wait_msg.replace('[second]', init_secode_left));
  614. var mtimer = setInterval(function () {
  615. if (init_secode_left > 0) {
  616. init_secode_left--;
  617. $this.text(wait_msg.replace('[second]', init_secode_left));
  618. } else {
  619. clearInterval(mtimer);
  620. $this.text(init_text);
  621. $this.data('sending', false);
  622. }
  623. }, 1000);
  624. } else {
  625. $captchaInput.val('');
  626. var $verify_img = $form.find(".verify_img");
  627. if ($verify_img.length) {
  628. $verify_img.attr("src", $verify_img.attr("src") + "&refresh=" + Math.random());
  629. }
  630. noty({
  631. text: data.msg,
  632. type: 'error',
  633. layout: 'center'
  634. });
  635. $this.data('sending', false);
  636. }
  637. },
  638. error: function () {
  639. $this.data('sending', false);
  640. },
  641. complete: function () {
  642. $this.data('loading', false);
  643. }
  644. });
  645. });
  646. });
  647. }
  648. /*复选框全选(支持多个,纵横双控全选)。
  649. *实例:版块编辑-权限相关(双控),验证机制-验证策略(单控)
  650. *说明:
  651. * "js-check"的"data-xid"对应其左侧"js-check-all"的"data-checklist";
  652. * "js-check"的"data-yid"对应其上方"js-check-all"的"data-checklist";
  653. * 全选框的"data-direction"代表其控制的全选方向(x或y);
  654. * "js-check-wrap"同一块全选操作区域的父标签class,多个调用考虑
  655. */
  656. if ($('.js-check-wrap').length) {
  657. var total_check_all = $('input.js-check-all');
  658. //遍历所有全选框
  659. $.each(total_check_all, function () {
  660. var check_all = $(this),
  661. check_items;
  662. //分组各纵横项
  663. var check_all_direction = check_all.data('direction');
  664. check_items = $('input.js-check[data-' + check_all_direction + 'id="' + check_all.data('checklist') + '"]').not(":disabled");
  665. //点击全选框
  666. check_all.change(function (e) {
  667. var check_wrap = check_all.parents('.js-check-wrap'); //当前操作区域所有复选框的父标签(重用考虑)
  668. if ($(this).prop('checked')) {
  669. //全选状态
  670. check_items.prop('checked', true);
  671. //所有项都被选中
  672. if (check_wrap.find('input.js-check').length === check_wrap.find('input.js-check:checked').length) {
  673. check_wrap.find(total_check_all).prop('checked', true);
  674. }
  675. } else {
  676. //非全选状态
  677. check_items.removeProp('checked');
  678. check_wrap.find(total_check_all).removeProp('checked');
  679. //另一方向的全选框取消全选状态
  680. var direction_invert = check_all_direction === 'x' ? 'y' : 'x';
  681. check_wrap.find($('input.js-check-all[data-direction="' + direction_invert + '"]')).removeProp('checked');
  682. }
  683. });
  684. //点击非全选时判断是否全部勾选
  685. check_items.change(function () {
  686. if ($(this).prop('checked')) {
  687. if (check_items.filter(':checked').length === check_items.length) {
  688. //已选择和未选择的复选框数相等
  689. check_all.prop('checked', true);
  690. }
  691. } else {
  692. check_all.removeProp('checked');
  693. }
  694. });
  695. });
  696. }
  697. //日期选择器
  698. var dateInput = $("input.js-date");
  699. if (dateInput.length) {
  700. Wind.use('datePicker', function () {
  701. dateInput.datePicker();
  702. });
  703. }
  704. //日期+时间选择器
  705. var dateTimeInput = $("input.js-datetime");
  706. if (dateTimeInput.length) {
  707. Wind.use('datePicker', function () {
  708. dateTimeInput.datePicker({
  709. time: true
  710. });
  711. });
  712. }
  713. // bootstrap年选择器
  714. var bootstrapYearInput = $("input.js-bootstrap-year")
  715. if (bootstrapYearInput.length) {
  716. Wind.css('bootstrapDatetimePicker');
  717. Wind.use('bootstrapDatetimePicker', function () {
  718. bootstrapYearInput.datetimepicker({
  719. language: 'zh-CN',
  720. format: 'yyyy',
  721. minView: 'decade',
  722. startView: 'decade',
  723. todayBtn: 1,
  724. autoclose: true
  725. });
  726. });
  727. }
  728. // bootstrap年月份选择器
  729. var bootstrapYearMonthInput = $("input.js-bootstrap-year-month");
  730. if (bootstrapYearMonthInput.length) {
  731. Wind.css('bootstrapDatetimePicker');
  732. Wind.use('bootstrapDatetimePicker', function () {
  733. bootstrapYearMonthInput.datetimepicker({
  734. language: 'zh-CN',
  735. format: 'yyyy-mm',
  736. minView: 'year',
  737. startView: 'decade',
  738. todayBtn: 1,
  739. autoclose: true
  740. });
  741. });
  742. }
  743. // bootstrap日期选择器
  744. var bootstrapDateInput = $("input.js-bootstrap-date")
  745. if (bootstrapDateInput.length) {
  746. Wind.css('bootstrapDatetimePicker');
  747. Wind.use('bootstrapDatetimePicker', function () {
  748. bootstrapDateInput.datetimepicker({
  749. language: 'zh-CN',
  750. format: 'yyyy-mm-dd',
  751. minView: 'month',
  752. todayBtn: 1,
  753. autoclose: true
  754. });
  755. });
  756. }
  757. // bootstrap日期选择器日期+时间选择器
  758. var bootstrapDateTimeInput = $("input.js-bootstrap-datetime");
  759. if (bootstrapDateTimeInput.length) {
  760. Wind.css('bootstrapDatetimePicker');
  761. Wind.use('bootstrapDatetimePicker', function () {
  762. bootstrapDateTimeInput.datetimepicker({
  763. language: 'zh-CN',
  764. format: 'yyyy-mm-dd hh:ii',
  765. todayBtn: 1,
  766. autoclose: true
  767. });
  768. });
  769. }
  770. //赞,拍等,有数量操作的按钮
  771. var $js_count_btn = $('a.js-count-btn');
  772. if ($js_count_btn.length) {
  773. Wind.use('noty', function () {
  774. $js_count_btn.on('click', function (e) {
  775. e.preventDefault();
  776. var $this = $(this),
  777. href = $this.prop('href');
  778. $.post(href, {}, function (data) {
  779. if (data.code == 1) {
  780. var $count = $this.find(".count");
  781. var count = parseInt($count.text());
  782. $count.text(count + 1);
  783. if (data.msg) {
  784. noty({
  785. text: data.msg,
  786. type: 'success',
  787. layout: 'center',
  788. callback: {
  789. afterClose: function () {
  790. if (data.url) {
  791. location.href = data.url;
  792. }
  793. }
  794. }
  795. });
  796. }
  797. } else if (data.code == 0) {
  798. noty({
  799. text: data.msg,
  800. type: 'error',
  801. layout: 'center',
  802. callback: {
  803. afterClose: function () {
  804. if (data.url) {
  805. location.href = data.url;
  806. }
  807. }
  808. }
  809. });
  810. }
  811. }, "json");
  812. });
  813. });
  814. }
  815. //地址联动
  816. var $js_address_select = $('.js-address-select');
  817. if ($js_address_select.length > 0) {
  818. $('.js-address-province-select,.js-address-city-select').change(function () {
  819. var $this = $(this);
  820. var id = $this.val();
  821. var $child_area_select;
  822. var $this_js_address_select = $this.parents('.js-address-select');
  823. if ($this.is('.js-address-province-select')) {
  824. $child_area_select = $this_js_address_select.find('.js-address-city-select');
  825. $this_js_address_select.find('.js-address-district-select').hide();
  826. } else {
  827. $child_area_select = $this_js_address_select.find('.js-address-district-select');
  828. }
  829. var empty_option = '<option class="js-address-empty-option" value="">' + $child_area_select.find('.js-address-empty-option').text() + '</option>';
  830. $child_area_select.html(empty_option);
  831. var child_area_html = $this.data('childarea' + id);
  832. if (child_area_html) {
  833. $child_area_select.show();
  834. $child_area_select.html(child_area_html);
  835. return;
  836. }
  837. $.ajax({
  838. url: $this_js_address_select.data('url'),
  839. type: 'POST',
  840. dataType: 'JSON',
  841. data: {id: id},
  842. success: function (data) {
  843. if (data.code == 1) {
  844. if (data.data.areas.length > 0) {
  845. var html = [empty_option];
  846. $.each(data.data.areas, function (i, area) {
  847. var area_html = '<option value="[id]">[name]</option>';
  848. area_html = area_html.replace('[name]', area.name);
  849. area_html = area_html.replace('[id]', area.id);
  850. html.push(area_html);
  851. });
  852. html = html.join('', html);
  853. $this.data('childarea' + id, html);
  854. $child_area_select.html(html);
  855. $child_area_select.show();
  856. } else {
  857. $child_area_select.hide();
  858. }
  859. }
  860. },
  861. error: function () {
  862. },
  863. complete: function () {
  864. }
  865. });
  866. });
  867. }
  868. //地址联动end
  869. //
  870. var $js_action_btn = $('a.js-action-btn');
  871. if ($js_action_btn.length) {
  872. Wind.use('noty', function () {
  873. $js_action_btn.on('click', function (e) {
  874. e.preventDefault();
  875. var $this = $(this),
  876. href = $this.prop('href');
  877. $.post(href, {}, function (data) {
  878. if (data.code == '1') {
  879. if (data.msg) {
  880. noty({
  881. text: data.msg,
  882. type: 'success',
  883. layout: 'center',
  884. callback: {
  885. afterClose: function () {
  886. if (data.url) {
  887. location.href = data.url;
  888. }
  889. }
  890. }
  891. });
  892. }
  893. } else if (data.code == 0) {
  894. noty({
  895. text: data.msg,
  896. type: 'error',
  897. layout: 'center',
  898. callback: {
  899. afterClose: function () {
  900. if (data.url) {
  901. location.href = data.url;
  902. }
  903. }
  904. }
  905. });
  906. }
  907. }, "json");
  908. });
  909. });
  910. }
  911. var $js_favorite_btn = $('a.js-favorite-btn');
  912. if ($js_favorite_btn.length) {
  913. Wind.use('noty', function () {
  914. $js_favorite_btn.on('click', function (e) {
  915. e.preventDefault();
  916. var $this = $(this),
  917. href = $this.prop('href'),
  918. url = $this.data("url"),
  919. id = $this.data("id"),
  920. table = $this.data('table'),
  921. title = $this.data("title"),
  922. description = $this.data("description");
  923. $.post(href, {
  924. id: id,
  925. table: table,
  926. url: url,
  927. title: title,
  928. description: description
  929. }, function (data) {
  930. if (data.code == 1) {
  931. if (data.msg) {
  932. noty({
  933. text: data.msg,
  934. type: 'success',
  935. layout: 'center',
  936. callback: {
  937. afterClose: function () {
  938. if (data.url) {
  939. location.href = data.url;
  940. }
  941. }
  942. }
  943. });
  944. }
  945. } else if (data.code == 0) {
  946. noty({
  947. text: data.msg,
  948. type: 'error',
  949. layout: 'center',
  950. callback: {
  951. afterClose: function () {
  952. if (data.url) {
  953. location.href = data.url;
  954. }
  955. }
  956. }
  957. });
  958. }
  959. }, "json");
  960. });
  961. });
  962. }
  963. })();
  964. //重新刷新页面,使用location.reload()有可能导致重新提交
  965. function reloadPage(win) {
  966. if (win) {
  967. } else {
  968. win = window;
  969. }
  970. var location = win.location;
  971. location.href = location.pathname + location.search;
  972. }
  973. //页面跳转
  974. function redirect(url) {
  975. location.href = url;
  976. }
  977. /**
  978. * 读取cookie
  979. * @param name
  980. * @returns
  981. */
  982. function getCookie(name) {
  983. var cookieValue = null;
  984. if (document.cookie && document.cookie != '') {
  985. var cookies = document.cookie.split(';');
  986. for (var i = 0; i < cookies.length; i++) {
  987. var cookie = jQuery.trim(cookies[i]);
  988. // Does this cookie string begin with the name we want?
  989. if (cookie.substring(0, name.length + 1) == (name + '=')) {
  990. cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
  991. break;
  992. }
  993. }
  994. }
  995. return cookieValue;
  996. }
  997. /**
  998. * 设置cookie
  999. */
  1000. function setCookie(name, value, options) {
  1001. options = options || {};
  1002. if (value === null) {
  1003. value = '';
  1004. options.expires = -1;
  1005. }
  1006. var expires = '';
  1007. if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
  1008. var date;
  1009. if (typeof options.expires == 'number') {
  1010. date = new Date();
  1011. date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
  1012. } else {
  1013. date = options.expires;
  1014. }
  1015. expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
  1016. }
  1017. var path = options.path ? '; path=' + options.path : '';
  1018. var domain = options.domain ? '; domain=' + options.domain : '';
  1019. var secure = options.secure ? '; secure' : '';
  1020. document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
  1021. }
  1022. function openIframeDialog(url, title, options) {
  1023. var params = {
  1024. title: title,
  1025. lock: true,
  1026. opacity: 0,
  1027. width: "95%"
  1028. };
  1029. params = options ? $.extend(params, options) : params;
  1030. Wind.use('artDialog', 'iframeTools', function () {
  1031. art.dialog.open(url, params);
  1032. });
  1033. }
  1034. /**
  1035. * 打开地图对话框
  1036. *
  1037. * @param url
  1038. * @param title
  1039. * @param options
  1040. * @param callback
  1041. */
  1042. function openMapDialog(url, title, options, callback) {
  1043. Wind.css('artDialog');
  1044. var params = {
  1045. title: title,
  1046. lock: true,
  1047. opacity: 0,
  1048. width: "95%",
  1049. height: 400,
  1050. ok: function () {
  1051. if (callback) {
  1052. var d = this.iframe.contentWindow;
  1053. var lng = $("#lng_input", d.document).val();
  1054. var lat = $("#lat_input", d.document).val();
  1055. var address = {};
  1056. address.address = $("#address_input", d.document).val();
  1057. address.province = $("#province_input", d.document).val();
  1058. address.city = $("#city_input", d.document).val();
  1059. address.district = $("#district_input", d.document).val();
  1060. callback.apply(this, [lng, lat, address]);
  1061. }
  1062. }
  1063. };
  1064. params = options ? $.extend(params, options) : params;
  1065. Wind.use('artDialog', 'iframeTools', function () {
  1066. art.dialog.open(url, params);
  1067. });
  1068. }
  1069. /**
  1070. * 打开文件上传对话框
  1071. * @param dialog_title 对话框标题
  1072. * @param callback 回调方法,参数有(当前dialog对象,选择的文件数组,你设置的extra_params)
  1073. * @param extra_params 额外参数,object
  1074. * @param multi 是否可以多选
  1075. * @param filetype 文件类型,image,video,audio,file
  1076. * @param app 应用名,CMF的应用名
  1077. */
  1078. function openUploadDialog(dialog_title, callback, extra_params, multi, filetype, app) {
  1079. Wind.css('artDialog');
  1080. multi = multi ? 1 : 0;
  1081. filetype = filetype ? filetype : 'image';
  1082. app = app ? app : GV.APP;
  1083. var params = '&multi=' + multi + '&filetype=' + filetype + '&app=' + app;
  1084. Wind.use("artDialog", "iframeTools", function () {
  1085. art.dialog.open(GV.ROOT + 'user/Asset/webuploader?' + params, {
  1086. title: dialog_title,
  1087. id: new Date().getTime(),
  1088. width: '600px',
  1089. height: '350px',
  1090. lock: true,
  1091. fixed: true,
  1092. background: "#CCCCCC",
  1093. opacity: 0,
  1094. ok: function () {
  1095. if (typeof callback == 'function') {
  1096. var iframewindow = this.iframe.contentWindow;
  1097. var files = iframewindow.get_selected_files();
  1098. console.log(files);
  1099. if (files && files.length > 0) {
  1100. callback.apply(this, [this, files, extra_params]);
  1101. } else {
  1102. return false;
  1103. }
  1104. }
  1105. },
  1106. cancel: true
  1107. });
  1108. });
  1109. }
  1110. /**
  1111. * 单个文件上传
  1112. * @param dialog_title 上传对话框标题
  1113. * @param input_selector 图片容器
  1114. * @param filetype 文件类型,image,video,audio,file
  1115. * @param extra_params 额外参数,object
  1116. * @param app 应用名,CMF的应用名
  1117. */
  1118. function uploadOne(dialog_title, input_selector, filetype, extra_params, app) {
  1119. filetype = filetype ? filetype : 'file';
  1120. openUploadDialog(dialog_title, function (dialog, files) {
  1121. $(input_selector).val(files[0].filepath);
  1122. $(input_selector + '-preview').attr('href', files[0].preview_url);
  1123. $(input_selector + '-name').val(files[0].name);
  1124. $(input_selector + '-name-text').text(files[0].name);
  1125. }, extra_params, 0, filetype, app);
  1126. }
  1127. /**
  1128. * 单个图片上传
  1129. * @param dialog_title 上传对话框标题
  1130. * @param input_selector 图片容器
  1131. * @param extra_params 额外参数,object
  1132. * @param app 应用名,CMF的应用名
  1133. */
  1134. function uploadOneImage(dialog_title, input_selector, extra_params, app) {
  1135. openUploadDialog(dialog_title, function (dialog, files) {
  1136. $(input_selector).val(files[0].filepath);
  1137. $(input_selector + '-preview').attr('src', files[0].preview_url);
  1138. $(input_selector + '-name').val(files[0].name);
  1139. $(input_selector + '-name-text').text(files[0].name);
  1140. }, extra_params, 0, 'image', app);
  1141. }
  1142. /**
  1143. * 多图上传
  1144. * @param dialog_title 上传对话框标题
  1145. * @param container_selector 图片容器
  1146. * @param item_tpl_wrapper_id 单个图片html模板容器id
  1147. * @param extra_params 额外参数,object
  1148. * @param app 应用名,CMF 的应用名
  1149. */
  1150. function uploadMultiImage(dialog_title, container_selector, item_tpl_wrapper_id, extra_params, app) {
  1151. openUploadDialog(dialog_title, function (dialog, files) {
  1152. var tpl = $('#' + item_tpl_wrapper_id).html();
  1153. var html = '';
  1154. $.each(files, function (i, item) {
  1155. var itemtpl = tpl;
  1156. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  1157. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  1158. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  1159. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  1160. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  1161. html += itemtpl;
  1162. });
  1163. $(container_selector).append(html);
  1164. }, extra_params, 1, 'image', app);
  1165. }
  1166. /**
  1167. * 多文件上传
  1168. * @param dialog_title 上传对话框标题
  1169. * @param container_selector 图片容器
  1170. * @param item_tpl_wrapper_id 单个图片html模板容器id
  1171. * @param filetype 文件类型,image,video,audio,file
  1172. * @param extra_params 额外参数,object
  1173. * @param app 应用名,CMF 的应用名
  1174. */
  1175. function uploadMultiFile(dialog_title, container_selector, item_tpl_wrapper_id, filetype, extra_params, app) {
  1176. filetype = filetype ? filetype : 'file';
  1177. openUploadDialog(dialog_title, function (dialog, files) {
  1178. var tpl = $('#' + item_tpl_wrapper_id).html();
  1179. var html = '';
  1180. $.each(files, function (i, item) {
  1181. var itemtpl = tpl;
  1182. itemtpl = itemtpl.replace(/\{id\}/g, item.id);
  1183. itemtpl = itemtpl.replace(/\{url\}/g, item.url);
  1184. itemtpl = itemtpl.replace(/\{preview_url\}/g, item.preview_url);
  1185. itemtpl = itemtpl.replace(/\{filepath\}/g, item.filepath);
  1186. itemtpl = itemtpl.replace(/\{name\}/g, item.name);
  1187. html += itemtpl;
  1188. });
  1189. $(container_selector).append(html);
  1190. }, extra_params, 1, filetype, app);
  1191. }
  1192. function openIframeLayer(url, title, options) {
  1193. var params = {
  1194. type: 2,
  1195. title: title,
  1196. shadeClose: true,
  1197. // skin: 'layui-layer-nobg',
  1198. shade: [0.001, '#000000'],
  1199. shadeClose: true,
  1200. area: ['95%', '90%'],
  1201. move: false,
  1202. content: url,
  1203. yes: function (index, layero) {
  1204. //do something
  1205. layer.close(index); //如果设定了yes回调,需进行手工关闭
  1206. }
  1207. };
  1208. params = options ? $.extend(params, options) : params;
  1209. Wind.css('layer');
  1210. Wind.use("layer", function () {
  1211. layer.open(params);
  1212. });
  1213. }