Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
飞
飞鹤小程序
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
FH
飞鹤小程序
Commits
ce7a6d75
Commit
ce7a6d75
authored
Jul 28, 2025
by
spc
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feeding fixed
parent
caf6d404
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
214 additions
and
59 deletions
+214
-59
feedingIndex.vue
pages/feedingIndex/feedingIndex.vue
+140
-44
feedingRecord.vue
pages/feedingRecord/feedingRecord.vue
+74
-15
No files found.
pages/feedingIndex/feedingIndex.vue
View file @
ce7a6d75
This diff is collapsed.
Click to expand it.
pages/feedingRecord/feedingRecord.vue
View file @
ce7a6d75
...
@@ -8,9 +8,13 @@
...
@@ -8,9 +8,13 @@
<view
class=
"nav-left"
>
<view
class=
"nav-left"
>
<image
:src=
"feedingRecordRes.icon_return"
class=
"back-btn"
@
click=
"goBack"
/>
<image
:src=
"feedingRecordRes.icon_return"
class=
"back-btn"
@
click=
"goBack"
/>
<image
:src=
"feedingRecordRes.icon_star"
class=
"baby-icon-star"
/>
<image
:src=
"feedingRecordRes.icon_star"
class=
"baby-icon-star"
/>
<view
class=
"baby-info"
@
click=
"showBabySwitch"
>
<view
class=
"baby-info"
@
click=
"showBabySwitch"
v-if=
"babyList.length > 1"
>
<text
class=
"baby-name"
>
{{
babyList
[
currentBabyIndex
].
name
}}
</text>
<text
class=
"baby-name"
>
{{
getCurrentBabyName
()
}}
</text>
<text
class=
"baby-age"
>
{{
calculateBabyAge
(
babyList
[
currentBabyIndex
].
birthday
)
}}
</text>
<text
class=
"baby-age"
>
{{
getCurrentBabyAge
()
}}
</text>
</view>
<view
class=
"baby-info"
v-else
>
<text
class=
"baby-name"
>
{{
getCurrentBabyName
()
}}
</text>
<text
class=
"baby-age"
>
{{
getCurrentBabyAge
()
}}
</text>
</view>
</view>
<image
:src=
"feedingRecordRes.icon_baby_change"
class=
"baby-icon-change"
/>
<image
:src=
"feedingRecordRes.icon_baby_change"
class=
"baby-icon-change"
/>
</view>
</view>
...
@@ -206,6 +210,7 @@
...
@@ -206,6 +210,7 @@
:baby-list=
"babyList"
:baby-list=
"babyList"
:selected-index=
"currentBabyIndex"
:selected-index=
"currentBabyIndex"
@
change=
"onBabyChange"
@
change=
"onBabyChange"
v-if=
"babyList.length > 1"
/>
/>
</template>
</template>
...
@@ -715,7 +720,10 @@ function goBack() {
...
@@ -715,7 +720,10 @@ function goBack() {
// 宝宝切换相关方法
// 宝宝切换相关方法
function
showBabySwitch
()
{
function
showBabySwitch
()
{
showBabySwitchPopup
.
value
=
true
// 只有当有多个宝宝时才显示切换弹窗
if
(
babyList
.
value
.
length
>
1
)
{
showBabySwitchPopup
.
value
=
true
}
}
}
function
onBabyChange
(
baby
,
index
)
{
function
onBabyChange
(
baby
,
index
)
{
...
@@ -737,18 +745,69 @@ function onBabyChange(baby, index) {
...
@@ -737,18 +745,69 @@ function onBabyChange(baby, index) {
}
}
function
calculateBabyAge
(
birthday
)
{
function
calculateBabyAge
(
birthday
)
{
const
birthDate
=
new
Date
(
birthday
)
// 检查生日参数是否有效
const
today
=
new
Date
()
if
(
!
birthday
)
{
const
diffTime
=
Math
.
abs
(
today
-
birthDate
)
return
'0天'
const
diffDays
=
Math
.
ceil
(
diffTime
/
(
1000
*
60
*
60
*
24
))
}
const
years
=
Math
.
floor
(
diffDays
/
365
)
const
days
=
diffDays
%
365
if
(
years
>
0
)
{
try
{
return
`
${
years
}
岁
${
days
}
天`
const
birthDate
=
new
Date
(
birthday
)
}
else
{
const
today
=
new
Date
()
return
`
${
days
}
天`
// 检查日期是否有效
if
(
isNaN
(
birthDate
.
getTime
())
||
isNaN
(
today
.
getTime
()))
{
console
.
warn
(
'无效的日期格式:'
,
birthday
)
return
'0天'
}
const
diffTime
=
Math
.
abs
(
today
-
birthDate
)
const
diffDays
=
Math
.
ceil
(
diffTime
/
(
1000
*
60
*
60
*
24
))
// 检查计算结果是否有效
if
(
isNaN
(
diffDays
)
||
diffDays
<
0
)
{
console
.
warn
(
'日期计算错误:'
,
{
birthday
,
diffDays
})
return
'0天'
}
const
years
=
Math
.
floor
(
diffDays
/
365
)
const
days
=
diffDays
%
365
if
(
years
>
0
)
{
return
`
${
years
}
岁
${
days
}
天`
}
else
{
return
`
${
days
}
天`
}
}
catch
(
error
)
{
console
.
error
(
'计算宝宝年龄时出错:'
,
error
,
birthday
)
return
'0天'
}
}
// 安全获取当前宝宝姓名
function
getCurrentBabyName
()
{
try
{
const
currentBaby
=
babyList
.
value
[
currentBabyIndex
.
value
]
if
(
currentBaby
&&
currentBaby
.
name
)
{
return
currentBaby
.
name
}
return
'宝宝'
}
catch
(
error
)
{
console
.
error
(
'获取宝宝姓名时出错:'
,
error
)
return
'宝宝'
}
}
// 安全获取当前宝宝年龄
function
getCurrentBabyAge
()
{
try
{
const
currentBaby
=
babyList
.
value
[
currentBabyIndex
.
value
]
if
(
currentBaby
&&
currentBaby
.
birthday
)
{
return
calculateBabyAge
(
currentBaby
.
birthday
)
}
return
'0天'
}
catch
(
error
)
{
console
.
error
(
'获取宝宝年龄时出错:'
,
error
)
return
'0天'
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment