madmin.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. layui.define(['message', 'table', 'jquery', 'element', 'yaml', 'form', 'tab', 'menu', 'frame', 'theme', 'convert'],
  2. function(exports) {
  3. "use strict";
  4. var $ = layui.jquery,
  5. form = layui.form,
  6. element = layui.element,
  7. yaml = layui.yaml,
  8. pearTab = layui.tab,
  9. convert = layui.convert,
  10. pearMenu = layui.menu,
  11. pearFrame = layui.frame,
  12. pearTheme = layui.theme,
  13. message = layui.message;
  14. if (typeof(window._CONFIG_) == "undefined") {
  15. window._CONFIG_ = {};
  16. }
  17. var bodyFrame;
  18. var sideMenu;
  19. var bodyTab;
  20. var config;
  21. var logout = function() {};
  22. var msgInstance;
  23. var body = $('body');
  24. var pearAdmin = new function() {
  25. var configType = 'yml';
  26. var configPath = getAppConfigPath();
  27. this.setConfigPath = function(path) {
  28. // configPath = path;
  29. }
  30. this.setConfigType = function(type) {
  31. configType = type;
  32. }
  33. this.render = function(initConfig) {
  34. if (initConfig !== undefined) {
  35. applyConfig(initConfig);
  36. } else {
  37. applyConfig(pearAdmin.readConfig());
  38. }
  39. }
  40. // by jim
  41. this.getConfig = function()
  42. {
  43. var config = {};
  44. if (!window._CONFIG_ || Object.getOwnPropertyNames(window._CONFIG_).length == 0) {
  45. config = pearAdmin.readConfig();
  46. } else {
  47. config = window._CONFIG_;
  48. }
  49. return config;
  50. }
  51. this.setAvatar = function(url, username) {
  52. var image = new Image();
  53. image.src = url || "admin/images/avatar.jpg";
  54. image.onload = function() {
  55. $(".layui-nav-img").attr("src", convert.imageToBase64(image));
  56. }
  57. $(".layui-nav-img").parent().append(username);
  58. }
  59. // by jim
  60. this.readConfig = function() {
  61. var data = {};
  62. if (configType === "yml") {
  63. data = yaml.load(configPath);
  64. } else {
  65. $.ajax({
  66. url: configPath,
  67. type: 'get',
  68. dataType: 'json',
  69. async: false,
  70. success: function(result) {
  71. data = result;
  72. }
  73. })
  74. }
  75. // by jim
  76. window._CONFIG_ = data;
  77. return data;
  78. }
  79. this.messageRender = function(option) {
  80. var option = {
  81. elem: '.message',
  82. url: option.header.message,
  83. height: '250px'
  84. };
  85. msgInstance = message.render(option);
  86. }
  87. this.logoRender = function(param) {
  88. $(".layui-logo .logo").attr("src", param.logo.image);
  89. $(".layui-logo .title").html(param.logo.title);
  90. }
  91. this.menuRender = function(param) {
  92. sideMenu = pearMenu.render({
  93. elem: 'sideMenu',
  94. async: param.menu.async !== undefined ? param.menu.async : true,
  95. theme: "dark-theme",
  96. height: '100%',
  97. method: param.menu.method,
  98. control: isControl(param) === 'true' || isControl(param) === true ? 'control' : false, // control
  99. controlWidth: param.menu.controlWidth,
  100. defaultMenu: 0,
  101. accordion: param.menu.accordion,
  102. url: param.menu.data,
  103. data: param.menu.data,
  104. parseData: false,
  105. change: function() {
  106. compatible();
  107. },
  108. done: function() {
  109. sideMenu.selectItem(param.menu.select);
  110. pearAdmin.collaspe(param);
  111. }
  112. });
  113. }
  114. this.bodyRender = function(param) {
  115. body.on("click", ".refresh", function() {
  116. refresh();
  117. })
  118. if (isMuiltTab(param) === "true" || isMuiltTab(param) === true) {
  119. bodyTab = pearTab.render({
  120. elem: 'content',
  121. roll: true,
  122. tool: true,
  123. width: '100%',
  124. height: '100%',
  125. session: param.tab.session,
  126. index: 0,
  127. tabMax: param.tab.max,
  128. closeEvent: function(id) {
  129. sideMenu.selectItem(id);
  130. },
  131. data: [{
  132. id: param.tab.index.id,
  133. url: param.tab.index.href,
  134. title: param.tab.index.title,
  135. close: false
  136. }],
  137. success: function(id) {
  138. if (param.tab.session) {
  139. setTimeout(function() {
  140. sideMenu.selectItem(id);
  141. bodyTab.positionTab();
  142. }, 500)
  143. }
  144. }
  145. });
  146. bodyTab.click(function(id) {
  147. if (!param.tab.keepState) {
  148. bodyTab.refresh(false);
  149. }
  150. bodyTab.positionTab();
  151. sideMenu.selectItem(id);
  152. })
  153. sideMenu.click(function(dom, data) {
  154. bodyTab.addTabOnly({
  155. id: data.menuId,
  156. title: data.menuTitle,
  157. url: data.menuUrl,
  158. icon: data.menuIcon,
  159. close: true
  160. }, 300);
  161. compatible();
  162. })
  163. } else {
  164. bodyFrame = pearFrame.render({
  165. elem: 'content',
  166. title: '总数据',
  167. url: param.tab.index.href,
  168. width: '100%',
  169. height: '100%'
  170. });
  171. sideMenu.click(function(dom, data) {
  172. bodyFrame.changePage(data.menuUrl, true);
  173. compatible()
  174. })
  175. }
  176. }
  177. this.keepLoad = function(param) {
  178. compatible()
  179. setTimeout(function() {
  180. $(".loader-main").fadeOut(200);
  181. }, param.other.keepLoad)
  182. }
  183. this.themeRender = function(option) {
  184. if (option.theme.allowCustom === false) {
  185. $(".setting").remove();
  186. }
  187. var colorId = localStorage.getItem("theme-color");
  188. var currentColor = getColorById(colorId);
  189. localStorage.setItem("theme-color", currentColor.id);
  190. localStorage.setItem("theme-color-color", currentColor.color);
  191. localStorage.setItem("theme-color-second", currentColor.second);
  192. pearTheme.changeTheme(window, isAutoHead(config));
  193. var menu = localStorage.getItem("theme-menu");
  194. if (menu === null) {
  195. menu = option.theme.defaultMenu;
  196. } else {
  197. if (option.theme.allowCustom === false) {
  198. menu = option.theme.defaultMenu;
  199. }
  200. }
  201. var header = localStorage.getItem("theme-header");
  202. if (header === null) {
  203. header = option.theme.defaultHeader;
  204. } else {
  205. if (option.theme.allowCustom === false) {
  206. header = option.theme.defaultHeader;
  207. }
  208. }
  209. var banner = localStorage.getItem("theme-banner");
  210. if (banner === null) {
  211. banner = option.theme.banner;
  212. } else {
  213. if (option.theme.allowCustom === false) {
  214. banner = option.theme.banner;
  215. }
  216. }
  217. var autoHead = localStorage.getItem("auto-head");
  218. if (autoHead === null) {
  219. autoHead = option.other.autoHead;
  220. } else {
  221. if (option.theme.allowCustom === false) {
  222. autoHead = option.other.autoHead;
  223. }
  224. }
  225. var muiltTab = localStorage.getItem("muilt-tab");
  226. if (muiltTab === null) {
  227. muiltTab = option.tab.enable;
  228. } else {
  229. if (option.theme.allowCustom === false) {
  230. muiltTab = option.tab.enable;
  231. }
  232. }
  233. var control = localStorage.getItem("control");
  234. if (control === null) {
  235. control = option.menu.control;
  236. } else {
  237. if (option.theme.allowCustom === false) {
  238. control = option.menu.control;
  239. }
  240. }
  241. localStorage.setItem("muilt-tab", muiltTab);
  242. localStorage.setItem("theme-banner", banner);
  243. localStorage.setItem("theme-menu", menu);
  244. localStorage.setItem("theme-header", header);
  245. localStorage.setItem("auto-head", autoHead);
  246. localStorage.setItem("control", control);
  247. this.menuSkin(menu);
  248. this.headerSkin(header);
  249. this.bannerSkin(banner);
  250. }
  251. this.bannerSkin = function(theme) {
  252. var pearAdmin = $(".pear-admin");
  253. pearAdmin.removeClass("banner-layout");
  254. if (theme === true || theme === "true") {
  255. pearAdmin.addClass("banner-layout");
  256. }
  257. }
  258. this.collaspe = function(param) {
  259. if (param.menu.collaspe) {
  260. if ($(window).width() >= 768) {
  261. collaspe()
  262. }
  263. }
  264. }
  265. this.menuSkin = function(theme) {
  266. var pearAdmin = $(".pear-admin .layui-side");
  267. pearAdmin.removeClass("light-theme");
  268. pearAdmin.removeClass("dark-theme");
  269. pearAdmin.addClass(theme);
  270. }
  271. this.headerSkin = function(theme) {
  272. var pearAdmin = $(".pear-admin .layui-header");
  273. pearAdmin.removeClass("light-theme");
  274. pearAdmin.removeClass("dark-theme");
  275. pearAdmin.addClass(theme);
  276. }
  277. this.logout = function(callback) {
  278. logout = callback;
  279. }
  280. this.message = function(callback) {
  281. if (callback != null) {
  282. msgInstance.click(callback);
  283. }
  284. }
  285. this.collaspeSide = function() {
  286. collaspe()
  287. }
  288. this.refreshThis = function() {
  289. refresh()
  290. }
  291. this.addTab = function(id, title, url) {
  292. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  293. bodyTab.addTabOnly({
  294. id: id,
  295. title: title,
  296. url: url,
  297. icon: null,
  298. close: true
  299. }, 400);
  300. } else {
  301. return;
  302. }
  303. }
  304. this.closeTab = function(id) {
  305. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  306. pearTab.delTabByElem('content', id, function(currentId){
  307. sideMenu.selectItem(currentId);
  308. });
  309. } else {
  310. return;
  311. }
  312. }
  313. this.closeCurrentTab = function() {
  314. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  315. pearTab.delCurrentTabByElem('content', function(id){
  316. sideMenu.selectItem(id);
  317. });
  318. } else {
  319. return;
  320. }
  321. }
  322. this.closeOtherTab = function() {
  323. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  324. pearTab.delOtherTabByElem('content', function(id){
  325. sideMenu.selectItem(id);
  326. });
  327. } else {
  328. return;
  329. }
  330. }
  331. this.closeAllTab = function() {
  332. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  333. pearTab.delAllTabByElem('content', function(id){
  334. sideMenu.selectItem(id);
  335. });
  336. } else {
  337. return;
  338. }
  339. }
  340. this.changeIframe = function(id, title, url) {
  341. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  342. return;
  343. } else {
  344. sideMenu.selectItem(id);
  345. bodyFrame.changePage(url, true);
  346. }
  347. }
  348. this.jump = function(id, title, url) {
  349. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  350. pearAdmin.addTab(id, title, url)
  351. } else {
  352. pearAdmin.changeIframe(id, title, url)
  353. }
  354. }
  355. this.fullScreen = function() {
  356. if ($(".fullScreen").hasClass("layui-icon-screen-restore")) {
  357. screenFun(2).then(function() {
  358. $(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
  359. });
  360. } else {
  361. screenFun(1).then(function() {
  362. $(".fullScreen").eq(0).addClass("layui-icon-screen-restore");
  363. });
  364. }
  365. }
  366. };
  367. function refresh() {
  368. var refreshA = $(".refresh a");
  369. refreshA.removeClass("layui-icon-refresh-1");
  370. refreshA.addClass("layui-anim");
  371. refreshA.addClass("layui-anim-rotate");
  372. refreshA.addClass("layui-anim-loop");
  373. refreshA.addClass("layui-icon-loading");
  374. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) bodyTab.refresh(400);
  375. else bodyFrame.refresh(400);
  376. setTimeout(function() {
  377. refreshA.addClass("layui-icon-refresh-1");
  378. refreshA.removeClass("layui-anim");
  379. refreshA.removeClass("layui-anim-rotate");
  380. refreshA.removeClass("layui-anim-loop");
  381. refreshA.removeClass("layui-icon-loading");
  382. }, 600)
  383. }
  384. function collaspe() {
  385. sideMenu.collaspe();
  386. var admin = $(".pear-admin");
  387. var left = $(".layui-icon-spread-left")
  388. var right = $(".layui-icon-shrink-right")
  389. if (admin.is(".pear-mini")) {
  390. left.addClass("layui-icon-shrink-right")
  391. left.removeClass("layui-icon-spread-left")
  392. admin.removeClass("pear-mini");
  393. } else {
  394. right.addClass("layui-icon-spread-left")
  395. right.removeClass("layui-icon-shrink-right")
  396. admin.addClass("pear-mini");
  397. }
  398. }
  399. body.on("click", ".logout", function() {
  400. if (logout()) {
  401. bodyTab.clear();
  402. }
  403. })
  404. body.on("click", ".collaspe,.pear-cover", function() {
  405. collaspe();
  406. });
  407. body.on("click", ".fullScreen", function() {
  408. if ($(this).hasClass("layui-icon-screen-restore")) {
  409. screenFun(2).then(function() {
  410. $(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
  411. });
  412. } else {
  413. screenFun(1).then(function() {
  414. $(".fullScreen").eq(0).addClass("layui-icon-screen-restore");
  415. });
  416. }
  417. });
  418. body.on("click", '[user-menu-id]', function() {
  419. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  420. bodyTab.addTabOnly({
  421. id: $(this).attr("user-menu-id"),
  422. title: $(this).attr("user-menu-title"),
  423. url: $(this).attr("user-menu-url"),
  424. icon: "",
  425. close: true
  426. }, 300);
  427. } else {
  428. bodyFrame.changePage($(this).attr("user-menu-url"), true);
  429. }
  430. });
  431. body.on("click", ".setting", function() {
  432. var menuItem =
  433. '<li class="layui-this" data-select-bgcolor="dark-theme" >' +
  434. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  435. '<div><span style="display:block; width: 20%; float: left; height: 12px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: white;"></span></div>' +
  436. '<div><span style="display:block; width: 20%; float: left; height: 40px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 40px; background: #f4f5f7;"></span></div>' +
  437. '</a>' +
  438. '</li>';
  439. menuItem +=
  440. '<li data-select-bgcolor="light-theme" >' +
  441. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  442. '<div><span style="display:block; width: 20%; float: left; height: 12px; background: white;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: white;"></span></div>' +
  443. '<div><span style="display:block; width: 20%; float: left; height: 40px; background: white;"></span><span style="display:block; width: 80%; float: left; height: 40px; background: #f4f5f7;"></span></div>' +
  444. '</a>' +
  445. '</li>';
  446. var menuHtml =
  447. '<div class="pearone-color">\n' +
  448. '<div class="color-title">菜单风格</div>\n' +
  449. '<div class="color-content">\n' +
  450. '<ul>\n' + menuItem + '</ul>\n' +
  451. '</div>\n' +
  452. '</div>';
  453. var headItem =
  454. '<li class="layui-this" data-select-header="light-theme" >' +
  455. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  456. '<div><span style="display:block; width: 20%; float: left; height: 12px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: white;"></span></div>' +
  457. '<div><span style="display:block; width: 20%; float: left; height: 40px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 40px; background: #f4f5f7;"></span></div>' +
  458. '</a>' +
  459. '</li>';
  460. headItem +=
  461. '<li data-select-header="dark-theme" >' +
  462. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  463. '<div><span style="display:block; width: 20%; float: left; height: 12px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 12px; background: #28333E;"></span></div>' +
  464. '<div><span style="display:block; width: 20%; float: left; height: 40px; background: #28333E;"></span><span style="display:block; width: 80%; float: left; height: 40px; background: #f4f5f7;"></span></div>' +
  465. '</a>' +
  466. '</li>';
  467. var headHtml =
  468. '<div class="pearone-color">\n' +
  469. '<div class="color-title">顶部风格</div>\n' +
  470. '<div class="color-content">\n' +
  471. '<ul>\n' + headItem + '</ul>\n' +
  472. '</div>\n' +
  473. '</div>';
  474. var moreItem =
  475. '<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="control" lay-filter="control" lay-skin="switch" lay-text="开|关"></div><span class="set-text">菜单</span></div>';
  476. moreItem +=
  477. '<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="muilt-tab" lay-filter="muilt-tab" lay-skin="switch" lay-text="开|关"></div><span class="set-text">视图</span></div>';
  478. moreItem +=
  479. '<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="banner" lay-filter="banner" lay-skin="switch" lay-text="开|关"></div><span class="set-text">通栏</span></div>';
  480. moreItem +=
  481. '<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="auto-head" lay-filter="auto-head" lay-skin="switch" lay-text="开|关"></div><span class="set-text">通色</span></div>';
  482. var moreHtml = '<br><div class="pearone-color">\n' +
  483. '<div class="color-title">更多设置</div>\n' +
  484. '<div class="color-content">\n' +
  485. '<form class="layui-form">\n' + moreItem + '</form>\n' +
  486. '</div>\n' +
  487. '</div>';
  488. layer.open({
  489. type: 1,
  490. offset: 'r',
  491. area: ['320px', '100%'],
  492. title: false,
  493. shade: 0.1,
  494. closeBtn: 0,
  495. shadeClose: false,
  496. anim: -1,
  497. skin: 'layer-anim-right',
  498. move: false,
  499. content: menuHtml + headHtml + buildColorHtml() + moreHtml + bottomTool(),
  500. success: function(layero, index) {
  501. form.render();
  502. var color = localStorage.getItem("theme-color");
  503. var menu = localStorage.getItem("theme-menu");
  504. var header = localStorage.getItem("theme-header");
  505. if (color !== "null") {
  506. $(".select-color-item").removeClass("layui-icon").removeClass("layui-icon-ok");
  507. $("*[color-id='" + color + "']").addClass("layui-icon").addClass("layui-icon-ok");
  508. }
  509. if (menu !== "null") {
  510. $("*[data-select-bgcolor]").removeClass("layui-this");
  511. $("[data-select-bgcolor='" + menu + "']").addClass("layui-this");
  512. }
  513. if (header !== "null") {
  514. $("*[data-select-header]").removeClass("layui-this");
  515. $("[data-select-header='" + header + "']").addClass("layui-this");
  516. }
  517. $('#layui-layer-shade' + index).click(function() {
  518. var $layero = $('#layui-layer' + index);
  519. $layero.animate({
  520. left: $layero.offset().left + $layero.width()
  521. }, 200, function() {
  522. layer.close(index);
  523. });
  524. })
  525. $('#closeTheme').click(function() {
  526. var $layero = $('#layui-layer' + index);
  527. $layero.animate({
  528. left: $layero.offset().left + $layero.width()
  529. }, 200, function() {
  530. layer.close(index);
  531. });
  532. })
  533. form.on('switch(control)', function(data) {
  534. localStorage.setItem("control", this.checked);
  535. window.location.reload();
  536. })
  537. form.on('switch(muilt-tab)', function(data) {
  538. localStorage.setItem("muilt-tab", this.checked);
  539. window.location.reload();
  540. })
  541. form.on('switch(auto-head)', function(data) {
  542. localStorage.setItem("auto-head", this.checked);
  543. pearTheme.changeTheme(window, this.checked);
  544. })
  545. form.on('switch(banner)', function(data) {
  546. localStorage.setItem("theme-banner", this.checked);
  547. pearAdmin.bannerSkin(this.checked);
  548. })
  549. if (localStorage.getItem('theme-banner') === 'true') {
  550. $('input[name="banner"]').attr('checked', 'checked')
  551. } else {
  552. $('input[name="banner"]').removeAttr('checked')
  553. }
  554. if (localStorage.getItem('control') === 'true') {
  555. $('input[name="control"]').attr('checked', 'checked')
  556. } else {
  557. $('input[name="control"]').removeAttr('checked')
  558. }
  559. if (localStorage.getItem('muilt-tab') === 'true') {
  560. $('input[name="muilt-tab"]').attr('checked', 'checked')
  561. } else {
  562. $('input[name="muilt-tab"]').removeAttr('checked')
  563. }
  564. if (localStorage.getItem('auto-head') === 'true') {
  565. $('input[name="auto-head"]').attr('checked', 'checked')
  566. } else {
  567. $('input[name="auto-head"]').removeAttr('checked')
  568. }
  569. form.render('checkbox');
  570. }
  571. });
  572. });
  573. function bottomTool() {
  574. return "<button id='closeTheme' style='position: absolute;bottom: 20px;left: 20px;' class='pear-btn'>关闭</button>"
  575. }
  576. body.on('click', '[data-select-bgcolor]', function() {
  577. var theme = $(this).attr('data-select-bgcolor');
  578. $('[data-select-bgcolor]').removeClass("layui-this");
  579. $(this).addClass("layui-this");
  580. localStorage.setItem("theme-menu", theme);
  581. pearAdmin.menuSkin(theme);
  582. });
  583. body.on('click', '[data-select-header]', function() {
  584. var theme = $(this).attr('data-select-header');
  585. $('[data-select-header]').removeClass("layui-this");
  586. $(this).addClass("layui-this");
  587. localStorage.setItem("theme-header", theme);
  588. pearAdmin.headerSkin(theme);
  589. });
  590. body.on('click', '.select-color-item', function() {
  591. $(".select-color-item").removeClass("layui-icon").removeClass("layui-icon-ok");
  592. $(this).addClass("layui-icon").addClass("layui-icon-ok");
  593. var colorId = $(".select-color-item.layui-icon-ok").attr("color-id");
  594. var currentColor = getColorById(colorId);
  595. localStorage.setItem("theme-color", currentColor.id);
  596. localStorage.setItem("theme-color-color", currentColor.color);
  597. localStorage.setItem("theme-color-second", currentColor.second);
  598. pearTheme.changeTheme(window, isAutoHead(config));
  599. });
  600. function applyConfig(param) {
  601. config = param;
  602. pearAdmin.logoRender(param);
  603. pearAdmin.menuRender(param);
  604. pearAdmin.bodyRender(param);
  605. pearAdmin.themeRender(param);
  606. pearAdmin.keepLoad(param);
  607. if (param.header.message != false) {
  608. pearAdmin.messageRender(param);
  609. }
  610. }
  611. function getColorById(id) {
  612. var color;
  613. var flag = false;
  614. $.each(config.colors, function(i, value) {
  615. if (value.id === id) {
  616. color = value;
  617. flag = true;
  618. }
  619. })
  620. if (flag === false || config.theme.allowCustom === false) {
  621. $.each(config.colors, function(i, value) {
  622. if (value.id === config.theme.defaultColor) {
  623. color = value;
  624. }
  625. })
  626. }
  627. return color;
  628. }
  629. function buildColorHtml() {
  630. var colors = "";
  631. $.each(config.colors, function(i, value) {
  632. colors += "<span class='select-color-item' color-id='" + value.id + "' style='background-color:" + value.color +
  633. ";'></span>";
  634. })
  635. return "<div class='select-color'><div class='select-color-title'>主题配色</div><div class='select-color-content'>" +
  636. colors + "</div></div>"
  637. }
  638. function compatible() {
  639. if ($(window).width() <= 768) {
  640. collaspe()
  641. }
  642. }
  643. function screenFun(num) {
  644. num = num || 1;
  645. num = num * 1;
  646. var docElm = document.documentElement;
  647. switch (num) {
  648. case 1:
  649. if (docElm.requestFullscreen) {
  650. docElm.requestFullscreen();
  651. } else if (docElm.mozRequestFullScreen) {
  652. docElm.mozRequestFullScreen();
  653. } else if (docElm.webkitRequestFullScreen) {
  654. docElm.webkitRequestFullScreen();
  655. } else if (docElm.msRequestFullscreen) {
  656. docElm.msRequestFullscreen();
  657. }
  658. break;
  659. case 2:
  660. if (document.exitFullscreen) {
  661. document.exitFullscreen();
  662. } else if (document.mozCancelFullScreen) {
  663. document.mozCancelFullScreen();
  664. } else if (document.webkitCancelFullScreen) {
  665. document.webkitCancelFullScreen();
  666. } else if (document.msExitFullscreen) {
  667. document.msExitFullscreen();
  668. }
  669. break;
  670. }
  671. return new Promise(function(res, rej) {
  672. res("返回值");
  673. });
  674. }
  675. function isFullscreen() {
  676. return document.fullscreenElement ||
  677. document.msFullscreenElement ||
  678. document.mozFullScreenElement ||
  679. document.webkitFullscreenElement || false;
  680. }
  681. function isControl(option) {
  682. if (option.theme.allowCustom) {
  683. if (localStorage.getItem("control") != null) {
  684. return localStorage.getItem("control")
  685. } else {
  686. return option.menu.control
  687. }
  688. } else {
  689. return option.menu.control
  690. }
  691. }
  692. function isAutoHead(option) {
  693. if (option.theme.allowCustom) {
  694. if (localStorage.getItem("auto-head") != null) {
  695. return localStorage.getItem("auto-head");
  696. } else {
  697. return option.other.autoHead;
  698. }
  699. } else {
  700. return option.other.autoHead;
  701. }
  702. }
  703. function isMuiltTab(option) {
  704. if (option.theme.allowCustom) {
  705. if (localStorage.getItem("muilt-tab") != null) {
  706. return localStorage.getItem("muilt-tab")
  707. } else {
  708. return option.tab.enable
  709. }
  710. } else {
  711. return option.tab.enable
  712. }
  713. }
  714. window.onresize = function() {
  715. if (!isFullscreen()) {
  716. $(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
  717. }
  718. }
  719. exports('madmin', pearAdmin);
  720. })