All checks were successful
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Successful in 50s
- 精油价目新增分两个tab:新增精油(标准容量) / 新增其他产品(ml/g/颗) - saveOil支持unit参数 - 配方卡片:含产品的配方直接显示产品用量+单位(如30g) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
158 lines
3.7 KiB
Vue
158 lines
3.7 KiB
Vue
<template>
|
|
<div class="recipe-card" @click="$emit('click', index)">
|
|
<div class="recipe-card-name">{{ recipe.name }} <span v-if="volumeLabel" class="recipe-card-volume">{{ volumeLabel }}</span></div>
|
|
<div v-if="visibleTags.length" class="recipe-card-tags">
|
|
<span v-for="tag in visibleTags" :key="tag" class="tag" :class="{ 'tag-reviewed': tag === '已审核' }">{{ tag }}</span>
|
|
</div>
|
|
<div class="recipe-card-oils">{{ oilNames }}</div>
|
|
<div class="recipe-card-bottom">
|
|
<div class="recipe-card-price">💰 {{ priceInfo.cost }}</div>
|
|
<button
|
|
class="fav-btn"
|
|
:class="{ favorited: isFav }"
|
|
@click.stop="$emit('toggle-fav', recipe._id)"
|
|
:title="isFav ? '取消收藏' : '收藏'"
|
|
>{{ isFav ? '★' : '☆' }}</button>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { computed } from 'vue'
|
|
import { useOilsStore } from '../stores/oils'
|
|
import { useRecipesStore, EDITOR_ONLY_TAGS } from '../stores/recipes'
|
|
import { useAuthStore } from '../stores/auth'
|
|
|
|
const props = defineProps({
|
|
recipe: { type: Object, required: true },
|
|
index: { type: Number, required: true },
|
|
})
|
|
|
|
defineEmits(['click', 'toggle-fav'])
|
|
|
|
const oilsStore = useOilsStore()
|
|
const recipesStore = useRecipesStore()
|
|
const auth = useAuthStore()
|
|
|
|
const visibleTags = computed(() => {
|
|
if (!props.recipe.tags) return []
|
|
if (!auth.canEdit) return []
|
|
const tags = [...props.recipe.tags]
|
|
return tags.sort((a, b) => a.localeCompare(b, 'zh'))
|
|
})
|
|
|
|
const oilNames = computed(() =>
|
|
[...props.recipe.ingredients].sort((a, b) => a.oil.localeCompare(b.oil, 'zh')).map(i => i.oil).join('、')
|
|
)
|
|
const priceInfo = computed(() => oilsStore.fmtCostWithRetail(props.recipe.ingredients))
|
|
const isFav = computed(() => recipesStore.isFavorite(props.recipe))
|
|
|
|
const volumeLabel = computed(() => {
|
|
const ings = props.recipe.ingredients || []
|
|
const coco = ings.find(i => i.oil === '椰子油')
|
|
if (coco && coco.drops) {
|
|
const totalDrops = ings.reduce((s, i) => s + (i.drops || 0), 0)
|
|
const ml = totalDrops / 18.6
|
|
if (ml <= 2) return '单次'
|
|
return `${Math.round(ml)}ml`
|
|
}
|
|
// Non-coconut: find portion product and show its amount + unit
|
|
const portionIng = ings.find(i => oilsStore.isPortionUnit(i.oil))
|
|
if (portionIng) {
|
|
return `${portionIng.drops}${oilsStore.unitLabel(portionIng.oil)}`
|
|
}
|
|
return ''
|
|
})
|
|
</script>
|
|
|
|
<style scoped>
|
|
.recipe-card {
|
|
background: white;
|
|
border-radius: 14px;
|
|
padding: 18px;
|
|
cursor: pointer;
|
|
box-shadow: 0 4px 20px rgba(90, 60, 30, 0.08);
|
|
border: 2px solid transparent;
|
|
transition: all 0.2s;
|
|
}
|
|
|
|
.recipe-card:hover {
|
|
transform: translateY(-3px);
|
|
box-shadow: 0 8px 32px rgba(90, 60, 30, 0.15);
|
|
border-color: #c8ddc9;
|
|
}
|
|
|
|
.recipe-card-name {
|
|
font-family: 'Noto Serif SC', serif;
|
|
font-size: 16px;
|
|
font-weight: 600;
|
|
color: #2c2416;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
.recipe-card-tags {
|
|
display: flex;
|
|
flex-wrap: wrap;
|
|
gap: 5px;
|
|
margin-bottom: 6px;
|
|
}
|
|
|
|
.tag {
|
|
font-size: 11px;
|
|
padding: 2px 8px;
|
|
border-radius: 8px;
|
|
background: #eef4ee;
|
|
color: #5a7d5e;
|
|
}
|
|
|
|
.tag-reviewed {
|
|
background: #e3f2fd;
|
|
color: #1565c0;
|
|
}
|
|
|
|
.recipe-card-oils {
|
|
font-size: 12px;
|
|
color: #9a8570;
|
|
line-height: 1.7;
|
|
}
|
|
|
|
.recipe-card-volume {
|
|
font-size: 10px;
|
|
color: #b0aab5;
|
|
font-weight: 400;
|
|
margin-left: 4px;
|
|
}
|
|
|
|
.recipe-card-bottom {
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
.recipe-card-price {
|
|
font-size: 13px;
|
|
color: #5a7d5e;
|
|
font-weight: 600;
|
|
}
|
|
|
|
.fav-btn {
|
|
background: none;
|
|
border: none;
|
|
font-size: 20px;
|
|
cursor: pointer;
|
|
color: #d4cfc7;
|
|
padding: 2px 4px;
|
|
line-height: 1;
|
|
transition: color 0.2s;
|
|
}
|
|
|
|
.fav-btn.favorited {
|
|
color: #f5a623;
|
|
}
|
|
|
|
.fav-btn:hover {
|
|
color: #f5a623;
|
|
}
|
|
</style>
|