测试环境链接替换,部分问题修复,增加批量退菜功能

This commit is contained in:
2026-07-07 15:26:08 +08:00
parent b93429ed99
commit c001f982b4
29 changed files with 1975 additions and 349 deletions

View File

@@ -1434,28 +1434,95 @@
searchResult.value = returnSearchGoods();
}
function returnSearchGoods() {
const newval = searchValue.value;
let arr = [];
let goods = [];
for (let i in data.tabbar) {
const goodsArr = data.tabbar[i].foods || [];
for (let k in goodsArr) {
goods.push({
...goodsArr[k],
index: i,
goodsIndex: k,
});
}
}
if (newval == "") {
arr = goods;
} else {
arr = goods.filter((v) => v.name.includes(newval.trim()));
}
return arr;
// function returnSearchGoods() {
// const newval = searchValue.value;
// let arr = [];
// let goods = [];
// for (let i in data.tabbar) {
// const goodsArr = data.tabbar[i].foods || [];
// for (let k in goodsArr) {
// goods.push({
// ...goodsArr[k],
// index: i,
// goodsIndex: k,
// });
// }
// }
// if (newval == "") {
// arr = goods;
// } else {
// arr = goods.filter((v) => v.name.includes(newval.trim()));
// }
// return arr;
// }
// ===========================
// 🔥 通用汉字转拼音首字母(无依赖、全汉字支持)
// ===========================
function getFirstLetter(str) {
if (!str) return '';
let result = '';
for (let i = 0; i < str.length; i++) {
const char = str[i];
// 核心:利用 localeCompare 排序特性获取拼音首字母(通用、标准、永不失效)
const letters = 'abcdefghjklmnopqrstwxyz';
let match = '';
for (let j = 0; j < letters.length; j++) {
const l = letters[j];
if (char.localeCompare(l, 'zh-CN') === 0) {
match = l;
break;
}
}
if (match) {
result += match;
} else if (/[\u4e00-\u9fa5]/.test(char)) {
// 中文处理
const charCode = char.charCodeAt(0);
if (charCode >= 0x4E00 && charCode <= 0x9FA5) {
const index = Math.floor((charCode - 0x4E00) / 0x320);
const letter = 'abcdefghjklmnopqrstwxyz'[Math.min(index, 23)];
result += letter || '';
}
} else {
// 英文数字符号
result += char.toLowerCase();
}
}
return result;
}
// ===========================
// 你的搜索函数(直接用)
// ===========================
function returnSearchGoods() {
const newval = searchValue.value;
let goods = [];
for (let i in data.tabbar) {
const goodsArr = data.tabbar[i].foods || [];
for (let k in goodsArr) {
goods.push({
...goodsArr[k],
index: i,
goodsIndex: k,
});
}
}
if (!newval.trim()) {
return goods;
}
const keyword = newval.trim().toLowerCase();
return goods.filter(item => {
const name = item.name || '';
const pinyin = getFirstLetter(name);
console.log(name, '→', pinyin);
return name.toLowerCase().includes(keyword) || pinyin.includes(keyword);
});
}
function clearSearch() {
isSearch.value = false;
}