admin.js 80 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677
  1. /** EasyWeb iframe v3.1.8 date:2020-05-04 License By http://easyweb.vip */
  2. layui.define(['layer'], function (exports) {
  3. var $ = layui.jquery;
  4. var layer = layui.layer;
  5. var setter = layui.cache;
  6. var bodyDOM = '.layui-layout-admin>.layui-body';
  7. var tabDOM = bodyDOM + '>.layui-tab';
  8. var sideDOM = '.layui-layout-admin>.layui-side>.layui-side-scroll';
  9. var headerDOM = '.layui-layout-admin>.layui-header';
  10. var navFilter = 'admin-side-nav';
  11. var admin = {version: '3.1.8', layerData: {}};
  12. /** 设置侧栏折叠 */
  13. admin.flexible = function (expand) {
  14. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.flexible(expand);
  15. var $layout = $('.layui-layout-admin');
  16. var isExapnd = $layout.hasClass('admin-nav-mini');
  17. if (expand === undefined) expand = isExapnd;
  18. if (isExapnd === expand) {
  19. if (window.sideFlexTimer) clearTimeout(window.sideFlexTimer);
  20. $layout.addClass('admin-side-flexible');
  21. window.sideFlexTimer = setTimeout(function () {
  22. $layout.removeClass('admin-side-flexible');
  23. }, 600);
  24. if (expand) {
  25. admin.hideTableScrollBar();
  26. $layout.removeClass('admin-nav-mini');
  27. } else {
  28. $layout.addClass('admin-nav-mini');
  29. }
  30. layui.event.call(this, 'admin', 'flexible({*})', {expand: expand});
  31. }
  32. };
  33. /** 设置导航栏选中 */
  34. admin.activeNav = function (url) {
  35. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.activeNav(url);
  36. if (!url) return console.warn('active url is null');
  37. $(sideDOM + '>.layui-nav .layui-nav-item .layui-nav-child dd.layui-this').removeClass('layui-this');
  38. $(sideDOM + '>.layui-nav .layui-nav-item.layui-this').removeClass('layui-this');
  39. var $a = $(sideDOM + '>.layui-nav a[lay-href="' + url + '"]');
  40. if ($a.length === 0) return console.warn(url + ' not found');
  41. var isMini = $('.layui-layout-admin').hasClass('admin-nav-mini');
  42. if ($(sideDOM + '>.layui-nav').attr('lay-shrink') === '_all') { // 手风琴效果
  43. var $pChilds = $a.parent('dd').parents('.layui-nav-child');
  44. if (!isMini) {
  45. $(sideDOM + '>.layui-nav .layui-nav-itemed>.layui-nav-child').not($pChilds)
  46. .css('display', 'block').slideUp('fast', function () {
  47. $(this).css('display', '');
  48. });
  49. }
  50. $(sideDOM + '>.layui-nav .layui-nav-itemed').not($pChilds.parent()).removeClass('layui-nav-itemed');
  51. }
  52. $a.parent().addClass('layui-this'); // 选中当前
  53. // 展开所有父级
  54. var $asParents = $a.parent('dd').parents('.layui-nav-child').parent();
  55. if (!isMini) {
  56. var $childs = $asParents.not('.layui-nav-itemed').children('.layui-nav-child');
  57. $childs.slideDown('fast', function () {
  58. if ($(this).is($childs.last())) {
  59. $childs.css('display', '');
  60. // 菜单超出屏幕自动滚动
  61. var topBeyond = $a.offset().top + $a.outerHeight() + 30 - admin.getPageHeight();
  62. var topDisparity = 50 + 65 - $a.offset().top;
  63. if (topBeyond > 0) {
  64. $(sideDOM).animate({'scrollTop': $(sideDOM).scrollTop() + topBeyond}, 300);
  65. } else if (topDisparity > 0) {
  66. $(sideDOM).animate({'scrollTop': $(sideDOM).scrollTop() - topDisparity}, 300);
  67. }
  68. }
  69. });
  70. }
  71. $asParents.addClass('layui-nav-itemed');
  72. // 适配多系统模式
  73. $('ul[lay-filter="' + navFilter + '"]').addClass('layui-hide');
  74. var $aUl = $a.parents('.layui-nav');
  75. $aUl.removeClass('layui-hide');
  76. $(headerDOM + '>.layui-nav>.layui-nav-item').removeClass('layui-this');
  77. $(headerDOM + '>.layui-nav>.layui-nav-item>a[nav-bind="' + $aUl.attr('nav-id') + '"]').parent().addClass('layui-this');
  78. // 每次进行刷新页面数据
  79. admin.refresh(url)
  80. };
  81. /** 右侧弹出 */
  82. admin.popupRight = function (param) {
  83. param.anim = -1;
  84. param.offset = 'r';
  85. param.move = false;
  86. param.fixed = true;
  87. if (param.area === undefined) param.area = '336px';
  88. if (param.title === undefined) param.title = false;
  89. if (param.closeBtn === undefined) param.closeBtn = false;
  90. if (param.shadeClose === undefined) param.shadeClose = true;
  91. if (param.skin === undefined) param.skin = 'layui-anim layui-anim-rl layui-layer-adminRight';
  92. return admin.open(param);
  93. };
  94. /** 封装layer.open */
  95. admin.open = function (param) {
  96. if (param.content && param.type === 2) param.url = undefined; // 参数纠正
  97. if (param.url && (param.type === 2 || param.type === undefined)) param.type = 1; // 参数纠正
  98. if (param.area === undefined) param.area = param.type === 2 ? ['360px', '300px'] : '360px';
  99. if (param.offset === undefined) param.offset = '70px';
  100. if (param.shade === undefined) param.shade = .1;
  101. if (param.fixed === undefined) param.fixed = false;
  102. if (param.resize === undefined) param.resize = false;
  103. if (param.skin === undefined) param.skin = 'layui-layer-admin';
  104. var eCallBack = param.end;
  105. param.end = function () {
  106. layer.closeAll('tips'); // 关闭表单验证的tips
  107. eCallBack && eCallBack();
  108. };
  109. if (param.url) {
  110. var sCallBack = param.success;
  111. param.success = function (layero, index) {
  112. $(layero).data('tpl', param.tpl || '');
  113. admin.reloadLayer(index, param.url, sCallBack);
  114. };
  115. } else if (param.tpl && param.content) {
  116. param.content = admin.util.tpl(param.content, param.data, setter.tplOpen, setter.tplClose);
  117. }
  118. var layIndex = layer.open(param);
  119. if (param.data) admin.layerData['d' + layIndex] = param.data;
  120. return layIndex;
  121. };
  122. /** 获取弹窗数据 */
  123. admin.getLayerData = function (index, key) {
  124. if (index === undefined) {
  125. index = parent.layer.getFrameIndex(window.name);
  126. if (index === undefined) return null;
  127. else return parent.layui.admin.getLayerData(parseInt(index), key);
  128. } else if (isNaN(index)) {
  129. index = admin.getLayerIndex(index);
  130. }
  131. if (index === undefined) return;
  132. var layerData = admin.layerData['d' + index];
  133. if (key && layerData) return layerData[key];
  134. return layerData;
  135. };
  136. /** 放入弹窗数据 */
  137. admin.putLayerData = function (key, value, index) {
  138. if (index === undefined) {
  139. index = parent.layer.getFrameIndex(window.name);
  140. if (index === undefined) return;
  141. else return parent.layui.admin.putLayerData(key, value, parseInt(index));
  142. } else if (isNaN(index)) {
  143. index = admin.getLayerIndex(index);
  144. }
  145. if (index === undefined) return;
  146. var layerData = admin.getLayerData(index);
  147. if (!layerData) layerData = {};
  148. layerData[key] = value;
  149. admin.layerData['d' + index] = layerData;
  150. };
  151. /** 刷新url方式的layer */
  152. admin.reloadLayer = function (index, url, success) {
  153. if (typeof url === 'function') {
  154. success = url;
  155. url = undefined;
  156. }
  157. if (isNaN(index)) index = admin.getLayerIndex(index);
  158. if (index === undefined) return;
  159. var $layero = $('#layui-layer' + index);
  160. if (url === undefined) url = $layero.data('url');
  161. if (!url) return;
  162. $layero.data('url', url);
  163. admin.showLoading($layero);
  164. admin.ajax({
  165. url: url,
  166. dataType: 'html',
  167. success: function (res) {
  168. admin.removeLoading($layero, false);
  169. if (typeof res !== 'string') res = JSON.stringify(res);
  170. var tpl = $layero.data('tpl');
  171. // 模板解析
  172. if (tpl === true || tpl === 'true') {
  173. var data = admin.getLayerData(index) || {};
  174. data.layerIndex = index;
  175. // 模板里面有动态模板处理
  176. var $html = $('<div>' + res + '</div>'), tplAll = {};
  177. $html.find('script,[tpl-ignore]').each(function (i) {
  178. var $this = $(this);
  179. tplAll['temp_' + i] = $this[0].outerHTML;
  180. $this.after('${temp_' + i + '}').remove();
  181. });
  182. res = admin.util.tpl($html.html(), data, setter.tplOpen, setter.tplClose);
  183. for (var f in tplAll) res = res.replace('${' + f + '}', tplAll[f]);
  184. }
  185. $layero.children('.layui-layer-content').html(res);
  186. admin.renderTpl('#layui-layer' + index + ' [ew-tpl]');
  187. success && success($layero[0], index);
  188. }
  189. });
  190. };
  191. /** 封装layer.alert */
  192. admin.alert = function (content, options, yes) {
  193. if (typeof options === 'function') {
  194. yes = options;
  195. options = {};
  196. }
  197. if (options.skin === undefined) options.skin = 'layui-layer-admin';
  198. if (options.shade === undefined) options.shade = .1;
  199. return layer.alert(content, options, yes);
  200. };
  201. /** 封装layer.confirm */
  202. admin.confirm = function (content, options, yes, cancel) {
  203. if (typeof options === 'function') {
  204. cancel = yes;
  205. yes = options;
  206. options = {};
  207. }
  208. if (options.skin === undefined) options.skin = 'layui-layer-admin';
  209. if (options.shade === undefined) options.shade = .1;
  210. return layer.confirm(content, options, yes, cancel);
  211. };
  212. /** 封装layer.prompt */
  213. admin.prompt = function (options, yes) {
  214. if (typeof options === 'function') {
  215. yes = options;
  216. options = {};
  217. }
  218. if (options.skin === undefined) options.skin = 'layui-layer-admin layui-layer-prompt';
  219. if (options.shade === undefined) options.shade = .1;
  220. return layer.prompt(options, yes);
  221. };
  222. /** 封装ajax请求,返回数据类型为json */
  223. admin.req = function (url, data, success, method, option) {
  224. if (typeof data === 'function') {
  225. option = method;
  226. method = success;
  227. success = data;
  228. data = {};
  229. }
  230. if (method !== undefined && typeof method !== 'string') {
  231. option = method;
  232. method = undefined;
  233. }
  234. if (!method) method = 'GET';
  235. if (typeof data === 'string') {
  236. if (!option) option = {};
  237. if (!option.contentType) option.contentType = 'application/json;charset=UTF-8';
  238. } else if (setter.reqPutToPost) {
  239. if ('put' === method.toLowerCase()) {
  240. method = 'POST';
  241. data._method = 'PUT';
  242. } else if ('delete' === method.toLowerCase()) {
  243. method = 'GET';
  244. data._method = 'DELETE';
  245. }
  246. }
  247. return admin.ajax($.extend({
  248. url: (setter.baseServer || '') + url, data: data, type: method, dataType: 'json', success: success
  249. }, option));
  250. };
  251. /** 封装ajax请求 */
  252. admin.ajax = function (param) {
  253. var oldParam = admin.util.deepClone(param);
  254. if (!param.dataType) param.dataType = 'json';
  255. if (!param.headers) param.headers = {};
  256. // 统一设置header
  257. var headers = setter.getAjaxHeaders(param.url);
  258. if (headers) {
  259. for (var i = 0; i < headers.length; i++) {
  260. if (param.headers[headers[i].name] === undefined) param.headers[headers[i].name] = headers[i].value;
  261. }
  262. }
  263. // success预处理
  264. var success = param.success;
  265. param.success = function (result, status, xhr) {
  266. var before = setter.ajaxSuccessBefore(admin.parseJSON(result), param.url, {
  267. param: oldParam, reload: function (p) {
  268. admin.ajax($.extend(true, oldParam, p));
  269. }, update: function (r) {
  270. result = r;
  271. }, xhr: xhr
  272. });
  273. if (before !== false) success && success(result, status, xhr);
  274. else param.cancel && param.cancel();
  275. };
  276. param.error = function (xhr, status) {
  277. param.success({code: xhr.status, msg: xhr.statusText}, status, xhr);
  278. };
  279. // 解决缓存问题
  280. if (layui.cache.version && (!setter.apiNoCache || param.dataType.toLowerCase() !== 'json')) {
  281. if (param.url.indexOf('?') === -1) param.url += '?v=';
  282. else param.url += '&v=';
  283. if (layui.cache.version === true) param.url += new Date().getTime();
  284. else param.url += layui.cache.version;
  285. }
  286. return $.ajax(param);
  287. };
  288. /** 解析json */
  289. admin.parseJSON = function (str) {
  290. if (typeof str === 'string') {
  291. try {
  292. return JSON.parse(str);
  293. } catch (e) {
  294. }
  295. }
  296. return str;
  297. };
  298. /** 显示加载动画 */
  299. admin.showLoading = function (elem, type, opacity, size) {
  300. if (elem !== undefined && (typeof elem !== 'string') && !(elem instanceof $)) {
  301. type = elem.type;
  302. opacity = elem.opacity;
  303. size = elem.size;
  304. elem = elem.elem;
  305. }
  306. if (type === undefined) type = setter.defaultLoading || 1;
  307. if (size === undefined) size = 'sm';
  308. if (elem === undefined) elem = 'body';
  309. var loader = [
  310. '<div class="ball-loader ' + size + '"><span></span><span></span><span></span><span></span></div>',
  311. '<div class="rubik-loader ' + size + '"></div>',
  312. '<div class="signal-loader ' + size + '"><span></span><span></span><span></span><span></span></div>',
  313. '<div class="layui-loader ' + size + '"><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i></div>'
  314. ];
  315. $(elem).addClass('page-no-scroll'); // 禁用滚动条
  316. $(elem).scrollTop(0);
  317. var $loading = $(elem).children('.page-loading');
  318. if ($loading.length <= 0) {
  319. $(elem).append('<div class="page-loading">' + loader[type - 1] + '</div>');
  320. $loading = $(elem).children('.page-loading');
  321. }
  322. if (opacity !== undefined) $loading.css('background-color', 'rgba(255,255,255,' + opacity + ')');
  323. $loading.show();
  324. };
  325. /** 移除加载动画 */
  326. admin.removeLoading = function (elem, fade, del) {
  327. if (elem === undefined) elem = 'body';
  328. if (fade === undefined) fade = true;
  329. var $loading = $(elem).children('.page-loading');
  330. if (del) $loading.remove();
  331. else if (fade) $loading.fadeOut('fast');
  332. else $loading.hide();
  333. $(elem).removeClass('page-no-scroll');
  334. };
  335. /** 缓存临时数据 */
  336. admin.putTempData = function (key, value, local) {
  337. var tableName = local ? setter.tableName : setter.tableName + '_tempData';
  338. if (value === undefined || value === null) {
  339. if (local) layui.data(tableName, {key: key, remove: true});
  340. else layui.sessionData(tableName, {key: key, remove: true});
  341. } else {
  342. if (local) layui.data(tableName, {key: key, value: value});
  343. else layui.sessionData(tableName, {key: key, value: value});
  344. }
  345. };
  346. /** 获取缓存临时数据 */
  347. admin.getTempData = function (key, local) {
  348. if (typeof key === 'boolean') {
  349. local = key;
  350. key = undefined;
  351. }
  352. var tableName = local ? setter.tableName : setter.tableName + '_tempData';
  353. var tempData = local ? layui.data(tableName) : layui.sessionData(tableName);
  354. if (!key) return tempData;
  355. return tempData ? tempData[key] : undefined;
  356. };
  357. /** 滑动选项卡 */
  358. admin.rollPage = function (d) {
  359. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.rollPage(d);
  360. var $tabTitle = $(tabDOM + '>.layui-tab-title');
  361. var left = $tabTitle.scrollLeft();
  362. if ('left' === d) {
  363. $tabTitle.animate({'scrollLeft': left - 120}, 100);
  364. } else if ('auto' === d) {
  365. var autoLeft = 0;
  366. $tabTitle.children("li").each(function () {
  367. if ($(this).hasClass('layui-this')) return false;
  368. else autoLeft += $(this).outerWidth();
  369. });
  370. $tabTitle.animate({'scrollLeft': autoLeft - 120}, 100);
  371. } else {
  372. $tabTitle.animate({'scrollLeft': left + 120}, 100);
  373. }
  374. };
  375. /** 刷新当前选项卡 */
  376. admin.refresh = function (url, isIndex) {
  377. console.log(url,isIndex)
  378. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.refresh(url);
  379. var $iframe;
  380. if (!url) {
  381. $iframe = $(tabDOM + '>.layui-tab-content>.layui-tab-item.layui-show>.admin-iframe');
  382. if (!$iframe || $iframe.length <= 0) $iframe = $(bodyDOM + '>div>.admin-iframe');
  383. } else {
  384. $iframe = $(tabDOM + '>.layui-tab-content>.layui-tab-item>.admin-iframe[lay-id="' + url + '"]');
  385. if (!$iframe || $iframe.length <= 0) $iframe = $(bodyDOM + '>.admin-iframe');
  386. }
  387. if (!$iframe || !$iframe[0]) return console.warn(url + ' is not found');
  388. try {
  389. if (isIndex && $iframe[0].contentWindow.refreshTab) {
  390. $iframe[0].contentWindow.refreshTab();
  391. } else {
  392. admin.showLoading({elem: $iframe.parent(), size: ''});
  393. $iframe[0].contentWindow.location.reload();
  394. }
  395. } catch (e) {
  396. console.warn(e);
  397. $iframe.attr('src', $iframe.attr('src'));
  398. }
  399. };
  400. /** 关闭当前选项卡 */
  401. admin.closeThisTabs = function (url) {
  402. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.closeThisTabs(url);
  403. admin.closeTabOperNav();
  404. var $title = $(tabDOM + '>.layui-tab-title');
  405. if (!url) {
  406. if ($title.find('li').first().hasClass('layui-this')) return layer.msg('主页不能关闭', {icon: 2});
  407. $title.find('li.layui-this').find('.layui-tab-close').trigger('click');
  408. } else {
  409. if (url === $title.find('li').first().attr('lay-id')) return layer.msg('主页不能关闭', {icon: 2});
  410. $title.find('li[lay-id="' + url + '"]').find('.layui-tab-close').trigger('click');
  411. }
  412. };
  413. /** 关闭其他选项卡 */
  414. admin.closeOtherTabs = function (url) {
  415. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.closeOtherTabs(url);
  416. if (!url) {
  417. $(tabDOM + '>.layui-tab-title li:gt(0):not(.layui-this)').find('.layui-tab-close').trigger('click');
  418. } else {
  419. $(tabDOM + '>.layui-tab-title li:gt(0)').each(function () {
  420. if (url !== $(this).attr('lay-id')) $(this).find('.layui-tab-close').trigger('click');
  421. });
  422. }
  423. admin.closeTabOperNav();
  424. };
  425. /** 关闭所有选项卡 */
  426. admin.closeAllTabs = function () {
  427. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.closeAllTabs();
  428. $(tabDOM + '>.layui-tab-title li:gt(0)').find('.layui-tab-close').trigger('click');
  429. $(tabDOM + '>.layui-tab-title li:eq(0)').trigger('click');
  430. admin.closeTabOperNav();
  431. };
  432. /** 关闭选项卡操作菜单 */
  433. admin.closeTabOperNav = function () {
  434. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.closeTabOperNav();
  435. $('.layui-icon-down .layui-nav .layui-nav-child').removeClass('layui-show');
  436. };
  437. /** 设置主题 */
  438. admin.changeTheme = function (theme, win, noCache, noChild) {
  439. if (!noCache) admin.putSetting('defaultTheme', theme);
  440. if (!win) win = top;
  441. admin.removeTheme(win);
  442. if (theme) {
  443. try {
  444. var $body = win.layui.jquery('body');
  445. $body.addClass(theme);
  446. $body.data('theme', theme);
  447. } catch (e) {
  448. }
  449. }
  450. if (noChild) return;
  451. var ifs = win.frames;
  452. for (var i = 0; i < ifs.length; i++) admin.changeTheme(theme, ifs[i], true, false);
  453. };
  454. /** 移除主题 */
  455. admin.removeTheme = function (w) {
  456. if (!w) w = window;
  457. try {
  458. var $body = w.layui.jquery('body');
  459. var theme = $body.data('theme');
  460. if (theme) $body.removeClass(theme);
  461. $body.removeData('theme');
  462. } catch (e) {
  463. }
  464. };
  465. /** 关闭当前iframe层弹窗 */
  466. admin.closeThisDialog = function () {
  467. return admin.closeDialog();
  468. };
  469. /** 关闭elem所在的页面层弹窗 */
  470. admin.closeDialog = function (elem) {
  471. if (elem) layer.close(admin.getLayerIndex(elem));
  472. else parent.layer.close(parent.layer.getFrameIndex(window.name));
  473. };
  474. /** 获取页面层弹窗的index */
  475. admin.getLayerIndex = function (elem) {
  476. if (!elem) return parent.layer.getFrameIndex(window.name);
  477. var id = $(elem).parents('.layui-layer').first().attr('id');
  478. if (id && id.length >= 11) return id.substring(11);
  479. };
  480. /** 让当前的iframe弹层自适应高度 */
  481. admin.iframeAuto = function () {
  482. return parent.layer.iframeAuto(parent.layer.getFrameIndex(window.name));
  483. };
  484. /** 获取浏览器高度 */
  485. admin.getPageHeight = function () {
  486. return document.documentElement.clientHeight || document.body.clientHeight;
  487. };
  488. /** 获取浏览器宽度 */
  489. admin.getPageWidth = function () {
  490. return document.documentElement.clientWidth || document.body.clientWidth;
  491. };
  492. /** 绑定表单弹窗 */
  493. admin.modelForm = function (layero, btnFilter, formFilter) {
  494. var $layero = $(layero);
  495. $layero.addClass('layui-form');
  496. if (formFilter) $layero.attr('lay-filter', formFilter);
  497. // 确定按钮绑定submit
  498. var $btnSubmit = $layero.find('.layui-layer-btn .layui-layer-btn0');
  499. $btnSubmit.attr('lay-submit', '');
  500. $btnSubmit.attr('lay-filter', btnFilter);
  501. };
  502. /** loading按钮 */
  503. admin.btnLoading = function (elem, text, loading) {
  504. if (text !== undefined && (typeof text === 'boolean')) {
  505. loading = text;
  506. text = undefined;
  507. }
  508. if (text === undefined) text = '&nbsp;加载中';
  509. if (loading === undefined) loading = true;
  510. var $elem = $(elem);
  511. if (loading) {
  512. $elem.addClass('ew-btn-loading');
  513. $elem.prepend('<span class="ew-btn-loading-text"><i class="layui-icon layui-icon-loading layui-anim layui-anim-rotate layui-anim-loop"></i>' + text + '</span>');
  514. $elem.attr('disabled', 'disabled').prop('disabled', true);
  515. } else {
  516. $elem.removeClass('ew-btn-loading');
  517. $elem.children('.ew-btn-loading-text').remove();
  518. $elem.removeProp('disabled').removeAttr('disabled');
  519. }
  520. };
  521. /** 鼠标移入侧边栏自动展开 */
  522. admin.openSideAutoExpand = function () {
  523. var $side = $('.layui-layout-admin>.layui-side');
  524. $side.off('mouseenter.openSideAutoExpand').on("mouseenter.openSideAutoExpand", function () {
  525. if (!$(this).parent().hasClass('admin-nav-mini')) return;
  526. admin.flexible(true);
  527. $(this).addClass('side-mini-hover');
  528. });
  529. $side.off('mouseleave.openSideAutoExpand').on("mouseleave.openSideAutoExpand", function () {
  530. if (!$(this).hasClass('side-mini-hover')) return;
  531. admin.flexible(false);
  532. $(this).removeClass('side-mini-hover');
  533. });
  534. };
  535. /** 表格单元格超出内容自动展开 */
  536. admin.openCellAutoExpand = function () {
  537. var $body = $('body');
  538. $body.off('mouseenter.openCellAutoExpand').on('mouseenter.openCellAutoExpand', '.layui-table-view td', function () {
  539. $(this).find('.layui-table-grid-down').trigger('click');
  540. });
  541. $body.off('mouseleave.openCellAutoExpand').on('mouseleave.openCellAutoExpand', '.layui-table-tips>.layui-layer-content', function () {
  542. $('.layui-table-tips-c').trigger('click');
  543. });
  544. };
  545. /** open事件解析layer参数 */
  546. admin.parseLayerOption = function (option) {
  547. // 数组类型进行转换
  548. for (var f in option) {
  549. if (!option.hasOwnProperty(f)) continue;
  550. if (option[f] && option[f].toString().indexOf(',') !== -1) option[f] = option[f].toString().split(',');
  551. }
  552. // function类型参数转换
  553. var fs = {'success': 'layero,index', 'cancel': 'index,layero', 'end': '', 'full': '', 'min': '', 'restore': ''};
  554. for (var k in fs) {
  555. if (!fs.hasOwnProperty(k) || !option[k]) continue;
  556. try {
  557. if (/^[a-zA-Z_]+[a-zA-Z0-9_]+$/.test(option[k])) option[k] += '()';
  558. option[k] = new Function(fs[k], option[k]);
  559. } catch (e) {
  560. option[k] = undefined;
  561. }
  562. }
  563. // content取内容
  564. if (option.content && (typeof option.content === 'string') && option.content.indexOf('#') === 0) {
  565. if ($(option.content).is('script')) option.content = $(option.content).html();
  566. else option.content = $(option.content);
  567. }
  568. if (option.type === undefined && option.url === undefined) option.type = 2; // 默认为iframe类型
  569. return option;
  570. };
  571. /** 字符串形式的parent.parent转window对象 */
  572. admin.strToWin = function (str) {
  573. var win = window;
  574. if (!str) return win;
  575. var ws = str.split('.');
  576. for (var i = 0; i < ws.length; i++) win = win[ws[i]];
  577. return win;
  578. };
  579. /** 解决折叠侧边栏表格滚动条闪现 */
  580. admin.hideTableScrollBar = function (win) {
  581. if (admin.getPageWidth() <= 768) return;
  582. if (!win) {
  583. var $iframe = $(tabDOM + '>.layui-tab-content>.layui-tab-item.layui-show>.admin-iframe');
  584. if ($iframe.length <= 0) $iframe = $(bodyDOM + '>div>.admin-iframe');
  585. if ($iframe.length > 0) win = $iframe[0].contentWindow;
  586. }
  587. try { // 可能会跨域
  588. if (window.hsbTimer) clearTimeout(window.hsbTimer);
  589. win.layui.jquery('.layui-table-body.layui-table-main').addClass('no-scrollbar');
  590. window.hsbTimer = setTimeout(function () {
  591. win.layui.jquery('.layui-table-body.layui-table-main').removeClass('no-scrollbar');
  592. }, 800);
  593. } catch (e) {
  594. }
  595. };
  596. /** 判断是否是主框架 */
  597. admin.isTop = function () {
  598. return $(bodyDOM).length > 0;
  599. };
  600. /** admin提供的事件 */
  601. admin.events = {
  602. /* 折叠侧导航 */
  603. flexible: function () {
  604. admin.strToWin($(this).data('window')).layui.admin.flexible();
  605. },
  606. /* 刷新主体部分 */
  607. refresh: function () {
  608. admin.strToWin($(this).data('window')).layui.admin.refresh();
  609. },
  610. /* 后退 */
  611. back: function () {
  612. admin.strToWin($(this).data('window')).history.back();
  613. },
  614. /* 设置主题 */
  615. theme: function () {
  616. var option = admin.util.deepClone($(this).data());
  617. console.log(option);
  618. admin.strToWin(option.window).layui.admin.popupRight($.extend({
  619. id: 'layer-theme', url: option.url || 'page/tpl/tpl-theme.html'
  620. }, admin.parseLayerOption(option)));
  621. },
  622. /* 打开便签 */
  623. note: function () {
  624. var option = admin.util.deepClone($(this).data());
  625. admin.strToWin(option.window).layui.admin.popupRight($.extend({
  626. id: 'layer-note', url: option.url || 'page/tpl/tpl-note.html'
  627. }, admin.parseLayerOption(option)));
  628. },
  629. /* 打开消息 */
  630. message: function () {
  631. var option = admin.util.deepClone($(this).data());
  632. admin.strToWin(option.window).layui.admin.popupRight($.extend({
  633. id: 'layer-notice', url: option.url || 'page/tpl/tpl-message.html'
  634. }, admin.parseLayerOption(option)));
  635. },
  636. /* 打开修改密码弹窗 */
  637. psw: function () {
  638. var option = admin.util.deepClone($(this).data());
  639. console.log(option)
  640. admin.strToWin(option.window).layui.admin.open($.extend({
  641. id: 'layer-psw', title: '修改密码', shade: 0, url: option.url || 'page/tpl/tpl-password.html'
  642. }, admin.parseLayerOption(option)));
  643. },
  644. /* 退出登录 */
  645. logout: function () {
  646. var option = admin.util.deepClone($(this).data());
  647. admin.unlockScreen();
  648. function doLogout() {
  649. if (option.ajax) {
  650. var loadIndex = layer.load(2);
  651. admin.req(option.ajax, function (res) {
  652. layer.close(loadIndex);
  653. if (option.parseData) {
  654. try {
  655. var parseData = new Function('res', option.parseData);
  656. res = parseData(res);
  657. } catch (e) {
  658. console.error(e);
  659. }
  660. }
  661. if (res.code == (option.code || 0)) {
  662. setter.removeToken && setter.removeToken();
  663. location.replace(option.url || '/');
  664. } else {
  665. layer.msg(res.msg, {icon: 2});
  666. }
  667. }, option.method || 'delete');
  668. } else {
  669. setter.removeToken && setter.removeToken();
  670. location.replace(option.url || '/');
  671. }
  672. }
  673. if (false === option.confirm || 'false' === option.confirm) return doLogout();
  674. admin.strToWin(option.window).layui.layer.confirm(option.content || '确定要退出登录吗?', $.extend({
  675. title: '温馨提示', skin: 'layui-layer-admin', shade: .1
  676. }, admin.parseLayerOption(option)), function () {
  677. doLogout();
  678. });
  679. },
  680. /* 打开弹窗 */
  681. open: function () {
  682. var option = admin.util.deepClone($(this).data());
  683. admin.strToWin(option.window).layui.admin.open(admin.parseLayerOption(option));
  684. },
  685. /* 打开右侧弹窗 */
  686. popupRight: function () {
  687. var option = admin.util.deepClone($(this).data());
  688. admin.strToWin(option.window).layui.admin.popupRight(admin.parseLayerOption(option));
  689. },
  690. /* 全屏 */
  691. fullScreen: function () {
  692. var ac = 'layui-icon-screen-full', ic = 'layui-icon-screen-restore';
  693. var $ti = $(this).find('i');
  694. var isFullscreen = document.fullscreenElement || document.msFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement || false;
  695. if (isFullscreen) {
  696. var efs = document.exitFullscreen || document.webkitExitFullscreen || document.mozCancelFullScreen || document.msExitFullscreen;
  697. if (efs) {
  698. efs.call(document);
  699. } else if (window.ActiveXObject) {
  700. var ws = new ActiveXObject('WScript.Shell');
  701. ws && ws.SendKeys('{F11}');
  702. }
  703. $ti.addClass(ac).removeClass(ic);
  704. } else {
  705. var el = document.documentElement;
  706. var rfs = el.requestFullscreen || el.webkitRequestFullscreen || el.mozRequestFullScreen || el.msRequestFullscreen;
  707. if (rfs) {
  708. rfs.call(el);
  709. } else if (window.ActiveXObject) {
  710. var wss = new ActiveXObject('WScript.Shell');
  711. wss && wss.SendKeys('{F11}');
  712. }
  713. $ti.addClass(ic).removeClass(ac);
  714. }
  715. },
  716. /* 左滑动tab */
  717. leftPage: function () {
  718. admin.strToWin($(this).data('window')).layui.admin.rollPage('left');
  719. },
  720. /* 右滑动tab */
  721. rightPage: function () {
  722. admin.strToWin($(this).data('window')).layui.admin.rollPage();
  723. },
  724. /* 关闭当前选项卡 */
  725. closeThisTabs: function () {
  726. var url = $(this).data('url');
  727. admin.strToWin($(this).data('window')).layui.admin.closeThisTabs(url);
  728. },
  729. /* 关闭其他选项卡 */
  730. closeOtherTabs: function () {
  731. admin.strToWin($(this).data('window')).layui.admin.closeOtherTabs();
  732. },
  733. /* 关闭所有选项卡 */
  734. closeAllTabs: function () {
  735. admin.strToWin($(this).data('window')).layui.admin.closeAllTabs();
  736. },
  737. /* 关闭当前弹窗(智能) */
  738. closeDialog: function () {
  739. if ($(this).parents('.layui-layer').length > 0) admin.closeDialog(this);
  740. else admin.closeDialog();
  741. },
  742. /* 关闭当前iframe弹窗 */
  743. closeIframeDialog: function () {
  744. admin.closeDialog();
  745. },
  746. /* 关闭当前页面层弹窗 */
  747. closePageDialog: function () {
  748. admin.closeDialog(this);
  749. },
  750. /* 锁屏 */
  751. lockScreen: function () {
  752. admin.strToWin($(this).data('window')).layui.admin.lockScreen($(this).data('url'));
  753. }
  754. };
  755. /** 选择位置 */
  756. admin.chooseLocation = function (param) {
  757. var dialogTitle = param.title; // 弹窗标题
  758. var onSelect = param.onSelect; // 选择回调
  759. var needCity = param.needCity; // 是否返回行政区
  760. var mapCenter = param.center; // 地图中心
  761. var defaultZoom = param.defaultZoom; // 地图默认缩放级别
  762. var pointZoom = param.pointZoom; // 选中时地图缩放级别
  763. var searchKeywords = param.keywords; // poi检索关键字
  764. var searchPageSize = param.pageSize; // poi检索最大数量
  765. var mapJsUrl = param.mapJsUrl; // 高德地图js的url
  766. if (dialogTitle === undefined) dialogTitle = '选择位置';
  767. if (defaultZoom === undefined) defaultZoom = 11;
  768. if (pointZoom === undefined) pointZoom = 17;
  769. if (searchKeywords === undefined) searchKeywords = '';
  770. if (searchPageSize === undefined) searchPageSize = 30;
  771. if (mapJsUrl === undefined) mapJsUrl = 'https://webapi.amap.com/maps?v=1.4.14&key=de9126c873386b47164937c9e4d5a361';
  772. var isSelMove = false, selLocation;
  773. // 搜索附近
  774. var searchNearBy = function (lat, lng) {
  775. AMap.service(['AMap.PlaceSearch'], function () {
  776. var placeSearch = new AMap.PlaceSearch({
  777. type: '汽车服务|汽车销售|汽车维修|摩托车服务|餐饮服务|购物服务|生活服务|体育休闲服务| 医疗保健服务|住宿服务|风景名胜|\n' +
  778. ' 商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施', pageSize: searchPageSize, pageIndex: 1
  779. });
  780. var cpoint = [lng, lat];
  781. placeSearch.searchNearBy(searchKeywords, cpoint, 1000, function (status, result) {
  782. if (status === 'complete') {
  783. var pois = result.poiList.pois;
  784. var htmlList = '';
  785. for (var i = 0; i < pois.length; i++) {
  786. var poiItem = pois[i];
  787. if (poiItem.location !== undefined) {
  788. htmlList += '<div data-lng="' + poiItem.location.lng + '" data-lat="' + poiItem.location.lat + '" class="ew-map-select-search-list-item">';
  789. htmlList += ' <div class="ew-map-select-search-list-item-title">' + poiItem.name + '</div>';
  790. htmlList += ' <div class="ew-map-select-search-list-item-address">' + poiItem.address + '</div>';
  791. htmlList += ' <div class="ew-map-select-search-list-item-icon-ok layui-hide"><i class="layui-icon layui-icon-ok-circle"></i></div>';
  792. htmlList += '</div>';
  793. }
  794. }
  795. $('#ew-map-select-pois').html(htmlList);
  796. }
  797. });
  798. });
  799. };
  800. // 渲染地图
  801. var renderMap = function () {
  802. var mapOption = {
  803. resizeEnable: true, // 监控地图容器尺寸变化
  804. zoom: defaultZoom // 初缩放级别
  805. };
  806. mapCenter && (mapOption.center = mapCenter);
  807. var map = new AMap.Map('ew-map-select-map', mapOption);
  808. // 地图加载完成
  809. map.on('complete', function () {
  810. var center = map.getCenter();
  811. searchNearBy(center.lat, center.lng);
  812. });
  813. // 地图移动结束事件
  814. map.on('moveend', function () {
  815. if (isSelMove) {
  816. isSelMove = false;
  817. } else {
  818. $('#ew-map-select-tips').addClass('layui-hide');
  819. $('#ew-map-select-center-img').removeClass('bounceInDown');
  820. setTimeout(function () {
  821. $('#ew-map-select-center-img').addClass('bounceInDown');
  822. });
  823. var center = map.getCenter();
  824. searchNearBy(center.lat, center.lng);
  825. }
  826. });
  827. // poi列表点击事件
  828. $('#ew-map-select-pois').off('click').on('click', '.ew-map-select-search-list-item', function () {
  829. $('#ew-map-select-tips').addClass('layui-hide');
  830. $('#ew-map-select-pois .ew-map-select-search-list-item-icon-ok').addClass('layui-hide');
  831. $(this).find('.ew-map-select-search-list-item-icon-ok').removeClass('layui-hide');
  832. $('#ew-map-select-center-img').removeClass('bounceInDown');
  833. setTimeout(function () {
  834. $('#ew-map-select-center-img').addClass('bounceInDown');
  835. });
  836. var lng = $(this).data('lng');
  837. var lat = $(this).data('lat');
  838. var name = $(this).find('.ew-map-select-search-list-item-title').text();
  839. var address = $(this).find('.ew-map-select-search-list-item-address').text();
  840. selLocation = {name: name, address: address, lat: lat, lng: lng};
  841. isSelMove = true;
  842. map.setZoomAndCenter(pointZoom, [lng, lat]);
  843. });
  844. // 确定按钮点击事件
  845. $('#ew-map-select-btn-ok').click(function () {
  846. if (selLocation === undefined) {
  847. layer.msg('请点击位置列表选择', {icon: 2, anim: 6});
  848. } else if (onSelect) {
  849. if (needCity) {
  850. var loadIndex = layer.load(2);
  851. map.setCenter([selLocation.lng, selLocation.lat]);
  852. map.getCity(function (result) {
  853. layer.close(loadIndex);
  854. selLocation.city = result;
  855. admin.closeDialog('#ew-map-select-btn-ok');
  856. onSelect(selLocation);
  857. });
  858. } else {
  859. admin.closeDialog('#ew-map-select-btn-ok');
  860. onSelect(selLocation);
  861. }
  862. } else {
  863. admin.closeDialog('#ew-map-select-btn-ok');
  864. }
  865. });
  866. // 搜索提示
  867. var $inputSearch = $('#ew-map-select-input-search');
  868. $inputSearch.off('input').on('input', function () {
  869. var keywords = $(this).val();
  870. var $selectTips = $('#ew-map-select-tips');
  871. if (!keywords) {
  872. $selectTips.html('');
  873. $selectTips.addClass('layui-hide');
  874. }
  875. AMap.plugin('AMap.Autocomplete', function () {
  876. var autoComplete = new AMap.Autocomplete({city: '全国'});
  877. autoComplete.search(keywords, function (status, result) {
  878. if (result.tips) {
  879. var tips = result.tips;
  880. var htmlList = '';
  881. for (var i = 0; i < tips.length; i++) {
  882. var tipItem = tips[i];
  883. if (tipItem.location !== undefined) {
  884. htmlList += '<div data-lng="' + tipItem.location.lng + '" data-lat="' + tipItem.location.lat + '" class="ew-map-select-search-list-item">';
  885. htmlList += ' <div class="ew-map-select-search-list-item-icon-search"><i class="layui-icon layui-icon-search"></i></div>';
  886. htmlList += ' <div class="ew-map-select-search-list-item-title">' + tipItem.name + '</div>';
  887. htmlList += ' <div class="ew-map-select-search-list-item-address">' + tipItem.address + '</div>';
  888. htmlList += '</div>';
  889. }
  890. }
  891. $selectTips.html(htmlList);
  892. if (tips.length === 0) $('#ew-map-select-tips').addClass('layui-hide');
  893. else $('#ew-map-select-tips').removeClass('layui-hide');
  894. } else {
  895. $selectTips.html('');
  896. $selectTips.addClass('layui-hide');
  897. }
  898. });
  899. });
  900. });
  901. $inputSearch.off('blur').on('blur', function () {
  902. var keywords = $(this).val();
  903. var $selectTips = $('#ew-map-select-tips');
  904. if (!keywords) {
  905. $selectTips.html('');
  906. $selectTips.addClass('layui-hide');
  907. }
  908. });
  909. $inputSearch.off('focus').on('focus', function () {
  910. var keywords = $(this).val();
  911. if (keywords) $('#ew-map-select-tips').removeClass('layui-hide');
  912. });
  913. // tips列表点击事件
  914. $('#ew-map-select-tips').off('click').on('click', '.ew-map-select-search-list-item', function () {
  915. $('#ew-map-select-tips').addClass('layui-hide');
  916. var lng = $(this).data('lng');
  917. var lat = $(this).data('lat');
  918. selLocation = undefined;
  919. map.setZoomAndCenter(pointZoom, [lng, lat]);
  920. });
  921. };
  922. // 显示弹窗
  923. var htmlStr = [
  924. '<div class="ew-map-select-tool" style="position: relative;">',
  925. ' 搜索:<input id="ew-map-select-input-search" class="layui-input icon-search inline-block" style="width: 190px;" placeholder="输入关键字搜索" autocomplete="off" />',
  926. ' <button id="ew-map-select-btn-ok" class="layui-btn icon-btn pull-right" type="button"><i class="layui-icon">&#xe605;</i>确定</button>',
  927. ' <div id="ew-map-select-tips" class="ew-map-select-search-list layui-hide">',
  928. ' </div>',
  929. '</div>',
  930. '<div class="layui-row ew-map-select">',
  931. ' <div class="layui-col-sm7 ew-map-select-map-group" style="position: relative;">',
  932. ' <div id="ew-map-select-map"></div>',
  933. ' <i id="ew-map-select-center-img2" class="layui-icon layui-icon-add-1"></i>',
  934. ' <img id="ew-map-select-center-img" src="https://3gimg.qq.com/lightmap/components/locationPicker2/image/marker.png" alt=""/>',
  935. ' </div>',
  936. ' <div id="ew-map-select-pois" class="layui-col-sm5 ew-map-select-search-list">',
  937. ' </div>',
  938. '</div>'].join('');
  939. admin.open({
  940. id: 'ew-map-select', type: 1, title: dialogTitle, area: '750px', content: htmlStr,
  941. success: function (layero, dIndex) {
  942. var $content = $(layero).children('.layui-layer-content');
  943. $content.css('overflow', 'visible');
  944. admin.showLoading($content);
  945. window._AMapSecurityConfig = {
  946. securityJsCode:'6197a370ff36f1b49164dd7baaea52a5',
  947. }
  948. if (undefined === window.AMap) {
  949. $.getScript(mapJsUrl, function () {
  950. renderMap();
  951. admin.removeLoading($content);
  952. });
  953. } else {
  954. renderMap();
  955. admin.removeLoading($content);
  956. }
  957. }
  958. });
  959. };
  960. /** 裁剪图片 */
  961. admin.cropImg = function (param) {
  962. var uploadedImageType = 'image/jpeg'; // 当前图片的类型
  963. var aspectRatio = param.aspectRatio; // 裁剪比例
  964. var imgSrc = param.imgSrc; // 裁剪图片
  965. var imgType = param.imgType; // 图片类型
  966. var onCrop = param.onCrop; // 裁剪完成回调
  967. var limitSize = param.limitSize; // 限制选择的图片大小
  968. var acceptMime = param.acceptMime; // 限制选择的图片类型
  969. var imgExts = param.exts; // 限制选择的图片类型
  970. var dialogTitle = param.title; // 弹窗的标题
  971. if (aspectRatio === undefined) aspectRatio = 1;
  972. if (dialogTitle === undefined) dialogTitle = '裁剪图片';
  973. if (imgType) uploadedImageType = imgType;
  974. layui.use(['Cropper', 'upload'], function () {
  975. var Cropper = layui.Cropper, upload = layui.upload;
  976. // 渲染组件
  977. function renderElem() {
  978. var imgCropper, $cropImg = $('#ew-crop-img');
  979. // 上传文件按钮绑定事件
  980. var uploadOptions = {
  981. elem: '#ew-crop-img-upload', auto: false, drag: false,
  982. choose: function (obj) {
  983. obj.preview(function (index, file, result) {
  984. uploadedImageType = file.type;
  985. $cropImg.attr('src', result);
  986. if (!imgSrc || !imgCropper) {
  987. imgSrc = result;
  988. renderElem();
  989. } else {
  990. imgCropper.destroy();
  991. imgCropper = new Cropper($cropImg[0], options);
  992. }
  993. });
  994. }
  995. };
  996. if (limitSize !== undefined) uploadOptions.size = limitSize;
  997. if (acceptMime !== undefined) uploadOptions.acceptMime = acceptMime;
  998. if (imgExts !== undefined) uploadOptions.exts = imgExts;
  999. upload.render(uploadOptions);
  1000. // 没有传图片触发上传图片
  1001. if (!imgSrc) return $('#ew-crop-img-upload').trigger('click');
  1002. // 渲染裁剪组件
  1003. var options = {aspectRatio: aspectRatio, preview: '#ew-crop-img-preview'};
  1004. imgCropper = new Cropper($cropImg[0], options);
  1005. // 操作按钮绑定事件
  1006. $('.ew-crop-tool').on('click', '[data-method]', function () {
  1007. var data = $(this).data(), cropped, result;
  1008. if (!imgCropper || !data.method) return;
  1009. data = $.extend({}, data);
  1010. cropped = imgCropper.cropped;
  1011. switch (data.method) {
  1012. case 'rotate':
  1013. if (cropped && options.viewMode > 0) imgCropper.clear();
  1014. break;
  1015. case 'getCroppedCanvas':
  1016. if (uploadedImageType === 'image/jpeg') {
  1017. if (!data.option) data.option = {};
  1018. data.option.fillColor = '#fff';
  1019. }
  1020. break;
  1021. }
  1022. result = imgCropper[data.method](data.option, data.secondOption);
  1023. switch (data.method) {
  1024. case 'rotate':
  1025. if (cropped && options.viewMode > 0) imgCropper.crop();
  1026. break;
  1027. case 'scaleX':
  1028. case 'scaleY':
  1029. $(this).data('option', -data.option);
  1030. break;
  1031. case 'getCroppedCanvas':
  1032. if (result) {
  1033. onCrop && onCrop(result.toDataURL(uploadedImageType));
  1034. admin.closeDialog('#ew-crop-img');
  1035. } else {
  1036. layer.msg('裁剪失败', {icon: 2, anim: 6});
  1037. }
  1038. break;
  1039. }
  1040. });
  1041. }
  1042. // 显示弹窗
  1043. var htmlStr = [
  1044. '<div class="layui-row">',
  1045. ' <div class="layui-col-sm8" style="min-height: 9rem;">',
  1046. ' <img id="ew-crop-img" src="', imgSrc || '', '" style="max-width:100%;" alt=""/>',
  1047. ' </div>',
  1048. ' <div class="layui-col-sm4 layui-hide-xs" style="padding: 15px;text-align: center;">',
  1049. ' <div id="ew-crop-img-preview" style="width: 100%;height: 9rem;overflow: hidden;display: inline-block;border: 1px solid #dddddd;"></div>',
  1050. ' </div>',
  1051. '</div>',
  1052. '<div class="text-center ew-crop-tool" style="padding: 15px 10px 5px 0;">',
  1053. ' <div class="layui-btn-group" style="margin-bottom: 10px;margin-left: 10px;">',
  1054. ' <button title="放大" data-method="zoom" data-option="0.1" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-add-1"></i></button>',
  1055. ' <button title="缩小" data-method="zoom" data-option="-0.1" class="layui-btn icon-btn" type="button"><span style="display: inline-block;width: 12px;height: 2.5px;background: rgba(255, 255, 255, 0.9);vertical-align: middle;margin: 0 4px;"></span></button>',
  1056. ' </div>',
  1057. ' <div class="layui-btn-group layui-hide-xs" style="margin-bottom: 10px;">',
  1058. ' <button title="向左旋转" data-method="rotate" data-option="-45" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-refresh-1" style="transform: rotateY(180deg) rotate(40deg);display: inline-block;"></i></button>',
  1059. ' <button title="向右旋转" data-method="rotate" data-option="45" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-refresh-1" style="transform: rotate(30deg);display: inline-block;"></i></button>',
  1060. ' </div>',
  1061. ' <div class="layui-btn-group" style="margin-bottom: 10px;">',
  1062. ' <button title="左移" data-method="move" data-option="-10" data-second-option="0" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-left"></i></button>',
  1063. ' <button title="右移" data-method="move" data-option="10" data-second-option="0" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-right"></i></button>',
  1064. ' <button title="上移" data-method="move" data-option="0" data-second-option="-10" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-up"></i></button>',
  1065. ' <button title="下移" data-method="move" data-option="0" data-second-option="10" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-down"></i></button>',
  1066. ' </div>',
  1067. ' <div class="layui-btn-group" style="margin-bottom: 10px;">',
  1068. ' <button title="左右翻转" data-method="scaleX" data-option="-1" class="layui-btn icon-btn" type="button" style="position: relative;width: 41px;"><i class="layui-icon layui-icon-triangle-r" style="position: absolute;left: 9px;top: 0;transform: rotateY(180deg);font-size: 16px;"></i><i class="layui-icon layui-icon-triangle-r" style="position: absolute; right: 3px; top: 0;font-size: 16px;"></i></button>',
  1069. ' <button title="上下翻转" data-method="scaleY" data-option="-1" class="layui-btn icon-btn" type="button" style="position: relative;width: 41px;"><i class="layui-icon layui-icon-triangle-d" style="position: absolute;left: 11px;top: 6px;transform: rotateX(180deg);line-height: normal;font-size: 16px;"></i><i class="layui-icon layui-icon-triangle-d" style="position: absolute; left: 11px; top: 14px;line-height: normal;font-size: 16px;"></i></button>',
  1070. ' </div>',
  1071. ' <div class="layui-btn-group" style="margin-bottom: 10px;">',
  1072. ' <button title="重新开始" data-method="reset" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-refresh"></i></button>',
  1073. ' <button title="选择图片" id="ew-crop-img-upload" class="layui-btn icon-btn" type="button" style="border-radius: 0 2px 2px 0;"><i class="layui-icon layui-icon-upload-drag"></i></button>',
  1074. ' </div>',
  1075. ' <button data-method="getCroppedCanvas" data-option="{ &quot;maxWidth&quot;: 4096, &quot;maxHeight&quot;: 4096 }" class="layui-btn icon-btn" type="button" style="margin-left: 10px;margin-bottom: 10px;"><i class="layui-icon">&#xe605;</i>完成</button>',
  1076. '</div>'].join('');
  1077. admin.open({
  1078. title: dialogTitle, area: '665px', type: 1, content: htmlStr,
  1079. success: function (layero, dIndex) {
  1080. $(layero).children('.layui-layer-content').css('overflow', 'visible');
  1081. renderElem();
  1082. }
  1083. });
  1084. });
  1085. };
  1086. /** 工具类 */
  1087. admin.util = {
  1088. /* 百度地图坐标转高德地图坐标 */
  1089. Convert_BD09_To_GCJ02: function (point) {
  1090. var x_pi = (3.14159265358979324 * 3000.0) / 180.0;
  1091. var x = point.lng - 0.0065, y = point.lat - 0.006;
  1092. var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  1093. var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  1094. return {lng: z * Math.cos(theta), lat: z * Math.sin(theta)};
  1095. },
  1096. /* 高德地图坐标转百度地图坐标 */
  1097. Convert_GCJ02_To_BD09: function (point) {
  1098. var x_pi = (3.14159265358979324 * 3000.0) / 180.0;
  1099. var x = point.lng, y = point.lat;
  1100. var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
  1101. var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
  1102. return {lng: z * Math.cos(theta) + 0.0065, lat: z * Math.sin(theta) + 0.006};
  1103. },
  1104. /* 动态数字 */
  1105. animateNum: function (elem, isThd, delay, grain) {
  1106. isThd = isThd === null || isThd === undefined || isThd === true || isThd === 'true'; // 是否是千分位
  1107. delay = isNaN(delay) ? 500 : delay; // 动画延迟
  1108. grain = isNaN(grain) ? 100 : grain; // 动画粒度
  1109. var getPref = function (str) {
  1110. var pref = '';
  1111. for (var i = 0; i < str.length; i++) if (!isNaN(str.charAt(i))) return pref; else pref += str.charAt(i);
  1112. }, getSuf = function (str) {
  1113. var suf = '';
  1114. for (var i = str.length - 1; i >= 0; i--) if (!isNaN(str.charAt(i))) return suf; else suf = str.charAt(i) + suf;
  1115. }, toThd = function (num, isThd) {
  1116. if (!isThd) return num;
  1117. if (!/^[0-9]+.?[0-9]*$/.test(num)) return num;
  1118. num = num.toString();
  1119. return num.replace(num.indexOf('.') > 0 ? /(\d)(?=(\d{3})+(?:\.))/g : /(\d)(?=(\d{3})+(?:$))/g, '$1,');
  1120. };
  1121. $(elem).each(function () {
  1122. var $this = $(this);
  1123. var num = $this.data('num');
  1124. if (!num) {
  1125. num = $this.text().replace(/,/g, ''); // 内容
  1126. $this.data('num', num);
  1127. }
  1128. var flag = 'INPUT,TEXTAREA'.indexOf($this.get(0).tagName) >= 0; // 是否是输入框
  1129. var pref = getPref(num.toString()), suf = getSuf(num.toString());
  1130. var strNum = num.toString().replace(pref, '').replace(suf, '');
  1131. if (isNaN(strNum * 1) || strNum === '0') {
  1132. flag ? $this.val(num) : $this.html(num);
  1133. return console.error('not a number');
  1134. }
  1135. var int_dec = strNum.split('.');
  1136. var deciLen = int_dec[1] ? int_dec[1].length : 0;
  1137. var startNum = 0.0, endNum = strNum;
  1138. if (Math.abs(endNum * 1) > 10) startNum = parseFloat(int_dec[0].substring(0, int_dec[0].length - 1) + (int_dec[1] ? '.0' + int_dec[1] : ''));
  1139. var oft = (endNum - startNum) / grain, temp = 0;
  1140. var mTime = setInterval(function () {
  1141. var str = pref + toThd(startNum.toFixed(deciLen), isThd) + suf;
  1142. flag ? $this.val(str) : $this.html(str);
  1143. startNum += oft;
  1144. temp++;
  1145. if (Math.abs(startNum) >= Math.abs(endNum * 1) || temp > 5000) {
  1146. str = pref + toThd(endNum, isThd) + suf;
  1147. flag ? $this.val(str) : $this.html(str);
  1148. clearInterval(mTime);
  1149. }
  1150. }, delay / grain);
  1151. });
  1152. },
  1153. /* 深度克隆对象 */
  1154. deepClone: function (obj) {
  1155. var result;
  1156. var oClass = admin.util.isClass(obj);
  1157. if (oClass === 'Object') result = {};
  1158. else if (oClass === 'Array') result = [];
  1159. else return obj;
  1160. for (var key in obj) {
  1161. if (!obj.hasOwnProperty(key)) continue;
  1162. var copy = obj[key], cClass = admin.util.isClass(copy);
  1163. if (cClass === 'Object') result[key] = arguments.callee(copy); // 递归调用
  1164. else if (cClass === 'Array') result[key] = arguments.callee(copy);
  1165. else result[key] = obj[key];
  1166. }
  1167. return result;
  1168. },
  1169. /* 获取变量类型 */
  1170. isClass: function (o) {
  1171. if (o === null) return 'Null';
  1172. if (o === undefined) return 'Undefined';
  1173. return Object.prototype.toString.call(o).slice(8, -1);
  1174. },
  1175. /* 判断富文本是否为空 */
  1176. fullTextIsEmpty: function (text) {
  1177. if (!text) return true;
  1178. var noTexts = ['img', 'audio', 'video', 'iframe', 'object'];
  1179. for (var i = 0; i < noTexts.length; i++) {
  1180. if (text.indexOf('<' + noTexts[i]) > -1) return false;
  1181. }
  1182. var str = text.replace(/\s*/g, ''); // 去掉所有空格
  1183. if (!str) return true;
  1184. str = str.replace(/&nbsp;/ig, ''); // 去掉所有&nbsp;
  1185. if (!str) return true;
  1186. str = str.replace(/<[^>]+>/g, ''); // 去掉所有html标签
  1187. return !str;
  1188. },
  1189. /* 移除元素的style */
  1190. removeStyle: function (elem, names) {
  1191. if (typeof names === 'string') names = [names];
  1192. for (var i = 0; i < names.length; i++) $(elem).css(names[i], '');
  1193. },
  1194. /* 滚动到顶部 */
  1195. scrollTop: function (elem) {
  1196. $(elem || 'html,body').animate({scrollTop: 0}, 300);
  1197. },
  1198. /* 模板解析 */
  1199. tpl: function (html, data, openCode, closeCode) {
  1200. if (html === undefined || html === null || typeof html !== 'string') return html;
  1201. if (!data) data = {};
  1202. if (!openCode) openCode = '{{';
  1203. if (!closeCode) closeCode = '}}';
  1204. var tool = {
  1205. exp: function (str) {
  1206. return new RegExp(str, 'g');
  1207. },
  1208. // 匹配满足规则内容
  1209. query: function (type, _, __) {
  1210. var types = ['#([\\s\\S])+?', '([^{#}])*?'][type || 0];
  1211. return tool.exp((_ || '') + openCode + types + closeCode + (__ || ''));
  1212. },
  1213. escape: function (str) {
  1214. return String(str || '').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&amp;')
  1215. .replace(/</g, '&lt;').replace(/>/g, '&gt;')
  1216. .replace(/'/g, '&#39;').replace(/"/g, '&quot;');
  1217. },
  1218. error: function (e, tplog) {
  1219. console.error('Laytpl Error:' + e + '\n' + (tplog || ''));
  1220. },
  1221. parse: function (tpl, data) {
  1222. var tplog = tpl;
  1223. try {
  1224. var jss = tool.exp('^' + openCode + '#'), jsse = tool.exp(closeCode + '$');
  1225. tpl = tpl.replace(tool.exp(openCode + '#'), openCode + '# ')
  1226. .replace(tool.exp(closeCode + '}'), '} ' + closeCode).replace(/\\/g, '\\\\')
  1227. // 不匹配指定区域的内容
  1228. .replace(tool.exp(openCode + '!(.+?)!' + closeCode), function (str) {
  1229. str = str.replace(tool.exp('^' + openCode + '!'), '')
  1230. .replace(tool.exp('!' + closeCode), '')
  1231. .replace(tool.exp(openCode + '|' + closeCode), function (tag) {
  1232. return tag.replace(/(.)/g, '\\$1')
  1233. });
  1234. return str
  1235. })
  1236. // 匹配JS规则内容
  1237. .replace(/(?="|')/g, '\\').replace(tool.query(), function (str) {
  1238. str = str.replace(jss, '').replace(jsse, '');
  1239. return '";' + str.replace(/\\/g, '') + ';view+="';
  1240. })
  1241. // 匹配普通字段
  1242. .replace(tool.query(1), function (str) {
  1243. var start = '"+(';
  1244. if (str.replace(/\s/g, '') === openCode + closeCode) return '';
  1245. str = str.replace(tool.exp(openCode + '|' + closeCode), '');
  1246. if (/^=/.test(str)) {
  1247. str = str.replace(/^=/, '');
  1248. start = '"+_escape_(';
  1249. }
  1250. return start + str.replace(/\\/g, '') + ')+"';
  1251. })
  1252. // 换行符处理
  1253. .replace(/\r\n/g, '\\r\\n" + "').replace(/\n/g, '\\n" + "').replace(/\r/g, '\\r" + "');
  1254. tpl = '"use strict";var view = "' + tpl + '";return view;';
  1255. tpl = new Function('d, _escape_', tpl);
  1256. return tpl(data, tool.escape);
  1257. } catch (e) {
  1258. tool.error(e, tplog);
  1259. return tplog;
  1260. }
  1261. }
  1262. };
  1263. return tool.parse(html, data);
  1264. },
  1265. /* 渲染动态模板 */
  1266. render: function (option) {
  1267. if (typeof option.url === 'string') {
  1268. option.success = function (res) {
  1269. admin.util.render($.extend({}, option, {url: res}));
  1270. };
  1271. if (option.ajax === 'ajax') admin.ajax(option);
  1272. else admin.req(option.url, option.where, option.success, option.method, option);
  1273. return;
  1274. }
  1275. var html = admin.util.tpl(option.tpl, option.url,
  1276. option.open || setter.tplOpen, option.close || setter.tplClose);
  1277. $(option.elem).next('[ew-tpl-rs]').remove();
  1278. $(option.elem).after(html);
  1279. $(option.elem).next().attr('ew-tpl-rs', '');
  1280. option.done && option.done(option.url);
  1281. }
  1282. };
  1283. /** 锁屏功能 */
  1284. admin.lockScreen = function (url) {
  1285. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.lockScreen(url);
  1286. if (!url) url = 'page/tpl/tpl-lock-screen.html';
  1287. var $lock = $('#ew-lock-screen-group');
  1288. if ($lock.length > 0) {
  1289. $lock.fadeIn('fast');
  1290. admin.isLockScreen = true;
  1291. admin.putTempData('isLockScreen', admin.isLockScreen, true);
  1292. } else {
  1293. var loadIndex = layer.load(2);
  1294. admin.ajax({
  1295. url: url, dataType: 'html',
  1296. success: function (res) {
  1297. layer.close(loadIndex);
  1298. if (typeof res === 'string') {
  1299. $('body').append('<div id="ew-lock-screen-group">' + res + '</div>');
  1300. admin.isLockScreen = true;
  1301. admin.putTempData('isLockScreen', admin.isLockScreen, true);
  1302. admin.putTempData('lockScreenUrl', url, true);
  1303. } else {
  1304. console.error(res);
  1305. layer.msg(JSON.stringify(res), {icon: 2, anim: 6});
  1306. }
  1307. }
  1308. });
  1309. }
  1310. };
  1311. /** 解除锁屏 */
  1312. admin.unlockScreen = function (isRemove) {
  1313. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.unlockScreen(isRemove);
  1314. var $lock = $('#ew-lock-screen-group');
  1315. isRemove ? $lock.remove() : $lock.fadeOut('fast');
  1316. admin.isLockScreen = false;
  1317. admin.putTempData('isLockScreen', null, true);
  1318. };
  1319. /** tips方法封装 */
  1320. admin.tips = function (option) {
  1321. return layer.tips(option.text, option.elem, {
  1322. tips: [option.direction || 1, option.bg || '#191a23'],
  1323. tipsMore: option.tipsMore, time: option.time || -1,
  1324. success: function (layero) {
  1325. var $content = $(layero).children('.layui-layer-content');
  1326. if (option.padding || option.padding === 0) $content.css('padding', option.padding);
  1327. if (option.color) $content.css('color', option.color);
  1328. if (option.bgImg) $content.css('background-image', option.bgImg).children('.layui-layer-TipsG').css('z-index', '-1');
  1329. if (option.fontSize) $content.css('font-size', option.fontSize);
  1330. if (!option.offset) return;
  1331. var offset = option.offset.split(',');
  1332. var top = offset[0], left = offset.length > 1 ? offset[1] : undefined;
  1333. if (top) $(layero).css('margin-top', top);
  1334. if (left) $(layero).css('margin-left', left);
  1335. }
  1336. });
  1337. };
  1338. /** 渲染动态模板 */
  1339. admin.renderTpl = function (elem) {
  1340. if (!layui.admin) layui.admin = admin;
  1341. // 解析数据
  1342. function parseData(data) {
  1343. if (!data) return;
  1344. try {
  1345. return new Function('return ' + data + ';')();
  1346. } catch (e) {
  1347. console.error(e + '\nlay-data: ' + data);
  1348. }
  1349. }
  1350. $(elem || '[ew-tpl]').each(function () {
  1351. var $this = $(this);
  1352. var option = $(this).data();
  1353. option.elem = $this;
  1354. option.tpl = $this.html();
  1355. option.url = parseData($this.attr('ew-tpl'));
  1356. option.headers = parseData(option.headers);
  1357. option.where = parseData(option.where);
  1358. if (option.done) {
  1359. try {
  1360. option.done = new Function('res', option.done);
  1361. } catch (e) {
  1362. console.error(e + '\nlay-data:' + option.done);
  1363. option.done = undefined;
  1364. }
  1365. }
  1366. admin.util.render(option);
  1367. });
  1368. };
  1369. /** 事件监听 */
  1370. admin.on = function (events, callback) {
  1371. return layui.onevent.call(this, 'admin', events, callback);
  1372. };
  1373. /** 修改配置信息 */
  1374. admin.putSetting = function (key, value) {
  1375. setter[key] = value;
  1376. admin.putTempData(key, value, true);
  1377. };
  1378. /** 恢复配置信息 */
  1379. admin.recoverState = function () {
  1380. // 恢复锁屏状态
  1381. if (admin.getTempData('isLockScreen', true)) admin.lockScreen(admin.getTempData('lockScreenUrl', true));
  1382. // 恢复配置的主题
  1383. if (setter.defaultTheme) admin.changeTheme(setter.defaultTheme, window, true, true);
  1384. // 恢复页脚状态、导航箭头
  1385. if (setter.closeFooter) $('body').addClass('close-footer');
  1386. if (setter.navArrow !== undefined) {
  1387. var $nav = $(sideDOM + '>.layui-nav-tree');
  1388. $nav.removeClass('arrow2 arrow3');
  1389. if (setter.navArrow) $nav.addClass(setter.navArrow);
  1390. }
  1391. // 恢复tab自动刷新
  1392. if (setter.pageTabs && setter.tabAutoRefresh == 'true') $(tabDOM).attr('lay-autoRefresh', 'true');
  1393. };
  1394. /* 事件监听 */
  1395. admin.on = function (events, callback) {
  1396. return layui.onevent.call(this, 'admin', events, callback);
  1397. };
  1398. /** 侧导航折叠状态下鼠标经过无限悬浮效果 */
  1399. var navItemDOM = '.layui-layout-admin.admin-nav-mini>.layui-side .layui-nav .layui-nav-item';
  1400. $(document).on('mouseenter', navItemDOM + ',' + navItemDOM + ' .layui-nav-child>dd', function () {
  1401. if (admin.getPageWidth() > 768) {
  1402. var $that = $(this), $navChild = $that.find('>.layui-nav-child');
  1403. if ($navChild.length > 0) {
  1404. $that.addClass('admin-nav-hover');
  1405. $navChild.css('left', $that.offset().left + $that.outerWidth());
  1406. var top = $that.offset().top;
  1407. if (top + $navChild.outerHeight() > admin.getPageHeight()) {
  1408. top = top - $navChild.outerHeight() + $that.outerHeight();
  1409. if (top < 60) top = 60;
  1410. $navChild.addClass('show-top');
  1411. }
  1412. $navChild.css('top', top);
  1413. $navChild.addClass('ew-anim-drop-in');
  1414. } else if ($that.hasClass('layui-nav-item')) {
  1415. admin.tips({elem: $that, text: $that.find('cite').text(), direction: 2, offset: '12px'});
  1416. }
  1417. }
  1418. }).on('mouseleave', navItemDOM + ',' + navItemDOM + ' .layui-nav-child>dd', function () {
  1419. layer.closeAll('tips');
  1420. var $this = $(this);
  1421. $this.removeClass('admin-nav-hover');
  1422. var $child = $this.find('>.layui-nav-child');
  1423. $child.removeClass('show-top ew-anim-drop-in');
  1424. $child.css({'left': 'auto', 'top': 'auto'});
  1425. });
  1426. /** 所有ew-event */
  1427. $(document).on('click', '*[ew-event]', function () {
  1428. var te = admin.events[$(this).attr('ew-event')];
  1429. te && te.call(this, $(this));
  1430. });
  1431. /** 所有lay-tips处理 */
  1432. $(document).on('mouseenter', '*[lay-tips]', function () {
  1433. var $this = $(this);
  1434. admin.tips({
  1435. elem: $this, text: $this.attr('lay-tips'), direction: $this.attr('lay-direction'),
  1436. bg: $this.attr('lay-bg'), offset: $this.attr('lay-offset'),
  1437. padding: $this.attr('lay-padding'), color: $this.attr('lay-color'),
  1438. bgImg: $this.attr('lay-bgImg'), fontSize: $this.attr('lay-fontSize')
  1439. });
  1440. }).on('mouseleave', '*[lay-tips]', function () {
  1441. layer.closeAll('tips');
  1442. });
  1443. /** 表单搜索展开更多 */
  1444. $(document).on('click', '.form-search-expand,[search-expand]', function () {
  1445. var $this = $(this);
  1446. var $form = $this.parents('.layui-form').first();
  1447. var expand = $this.data('expand');
  1448. var change = $this.attr('search-expand');
  1449. if (expand === undefined || expand === true) {
  1450. expand = true;
  1451. $this.data('expand', false);
  1452. $this.html('收起 <i class="layui-icon layui-icon-up"></i>');
  1453. var $elem = $form.find('.form-search-show-expand');
  1454. $elem.attr('expand-show', '');
  1455. $elem.removeClass('form-search-show-expand');
  1456. } else {
  1457. expand = false;
  1458. $this.data('expand', true);
  1459. $this.html('展开 <i class="layui-icon layui-icon-down"></i>');
  1460. $form.find('[expand-show]').addClass('form-search-show-expand');
  1461. }
  1462. if (!change) return;
  1463. new Function('d', change)({expand: expand, elem: $this});
  1464. });
  1465. /** select使用fixed定位显示 */
  1466. $(document).on('click.ew-sel-fixed', '.ew-select-fixed .layui-form-select .layui-select-title', function () {
  1467. var $this = $(this), $dl = $this.parent().children('dl'), tTop = $this.offset().top;
  1468. var tWidth = $this.outerWidth(), tHeight = $this.outerHeight(), scrollT = $(document).scrollTop();
  1469. var dWidth = $dl.outerWidth(), dHeight = $dl.outerHeight();
  1470. var top = tTop + tHeight + 5 - scrollT, left = $this.offset().left;
  1471. if (top + dHeight > admin.getPageHeight()) top = top - dHeight - tHeight - 10;
  1472. if (left + dWidth > admin.getPageWidth()) left = left - dWidth + tWidth;
  1473. $dl.css({'left': left, 'top': top, 'min-width': tWidth});
  1474. });
  1475. /** 用于滚动时关闭一些fixed的组件 */
  1476. admin.hideFixedEl = function () {
  1477. $('.ew-select-fixed .layui-form-select').removeClass('layui-form-selected layui-form-selectup'); // select
  1478. $('body>.layui-laydate').remove(); // laydate
  1479. };
  1480. /** 垂直导航栏展开折叠增加过渡效果 */
  1481. $(document).on('click', '.layui-nav-tree>.layui-nav-item a', function () {
  1482. var $this = $(this), $child = $this.siblings('.layui-nav-child'), $parent = $this.parent();
  1483. if ($child.length === 0) return;
  1484. if ($parent.hasClass('admin-nav-hover')) return;
  1485. if ($parent.hasClass('layui-nav-itemed')) { // 因为layui会处理一遍所以这里状态是相反的
  1486. $child.css('display', 'none').slideDown('fast', function () {
  1487. $(this).css('display', '');
  1488. });
  1489. } else {
  1490. $child.css('display', 'block').slideUp('fast', function () {
  1491. $(this).css('display', '');
  1492. });
  1493. }
  1494. if ($this.parents('.layui-nav').attr('lay-shrink') === '_all') { // 手风琴效果
  1495. var $siblings = $this.parent().siblings('.layui-nav-itemed');
  1496. $siblings.children('.layui-nav-child').css('display', 'block').slideUp('fast', function () {
  1497. $(this).css('display', '');
  1498. });
  1499. $siblings.removeClass('layui-nav-itemed');
  1500. }
  1501. });
  1502. $('.layui-nav-tree[lay-shrink="all"]').attr('lay-shrink', '_all'); // 让layui不处理手风琴效果
  1503. /** 折叠面板展开折叠增加过渡效果 */
  1504. $(document).on('click', '.layui-collapse>.layui-colla-item>.layui-colla-title', function () {
  1505. var $this = $(this), $content = $this.siblings('.layui-colla-content')
  1506. , $collapse = $this.parent().parent(), isNone = $content.hasClass('layui-show');
  1507. if (isNone) { // 因为layui会处理一遍所以这里状态是相反的
  1508. $content.removeClass('layui-show').slideDown('fast').addClass('layui-show');
  1509. } else {
  1510. $content.css('display', 'block').slideUp('fast', function () {
  1511. $(this).css('display', '');
  1512. });
  1513. }
  1514. $this.children('.layui-colla-icon').html('&#xe602;')
  1515. .css({'transition': 'all .3s', 'transform': 'rotate(' + (isNone ? '90deg' : '0deg') + ')'});
  1516. if ($collapse.attr('lay-shrink') === '_all') { // 手风琴效果
  1517. var $show = $collapse.children('.layui-colla-item').children('.layui-colla-content.layui-show').not($content);
  1518. $show.css('display', 'block').slideUp('fast', function () {
  1519. $(this).css('display', '');
  1520. });
  1521. $show.removeClass('layui-show');
  1522. $show.siblings('.layui-colla-title').children('.layui-colla-icon').html('&#xe602;')
  1523. .css({'transition': 'all .3s', 'transform': 'rotate(0deg)'});
  1524. }
  1525. });
  1526. $('.layui-collapse[lay-accordion]').attr('lay-shrink', '_all').removeAttr('lay-accordion'); // 让layui不处理手风琴效果
  1527. /** 表单验证tips提示样式修改 */
  1528. layer.oldTips = layer.tips;
  1529. layer.tips = function (content, follow, options) {
  1530. var $fFip; // 判断是否是表单验证调用的tips
  1531. if ($(follow).length > 0 && $(follow).parents('.layui-form').length > 0) {
  1532. if ($(follow).is('input') || $(follow).is('textarea')) {
  1533. $fFip = $(follow);
  1534. } else if ($(follow).hasClass('layui-form-select') || $(follow).hasClass('layui-form-radio')
  1535. || $(follow).hasClass('layui-form-checkbox') || $(follow).hasClass('layui-form-switch')) {
  1536. $fFip = $(follow).prev();
  1537. }
  1538. }
  1539. if (!$fFip) return layer.oldTips(content, follow, options);
  1540. options.tips = [$fFip.attr('lay-direction') || 3, $fFip.attr('lay-bg') || '#ff4c4c'];
  1541. setTimeout(function () {
  1542. options.success = function (layero) {
  1543. $(layero).children('.layui-layer-content').css('padding', '6px 12px');
  1544. };
  1545. layer.oldTips(content, follow, options);
  1546. }, 100);
  1547. };
  1548. /** 所有ew-href处理 */
  1549. $(document).on('click', '*[ew-href]', function () {
  1550. var $this = $(this);
  1551. var href = $this.attr('ew-href');
  1552. if (!href || href === '#') return;
  1553. if (href.indexOf('javascript:') === 0) return new Function(href.substring(11))();
  1554. var title = $this.attr('ew-title') || $this.text();
  1555. var win = $this.data('window');
  1556. win ? (win = admin.strToWin(win)) : (win = top);
  1557. var end = $this.attr('ew-end');
  1558. try {
  1559. if (end) end = new Function(end);
  1560. else end = undefined;
  1561. } catch (e) {
  1562. console.error(e);
  1563. }
  1564. if (win.layui && win.layui.index) win.layui.index.openTab({title: title || '', url: href, end: end});
  1565. else location.href = href;
  1566. });
  1567. /** 帮助鼠标右键菜单完成点击空白关闭的功能 */
  1568. if (!layui.contextMenu) {
  1569. $(document).off('click.ctxMenu').on('click.ctxMenu', function () {
  1570. try {
  1571. var ifs = top.window.frames;
  1572. for (var i = 0; i < ifs.length; i++) {
  1573. var tif = ifs[i];
  1574. try { // 可能会跨域
  1575. if (tif.layui && tif.layui.jquery) tif.layui.jquery('body>.ctxMenu').remove();
  1576. } catch (e) {
  1577. }
  1578. }
  1579. try { // 可能会跨域
  1580. if (top.layui && top.layui.jquery) top.layui.jquery('body>.ctxMenu').remove();
  1581. } catch (e) {
  1582. }
  1583. } catch (e) {
  1584. }
  1585. });
  1586. }
  1587. /** 读取缓存的配置信息 */
  1588. setter = $.extend({
  1589. pageTabs: true, cacheTab: true, openTabCtxMenu: true, maxTabNum: 20, tableName: 'easyweb-iframe',
  1590. apiNoCache: true, ajaxSuccessBefore: function (res, url, obj) {
  1591. return admin.ajaxSuccessBefore ? admin.ajaxSuccessBefore(res, url, obj) : true;
  1592. }, getAjaxHeaders: function (res, url, obj) {
  1593. return admin.getAjaxHeaders ? admin.getAjaxHeaders(res, url, obj) : [];
  1594. }
  1595. }, setter);
  1596. var cache = admin.getTempData(true);
  1597. if (cache) {
  1598. var keys = ['pageTabs', 'cacheTab', 'defaultTheme', 'navArrow', 'closeFooter', 'tabAutoRefresh'];
  1599. for (var i = 0; i < keys.length; i++) if (cache[keys[i]] !== undefined) setter[keys[i]] = cache[keys[i]];
  1600. }
  1601. admin.recoverState(); // 恢复本地配置
  1602. admin.renderTpl(); // 渲染动态模板
  1603. admin.setter = setter;
  1604. if (layui.device().ios) $('body').addClass('ios-iframe-body'); // ios浏览器iframe兼容
  1605. exports('admin', admin);
  1606. });