base.js 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. //多选
  2. $(document).ready(function() {
  3. if ($(".single-optgroup-select").length > 0) {
  4. $('.single-optgroup-select').multiselect({
  5. enableFiltering: true,
  6. enableHTML: true,
  7. disableIfEmpty: true,
  8. buttonClass: 'btn btn-white',
  9. templates: {
  10. button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
  11. ul: '<ul class="multiselect-container dropdown-menu" style="width: 300px;"></ul>',
  12. filter: '<li class="multiselect-item multiselect-filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
  13. filterClearBtn: '',
  14. li: '<li><a tabindex="0"><label></label></a></li>',
  15. divider: '<li class="multiselect-item divider"></li>',
  16. liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
  17. },
  18. onChange: function (e) {
  19. if(check_function_exist('singleSelectChange')){ // 方法存在即调用,该方法需要自己实现,抽出一个值改变的方法
  20. singleSelectChange(e.context.value);
  21. }
  22. }
  23. });
  24. }
  25. if ($(".single-select").length > 0) {
  26. $('.single-select').multiselect({
  27. enableFiltering: true,
  28. enableHTML: true,
  29. disableIfEmpty: true,
  30. buttonClass: 'btn btn-white',
  31. templates: {
  32. button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
  33. ul: '<ul class="multiselect-container dropdown-menu" style="width: 219px;"></ul>',
  34. filter: '<li class="multiselect-item multiselect-filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
  35. filterClearBtn: '',
  36. li: '<li><a tabindex="0"><label></label></a></li>',
  37. divider: '<li class="multiselect-item divider"></li>',
  38. liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
  39. },
  40. onChange: function (e) {
  41. if(check_function_exist('singleSelectChange')){ // 方法存在即调用,该方法需要自己实现,抽出一个值改变的方法
  42. singleSelectChange(e.context.value);
  43. }
  44. }
  45. });
  46. }
  47. if ($(".multi-select").length > 0) {
  48. $('.multi-select').multiselect({
  49. enableFiltering: true,
  50. enableHTML: true,
  51. enableClickableOptGroups: true,
  52. disableIfEmpty: true,
  53. enableCollapsibleOptGroups: true,
  54. buttonClass: 'btn btn-white',
  55. templates: {
  56. button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
  57. ul: '<ul class="multiselect-container dropdown-menu" style="width: 300px;"></ul>',
  58. filter: '<li class="multiselect-item multiselect-filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
  59. filterClearBtn: '',
  60. li: '<li><a tabindex="0"><label></label></a></li>',
  61. divider: '<li class="multiselect-item divider"></li>',
  62. liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
  63. }
  64. });
  65. }
  66. if ($(".multi-select-filter").length > 0) {
  67. $('.multi-select-filter').multiselect({
  68. enableFiltering: true,
  69. includeSelectAllOption: true,
  70. numberDisplayed: 3,
  71. enableHTML: true,
  72. enableClickableOptGroups: false,
  73. disableIfEmpty: true,
  74. enableCollapsibleOptGroups: true,
  75. buttonClass: 'btn btn-white',
  76. templates: {
  77. button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
  78. ul: '<ul class="multiselect-container dropdown-menu" style="width: 300px;"></ul>',
  79. filter: '<li class="multiselect-item multiselect-filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
  80. filterClearBtn: '',
  81. li: '<li><a tabindex="0"><label></label></a></li>',
  82. divider: '<li class="multiselect-item divider"></li>',
  83. liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
  84. }
  85. });
  86. }
  87. if ($(".multi-select-filter-selectall").length > 0) {
  88. $('.multi-select-filter-selectall').multiselect({
  89. enableFiltering: true,
  90. includeSelectAllOption: true,
  91. numberDisplayed: 3,
  92. enableHTML: true,
  93. enableClickableOptGroups: true,
  94. disableIfEmpty: true,
  95. enableCollapsibleOptGroups: true,
  96. buttonClass: 'btn btn-white',
  97. templates: {
  98. button: '<button type="button" class="multiselect dropdown-toggle" data-toggle="dropdown"><span class="multiselect-selected-text"></span> &nbsp;<b class="fa fa-caret-down"></b></button>',
  99. ul: '<ul class="multiselect-container dropdown-menu" style="width: 300px;"></ul>',
  100. filter: '<li class="multiselect-item multiselect-filter"><div class="input-group"><span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span><input class="form-control multiselect-search" type="text"></div></li>',
  101. filterClearBtn: '',
  102. li: '<li><a tabindex="0"><label></label></a></li>',
  103. divider: '<li class="multiselect-item divider"></li>',
  104. liGroup: '<li class="multiselect-item multiselect-group"><label></label></li>'
  105. }
  106. });
  107. }
  108. });
  109. $(document).ready(function() {
  110. //播放音频
  111. /*if ($("audio").length > 0) {
  112. audiojs.events.ready(function() {
  113. if ($('audio').attr('type') !== 'hide') {
  114. var as = audiojs.createAll();
  115. } else {
  116. $('audio').hide();
  117. }
  118. });
  119. }*/
  120. });
  121. // 快速编辑
  122. $(document).on('click', '.quick-edit-text', function(e) {
  123. var $this = $(this),
  124. defaultValue = $this.attr('data-vaule');
  125. if ($this.hasClass('editing'))
  126. return;
  127. var input = '<input type="number" maxlength="4" style="width:2.5em;" value=' + defaultValue + '>';
  128. $this.addClass('editing').html(input);
  129. });
  130. // <span class="quick-edit-text" data-url="sort?id=<?=$item->ExBuildFormID?>" data-vaule="<?=$item->Sort?>"><?=$item->Sort?></span>
  131. $(document).on('focusout', '.quick-edit-text input', function(e) {
  132. var $this = $(this).parent(),
  133. $input = $(this),
  134. value = $input.val(),
  135. url = $this.attr('data-url'),
  136. defaultValue = $this.attr('data-vaule');
  137. if (value == '') {
  138. $this.html(defaultValue);
  139. $this.removeClass('editing');
  140. layer.tips('未填写排序值', '.quick-edit-text');
  141. return;
  142. }
  143. var bOk = false;
  144. if (value != defaultValue) {
  145. $.post(url, 'value=' + value, function(result) {
  146. layer.tips(result.info, '.quick-edit-text');
  147. if (result.status == 1) {
  148. bOk = true;
  149. if (result.url === undefined || result.url == '') {
  150. //赋值
  151. $this.html(value);
  152. } else {
  153. window.location.href = result.url;
  154. }
  155. }
  156. });
  157. }
  158. $this.removeClass('editing');
  159. if (!bOk) {
  160. $this.html(defaultValue);
  161. }
  162. });
  163. $(document).ready(function() {
  164. if ($('.dialog-datetime').length > 0) {
  165. //时间控件
  166. var $this = $('.dialog-datetime');
  167. $this.each(function(index, element) {
  168. var defaultValue = $(element).attr('data-rules');
  169. if (defaultValue != undefined && defaultValue !== '') {
  170. $(element).datetimepicker(eval('(' + defaultValue + ')'));
  171. } else {
  172. var step = $(element).attr('data-minute-step');
  173. var format = $(element).attr('data-date-format');
  174. if ('yyyy' == format) {
  175. minView = "decade";
  176. maxView = 'decade';
  177. startView = 'decade';
  178. } else if ('yyyy-mm' == format) {
  179. minView = "year";
  180. maxView = 'year';
  181. startView = 'year';
  182. } else if ('yyyy-mm-dd' == format) {
  183. minView = "month";
  184. maxView = 'month';
  185. startView = 'month';
  186. } else if ('yyyy-mm-dd hh' == format) {
  187. minView = "day";
  188. maxView = 'month';
  189. startView = 'month';
  190. } else if ('yyyy-mm-dd hh:ii' == format) {
  191. minView = "hour";
  192. maxView = 'month';
  193. startView = 'month';
  194. } else if ('hh:ii' == format) {
  195. minView = "hour";
  196. maxView = 'hour';
  197. startView = 'hour';
  198. } else if ('hh' == format) {
  199. minView = "hour";
  200. maxView = 'hour';
  201. startView = 'hour';
  202. format = "hh:ii";
  203. step = 60;
  204. } else {
  205. minView = "hour";
  206. maxView = 'month';
  207. startView = 'month';
  208. }
  209. // alert(minView);
  210. $(element).datetimepicker({
  211. minView: minView,
  212. maxView: maxView,
  213. weekStart: 1,
  214. startView: startView,
  215. minuteStep: parseInt(step),
  216. showMeridian: true,
  217. format: format,
  218. autoclose: true,
  219. todayBtn: false,
  220. forceParse: true
  221. });
  222. }
  223. });
  224. }
  225. });
  226. //删除
  227. $(document).on('click', '.btn-confirm', function(e) {
  228. var $this = $(this),
  229. msg = $this.attr('data-confirm') || '你确定执行该操作吗?';
  230. url = $this.attr('href') || $this.attr('data-url');
  231. layer.confirm(msg, {
  232. icon: 3,
  233. btn: ['确定', '取消'],
  234. skin: 'layer-ext-moon'
  235. }, function(index) {
  236. window.location.href = url;
  237. });
  238. return false;
  239. });
  240. //删除
  241. $(document).on('click', '.btn-confirm-get', function(e) {
  242. var $this = $(this),
  243. msg = $this.attr('data-confirm') || '你确定执行该操作吗?';
  244. url = $this.attr('href') || $this.attr('data-url');
  245. layer.confirm(msg, {
  246. icon: 3,
  247. btn: ['确定', '取消'],
  248. skin: 'layer-ext-moon'
  249. }, function(index) {
  250. $.get(url, function(result) {
  251. layer.close(index);
  252. if (result.info != undefined && result.info != '') {
  253. if (result.status == 1) {
  254. layer.alert(result.info, { icon: 1, skin: 'layer-ext-moon' }, function() {
  255. if (result.url === undefined || result.url == '') {
  256. parent.location.reload();
  257. } else {
  258. window.location.href = result.url;
  259. }
  260. });
  261. } else {
  262. layer.alert(result.info, { icon: 2, skin: 'layer-ext-moon' });
  263. }
  264. } else {
  265. //parent.location.reload();
  266. }
  267. });
  268. });
  269. return false;
  270. // var cf = confirm(msg);
  271. // if(!cf) e.stopImmediatePropagation(); // 阻止事件追加
  272. // return cf ? true : false;
  273. });
  274. //弹出窗
  275. $(document).on('click', '.btn-dialog-pop', function(e) {
  276. e.preventDefault();
  277. var $this = $(this),
  278. id = $this.attr('data-id') || 'dialog',
  279. url = $this.attr('href') || $this.attr('data-url');
  280. var title = $this.text();
  281. layer.open({
  282. type: 2,
  283. shade: 0.8,
  284. title: title,
  285. area: 'auto',
  286. area: ['800px', '90%'],
  287. fix: false, //不固定
  288. maxmin: true,
  289. content: url,
  290. skin: 'layer-ext-moon',
  291. success: function(layero, index) {
  292. layer.iframeAuto(index);
  293. //设置标题
  294. //layer.title($this.text(), index);
  295. },
  296. btn: ['取消']
  297. });
  298. });
  299. $(document).on('click', '.btn-dialog-pop2', function(e) {
  300. e.preventDefault();
  301. var $this = $(this),
  302. id = $this.attr('data-id') || 'dialog',
  303. url = $this.attr('href') || $this.attr('data-url');
  304. var title = $this.text();
  305. layer.open({
  306. type: 2,
  307. shade: 0.8,
  308. title: title,
  309. area: 'auto',
  310. area: ['80%', '90%'],
  311. fix: false, //不固定
  312. maxmin: true,
  313. content: url,
  314. skin: 'layer-ext-moon',
  315. success: function(layero, index) {
  316. layer.iframeAuto(index);
  317. //设置标题
  318. //layer.title($this.text(), index);
  319. },
  320. btn: ['取消']
  321. });
  322. });
  323. $(document).on('click', '.btn-dialog-pop3', function(e) {
  324. e.preventDefault();
  325. var $this = $(this),
  326. id = $this.attr('data-id') || 'dialog',
  327. url = $this.attr('href') || $this.attr('data-url');
  328. var title = $this.text();
  329. parent.layer.open({
  330. type: 2,
  331. shade: 0.8,
  332. title: title,
  333. area: 'auto',
  334. area: ['60%', '90%'],
  335. fix: false, //不固定
  336. maxmin: true,
  337. content: url,
  338. skin: 'layer-ext-moon',
  339. success: function(layero, index) {
  340. layer.iframeAuto(index);
  341. //设置标题
  342. //layer.title($this.text(), index);
  343. },
  344. btn: ['取消']
  345. });
  346. });
  347. $(document).ready(function() {
  348. //表单静态提交,并且刷新本页
  349. $('.ajax-form').ajaxSubmit(function(result) {
  350. jFlyer.show_result_info(result);
  351. });
  352. });
  353. var jFlyer = {};
  354. jFlyer.is_null = function(str) {
  355. if (str == null) {
  356. return true;
  357. }
  358. if (str == "") {
  359. return true;
  360. }
  361. var regu = "^[ ]+$";
  362. var re = new RegExp(regu);
  363. return re.test(str);
  364. }
  365. //private
  366. jFlyer.show_result_info = function(result) {
  367. function refresh(url){
  368. if (!jFlyer.is_null(url)) {
  369. window.location.href = url;
  370. return;
  371. }
  372. if (result.status == 1) {
  373. parent.location.reload();
  374. }
  375. };
  376. if (!jFlyer.is_null(result.info)) {
  377. layer.alert(result.info, {
  378. icon: (result.status == 1) ? 1 : 2,
  379. skin: 'layer-ext-moon',
  380. yes: function(index) {
  381. layer.close(index);
  382. refresh(result.url);
  383. }
  384. });
  385. }else{
  386. refresh(result.url)
  387. }
  388. }
  389. //class 为 btn-dialog-form 的点击弹出
  390. $(document).off('click', '.btn-dialog-form').on('click', '.btn-dialog-form', function(e) {
  391. e.preventDefault();
  392. var $this = $(this),
  393. id = $this.attr('data-id') || 'dialog',
  394. url = $this.attr('href') || $this.attr('data-url');
  395. var title = $this.text();
  396. jFlyer.show_dialog_form(title, url);
  397. return false;
  398. });
  399. jFlyer.show_dialog_form_callback = function(title, url, callback) {
  400. layer.open({
  401. type: 2,
  402. shade: 0.8,
  403. title: title,
  404. area: ['800px', '90%'],
  405. fix: false, //不固定
  406. maxmin: true,
  407. content: url,
  408. skin: 'layer-ext-moon',
  409. success: function(layero, index) {
  410. layer.iframeAuto(index);
  411. var form = layer.getChildFrame('form', index);
  412. //如果form的action为空,将当前的action 弄过去
  413. if (form.attr('action') === undefined || form.attr('action') === '') {
  414. form.attr('action', url);
  415. }
  416. },
  417. // btn: ['确定', '取消'],
  418. yes: function(index) {
  419. var form = layer.getChildFrame('form', index);
  420. if(form[0].dataset.next == 'true'){
  421. layer.msg('请点击下一步');
  422. return false;
  423. }
  424. $.Form.ajaxSubmit(form, function(result) {
  425. if (result.status == 1) {
  426. layer.close(index);
  427. }
  428. callback(result, form);
  429. });
  430. }
  431. });
  432. }
  433. jFlyer.show_dialog_form = function(title, url) {
  434. jFlyer.show_dialog_form_callback(title, url, function(result, form) {
  435. jFlyer.show_result_info(result);
  436. });
  437. }
  438. $(document).off('click', '.btn-dialog-form2').on('click', '.btn-dialog-form2', function(e) {
  439. e.preventDefault();
  440. var $this = $(this),
  441. id = $this.attr('data-id') || 'dialog',
  442. url = $this.attr('href') || $this.attr('data-url');
  443. var title = $this.text();
  444. jFlyer.show_dialog_form2(title, url);
  445. return false;
  446. });
  447. jFlyer.show_dialog_form_callback2 = function(title, url, callback) {
  448. layer.open({
  449. type: 2,
  450. shade: 0.8,
  451. title: title,
  452. area: ['600px', '90%'],
  453. fix: false, //不固定
  454. maxmin: true,
  455. content: url,
  456. skin: 'layer-ext-moon',
  457. success: function(layero, index) {
  458. layer.iframeAuto(index);
  459. var form = layer.getChildFrame('form', index);
  460. //如果form的action为空,将当前的action 弄过去
  461. if (form.attr('action') === undefined || form.attr('action') === '') {
  462. form.attr('action', url);
  463. }
  464. },
  465. btn: ['确定', '取消'],
  466. yes: function(index) {
  467. var form = layer.getChildFrame('form', index);
  468. $.Form.ajaxSubmit(form, function(result) {
  469. if (result.status == 1) {
  470. layer.close(index);
  471. }
  472. callback(result, form);
  473. });
  474. }
  475. });
  476. }
  477. jFlyer.show_dialog_form2 = function(title, url) {
  478. jFlyer.show_dialog_form_callback2(title, url, function(result, form) {
  479. jFlyer.show_result_info(result);
  480. });
  481. }
  482. $(document).off('click', '.btn-dialog-form3').on('click', '.btn-dialog-form3', function(e) {
  483. e.preventDefault();
  484. var $this = $(this),
  485. id = $this.attr('data-id') || 'dialog',
  486. url = $this.attr('href') || $this.attr('data-url');
  487. var title = $this.text();
  488. jFlyer.show_dialog_form3(title, url);
  489. return false;
  490. });
  491. jFlyer.show_dialog_form_callback3 = function(title, url, callback) {
  492. parent.layer.open({
  493. type: 2,
  494. shade: 0.8,
  495. title: title,
  496. area: ['60%', '90%'],
  497. fix: false, //不固定
  498. maxmin: true,
  499. content: url,
  500. skin: 'layer-ext-moon',
  501. success: function(layero, index) {
  502. layer.iframeAuto(index);
  503. var form = layer.getChildFrame('form', index);
  504. //如果form的action为空,将当前的action 弄过去
  505. if (form.attr('action') === undefined || form.attr('action') === '') {
  506. form.attr('action', url);
  507. }
  508. },
  509. btn: ['确定', '取消'],
  510. yes: function(index) {
  511. var form = layer.getChildFrame('form', index);
  512. $.Form.ajaxSubmit(form, function(result) {
  513. if (result.status == 1) {
  514. layer.close(index);
  515. }
  516. callback(result, form);
  517. });
  518. }
  519. });
  520. }
  521. jFlyer.show_dialog_form3 = function(title, url) {
  522. jFlyer.show_dialog_form_callback3(title, url, function(result, form) {
  523. jFlyer.show_result_info(result);
  524. });
  525. }
  526. jFlyer.is_function = function(fn) {
  527. return Object.prototype.toString.call(fn) === '[object Function]';
  528. }
  529. jFlyer.get_data = function(url, callback) {
  530. var layerIndexget = layer.load(1);
  531. $.get(url, function(result) {
  532. layer.close(layerIndexget);
  533. if (callback != undefined && jFlyer.is_function(callback)) {
  534. callback(result);
  535. }
  536. });
  537. }
  538. jFlyer.post_data = function(url, data, callback) {
  539. var layerIndex = layer.load(1);
  540. $.post(url, data, function(result) {
  541. layer.close(layerIndex);
  542. if (callback != undefined && jFlyer.is_function(callback)) {
  543. callback(result);
  544. }
  545. });
  546. }
  547. jFlyer.show_pop_info = function(info, reload, callback) {
  548. layer.open({
  549. content: info,
  550. btn: '确定',
  551. yes: function(index) {
  552. layer.close(index);
  553. if (callback != undefined && jFlyer.is_function(callback)) {
  554. callback();
  555. }
  556. if (reload) {
  557. location.reload();
  558. }
  559. }
  560. });
  561. }
  562. //ajax get请求
  563. $(document).on('click','.ajax-get',function(){
  564. var that = this;
  565. var confirm_msg = $(this).attr('data-confirm')?$(this).attr('data-confirm'):'确认要执行该操作吗?';
  566. if ( $(this).hasClass('confirm') ) {
  567. layer.confirm(confirm_msg, {
  568. btn: ['确认', '取消'], //按钮
  569. shade: false //不显示遮罩
  570. }, function() {
  571. layer.closeAll();
  572. ajax_get_fun(that);
  573. }, function() {
  574. layer.closeAll();
  575. });
  576. }else{
  577. ajax_get_fun(that);
  578. }
  579. return false;
  580. });
  581. function ajax_get_fun(that) {
  582. var target;
  583. if ( (target = $(that).attr('href')) || (target = $(that).attr('url')) ) {
  584. var flag = $(that).attr('data-flag');
  585. if(flag == 1){
  586. return '';
  587. }
  588. $(that).attr('data-flag',1);
  589. $.get(target).success(function(data){
  590. if (data.status == 1) {
  591. layer.msg(data.info, {time: 1500, icon:6,offset:0});
  592. setTimeout(function(){
  593. if( $(that).hasClass('no-refresh')){
  594. $(that).attr('data-flag',0);
  595. }else{
  596. if (data.url === undefined || data.url == '') {
  597. location.reload();
  598. } else {
  599. window.location.href = result.url;
  600. }
  601. }
  602. },1500);
  603. }else{
  604. layer.msg(data.info, {time: 1500, icon:5,offset:0,shift: 6});
  605. $(that).attr('data-flag',0);
  606. }
  607. });
  608. }
  609. }
  610. //打开查看图片
  611. function open_img(_self) {
  612. var src = $(_self).attr('src');
  613. var img = new Image();
  614. img.src = src;
  615. var width = $(window).width()*0.8;
  616. var height = $(window).height()*0.8;
  617. img.onload = function(){
  618. var imgw = img.width;
  619. var imgh = img.height;
  620. if(imgw > width&&imgh < height){
  621. imgh = imgh*width/imgw;
  622. imgw = width;
  623. }else if(imgw < width&&imgh > height){
  624. imgw = imgw*height/imgh;
  625. imgh = height;
  626. }else if(imgw > width&&imgh > height){
  627. var bl1 = width/height;
  628. var bl2 = imgw/imgh;
  629. if(bl1 < bl2){
  630. imgh = imgh*width/imgw;
  631. imgw = width;
  632. }else if(bl1 > bl2){
  633. imgw = imgw*height/imgh;
  634. imgh = height;
  635. }else{
  636. imgh = height;
  637. imgw = width;
  638. }
  639. }
  640. var imgs = '<img width="'+imgw+'" height="'+imgh+'" src="'+src+'" />';
  641. layer.open({
  642. type: 1,
  643. title: false,
  644. closeBtn: 1,
  645. area: [imgw+'px', imgh+'px'],
  646. skin: 'layui-layer-nobg', //没有背景色
  647. shadeClose: true,
  648. content: imgs
  649. });
  650. };
  651. }
  652. //左侧导航高量
  653. function add_highlight(url) {
  654. $('#sidebar li').removeClass('active').removeClass('open');
  655. $('#sidebar a[href="'+url+'"]').parent().addClass('active');
  656. $('#sidebar a[href="'+url+'"]').parent().parent().parent().addClass('active').addClass('open');
  657. }
  658. //检查函数是否存在
  659. function check_function_exist(funcName) {
  660. try{
  661. if(typeof(eval(funcName))=="function"){
  662. return true;
  663. }
  664. }catch(e){}
  665. return false;
  666. }