diff --git a/env/.env.development b/env/.env.development index 4d56587..2f44a5a 100644 --- a/env/.env.development +++ b/env/.env.development @@ -5,7 +5,7 @@ VITE_DELETE_CONSOLE=false #本地环境 #VITE_SERVER_BASEURL=http://liuyao.nat100.top/meiguowaimai -VITE_SERVER_BASEURL=http://192.168.5.4:8080 -#VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api +#VITE_SERVER_BASEURL=http://192.168.5.4:8080 +VITE_SERVER_BASEURL=https://howhowfresh.com/prod-api #VITE_SERVER_BASEURL=http://192.168.1.8:8811 #VITE_SERVER_BASEURL=http://mifengchuantou.natapp1.cc/meiguowaimai diff --git a/src/locale/en.json b/src/locale/en.json index adf30f8..38e305f 100644 --- a/src/locale/en.json +++ b/src/locale/en.json @@ -134,7 +134,9 @@ "overview": "Overview", "tipsDesc": "They help customers choose what to order.To add photos,go to items and choose menu item", "tipsTitle": "Photos of menu items can increase sales", - "title": "Items" + "title": "Items", + "pickerNoMenu": "No menu data available", + "pickerSelectValidMenu": "Please select a valid menu item" }, "mine": { "complaintsSuggestions": "Complaints And Suggestions", diff --git a/src/locale/zh-Hans.json b/src/locale/zh-Hans.json index 248a756..476d349 100644 --- a/src/locale/zh-Hans.json +++ b/src/locale/zh-Hans.json @@ -134,7 +134,9 @@ "overview": "总览", "tipsDesc": "他们帮助顾客选择要点什么。要添加照片,请转到项目并选择菜单项", "tipsTitle": "菜单上的照片可以增加销量", - "title": "菜品" + "title": "菜品", + "pickerNoMenu": "暂无菜单数据", + "pickerSelectValidMenu": "请在有效选项上选择菜单" }, "mine": { "complaintsSuggestions": "投诉建议", diff --git a/src/pages/home/components/tabbar-menu/components/menu-swiper-list/menu-swiper-list.vue b/src/pages/home/components/tabbar-menu/components/menu-swiper-list/menu-swiper-list.vue index 2953c3e..6b72ae3 100644 --- a/src/pages/home/components/tabbar-menu/components/menu-swiper-list/menu-swiper-list.vue +++ b/src/pages/home/components/tabbar-menu/components/menu-swiper-list/menu-swiper-list.vue @@ -149,12 +149,13 @@ async function ensureMenuListLoaded() { } const findIndexById = (array: any[], targetId: string | number) => - array.findIndex((item) => item.id === targetId); + array.findIndex((item) => String(item.id) === String(targetId)); function indexChangeMenu(id: string) { // 最新的菜单ID console.log('indexChangeMenu', id) - currentMenuIndex.value = findIndexById(menuList.value, id) + const idx = findIndexById(menuList.value, id) + currentMenuIndex.value = idx >= 0 ? idx : 0 console.log('当前选中的菜单索引', currentMenuIndex.value) getMenuDetail().then(() => { paging.value?.reload() @@ -165,9 +166,14 @@ function indexChangeMenu(id: string) { const menuDishListData = ref([]) async function getMenuDetail() { + const recipeId = currentMenu.value?.id + if (recipeId === undefined || recipeId === null || String(recipeId).trim() === '') { + menuDishListData.value = [] + return + } return appMerchantMenuMenuDetailPost({ params: { - recipeId: currentMenu.value.id || '' + recipeId } }).then((res: any) => { console.log('获取菜单详情', res) @@ -294,9 +300,14 @@ function deleteRecipe(item: MerchantDishVo) { }); } +function getCurrentMenuId() { + return currentMenu.value?.id as string | number | undefined +} + defineExpose({ initData, - indexChangeMenu + indexChangeMenu, + getCurrentMenuId }) // 当前商家是否已经入驻了 diff --git a/src/pages/home/components/tabbar-menu/components/menu.vue b/src/pages/home/components/tabbar-menu/components/menu.vue index d6cbd1d..33a0adb 100644 --- a/src/pages/home/components/tabbar-menu/components/menu.vue +++ b/src/pages/home/components/tabbar-menu/components/menu.vue @@ -5,7 +5,8 @@ import {useUserStore} from "@/store"; const userStore = useUserStore() const {t} = useI18n(); const show = ref(false); -const pickerValue = ref(0) +/** 与 wd-picker-view 的 value-key 一致,存菜单 id(非列索引) */ +const pickerValue = ref('') const emits = defineEmits(['confirm']) // 默认分页配置(避免一次请求 1000 条) @@ -17,9 +18,21 @@ type MenuColumnItem = { label: string } -function onOpen(value: number) { - getMenuListByMerchant() - show.value = true; +/** 打开选择器;selectedMenuId 为当前概览选中的菜单 id,用于回显 */ +async function onOpen(selectedMenuId?: string | number) { + await getMenuListByMerchant() + if (columns.value.length === 0) { + uni.showToast({ + title: t('pages.menu.pickerNoMenu'), + icon: 'none', + }) + return + } + const match = selectedMenuId != null && selectedMenuId !== '' + ? columns.value.find((c) => String(c.value) === String(selectedMenuId)) + : undefined + pickerValue.value = match ? match.value : columns.value[0].value + show.value = true } const columns = ref([]) @@ -63,8 +76,30 @@ function handleClose() { } function handleSubmit() { - console.log('handleSubmit', pickerValue.value) - emits('confirm', pickerValue.value) + if (columns.value.length === 0) { + uni.showToast({ + title: t('pages.menu.pickerNoMenu'), + icon: 'none', + }) + return + } + const pv = pickerValue.value + if (pv === '' || pv === undefined || pv === null) { + uni.showToast({ + title: t('pages.menu.pickerSelectValidMenu'), + icon: 'none', + }) + return + } + const isValid = columns.value.some((c) => String(c.value) === String(pv)) + if (!isValid) { + uni.showToast({ + title: t('pages.menu.pickerSelectValidMenu'), + icon: 'none', + }) + return + } + emits('confirm', String(pv)) handleClose() } @@ -87,7 +122,13 @@ defineExpose({ {{ t('common.confirm') }} - + diff --git a/src/pages/home/components/tabbar-menu/tabbar-menu.vue b/src/pages/home/components/tabbar-menu/tabbar-menu.vue index 054e809..8510344 100644 --- a/src/pages/home/components/tabbar-menu/tabbar-menu.vue +++ b/src/pages/home/components/tabbar-menu/tabbar-menu.vue @@ -54,10 +54,17 @@ async function getPlatformDefaultStoreInfo() { console.log('getPlatformDefaultStoreInfo被处罚了') } +function getCurrentMenuId() { + const list = menuSwiperListRef.value as any + if (!list || !Array.isArray(list)) return undefined + return list[0]?.getCurrentMenuId?.() +} + defineExpose({ indexChangeMenu, initData, init: getPlatformDefaultStoreInfo, + getCurrentMenuId, }) diff --git a/src/pages/home/index.vue b/src/pages/home/index.vue index 22dcee8..cbf9a63 100644 --- a/src/pages/home/index.vue +++ b/src/pages/home/index.vue @@ -74,8 +74,9 @@ function handleChooseLanguage() { const changeMenuRef = ref() function changeMenu() { + const menuId = tabbarMenuRef.value?.getCurrentMenuId?.() if (changeMenuRef.value) { - changeMenuRef.value.onOpen() + changeMenuRef.value.onOpen(menuId) } }