fix: choose tool

This commit is contained in:
YunYouJun
2022-04-15 22:25:53 +08:00
parent b078f9e6fa
commit 75060adf3c
3 changed files with 12 additions and 7 deletions

View File

@@ -21,7 +21,7 @@ const displayedRecipe = computed(() => {
if (strict.value) { if (strict.value) {
const stuffFlag = curStuff.value.every(stuff => item.stuff.includes(stuff)) const stuffFlag = curStuff.value.every(stuff => item.stuff.includes(stuff))
const toolFlag = curTool.value ? item.tools?.includes(curTool.value) : true const toolFlag = curTool.value ? item.tools?.includes(curTool.value) : true
return curTool.value ? stuffFlag && toolFlag : stuffFlag return stuffFlag && toolFlag
} }
else { else {
const stuffFlag = curStuff.value.some(stuff => item.stuff.includes(stuff)) const stuffFlag = curStuff.value.some(stuff => item.stuff.includes(stuff))
@@ -49,14 +49,15 @@ const toggleStuff = (item: StuffItem, category = '') => {
* @param item * @param item
*/ */
const clickTool = (item: StuffItem) => { const clickTool = (item: StuffItem) => {
if (curTool.value === item.name) const value = typeof item.value !== 'undefined' ? item.value : item.name
if (curTool.value === value)
curTool.value = '' curTool.value = ''
else else
curTool.value = item.name curTool.value = value
gtm?.trackEvent({ gtm?.trackEvent({
event: 'stuff', event: 'stuff',
category: `tool_${item.name}`, category: `tool_${value}`,
action: 'click', action: 'click',
label: '工具', label: '工具',
}) })
@@ -124,7 +125,7 @@ const clickTool = (item: StuffItem) => {
</h2> </h2>
<ToolTag <ToolTag
v-for="item, i in tools" :key="i" v-for="item, i in tools" :key="i"
:active="curTool === item.name" :active="[item.value, item.name].includes(curTool)"
@click="clickTool(item)" @click="clickTool(item)"
> >
<span v-if="item.emoji" class="inline-flex">{{ item.emoji }}</span> <span v-if="item.emoji" class="inline-flex">{{ item.emoji }}</span>

View File

@@ -10,10 +10,9 @@ const gtm = useGtm()
const triggerGtm = (val: string) => { const triggerGtm = (val: string) => {
gtm?.trackEvent({ gtm?.trackEvent({
event: 'recipe', event: 'recipe',
category: 'dish', category: `dish_${val}`,
action: 'click', action: 'click',
label: '跳转菜谱', label: '跳转菜谱',
value: val,
}) })
} }
</script> </script>

View File

@@ -19,6 +19,10 @@ export interface StuffItem {
* 图标名称 * 图标名称
*/ */
icon?: string icon?: string
/**
* value
*/
value?: string
} }
/** /**
@@ -178,5 +182,6 @@ export const tools: StuffItem[] = [
name: '一口啥都能煮的大锅', name: '一口啥都能煮的大锅',
emoji: '', emoji: '',
icon: 'i-mdi-pot-steam-outline', icon: 'i-mdi-pot-steam-outline',
value: '',
}, },
] ]