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
4 changed files with 39 additions and 19 deletions

View File

@@ -238,6 +238,8 @@ def init_db():
c.execute("ALTER TABLE recipes ADD COLUMN owner_id INTEGER")
if "updated_by" not in cols:
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
count = c.execute("SELECT COUNT(*) FROM users").fetchone()[0]

View File

@@ -95,6 +95,7 @@ class RecipeIn(BaseModel):
class RecipeUpdate(BaseModel):
name: Optional[str] = None
en_name: Optional[str] = None
note: Optional[str] = None
ingredients: Optional[list[IngredientIn]] = None
tags: Optional[list[str]] = None
@@ -308,7 +309,7 @@ def symptom_search(body: dict, user=Depends(get_current_user)):
conn = get_db()
# Search in recipe names
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()
exact = []
related = []
@@ -696,6 +697,7 @@ def _recipe_to_dict(conn, row):
return {
"id": rid,
"name": row["name"],
"en_name": row["en_name"] if "en_name" in row.keys() else "",
"note": row["note"],
"owner_id": row["owner_id"],
"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()
# Admin sees all; others see admin-owned (adopted) + their own
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:
admin = conn.execute("SELECT id FROM users WHERE role = 'admin' LIMIT 1").fetchone()
admin_id = admin["id"] if admin else 1
user_id = user.get("id")
if user_id:
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)
).fetchall()
else:
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,)
).fetchall()
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}")
def get_recipe(recipe_id: int):
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:
conn.close()
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))
if update.note is not None:
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:
c.execute("DELETE FROM recipe_ingredients WHERE recipe_id = ?", (recipe_id,))
for ing in update.ingredients:
@@ -833,7 +837,7 @@ def delete_recipe(recipe_id: int, user=Depends(get_current_user)):
conn = get_db()
row = _check_recipe_permission(conn, recipe_id, user)
# 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)
log_audit(conn, user["id"], "delete_recipe", "recipe", recipe_id, row["name"],
json.dumps(snapshot, ensure_ascii=False))
@@ -1336,7 +1340,7 @@ def recipes_by_inventory(user=Depends(get_current_user)):
if not inv:
conn.close()
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 = []
for r in rows:
recipe = _recipe_to_dict(conn, r)

View File

@@ -5,7 +5,7 @@
<div v-if="viewMode === 'card'" class="detail-card-view">
<!-- Top bar with close + edit -->
<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">
{{ isFav ? ' 已收藏' : ' 收藏' }}
</button>
@@ -122,7 +122,7 @@
<button class="action-btn" @click="saveImage">💾 保存图片</button>
<button class="action-btn" @click="copyText">📋 复制文字</button>
<button
v-if="cardLang === 'en'"
v-if="cardLang === 'en' && authStore.canManage"
class="action-btn"
@click="showTranslationEditor = true"
> 修改翻译</button>
@@ -350,6 +350,7 @@ import { useUiStore } from '../stores/ui'
import { useDiaryStore } from '../stores/diary'
import { api } from '../composables/useApi'
import { oilEn, recipeNameEn } from '../composables/useOilTranslation'
import { showPrompt } from '../composables/useDialog'
// TagPicker replaced with inline tag editing
const props = defineProps({
@@ -518,9 +519,20 @@ function copyText() {
})
}
function applyTranslation() {
// translations stored in customOilNameEn / customRecipeNameEn
async function applyTranslation() {
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
nextTick(() => generateCardImage())
}
@@ -535,7 +547,7 @@ function getCardOilName(name) {
function getCardRecipeName() {
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
}
@@ -565,16 +577,16 @@ async function saveToDiary() {
ui.openLogin()
return
}
const name = prompt('保存为我的配方,名称:', recipe.value.name)
const name = await showPrompt('保存为我的配方,名称:', recipe.value.name)
if (!name) return
try {
await api.post('/api/diary', {
await recipesStore.saveRecipe({
name,
source_recipe_id: recipe.value._id || null,
ingredients: recipe.value.ingredients.map(i => ({ oil: i.oil, drops: i.drops })),
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) {
ui.showToast('保存失败: ' + (e?.message || '未知错误'))
}
@@ -640,7 +652,7 @@ onMounted(() => {
editTags.value = [...(r.tags || [])]
editIngredients.value = (r.ingredients || []).map(i => ({ oil: i.oil, drops: i.drops }))
// Init translation defaults
customRecipeNameEn.value = recipeNameEn(r.name)
customRecipeNameEn.value = r.en_name || recipeNameEn(r.name)
const enMap = {}
;(r.ingredients || []).forEach(ing => {
enMap[ing.oil] = oilEn(ing.oil) || ing.oil
@@ -787,9 +799,10 @@ async function saveRecipe() {
name: editName.value.trim(),
note: editNote.value.trim(),
tags: editTags.value,
ingredients,
ingredients: ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })),
}
await recipesStore.saveRecipe(payload)
await recipesStore.loadRecipes()
ui.showToast('保存成功')
emit('close')
} catch (e) {

View File

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