修复插件配置问题

This commit is contained in:
2022-08-17 12:56:26 +08:00
parent 6632d8cea1
commit 916507d7f2
5 changed files with 205 additions and 26 deletions

View File

@ -1,19 +1,28 @@
import PickleComplate from "../vendor/picomplete/picomplete";
(function () {
new PickleComplate({
request: {
url: '/programs/construct/append/from_list?',
type: 'GET',
value: 'from',
text: 'from',
},
config: {
type: 'server',
target: '#from_select',
clickCallback: (target, node) => {
target.value = node.value;
},
},
})
const pickle_config = {
target: '#from_select',
suggest: ["alias", "abbr"],
clickCallback: (target, node) => {
target.value = node.value;
}
};
let local_data_string = window.localStorage.getItem("append_from_list");
if (!local_data_string) {
return fetch("/programs/construct/append/from_list", {
"method": "GET",
}).then((response) => response.json()).then((data) => {
window.localStorage.setItem("append_from_list", JSON.stringify(data));
new PickleComplate({
data: data,
config: pickle_config,
})
});
} else {
new PickleComplate({
data: JSON.parse(local_data_string),
config: pickle_config,
})
}
})()

View File

@ -96,7 +96,7 @@ export default class PickleComplate {
this.sug_div = document.createElement('DIV');
this.sug_div.classList.add('picomplete-items');
for (let i = 0; i < this.container.length; i++) {
if (this.container[i].text.toLowerCase().includes(el.value.toLowerCase()) || this.container[i].value.toLowerCase().includes(el.value.toLowerCase())) {
if (this.containsSuggest(this.container[i], el.value)) {
//create list item
let item = document.createElement('DIV');
//set class
@ -117,6 +117,23 @@ export default class PickleComplate {
if(this.sug_div !== null) this.element.parentNode.appendChild(this.sug_div);
}
containsSuggest(item, value) {
if (item.text.toLowerCase().includes(value.toLowerCase()) ||
item.value.toLowerCase().includes(value.toLowerCase())) {
return true;
}
if (this.config.suggest) {
if (typeof this.config.suggest === "string") {
this.config.suggest = [this.config.suggest]
}
for (const suggest_key of this.config.suggest) {
if (item.hasOwnProperty(suggest_key) && item[suggest_key].toLowerCase().includes(value.toLowerCase())) {
return true;
}
}
}
}
/**