From 56ad10ef07796cd84a391cce117950ebc267a176 Mon Sep 17 00:00:00 2001 From: YunYouJun Date: Thu, 14 Apr 2022 23:32:24 +0800 Subject: [PATCH] feat: add strict mode --- scripts/convert.ts | 11 +- src/components/ChooseFood.vue | 30 ++- src/data/foot.ts | 4 + src/data/recipe.csv | 416 +++++++++++++++++++++++++++++++++- src/types/recipe.ts | 12 +- unocss.config.ts | 2 +- 6 files changed, 455 insertions(+), 20 deletions(-) diff --git a/scripts/convert.ts b/scripts/convert.ts index bb4475c..27e09e5 100644 --- a/scripts/convert.ts +++ b/scripts/convert.ts @@ -2,7 +2,7 @@ import fs from 'fs' import path from 'path' import consola from 'consola' -import type { Recipe } from '~/types' +import type { Recipe, RecipeItem } from '~/types' const recipeCsvFile = path.resolve(__dirname, '../src/data/recipe.csv') const recipeJsonFile = path.resolve(__dirname, '../src/data/recipe.json') @@ -11,7 +11,7 @@ function run() { const csvData = fs.readFileSync(recipeCsvFile, 'utf-8') const lines = csvData.split(/\r?\n/) - if (lines[0].trim() !== '名称,食材,链接,标签/描述,方法,工具') { + if (lines[0].trim() !== 'name,stuff,link,difficulty,tags,methods,tools') { consola.warn(`Headers Changed: ${lines[0]}`) return } @@ -26,9 +26,10 @@ function run() { name: attrs[0].trim(), stuff: attrs[1].trim().split(sep), link: attrs[2].trim(), - tags: attrs[3].trim().split(sep), - methods: attrs[4].trim().split(sep), - tools: attrs[5].trim().split(sep), + difficulty: attrs[3] && attrs[3].trim() as RecipeItem['difficulty'], + tags: attrs[4] ? attrs[4].trim().split(sep) : [], + methods: attrs[5] ? (attrs[5].trim().split(sep)) as RecipeItem['methods'] : [], + tools: attrs[6] ? attrs[6].trim().split(sep) : [], }) } }) diff --git a/src/components/ChooseFood.vue b/src/components/ChooseFood.vue index c7ab50d..bd49a2e 100644 --- a/src/components/ChooseFood.vue +++ b/src/components/ChooseFood.vue @@ -12,9 +12,13 @@ const recipe = ref(recipeData as Recipe) const rStore = useRecipeStore() const curStuff = computed(() => rStore.selectedStuff) +const strict = ref(false) const displayedRecipe = computed(() => { return recipe.value.filter((item) => { - return curStuff.value.some(stuff => item.stuff.includes(stuff)) + if (strict.value) + return curStuff.value.every(stuff => item.stuff.includes(stuff)) + else + return curStuff.value.some(stuff => item.stuff.includes(stuff)) }) }) @@ -26,18 +30,28 @@ const toggleStuff = (item: StuffItem) => {