diff --git a/src/components/ChooseFood.vue b/src/components/ChooseFood.vue index fd50dd3..915da5d 100644 --- a/src/components/ChooseFood.vue +++ b/src/components/ChooseFood.vue @@ -14,25 +14,36 @@ import { useInvisibleElement } from '~/composables/helper' const recipe = ref(recipeData as Recipe) const rStore = useRecipeStore() -const { strict } = storeToRefs(rStore) +const { strict, curTool } = storeToRefs(rStore) const curStuff = computed(() => rStore.selectedStuff) -const curTools = computed(() => rStore.selectedTools) // 默认严格模式 const displayedRecipe = computed(() => { - return recipe.value.filter((item) => { + const recipes = recipe.value.filter((item) => { if (strict.value) { const stuffFlag = curStuff.value.every(stuff => item.stuff.includes(stuff)) - // const toolFlag = curTools.value.every(tool => item.tools?.includes(tool)) - const toolFlag = curTools.value.some(tool => item.tools?.includes(tool)) - return curTools.value.length ? stuffFlag && toolFlag : stuffFlag + const toolFlag = item.tools?.includes(curTool.value) + return curTool.value ? stuffFlag && toolFlag : stuffFlag } else { const stuffFlag = curStuff.value.some(stuff => item.stuff.includes(stuff)) - const toolFlag = curTools.value.every(tool => item.tools?.includes(tool)) - return curTools.value.length ? stuffFlag && toolFlag : stuffFlag + const toolFlag = item.tools?.includes(curTool.value) + + // 同时存在 厨具和材料,则同时判断 + if (curTool.value && curStuff.value.length) { + return stuffFlag && toolFlag + } + else { + if (curStuff.value.length) + return stuffFlag + else if (curTool.value) + return toolFlag + + return false + } } }) + return recipes }) const { x, y } = usePointer() @@ -190,7 +201,7 @@ const { isVisible, show } = useInvisibleElement(recipePanel) {{ item.emoji }} @@ -212,7 +223,7 @@ const { isVisible, show } = useInvisibleElement(recipePanel)
- + 你要先选食材或工具哦~ diff --git a/src/stores/recipe.ts b/src/stores/recipe.ts index 42f1e47..3d0ad9a 100644 --- a/src/stores/recipe.ts +++ b/src/stores/recipe.ts @@ -4,10 +4,12 @@ export const useRecipeStore = defineStore('recipe', () => { const strict = ref(false) const curStuff = ref(new Set()) - const curTools = ref(new Set()) + // const curTools = ref(new Set()) + const curTool = ref('') const selectedStuff = computed(() => Array.from(curStuff.value)) - const selectedTools = computed(() => Array.from(curTools.value)) + // const selectedTools = computed(() => Array.from(curTools.value)) + // const selectedTools = ref('') function toggleStuff(name: string) { if (!curStuff) @@ -19,12 +21,14 @@ export const useRecipeStore = defineStore('recipe', () => { } function toggleTools(name: string) { - if (!curTools) - return - if (curTools.value.has(name)) - curTools.value.delete(name) + if (curTool.value === name) + curTool.value = '' else - curTools.value.add(name) + curTool.value = name + // if (curTools.value.has(name)) + // curTools.value.delete(name) + // else + // curTools.value.add(name) } /** @@ -32,12 +36,13 @@ export const useRecipeStore = defineStore('recipe', () => { */ function reset() { curStuff.value.clear() - curTools.value.clear() + // curTools.value.clear() + curTool.value = '' } return { strict, - selectedTools, + curTool, selectedStuff, toggleStuff, toggleTools,