feat(core): 优化nav右侧菜单栏
This commit is contained in:
@@ -443,7 +443,7 @@ class App extends Component {
|
|||||||
|
|
||||||
this.#nav_.register({
|
this.#nav_.register({
|
||||||
id: 'file',
|
id: 'file',
|
||||||
displayText: `${Msg.Lang['nav.btn.file']}(F)`,
|
displayText: Msg.Lang['nav.btn.file'],
|
||||||
scopeType: Nav.Scope.RIGHT,
|
scopeType: Nav.Scope.RIGHT,
|
||||||
weight: 1,
|
weight: 1,
|
||||||
menu: fileMenu
|
menu: fileMenu
|
||||||
@@ -451,7 +451,7 @@ class App extends Component {
|
|||||||
|
|
||||||
this.#nav_.register({
|
this.#nav_.register({
|
||||||
id: 'setting',
|
id: 'setting',
|
||||||
displayText: `${Msg.Lang['nav.btn.setting']}(S)`,
|
displayText: Msg.Lang['nav.btn.setting'],
|
||||||
scopeType: Nav.Scope.RIGHT,
|
scopeType: Nav.Scope.RIGHT,
|
||||||
weight: 2,
|
weight: 2,
|
||||||
menu: settingMenu
|
menu: settingMenu
|
||||||
|
|||||||
@@ -1,16 +1,21 @@
|
|||||||
goog.loadJs('common', () => {
|
goog.loadJs('common', () => {
|
||||||
|
|
||||||
|
goog.require('path');
|
||||||
goog.require('tippy');
|
goog.require('tippy');
|
||||||
|
goog.require('Mixly.Env');
|
||||||
goog.require('Mixly.Menu');
|
goog.require('Mixly.Menu');
|
||||||
goog.require('Mixly.Registry');
|
goog.require('Mixly.Registry');
|
||||||
|
goog.require('Mixly.HTMLTemplate');
|
||||||
goog.require('Mixly.IdGenerator');
|
goog.require('Mixly.IdGenerator');
|
||||||
goog.require('Mixly.ContextMenu');
|
goog.require('Mixly.ContextMenu');
|
||||||
goog.require('Mixly.DropdownMenu');
|
goog.require('Mixly.DropdownMenu');
|
||||||
goog.provide('Mixly.DropdownMenuGroup');
|
goog.provide('Mixly.DropdownMenuGroup');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
|
Env,
|
||||||
Menu,
|
Menu,
|
||||||
Registry,
|
Registry,
|
||||||
|
HTMLTemplate,
|
||||||
IdGenerator,
|
IdGenerator,
|
||||||
ContextMenu,
|
ContextMenu,
|
||||||
DropdownMenu
|
DropdownMenu
|
||||||
@@ -18,6 +23,13 @@ const {
|
|||||||
|
|
||||||
|
|
||||||
class DropdownMenuGroup {
|
class DropdownMenuGroup {
|
||||||
|
static {
|
||||||
|
HTMLTemplate.add(
|
||||||
|
'html/dropdown-menu-item.html',
|
||||||
|
new HTMLTemplate(goog.readFileSync(path.join(Env.templatePath, 'html/dropdown-menu-item.html')))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#singleton_ = null;
|
#singleton_ = null;
|
||||||
#menuItems_ = [];
|
#menuItems_ = [];
|
||||||
#ids_ = {};
|
#ids_ = {};
|
||||||
@@ -85,9 +97,12 @@ class DropdownMenuGroup {
|
|||||||
item.weight = 0;
|
item.weight = 0;
|
||||||
}
|
}
|
||||||
this.remove(item.id);
|
this.remove(item.id);
|
||||||
item.$elem = $(`<button class="layui-btn layui-btn-xs layui-btn-primary mixly-nav">${item.displayText}</button>`);
|
item.$elem = $(HTMLTemplate.get('html/dropdown-menu-item.html').render({
|
||||||
|
text: item.displayText
|
||||||
|
}));
|
||||||
const instance = tippy(item.$elem[0]);
|
const instance = tippy(item.$elem[0]);
|
||||||
item.$elem.attr('data-id', instance.id);
|
item.$elem.attr('data-id', instance.id);
|
||||||
|
item.$i = item.$elem.children('i');
|
||||||
item.instance = instance;
|
item.instance = instance;
|
||||||
const contextMenuId = IdGenerator.generate();
|
const contextMenuId = IdGenerator.generate();
|
||||||
const selector = `body > .mixly-dropdown-menus > div[m-id="${contextMenuId}"]`;
|
const selector = `body > .mixly-dropdown-menus > div[m-id="${contextMenuId}"]`;
|
||||||
@@ -103,10 +118,12 @@ class DropdownMenuGroup {
|
|||||||
},
|
},
|
||||||
events: {
|
events: {
|
||||||
show: (opt) => {
|
show: (opt) => {
|
||||||
|
item.$i.addClass('menu-shown');
|
||||||
this.#menuShown_ = true;
|
this.#menuShown_ = true;
|
||||||
this.#singleton_.setProps({});
|
this.#singleton_.setProps({});
|
||||||
},
|
},
|
||||||
hide: (opt) => {
|
hide: (opt) => {
|
||||||
|
item.$i.removeClass('menu-shown');
|
||||||
if (this.#trigged_) {
|
if (this.#trigged_) {
|
||||||
this.#trigged_ = false;
|
this.#trigged_ = false;
|
||||||
return true;
|
return true;
|
||||||
@@ -155,6 +172,10 @@ class DropdownMenuGroup {
|
|||||||
return this.#ids_[id].contextMenu;
|
return this.#ids_[id].contextMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
getInstance() {
|
||||||
|
return this.#singleton_;
|
||||||
|
}
|
||||||
|
|
||||||
remove(id) {
|
remove(id) {
|
||||||
let item = this.#ids_[id];
|
let item = this.#ids_[id];
|
||||||
if (!item) {
|
if (!item) {
|
||||||
|
|||||||
@@ -189,9 +189,12 @@
|
|||||||
{
|
{
|
||||||
"path": "/common/dropdown-menu-group.js",
|
"path": "/common/dropdown-menu-group.js",
|
||||||
"require": [
|
"require": [
|
||||||
|
"path",
|
||||||
"tippy",
|
"tippy",
|
||||||
|
"Mixly.Env",
|
||||||
"Mixly.Menu",
|
"Mixly.Menu",
|
||||||
"Mixly.Registry",
|
"Mixly.Registry",
|
||||||
|
"Mixly.HTMLTemplate",
|
||||||
"Mixly.IdGenerator",
|
"Mixly.IdGenerator",
|
||||||
"Mixly.ContextMenu",
|
"Mixly.ContextMenu",
|
||||||
"Mixly.DropdownMenu"
|
"Mixly.DropdownMenu"
|
||||||
|
|||||||
14
common/templates/html/dropdown-menu-item.html
Normal file
14
common/templates/html/dropdown-menu-item.html
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<style>
|
||||||
|
button[m-id="{{d.mId}}"] > i {
|
||||||
|
margin-left: 2px;
|
||||||
|
-webkit-transition: all .2s;
|
||||||
|
}
|
||||||
|
|
||||||
|
button[m-id="{{d.mId}}"] > i.menu-shown {
|
||||||
|
transform: rotate(180deg);
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
<button m-id="{{d.mId}}" class="mixly-nav layui-btn layui-btn-xs layui-btn-primary">
|
||||||
|
{{d.text}}
|
||||||
|
<i class="layui-icon layui-icon-down"></i>
|
||||||
|
</button>
|
||||||
Reference in New Issue
Block a user