|
|
@@ -417,22 +417,36 @@ const fetchCategoriesWithCuisines = async (storeId, keyword = '') => {
|
|
|
});
|
|
|
foodList.value = Array.from(byId.values());
|
|
|
mergeCartIntoFoodList();
|
|
|
+ return true;
|
|
|
} catch (err) {
|
|
|
console.error('获取分类与菜品失败:', err);
|
|
|
+ return false;
|
|
|
}
|
|
|
};
|
|
|
|
|
|
-// 选择分类:切换高亮并滚动右侧到对应分段
|
|
|
+// 选择分类:切换高亮并滚动右侧到对应分段(锚点定位)
|
|
|
const selectCategory = (index) => {
|
|
|
currentCategoryIndex.value = index;
|
|
|
scrollIntoViewId.value = 'section-' + index;
|
|
|
setTimeout(() => { scrollIntoViewId.value = ''; }, 400);
|
|
|
};
|
|
|
|
|
|
-// 搜索:带 keyword 重新请求分类+菜品
|
|
|
-const doSearch = () => {
|
|
|
+// 滚动到指定分段锚点(供搜索后定位用)
|
|
|
+const scrollToSection = (index) => {
|
|
|
+ currentCategoryIndex.value = index;
|
|
|
+ scrollIntoViewId.value = 'section-' + index;
|
|
|
+ setTimeout(() => { scrollIntoViewId.value = ''; }, 400);
|
|
|
+};
|
|
|
+
|
|
|
+// 搜索:带 keyword 重新请求分类+菜品,结果根据锚点定位到第一个分段
|
|
|
+const doSearch = async () => {
|
|
|
const storeId = uni.getStorageSync('currentStoreId') || '';
|
|
|
- if (storeId) fetchCategoriesWithCuisines(storeId, searchKeyword.value?.trim() ?? '');
|
|
|
+ if (!storeId) return;
|
|
|
+ const keyword = searchKeyword.value?.trim() ?? '';
|
|
|
+ const ok = await fetchCategoriesWithCuisines(storeId, keyword);
|
|
|
+ if (ok) {
|
|
|
+ nextTick(() => scrollToSection(0));
|
|
|
+ }
|
|
|
};
|
|
|
|
|
|
// 根据展示项(可能来自接口 cuisineId 或 foodList 的 id)找到 foodList 中的菜品
|