feat: generate emojis pre

This commit is contained in:
YunYouJun
2022-04-16 09:07:53 +08:00
parent 4345ba6b6e
commit bff0d9eada
6 changed files with 33 additions and 25 deletions

View File

@@ -8,7 +8,12 @@ import { meat, staple, tools, vegetable } from '~/data/food'
import recipeData from '~/data/recipe.json' import recipeData from '~/data/recipe.json'
import type { Recipe } from '~/types' import type { Recipe } from '~/types'
import { useRecipeStore } from '~/stores/recipe' import { useRecipeStore } from '~/stores/recipe'
const recipe = ref(recipeData as Recipe) import { generateEmojisFromStuff } from '~/utils'
(recipeData as Recipe).forEach((recipe) => {
recipe.emojis = generateEmojisFromStuff(recipe.stuff)
})
const recipe = ref<Recipe>(recipeData as Recipe)
const rStore = useRecipeStore() const rStore = useRecipeStore()
const curStuff = computed(() => rStore.selectedStuff) const curStuff = computed(() => rStore.selectedStuff)
@@ -65,7 +70,7 @@ const clickTool = (item: StuffItem) => {
<template> <template>
<div m="y-4"> <div m="y-4">
<h2 text="xl" font="bold" p="1"> <h2 text="xl" font="bold" p="1">
如果有 🥬 🥬 今天想吃
</h2> </h2>
<VegetableTag <VegetableTag
v-for="item, i in vegetable" :key="i" v-for="item, i in vegetable" :key="i"
@@ -85,7 +90,7 @@ const clickTool = (item: StuffItem) => {
</div> </div>
<div m="y-4"> <div m="y-4">
<h2 text="xl" font="bold" p="1"> <h2 text="xl" font="bold" p="1">
如果有 🥩 🥩 还想吃点
</h2> </h2>
<MeatTag <MeatTag
v-for="item, i in meat" :key="i" v-for="item, i in meat" :key="i"
@@ -102,7 +107,7 @@ const clickTool = (item: StuffItem) => {
</div> </div>
<div m="y-4"> <div m="y-4">
<h2 text="xl" font="bold" p="1"> <h2 text="xl" font="bold" p="1">
想来点 🍚 主食 🍚 想来点主食
</h2> </h2>
<StapleTag <StapleTag
v-for="item, i in staple" :key="i" v-for="item, i in staple" :key="i"
@@ -119,7 +124,7 @@ const clickTool = (item: StuffItem) => {
</div> </div>
<div m="t-4"> <div m="t-4">
<h2 text="xl" font="bold" p="1"> <h2 text="xl" font="bold" p="1">
打算用 🍳 厨具 🍳 打算用厨具
</h2> </h2>
<ToolTag <ToolTag
v-for="item, i in tools" :key="i" v-for="item, i in tools" :key="i"

View File

@@ -1,6 +1,5 @@
<script lang="ts" setup> <script lang="ts" setup>
import { useGtm } from '@gtm-support/vue-gtm' import { useGtm } from '@gtm-support/vue-gtm'
import { meat, staple, vegetable } from '~/data/food'
import type { RecipeItem } from '~/types' import type { RecipeItem } from '~/types'
defineProps<{ defineProps<{
dish: RecipeItem dish: RecipeItem
@@ -16,21 +15,6 @@ const triggerGtm = (val: string) => {
label: '跳转菜谱', label: '跳转菜谱',
}) })
} }
const getDishName = (dish: RecipeItem) => {
const name = dish.name
const emojis: string[] = []
dish.stuff.forEach((item) => {
const kinds = [vegetable, meat, staple]
kinds.forEach((kind) => {
kind.forEach((m) => {
if (m.name === item)
emojis.push(m.emoji)
})
})
})
return `${emojis.join(' ')} ${name}`
}
</script> </script>
<template> <template>
@@ -40,6 +24,6 @@ const getDishName = (dish: RecipeItem) => {
bg="blue-300 opacity-20" bg="blue-300 opacity-20"
@click="triggerGtm(dish.name)" @click="triggerGtm(dish.name)"
> >
<span text="sm blue-700 dark:blue-200">{{ getDishName(dish) }}</span> <span text="sm blue-700 dark:blue-200">{{ dish.emojis.join(' ') + ' ' + dish.name }}</span>
</a> </a>
</template> </template>

View File

@@ -7,8 +7,8 @@ defineProps<{
<template> <template>
<span <span
class="tag rounded" p="x-2" class="tag rounded" p="x-2"
:border="'~ stone-200 dark:stone-800' + (active ? 'dark:stone-200' : '')" :border="'~ stone-200 dark:stone-600'"
:bg="active ? 'stone-600 opacity-100' : 'stone-300 opacity-20'" :bg="active ? 'stone-600 opacity-100' : 'stone-300 opacity-5'"
:text="active ? 'stone-100' : 'stone-800 dark:stone-200'" :text="active ? 'stone-100' : 'stone-800 dark:stone-200'"
> >
<slot /> <slot />

View File

@@ -68,7 +68,7 @@ export const vegetable: StuffItem[] = [
}, },
{ {
name: '莴笋', name: '莴笋',
emoji: '🥗', emoji: '🎍',
}, },
{ {
name: '菌菇', name: '菌菇',

View File

@@ -13,6 +13,10 @@ export interface RecipeItem {
* 材料 * 材料
*/ */
stuff: string[] stuff: string[]
/**
* 根据材料生成
*/
emojis: string[]
/** /**
* 难度 * 难度
*/ */

15
src/utils/index.ts Normal file
View File

@@ -0,0 +1,15 @@
import { meat, staple, vegetable } from '~/data/food'
export function generateEmojisFromStuff(stuff: string[]) {
const emojis: string[] = []
stuff.forEach((item) => {
const kinds = [vegetable, meat, staple]
kinds.forEach((kind) => {
kind.forEach((m) => {
if (m.name === item)
emojis.push(m.emoji)
})
})
})
return emojis
}