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 4s
PR Preview / test (pull_request) Successful in 5s
PR Preview / deploy-preview (pull_request) Successful in 14s
Test / e2e-test (push) Failing after 55s

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-10 18:56:50 +00:00
parent a09cdcc60c
commit 3adcfc1169

View File

@@ -438,7 +438,7 @@ const newIngOil = ref('')
const newIngSearch = ref('') const newIngSearch = ref('')
const newIngDrops = ref(1) const newIngDrops = ref(1)
const newIngDropdownOpen = ref(false) const newIngDropdownOpen = ref(false)
const formVolume = ref('30') const formVolume = ref('')
const formCustomVolume = ref(null) const formCustomVolume = ref(null)
const formCustomUnit = ref('drops') const formCustomUnit = ref('drops')
const formDilution = ref(6) const formDilution = ref(6)
@@ -732,39 +732,8 @@ async function executeBatchAction(action) {
clearSelection() clearSelection()
} }
function calcDilutionFromIngs(ingredients) { function calcDilutionFromIngs() {
const ings = ingredients || [] // No default selection — user chooses
const coco = ings.find(i => i.oil === '椰子油')
const eoDrops = ings.filter(i => i.oil && i.oil !== '椰子油').reduce((s, i) => s + (i.drops || 0), 0)
const cocoDrops = coco ? (coco.drops || 0) : 0
const totalDrops = eoDrops + cocoDrops
// Set dilution ratio
if (eoDrops > 0 && cocoDrops > 0) {
const ratio = Math.round(cocoDrops / eoDrops)
// Clamp to available options
const options = [3,4,5,6,7,8,9,10,12,15,20]
formDilution.value = options.reduce((prev, curr) => Math.abs(curr - ratio) < Math.abs(prev - ratio) ? curr : prev)
}
// Set coconut drops for single mode
if (coco) {
formCocoRow.value.drops = cocoDrops
}
// Guess volume
if (!coco || cocoDrops === 0) {
formVolume.value = 'single'
} else {
const ml = totalDrops / DROPS_PER_ML
if (ml <= 2) formVolume.value = 'single'
else if (Math.abs(ml - 5) < 1.5) formVolume.value = '5'
else if (Math.abs(ml - 10) < 2.5) formVolume.value = '10'
else if (Math.abs(ml - 15) < 2.5) formVolume.value = '15'
else if (Math.abs(ml - 20) < 3) formVolume.value = '20'
else if (Math.abs(ml - 30) < 6) formVolume.value = '30'
else { formVolume.value = 'custom'; formCustomVolume.value = Math.round(ml) }
}
} }
function editRecipe(recipe) { function editRecipe(recipe) {
@@ -798,7 +767,7 @@ function resetForm() {
newIngOil.value = '' newIngOil.value = ''
newIngSearch.value = '' newIngSearch.value = ''
newIngDrops.value = 1 newIngDrops.value = 1
formVolume.value = '30' formVolume.value = ''
formCustomVolume.value = null formCustomVolume.value = null
formDilution.value = 6 formDilution.value = 6
} }