Skip to content

Commit 6535d84

Browse files
author
hikki
committed
右键菜单
1 parent fd9b39e commit 6535d84

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

resources/assets/component.js

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@ type="rotate"from="0 20 20"to="360 20 20"dur="0.5s"repeatCount="indefinite"/></p
5959
div.innerHTML = message;
6060
let w = window.innerWidth / 2 - 140;
6161
let h = window.innerHeight / 2 - 145;
62-
div.style = "z-index: 1000000; position: fixed;background-color: rgba(0,0,0,.6);color: #fff;" +
62+
let style = "z-index: 1000000; position: fixed;background-color: rgba(0,0,0,.6);color: #fff;" +
6363
"width: 280px;height: 45px;line-height: 40px;border-radius: 3px;text-align: center;" +
6464
"top:" + h + "px;left:" + w + "px;";
65+
div.setAttribute('style',style);
6566
document.getElementsByTagName("BODY")[0].appendChild(div);
66-
var task = setTimeout(function () {
67+
let task = setTimeout(function () {
6768
clearTimeout(task);
6869
div.parentNode.removeChild(div);
6970
if (typeof callback === 'function') callback();
@@ -75,20 +76,21 @@ type="rotate"from="0 20 20"to="360 20 20"dur="0.5s"repeatCount="indefinite"/></p
7576
}, options);
7677
let ul = document.createElement('ul');
7778
ul.className = 'dlp dlp-contextmenu';
78-
for (let k in list) {
79+
list.forEach((v)=>{
7980
let li = document.createElement('li');
8081
li.className = 'dlp dlp-text';
81-
li.textContent = k;
82+
li.textContent = v.title;
8283
li.style.width = options.W;
83-
if (typeof list[k] === 'function') {
84+
if (typeof v.func === 'function') {
8485
li.addEventListener('click', () => {
85-
list[k]();
86+
v.func();
8687
ul.remove();
8788
});
8889
ul.append(li);
8990
}
90-
}
91-
ul.style = `top: ${event.pageY - 3}px;left: ${event.pageX - 3}px;`;
91+
});
92+
ul.style.top = `${event.pageY - 3}px`;
93+
ul.style.left = `${event.pageX - 3}px`;
9294
ul.addEventListener('mouseleave', () => {
9395
ul.remove();
9496
});
@@ -153,8 +155,8 @@ class ComponentDot {
153155
let html = `<div class="dlp-dot" ><div class="dot-top"><input type="text" class="dlp dot-search" placeholder="搜索名称"><div class="dot-selected dlp-scroll">${selected_dom}</div></div><div class="dot-body"><div class="dot-select dlp-scroll">${select_dom}</div></div></div>
154156
<input name="${this.name}[select]" value='${JSON.stringify(selected)}' type="hidden"><input name="${this.name}[insert]" value="[]" type="hidden"><input name="${this.name}[delete]" value="[]" type="hidden">`;
155157
this.DOM.insertAdjacentHTML('afterbegin', html);
156-
this.SELECTED_DOM = document.querySelector(`#${this.name} .dot-selected`);
157-
this.CONTENT_DOM = document.querySelector(`#${this.name} .dot-select`);
158+
this.SELECTED_DOM = document.querySelector(`#${this.name} .dot-selected`);
159+
this.CONTENT_DOM = document.querySelector(`#${this.name} .dot-select`);
158160
this.selectInputDOM = document.querySelector(`input[name='${this.name}[select]']`);
159161
this.insertInputDOM = document.querySelector(`input[name='${this.name}[insert]']`);
160162
this.deleteInputDOM = document.querySelector(`input[name='${this.name}[delete]']`);
@@ -316,16 +318,16 @@ class ComponentCascadeDot {
316318
div.addEventListener("contextmenu", (e) => {
317319
e.preventDefault();
318320
let k = parseInt(div.getAttribute('data-k'));
319-
_component.contextmenu(e, {
320-
'全选': () => {
321+
_component.contextmenu(e, [
322+
{title:'全选',func: () => {
321323
object.checkAll(stack + 1,
322324
this.dimensional_data[stack][k].nodes,true);
323-
},
324-
'取消': () => {
325+
}},
326+
{title:'取消',func: () => {
325327
object.checkAll(stack + 1,
326328
this.dimensional_data[stack][k].nodes,false);
327-
}
328-
});
329+
}}
330+
]);
329331
});
330332
}else {
331333
div.addEventListener("contextmenu", (e) => {
@@ -872,7 +874,7 @@ class ComponentPlane {
872874
}
873875

874876
makeModal() {
875-
let html = `<div id="dlp-plane" class="dlp-plane-gauze"><div style="width: ${window.innerWidth * this.OPTIONS.W}px;"><div class="dlp plane-header"></div><div class="plane-body dlp-scroll" style="max-height:${window.innerHeight * this.OPTIONS.H}px;min-height:${window.innerHeight * this.OPTIONS.H / 2}px;"></div></div></div>`;
877+
let html = `<div id="dlp-plane" class="dlp-plane-gauze"><div style="width: ${window.innerWidth * this.OPTIONS.W}px;"><div class="dlp plane-header"></div><div class="plane-body dlp-scroll" style="max-height:${window.innerHeight * this.OPTIONS.H + 'px'};min-height:${window.innerHeight * this.OPTIONS.H / 2 + 'px'};"></div></div></div>`;
876878
document.body.insertAdjacentHTML('beforeEnd', html);
877879
this.DOM = document.getElementById('dlp-plane');
878880
/*X*/
@@ -937,7 +939,8 @@ class ComponentPlane {
937939
return;
938940
}
939941
this.LOADING_DOM = document.createElement('div');
940-
this.LOADING_DOM.style = 'width: 100%;height: 100px;';
942+
this.LOADING_DOM.style.width = '100%';
943+
this.LOADING_DOM.style.height = '100px';
941944
this.LOADING_DOM.insertAdjacentHTML('afterbegin', _component.loading);
942945
this.MODEL_BODY_DOM.append(this.LOADING_DOM);
943946
}
@@ -993,10 +996,10 @@ class ComponentSortable {
993996

994997
this.items.forEach((item, index) => {
995998
item.style.position = 'absolute';
996-
item.style.top = 0;
997-
item.style.left = 0;
999+
item.style.top = '0';
1000+
item.style.left = '0';
9981001
item.style.transform = `translateY(${offsetsTop[index]}px)`;
999-
item.style.zIndex = (item === this.item) ? 2 : 1;
1002+
item.style.zIndex = (item === this.item) ? '2' : '1';
10001003
});
10011004

10021005
this.positions = this.items.map((item, index) => index);
@@ -1058,7 +1061,7 @@ class ComponentSortable {
10581061
this.animation = false;
10591062
}, this.options.animationSpeed);
10601063

1061-
window.removeEventListener((this.touch ? 'touchmove' : 'mousemove'), this.dragMove, {passive: false});
1064+
window.removeEventListener((this.touch ? 'touchmove' : 'mousemove'), this.dragMove);
10621065
window.removeEventListener((this.touch ? 'touchend' : 'mouseup'), this.dragEnd, false);
10631066
}
10641067

0 commit comments

Comments
 (0)