支持复制常驻留言

This commit is contained in:
2022-08-22 11:07:52 +08:00
parent d897e9a33d
commit 4ef6a822c1
7 changed files with 127 additions and 21 deletions

View File

@ -0,0 +1,30 @@
import PickleComplate from "../vendor/picomplete/picomplete";
(function () {
const id_input = document.getElementById("broadcast_id")
const pickle_config = {
target: '#broadcast_select',
suggest: ["alias", "abbr"],
clickCallback: (target, node) => {
target.value = node.text;
id_input.value = node.value;
}
};
let local_data_string = window.localStorage.getItem("append_broadcast_list");
if (!local_data_string) {
return fetch("/programs/construct/append/broadcast_list", {
"method": "GET",
}).then((response) => response.json()).then((data) => {
window.localStorage.setItem("append_broadcast_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

@ -118,8 +118,8 @@ export default class PickleComplate {
}
containsSuggest(item, value) {
if (item.text.toLowerCase().includes(value.toLowerCase()) ||
item.value.toLowerCase().includes(value.toLowerCase())) {
if (item.text.toString().toLowerCase().includes(value.toLowerCase()) ||
item.value.toString().toLowerCase().includes(value.toLowerCase())) {
return true;
}
if (this.config.suggest) {
@ -127,7 +127,7 @@ export default class PickleComplate {
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())) {
if (item.hasOwnProperty(suggest_key) && item[suggest_key].toString().toLowerCase().includes(value.toLowerCase())) {
return true;
}
}