feat: 配方卡片加入上传个人二维码功能
Some checks failed
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Failing after 1m8s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 13s
Some checks failed
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Failing after 1m8s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 13s
- RecipeDetailOverlay: 未上传二维码/背景图时,卡片上方显示提示横幅,下方出现「上传我的二维码」按钮,点击跳转到 MyDiary 品牌设置页并记录来源配方 - MyDiary: 新增二维码图片上传区域(直接上传图片文件,存为 base64 → PUT /api/brand qr_code 字段);上传成功后若有待返回配方则自动跳回配方卡片;修复 loadBrandSettings 字段名与后端不一致的问题 - RecipeSearch: 支持 ?openRecipe= 查询参数,页面挂载时自动打开指定配方卡片,实现从 MyDiary 上传后无缝返回 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
|||||||
<div v-if="viewMode === 'card'" class="detail-card-view">
|
<div v-if="viewMode === 'card'" class="detail-card-view">
|
||||||
<!-- Top bar with close + edit -->
|
<!-- Top bar with close + edit -->
|
||||||
<div class="card-header">
|
<div class="card-header">
|
||||||
<div class="card-top-actions" v-if="authStore.isLoggedIn">
|
<div class="card-top-actions">
|
||||||
<button class="action-btn action-btn-fav action-btn-sm" @click="handleToggleFavorite">
|
<button class="action-btn action-btn-fav action-btn-sm" @click="handleToggleFavorite">
|
||||||
{{ isFav ? '★ 已收藏' : '☆ 收藏' }}
|
{{ isFav ? '★ 已收藏' : '☆ 收藏' }}
|
||||||
</button>
|
</button>
|
||||||
@@ -36,6 +36,12 @@
|
|||||||
>English</button>
|
>English</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- QR / brand upload hint -->
|
||||||
|
<div v-if="showBrandHint" class="brand-upload-hint">
|
||||||
|
<span class="hint-icon">✨</span>
|
||||||
|
<span>上传你的专属二维码,生成属于自己的配方卡片</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Card image (rendered by html2canvas) -->
|
<!-- Card image (rendered by html2canvas) -->
|
||||||
<div v-show="!cardImageUrl" ref="cardRef" class="export-card">
|
<div v-show="!cardImageUrl" ref="cardRef" class="export-card">
|
||||||
<!-- Brand overlay layers -->
|
<!-- Brand overlay layers -->
|
||||||
@@ -122,10 +128,15 @@
|
|||||||
<button class="action-btn" @click="saveImage">💾 保存图片</button>
|
<button class="action-btn" @click="saveImage">💾 保存图片</button>
|
||||||
<button class="action-btn" @click="copyText">📋 复制文字</button>
|
<button class="action-btn" @click="copyText">📋 复制文字</button>
|
||||||
<button
|
<button
|
||||||
v-if="cardLang === 'en'"
|
v-if="cardLang === 'en' && authStore.canManage"
|
||||||
class="action-btn"
|
class="action-btn"
|
||||||
@click="showTranslationEditor = true"
|
@click="showTranslationEditor = true"
|
||||||
>✏️ 修改翻译</button>
|
>✏️ 修改翻译</button>
|
||||||
|
<button
|
||||||
|
v-if="showBrandHint"
|
||||||
|
class="action-btn action-btn-qr"
|
||||||
|
@click="goUploadQr"
|
||||||
|
>📲 上传我的二维码</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Translation editor (inline) -->
|
<!-- Translation editor (inline) -->
|
||||||
@@ -342,6 +353,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
import html2canvas from 'html2canvas'
|
import html2canvas from 'html2canvas'
|
||||||
import { useOilsStore, DROPS_PER_ML, VOLUME_DROPS } from '../stores/oils'
|
import { useOilsStore, DROPS_PER_ML, VOLUME_DROPS } from '../stores/oils'
|
||||||
import { useRecipesStore } from '../stores/recipes'
|
import { useRecipesStore } from '../stores/recipes'
|
||||||
@@ -363,6 +375,7 @@ const recipesStore = useRecipesStore()
|
|||||||
const authStore = useAuthStore()
|
const authStore = useAuthStore()
|
||||||
const ui = useUiStore()
|
const ui = useUiStore()
|
||||||
const diaryStore = useDiaryStore()
|
const diaryStore = useDiaryStore()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
// ---- View state ----
|
// ---- View state ----
|
||||||
const viewMode = ref('card')
|
const viewMode = ref('card')
|
||||||
@@ -453,6 +466,18 @@ async function loadBrand() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Whether to show the brand/QR upload hint
|
||||||
|
const showBrandHint = computed(() =>
|
||||||
|
authStore.isLoggedIn && !!brand.value && !brand.value.qr_code && !brand.value.brand_bg
|
||||||
|
)
|
||||||
|
|
||||||
|
function goUploadQr() {
|
||||||
|
if (recipe.value._id) {
|
||||||
|
localStorage.setItem('oil_return_recipe_id', recipe.value._id)
|
||||||
|
}
|
||||||
|
router.push('/mydiary')
|
||||||
|
}
|
||||||
|
|
||||||
// ---- Card image generation ----
|
// ---- Card image generation ----
|
||||||
async function generateCardImage() {
|
async function generateCardImage() {
|
||||||
if (!cardRef.value || generatingImage.value) return
|
if (!cardRef.value || generatingImage.value) return
|
||||||
@@ -787,9 +812,11 @@ async function saveRecipe() {
|
|||||||
name: editName.value.trim(),
|
name: editName.value.trim(),
|
||||||
note: editNote.value.trim(),
|
note: editNote.value.trim(),
|
||||||
tags: editTags.value,
|
tags: editTags.value,
|
||||||
ingredients,
|
ingredients: ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })),
|
||||||
}
|
}
|
||||||
await recipesStore.saveRecipe(payload)
|
await recipesStore.saveRecipe(payload)
|
||||||
|
// Reload recipes so the data is fresh when re-opened
|
||||||
|
await recipesStore.loadRecipes()
|
||||||
ui.showToast('保存成功')
|
ui.showToast('保存成功')
|
||||||
emit('close')
|
emit('close')
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
@@ -1134,6 +1161,42 @@ async function saveRecipe() {
|
|||||||
background: var(--sage-mist, #eef4ee);
|
background: var(--sage-mist, #eef4ee);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Brand upload hint banner */
|
||||||
|
.brand-upload-hint {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 8px;
|
||||||
|
background: linear-gradient(135deg, #eef4ee, #f5f0e8);
|
||||||
|
border: 1.5px dashed var(--sage-light, #c8ddc9);
|
||||||
|
border-radius: 10px;
|
||||||
|
padding: 10px 16px;
|
||||||
|
margin-bottom: 14px;
|
||||||
|
font-size: 13px;
|
||||||
|
color: var(--sage-dark, #5a7d5e);
|
||||||
|
font-weight: 500;
|
||||||
|
animation: hint-pop 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hint-icon {
|
||||||
|
font-size: 18px;
|
||||||
|
flex-shrink: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes hint-pop {
|
||||||
|
from { opacity: 0; transform: translateY(-6px); }
|
||||||
|
to { opacity: 1; transform: translateY(0); }
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn-qr {
|
||||||
|
background: linear-gradient(135deg, #c8ddc9, var(--sage, #7a9e7e));
|
||||||
|
color: #fff;
|
||||||
|
border-color: transparent;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn-qr:hover {
|
||||||
|
opacity: 0.88;
|
||||||
|
}
|
||||||
|
|
||||||
/* Card bottom actions */
|
/* Card bottom actions */
|
||||||
.card-bottom-actions {
|
.card-bottom-actions {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|||||||
@@ -123,6 +123,16 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="form-group">
|
||||||
|
<label>我的二维码图片</label>
|
||||||
|
<div class="upload-area" @click="triggerUpload('qr')">
|
||||||
|
<img v-if="brandQrImage" :src="brandQrImage" class="upload-preview qr-upload-preview" />
|
||||||
|
<span v-else class="upload-hint">📲 点击上传二维码图片</span>
|
||||||
|
</div>
|
||||||
|
<input ref="qrInput" type="file" accept="image/*" style="display:none" @change="handleUpload('qr', $event)" />
|
||||||
|
<div class="field-hint">上传后将显示在配方卡片右下角</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label>品牌Logo</label>
|
<label>品牌Logo</label>
|
||||||
<div class="upload-area" @click="triggerUpload('logo')">
|
<div class="upload-area" @click="triggerUpload('logo')">
|
||||||
@@ -202,6 +212,7 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, watch } from 'vue'
|
import { ref, computed, onMounted, watch } from 'vue'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
import { useAuthStore } from '../stores/auth'
|
import { useAuthStore } from '../stores/auth'
|
||||||
import { useOilsStore } from '../stores/oils'
|
import { useOilsStore } from '../stores/oils'
|
||||||
import { useDiaryStore } from '../stores/diary'
|
import { useDiaryStore } from '../stores/diary'
|
||||||
@@ -214,6 +225,7 @@ const auth = useAuthStore()
|
|||||||
const oils = useOilsStore()
|
const oils = useOilsStore()
|
||||||
const diaryStore = useDiaryStore()
|
const diaryStore = useDiaryStore()
|
||||||
const ui = useUiStore()
|
const ui = useUiStore()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const activeTab = ref('brand')
|
const activeTab = ref('brand')
|
||||||
const pasteText = ref('')
|
const pasteText = ref('')
|
||||||
@@ -224,10 +236,12 @@ const newEntryText = ref('')
|
|||||||
// Brand settings
|
// Brand settings
|
||||||
const brandName = ref('')
|
const brandName = ref('')
|
||||||
const brandQrUrl = ref('')
|
const brandQrUrl = ref('')
|
||||||
|
const brandQrImage = ref('')
|
||||||
const brandLogo = ref('')
|
const brandLogo = ref('')
|
||||||
const brandBg = ref('')
|
const brandBg = ref('')
|
||||||
const logoInput = ref(null)
|
const logoInput = ref(null)
|
||||||
const bgInput = ref(null)
|
const bgInput = ref(null)
|
||||||
|
const qrInput = ref(null)
|
||||||
|
|
||||||
// Account settings
|
// Account settings
|
||||||
const displayName = ref('')
|
const displayName = ref('')
|
||||||
@@ -345,8 +359,9 @@ async function loadBrandSettings() {
|
|||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
brandName.value = data.brand_name || ''
|
brandName.value = data.brand_name || ''
|
||||||
brandQrUrl.value = data.qr_url || ''
|
brandQrUrl.value = data.qr_url || ''
|
||||||
brandLogo.value = data.logo_url || ''
|
brandQrImage.value = data.qr_code || ''
|
||||||
brandBg.value = data.bg_url || ''
|
brandLogo.value = data.brand_logo || ''
|
||||||
|
brandBg.value = data.brand_bg || ''
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
// no brand settings yet
|
// no brand settings yet
|
||||||
@@ -369,26 +384,46 @@ async function saveBrandSettings() {
|
|||||||
|
|
||||||
function triggerUpload(type) {
|
function triggerUpload(type) {
|
||||||
if (type === 'logo') logoInput.value?.click()
|
if (type === 'logo') logoInput.value?.click()
|
||||||
else bgInput.value?.click()
|
else if (type === 'bg') bgInput.value?.click()
|
||||||
|
else if (type === 'qr') qrInput.value?.click()
|
||||||
|
}
|
||||||
|
|
||||||
|
function readFileAsBase64(file) {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const reader = new FileReader()
|
||||||
|
reader.onload = e => resolve(e.target.result)
|
||||||
|
reader.onerror = reject
|
||||||
|
reader.readAsDataURL(file)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleUpload(type, event) {
|
async function handleUpload(type, event) {
|
||||||
const file = event.target.files[0]
|
const file = event.target.files[0]
|
||||||
if (!file) return
|
if (!file) return
|
||||||
const formData = new FormData()
|
|
||||||
formData.append('file', file)
|
|
||||||
formData.append('type', type)
|
|
||||||
try {
|
try {
|
||||||
const token = localStorage.getItem('oil_auth_token') || ''
|
const base64 = await readFileAsBase64(file)
|
||||||
const res = await fetch('/api/brand-upload', {
|
const fieldMap = { logo: 'brand_logo', bg: 'brand_bg', qr: 'qr_code' }
|
||||||
method: 'POST',
|
const field = fieldMap[type]
|
||||||
headers: token ? { Authorization: 'Bearer ' + token } : {},
|
if (!field) return
|
||||||
body: formData,
|
const res = await api('/api/brand', {
|
||||||
|
method: 'PUT',
|
||||||
|
body: JSON.stringify({ [field]: base64 }),
|
||||||
})
|
})
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json()
|
if (type === 'logo') brandLogo.value = base64
|
||||||
if (type === 'logo') brandLogo.value = data.url
|
else if (type === 'bg') brandBg.value = base64
|
||||||
else brandBg.value = data.url
|
else if (type === 'qr') {
|
||||||
|
brandQrImage.value = base64
|
||||||
|
// If user came here from a recipe card, navigate back
|
||||||
|
const returnRecipeId = localStorage.getItem('oil_return_recipe_id')
|
||||||
|
if (returnRecipeId) {
|
||||||
|
localStorage.removeItem('oil_return_recipe_id')
|
||||||
|
ui.showToast('二维码已上传,返回配方卡片 ✨')
|
||||||
|
await new Promise(r => setTimeout(r, 800))
|
||||||
|
router.push('/?openRecipe=' + encodeURIComponent(returnRecipeId))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
ui.showToast('上传成功')
|
ui.showToast('上传成功')
|
||||||
}
|
}
|
||||||
} catch {
|
} catch {
|
||||||
@@ -783,6 +818,18 @@ async function applyBusiness() {
|
|||||||
max-height: 100px;
|
max-height: 100px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.qr-upload-preview {
|
||||||
|
max-width: 120px;
|
||||||
|
max-height: 120px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.field-hint {
|
||||||
|
font-size: 12px;
|
||||||
|
color: #9b94a3;
|
||||||
|
margin-top: 4px;
|
||||||
|
padding-left: 2px;
|
||||||
|
}
|
||||||
|
|
||||||
.upload-hint {
|
.upload-hint {
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
color: #b0aab5;
|
color: #b0aab5;
|
||||||
|
|||||||
@@ -123,7 +123,8 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, nextTick } from 'vue'
|
import { ref, computed, onMounted, nextTick, watch } from 'vue'
|
||||||
|
import { useRoute, useRouter } from 'vue-router'
|
||||||
import { useAuthStore } from '../stores/auth'
|
import { useAuthStore } from '../stores/auth'
|
||||||
import { useOilsStore } from '../stores/oils'
|
import { useOilsStore } from '../stores/oils'
|
||||||
import { useRecipesStore } from '../stores/recipes'
|
import { useRecipesStore } from '../stores/recipes'
|
||||||
@@ -136,6 +137,8 @@ const auth = useAuthStore()
|
|||||||
const oils = useOilsStore()
|
const oils = useOilsStore()
|
||||||
const recipeStore = useRecipesStore()
|
const recipeStore = useRecipesStore()
|
||||||
const ui = useUiStore()
|
const ui = useUiStore()
|
||||||
|
const route = useRoute()
|
||||||
|
const router = useRouter()
|
||||||
|
|
||||||
const searchQuery = ref('')
|
const searchQuery = ref('')
|
||||||
const selectedCategory = ref(null)
|
const selectedCategory = ref(null)
|
||||||
@@ -154,6 +157,27 @@ onMounted(async () => {
|
|||||||
} catch {
|
} catch {
|
||||||
// category modules are optional
|
// category modules are optional
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return to a recipe card after QR upload redirect
|
||||||
|
const openRecipeId = route.query.openRecipe
|
||||||
|
if (openRecipeId) {
|
||||||
|
router.replace({ path: '/', query: {} })
|
||||||
|
const tryOpen = () => {
|
||||||
|
const idx = recipeStore.recipes.findIndex(r => r._id === openRecipeId)
|
||||||
|
if (idx >= 0) {
|
||||||
|
openDetail(idx)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if (!tryOpen()) {
|
||||||
|
// Recipes might not be loaded yet, watch until available
|
||||||
|
const stop = watch(
|
||||||
|
() => recipeStore.recipes.length,
|
||||||
|
() => { if (tryOpen()) stop() },
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
function selectCategory(cat) {
|
function selectCategory(cat) {
|
||||||
|
|||||||
Reference in New Issue
Block a user