index.js 823 B

123456789101112131415161718192021222324252627282930313233343536
  1. require("../css/index.less");
  2. const $ = require('jquery');
  3. require('jquery-templates');
  4. const {api,post,pageMap} = require('./utils.js');
  5. $(function(){
  6. getMenu();
  7. //菜单展开收起
  8. });
  9. function initMenu(data){
  10. //菜单数据填充
  11. $("#menuTmpl").tmpl(data).appendTo(".menu");
  12. //菜单收起展开
  13. $(".list-1").on("click",function(){
  14. $(this).find("ul").slideToggle();
  15. });
  16. $(".list-1 li").on("click",function(e){
  17. e.stopPropagation();
  18. });
  19. //右侧页面切换
  20. $(".page").on("click",function(){
  21. const code = $(this).attr("code");
  22. const url = './'+pageMap[code];
  23. $("#contentIframe").attr("src",url);
  24. });
  25. }
  26. function getMenu(){
  27. post(api.getMenu).then(function(res){
  28. if(res.data.code==='0'){
  29. const data = res.data.data;
  30. initMenu(data.menuWrappers);
  31. }
  32. });
  33. };