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
5cbb97a3
Commit
5cbb97a3
authored
Jun 09, 2025
by
tao.huang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 修复日期默认
parent
c8b89655
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
5 deletions
+50
-5
PickerCustom.vue
components/PickerCustom.vue
+49
-4
person.vue
pages/person/person.vue
+1
-1
No files found.
components/PickerCustom.vue
View file @
5cbb97a3
...
...
@@ -118,6 +118,17 @@ const futureYear = futureDate.getFullYear();
const
futureMonth
=
futureDate
.
getMonth
()
+
1
;
const
futureDay
=
futureDate
.
getDate
();
// 工具函数:根据日期字符串获取索引
function
getPickerIndexByDate
(
dateStr
)
{
if
(
!
dateStr
)
return
null
;
const
[
year
,
month
,
day
]
=
dateStr
.
split
(
'-'
).
map
(
Number
);
const
yearIdx
=
years
.
value
.
findIndex
(
y
=>
y
===
year
);
const
monthIdx
=
months
.
value
.
findIndex
(
m
=>
m
===
month
);
const
dayIdx
=
days
.
value
.
findIndex
(
d
=>
d
===
day
);
if
(
yearIdx
<
0
||
monthIdx
<
0
||
dayIdx
<
0
)
return
null
;
return
[
yearIdx
,
monthIdx
,
dayIdx
];
}
const
years
=
computed
(()
=>
{
const
arr
=
[];
const
startYear
=
currentYear
-
3
;
...
...
@@ -184,8 +195,43 @@ const columns = computed(() => {
const
defaultValue
=
computed
(()
=>
{
if
(
props
.
mode
===
"date"
)
{
// 默认选中今年1月1日
return
[
years
.
value
.
length
-
1
,
0
,
0
];
console
.
log
(
"defaultValue"
,
props
.
value
);
// 1. value为索引数组
if
(
Array
.
isArray
(
props
.
value
)
&&
props
.
value
.
length
===
3
)
{
return
props
.
value
;
}
// 2. value为日期字符串
if
(
typeof
props
.
value
===
"string"
&&
props
.
value
.
match
(
/^
\d
{4
}
-
\d
{2
}
-
\d
{2
}
$/
))
{
const
idxArr
=
getPickerIndexByDate
(
props
.
value
);
if
(
idxArr
)
return
idxArr
;
}
// 3. 默认选中今天
const
yearIdx
=
years
.
value
.
findIndex
(
y
=>
y
===
currentYear
);
// 直接用当前年推算可用月份
let
tempMonths
=
[];
let
startMonth
=
1
,
endMonth
=
12
;
if
(
yearIdx
===
0
)
startMonth
=
currentMonth
;
if
(
yearIdx
===
years
.
value
.
length
-
1
)
endMonth
=
futureMonth
;
for
(
let
i
=
startMonth
;
i
<=
endMonth
;
i
++
)
tempMonths
.
push
(
i
);
const
monthIdx
=
tempMonths
.
findIndex
(
m
=>
m
===
currentMonth
);
// days
let
tempDays
=
[
"请选择"
];
if
(
yearIdx
>=
0
&&
monthIdx
>=
0
)
{
const
selectedYear
=
years
.
value
[
yearIdx
];
const
selectedMonth
=
tempMonths
[
monthIdx
];
const
dayCount
=
new
Date
(
selectedYear
,
selectedMonth
,
0
).
getDate
();
let
startDay
=
1
,
endDay
=
dayCount
;
if
(
yearIdx
===
0
&&
selectedMonth
===
currentMonth
)
startDay
=
currentDay
;
if
(
yearIdx
===
years
.
value
.
length
-
1
&&
selectedMonth
===
futureMonth
)
endDay
=
futureDay
;
for
(
let
i
=
startDay
;
i
<=
endDay
;
i
++
)
tempDays
.
push
(
i
);
}
const
dayIdx
=
tempDays
.
findIndex
(
d
=>
d
===
currentDay
);
return
[
yearIdx
>=
0
?
yearIdx
:
0
,
monthIdx
>=
0
?
monthIdx
:
0
,
dayIdx
>=
0
?
dayIdx
:
0
,
];
}
else
if
(
Array
.
isArray
(
props
.
value
))
{
return
props
.
value
;
}
else
{
...
...
@@ -199,7 +245,7 @@ watch(
()
=>
props
.
value
,
(
val
)
=>
{
if
(
props
.
mode
===
"date"
)
{
pickerValue
.
value
=
[...
val
];
pickerValue
.
value
=
[...
defaultValue
.
value
];
}
else
if
(
Array
.
isArray
(
val
))
{
pickerValue
.
value
=
[...
val
];
}
else
{
...
...
@@ -211,7 +257,6 @@ watch(
function
open
()
{
if
(
props
.
disabled
)
return
;
pickerValue
.
value
=
[...
defaultValue
.
value
];
show
.
value
=
true
;
props
.
onLayerVisibleChange
(
true
);
}
...
...
pages/person/person.vue
View file @
5cbb97a3
...
...
@@ -96,7 +96,7 @@
v-else-if=
"item.type === 'picker'"
:mode=
"item.mode"
:range=
"item.range"
:value=
"getPickerIndex(item)"
:value=
"
item.mode === 'date' ? formData[item.name] :
getPickerIndex(item)"
:onPickerChange=
"(e) => onPickerChange(e, item.name)"
:onLayerVisibleChange=
"(e) => (pageStatus.btnStatus = !e)"
:onStatusChange=
"onDateStatusChange"
...
...
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