Skip to content

Commit 73c8696

Browse files
author
hikki
committed
v3.6
1 parent f615ef6 commit 73c8696

File tree

2 files changed

+62
-23
lines changed

2 files changed

+62
-23
lines changed

resources/assets/component.js

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ window.ComponentDot = class {
315315
}
316316

317317
menuSelect(select){
318-
if(this.limit == 1){
318+
if(this.limit === 1){
319319
this.SELECTED_DOM.innerHTML = `<p class="dlp-text">${select[this.select_data[0]]}</p>`;
320320
return;
321321
}
@@ -878,7 +878,7 @@ window.ComponentLine = class {
878878
case 'select':
879879
let td = document.createElement('td');
880880
td.style = val.style;
881-
td.append(this.menuMake([],val.options,val.options_limit,val.name));
881+
td.append(this.menuMake(column,[],val.options,val.options_limit,val.name));
882882
foot.append(td);
883883
break;
884884
case 'datetime':
@@ -934,6 +934,15 @@ window.ComponentLine = class {
934934
continue;
935935
}
936936
let td = document.createElement('td');
937+
if(columns[column].type === 'select') {
938+
let v = this.DATA[key][column];
939+
if (/^[0-9]+$/.test(v)) {
940+
v = [parseInt(v)];
941+
} else if (Array.isArray(v) === false) {
942+
v = [];
943+
}
944+
value[column] = v;
945+
}
937946
if (value[column]) {
938947
record[column] = value[column];
939948
this.makeTd(td, columns[column], value[column], column);
@@ -1012,14 +1021,6 @@ window.ComponentLine = class {
10121021
let input;
10131022
let DATA = this.DATA;
10141023
let DATA_INPUT = this.DATA_INPUT;
1015-
let input_change = function input_change() {
1016-
let key = input.parentNode.parentNode.getAttribute('data-key');
1017-
let column = input.getAttribute('data-column');
1018-
if (DATA[key]) {
1019-
DATA[key][column] = input.value;
1020-
DATA_INPUT.value = JSON.stringify(DATA);
1021-
}
1022-
};
10231024
switch (settings.type) {
10241025
case 'text':
10251026
td.insertAdjacentHTML('afterbegin', `<p style="display: block;" class="dlp text-white dlp-text" title="${value}">${value}</p>`);
@@ -1030,7 +1031,12 @@ window.ComponentLine = class {
10301031
input.setAttribute('data-column', column);
10311032
input.value = value;
10321033
input.addEventListener('input', () => {
1033-
input_change();
1034+
let key = input.parentNode.parentNode.getAttribute('data-key');
1035+
let column = input.getAttribute('data-column');
1036+
if (DATA[key]) {
1037+
DATA[key][column] = input.value;
1038+
DATA_INPUT.value = JSON.stringify(DATA);
1039+
}
10341040
}, false);
10351041
td.appendChild(input);
10361042
break;
@@ -1053,12 +1059,17 @@ window.ComponentLine = class {
10531059
}
10541060
this.format_settings[column] = format;
10551061
input.addEventListener('blur', () => {
1056-
input_change();
1062+
let key = input.parentNode.parentNode.getAttribute('data-key');
1063+
let column = input.getAttribute('data-column');
1064+
if (DATA[key]) {
1065+
DATA[key][column] = input.value;
1066+
DATA_INPUT.value = JSON.stringify(DATA);
1067+
}
10571068
}, false);
10581069
td.appendChild(input);
10591070
break;
10601071
case 'select':
1061-
td.append(this.menuMake([],settings.options,settings.options_limit,settings.name));
1072+
td.append(this.menuMake(column,value,settings.options,settings.options_limit,settings.name));
10621073
break;
10631074
default:
10641075
td.insertAdjacentHTML('afterbegin', `<p style="display: block;" class="dlp text-white dlp-text" title="${value}">${value}</p>`);
@@ -1104,7 +1115,7 @@ window.ComponentLine = class {
11041115
td.className = 'operate-column';
11051116
}
11061117

1107-
menuMake(selected, select,limit,placeholder){
1118+
menuMake(column,selected, select,limit,placeholder){
11081119
let menu = document.createElement('div');
11091120
menu.className = 'dlp-dot-menu';
11101121

@@ -1125,23 +1136,51 @@ window.ComponentLine = class {
11251136

11261137
let check = _component.check;
11271138
check = check.replace(`width="16" height="16"`,`width="12" height="12"`);
1128-
this.id_line_hash = [];
1129-
let line = 0;
11301139
for (let id in select){
11311140
if(!select.hasOwnProperty(id))continue;
1132-
this.id_line_hash[id] = line;
1133-
line++;
11341141
let option = document.createElement('div');
11351142
option.className = 'option';
11361143
option.setAttribute('data-id',id);
11371144
option.insertAdjacentHTML('afterbegin',`<div class="dlp dlp-text" data-v="${id}">${select[id]}</div><div></div>`);
11381145
option.addEventListener('click', ()=>{
11391146
id = parseInt(id);
1140-
1147+
let data_key = parseInt(menu.parentNode.parentNode.getAttribute('data-key'));
1148+
let selected = this.DATA[data_key][column];
1149+
let index = selected.indexOf(id);
1150+
if(index !== -1){
1151+
/*cancel*/
1152+
selected.splice(index,1);
1153+
option.classList.remove('option-active');
1154+
if(option.lastChild instanceof HTMLElement) option.lastChild.innerHTML = '';
1155+
menuSelect(select,selected,limit);
1156+
this.DATA[data_key][column] = selected;
1157+
if(selected.length === 0)menu_select.firstElementChild.textContent = placeholder;
1158+
return;
1159+
}
1160+
if (limit > 0 && selected.length >= limit) {
1161+
for (let line of list.childNodes){
1162+
if((selected.hasOwnProperty('0')) && line.getAttribute('data-id') === selected[0].toString()) line.click();
1163+
}
1164+
}
1165+
option.classList.add('option-active');
1166+
selected.push(id);
1167+
(option.lastChild instanceof HTMLElement) && option.lastChild.insertAdjacentHTML('afterbegin',check);
1168+
menuSelect(select,selected,limit);
11411169
}, false);
11421170
list.append(option);
11431171
}
11441172

1173+
function menuSelect(select,selected,limit){
1174+
if(limit === 1){
1175+
menu_select.firstElementChild.innerHTML = `<p class="dlp-text">${select[selected[0]]}</p>`;
1176+
return;
1177+
}
1178+
let html = '';
1179+
for(let id of this.select_data){
1180+
html += `<span class="dlp-text" title="${select[id]}">${select[id]}</span>`;
1181+
}
1182+
menu_select.firstElementChild.innerHTML = html;
1183+
}
11451184
menu.append(menu_select);
11461185
search_box.append(input);
11471186
menu_list.append(search_box);

test/index.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,21 +359,21 @@
359359
"31": "AIKA -",
360360
"33": "永井みひな",
361361
"36": "河北彩花"
362-
},[],1,true,'请选择');
362+
},[2],1,true,'请选择');
363363

364364
new ComponentLine("test2", {
365365
"name": {"name": "名称", "type": "input"},
366-
"meta": {"name": "信息", "type": "text","insert_type":"hidden"},
366+
"meta": {"name": "信息", "type": "text","insert_type":"input"},
367367
"url": {"name": "链接", "type": "image"},
368368
"time": {"name": "更新时间", "type": "datetime","insert_type":"datetime"},
369-
"is-small": {"name": "高清[1是 2否]", "type": "select","options":{1:'是',2:'否'},"options_limit":1, "style": "width:60px"}
369+
"is-small": {"name": "高清", "type": "select","options":{1:'是',2:'否'},"options_limit":1, "style": "width:60px"}
370370
}
371371
, [{
372372
"name": "TushyRaw.21.04.28.Penelope.Kay.XXX.SD.MP4-KLEENEX",
373373
"url": "magnet?xt=urnbtih1b771980c465052d1c96eade30be1297e1f73cff&dn=HDouban.comTushyRaw.21.04.28.Penelope.Kay.XXX.SD.MP4-KLEENEX",
374374
"meta": "(246MB,3\u500b\u6587\u4ef6)",
375375
"time": "2021-05-14 00:00:00",
376-
"is-small": 2
376+
"is-small": 1
377377
}, {
378378
"name": "T1080",
379379
"url": "magnet?xt=urnbtih20244eea8bafa94c27699ada817638f0a01fdbea&dn=HDouban.comTushyRaw.21.04.28.Penelope.Kay.XXX.1080p.MP4-NBQrarbg",

0 commit comments

Comments
 (0)