show_level.js 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. 'use strict';
  2. /**
  3. *
  4. *
  5. * @author Mai
  6. * @date
  7. * @version
  8. */
  9. $.cs_showLevel = function (setting) {
  10. const sortTitle = ['第一层', '第二层', '第三层','第四层', '第五层'];
  11. if (!setting.selector) throw '未指定模块';
  12. if (!setting.levels) {
  13. setting.levels = [
  14. { type: 'sort', count: 5, },
  15. { type: 'last', title: '最底层' },
  16. // { type: 'leafXmj', title: '只显示项目节' },
  17. // { type: 'curMeasure', title: '只显示本期计量' },
  18. ];
  19. }
  20. const initShowLevel = function () {
  21. const obj = $(setting.selector);
  22. const html = [];
  23. html.push('<button class="btn btn-sm btn-light dropdown-toggle text-primary" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">' +
  24. '<i class="fa fa-list-ol"></i> 显示层级</button>');
  25. html.push('<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="showLevelList">');
  26. for (const l of setting.levels) {
  27. if (l.type === 'sort') {
  28. let count = typeof l.count === 'function' ? l.count() : l.count;
  29. count = Math.min(count, 5);
  30. for (let i = 1; i <= count; ++i) {
  31. html.push(`<a class="dropdown-item" name="showLevel" tag="${i}" href="javascript: void(0);">${sortTitle[i-1]}</a>`);
  32. }
  33. } else {
  34. html.push(`<a class="dropdown-item" name="showLevel" tag="${l.type}" href="javascript: void(0);">${l.title}</a>`);
  35. }
  36. }
  37. html.push('</div>');
  38. obj.html(html.join(''));
  39. $('a[name=showLevel]').click(function () {
  40. setTimeout(() => {
  41. const tag = $(this).attr('tag');
  42. showWaitingView();
  43. setting.showLevel(tag);
  44. closeWaitingView();
  45. });
  46. });
  47. };
  48. return { initShowLevel } ;
  49. };