admin.js 23 KB

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