Skip to content

Commit 23beab9

Browse files
author
hikki
committed
8
1 parent 1fb3f9a commit 23beab9

File tree

2 files changed

+89
-28
lines changed

2 files changed

+89
-28
lines changed

resources/assets/component.css

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@
8484
font: inherit;
8585
align-items: center;
8686
}
87-
.dlp-button,.dlp-button-red,.dlp-button-green,.dlp-button-blue,.dlp-button-yellow{
87+
.dlp-button,.dlp-button-red,.dlp-button-green,.dlp-button-blue,.dlp-button-yellow,
88+
.dlp-button-active,.dlp-button-red-active,.dlp-button-green-active,.dlp-button-blue-active,.dlp-button-yellow-active{
8889
background: linear-gradient(180deg,#303030 0,#585858 49%,#000 59%,#3e3e3e 100%);
8990
border: solid 1px #262626;
9091
box-shadow: inset 0 3px 9px #232323, inset 0 3px 12px #323232, inset 0 15px 9px #4a4a4a, inset 0 3px 3px 0 #8b8b8b, 0 1px 3px rgb(16 16 16 / 66%);
@@ -101,11 +102,11 @@
101102
.dlp-button:hover{
102103
background: linear-gradient(180deg,#222222 0,#444 49%,#242424 59%,#3e3e3e 100%);
103104
}
104-
.dlp-button:disabled{
105+
.dlp-button:disabled,.dlp-button-active{
105106
cursor: not-allowed;
106107
background: #545454;
107108
border: solid 1px #262626;
108-
box-shadow: inset 0 2px 5px #141414, inset -2px 0 3px #444444, 0 0 3px #141414;
109+
box-shadow: inset 0 2px 5px #141414, inset -2px 0 3px #444444;
109110
color: #ccc;
110111
}
111112
.dlp-button-red{
@@ -116,11 +117,11 @@
116117
.dlp-button-red:hover{
117118
background: linear-gradient(180deg,#b70a0a 0,#b91d1d 49%,#870d0d 80%,#9f0000 100%);
118119
}
119-
.dlp-button-red:disabled{
120+
.dlp-button-red:disabled,.dlp-button-red-active{
120121
cursor: not-allowed;
121122
background: #b32a2a;
122123
border: solid 1px #262626;
123-
box-shadow: inset 0 2px 5px #3e0303, inset 0 0 3px #320202, 0 0 3px #a70000;
124+
box-shadow: inset 0 2px 5px #3e0303, inset 0 0 3px #320202;
124125
color: #ccc;
125126
}
126127
.dlp-button-green{
@@ -131,11 +132,11 @@
131132
.dlp-button-green:hover{
132133
background: linear-gradient(180deg,#20942b 0,#2ec33c 49%,#0a9517 59%,#017e0d 100%);
133134
}
134-
.dlp-button-green:disabled{
135+
.dlp-button-green:disabled,.dlp-button-green-active{
135136
cursor: not-allowed;
136137
background: #00c57c;
137138
border: solid 1px #006641;
138-
box-shadow: inset 0 2px 5px #006a39, inset 0 0 3px #006235, 0 0 3px #00fdc2;
139+
box-shadow: inset 0 2px 5px #006a39, inset 0 0 3px #006235;
139140
color: #f1f1f1;
140141
}
141142
.dlp-button-blue{
@@ -146,11 +147,11 @@
146147
.dlp-button-blue:hover{
147148
background: linear-gradient(180deg,#091f98 0,#2e32b7 49%,#3133bb 100%);
148149
}
149-
.dlp-button-blue:disabled{
150+
.dlp-button-blue:disabled,.dlp-button-blue-active{
150151
cursor: not-allowed;
151152
background: #1b7adb;
152153
border: solid 1px #006641;
153-
box-shadow: inset 0 2px 5px #00036a, inset 0 0 3px #0300b5, 0 0 3px #636fff;
154+
box-shadow: inset 0 2px 5px #00036a, inset 0 0 3px #0300b5;
154155
color: #dfdfdf;
155156
}
156157
.dlp-button-yellow{
@@ -162,13 +163,14 @@
162163
.dlp-button-yellow:hover{
163164
background: linear-gradient(180deg,#fff74c 0,#e1ed25 49%,#edff00 100%);
164165
}
165-
.dlp-button-yellow:disabled{
166+
.dlp-button-yellow:disabled,.dlp-button-yellow-active{
166167
cursor: not-allowed;
167168
background: #efff01;
168-
box-shadow: inset 0 2px 5px #cbd70f, inset 0 0 3px #d6ef0a, 0 0 3px #fff938;
169+
box-shadow: inset 0 2px 5px #cbd70f, inset 0 0 3px #d6ef0a;
169170
color: #b1b4fb;
170171
border: 1px solid #d3e100;
171172
}
173+
.dlp-button-active,.dlp-button-red-active,.dlp-button-green-active,.dlp-button-blue-active,.dlp-button-yellow-active{cursor: pointer}
172174
.dlp-alert{
173175
z-index: 1000000;
174176
background-color: rgba(0, 0, 0, 0.6);

resources/assets/component.js

Lines changed: 76 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ window.ComponentDot = class {
357357
};
358358

359359
this._search = function (search) {
360-
if (this._modSettings.mode) {
360+
if (this._modSettings.mode === 'menu') {
361361
if (search.value === '') {
362362
for (let node of this.CONTENT_DOM.childNodes) {
363363
node.style.display = 'flex';
@@ -424,17 +424,16 @@ window.ComponentDot = class {
424424
};
425425

426426
this._bind = function () {
427-
setTimeout(() => {
428-
this.CONTENT_DOM.childNodes.forEach((D) => {
429-
let id = D.getAttribute('data-id');
430-
if (this.selected_data.indexOf(id) !== -1) {
431-
this._triggerEvent.enable = false;
432-
D.click();
433-
this._triggerEvent.enable = true;
434-
}
435-
});
436-
if (this._modSettings.mode === true) this.DOM.querySelector('.menu-list').style.display = 'none';
427+
this.CONTENT_DOM.childNodes.forEach((D) => {
428+
let id = D.getAttribute('data-id');
429+
if (this.selected_data.indexOf(id) !== -1) {
430+
this._triggerEvent.enable = false;
431+
D.click();
432+
this._triggerEvent.enable = true;
433+
}
437434
});
435+
if (this._modSettings.mode === 'menu') this.DOM.querySelector('.menu-list').style.display = 'none';
436+
438437
if (this._useSearchMod === false) return;
439438
let search = this.DOM.querySelector(`.dot-search`);
440439
search.addEventListener('input', () => {
@@ -524,6 +523,43 @@ window.ComponentDot = class {
524523
this.CONTENT_DOM = this.DOM.querySelector(`.list`);
525524
};
526525

526+
this._switchMaker = function () {
527+
let select = this.select;
528+
let menu = document.createElement('div');
529+
menu.className = 'dlp-dot-switch';
530+
this.id_line_hash = [];
531+
let line = 0;
532+
for (let id in select) {
533+
if (!select.hasOwnProperty(id)) continue;
534+
this.id_line_hash[id] = line;
535+
line++;
536+
let option = document.createElement('button');
537+
option.setAttribute('data-id', id);
538+
option.className = `dlp-button${this._modSettings.color}`;
539+
option.textContent = select[id];
540+
option.addEventListener('click', () => {
541+
if (this.select_data.indexOf(id) !== -1) {
542+
/*cancel*/
543+
this._tagCal(id, this.MODE.delete);
544+
option.classList.remove(`dlp-button${this._modSettings.color}-active`);
545+
option.classList.add(`dlp-button${this._modSettings.color}`);
546+
return;
547+
}
548+
if (this.limit > 0 && this.select_data.length >= this.limit) {
549+
this._triggerEvent.enable = false;
550+
menu.childNodes[this.id_line_hash[this.select_data[0].toString()]].click();
551+
this._triggerEvent.enable = true;
552+
}
553+
option.classList.remove(`dlp-button${this._modSettings.color}`);
554+
option.classList.add(`dlp-button${this._modSettings.color}-active`);
555+
this._tagCal(id, this.MODE.insert);
556+
}, false);
557+
menu.append(option);
558+
}
559+
this.DOM.append(menu);
560+
this.CONTENT_DOM = menu;
561+
};
562+
527563
return this;
528564
}
529565

@@ -548,16 +584,37 @@ window.ComponentDot = class {
548584
return this;
549585
}
550586

551-
mod(settings = {mode: false, placeholder: '未选择', height: '150px', direction: 'down'}) {
587+
menuMod(settings = {placeholder: '未选择', height: '150px', direction: 'down'}) {
552588
this._modSettings = Object.assign({
553-
mode: false,
554589
placeholder: '未选择',
555590
height: '150px',
556591
direction: 'down'
557592
}, settings);
593+
this._modSettings.mode = 'menu';
594+
return this;
595+
}
596+
597+
switchMod(settings = {cols:0,color:''}){
598+
this._modSettings = Object.assign({
599+
cols: 0,
600+
color:'',
601+
}, settings);
602+
this._modSettings.mode = 'switch';
603+
switch (this._modSettings.color) {
604+
case "red":
605+
case "blue":
606+
case "green":
607+
case "yellow":
608+
this._modSettings.color = '-'+this._modSettings.color;
609+
break;
610+
default:
611+
this._modSettings.color = '';
612+
break;
613+
}
558614
return this;
559615
}
560616

617+
561618
useSearch() {
562619
this._useSearchMod = true;
563620
return this;
@@ -578,8 +635,11 @@ window.ComponentDot = class {
578635
}
579636

580637
make() {
581-
if (this._modSettings.mode === true) {
638+
if (this._modSettings.mode === 'menu') {
582639
this._menuMaker();
640+
}else if(this._modSettings.mode === 'switch'){
641+
this._switchMaker();
642+
this._useSearchMod = false;
583643
} else {
584644
let select = this.select;
585645
let select_dom = '';
@@ -1203,7 +1263,7 @@ window.ComponentLine = class {
12031263
td.append(menu);
12041264
let modSettings = Object.assign({
12051265
placeholder: '未选择',
1206-
height: '120px',
1266+
height: '150px',
12071267
limit: 1,
12081268
useSearch: false
12091269
}, column.options);
@@ -1214,8 +1274,7 @@ window.ComponentLine = class {
12141274
value = [parseInt(value)];
12151275
}
12161276
}
1217-
let dot = new ComponentDot(menu, column.select).selected(value).limitNum(modSettings.limit).mod({
1218-
mode: true,
1277+
let dot = new ComponentDot(menu, column.select).selected(value).limitNum(modSettings.limit).menuMod({
12191278
placeholder: modSettings.placeholder,
12201279
height: modSettings.height
12211280
});

0 commit comments

Comments
 (0)