fix: bug修复

This commit is contained in:
ilhamtahir committed 2025-04-28 11:09:21 +08:00
1 parent 1dfddbf1da
commit 22f6bd7ff5
7 files changed
+53 -48

No files matched your search

+5 -1
View File
@@ -1,4 +1,4 @@
import type { CreatePetRequest, Pet } from '@/model/pet' import type { CreatePetRequest, Pet, PetVariety } from '@/model/pet'
import httpClient from '@/api/httpClient' import httpClient from '@/api/httpClient'
export function createPet(createPetRequest: CreatePetRequest) { export function createPet(createPetRequest: CreatePetRequest) {
@@ -8,3 +8,7 @@ export function createPet(createPetRequest: CreatePetRequest) {
export function getOwnPets() { export function getOwnPets() {
return httpClient.get<Pet[]>('/pets/own') return httpClient.get<Pet[]>('/pets/own')
} }
export function petVarietiesList() {
return httpClient.get<PetVariety[]>('/pet-varieties/list')
}
+4
View File
@@ -12,6 +12,10 @@ const emits = defineEmits<{
'update:modelValue': [string | number] 'update:modelValue': [string | number]
}>() }>()
if (props.options.length && !props.modelValue) {
emits('update:modelValue', props.options[0].value)
}
function bindPickerChange(e: { detail: { value: number | string } }) { function bindPickerChange(e: { detail: { value: number | string } }) {
const currentIndex = e.detail.value as number const currentIndex = e.detail.value as number
emits('update:modelValue', props.options[currentIndex].value) emits('update:modelValue', props.options[currentIndex].value)
+4 -36
View File
@@ -1,8 +1,5 @@
<script setup lang="ts"> <script setup lang="ts">
import type { UniPopupDialogInstance } from '@uni-helper/uni-types' withDefaults(defineProps<{
import type { UniPopupInstance } from '@uni-helper/uni-ui-types'
const props = withDefaults(defineProps<{
modelValue: string | number modelValue: string | number
placeholder?: string placeholder?: string
suffix?: string suffix?: string
@@ -10,47 +7,18 @@ const props = withDefaults(defineProps<{
placeholder: '请输入内容', placeholder: '请输入内容',
}) })
const emits = defineEmits<{ defineEmits<{
'update:modelValue': [string | number] 'update:modelValue': [string | number]
}>() }>()
const uniPopupRef = ref<UniPopupInstance | null>(null)
const uniPopupDialogRef = ref<UniPopupDialogInstance | null>(null)
function dialogInputConfirm(value: any) {
if (value === '') {
uni.showToast({
title: props.placeholder,
icon: 'none',
})
return
}
emits('update:modelValue', value as (string | number))
if (uniPopupRef.value && uniPopupRef.value.close) {
uniPopupRef.value.close()
}
}
function handleClick() {
if (uniPopupRef.value && uniPopupRef.value.open) {
uniPopupRef.value.open()
}
}
</script> </script>
<template> <template>
<view class="w-full" @click="handleClick"> <view class="w-full flex items-center gap-2">
{{ modelValue }} <input class="text-right" :value="modelValue" :placeholder="placeholder" @input="$emit('update:modelValue', modelValue)">
<text v-if="suffix"> <text v-if="suffix">
{{ suffix }} {{ suffix }}
</text> </text>
</view> </view>
<uni-popup ref="uniPopupRef" type="dialog">
<uni-popup-dialog
ref="uniPopupDialogRef" mode="input" title="输入内容" :value="modelValue" :placeholder="placeholder"
@confirm="dialogInputConfirm"
/>
</uni-popup>
</template> </template>
<style scoped> <style scoped>
+5
View File
@@ -14,6 +14,7 @@ export interface Pet extends TraceableModel {
type: PetType type: PetType
weight: number weight: number
feedingPlan: FeedingPlan feedingPlan: FeedingPlan
varietyName: string
} }
export interface CreatePetRequest extends Omit<Pet, keyof TraceableModel> { export interface CreatePetRequest extends Omit<Pet, keyof TraceableModel> {
@@ -66,3 +67,7 @@ export interface CreateFeedingPlanRequest extends Omit<FeedingPlan, keyof BaseMo
petId: string petId: string
products: { id: string, dailyUsageWeight: number, percentage: number }[] products: { id: string, dailyUsageWeight: number, percentage: number }[]
} }
export interface PetVariety extends BaseModel {
name: string
}
+1 -5
View File
@@ -58,11 +58,7 @@ function reset() {
function handleReady() { function handleReady() {
reset() reset()
titleName.value = '喂养问卷' titleName.value = '喂养问卷'
controlFormDisplay.value.display2 = true controlFormDisplay.value.display3 = true
setTimeout(() => {
reset()
controlFormDisplay.value.display3 = true
}, 2000)
} }
function handleBackFeedStart() { function handleBackFeedStart() {
reset() reset()
+14 -5
View File
@@ -9,12 +9,18 @@ import ToolApi from '@/utils'
const safeHeight = ToolApi.getSafeHeight() const safeHeight = ToolApi.getSafeHeight()
const feedSloganBottom = ref<number>(13) const feedSloganBottom = ref<number>(13)
function handleNext() {
uni.navigateTo({ url: '/pages/feed-questionnaire/index' })
}
const feedingPlanStore = useFeedingPlanStore() const feedingPlanStore = useFeedingPlanStore()
function handleNext() {
if (!feedingPlanStore.pet.varietyName) {
uni.showToast({
title: '请选择品种',
icon: 'error',
})
return
}
uni.navigateTo({ url: '/pages/feed-questionnaire/index' })
}
const disabled = computed(() => { const disabled = computed(() => {
return feedingPlanStore.pet.type === PetType.DOG return feedingPlanStore.pet.type === PetType.DOG
}) })
@@ -35,9 +41,12 @@ const disabled = computed(() => {
</Cell> </Cell>
</CellGroup> </CellGroup>
<CellGroup class="w-full bg-[#fff] shadow-cell-group rounded-3 overflow-hidden"> <CellGroup class="w-full bg-[#fff] shadow-cell-group rounded-3 overflow-hidden">
<Cell title="品种" border> <Cell title="类别" border>
<PickerItem v-model="feedingPlanStore.pet.type" :options="feedingPlanStore.petTypeOptions" /> <PickerItem v-model="feedingPlanStore.pet.type" :options="feedingPlanStore.petTypeOptions" />
</Cell> </Cell>
<Cell title="品种" border>
<PickerItem v-model="feedingPlanStore.pet.varietyName" :options="feedingPlanStore.petVarietiesOptions" />
</Cell>
<Cell title="性别" border> <Cell title="性别" border>
<PickerItem v-model="feedingPlanStore.pet.gender" :options="feedingPlanStore.genderOptions" /> <PickerItem v-model="feedingPlanStore.pet.gender" :options="feedingPlanStore.genderOptions" />
</Cell> </Cell>
+20 -1
View File
@@ -1,7 +1,7 @@
import type { FeedingPlanProduct } from '@/model/feeding-plan' import type { FeedingPlanProduct } from '@/model/feeding-plan'
import type { Product } from '@/model/product' import type { Product } from '@/model/product'
import { createFeedingPlan, updateFeedingPlan } from '@/api/feeding-plan' import { createFeedingPlan, updateFeedingPlan } from '@/api/feeding-plan'
import { createPet } from '@/api/pet' import { createPet, petVarietiesList } from '@/api/pet'
import { import {
type CreateFeedingPlanRequest, type CreateFeedingPlanRequest,
type CreatePetRequest, type CreatePetRequest,
@@ -25,6 +25,23 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
{ value: Gender.FEMALE, label: '女孩' }, { value: Gender.FEMALE, label: '女孩' },
] ]
const petVarietiesOptions = ref<{
value: string
label: string
}[]>([])
const fetchPetVarieties = async () => {
const result = await petVarietiesList()
petVarietiesOptions.value = result.map((item) => {
return {
value: item.name,
label: item.name,
}
})
}
fetchPetVarieties()
const dailyCalories = ref(400) const dailyCalories = ref(400)
// @ts-expect-error @ts-ignore // @ts-expect-error @ts-ignore
const pet = ref <CreatePetRequest>({ const pet = ref <CreatePetRequest>({
@@ -39,6 +56,7 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
photo: '', photo: '',
type: PetType.CAT, type: PetType.CAT,
weight: 0, weight: 0,
varietyName: '',
}) })
const savedPet = ref<Pet | null>(null) const savedPet = ref<Pet | null>(null)
@@ -326,5 +344,6 @@ export const useFeedingPlanStore = defineStore('feeding-plan', () => {
confirm, confirm,
initPet, initPet,
initFeedingPlan, initFeedingPlan,
petVarietiesOptions,
} }
}) })