refactor: 拆分小程序 vue 结构

This commit is contained in:
2026-03-11 14:11:26 +08:00
commit b050c01a24
141 changed files with 24904 additions and 0 deletions

View File

@@ -0,0 +1,52 @@
import type { Ref } from 'vue'
import type {
FulfillmentScene,
MiniCategory,
MiniMenuSection
} from '@/shared'
import { getCategories, getMenu } from '@/services'
import type { useAppStore } from '@/stores'
type AppStoreInstance = ReturnType<typeof useAppStore>
export function createMenuDataActions (payload: {
appStore: AppStoreInstance
categories: Ref<MiniCategory[]>
errorMessage: Ref<string>
loading: Ref<boolean>
sections: Ref<MiniMenuSection[]>
}) {
const { appStore, categories, errorMessage, loading, sections } = payload
async function loadMenu () {
loading.value = true
errorMessage.value = ''
try {
await appStore.initBootstrap()
await appStore.initStores()
const [nextCategories, nextSections] = await Promise.all([
getCategories(appStore.currentStore.id, appStore.scene, appStore.channel),
getMenu(appStore.currentStore.id, appStore.scene, appStore.channel)
])
categories.value = nextCategories
sections.value = nextSections
} catch (error: unknown) {
errorMessage.value = error instanceof Error ? error.message : '菜单加载失败,请检查接口是否可用'
} finally {
loading.value = false
}
}
async function handleSceneChange (value: string) {
appStore.setScene(value as FulfillmentScene)
await loadMenu()
}
return {
handleSceneChange,
loadMenu
}
}