admin.js 80 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676
  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=006d995d433058322319fa797f2876f5';
  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. ' 商务住宅|政府机构及社会团体|科教文化服务|交通设施服务|金融保险服务|公司企业|道路附属设施|地名地址信息|公共设施',
  779. pageSize: searchPageSize,
  780. pageIndex: 1
  781. });
  782. var cpoint = [lng, lat];
  783. placeSearch.searchNearBy(searchKeywords, cpoint, 1000, function (status, result) {
  784. if (status === 'complete') {
  785. var pois = result.poiList.pois;
  786. var htmlList = '';
  787. for (var i = 0; i < pois.length; i++) {
  788. var poiItem = pois[i];
  789. if (poiItem.location !== undefined) {
  790. htmlList += '<div data-lng="' + poiItem.location.lng + '" data-lat="' + poiItem.location.lat + '" class="ew-map-select-search-list-item">';
  791. htmlList += ' <div class="ew-map-select-search-list-item-title">' + poiItem.name + '</div>';
  792. htmlList += ' <div class="ew-map-select-search-list-item-address">' + poiItem.address + '</div>';
  793. htmlList += ' <div class="ew-map-select-search-list-item-icon-ok layui-hide"><i class="layui-icon layui-icon-ok-circle"></i></div>';
  794. htmlList += '</div>';
  795. }
  796. }
  797. $('#ew-map-select-pois').html(htmlList);
  798. }
  799. });
  800. });
  801. };
  802. // 渲染地图
  803. var renderMap = function () {
  804. var mapOption = {
  805. resizeEnable: true, // 监控地图容器尺寸变化
  806. zoom: defaultZoom // 初缩放级别
  807. };
  808. mapCenter && (mapOption.center = mapCenter);
  809. var map = new AMap.Map('ew-map-select-map', mapOption);
  810. // 地图加载完成
  811. map.on('complete', function () {
  812. var center = map.getCenter();
  813. searchNearBy(center.lat, center.lng);
  814. });
  815. // 地图移动结束事件
  816. map.on('moveend', function () {
  817. if (isSelMove) {
  818. isSelMove = false;
  819. } else {
  820. $('#ew-map-select-tips').addClass('layui-hide');
  821. $('#ew-map-select-center-img').removeClass('bounceInDown');
  822. setTimeout(function () {
  823. $('#ew-map-select-center-img').addClass('bounceInDown');
  824. });
  825. var center = map.getCenter();
  826. searchNearBy(center.lat, center.lng);
  827. }
  828. });
  829. // poi列表点击事件
  830. $('#ew-map-select-pois').off('click').on('click', '.ew-map-select-search-list-item', function () {
  831. $('#ew-map-select-tips').addClass('layui-hide');
  832. $('#ew-map-select-pois .ew-map-select-search-list-item-icon-ok').addClass('layui-hide');
  833. $(this).find('.ew-map-select-search-list-item-icon-ok').removeClass('layui-hide');
  834. $('#ew-map-select-center-img').removeClass('bounceInDown');
  835. setTimeout(function () {
  836. $('#ew-map-select-center-img').addClass('bounceInDown');
  837. });
  838. var lng = $(this).data('lng');
  839. var lat = $(this).data('lat');
  840. var name = $(this).find('.ew-map-select-search-list-item-title').text();
  841. var address = $(this).find('.ew-map-select-search-list-item-address').text();
  842. selLocation = {name: name, address: address, lat: lat, lng: lng};
  843. isSelMove = true;
  844. map.setZoomAndCenter(pointZoom, [lng, lat]);
  845. });
  846. // 确定按钮点击事件
  847. $('#ew-map-select-btn-ok').click(function () {
  848. if (selLocation === undefined) {
  849. layer.msg('请点击位置列表选择', {icon: 2, anim: 6});
  850. } else if (onSelect) {
  851. if (needCity) {
  852. var loadIndex = layer.load(2);
  853. map.setCenter([selLocation.lng, selLocation.lat]);
  854. map.getCity(function (result) {
  855. layer.close(loadIndex);
  856. selLocation.city = result;
  857. admin.closeDialog('#ew-map-select-btn-ok');
  858. onSelect(selLocation);
  859. });
  860. } else {
  861. admin.closeDialog('#ew-map-select-btn-ok');
  862. onSelect(selLocation);
  863. }
  864. } else {
  865. admin.closeDialog('#ew-map-select-btn-ok');
  866. }
  867. });
  868. // 搜索提示
  869. var $inputSearch = $('#ew-map-select-input-search');
  870. $inputSearch.off('input').on('input', function () {
  871. var keywords = $(this).val();
  872. var $selectTips = $('#ew-map-select-tips');
  873. if (!keywords) {
  874. $selectTips.html('');
  875. $selectTips.addClass('layui-hide');
  876. }
  877. AMap.plugin('AMap.Autocomplete', function () {
  878. var autoComplete = new AMap.Autocomplete({city: '全国'});
  879. autoComplete.search(keywords, function (status, result) {
  880. if (result.tips) {
  881. var tips = result.tips;
  882. var htmlList = '';
  883. for (var i = 0; i < tips.length; i++) {
  884. var tipItem = tips[i];
  885. if (tipItem.location !== undefined) {
  886. htmlList += '<div data-lng="' + tipItem.location.lng + '" data-lat="' + tipItem.location.lat + '" class="ew-map-select-search-list-item">';
  887. htmlList += ' <div class="ew-map-select-search-list-item-icon-search"><i class="layui-icon layui-icon-search"></i></div>';
  888. htmlList += ' <div class="ew-map-select-search-list-item-title">' + tipItem.name + '</div>';
  889. htmlList += ' <div class="ew-map-select-search-list-item-address">' + tipItem.address + '</div>';
  890. htmlList += '</div>';
  891. }
  892. }
  893. $selectTips.html(htmlList);
  894. if (tips.length === 0) $('#ew-map-select-tips').addClass('layui-hide');
  895. else $('#ew-map-select-tips').removeClass('layui-hide');
  896. } else {
  897. $selectTips.html('');
  898. $selectTips.addClass('layui-hide');
  899. }
  900. });
  901. });
  902. });
  903. $inputSearch.off('blur').on('blur', function () {
  904. var keywords = $(this).val();
  905. var $selectTips = $('#ew-map-select-tips');
  906. if (!keywords) {
  907. $selectTips.html('');
  908. $selectTips.addClass('layui-hide');
  909. }
  910. });
  911. $inputSearch.off('focus').on('focus', function () {
  912. var keywords = $(this).val();
  913. if (keywords) $('#ew-map-select-tips').removeClass('layui-hide');
  914. });
  915. // tips列表点击事件
  916. $('#ew-map-select-tips').off('click').on('click', '.ew-map-select-search-list-item', function () {
  917. $('#ew-map-select-tips').addClass('layui-hide');
  918. var lng = $(this).data('lng');
  919. var lat = $(this).data('lat');
  920. selLocation = undefined;
  921. map.setZoomAndCenter(pointZoom, [lng, lat]);
  922. });
  923. };
  924. // 显示弹窗
  925. var htmlStr = [
  926. '<div class="ew-map-select-tool" style="position: relative;">',
  927. ' 搜索:<input id="ew-map-select-input-search" class="layui-input icon-search inline-block" style="width: 190px;" placeholder="输入关键字搜索" autocomplete="off" />',
  928. ' <button id="ew-map-select-btn-ok" class="layui-btn icon-btn pull-right" type="button"><i class="layui-icon">&#xe605;</i>确定</button>',
  929. ' <div id="ew-map-select-tips" class="ew-map-select-search-list layui-hide">',
  930. ' </div>',
  931. '</div>',
  932. '<div class="layui-row ew-map-select">',
  933. ' <div class="layui-col-sm7 ew-map-select-map-group" style="position: relative;">',
  934. ' <div id="ew-map-select-map"></div>',
  935. ' <i id="ew-map-select-center-img2" class="layui-icon layui-icon-add-1"></i>',
  936. ' <img id="ew-map-select-center-img" src="https://3gimg.qq.com/lightmap/components/locationPicker2/image/marker.png" alt=""/>',
  937. ' </div>',
  938. ' <div id="ew-map-select-pois" class="layui-col-sm5 ew-map-select-search-list">',
  939. ' </div>',
  940. '</div>'].join('');
  941. admin.open({
  942. id: 'ew-map-select', type: 1, title: dialogTitle, area: '750px', content: htmlStr,
  943. success: function (layero, dIndex) {
  944. var $content = $(layero).children('.layui-layer-content');
  945. $content.css('overflow', 'visible');
  946. admin.showLoading($content);
  947. if (undefined === window.AMap) {
  948. $.getScript(mapJsUrl, function () {
  949. renderMap();
  950. admin.removeLoading($content);
  951. });
  952. } else {
  953. renderMap();
  954. admin.removeLoading($content);
  955. }
  956. }
  957. });
  958. };
  959. /** 裁剪图片 */
  960. admin.cropImg = function (param) {
  961. var uploadedImageType = 'image/jpeg'; // 当前图片的类型
  962. var aspectRatio = param.aspectRatio; // 裁剪比例
  963. var imgSrc = param.imgSrc; // 裁剪图片
  964. var imgType = param.imgType; // 图片类型
  965. var onCrop = param.onCrop; // 裁剪完成回调
  966. var limitSize = param.limitSize; // 限制选择的图片大小
  967. var acceptMime = param.acceptMime; // 限制选择的图片类型
  968. var imgExts = param.exts; // 限制选择的图片类型
  969. var dialogTitle = param.title; // 弹窗的标题
  970. if (aspectRatio === undefined) aspectRatio = 1;
  971. if (dialogTitle === undefined) dialogTitle = '裁剪图片';
  972. if (imgType) uploadedImageType = imgType;
  973. layui.use(['Cropper', 'upload'], function () {
  974. var Cropper = layui.Cropper, upload = layui.upload;
  975. // 渲染组件
  976. function renderElem() {
  977. var imgCropper, $cropImg = $('#ew-crop-img');
  978. // 上传文件按钮绑定事件
  979. var uploadOptions = {
  980. elem: '#ew-crop-img-upload', auto: false, drag: false,
  981. choose: function (obj) {
  982. obj.preview(function (index, file, result) {
  983. uploadedImageType = file.type;
  984. $cropImg.attr('src', result);
  985. if (!imgSrc || !imgCropper) {
  986. imgSrc = result;
  987. renderElem();
  988. } else {
  989. imgCropper.destroy();
  990. imgCropper = new Cropper($cropImg[0], options);
  991. }
  992. });
  993. }
  994. };
  995. if (limitSize !== undefined) uploadOptions.size = limitSize;
  996. if (acceptMime !== undefined) uploadOptions.acceptMime = acceptMime;
  997. if (imgExts !== undefined) uploadOptions.exts = imgExts;
  998. upload.render(uploadOptions);
  999. // 没有传图片触发上传图片
  1000. if (!imgSrc) return $('#ew-crop-img-upload').trigger('click');
  1001. // 渲染裁剪组件
  1002. var options = {aspectRatio: aspectRatio, preview: '#ew-crop-img-preview'};
  1003. imgCropper = new Cropper($cropImg[0], options);
  1004. // 操作按钮绑定事件
  1005. $('.ew-crop-tool').on('click', '[data-method]', function () {
  1006. var data = $(this).data(), cropped, result;
  1007. if (!imgCropper || !data.method) return;
  1008. data = $.extend({}, data);
  1009. cropped = imgCropper.cropped;
  1010. switch (data.method) {
  1011. case 'rotate':
  1012. if (cropped && options.viewMode > 0) imgCropper.clear();
  1013. break;
  1014. case 'getCroppedCanvas':
  1015. if (uploadedImageType === 'image/jpeg') {
  1016. if (!data.option) data.option = {};
  1017. data.option.fillColor = '#fff';
  1018. }
  1019. break;
  1020. }
  1021. result = imgCropper[data.method](data.option, data.secondOption);
  1022. switch (data.method) {
  1023. case 'rotate':
  1024. if (cropped && options.viewMode > 0) imgCropper.crop();
  1025. break;
  1026. case 'scaleX':
  1027. case 'scaleY':
  1028. $(this).data('option', -data.option);
  1029. break;
  1030. case 'getCroppedCanvas':
  1031. if (result) {
  1032. onCrop && onCrop(result.toDataURL(uploadedImageType));
  1033. admin.closeDialog('#ew-crop-img');
  1034. } else {
  1035. layer.msg('裁剪失败', {icon: 2, anim: 6});
  1036. }
  1037. break;
  1038. }
  1039. });
  1040. }
  1041. // 显示弹窗
  1042. var htmlStr = [
  1043. '<div class="layui-row">',
  1044. ' <div class="layui-col-sm8" style="min-height: 9rem;">',
  1045. ' <img id="ew-crop-img" src="', imgSrc || '', '" style="max-width:100%;" alt=""/>',
  1046. ' </div>',
  1047. ' <div class="layui-col-sm4 layui-hide-xs" style="padding: 15px;text-align: center;">',
  1048. ' <div id="ew-crop-img-preview" style="width: 100%;height: 9rem;overflow: hidden;display: inline-block;border: 1px solid #dddddd;"></div>',
  1049. ' </div>',
  1050. '</div>',
  1051. '<div class="text-center ew-crop-tool" style="padding: 15px 10px 5px 0;">',
  1052. ' <div class="layui-btn-group" style="margin-bottom: 10px;margin-left: 10px;">',
  1053. ' <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>',
  1054. ' <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>',
  1055. ' </div>',
  1056. ' <div class="layui-btn-group layui-hide-xs" style="margin-bottom: 10px;">',
  1057. ' <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>',
  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: rotate(30deg);display: inline-block;"></i></button>',
  1059. ' </div>',
  1060. ' <div class="layui-btn-group" style="margin-bottom: 10px;">',
  1061. ' <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>',
  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-right"></i></button>',
  1063. ' <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>',
  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-down"></i></button>',
  1065. ' </div>',
  1066. ' <div class="layui-btn-group" style="margin-bottom: 10px;">',
  1067. ' <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>',
  1068. ' <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>',
  1069. ' </div>',
  1070. ' <div class="layui-btn-group" style="margin-bottom: 10px;">',
  1071. ' <button title="重新开始" data-method="reset" class="layui-btn icon-btn" type="button"><i class="layui-icon layui-icon-refresh"></i></button>',
  1072. ' <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>',
  1073. ' </div>',
  1074. ' <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>',
  1075. '</div>'].join('');
  1076. admin.open({
  1077. title: dialogTitle, area: '665px', type: 1, content: htmlStr,
  1078. success: function (layero, dIndex) {
  1079. $(layero).children('.layui-layer-content').css('overflow', 'visible');
  1080. renderElem();
  1081. }
  1082. });
  1083. });
  1084. };
  1085. /** 工具类 */
  1086. admin.util = {
  1087. /* 百度地图坐标转高德地图坐标 */
  1088. Convert_BD09_To_GCJ02: function (point) {
  1089. var x_pi = (3.14159265358979324 * 3000.0) / 180.0;
  1090. var x = point.lng - 0.0065, y = point.lat - 0.006;
  1091. var z = Math.sqrt(x * x + y * y) - 0.00002 * Math.sin(y * x_pi);
  1092. var theta = Math.atan2(y, x) - 0.000003 * Math.cos(x * x_pi);
  1093. return {lng: z * Math.cos(theta), lat: z * Math.sin(theta)};
  1094. },
  1095. /* 高德地图坐标转百度地图坐标 */
  1096. Convert_GCJ02_To_BD09: function (point) {
  1097. var x_pi = (3.14159265358979324 * 3000.0) / 180.0;
  1098. var x = point.lng, y = point.lat;
  1099. var z = Math.sqrt(x * x + y * y) + 0.00002 * Math.sin(y * x_pi);
  1100. var theta = Math.atan2(y, x) + 0.000003 * Math.cos(x * x_pi);
  1101. return {lng: z * Math.cos(theta) + 0.0065, lat: z * Math.sin(theta) + 0.006};
  1102. },
  1103. /* 动态数字 */
  1104. animateNum: function (elem, isThd, delay, grain) {
  1105. isThd = isThd === null || isThd === undefined || isThd === true || isThd === 'true'; // 是否是千分位
  1106. delay = isNaN(delay) ? 500 : delay; // 动画延迟
  1107. grain = isNaN(grain) ? 100 : grain; // 动画粒度
  1108. var getPref = function (str) {
  1109. var pref = '';
  1110. for (var i = 0; i < str.length; i++) if (!isNaN(str.charAt(i))) return pref; else pref += str.charAt(i);
  1111. }, getSuf = function (str) {
  1112. var suf = '';
  1113. for (var i = str.length - 1; i >= 0; i--) if (!isNaN(str.charAt(i))) return suf; else suf = str.charAt(i) + suf;
  1114. }, toThd = function (num, isThd) {
  1115. if (!isThd) return num;
  1116. if (!/^[0-9]+.?[0-9]*$/.test(num)) return num;
  1117. num = num.toString();
  1118. return num.replace(num.indexOf('.') > 0 ? /(\d)(?=(\d{3})+(?:\.))/g : /(\d)(?=(\d{3})+(?:$))/g, '$1,');
  1119. };
  1120. $(elem).each(function () {
  1121. var $this = $(this);
  1122. var num = $this.data('num');
  1123. if (!num) {
  1124. num = $this.text().replace(/,/g, ''); // 内容
  1125. $this.data('num', num);
  1126. }
  1127. var flag = 'INPUT,TEXTAREA'.indexOf($this.get(0).tagName) >= 0; // 是否是输入框
  1128. var pref = getPref(num.toString()), suf = getSuf(num.toString());
  1129. var strNum = num.toString().replace(pref, '').replace(suf, '');
  1130. if (isNaN(strNum * 1) || strNum === '0') {
  1131. flag ? $this.val(num) : $this.html(num);
  1132. return console.error('not a number');
  1133. }
  1134. var int_dec = strNum.split('.');
  1135. var deciLen = int_dec[1] ? int_dec[1].length : 0;
  1136. var startNum = 0.0, endNum = strNum;
  1137. 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] : ''));
  1138. var oft = (endNum - startNum) / grain, temp = 0;
  1139. var mTime = setInterval(function () {
  1140. var str = pref + toThd(startNum.toFixed(deciLen), isThd) + suf;
  1141. flag ? $this.val(str) : $this.html(str);
  1142. startNum += oft;
  1143. temp++;
  1144. if (Math.abs(startNum) >= Math.abs(endNum * 1) || temp > 5000) {
  1145. str = pref + toThd(endNum, isThd) + suf;
  1146. flag ? $this.val(str) : $this.html(str);
  1147. clearInterval(mTime);
  1148. }
  1149. }, delay / grain);
  1150. });
  1151. },
  1152. /* 深度克隆对象 */
  1153. deepClone: function (obj) {
  1154. var result;
  1155. var oClass = admin.util.isClass(obj);
  1156. if (oClass === 'Object') result = {};
  1157. else if (oClass === 'Array') result = [];
  1158. else return obj;
  1159. for (var key in obj) {
  1160. if (!obj.hasOwnProperty(key)) continue;
  1161. var copy = obj[key], cClass = admin.util.isClass(copy);
  1162. if (cClass === 'Object') result[key] = arguments.callee(copy); // 递归调用
  1163. else if (cClass === 'Array') result[key] = arguments.callee(copy);
  1164. else result[key] = obj[key];
  1165. }
  1166. return result;
  1167. },
  1168. /* 获取变量类型 */
  1169. isClass: function (o) {
  1170. if (o === null) return 'Null';
  1171. if (o === undefined) return 'Undefined';
  1172. return Object.prototype.toString.call(o).slice(8, -1);
  1173. },
  1174. /* 判断富文本是否为空 */
  1175. fullTextIsEmpty: function (text) {
  1176. if (!text) return true;
  1177. var noTexts = ['img', 'audio', 'video', 'iframe', 'object'];
  1178. for (var i = 0; i < noTexts.length; i++) {
  1179. if (text.indexOf('<' + noTexts[i]) > -1) return false;
  1180. }
  1181. var str = text.replace(/\s*/g, ''); // 去掉所有空格
  1182. if (!str) return true;
  1183. str = str.replace(/&nbsp;/ig, ''); // 去掉所有&nbsp;
  1184. if (!str) return true;
  1185. str = str.replace(/<[^>]+>/g, ''); // 去掉所有html标签
  1186. return !str;
  1187. },
  1188. /* 移除元素的style */
  1189. removeStyle: function (elem, names) {
  1190. if (typeof names === 'string') names = [names];
  1191. for (var i = 0; i < names.length; i++) $(elem).css(names[i], '');
  1192. },
  1193. /* 滚动到顶部 */
  1194. scrollTop: function (elem) {
  1195. $(elem || 'html,body').animate({scrollTop: 0}, 300);
  1196. },
  1197. /* 模板解析 */
  1198. tpl: function (html, data, openCode, closeCode) {
  1199. if (html === undefined || html === null || typeof html !== 'string') return html;
  1200. if (!data) data = {};
  1201. if (!openCode) openCode = '{{';
  1202. if (!closeCode) closeCode = '}}';
  1203. var tool = {
  1204. exp: function (str) {
  1205. return new RegExp(str, 'g');
  1206. },
  1207. // 匹配满足规则内容
  1208. query: function (type, _, __) {
  1209. var types = ['#([\\s\\S])+?', '([^{#}])*?'][type || 0];
  1210. return tool.exp((_ || '') + openCode + types + closeCode + (__ || ''));
  1211. },
  1212. escape: function (str) {
  1213. return String(str || '').replace(/&(?!#?[a-zA-Z0-9]+;)/g, '&amp;')
  1214. .replace(/</g, '&lt;').replace(/>/g, '&gt;')
  1215. .replace(/'/g, '&#39;').replace(/"/g, '&quot;');
  1216. },
  1217. error: function (e, tplog) {
  1218. console.error('Laytpl Error:' + e + '\n' + (tplog || ''));
  1219. },
  1220. parse: function (tpl, data) {
  1221. var tplog = tpl;
  1222. try {
  1223. var jss = tool.exp('^' + openCode + '#'), jsse = tool.exp(closeCode + '$');
  1224. tpl = tpl.replace(tool.exp(openCode + '#'), openCode + '# ')
  1225. .replace(tool.exp(closeCode + '}'), '} ' + closeCode).replace(/\\/g, '\\\\')
  1226. // 不匹配指定区域的内容
  1227. .replace(tool.exp(openCode + '!(.+?)!' + closeCode), function (str) {
  1228. str = str.replace(tool.exp('^' + openCode + '!'), '')
  1229. .replace(tool.exp('!' + closeCode), '')
  1230. .replace(tool.exp(openCode + '|' + closeCode), function (tag) {
  1231. return tag.replace(/(.)/g, '\\$1')
  1232. });
  1233. return str
  1234. })
  1235. // 匹配JS规则内容
  1236. .replace(/(?="|')/g, '\\').replace(tool.query(), function (str) {
  1237. str = str.replace(jss, '').replace(jsse, '');
  1238. return '";' + str.replace(/\\/g, '') + ';view+="';
  1239. })
  1240. // 匹配普通字段
  1241. .replace(tool.query(1), function (str) {
  1242. var start = '"+(';
  1243. if (str.replace(/\s/g, '') === openCode + closeCode) return '';
  1244. str = str.replace(tool.exp(openCode + '|' + closeCode), '');
  1245. if (/^=/.test(str)) {
  1246. str = str.replace(/^=/, '');
  1247. start = '"+_escape_(';
  1248. }
  1249. return start + str.replace(/\\/g, '') + ')+"';
  1250. })
  1251. // 换行符处理
  1252. .replace(/\r\n/g, '\\r\\n" + "').replace(/\n/g, '\\n" + "').replace(/\r/g, '\\r" + "');
  1253. tpl = '"use strict";var view = "' + tpl + '";return view;';
  1254. tpl = new Function('d, _escape_', tpl);
  1255. return tpl(data, tool.escape);
  1256. } catch (e) {
  1257. tool.error(e, tplog);
  1258. return tplog;
  1259. }
  1260. }
  1261. };
  1262. return tool.parse(html, data);
  1263. },
  1264. /* 渲染动态模板 */
  1265. render: function (option) {
  1266. if (typeof option.url === 'string') {
  1267. option.success = function (res) {
  1268. admin.util.render($.extend({}, option, {url: res}));
  1269. };
  1270. if (option.ajax === 'ajax') admin.ajax(option);
  1271. else admin.req(option.url, option.where, option.success, option.method, option);
  1272. return;
  1273. }
  1274. var html = admin.util.tpl(option.tpl, option.url,
  1275. option.open || setter.tplOpen, option.close || setter.tplClose);
  1276. $(option.elem).next('[ew-tpl-rs]').remove();
  1277. $(option.elem).after(html);
  1278. $(option.elem).next().attr('ew-tpl-rs', '');
  1279. option.done && option.done(option.url);
  1280. }
  1281. };
  1282. /** 锁屏功能 */
  1283. admin.lockScreen = function (url) {
  1284. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.lockScreen(url);
  1285. if (!url) url = 'page/tpl/tpl-lock-screen.html';
  1286. var $lock = $('#ew-lock-screen-group');
  1287. if ($lock.length > 0) {
  1288. $lock.fadeIn('fast');
  1289. admin.isLockScreen = true;
  1290. admin.putTempData('isLockScreen', admin.isLockScreen, true);
  1291. } else {
  1292. var loadIndex = layer.load(2);
  1293. admin.ajax({
  1294. url: url, dataType: 'html',
  1295. success: function (res) {
  1296. layer.close(loadIndex);
  1297. if (typeof res === 'string') {
  1298. $('body').append('<div id="ew-lock-screen-group">' + res + '</div>');
  1299. admin.isLockScreen = true;
  1300. admin.putTempData('isLockScreen', admin.isLockScreen, true);
  1301. admin.putTempData('lockScreenUrl', url, true);
  1302. } else {
  1303. console.error(res);
  1304. layer.msg(JSON.stringify(res), {icon: 2, anim: 6});
  1305. }
  1306. }
  1307. });
  1308. }
  1309. };
  1310. /** 解除锁屏 */
  1311. admin.unlockScreen = function (isRemove) {
  1312. if (window !== top && !admin.isTop() && top.layui && top.layui.admin) return top.layui.admin.unlockScreen(isRemove);
  1313. var $lock = $('#ew-lock-screen-group');
  1314. isRemove ? $lock.remove() : $lock.fadeOut('fast');
  1315. admin.isLockScreen = false;
  1316. admin.putTempData('isLockScreen', null, true);
  1317. };
  1318. /** tips方法封装 */
  1319. admin.tips = function (option) {
  1320. return layer.tips(option.text, option.elem, {
  1321. tips: [option.direction || 1, option.bg || '#191a23'],
  1322. tipsMore: option.tipsMore, time: option.time || -1,
  1323. success: function (layero) {
  1324. var $content = $(layero).children('.layui-layer-content');
  1325. if (option.padding || option.padding === 0) $content.css('padding', option.padding);
  1326. if (option.color) $content.css('color', option.color);
  1327. if (option.bgImg) $content.css('background-image', option.bgImg).children('.layui-layer-TipsG').css('z-index', '-1');
  1328. if (option.fontSize) $content.css('font-size', option.fontSize);
  1329. if (!option.offset) return;
  1330. var offset = option.offset.split(',');
  1331. var top = offset[0], left = offset.length > 1 ? offset[1] : undefined;
  1332. if (top) $(layero).css('margin-top', top);
  1333. if (left) $(layero).css('margin-left', left);
  1334. }
  1335. });
  1336. };
  1337. /** 渲染动态模板 */
  1338. admin.renderTpl = function (elem) {
  1339. if (!layui.admin) layui.admin = admin;
  1340. // 解析数据
  1341. function parseData(data) {
  1342. if (!data) return;
  1343. try {
  1344. return new Function('return ' + data + ';')();
  1345. } catch (e) {
  1346. console.error(e + '\nlay-data: ' + data);
  1347. }
  1348. }
  1349. $(elem || '[ew-tpl]').each(function () {
  1350. var $this = $(this);
  1351. var option = $(this).data();
  1352. option.elem = $this;
  1353. option.tpl = $this.html();
  1354. option.url = parseData($this.attr('ew-tpl'));
  1355. option.headers = parseData(option.headers);
  1356. option.where = parseData(option.where);
  1357. if (option.done) {
  1358. try {
  1359. option.done = new Function('res', option.done);
  1360. } catch (e) {
  1361. console.error(e + '\nlay-data:' + option.done);
  1362. option.done = undefined;
  1363. }
  1364. }
  1365. admin.util.render(option);
  1366. });
  1367. };
  1368. /** 事件监听 */
  1369. admin.on = function (events, callback) {
  1370. return layui.onevent.call(this, 'admin', events, callback);
  1371. };
  1372. /** 修改配置信息 */
  1373. admin.putSetting = function (key, value) {
  1374. setter[key] = value;
  1375. admin.putTempData(key, value, true);
  1376. };
  1377. /** 恢复配置信息 */
  1378. admin.recoverState = function () {
  1379. // 恢复锁屏状态
  1380. if (admin.getTempData('isLockScreen', true)) admin.lockScreen(admin.getTempData('lockScreenUrl', true));
  1381. // 恢复配置的主题
  1382. if (setter.defaultTheme) admin.changeTheme(setter.defaultTheme, window, true, true);
  1383. // 恢复页脚状态、导航箭头
  1384. if (setter.closeFooter) $('body').addClass('close-footer');
  1385. if (setter.navArrow !== undefined) {
  1386. var $nav = $(sideDOM + '>.layui-nav-tree');
  1387. $nav.removeClass('arrow2 arrow3');
  1388. if (setter.navArrow) $nav.addClass(setter.navArrow);
  1389. }
  1390. // 恢复tab自动刷新
  1391. if (setter.pageTabs && setter.tabAutoRefresh == 'true') $(tabDOM).attr('lay-autoRefresh', 'true');
  1392. };
  1393. /* 事件监听 */
  1394. admin.on = function (events, callback) {
  1395. return layui.onevent.call(this, 'admin', events, callback);
  1396. };
  1397. /** 侧导航折叠状态下鼠标经过无限悬浮效果 */
  1398. var navItemDOM = '.layui-layout-admin.admin-nav-mini>.layui-side .layui-nav .layui-nav-item';
  1399. $(document).on('mouseenter', navItemDOM + ',' + navItemDOM + ' .layui-nav-child>dd', function () {
  1400. if (admin.getPageWidth() > 768) {
  1401. var $that = $(this), $navChild = $that.find('>.layui-nav-child');
  1402. if ($navChild.length > 0) {
  1403. $that.addClass('admin-nav-hover');
  1404. $navChild.css('left', $that.offset().left + $that.outerWidth());
  1405. var top = $that.offset().top;
  1406. if (top + $navChild.outerHeight() > admin.getPageHeight()) {
  1407. top = top - $navChild.outerHeight() + $that.outerHeight();
  1408. if (top < 60) top = 60;
  1409. $navChild.addClass('show-top');
  1410. }
  1411. $navChild.css('top', top);
  1412. $navChild.addClass('ew-anim-drop-in');
  1413. } else if ($that.hasClass('layui-nav-item')) {
  1414. admin.tips({elem: $that, text: $that.find('cite').text(), direction: 2, offset: '12px'});
  1415. }
  1416. }
  1417. }).on('mouseleave', navItemDOM + ',' + navItemDOM + ' .layui-nav-child>dd', function () {
  1418. layer.closeAll('tips');
  1419. var $this = $(this);
  1420. $this.removeClass('admin-nav-hover');
  1421. var $child = $this.find('>.layui-nav-child');
  1422. $child.removeClass('show-top ew-anim-drop-in');
  1423. $child.css({'left': 'auto', 'top': 'auto'});
  1424. });
  1425. /** 所有ew-event */
  1426. $(document).on('click', '*[ew-event]', function () {
  1427. var te = admin.events[$(this).attr('ew-event')];
  1428. te && te.call(this, $(this));
  1429. });
  1430. /** 所有lay-tips处理 */
  1431. $(document).on('mouseenter', '*[lay-tips]', function () {
  1432. var $this = $(this);
  1433. admin.tips({
  1434. elem: $this, text: $this.attr('lay-tips'), direction: $this.attr('lay-direction'),
  1435. bg: $this.attr('lay-bg'), offset: $this.attr('lay-offset'),
  1436. padding: $this.attr('lay-padding'), color: $this.attr('lay-color'),
  1437. bgImg: $this.attr('lay-bgImg'), fontSize: $this.attr('lay-fontSize')
  1438. });
  1439. }).on('mouseleave', '*[lay-tips]', function () {
  1440. layer.closeAll('tips');
  1441. });
  1442. /** 表单搜索展开更多 */
  1443. $(document).on('click', '.form-search-expand,[search-expand]', function () {
  1444. var $this = $(this);
  1445. var $form = $this.parents('.layui-form').first();
  1446. var expand = $this.data('expand');
  1447. var change = $this.attr('search-expand');
  1448. if (expand === undefined || expand === true) {
  1449. expand = true;
  1450. $this.data('expand', false);
  1451. $this.html('收起 <i class="layui-icon layui-icon-up"></i>');
  1452. var $elem = $form.find('.form-search-show-expand');
  1453. $elem.attr('expand-show', '');
  1454. $elem.removeClass('form-search-show-expand');
  1455. } else {
  1456. expand = false;
  1457. $this.data('expand', true);
  1458. $this.html('展开 <i class="layui-icon layui-icon-down"></i>');
  1459. $form.find('[expand-show]').addClass('form-search-show-expand');
  1460. }
  1461. if (!change) return;
  1462. new Function('d', change)({expand: expand, elem: $this});
  1463. });
  1464. /** select使用fixed定位显示 */
  1465. $(document).on('click.ew-sel-fixed', '.ew-select-fixed .layui-form-select .layui-select-title', function () {
  1466. var $this = $(this), $dl = $this.parent().children('dl'), tTop = $this.offset().top;
  1467. var tWidth = $this.outerWidth(), tHeight = $this.outerHeight(), scrollT = $(document).scrollTop();
  1468. var dWidth = $dl.outerWidth(), dHeight = $dl.outerHeight();
  1469. var top = tTop + tHeight + 5 - scrollT, left = $this.offset().left;
  1470. if (top + dHeight > admin.getPageHeight()) top = top - dHeight - tHeight - 10;
  1471. if (left + dWidth > admin.getPageWidth()) left = left - dWidth + tWidth;
  1472. $dl.css({'left': left, 'top': top, 'min-width': tWidth});
  1473. });
  1474. /** 用于滚动时关闭一些fixed的组件 */
  1475. admin.hideFixedEl = function () {
  1476. $('.ew-select-fixed .layui-form-select').removeClass('layui-form-selected layui-form-selectup'); // select
  1477. $('body>.layui-laydate').remove(); // laydate
  1478. };
  1479. /** 垂直导航栏展开折叠增加过渡效果 */
  1480. $(document).on('click', '.layui-nav-tree>.layui-nav-item a', function () {
  1481. var $this = $(this), $child = $this.siblings('.layui-nav-child'), $parent = $this.parent();
  1482. if ($child.length === 0) return;
  1483. if ($parent.hasClass('admin-nav-hover')) return;
  1484. if ($parent.hasClass('layui-nav-itemed')) { // 因为layui会处理一遍所以这里状态是相反的
  1485. $child.css('display', 'none').slideDown('fast', function () {
  1486. $(this).css('display', '');
  1487. });
  1488. } else {
  1489. $child.css('display', 'block').slideUp('fast', function () {
  1490. $(this).css('display', '');
  1491. });
  1492. }
  1493. if ($this.parents('.layui-nav').attr('lay-shrink') === '_all') { // 手风琴效果
  1494. var $siblings = $this.parent().siblings('.layui-nav-itemed');
  1495. $siblings.children('.layui-nav-child').css('display', 'block').slideUp('fast', function () {
  1496. $(this).css('display', '');
  1497. });
  1498. $siblings.removeClass('layui-nav-itemed');
  1499. }
  1500. });
  1501. $('.layui-nav-tree[lay-shrink="all"]').attr('lay-shrink', '_all'); // 让layui不处理手风琴效果
  1502. /** 折叠面板展开折叠增加过渡效果 */
  1503. $(document).on('click', '.layui-collapse>.layui-colla-item>.layui-colla-title', function () {
  1504. var $this = $(this), $content = $this.siblings('.layui-colla-content')
  1505. , $collapse = $this.parent().parent(), isNone = $content.hasClass('layui-show');
  1506. if (isNone) { // 因为layui会处理一遍所以这里状态是相反的
  1507. $content.removeClass('layui-show').slideDown('fast').addClass('layui-show');
  1508. } else {
  1509. $content.css('display', 'block').slideUp('fast', function () {
  1510. $(this).css('display', '');
  1511. });
  1512. }
  1513. $this.children('.layui-colla-icon').html('&#xe602;')
  1514. .css({'transition': 'all .3s', 'transform': 'rotate(' + (isNone ? '90deg' : '0deg') + ')'});
  1515. if ($collapse.attr('lay-shrink') === '_all') { // 手风琴效果
  1516. var $show = $collapse.children('.layui-colla-item').children('.layui-colla-content.layui-show').not($content);
  1517. $show.css('display', 'block').slideUp('fast', function () {
  1518. $(this).css('display', '');
  1519. });
  1520. $show.removeClass('layui-show');
  1521. $show.siblings('.layui-colla-title').children('.layui-colla-icon').html('&#xe602;')
  1522. .css({'transition': 'all .3s', 'transform': 'rotate(0deg)'});
  1523. }
  1524. });
  1525. $('.layui-collapse[lay-accordion]').attr('lay-shrink', '_all').removeAttr('lay-accordion'); // 让layui不处理手风琴效果
  1526. /** 表单验证tips提示样式修改 */
  1527. layer.oldTips = layer.tips;
  1528. layer.tips = function (content, follow, options) {
  1529. var $fFip; // 判断是否是表单验证调用的tips
  1530. if ($(follow).length > 0 && $(follow).parents('.layui-form').length > 0) {
  1531. if ($(follow).is('input') || $(follow).is('textarea')) {
  1532. $fFip = $(follow);
  1533. } else if ($(follow).hasClass('layui-form-select') || $(follow).hasClass('layui-form-radio')
  1534. || $(follow).hasClass('layui-form-checkbox') || $(follow).hasClass('layui-form-switch')) {
  1535. $fFip = $(follow).prev();
  1536. }
  1537. }
  1538. if (!$fFip) return layer.oldTips(content, follow, options);
  1539. options.tips = [$fFip.attr('lay-direction') || 3, $fFip.attr('lay-bg') || '#ff4c4c'];
  1540. setTimeout(function () {
  1541. options.success = function (layero) {
  1542. $(layero).children('.layui-layer-content').css('padding', '6px 12px');
  1543. };
  1544. layer.oldTips(content, follow, options);
  1545. }, 100);
  1546. };
  1547. /** 所有ew-href处理 */
  1548. $(document).on('click', '*[ew-href]', function () {
  1549. var $this = $(this);
  1550. var href = $this.attr('ew-href');
  1551. if (!href || href === '#') return;
  1552. if (href.indexOf('javascript:') === 0) return new Function(href.substring(11))();
  1553. var title = $this.attr('ew-title') || $this.text();
  1554. var win = $this.data('window');
  1555. win ? (win = admin.strToWin(win)) : (win = top);
  1556. var end = $this.attr('ew-end');
  1557. try {
  1558. if (end) end = new Function(end);
  1559. else end = undefined;
  1560. } catch (e) {
  1561. console.error(e);
  1562. }
  1563. if (win.layui && win.layui.index) win.layui.index.openTab({title: title || '', url: href, end: end});
  1564. else location.href = href;
  1565. });
  1566. /** 帮助鼠标右键菜单完成点击空白关闭的功能 */
  1567. if (!layui.contextMenu) {
  1568. $(document).off('click.ctxMenu').on('click.ctxMenu', function () {
  1569. try {
  1570. var ifs = top.window.frames;
  1571. for (var i = 0; i < ifs.length; i++) {
  1572. var tif = ifs[i];
  1573. try { // 可能会跨域
  1574. if (tif.layui && tif.layui.jquery) tif.layui.jquery('body>.ctxMenu').remove();
  1575. } catch (e) {
  1576. }
  1577. }
  1578. try { // 可能会跨域
  1579. if (top.layui && top.layui.jquery) top.layui.jquery('body>.ctxMenu').remove();
  1580. } catch (e) {
  1581. }
  1582. } catch (e) {
  1583. }
  1584. });
  1585. }
  1586. /** 读取缓存的配置信息 */
  1587. setter = $.extend({
  1588. pageTabs: true, cacheTab: true, openTabCtxMenu: true, maxTabNum: 20, tableName: 'easyweb-iframe',
  1589. apiNoCache: true, ajaxSuccessBefore: function (res, url, obj) {
  1590. return admin.ajaxSuccessBefore ? admin.ajaxSuccessBefore(res, url, obj) : true;
  1591. }, getAjaxHeaders: function (res, url, obj) {
  1592. return admin.getAjaxHeaders ? admin.getAjaxHeaders(res, url, obj) : [];
  1593. }
  1594. }, setter);
  1595. var cache = admin.getTempData(true);
  1596. if (cache) {
  1597. var keys = ['pageTabs', 'cacheTab', 'defaultTheme', 'navArrow', 'closeFooter', 'tabAutoRefresh'];
  1598. for (var i = 0; i < keys.length; i++) if (cache[keys[i]] !== undefined) setter[keys[i]] = cache[keys[i]];
  1599. }
  1600. admin.recoverState(); // 恢复本地配置
  1601. admin.renderTpl(); // 渲染动态模板
  1602. admin.setter = setter;
  1603. if (layui.device().ios) $('body').addClass('ios-iframe-body'); // ios浏览器iframe兼容
  1604. exports('admin', admin);
  1605. });