16 Commits

Author SHA1 Message Date
533cd2a0bd fix: 上传图片后不再自动跳转,由用户手动点击返回配方卡片
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 5s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Failing after 1m21s
Co-Authored-By: YoYo <yoyo@euphon.net>
2026-04-08 19:41:04 +00:00
de74ffe638 fix: 配方卡片品牌样式与 initial commit 保持一致
Some checks failed
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 4s
PR Preview / deploy-preview (pull_request) Successful in 15s
Test / e2e-test (push) Failing after 1m16s
- 背景图改用 div+background-image,opacity 从 0.06 恢复为 0.12
- 二维码位置改回 top:36px/right:24px,尺寸 54×54,加圆角和阴影
- 二维码下方新增品牌名称小字(7px)
- Logo 位置改回 bottom:60px,尺寸 height:60px,opacity 0.2

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-08 07:42:47 +00:00
4761253d73 fix: 存为我的改用自定义 showPrompt,与主分支保持一致
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
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 1m18s
将 saveToDiary 中的原生 prompt() 替换为项目内置的
showPrompt(),使对话框样式与主分支及全站风格保持一致。

Co-Authored-By: YoYo <yoyo@euphon.net>
2026-04-07 23:09:29 +00:00
65239abc53 QR upload: replace inline hint with dialog, add back button in brand page
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Failing after 1m21s
- Replace the inline brand-upload-hint bar in RecipeDetailOverlay with a
  confirm dialog (「去上传」/「取消」) that pops up when the card opens
- Extend useDialog/CustomDialog to support custom ok/cancel button text
- Add a 「← 返回配方卡片」banner in MyDiary brand tab when navigated
  from a recipe card, allowing return without uploading

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 22:55:39 +00:00
19f4ab8abe fix: 顶部导航栏sticky修正、右上角显示角色身份、QR上传预览布局优化
Some checks failed
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 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Has been cancelled
- 预览环境下nav-tabs top偏移36px,避免被orange banner遮挡
- 登录用户名旁显示角色身份(查看者/编辑/管理员等)
- 账户页角色改用绿色渐变徽章样式,对齐UserMenu风格
- QR图片上传区改为120x120居中方形,预览样式与二维码链接预览一致

Closes #9 (part: items 1-3, accumulated to PR #5)

Co-Authored-By: YoYo <yoyo@euphon.net>
2026-04-07 22:54:45 +00:00
96504ed1d7 Resume pending action after login (favorite, diary, QR upload)
Some checks failed
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 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m4s
Add pendingAction callback to UI store. When user clicks favorite,
save-to-diary, or upload QR while not logged in, the action is stored
and automatically executed after successful login/register instead of
reloading the page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:39:59 +00:00
5eba04a1fa Fix toast rendering: display toast.msg instead of object
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 12s
Test / e2e-test (push) Failing after 1m7s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:35:41 +00:00
4d5e3c46e7 Shorten copy toast to just '已复制'
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 13s
Test / e2e-test (push) Failing after 1m4s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:34:07 +00:00
3bbe437616 Remove volume selector from recipe card view
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 5s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:33:16 +00:00
edc053ae0e Raise toast z-index to 9000 so it shows above all overlays
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 13s
Test / e2e-test (push) Has been cancelled
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:32:42 +00:00
b9681141af Fix LoginModal z-index to 6000 so it appears above recipe overlay
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 4s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 14s
Test / e2e-test (push) Failing after 1m4s
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-07 22:28:17 +00:00
dee4b1649a fix: 卡片预览加入容量切换,非单次滴数四舍五入
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 3s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Has been cancelled
- VOLUME_DROPS 新增「单次」(null,不缩放)
- 新增 scaleIngredients() 按比例缩放成分
- 卡片预览区加入容量切换按钮,切换后实时更新滴数与成本
- priceInfo 与 coconutDrops 均基于缩放后数据

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 22:27:21 +00:00
955512d344 feat: 未登录用户也显示二维码上传提示,点击时引导登录/注册
Some checks failed
PR Preview / teardown-preview (pull_request) Has been skipped
PR Preview / test (pull_request) Successful in 4s
Test / unit-test (push) Successful in 5s
Test / build-check (push) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 12s
Test / e2e-test (push) Failing after 1m8s
2026-04-07 22:25:10 +00:00
81ec5987b3 feat: 配方卡片加入上传个人二维码功能
- RecipeDetailOverlay: 未上传二维码/背景图时,卡片上方显示提示横幅,下方出现「上传我的二维码」按钮,点击跳转到 MyDiary 品牌设置页并记录来源配方
- MyDiary: 新增二维码图片上传区域(直接上传图片文件,存为 base64 → PUT /api/brand qr_code 字段);上传成功后若有待返回配方则自动跳回配方卡片;修复 loadBrandSettings 字段名与后端不一致的问题
- RecipeSearch: 支持 ?openRecipe= 查询参数,页面挂载时自动打开指定配方卡片,实现从 MyDiary 上传后无缝返回

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-07 22:25:10 +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
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
10 changed files with 327 additions and 62 deletions

View File

@@ -15,7 +15,9 @@
@click="toggleUserMenu"
>
<template v-if="auth.isLoggedIn">
👤 {{ auth.user.display_name || auth.user.username }}
👤 {{ auth.user.display_name || auth.user.username }}
<span style="font-size:10px;background:rgba(255,255,255,0.2);padding:2px 7px;border-radius:8px;margin:0 3px;vertical-align:middle;font-weight:400;letter-spacing:0">{{ roleLabel }}</span>
</template>
<template v-else>
<span style="background:rgba(255,255,255,0.2);padding:4px 12px;border-radius:12px">登录</span>
@@ -41,7 +43,7 @@
<UserMenu v-if="showUserMenu" @close="showUserMenu = false" />
<!-- Nav tabs -->
<div class="nav-tabs">
<div class="nav-tabs" :style="isPreview ? { top: '36px' } : {}">
<div class="nav-tab" :class="{ active: ui.currentSection === 'search' }" @click="goSection('search')">🔍 配方查询</div>
<div class="nav-tab" :class="{ active: ui.currentSection === 'manage' }" @click="requireLogin('manage')">📋 管理配方</div>
<div class="nav-tab" :class="{ active: ui.currentSection === 'inventory' }" @click="requireLogin('inventory')">📦 个人库存</div>
@@ -64,11 +66,11 @@
<CustomDialog />
<!-- Toast messages -->
<div v-for="(toast, i) in ui.toasts" :key="i" class="toast">{{ toast }}</div>
<div v-for="toast in ui.toasts" :key="toast.id" class="toast">{{ toast.msg }}</div>
</template>
<script setup>
import { ref, onMounted, watch } from 'vue'
import { ref, computed, onMounted, watch } from 'vue'
import { useRouter, useRoute } from 'vue-router'
import { useAuthStore } from './stores/auth'
import { useOilsStore } from './stores/oils'
@@ -86,6 +88,11 @@ const router = useRouter()
const route = useRoute()
const showUserMenu = ref(false)
const roleLabel = computed(() => {
const map = { admin: '管理员', senior_editor: '高级编辑', editor: '编辑', viewer: '查看者' }
return map[auth.user.role] || '查看者'
})
// Sync ui.currentSection from route on load and navigation
const routeToSection = { '/': 'search', '/manage': 'manage', '/inventory': 'inventory', '/oils': 'oils', '/projects': 'projects', '/mydiary': 'mydiary', '/audit': 'audit', '/bugs': 'bugs', '/users': 'users' }
watch(() => route.path, (path) => {

View File

@@ -445,7 +445,7 @@ body {
.toast {
position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%);
background: rgba(0,0,0,0.8); color: white; padding: 10px 24px;
border-radius: 20px; font-size: 14px; z-index: 999;
border-radius: 20px; font-size: 14px; z-index: 9000;
pointer-events: none; transition: opacity 0.3s;
}

View File

@@ -11,8 +11,8 @@
ref="promptInput"
/>
<div class="dialog-btn-row">
<button v-if="dialogState.type !== 'alert'" class="dialog-btn-outline" @click="cancel">取消</button>
<button class="dialog-btn-primary" @click="ok">确定</button>
<button v-if="dialogState.type !== 'alert'" class="dialog-btn-outline" @click="cancel">{{ dialogState.cancelText || '取消' }}</button>
<button class="dialog-btn-primary" @click="ok">{{ dialogState.okText || '确定' }}</button>
</div>
</div>
</div>

View File

@@ -104,8 +104,11 @@ async function submit() {
ui.showToast('注册成功')
}
emit('close')
// Reload page data after auth change
window.location.reload()
if (ui.pendingAction) {
ui.runPendingAction()
} else {
window.location.reload()
}
} catch (e) {
errorMsg.value = e?.message || (mode.value === 'login' ? '登录失败,请检查用户名和密码' : '注册失败,请重试')
} finally {
@@ -119,7 +122,7 @@ async function submit() {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.35);
z-index: 5000;
z-index: 6000;
display: flex;
align-items: center;
justify-content: center;

View File

@@ -39,18 +39,19 @@
<!-- Card image (rendered by html2canvas) -->
<div v-show="!cardImageUrl" ref="cardRef" class="export-card">
<!-- Brand overlay layers -->
<img
<div
v-if="brand.brand_bg"
:src="brand.brand_bg"
class="card-brand-bg"
crossorigin="anonymous"
/>
<img
v-if="brand.qr_code"
:src="brand.qr_code"
class="card-qr"
crossorigin="anonymous"
:style="{ backgroundImage: `url('${brand.brand_bg}')` }"
/>
<div v-if="brand.qr_code" class="card-qr-wrapper">
<img
:src="brand.qr_code"
class="card-qr"
crossorigin="anonymous"
/>
<div v-if="brand.brand_name" class="card-qr-name">{{ brand.brand_name }}</div>
</div>
<img
v-if="brand.brand_logo"
:src="brand.brand_logo"
@@ -126,6 +127,11 @@
class="action-btn"
@click="showTranslationEditor = true"
> 修改翻译</button>
<button
v-if="showBrandHint"
class="action-btn action-btn-qr"
@click="goUploadQr"
>📲 上传我的二维码</button>
</div>
<!-- Translation editor (inline) -->
@@ -342,6 +348,7 @@
<script setup>
import { ref, computed, onMounted, nextTick, watch } from 'vue'
import { useRouter } from 'vue-router'
import html2canvas from 'html2canvas'
import { useOilsStore, DROPS_PER_ML, VOLUME_DROPS } from '../stores/oils'
import { useRecipesStore } from '../stores/recipes'
@@ -349,6 +356,7 @@ import { useAuthStore } from '../stores/auth'
import { useUiStore } from '../stores/ui'
import { useDiaryStore } from '../stores/diary'
import { api } from '../composables/useApi'
import { showConfirm, showPrompt } from '../composables/useDialog'
import { oilEn, recipeNameEn } from '../composables/useOilTranslation'
// TagPicker replaced with inline tag editing
@@ -363,12 +371,14 @@ const recipesStore = useRecipesStore()
const authStore = useAuthStore()
const ui = useUiStore()
const diaryStore = useDiaryStore()
const router = useRouter()
// ---- View state ----
const viewMode = ref('card')
const cardRef = ref(null)
const cardImageUrl = ref(null)
const cardLang = ref('zh')
const selectedCardVolume = ref('单次')
const showTranslationEditor = ref(false)
const customRecipeNameEn = ref('')
const customOilNameEn = ref({})
@@ -387,14 +397,30 @@ const canEditThisRecipe = computed(() => {
const isFav = computed(() => recipesStore.isFavorite(recipe.value))
// Card ingredients: exclude coconut oil
const cardIngredients = computed(() =>
recipe.value.ingredients.filter(ing => ing.oil !== '椰子油')
// Scale ingredients proportionally to target volume; '单次' = no scaling
function scaleIngredients(ingredients, volume) {
const targetDrops = VOLUME_DROPS[volume]
if (!targetDrops) return ingredients // 单次:不缩放
const totalDrops = ingredients.reduce((sum, ing) => sum + (ing.drops || 0), 0)
if (totalDrops === 0) return ingredients
return ingredients.map(ing => ({
...ing,
drops: Math.round(ing.drops * targetDrops / totalDrops),
}))
}
// Card ingredients: scaled to selected volume, coconut oil excluded from display
const scaledCardIngredients = computed(() =>
scaleIngredients(recipe.value.ingredients, selectedCardVolume.value)
)
// Coconut oil drops
const cardIngredients = computed(() =>
scaledCardIngredients.value.filter(ing => ing.oil !== '椰子油')
)
// Coconut oil drops (from scaled set)
const coconutDrops = computed(() => {
const coco = recipe.value.ingredients.find(ing => ing.oil === '椰子油')
const coco = scaledCardIngredients.value.find(ing => ing.oil === '椰子油')
return coco ? coco.drops : 0
})
@@ -420,7 +446,7 @@ const dilutionDesc = computed(() => {
: `该配方适用于单次用量(共${totalDrops}滴),其中纯精油 ${totalEoDrops.value} 滴,椰子油 ${coconutDrops.value} 滴,稀释比例为 1:${ratio}`
})
const priceInfo = computed(() => oilsStore.fmtCostWithRetail(recipe.value.ingredients))
const priceInfo = computed(() => oilsStore.fmtCostWithRetail(scaledCardIngredients.value))
// Today string
const todayStr = computed(() => {
@@ -451,6 +477,30 @@ async function loadBrand() {
} catch {
brand.value = {}
}
// Show upload prompt if user hasn't set up brand assets yet
if (showBrandHint.value) {
const ok = await showConfirm(
'上传你的专属二维码,让配方卡片更专业 ✨',
{ okText: '去上传', cancelText: '取消' }
)
if (ok) goUploadQr()
}
}
// 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(() => goUploadQr())
return
}
if (recipe.value._id) {
localStorage.setItem('oil_return_recipe_id', recipe.value._id)
}
router.push('/mydiary')
}
// ---- Card image generation ----
@@ -483,6 +533,12 @@ function switchLang(lang) {
nextTick(() => generateCardImage())
}
function onCardVolumeChange(ml) {
selectedCardVolume.value = ml
cardImageUrl.value = null
nextTick(() => generateCardImage())
}
async function saveImage() {
if (!cardImageUrl.value) {
await generateCardImage()
@@ -512,7 +568,7 @@ function copyText() {
].filter(Boolean).join('\n')
navigator.clipboard.writeText(text).then(() => {
ui.showToast('已复制到剪贴板')
ui.showToast('已复制')
}).catch(() => {
ui.showToast('复制失败')
})
@@ -554,7 +610,7 @@ function getCardRecipeName() {
// ---- Favorite ----
async function handleToggleFavorite() {
if (!authStore.isLoggedIn) {
ui.openLogin()
ui.openLogin(() => handleToggleFavorite())
return
}
if (!recipe.value._id) {
@@ -573,10 +629,10 @@ async function handleToggleFavorite() {
// ---- Save to diary ----
async function saveToDiary() {
if (!authStore.isLoggedIn) {
ui.openLogin()
ui.openLogin(() => saveToDiary())
return
}
const name = prompt('保存为我的配方,名称:', recipe.value.name)
const name = await showPrompt('保存为我的配方,名称:', recipe.value.name)
if (!name) return
try {
await api.post('/api/diary', {
@@ -801,6 +857,7 @@ async function saveRecipe() {
ingredients: ingredients.map(i => ({ oil_name: i.oil, drops: i.drops })),
}
await recipesStore.saveRecipe(payload)
// Reload recipes so the data is fresh when re-opened
await recipesStore.loadRecipes()
ui.showToast('保存成功')
emit('close')
@@ -941,32 +998,52 @@ async function saveRecipe() {
inset: 0;
width: 100%;
height: 100%;
object-fit: cover;
opacity: 0.06;
background-size: cover;
background-position: center;
background-repeat: no-repeat;
opacity: 0.12;
z-index: 0;
pointer-events: none;
}
.card-qr {
.card-qr-wrapper {
position: absolute;
top: 16px;
right: 16px;
width: 64px;
height: 64px;
object-fit: contain;
z-index: 3;
opacity: 0.85;
top: 36px;
right: 24px;
display: flex;
flex-direction: column;
align-items: center;
gap: 3px;
z-index: 2;
}
.card-qr {
width: 54px;
height: 54px;
object-fit: cover;
border-radius: 6px;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}
.card-qr-name {
font-size: 7px;
color: var(--text-light, #8a7a6a);
text-align: center;
line-height: 1.3;
max-width: 68px;
white-space: pre-line;
}
.card-logo {
position: absolute;
bottom: 16px;
bottom: 60px;
left: 50%;
transform: translateX(-50%);
height: 28px;
height: 60px;
object-fit: contain;
z-index: 3;
opacity: 0.3;
z-index: 1;
opacity: 0.2;
pointer-events: none;
}
.card-brand-text {
@@ -1146,6 +1223,42 @@ async function saveRecipe() {
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 {
display: flex;
@@ -1403,6 +1516,10 @@ async function saveRecipe() {
margin-bottom: 10px;
}
.card-volume-controls {
margin: 8px 0 12px;
}
.volume-btn {
padding: 7px 16px;
border: 1.5px solid var(--border, #e0d4c0);

View File

@@ -5,6 +5,8 @@ export const dialogState = reactive({
type: 'alert', // 'alert', 'confirm', 'prompt'
message: '',
defaultValue: '',
okText: '',
cancelText: '',
resolve: null
})
@@ -13,15 +15,19 @@ export function showAlert(msg) {
dialogState.visible = true
dialogState.type = 'alert'
dialogState.message = msg
dialogState.okText = ''
dialogState.cancelText = ''
dialogState.resolve = resolve
})
}
export function showConfirm(msg) {
export function showConfirm(msg, opts = {}) {
return new Promise(resolve => {
dialogState.visible = true
dialogState.type = 'confirm'
dialogState.message = msg
dialogState.okText = opts.okText || ''
dialogState.cancelText = opts.cancelText || ''
dialogState.resolve = resolve
})
}

View File

@@ -5,6 +5,7 @@ import { api } from '../composables/useApi'
export const DROPS_PER_ML = 18.6
export const VOLUME_DROPS = {
'单次': null,
'2.5': 46,
'5': 93,
'10': 186,

View File

@@ -5,6 +5,7 @@ export const useUiStore = defineStore('ui', () => {
const currentSection = ref('search')
const showLoginModal = ref(false)
const toasts = ref([])
const pendingAction = ref(null)
let toastId = 0
@@ -20,7 +21,10 @@ export const useUiStore = defineStore('ui', () => {
}, duration)
}
function openLogin() {
function openLogin(afterLogin) {
if (afterLogin) {
pendingAction.value = afterLogin
}
showLoginModal.value = true
}
@@ -28,13 +32,23 @@ export const useUiStore = defineStore('ui', () => {
showLoginModal.value = false
}
function runPendingAction() {
if (pendingAction.value) {
const action = pendingAction.value
pendingAction.value = null
action()
}
}
return {
currentSection,
showLoginModal,
toasts,
pendingAction,
showSection,
showToast,
openLogin,
closeLogin,
runPendingAction,
}
})

View File

@@ -107,6 +107,11 @@
<!-- Brand Tab -->
<div v-if="activeTab === 'brand'" class="tab-content">
<!-- Back to recipe card (when navigated from a recipe) -->
<div v-if="returnRecipeId" class="return-banner">
<span>📋 上传完成后可返回配方卡片</span>
<button class="btn-return" @click="goBackToRecipe"> 返回配方卡片</button>
</div>
<div class="section-card">
<h4>🏷 品牌设置</h4>
@@ -123,6 +128,18 @@
</div>
</div>
<div class="form-group">
<label>我的二维码图片</label>
<div class="qr-preview">
<div class="upload-area qr-upload-area" @click="triggerUpload('qr')">
<img v-if="brandQrImage" :src="brandQrImage" class="qr-img" />
<span v-else class="upload-hint">📲 点击上传</span>
</div>
</div>
<input ref="qrInput" type="file" accept="image/*" style="display:none" @change="handleUpload('qr', $event)" />
<div class="field-hint" style="text-align:center">上传后将显示在配方卡片右下角</div>
</div>
<div class="form-group">
<label>品牌Logo</label>
<div class="upload-area" @click="triggerUpload('logo')">
@@ -161,7 +178,7 @@
<div class="form-group">
<label>角色</label>
<div class="form-static role-badge">{{ roleLabel }}</div>
<div class="role-badge-display">{{ roleLabel }}</div>
</div>
</div>
@@ -202,6 +219,7 @@
<script setup>
import { ref, computed, onMounted, watch } from 'vue'
import { useRouter } from 'vue-router'
import { useAuthStore } from '../stores/auth'
import { useOilsStore } from '../stores/oils'
import { useDiaryStore } from '../stores/diary'
@@ -214,20 +232,24 @@ const auth = useAuthStore()
const oils = useOilsStore()
const diaryStore = useDiaryStore()
const ui = useUiStore()
const router = useRouter()
const activeTab = ref('brand')
const pasteText = ref('')
const selectedDiaryId = ref(null)
const returnRecipeId = ref(null)
const selectedDiary = ref(null)
const newEntryText = ref('')
// Brand settings
const brandName = ref('')
const brandQrUrl = ref('')
const brandQrImage = ref('')
const brandLogo = ref('')
const brandBg = ref('')
const logoInput = ref(null)
const bgInput = ref(null)
const qrInput = ref(null)
// Account settings
const displayName = ref('')
@@ -250,8 +272,16 @@ onMounted(async () => {
await diaryStore.loadDiary()
displayName.value = auth.user.display_name || ''
await loadBrandSettings()
returnRecipeId.value = localStorage.getItem('oil_return_recipe_id') || null
})
function goBackToRecipe() {
if (returnRecipeId.value) {
localStorage.removeItem('oil_return_recipe_id')
router.push('/?openRecipe=' + encodeURIComponent(returnRecipeId.value))
}
}
function selectDiary(d) {
const id = d._id || d.id
selectedDiaryId.value = id
@@ -345,8 +375,9 @@ async function loadBrandSettings() {
const data = await res.json()
brandName.value = data.brand_name || ''
brandQrUrl.value = data.qr_url || ''
brandLogo.value = data.logo_url || ''
brandBg.value = data.bg_url || ''
brandQrImage.value = data.qr_code || ''
brandLogo.value = data.brand_logo || ''
brandBg.value = data.brand_bg || ''
}
} catch {
// no brand settings yet
@@ -369,26 +400,35 @@ async function saveBrandSettings() {
function triggerUpload(type) {
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) {
const file = event.target.files[0]
if (!file) return
const formData = new FormData()
formData.append('file', file)
formData.append('type', type)
try {
const token = localStorage.getItem('oil_auth_token') || ''
const res = await fetch('/api/brand-upload', {
method: 'POST',
headers: token ? { Authorization: 'Bearer ' + token } : {},
body: formData,
const base64 = await readFileAsBase64(file)
const fieldMap = { logo: 'brand_logo', bg: 'brand_bg', qr: 'qr_code' }
const field = fieldMap[type]
if (!field) return
const res = await api('/api/brand', {
method: 'PUT',
body: JSON.stringify({ [field]: base64 }),
})
if (res.ok) {
const data = await res.json()
if (type === 'logo') brandLogo.value = data.url
else brandBg.value = data.url
if (type === 'logo') brandLogo.value = base64
else if (type === 'bg') brandBg.value = base64
else if (type === 'qr') brandQrImage.value = base64
ui.showToast('上传成功')
}
} catch {
@@ -718,6 +758,39 @@ async function applyBusiness() {
border-color: #7ec6a4;
}
/* Return banner */
.return-banner {
display: flex;
align-items: center;
justify-content: space-between;
background: #f0faf5;
border: 1.5px solid #7ec6a4;
border-radius: 12px;
padding: 10px 14px;
margin-bottom: 14px;
font-size: 13px;
color: #3e7d5a;
gap: 10px;
}
.btn-return {
background: linear-gradient(135deg, #7ec6a4 0%, #4a9d7e 100%);
color: #fff;
border: none;
border-radius: 8px;
padding: 6px 14px;
font-size: 12px;
cursor: pointer;
font-family: inherit;
font-weight: 500;
white-space: nowrap;
flex-shrink: 0;
}
.btn-return:hover {
opacity: 0.9;
}
/* Brand */
.form-group {
margin-bottom: 14px;
@@ -739,8 +812,14 @@ async function applyBusiness() {
color: #6b6375;
}
.role-badge {
.role-badge-display {
display: inline-block;
font-size: 12px;
padding: 3px 12px;
border-radius: 8px;
background: linear-gradient(135deg, #e8f5e9, #c8e6c9);
color: #4a9d7e;
font-weight: 500;
}
.qr-preview {
@@ -783,6 +862,20 @@ async function applyBusiness() {
max-height: 100px;
}
.qr-upload-area {
width: 120px;
height: 120px;
min-height: unset;
border-radius: 8px;
}
.field-hint {
font-size: 12px;
color: #9b94a3;
margin-top: 4px;
padding-left: 2px;
}
.upload-hint {
font-size: 13px;
color: #b0aab5;

View File

@@ -123,7 +123,8 @@
</template>
<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 { useOilsStore } from '../stores/oils'
import { useRecipesStore } from '../stores/recipes'
@@ -136,6 +137,8 @@ const auth = useAuthStore()
const oils = useOilsStore()
const recipeStore = useRecipesStore()
const ui = useUiStore()
const route = useRoute()
const router = useRouter()
const searchQuery = ref('')
const selectedCategory = ref(null)
@@ -154,6 +157,27 @@ onMounted(async () => {
} catch {
// 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) {