diff --git a/src/components/ChooseFood.vue b/src/components/ChooseFood.vue index 78fb5c3..bd0d027 100644 --- a/src/components/ChooseFood.vue +++ b/src/components/ChooseFood.vue @@ -2,6 +2,7 @@ import MeatTag from './MeatTag.vue' import StapleTag from './StapleTag.vue' import DishTag from './DishTag.vue' +import type { StuffItem } from '~/data/foot' import { meat, staple, vegetable } from '~/data/foot' import recipeData from '~/data/recipe.json' import type { Recipe } from '~/types' @@ -9,12 +10,19 @@ import { useRecipeStore } from '~/stores/recipe' const recipe = ref(recipeData as Recipe) const rStore = useRecipeStore() +const curStuff = computed(() => rStore.selectedStuff) const displayedRecipe = computed(() => { return recipe.value.filter((item) => { - return Array.from(rStore.curStuff).some(stuff => item.stuff.includes(stuff)) + return curStuff.value.some(stuff => item.stuff.includes(stuff)) }) }) + +const toggleStuff = (item: StuffItem) => { + rStore.toggleStuff(item.name) + if (item.alias) + rStore.toggleStuff(item.alias) +} diff --git a/src/data/foot.ts b/src/data/foot.ts index 6e1fee3..1185f46 100644 --- a/src/data/foot.ts +++ b/src/data/foot.ts @@ -11,6 +11,10 @@ export interface StuffItem { * 图片链接 */ image?: string + /** + * 别名,譬如:西红柿/番茄 + */ + alias?: string } /** @@ -40,6 +44,7 @@ export const vegetable: StuffItem[] = [ { name: '番茄', emoji: '🍅', + alias: '西红柿', }, { name: '芹菜', diff --git a/src/pages/about.md b/src/pages/about.md index 12bc34f..97bfada 100644 --- a/src/pages/about.md +++ b/src/pages/about.md @@ -3,8 +3,6 @@ title: 关于 ---
- -

关于

diff --git a/src/stores/recipe.ts b/src/stores/recipe.ts index 14b44f2..d1283f1 100644 --- a/src/stores/recipe.ts +++ b/src/stores/recipe.ts @@ -2,8 +2,11 @@ import { acceptHMRUpdate, defineStore } from 'pinia' export const useRecipeStore = defineStore('recipe', () => { const curStuff = ref(new Set()) + const selectedStuff = computed(() => Array.from(curStuff.value)) function toggleStuff(name: string) { + if (!curStuff) + return if (curStuff.value.has(name)) curStuff.value.delete(name) else @@ -11,7 +14,7 @@ export const useRecipeStore = defineStore('recipe', () => { } return { - curStuff, + selectedStuff, toggleStuff, } }) diff --git a/src/styles/index.scss b/src/styles/index.scss index 860a5ff..eb3ccf4 100644 --- a/src/styles/index.scss +++ b/src/styles/index.scss @@ -12,3 +12,14 @@ a { padding: 2px 4px; // border: 1px solid var(--c-text); } + +/* we will explain what these classes do next! */ +.v-enter-active, +.v-leave-active { + transition: opacity 0.3s ease; +} + +.v-enter-from, +.v-leave-to { + opacity: 0; +}