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 4s
PR Preview / test (pull_request) Successful in 4s
PR Preview / deploy-preview (pull_request) Successful in 15s
Test / e2e-test (push) Failing after 52s
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 52s
新增去重: - 新增配方保存前检查公共库和个人配方同名 - 完全相同提示已有,内容不同显示差异可改名 编辑者权限: - editor可编辑所有公共配方(前端+后端) - editor不能编辑精油价目(已有) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -73,10 +73,8 @@ export const useAuthStore = defineStore('auth', () => {
|
||||
user.value = { ...DEFAULT_USER }
|
||||
}
|
||||
|
||||
function canEditRecipe(recipe) {
|
||||
if (isAdmin.value || user.value.role === 'senior_editor') return true
|
||||
if (canEdit.value && recipe._owner_id === user.value.id) return true
|
||||
return false
|
||||
function canEditRecipe() {
|
||||
return canEdit.value
|
||||
}
|
||||
|
||||
return {
|
||||
|
||||
@@ -964,6 +964,38 @@ async function saveCurrentRecipe() {
|
||||
tags: formTags.value,
|
||||
}
|
||||
|
||||
// Dedup check for new recipes (not editing)
|
||||
if (!editingRecipe.value) {
|
||||
const name = formName.value.trim()
|
||||
// Check public library
|
||||
const pubDup = recipeStore.recipes.find(r => r.name === name)
|
||||
// Check personal diary
|
||||
const diaryDup = diaryStore.userDiary.find(d => d.name === name)
|
||||
const dup = pubDup || diaryDup
|
||||
if (dup) {
|
||||
const dupIngs = (dup.ingredients || []).filter(i => i.oil).sort((a, b) => a.oil.localeCompare(b.oil))
|
||||
const myIngs = cleanIngs.filter(i => i.oil).sort((a, b) => a.oil.localeCompare(b.oil))
|
||||
const identical = dupIngs.length === myIngs.length && dupIngs.every((ing, i) => ing.oil === myIngs[i].oil && ing.drops === myIngs[i].drops)
|
||||
const where = pubDup ? '公共配方库' : '我的配方'
|
||||
if (identical) {
|
||||
ui.showToast(`${where}中已有一模一样的配方「${name}」`)
|
||||
return
|
||||
}
|
||||
// Show difference
|
||||
const existIngs = dupIngs.map(i => `${i.oil}${i.drops}滴`).join('、')
|
||||
const newIngs = myIngs.map(i => `${i.oil}${i.drops}滴`).join('、')
|
||||
const ok = await showConfirm(
|
||||
`${where}中已有同名配方「${name}」,内容不同:\n\n已有:${existIngs}\n新的:${newIngs}\n\n是否改名后保存?`,
|
||||
{ okText: '改名', cancelText: '取消' }
|
||||
)
|
||||
if (!ok) return
|
||||
const newName = await showPrompt('请输入新名称:', name)
|
||||
if (!newName || !newName.trim()) return
|
||||
formName.value = newName.trim()
|
||||
diaryPayload.name = newName.trim()
|
||||
}
|
||||
}
|
||||
|
||||
if (editingRecipe.value && editingRecipe.value._diary_id) {
|
||||
// Editing an existing diary recipe
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user