控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

admin.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903
  1. layui.define(['table', 'jquery', 'element','form', 'tab', 'menu', 'frame', 'theme','fullscreen'],
  2. function(exports) {
  3. "use strict";
  4. var $ = layui.jquery,
  5. form = layui.form,
  6. element = layui.element,
  7. pearTab = layui.tab,
  8. pearMenu = layui.menu,
  9. pearFrame = layui.frame,
  10. pearTheme = layui.theme,
  11. fullscreen=layui.fullscreen;
  12. var bodyFrame;
  13. var sideMenu;
  14. var bodyTab;
  15. var config;
  16. var logout = function() {};
  17. var msgInstance;
  18. var body = $('body');
  19. var pearAdmin = new function() {
  20. this.render = function(initConfig) {
  21. applyConfig(initConfig);
  22. }
  23. this.menuRender = function(param) {
  24. sideMenu = pearMenu.render({
  25. elem: 'sideMenu',
  26. async: param.menu.async !== undefined ? param.menu.async : true,
  27. theme: "dark-theme",
  28. height: '100%',
  29. method: param.menu.method,
  30. control: isControl(param) === 'true' || isControl(param) === true ? 'control' : false, // control
  31. defaultMenu: 0,
  32. accordion: param.menu.accordion,
  33. url: param.menu.data,
  34. data: param.menu.data,
  35. parseData: false,
  36. change: function() {
  37. compatible();
  38. },
  39. done: function() {
  40. sideMenu.isCollapse = param.menu.collapse;
  41. sideMenu.selectItem(param.menu.select);
  42. pearAdmin.collapse(param);
  43. }
  44. });
  45. }
  46. this.bodyRender = function(param) {
  47. body.on("click", ".refresh", function() {
  48. refresh();
  49. })
  50. if (isMuiltTab(param) === "true" || isMuiltTab(param) === true) {
  51. bodyTab = pearTab.render({
  52. elem: 'content',
  53. roll: true,
  54. tool: true,
  55. width: '100%',
  56. height: '100%',
  57. session: param.tab.session,
  58. index: 0,
  59. tabMax: param.tab.max,
  60. preload: param.tab.preload,
  61. closeEvent: function(id) {
  62. sideMenu.selectItem(id);
  63. },
  64. data: [{
  65. id: param.tab.index.id,
  66. url: param.tab.index.href,
  67. title: param.tab.index.title,
  68. close: false
  69. }],
  70. success: function(id) {
  71. if (param.tab.session) {
  72. setTimeout(function() {
  73. sideMenu.selectItem(id);
  74. bodyTab.positionTab();
  75. }, 500)
  76. }
  77. }
  78. });
  79. bodyTab.click(function(id) {
  80. if (!param.tab.keepState) {
  81. bodyTab.refresh(false);
  82. }
  83. bodyTab.positionTab();
  84. sideMenu.selectItem(id);
  85. })
  86. sideMenu.click(function(dom, data, change) {
  87. bodyTab.addTabOnly({
  88. id: data.menuId,
  89. title: data.menuTitle,
  90. url: data.menuUrl,
  91. icon: data.menuIcon,
  92. close: true
  93. }, 300);
  94. change !== false && compatible();
  95. })
  96. } else {
  97. bodyFrame = pearFrame.render({
  98. elem: 'content',
  99. title: '首页',
  100. url: param.tab.index.href,
  101. width: '100%',
  102. height: '100%'
  103. });
  104. sideMenu.click(function(dom, data) {
  105. bodyFrame.changePage(data.menuUrl, true);
  106. compatible()
  107. })
  108. }
  109. }
  110. this.keepLoad = function(param) {
  111. compatible()
  112. setTimeout(function() {
  113. $(".loader-main").fadeOut(200);
  114. }, param.other.keepLoad)
  115. }
  116. this.themeRender = function(option) {
  117. if (option.theme.allowCustom === false) {
  118. $(".setting").remove();
  119. }
  120. var colorId = localStorage.getItem("theme-color");
  121. var currentColor = getColorById(colorId);
  122. localStorage.setItem("theme-color", currentColor.id);
  123. localStorage.setItem("theme-color-color", currentColor.color);
  124. localStorage.setItem("theme-color-second", currentColor.second);
  125. pearTheme.changeTheme(window, isAutoHead(config));
  126. var menu = localStorage.getItem("theme-menu");
  127. if (menu === null) {
  128. menu = option.theme.defaultMenu;
  129. } else {
  130. if (option.theme.allowCustom === false) {
  131. menu = option.theme.defaultMenu;
  132. }
  133. }
  134. var header = localStorage.getItem("theme-header");
  135. if (header === null) {
  136. header = option.theme.defaultHeader;
  137. } else {
  138. if (option.theme.allowCustom === false) {
  139. header = option.theme.defaultHeader;
  140. }
  141. }
  142. var banner = localStorage.getItem("theme-banner");
  143. if (banner === null) {
  144. banner = option.theme.banner;
  145. } else {
  146. if (option.theme.allowCustom === false) {
  147. banner = option.theme.banner;
  148. }
  149. }
  150. var autoHead = localStorage.getItem("auto-head");
  151. if (autoHead === null) {
  152. autoHead = option.other.autoHead;
  153. } else {
  154. if (option.theme.allowCustom === false) {
  155. autoHead = option.other.autoHead;
  156. }
  157. }
  158. var muiltTab = localStorage.getItem("muilt-tab");
  159. if (muiltTab === null) {
  160. muiltTab = option.tab.enable;
  161. } else {
  162. if (option.theme.allowCustom === false) {
  163. muiltTab = option.tab.enable;
  164. }
  165. }
  166. var control = localStorage.getItem("control");
  167. if (control === null) {
  168. control = option.menu.control;
  169. } else {
  170. if (option.theme.allowCustom === false) {
  171. control = option.menu.control;
  172. }
  173. }
  174. var footer = localStorage.getItem("footer");
  175. if( footer === null) {
  176. footer = option.other.footer;
  177. }else{
  178. if (option.theme.allowCustom === false) {
  179. footer = option.other.footer;
  180. }
  181. }
  182. localStorage.setItem("muilt-tab", muiltTab);
  183. localStorage.setItem("theme-banner", banner);
  184. localStorage.setItem("theme-menu", menu);
  185. localStorage.setItem("theme-header", header);
  186. localStorage.setItem("auto-head", autoHead);
  187. localStorage.setItem("control", control);
  188. localStorage.setItem("footer", footer);
  189. this.menuSkin(menu);
  190. this.headerSkin(header);
  191. this.bannerSkin(banner);
  192. this.footer(footer);
  193. }
  194. this.footer = function(footer){
  195. var bodyDOM = $(".pear-admin .layui-body");
  196. var footerDOM = $(".pear-admin .layui-footer");
  197. if (footer === true || footer === "true") {
  198. footerDOM.removeClass("close");
  199. bodyDOM.css("bottom", footerDOM.outerHeight());
  200. } else {
  201. footerDOM.addClass("close");
  202. bodyDOM.css("bottom", "");
  203. }
  204. }
  205. this.bannerSkin = function(theme) {
  206. var pearAdmin = $(".pear-admin");
  207. pearAdmin.removeClass("banner-layout");
  208. if (theme === true || theme === "true") {
  209. pearAdmin.addClass("banner-layout");
  210. }
  211. }
  212. this.collapse = function(param) {
  213. if (param.menu.collapse) {
  214. if ($(window).width() >= 768) {
  215. collapse()
  216. }
  217. }
  218. }
  219. this.menuSkin = function(theme) {
  220. var pearAdmin = $(".pear-admin .layui-side");
  221. pearAdmin.removeClass("light-theme");
  222. pearAdmin.removeClass("dark-theme");
  223. pearAdmin.addClass(theme);
  224. }
  225. this.headerSkin = function(theme) {
  226. var pearAdmin = $(".pear-admin .layui-header");
  227. pearAdmin.removeClass("light-theme");
  228. pearAdmin.removeClass("dark-theme");
  229. pearAdmin.addClass(theme);
  230. }
  231. this.logout = function(callback) {
  232. logout = callback;
  233. }
  234. this.message = function(callback) {
  235. if (callback != null) {
  236. msgInstance.click(callback);
  237. }
  238. }
  239. this.collapseSide = function() {
  240. collapse()
  241. }
  242. this.refreshThis = function() {
  243. refresh()
  244. }
  245. this.refresh = function(id) {
  246. $("iframe[id='"+ id +"']").attr('src', $("iframe[id='"+ id +"']").attr('src'));
  247. }
  248. this.addTab = function(id, title, url) {
  249. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  250. bodyTab.addTabOnly({
  251. id: id,
  252. title: title,
  253. url: url,
  254. icon: null,
  255. close: true
  256. }, 400);
  257. } else {
  258. return;
  259. }
  260. }
  261. this.closeTab = function(id) {
  262. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  263. pearTab.delTabByElem('content', id, function(currentId){
  264. sideMenu.selectItem(currentId);
  265. });
  266. } else {
  267. return;
  268. }
  269. }
  270. this.closeCurrentTab = function() {
  271. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  272. pearTab.delCurrentTabByElem('content', function(id){
  273. sideMenu.selectItem(id);
  274. });
  275. } else {
  276. return;
  277. }
  278. }
  279. this.closeOtherTab = function() {
  280. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  281. pearTab.delOtherTabByElem('content', function(id){
  282. sideMenu.selectItem(id);
  283. });
  284. } else {
  285. return;
  286. }
  287. }
  288. this.closeAllTab = function() {
  289. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  290. pearTab.delAllTabByElem('content', function(id){
  291. sideMenu.selectItem(id);
  292. });
  293. } else {
  294. return;
  295. }
  296. }
  297. this.changeTabTitle = function(id, title) {
  298. pearTab.changeTabTitleById('content', id ,title);
  299. }
  300. this.changeIframe = function(id, title, url) {
  301. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  302. return;
  303. } else {
  304. sideMenu.selectItem(id);
  305. bodyFrame.changePage(url, true);
  306. }
  307. }
  308. this.jump = function(id, title, url) {
  309. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  310. pearAdmin.addTab(id, title, url)
  311. } else {
  312. pearAdmin.changeIframe(id, title, url)
  313. }
  314. }
  315. this.fullScreen = function() {
  316. if ($(".fullScreen").hasClass("layui-icon-screen-restore")) {
  317. screenFun(2).then(function() {
  318. $(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
  319. });
  320. } else {
  321. screenFun(1).then(function() {
  322. $(".fullScreen").eq(0).addClass("layui-icon-screen-restore");
  323. });
  324. }
  325. }
  326. };
  327. function refresh() {
  328. var refreshA = $(".refresh a");
  329. refreshA.removeClass("layui-icon-refresh-1");
  330. refreshA.addClass("layui-anim");
  331. refreshA.addClass("layui-anim-rotate");
  332. refreshA.addClass("layui-anim-loop");
  333. refreshA.addClass("layui-icon-loading");
  334. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) bodyTab.refresh(true);
  335. else bodyFrame.refresh(true);
  336. setTimeout(function() {
  337. refreshA.addClass("layui-icon-refresh-1");
  338. refreshA.removeClass("layui-anim");
  339. refreshA.removeClass("layui-anim-rotate");
  340. refreshA.removeClass("layui-anim-loop");
  341. refreshA.removeClass("layui-icon-loading");
  342. }, 600)
  343. }
  344. function collapse() {
  345. sideMenu.collapse();
  346. var admin = $(".pear-admin");
  347. var left = $(".layui-icon-spread-left")
  348. var right = $(".layui-icon-shrink-right")
  349. if (admin.is(".pear-mini")) {
  350. left.addClass("layui-icon-shrink-right")
  351. left.removeClass("layui-icon-spread-left")
  352. admin.removeClass("pear-mini");
  353. sideMenu.isCollapse = false;
  354. } else {
  355. right.addClass("layui-icon-spread-left")
  356. right.removeClass("layui-icon-shrink-right")
  357. admin.addClass("pear-mini");
  358. sideMenu.isCollapse = true;
  359. }
  360. }
  361. body.on("click", ".logout", function() {
  362. if (logout() && bodyTab) {
  363. bodyTab.clear();
  364. }
  365. })
  366. body.on("click", ".collapse,.pear-cover", function() {
  367. collapse();
  368. });
  369. body.on("click", ".menuSearch", function () {
  370. // 过滤菜单
  371. var filterHandle = function (filterData, val) {
  372. if (!val) return [];
  373. var filteredMenus = [];
  374. filterData = $.extend(true, {}, filterData);
  375. $.each(filterData, function (index, item) {
  376. if (item.childlist && item.childlist.length) {
  377. var childlist = filterHandle(item.childlist, val)
  378. var obj = $.extend({}, item, { childlist: childlist });
  379. if (childlist && childlist.length) {
  380. filteredMenus.push(obj);
  381. } else if (item.title.indexOf(val) >= 0) {
  382. item.childlist = []; // 父级匹配但子级不匹配,就去除子级
  383. filteredMenus.push($.extend({}, item));
  384. }
  385. } else if (item.title.indexOf(val) >= 0) {
  386. filteredMenus.push(item);
  387. }
  388. })
  389. return filteredMenus;
  390. }
  391. // 树转路径
  392. var tiledHandle = function (data) {
  393. var tiledMenus = [];
  394. var treeTiled = function (data, content) {
  395. var path = "";
  396. var separator = " / ";
  397. // 上级路径
  398. if (!content) content = "";
  399. $.each(data, function (index, item) {
  400. if (item.childlist && item.childlist.length) {
  401. path += content + item.title + separator;
  402. var childPath = treeTiled(item.childlist, path);
  403. path += childPath;
  404. if (!childPath) path = ""; // 重置路径
  405. } else {
  406. path += content + item.title
  407. tiledMenus.push({ path: path, info: item });
  408. path = ""; //重置路径
  409. }
  410. })
  411. return path;
  412. };
  413. treeTiled(data);
  414. return tiledMenus;
  415. }
  416. // 创建搜索列表
  417. var createList = function (data) {
  418. var _listHtml = '';
  419. $.each(data, function (index, item) {
  420. _listHtml += '<li smenu-id="' + item.info.id + '" smenu-icon="' + item.info.icon + '" smenu-url="' + item.info.href + '" smenu-title="' + item.info.title + '" smenu-type="' + item.info.type + '">';
  421. _listHtml += ' <span><i style="margin-right:10px" class=" ' + item.info.icon + '"></i>' + item.path + '</span>';
  422. _listHtml += ' <i class="layui-icon layui-icon-right"></i>';
  423. _listHtml += '</li>'
  424. })
  425. return _listHtml;
  426. }
  427. var _html = [
  428. '<div class="menu-search-content">',
  429. ' <div class="layui-form menu-search-input-wrapper">',
  430. ' <div class=" layui-input-wrap layui-input-wrap-prefix">',
  431. ' <div class="layui-input-prefix">',
  432. ' <i class="layui-icon layui-icon-search"></i>',
  433. ' </div>',
  434. ' <input type="text" name="menuSearch" value="" placeholder="搜索菜单" autocomplete="off" class="layui-input" lay-affix="clear">',
  435. ' </div>',
  436. ' </div>',
  437. ' <div class="menu-search-no-data">暂无搜索结果</div>',
  438. ' <ul class="menu-search-list">',
  439. ' </ul>',
  440. ' <div class="menu-search-tips"><div><span class="mr-1">选择</span><kbd class="mr-1 w-5"> ↑ </kbd><kbd class="mr-5 w-5"> ↓ </kbd>',
  441. '<span class="mr-1">确定</span><kbd class="mr-5"> Enter </kbd><span class="mr-1">关闭</span><kbd class="mr-1"> Esc </kbd></div></div>',
  442. '</div>'
  443. ].join('');
  444. layer.open({
  445. type: 1,
  446. offset: "10%",
  447. area: ['600px'],
  448. title: false,
  449. closeBtn: 0,
  450. shadeClose: true,
  451. anim: 0,
  452. move: false,
  453. content: _html,
  454. success: function(layero,layeridx){
  455. var $layer = layero;
  456. var $content = $(layero).children('.layui-layer-content');
  457. var $input = $(".menu-search-input-wrapper input");
  458. var $noData = $(".menu-search-no-data");
  459. var $list = $(".menu-search-list");
  460. var menuData = sideMenu.option.data;
  461. $layer.css("border-radius", "6px");
  462. $input.off("focus").focus();
  463. // 搜索菜单
  464. $input.off("input").on("input", debounce(function(){
  465. var keywords = $input.val().trim();
  466. var filteredMenus = filterHandle(menuData, keywords);
  467. if(filteredMenus.length){
  468. var tiledMenus = tiledHandle(filteredMenus);
  469. var listHtml = createList(tiledMenus);
  470. $noData.css("display", "none");
  471. $list.html("").append(listHtml).children(":first").addClass("this")
  472. }else{
  473. $list.html("");
  474. $noData.css("display", "flex");
  475. }
  476. var currentHeight = $(".menu-search-content").outerHeight()
  477. $layer.css("height", currentHeight);
  478. $content.css("height", currentHeight);
  479. }, 500)
  480. )
  481. // 搜索列表点击事件
  482. $list.off("click").on("click", "li", function () {
  483. var menuId = $(this).attr("smenu-id");
  484. var menuUrl = $(this).attr("smenu-url");
  485. var menuIcon = $(this).attr("smenu-icon");
  486. var menuTitle = $(this).attr("smenu-title");
  487. var menuType = $(this).attr("smenu-type");
  488. var openableWindow = menuType === "1" || menuType === 1;
  489. if(sideMenu.isCollapse){
  490. collapse();
  491. }
  492. if (openableWindow) {
  493. pearAdmin.jump(menuId, menuTitle, menuUrl)
  494. } else {
  495. sideMenu.selectItem(menuId);
  496. }
  497. compatible();
  498. layer.close(layeridx);
  499. })
  500. $list.off('mouseenter').on("mouseenter", "li", function () {
  501. $(".menu-search-list li.this").removeClass("this");
  502. $(this).addClass("this");
  503. }).off("mouseleave").on("mouseleave", "li", function(){
  504. $(this).removeClass("this");
  505. })
  506. // 监听键盘事件
  507. // Enter:13 Spacebar:32 UpArrow:38 DownArrow:40 Esc:27
  508. $(document).off("keydown").keydown(function (e) {
  509. if (e.keyCode === 13 || e.keyCode === 32) {
  510. e.preventDefault();
  511. var menuId = $(".menu-search-list li.this").attr("smenu-id");
  512. var menuUrl = $(".menu-search-list li.this").attr("smenu-url");
  513. var menuTitle = $(".menu-search-list li.this").attr("smenu-title");
  514. var menuType = $(".menu-search-list li.this").attr("smenu-type");
  515. var openableWindow = menuType === "1" || menuType === 1;
  516. if (sideMenu.isCollapse) {
  517. collapse();
  518. }
  519. if (openableWindow) {
  520. pearAdmin.jump(menuId, menuTitle, menuUrl)
  521. } else {
  522. sideMenu.selectItem(menuId);
  523. }
  524. compatible();
  525. layer.close(layeridx);
  526. }else if(e.keyCode === 38){
  527. e.preventDefault();
  528. var prevEl = $(".menu-search-list li.this").prev();
  529. $(".menu-search-list li.this").removeClass("this");
  530. if(prevEl.length !== 0){
  531. prevEl.addClass("this");
  532. }else{
  533. $list.children().last().addClass("this");
  534. }
  535. }else if(e.keyCode === 40){
  536. e.preventDefault();
  537. var nextEl = $(".menu-search-list li.this").next();
  538. $(".menu-search-list li.this").removeClass("this");
  539. if(nextEl.length !== 0){
  540. nextEl.addClass("this");
  541. }else{
  542. $list.children().first().addClass("this");
  543. }
  544. }else if(e.keyCode === 27){
  545. e.preventDefault();
  546. layer.close(layeridx);
  547. }
  548. })
  549. }
  550. })
  551. });
  552. body.on("click", ".fullScreen", function() {
  553. if ($(this).hasClass("layui-icon-screen-restore")) {
  554. fullscreen.fullClose().then(function() {
  555. $(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
  556. });
  557. } else {
  558. fullscreen.fullScreen().then(function() {
  559. $(".fullScreen").eq(0).addClass("layui-icon-screen-restore");
  560. });
  561. }
  562. });
  563. body.on("click", '[user-menu-id]', function() {
  564. if (isMuiltTab(config) === "true" || isMuiltTab(config) === true) {
  565. bodyTab.addTabOnly({
  566. id: $(this).attr("user-menu-id"),
  567. title: $(this).attr("user-menu-title"),
  568. url: $(this).attr("user-menu-url"),
  569. icon: "",
  570. close: true
  571. }, 300);
  572. } else {
  573. bodyFrame.changePage($(this).attr("user-menu-url"), true);
  574. }
  575. });
  576. body.on("click", ".setting", function() {
  577. var menuItem =
  578. '<li class="layui-this" data-select-bgcolor="dark-theme" >' +
  579. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  580. '<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>' +
  581. '<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>' +
  582. '</a>' +
  583. '</li>';
  584. menuItem +=
  585. '<li data-select-bgcolor="light-theme" >' +
  586. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  587. '<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>' +
  588. '<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>' +
  589. '</a>' +
  590. '</li>';
  591. var menuHtml =
  592. '<div class="pearone-color">\n' +
  593. '<div class="color-title">菜单风格</div>\n' +
  594. '<div class="color-content">\n' +
  595. '<ul>\n' + menuItem + '</ul>\n' +
  596. '</div>\n' +
  597. '</div>';
  598. var headItem =
  599. '<li class="layui-this" data-select-header="light-theme" >' +
  600. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  601. '<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>' +
  602. '<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>' +
  603. '</a>' +
  604. '</li>';
  605. headItem +=
  606. '<li data-select-header="dark-theme" >' +
  607. '<a href="javascript:;" data-skin="skin-blue" style="" class="clearfix full-opacity-hover">' +
  608. '<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>' +
  609. '<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>' +
  610. '</a>' +
  611. '</li>';
  612. var headHtml =
  613. '<div class="pearone-color">\n' +
  614. '<div class="color-title">顶部风格</div>\n' +
  615. '<div class="color-content">\n' +
  616. '<ul>\n' + headItem + '</ul>\n' +
  617. '</div>\n' +
  618. '</div>';
  619. var moreItem =
  620. '<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>';
  621. moreItem +=
  622. '<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>';
  623. moreItem +=
  624. '<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>';
  625. moreItem +=
  626. '<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>';
  627. moreItem +=
  628. '<div class="layui-form-item"><div class="layui-input-inline"><input type="checkbox" name="footer" lay-filter="footer" lay-skin="switch" lay-text="开|关"></div><span class="set-text">页脚</span></div>';
  629. var moreHtml = '<br><div class="pearone-color">\n' +
  630. '<div class="color-title">更多设置</div>\n' +
  631. '<div class="color-content">\n' +
  632. '<form class="layui-form">\n' + moreItem + '</form>\n' +
  633. '</div>\n' +
  634. '</div>';
  635. layer.open({
  636. type: 1,
  637. offset: 'r',
  638. area: ['320px', '100%'],
  639. title: false,
  640. shade: 0.1,
  641. closeBtn: 0,
  642. shadeClose: false,
  643. anim: -1,
  644. skin: 'layer-anim-right',
  645. move: false,
  646. content: menuHtml + headHtml + buildColorHtml() + moreHtml,
  647. success: function(layero, index) {
  648. form.render();
  649. var color = localStorage.getItem("theme-color");
  650. var menu = localStorage.getItem("theme-menu");
  651. var header = localStorage.getItem("theme-header");
  652. if (color !== "null") {
  653. $(".select-color-item").removeClass("layui-icon").removeClass("layui-icon-ok");
  654. $("*[color-id='" + color + "']").addClass("layui-icon").addClass("layui-icon-ok");
  655. }
  656. if (menu !== "null") {
  657. $("*[data-select-bgcolor]").removeClass("layui-this");
  658. $("[data-select-bgcolor='" + menu + "']").addClass("layui-this");
  659. }
  660. if (header !== "null") {
  661. $("*[data-select-header]").removeClass("layui-this");
  662. $("[data-select-header='" + header + "']").addClass("layui-this");
  663. }
  664. $('#layui-layer-shade' + index).click(function() {
  665. var $layero = $('#layui-layer' + index);
  666. $layero.animate({
  667. left: $layero.offset().left + $layero.width()
  668. }, 200, function() {
  669. layer.close(index);
  670. });
  671. })
  672. form.on('switch(control)', function(data) {
  673. localStorage.setItem("control", this.checked);
  674. window.location.reload();
  675. })
  676. form.on('switch(muilt-tab)', function(data) {
  677. localStorage.setItem("muilt-tab", this.checked);
  678. window.location.reload();
  679. })
  680. form.on('switch(auto-head)', function(data) {
  681. localStorage.setItem("auto-head", this.checked);
  682. pearTheme.changeTheme(window, this.checked);
  683. })
  684. form.on('switch(banner)', function(data) {
  685. localStorage.setItem("theme-banner", this.checked);
  686. pearAdmin.bannerSkin(this.checked);
  687. })
  688. form.on('switch(footer)', function (data) {
  689. localStorage.setItem("footer", this.checked);
  690. pearAdmin.footer(this.checked);
  691. })
  692. if (localStorage.getItem('theme-banner') === 'true') {
  693. $('input[name="banner"]').attr('checked', 'checked')
  694. } else {
  695. $('input[name="banner"]').removeAttr('checked')
  696. }
  697. if (localStorage.getItem('control') === 'true') {
  698. $('input[name="control"]').attr('checked', 'checked')
  699. } else {
  700. $('input[name="control"]').removeAttr('checked')
  701. }
  702. if (localStorage.getItem('muilt-tab') === 'true') {
  703. $('input[name="muilt-tab"]').attr('checked', 'checked')
  704. } else {
  705. $('input[name="muilt-tab"]').removeAttr('checked')
  706. }
  707. if (localStorage.getItem('auto-head') === 'true') {
  708. $('input[name="auto-head"]').attr('checked', 'checked')
  709. } else {
  710. $('input[name="auto-head"]').removeAttr('checked')
  711. }
  712. if (localStorage.getItem('footer') === 'true') {
  713. $('input[name="footer"]').attr('checked', 'checked')
  714. } else {
  715. $('input[name="footer"]').removeAttr('checked')
  716. }
  717. form.render('checkbox');
  718. }
  719. });
  720. });
  721. body.on('click', '[data-select-bgcolor]', function() {
  722. var theme = $(this).attr('data-select-bgcolor');
  723. $('[data-select-bgcolor]').removeClass("layui-this");
  724. $(this).addClass("layui-this");
  725. localStorage.setItem("theme-menu", theme);
  726. pearAdmin.menuSkin(theme);
  727. });
  728. body.on('click', '[data-select-header]', function() {
  729. var theme = $(this).attr('data-select-header');
  730. $('[data-select-header]').removeClass("layui-this");
  731. $(this).addClass("layui-this");
  732. localStorage.setItem("theme-header", theme);
  733. pearAdmin.headerSkin(theme);
  734. });
  735. body.on('click', '.select-color-item', function() {
  736. $(".select-color-item").removeClass("layui-icon").removeClass("layui-icon-ok");
  737. $(this).addClass("layui-icon").addClass("layui-icon-ok");
  738. var colorId = $(".select-color-item.layui-icon-ok").attr("color-id");
  739. var currentColor = getColorById(colorId);
  740. localStorage.setItem("theme-color", currentColor.id);
  741. localStorage.setItem("theme-color-color", currentColor.color);
  742. localStorage.setItem("theme-color-second", currentColor.second);
  743. pearTheme.changeTheme(window, isAutoHead(config));
  744. });
  745. function applyConfig(param) {
  746. config = param;
  747. pearAdmin.menuRender(param);
  748. pearAdmin.bodyRender(param);
  749. pearAdmin.themeRender(param);
  750. pearAdmin.keepLoad(param);
  751. }
  752. function getColorById(id) {
  753. var color;
  754. var flag = false;
  755. $.each(config.colors, function(i, value) {
  756. if (value.id === id) {
  757. color = value;
  758. flag = true;
  759. }
  760. })
  761. if (flag === false || config.theme.allowCustom === false) {
  762. $.each(config.colors, function(i, value) {
  763. if (value.id === config.theme.defaultColor) {
  764. color = value;
  765. }
  766. })
  767. }
  768. return color;
  769. }
  770. function buildColorHtml() {
  771. var colors = "";
  772. $.each(config.colors, function(i, value) {
  773. colors += "<span class='select-color-item' color-id='" + value.id + "' style='background-color:" + value.color +
  774. ";'></span>";
  775. })
  776. return "<div class='select-color'><div class='select-color-title'>主题配色</div><div class='select-color-content'>" +
  777. colors + "</div></div>"
  778. }
  779. function compatible() {
  780. if ($(window).width() <= 768) {
  781. collapse()
  782. }
  783. }
  784. function isControl(option) {
  785. if (option.theme.allowCustom) {
  786. if (localStorage.getItem("control") != null) {
  787. return localStorage.getItem("control")
  788. } else {
  789. return option.menu.control
  790. }
  791. } else {
  792. return option.menu.control
  793. }
  794. }
  795. function isAutoHead(option) {
  796. if (option.theme.allowCustom) {
  797. if (localStorage.getItem("auto-head") != null) {
  798. return localStorage.getItem("auto-head");
  799. } else {
  800. return option.other.autoHead;
  801. }
  802. } else {
  803. return option.other.autoHead;
  804. }
  805. }
  806. function isMuiltTab(option) {
  807. if (option.theme.allowCustom) {
  808. if (localStorage.getItem("muilt-tab") != null) {
  809. return localStorage.getItem("muilt-tab")
  810. } else {
  811. return option.tab.enable
  812. }
  813. } else {
  814. return option.tab.enable
  815. }
  816. }
  817. window.onresize = function() {
  818. if (!fullscreen.isFullscreen()) {
  819. $(".fullScreen").eq(0).removeClass("layui-icon-screen-restore");
  820. }
  821. }
  822. $(window).on('resize', debounce(function () {
  823. if (sideMenu && !sideMenu.isCollapse && $(window).width() <= 768) {
  824. collapse();
  825. }
  826. },50));
  827. function debounce(fn, awaitTime) {
  828. var timerID = null
  829. return function () {
  830. var arg = arguments[0]
  831. if (timerID) {
  832. clearTimeout(timerID)
  833. }
  834. timerID = setTimeout(function () {
  835. fn(arg)
  836. }, awaitTime)
  837. }
  838. }
  839. exports('admin', pearAdmin);
  840. })