食谱制作页面的快捷列表关键字搜索

This commit is contained in:
xiezhijun
2021-06-17 18:42:17 +08:00
parent a731b57bdc
commit 1951e18871
10 changed files with 137 additions and 7 deletions

View File

@ -1,8 +1,19 @@
export function getShortCut() {
export function getShortCut(key) {
return new Promise((res, rej) => {
try {
const data = JSON.parse(localStorage.getItem("shortCut") || "[]");
res(data);
//关键字检索
if(key != undefined && key != null && key != ""){
const resultData = [];
data.forEach((item,index) => {
if(item.name.indexOf(key) != -1 || (item.className != undefined && item.className != null && item.className.indexOf(key) != -1)){
resultData.push(item);
}
});
res(resultData);
}else{
res(data);
}
} catch (error) {
rej(error);
}
@ -35,6 +46,19 @@ export async function removeShortCut(id) {
});
}
export async function removeMuchShortCut(ids) {
const shortCutList = await getShortCut();
return new Promise((res, rej) => {
try {
const newShortCutList = shortCutList.filter(obj => ids.indexOf(obj.id) == -1);
localStorage.setItem("shortCut", JSON.stringify(newShortCutList));
res();
} catch (error) {
rej(error);
}
});
}
export async function editShortCut(data) {
const shortCutList = await getShortCut();
return new Promise((res, rej) => {