12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- 'use strict';
- /**
- *
- *
- * @author Mai
- * @date
- * @version
- */
- $.cs_showLevel = function (setting) {
- const sortTitle = ['第一层', '第二层', '第三层','第四层', '第五层'];
- if (!setting.selector) throw '未指定模块';
- if (!setting.levels) {
- setting.levels = [
- { type: 'sort', count: 5, },
- { type: 'last', title: '最底层' },
- // { type: 'leafXmj', title: '只显示项目节' },
- // { type: 'curMeasure', title: '只显示本期计量' },
- ];
- }
- const initShowLevel = function () {
- const obj = $(setting.selector);
- const html = [];
- 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">' +
- '<i class="fa fa-list-ol"></i> 显示层级</button>');
- html.push('<div class="dropdown-menu" aria-labelledby="dropdownMenuButton" id="showLevelList">');
- for (const l of setting.levels) {
- if (l.type === 'sort') {
- let count = typeof l.count === 'function' ? l.count() : l.count;
- count = Math.min(count, 5);
- for (let i = 1; i <= l.count; ++i) {
- html.push(`<a class="dropdown-item" name="showLevel" tag="${i}" href="javascript: void(0);">${sortTitle[i-1]}</a>`);
- }
- } else {
- html.push(`<a class="dropdown-item" name="showLevel" tag="${l.type}" href="javascript: void(0);">${l.title}</a>`);
- }
- }
- html.push('</div>');
- obj.html(html.join(''));
- $('a[name=showLevel]').click(function () {
- setTimeout(() => {
- const tag = $(this).attr('tag');
- showWaitingView();
- setting.showLevel(tag);
- closeWaitingView();
- });
- });
- refreshMenuVisible();
- };
- const refreshMenuVisible = function () {
- const showMenu = function (tag, visible) {
- if (visible) $(`[tag=${tag}]`).show();
- if (!visible) $(`[tag=${tag}]`).hide();
- };
- for (const l of setting.levels) {
- if (l.type === 'sort') {
- let visibleCount = typeof l.visible_count === 'function' ? l.visible_count() : l.visible_count;
- for (let i = 1; i <= l.count; ++i) {
- showMenu(i, i <= visibleCount);
- }
- } else {
- const visible = typeof l.visible === 'function' ? l.visible() : l.visible;
- showMenu(l.type, visible);
- }
- }
- };
- return { initShowLevel, refreshMenuVisible } ;
- };
|