소스 검색

feat: update input event handling in PopupInput and adjust feeding plan calculations

IlhamTahir 1 개월 전
부모
커밋
53cf9d12ea
4개의 변경된 파일12개의 추가작업 그리고 6개의 파일을 삭제
  1. 1 1
      src/components/PopupInput.vue
  2. 2 1
      src/model/product.ts
  3. 8 4
      src/stores/feeding-plan.ts
  4. 1 0
      vite.config.ts

+ 1 - 1
src/components/PopupInput.vue

@@ -14,7 +14,7 @@ defineEmits<{
 
 <template>
   <view class="w-full flex items-center gap-2">
-    <input class="text-right" :value="modelValue" :placeholder="placeholder" @input="$emit('update:modelValue', modelValue)">
+    <input class="text-right" :value="modelValue" :placeholder="placeholder" @input="$emit('update:modelValue', $event.detail.value)">
     <text v-if="suffix">
       {{ suffix }}
     </text>

+ 2 - 1
src/model/product.ts

@@ -5,7 +5,8 @@ export interface Product extends BaseModel {
   category: ProductCategory
   photo: string
   tags: string[]
-  totalCalories: number
+  meValue: number | null // ME值(kcal/g),直接配置的代谢能
+  totalCalories: number // 产品总能量(kcal)
   totalWeight: number
 }
 export enum ProductCategory {

+ 8 - 4
src/stores/feeding-plan.ts

@@ -128,8 +128,9 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
       return 1.2
     }
 
+    // 未绝育成年猫/活跃:系数1.4(根据新规则从1.6调整为1.4)
     if (pet.value.isActive && !pet.value.isSterilization && ageInMonths > 12) {
-      return 1.6
+      return 1.4
     }
 
     if (feedingPlan.value.targetWeight < pet.value.weight) {
@@ -145,9 +146,12 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
 
   const rer = ref(0)
 
-  watch(() => pet.value.weight, () => {
-    feedingPlan.value.targetWeight = calculateIdealWeight()
-    rer.value = calculateRER(pet.value.weight)
+  // 监听体重和体型变化,重新计算理想体重和RER
+  // RER应该使用理想体重而不是当前体重
+  watch([() => pet.value.weight, () => pet.value.bodyType], () => {
+    const idealWeight = calculateIdealWeight()
+    feedingPlan.value.targetWeight = idealWeight
+    rer.value = calculateRER(idealWeight)
   })
 
   const feedingGoalOptions = [

+ 1 - 0
vite.config.ts

@@ -32,6 +32,7 @@ export default async ({ command, mode }) => {
       },
     },
     server: {
+      port: 5175,
       proxy: {
         '/api': {
           target: env.VITE_PROXY_ENDPOINT,