6 Commits

Author SHA1 Message Date
b07b97bf1e fix: 存为我的改写入 recipes 表,确保在「我的配方」和「管理配方」中显示
Some checks failed
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
Test / e2e-test (push) Failing after 1m6s
PR Preview / test (pull_request) Has been skipped
PR Preview / teardown-preview (pull_request) Successful in 13s
PR Preview / deploy-preview (pull_request) Has been skipped
之前 saveToDiary() 调用 POST /api/diary,数据写入 user_diary 表,
只在「我的配方日记」(/mydiary) 中可见。
改为调用 recipesStore.saveRecipe(),写入 recipes 表并以当前用户为 owner,
GET /api/recipes 会返回该用户自己创建的配方,
RecipeSearch 的「我的配方」预览和 RecipeManager 的配方列表均可显示。

Co-Authored-By: YoYo <yoyo@euphon.net>
2026-04-08 19:44:15 +00:00
2ab192c3ba feat: 存为我的提示框改用自定义 CustomDialog
Some checks failed
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / teardown-preview (pull_request) Has been skipped
Test / e2e-test (push) Failing after 1m7s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 15s
将 saveToDiary 中的原生 prompt() 替换为项目内置的
showPrompt(),与全站风格保持一致。
2026-04-07 22:49:07 +00:00
70413971e3 Merge pull request 'dev' (#2) from dev into main
Some checks failed
Deploy Production / test (push) Successful in 5s
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
Deploy Production / deploy (push) Successful in 5s
Test / e2e-test (push) Failing after 1m7s
Reviewed-on: #2
2026-04-07 22:12:00 +00:00
6804835e85 Persist recipe English name translation to database
Some checks failed
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
Test / e2e-test (push) Failing after 1m7s
PR Preview / test (pull_request) Has been skipped
PR Preview / teardown-preview (pull_request) Successful in 14s
PR Preview / deploy-preview (pull_request) Has been skipped
- Add en_name column to recipes table (migration in database.py)
- Include en_name in recipe API responses and RecipeUpdate model
- Save en_name when admin/senior_editor applies translation
- Load en_name on overlay open, so translation persists across sessions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:08:05 +00:00
2088019ed7 Fix overlay: always show buttons, restrict translation, fix save data
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 4s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 15s
Test / e2e-test (push) Failing after 1m5s
- Always show favorite/save-to-diary buttons (login check on click)
- Restrict translation editor to senior_editor/admin only (canManage)
- Fix save: map ingredient oil→oil_name for API, reload recipes after
- Ensures next open shows the saved data

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 21:59:41 +00:00
fam
7ba1e28370 Merge pull request 'Refactor: 前端重构为 Vue 3 + Vite + Pinia + Cypress E2E' (#1) from dev into main
Reviewed-on: #1
2026-04-06 19:22:19 +00:00
6 changed files with 50 additions and 168 deletions

View File

@@ -238,6 +238,8 @@ def init_db():
c.execute("ALTER TABLE recipes ADD COLUMN owner_id INTEGER") c.execute("ALTER TABLE recipes ADD COLUMN owner_id INTEGER")
if "updated_by" not in cols: if "updated_by" not in cols:
c.execute("ALTER TABLE recipes ADD COLUMN updated_by INTEGER") c.execute("ALTER TABLE recipes ADD COLUMN updated_by INTEGER")
if "en_name" not in cols:
c.execute("ALTER TABLE recipes ADD COLUMN en_name TEXT DEFAULT ''")
# Seed admin user if no users exist # Seed admin user if no users exist
count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0] count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0]

View File

@@ -95,6 +95,7 @@ class RecipeIn(BaseModel):
class RecipeUpdate(BaseModel): class RecipeUpdate(BaseModel):
name: Optional[str] = None name: Optional[str] = None
en_name: Optional[str] = None
note: Optional[str] = None note: Optional[str] = None
ingredients: Optional[list[IngredientIn]] = None ingredients: Optional[list[IngredientIn]] = None
tags: Optional[list[str]] = None tags: Optional[list[str]] = None
@@ -308,7 +309,7 @@ def symptom_search(body: dict, user=Depends(get_current_user)):
conn = get_db() conn = get_db()
# Search in recipe names # Search in recipe names
rows = conn.execute( rows = conn.execute(
"SELECT id, name, note, owner_id, version FROM recipes ORDER BY id" "SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id"
).fetchall() ).fetchall()
exact = [] exact = []
related = [] related = []
@@ -696,6 +697,7 @@ def _recipe_to_dict(conn, row):
return { return {
"id": rid, "id": rid,
"name": row["name"], "name": row["name"],
"en_name": row["en_name"] if "en_name" in row.keys() else "",
"note": row["note"], "note": row["note"],
"owner_id": row["owner_id"], "owner_id": row["owner_id"],
"owner_name": (owner["display_name"] or owner["username"]) if owner else None, "owner_name": (owner["display_name"] or owner["username"]) if owner else None,
@@ -710,19 +712,19 @@ def list_recipes(user=Depends(get_current_user)):
conn = get_db() conn = get_db()
# Admin sees all; others see admin-owned (adopted) + their own # Admin sees all; others see admin-owned (adopted) + their own
if user["role"] == "admin": if user["role"] == "admin":
rows = conn.execute("SELECT id, name, note, owner_id, version FROM recipes ORDER BY id").fetchall() rows = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id").fetchall()
else: else:
admin = conn.execute("SELECT id FROM users WHERE role = 'admin' LIMIT 1").fetchone() admin = conn.execute("SELECT id FROM users WHERE role = 'admin' LIMIT 1").fetchone()
admin_id = admin["id"] if admin else 1 admin_id = admin["id"] if admin else 1
user_id = user.get("id") user_id = user.get("id")
if user_id: if user_id:
rows = conn.execute( rows = conn.execute(
"SELECT id, name, note, owner_id, version FROM recipes WHERE owner_id = ? OR owner_id = ? ORDER BY id", "SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE owner_id = ? OR owner_id = ? ORDER BY id",
(admin_id, user_id) (admin_id, user_id)
).fetchall() ).fetchall()
else: else:
rows = conn.execute( rows = conn.execute(
"SELECT id, name, note, owner_id, version FROM recipes WHERE owner_id = ? ORDER BY id", "SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE owner_id = ? ORDER BY id",
(admin_id,) (admin_id,)
).fetchall() ).fetchall()
result = [_recipe_to_dict(conn, r) for r in rows] result = [_recipe_to_dict(conn, r) for r in rows]
@@ -733,7 +735,7 @@ def list_recipes(user=Depends(get_current_user)):
@app.get("/api/recipes/{recipe_id}") @app.get("/api/recipes/{recipe_id}")
def get_recipe(recipe_id: int): def get_recipe(recipe_id: int):
conn = get_db() conn = get_db()
row = conn.execute("SELECT id, name, note, owner_id, version FROM recipes WHERE id = ?", (recipe_id,)).fetchone() row = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
if not row: if not row:
conn.close() conn.close()
raise HTTPException(404, "Recipe not found") raise HTTPException(404, "Recipe not found")
@@ -804,6 +806,8 @@ def update_recipe(recipe_id: int, update: RecipeUpdate, user=Depends(get_current
c.execute("UPDATE recipes SET name = ? WHERE id = ?", (update.name, recipe_id)) c.execute("UPDATE recipes SET name = ? WHERE id = ?", (update.name, recipe_id))
if update.note is not None: if update.note is not None:
c.execute("UPDATE recipes SET note = ? WHERE id = ?", (update.note, recipe_id)) c.execute("UPDATE recipes SET note = ? WHERE id = ?", (update.note, recipe_id))
if update.en_name is not None:
c.execute("UPDATE recipes SET en_name = ? WHERE id = ?", (update.en_name, recipe_id))
if update.ingredients is not None: if update.ingredients is not None:
c.execute("DELETE FROM recipe_ingredients WHERE recipe_id = ?", (recipe_id,)) c.execute("DELETE FROM recipe_ingredients WHERE recipe_id = ?", (recipe_id,))
for ing in update.ingredients: for ing in update.ingredients:
@@ -833,7 +837,7 @@ def delete_recipe(recipe_id: int, user=Depends(get_current_user)):
conn = get_db() conn = get_db()
row = _check_recipe_permission(conn, recipe_id, user) row = _check_recipe_permission(conn, recipe_id, user)
# Save full snapshot for undo # Save full snapshot for undo
full = conn.execute("SELECT id, name, note, owner_id, version FROM recipes WHERE id = ?", (recipe_id,)).fetchone() full = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes WHERE id = ?", (recipe_id,)).fetchone()
snapshot = _recipe_to_dict(conn, full) snapshot = _recipe_to_dict(conn, full)
log_audit(conn, user["id"], "delete_recipe", "recipe", recipe_id, row["name"], log_audit(conn, user["id"], "delete_recipe", "recipe", recipe_id, row["name"],
json.dumps(snapshot, ensure_ascii=False)) json.dumps(snapshot, ensure_ascii=False))
@@ -1336,7 +1340,7 @@ def recipes_by_inventory(user=Depends(get_current_user)):
if not inv: if not inv:
conn.close() conn.close()
return [] return []
rows = conn.execute("SELECT id, name, note, owner_id, version FROM recipes ORDER BY id").fetchall() rows = conn.execute("SELECT id, name, note, owner_id, version, en_name FROM recipes ORDER BY id").fetchall()
result = [] result = []
for r in rows: for r in rows:
recipe = _recipe_to_dict(conn, r) recipe = _recipe_to_dict(conn, r)

View File

@@ -36,12 +36,6 @@
>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 -->
@@ -132,11 +126,6 @@
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) -->
@@ -353,7 +342,6 @@
<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'
@@ -362,6 +350,7 @@ import { useUiStore } from '../stores/ui'
import { useDiaryStore } from '../stores/diary' import { useDiaryStore } from '../stores/diary'
import { api } from '../composables/useApi' import { api } from '../composables/useApi'
import { oilEn, recipeNameEn } from '../composables/useOilTranslation' import { oilEn, recipeNameEn } from '../composables/useOilTranslation'
import { showPrompt } from '../composables/useDialog'
// TagPicker replaced with inline tag editing // TagPicker replaced with inline tag editing
const props = defineProps({ const props = defineProps({
@@ -375,7 +364,6 @@ 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')
@@ -466,22 +454,6 @@ async function loadBrand() {
} }
} }
// Whether to show the brand/QR upload hint (show to all users who haven't set up brand assets)
const showBrandHint = computed(() =>
!!brand.value && !brand.value.qr_code && !brand.value.brand_bg
)
function goUploadQr() {
if (!authStore.isLoggedIn) {
ui.openLogin()
return
}
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
@@ -547,9 +519,20 @@ function copyText() {
}) })
} }
function applyTranslation() { async function applyTranslation() {
// translations stored in customOilNameEn / customRecipeNameEn
showTranslationEditor.value = false showTranslationEditor.value = false
// Persist en_name to backend
if (recipe.value._id && customRecipeNameEn.value) {
try {
await api.put(`/api/recipes/${recipe.value._id}`, {
en_name: customRecipeNameEn.value,
version: recipe.value._version,
})
ui.showToast('翻译已保存')
} catch (e) {
ui.showToast('翻译保存失败')
}
}
cardImageUrl.value = null cardImageUrl.value = null
nextTick(() => generateCardImage()) nextTick(() => generateCardImage())
} }
@@ -564,7 +547,7 @@ function getCardOilName(name) {
function getCardRecipeName() { function getCardRecipeName() {
if (cardLang.value === 'en') { if (cardLang.value === 'en') {
return customRecipeNameEn.value || recipeNameEn(recipe.value.name) return customRecipeNameEn.value || recipe.value.en_name || recipeNameEn(recipe.value.name)
} }
return recipe.value.name return recipe.value.name
} }
@@ -594,16 +577,16 @@ async function saveToDiary() {
ui.openLogin() ui.openLogin()
return return
} }
const name = prompt('保存为我的配方,名称:', recipe.value.name) const name = await showPrompt('保存为我的配方,名称:', recipe.value.name)
if (!name) return if (!name) return
try { try {
await api.post('/api/diary', { await recipesStore.saveRecipe({
name, name,
source_recipe_id: recipe.value._id || null,
ingredients: recipe.value.ingredients.map(i => ({ oil: i.oil, drops: i.drops })),
note: recipe.value.note || '', note: recipe.value.note || '',
ingredients: recipe.value.ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })),
tags: recipe.value.tags || [],
}) })
ui.showToast('已保存到「我的配方日记」') ui.showToast('已保存到「我的配方」')
} catch (e) { } catch (e) {
ui.showToast('保存失败: ' + (e?.message || '未知错误')) ui.showToast('保存失败: ' + (e?.message || '未知错误'))
} }
@@ -669,7 +652,7 @@ onMounted(() => {
editTags.value = [...(r.tags || [])] editTags.value = [...(r.tags || [])]
editIngredients.value = (r.ingredients || []).map(i => ({ oil: i.oil, drops: i.drops })) editIngredients.value = (r.ingredients || []).map(i => ({ oil: i.oil, drops: i.drops }))
// Init translation defaults // Init translation defaults
customRecipeNameEn.value = recipeNameEn(r.name) customRecipeNameEn.value = r.en_name || recipeNameEn(r.name)
const enMap = {} const enMap = {}
;(r.ingredients || []).forEach(ing => { ;(r.ingredients || []).forEach(ing => {
enMap[ing.oil] = oilEn(ing.oil) || ing.oil enMap[ing.oil] = oilEn(ing.oil) || ing.oil
@@ -819,7 +802,6 @@ async function saveRecipe() {
ingredients: ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })), 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() await recipesStore.loadRecipes()
ui.showToast('保存成功') ui.showToast('保存成功')
emit('close') emit('close')
@@ -1165,42 +1147,6 @@ 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;

View File

@@ -16,6 +16,7 @@ export const useRecipesStore = defineStore('recipes', () => {
_owner_name: r._owner_name ?? r.owner_name ?? '', _owner_name: r._owner_name ?? r.owner_name ?? '',
_version: r._version ?? r.version ?? 1, _version: r._version ?? r.version ?? 1,
name: r.name, name: r.name,
en_name: r.en_name ?? '',
note: r.note ?? '', note: r.note ?? '',
tags: r.tags ?? [], tags: r.tags ?? [],
ingredients: (r.ingredients ?? []).map((ing) => ({ ingredients: (r.ingredients ?? []).map((ing) => ({

View File

@@ -123,16 +123,6 @@
</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')">
@@ -212,7 +202,6 @@
<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'
@@ -225,7 +214,6 @@ 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('')
@@ -236,12 +224,10 @@ 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('')
@@ -359,9 +345,8 @@ 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 || ''
brandQrImage.value = data.qr_code || '' brandLogo.value = data.logo_url || ''
brandLogo.value = data.brand_logo || '' brandBg.value = data.bg_url || ''
brandBg.value = data.brand_bg || ''
} }
} catch { } catch {
// no brand settings yet // no brand settings yet
@@ -384,46 +369,26 @@ async function saveBrandSettings() {
function triggerUpload(type) { function triggerUpload(type) {
if (type === 'logo') logoInput.value?.click() if (type === 'logo') logoInput.value?.click()
else if (type === 'bg') bgInput.value?.click() else 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 base64 = await readFileAsBase64(file) const token = localStorage.getItem('oil_auth_token') || ''
const fieldMap = { logo: 'brand_logo', bg: 'brand_bg', qr: 'qr_code' } const res = await fetch('/api/brand-upload', {
const field = fieldMap[type] method: 'POST',
if (!field) return headers: token ? { Authorization: 'Bearer ' + token } : {},
const res = await api('/api/brand', { body: formData,
method: 'PUT',
body: JSON.stringify({ [field]: base64 }),
}) })
if (res.ok) { if (res.ok) {
if (type === 'logo') brandLogo.value = base64 const data = await res.json()
else if (type === 'bg') brandBg.value = base64 if (type === 'logo') brandLogo.value = data.url
else if (type === 'qr') { else brandBg.value = data.url
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 {
@@ -818,18 +783,6 @@ 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;

View File

@@ -123,8 +123,7 @@
</template> </template>
<script setup> <script setup>
import { ref, computed, onMounted, nextTick, watch } from 'vue' import { ref, computed, onMounted, nextTick } 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'
@@ -137,8 +136,6 @@ 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)
@@ -157,27 +154,6 @@ 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) {