◆42Lab是非盈利性、非官方的云图计划维基百科。 ◆诚邀指挥官们加入编辑部共同建设wiki。点这里加入42Lab ◆如果您发现某些内容错误/空缺,请勇于修正/添加!参与进来其实很容易! ◆有任何意见、建议、纠错,欢迎在任意评论区评论 ◆编辑讨论QQ群741423564 微博@GFwiki少前百科 欢迎您 |
“Widget:EnemyQuery”的版本间的差异
来自42LAB
(移除多余的全选键状态) |
|||
(未显示同一用户的3个中间版本) | |||
第365行: | 第365行: | ||
var inputText = document.getElementById("inputQuery") //文本框定义 | var inputText = document.getElementById("inputQuery") //文本框定义 | ||
var sortList = window.EnemyData; // 初始化敌方数据 | var sortList = window.EnemyData; // 初始化敌方数据 | ||
+ | const chipSets = $('.chip-set'); | ||
+ | const filterGroups = []; | ||
+ | for (const chipSet of chipSets) { | ||
+ | const filterGroup = { | ||
+ | field: chipSet.dataset.field, | ||
+ | type: chipSet.dataset.type, | ||
+ | chipSet: $(chipSet).children('.chip'), | ||
+ | filterFunc(query) { | ||
+ | const check = new Map(); | ||
+ | let n = 0; | ||
+ | for (const chip of this.chipSet) { | ||
+ | const value = chip.dataset.value; | ||
+ | check.set(value, chip.classList.contains('chip-checked')); | ||
+ | if (check.get(value)) n++; | ||
+ | } | ||
+ | if (n === 0) return true; | ||
+ | if (this.type == 'exist') { | ||
+ | return query[this.field] !== undefined; | ||
+ | } | ||
+ | if (this.type == 'contain') { | ||
+ | const values = query[this.field]?.split(this.separator) || []; | ||
+ | for (const value of values) { | ||
+ | if (check.get(value)) return true; | ||
+ | } | ||
+ | } | ||
+ | return check.get(query[this.field]); | ||
+ | } | ||
+ | }; | ||
+ | if (chipSet.dataset.type == 'contain') { | ||
+ | filterGroup.separator = chipSet.dataset.separator; | ||
+ | } | ||
+ | filterGroups.push(filterGroup); | ||
+ | } | ||
var emptydiv = "\<div class='' id=\"tableempty\"\>无结果\<\/div\>"; //无结果label | var emptydiv = "\<div class='' id=\"tableempty\"\>无结果\<\/div\>"; //无结果label | ||
第523行: | 第556行: | ||
const t = e.currentTarget; | const t = e.currentTarget; | ||
const line = t.parentElement.querySelectorAll('.filter_item'); | const line = t.parentElement.querySelectorAll('.filter_item'); | ||
− | + | for (const i of line) { | |
− | + | i.checked = false; | |
− | + | i.classList.remove('chip-checked'); | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
− | |||
apply_filter(); | apply_filter(); | ||
} | } | ||
第546行: | 第569行: | ||
t.checked = !t.checked; | t.checked = !t.checked; | ||
apply_filter(); | apply_filter(); | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
} | } | ||
第625行: | 第637行: | ||
for (let i = 0; i < types.length; i++) { | for (let i = 0; i < types.length; i++) { | ||
tCheck[types[i]] = document.getElementById('type_'+types[i]).checked; | tCheck[types[i]] = document.getElementById('type_'+types[i]).checked; | ||
− | if (tCheck[types[i]] | + | if (tCheck[types[i]]) {nt++} |
} | } | ||
if (nt == 0){return true} | if (nt == 0){return true} | ||
else { | else { | ||
− | if(tCheck[typeTrans[query.type]]){return true} else {return false} | + | if(tCheck[typeTrans[query.type]||'other']){return true} else {return false} |
} | } | ||
} | } | ||
− | function filter_box(cond){ | + | function filter_box(cond) { |
− | + | return filterGroups.every(filterGroup => filterGroup.filterFunc(cond)); | |
} | } | ||