Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
京东前端
nutui
提交
39cdfebb
N
nutui
项目概览
京东前端
/
nutui
通知
37
Star
4
Fork
1
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nutui
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
39cdfebb
编写于
3月 24, 2021
作者:
richard_1015
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'next' of
https://github.com/jdf2e/nutui
into next
上级
14e3a843
bc68015d
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
60 addition
and
44 deletion
+60
-44
src/packages/calendar/demo.vue
src/packages/calendar/demo.vue
+9
-9
src/packages/calendar/doc.md
src/packages/calendar/doc.md
+2
-1
src/packages/calendar/index.vue
src/packages/calendar/index.vue
+3
-3
src/packages/calendaritem/index.vue
src/packages/calendaritem/index.vue
+46
-31
未找到文件。
src/packages/calendar/demo.vue
浏览文件 @
39cdfebb
...
@@ -3,7 +3,7 @@
...
@@ -3,7 +3,7 @@
<h2>
基础用法
</h2>
<h2>
基础用法
</h2>
<div>
<div>
<nut-cell
<nut-cell
:show
I
con=
"true"
:show
-i
con=
"true"
title=
"选择单个日期"
title=
"选择单个日期"
:desc=
"date ? `$
{date} ${dateWeek}` : '请选择'"
:desc=
"date ? `$
{date} ${dateWeek}` : '请选择'"
@click="openSwitch('isVisible')"
@click="openSwitch('isVisible')"
...
@@ -22,7 +22,7 @@
...
@@ -22,7 +22,7 @@
<div>
<div>
<nut-cell
<nut-cell
:show
I
con=
"true"
:show
-i
con=
"true"
title=
"选择日期区间"
title=
"选择日期区间"
:desc=
"date1 ? `$
{date1[0]}至${date1[1]}` : '请选择'"
:desc=
"date1 ? `$
{date1[0]}至${date1[1]}` : '请选择'"
@click="openSwitch('isVisible1')"
@click="openSwitch('isVisible1')"
...
@@ -43,7 +43,7 @@
...
@@ -43,7 +43,7 @@
<h2>
自定义日历-自动回填
</h2>
<h2>
自定义日历-自动回填
</h2>
<div>
<div>
<nut-cell
<nut-cell
:show
I
con=
"true"
:show
-i
con=
"true"
title=
"选择日期"
title=
"选择日期"
:desc=
"date3 ? date3 : '请选择'"
:desc=
"date3 ? date3 : '请选择'"
@
click=
"openSwitch('isVisible3')"
@
click=
"openSwitch('isVisible3')"
...
@@ -107,29 +107,29 @@ export default createDemo({
...
@@ -107,29 +107,29 @@ export default createDemo({
isVisible3
:
false
,
isVisible3
:
false
,
date3
:
''
date3
:
''
});
});
const
openSwitch
=
param
=>
{
const
openSwitch
=
(
param
:
string
)
=>
{
state
[
`
${
param
}
`
]
=
true
;
state
[
`
${
param
}
`
]
=
true
;
};
};
const
closeSwitch
=
param
=>
{
const
closeSwitch
=
(
param
:
string
)
=>
{
state
[
`
${
param
}
`
]
=
false
;
state
[
`
${
param
}
`
]
=
false
;
};
};
const
setChooseValue
=
param
=>
{
const
setChooseValue
=
(
param
:
string
)
=>
{
state
.
date
=
param
[
3
];
state
.
date
=
param
[
3
];
state
.
dateWeek
=
param
[
4
];
state
.
dateWeek
=
param
[
4
];
};
};
const
setChooseValue1
=
param
=>
{
const
setChooseValue1
=
(
param
:
string
)
=>
{
state
.
date1
=
[...[
param
[
0
][
3
],
param
[
1
][
3
]]];
state
.
date1
=
[...[
param
[
0
][
3
],
param
[
1
][
3
]]];
};
};
const
setChooseValue2
=
param
=>
{
const
setChooseValue2
=
(
param
:
string
)
=>
{
state
.
date2
=
param
[
3
];
state
.
date2
=
param
[
3
];
console
.
log
(
state
.
date2
);
console
.
log
(
state
.
date2
);
};
};
const
setChooseValue3
=
param
=>
{
const
setChooseValue3
=
(
param
:
string
)
=>
{
state
.
date3
=
param
[
3
];
state
.
date3
=
param
[
3
];
};
};
...
...
src/packages/calendar/doc.md
浏览文件 @
39cdfebb
...
@@ -201,12 +201,13 @@ setup() {
...
@@ -201,12 +201,13 @@ setup() {
| poppable | 是否弹窗状态展示 | Boolean | true |
| poppable | 是否弹窗状态展示 | Boolean | true |
| is-auto-back-fill | 自动回填 | Boolean | false |
| is-auto-back-fill | 自动回填 | Boolean | false |
| title | 显示标题 | String | ‘日期选择’ |
| title | 显示标题 | String | ‘日期选择’ |
| default-value | 默认值,日期选择 String 格式,区间选择 Array 格式 | String
/
Array | null |
| default-value | 默认值,日期选择 String 格式,区间选择 Array 格式 | String
、
Array | null |
| start-date | 开始日期, 如果不限制开始日期传 null | String | 今天 |
| start-date | 开始日期, 如果不限制开始日期传 null | String | 今天 |
| end-date | 结束日期,如果不限制结束日期传 null | String | 距离今天 365 天 |
| end-date | 结束日期,如果不限制结束日期传 null | String | 距离今天 365 天 |
### Events
### Events
| 事件名 | 说明 | 回调参数 |
| 事件名 | 说明 | 回调参数 |
| ----------------- | --------------------- | -------------- |
| choose | 选择之后或是点击确认按钮触发 | 日期数组(包含年月日和星期)
| choose | 选择之后或是点击确认按钮触发 | 日期数组(包含年月日和星期)
| close | 关闭时触发 | -
| close | 关闭时触发 | -
src/packages/calendar/index.vue
浏览文件 @
39cdfebb
<
template
>
<
template
>
<nut-popup
<nut-popup
v-if=
"poppable"
v-if=
"poppable"
v-model:show=
"
state.
childIsVisible"
v-model:show=
"childIsVisible"
position=
"bottom"
position=
"bottom"
round
round
:closeable=
"true"
:closeable=
"true"
...
@@ -99,7 +99,7 @@ export default create({
...
@@ -99,7 +99,7 @@ export default create({
emit
(
'
close
'
);
emit
(
'
close
'
);
};
};
const
choose
=
param
=>
{
const
choose
=
(
param
:
string
)
=>
{
close
();
close
();
emit
(
'
choose
'
,
param
);
emit
(
'
choose
'
,
param
);
};
};
...
@@ -123,7 +123,7 @@ export default create({
...
@@ -123,7 +123,7 @@ export default create({
close
,
close
,
choose
,
choose
,
calendarRef
,
calendarRef
,
state
,
...
toRefs
(
state
)
,
...
toRefs
(
props
)
...
toRefs
(
props
)
};
};
}
}
...
...
src/packages/calendaritem/index.vue
浏览文件 @
39cdfebb
...
@@ -108,6 +108,16 @@ interface CalendarState {
...
@@ -108,6 +108,16 @@ interface CalendarState {
isRange
:
boolean
;
isRange
:
boolean
;
timer
:
number
;
timer
:
number
;
}
}
interface
Day
{
day
:
string
|
number
;
type
:
string
;
}
interface
MonthInfo
{
curData
:
string
[]
|
string
;
title
:
string
;
monthData
:
Day
[];
}
export
default
create
({
export
default
create
({
props
:
{
props
:
{
...
@@ -176,35 +186,35 @@ export default create({
...
@@ -176,35 +186,35 @@ export default create({
});
});
// 日期转化成数组
// 日期转化成数组
const
splitDate
=
date
=>
{
const
splitDate
=
(
date
:
string
)
=>
{
return
date
.
split
(
'
-
'
);
return
date
.
split
(
'
-
'
);
};
};
const
isStart
=
currDate
=>
{
const
isStart
=
(
currDate
:
string
)
=>
{
return
Utils
.
isEqual
(
state
.
currDate
[
0
],
currDate
);
return
Utils
.
isEqual
(
state
.
currDate
[
0
],
currDate
);
};
};
const
isEnd
=
currDate
=>
{
const
isEnd
=
(
currDate
:
string
)
=>
{
return
Utils
.
isEqual
(
state
.
currDate
[
1
],
currDate
);
return
Utils
.
isEqual
(
state
.
currDate
[
1
],
currDate
);
};
};
// 获取当前数据
// 获取当前数据
const
getCurrDate
=
(
day
,
month
,
isRange
?
)
=>
{
const
getCurrDate
=
(
day
:
Day
,
month
:
MonthInfo
,
isRange
?:
boolean
)
=>
{
return
isRange
return
isRange
?
month
.
curData
[
3
]
+
?
month
.
curData
[
3
]
+
'
-
'
+
'
-
'
+
month
.
curData
[
4
]
+
month
.
curData
[
4
]
+
'
-
'
+
'
-
'
+
Utils
.
getNumTwoBit
(
day
.
day
)
Utils
.
getNumTwoBit
(
+
day
.
day
)
:
month
.
curData
[
0
]
+
:
month
.
curData
[
0
]
+
'
-
'
+
'
-
'
+
month
.
curData
[
1
]
+
month
.
curData
[
1
]
+
'
-
'
+
'
-
'
+
Utils
.
getNumTwoBit
(
day
.
day
);
Utils
.
getNumTwoBit
(
+
day
.
day
);
};
};
// 获取样式
// 获取样式
const
getClass
=
(
day
,
month
,
isRange
?
)
=>
{
const
getClass
=
(
day
:
Day
,
month
:
MonthInfo
,
isRange
?:
boolean
)
=>
{
const
currDate
=
getCurrDate
(
day
,
month
,
isRange
);
const
currDate
=
getCurrDate
(
day
,
month
,
isRange
);
if
(
day
.
type
==
'
curr
'
)
{
if
(
day
.
type
==
'
curr
'
)
{
if
(
if
(
...
@@ -244,14 +254,19 @@ export default create({
...
@@ -244,14 +254,19 @@ export default create({
};
};
// 选中数据
// 选中数据
const
chooseDay
=
(
day
,
month
,
isFirst
,
isRange
?)
=>
{
const
chooseDay
=
(
day
:
Day
,
month
:
MonthInfo
,
isFirst
:
boolean
,
isRange
?:
boolean
)
=>
{
if
(
getClass
(
day
,
month
,
isRange
)
!=
`
${
state
.
dayPrefix
}
-disabled`
)
{
if
(
getClass
(
day
,
month
,
isRange
)
!=
`
${
state
.
dayPrefix
}
-disabled`
)
{
let
days
=
[...
month
.
curData
];
let
days
=
[...
month
.
curData
];
days
=
isRange
?
days
.
splice
(
3
)
:
days
.
splice
(
0
,
3
);
days
=
isRange
?
days
.
splice
(
3
)
:
days
.
splice
(
0
,
3
);
days
[
2
]
=
days
[
2
]
=
typeof
day
.
day
==
'
number
'
?
Utils
.
getNumTwoBit
(
day
.
day
)
:
day
.
day
;
typeof
day
.
day
==
'
number
'
?
Utils
.
getNumTwoBit
(
day
.
day
)
:
day
.
day
;
days
[
3
]
=
`
${
days
[
0
]}
-
${
days
[
1
]}
-
${
days
[
2
]}
`
;
days
[
3
]
=
`
${
days
[
0
]}
-
${
days
[
1
]}
-
${
days
[
2
]}
`
;
days
[
4
]
=
Utils
.
getWhatDay
(
days
[
0
],
days
[
1
],
days
[
2
]);
days
[
4
]
=
Utils
.
getWhatDay
(
+
days
[
0
],
+
days
[
1
],
+
days
[
2
]);
if
(
!
state
.
isRange
)
{
if
(
!
state
.
isRange
)
{
state
.
currDate
=
days
[
3
];
state
.
currDate
=
days
[
3
];
state
.
chooseData
=
[...
days
];
state
.
chooseData
=
[...
days
];
...
@@ -283,7 +298,7 @@ export default create({
...
@@ -283,7 +298,7 @@ export default create({
};
};
// 获取当前月数据
// 获取当前月数据
const
getCurrData
=
type
=>
{
const
getCurrData
=
(
type
:
string
)
=>
{
const
monthData
=
const
monthData
=
type
==
'
prev
'
type
==
'
prev
'
?
state
.
monthsData
[
0
]
?
state
.
monthsData
[
0
]
...
@@ -304,7 +319,7 @@ export default create({
...
@@ -304,7 +319,7 @@ export default create({
};
};
// 获取日期状态
// 获取日期状态
const
getDaysStatus
=
(
days
,
type
)
=>
{
const
getDaysStatus
=
(
days
:
number
,
type
:
string
)
=>
{
// 修复:当某个月的1号是周日时,月份下方会空出来一行
// 修复:当某个月的1号是周日时,月份下方会空出来一行
if
(
type
==
'
prev
'
&&
days
>=
7
)
{
if
(
type
==
'
prev
'
&&
days
>=
7
)
{
days
-=
7
;
days
-=
7
;
...
@@ -318,19 +333,19 @@ export default create({
...
@@ -318,19 +333,19 @@ export default create({
};
};
// 获取月数据
// 获取月数据
const
getMonth
=
(
curData
,
type
)
=>
{
const
getMonth
=
(
curData
:
string
[],
type
:
string
)
=>
{
const
preMonthDays
=
Utils
.
getMonthPreDay
(
curData
[
0
],
curData
[
1
]);
const
preMonthDays
=
Utils
.
getMonthPreDay
(
+
curData
[
0
],
+
curData
[
1
]);
const
currMonthDays
=
Utils
.
getMonthDays
(
curData
[
0
],
curData
[
1
]);
const
currMonthDays
=
Utils
.
getMonthDays
(
curData
[
0
],
curData
[
1
]);
const
title
=
{
const
title
=
{
year
:
curData
[
0
],
year
:
curData
[
0
],
month
:
curData
[
1
]
month
:
curData
[
1
]
};
};
const
monthInfo
=
{
const
monthInfo
:
MonthInfo
=
{
curData
:
curData
,
curData
:
curData
,
title
:
`
${
title
.
year
}
年
${
title
.
month
}
月`
,
title
:
`
${
title
.
year
}
年
${
title
.
month
}
月`
,
monthData
:
[
monthData
:
[
...
getDaysStatus
(
preMonthDays
,
'
prev
'
),
...
(
getDaysStatus
(
preMonthDays
,
'
prev
'
)
as
Day
[]
),
...
getDaysStatus
(
currMonthDays
,
'
curr
'
)
...
(
getDaysStatus
(
currMonthDays
,
'
curr
'
)
as
Day
[]
)
]
]
};
};
if
(
type
==
'
next
'
)
{
if
(
type
==
'
next
'
)
{
...
@@ -364,8 +379,8 @@ export default create({
...
@@ -364,8 +379,8 @@ export default create({
// 初始化数据
// 初始化数据
const
initData
=
()
=>
{
const
initData
=
()
=>
{
// 初始化开始结束数据
// 初始化开始结束数据
state
.
startData
=
props
.
startDate
?
splitDate
(
props
.
startDate
)
:
null
;
state
.
startData
=
props
.
startDate
?
splitDate
(
props
.
startDate
)
:
''
;
state
.
endData
=
props
.
endDate
?
splitDate
(
props
.
endDate
)
:
null
;
state
.
endData
=
props
.
endDate
?
splitDate
(
props
.
endDate
)
:
''
;
// 初始化当前日期
// 初始化当前日期
if
(
!
props
.
defaultValue
)
{
if
(
!
props
.
defaultValue
)
{
...
@@ -409,7 +424,7 @@ export default create({
...
@@ -409,7 +424,7 @@ export default create({
state
.
currDate
=
props
.
endDate
;
state
.
currDate
=
props
.
endDate
;
}
}
state
.
defaultData
=
[...
splitDate
(
state
.
currDate
)];
state
.
defaultData
=
[...
splitDate
(
state
.
currDate
as
string
)];
}
}
getMonth
(
state
.
defaultData
,
'
next
'
);
getMonth
(
state
.
defaultData
,
'
next
'
);
...
@@ -442,7 +457,7 @@ export default create({
...
@@ -442,7 +457,7 @@ export default create({
};
};
// 区间选择&&当前月&&选中态
// 区间选择&&当前月&&选中态
const
isActive
=
(
day
,
month
)
=>
{
const
isActive
=
(
day
:
Day
,
month
:
MonthInfo
)
=>
{
return
(
return
(
state
.
isRange
&&
state
.
isRange
&&
day
.
type
==
'
curr
'
&&
day
.
type
==
'
curr
'
&&
...
@@ -451,7 +466,7 @@ export default create({
...
@@ -451,7 +466,7 @@ export default create({
};
};
// 是否有开始提示
// 是否有开始提示
const
isStartTip
=
(
day
,
month
)
=>
{
const
isStartTip
=
(
day
:
Day
,
month
:
MonthInfo
)
=>
{
if
(
isActive
(
day
,
month
))
{
if
(
isActive
(
day
,
month
))
{
return
isStart
(
getCurrDate
(
day
,
month
));
return
isStart
(
getCurrDate
(
day
,
month
));
}
else
{
}
else
{
...
@@ -460,12 +475,12 @@ export default create({
...
@@ -460,12 +475,12 @@ export default create({
};
};
// 是否有结束提示
// 是否有结束提示
const
isEndTip
=
(
day
,
month
)
=>
{
const
isEndTip
=
(
day
:
Day
,
month
:
MonthInfo
)
=>
{
return
isActive
(
day
,
month
);
return
isActive
(
day
,
month
);
};
};
// 是否有是当前日期
// 是否有是当前日期
const
isCurrDay
=
(
month
,
day
)
=>
{
const
isCurrDay
=
(
month
:
any
,
day
:
string
)
=>
{
const
date
=
`
${
month
.
curData
[
0
]}
-
${
month
.
curData
[
1
]}
-
${
day
}
`
;
const
date
=
`
${
month
.
curData
[
0
]}
-
${
month
.
curData
[
1
]}
-
${
day
}
`
;
return
Utils
.
isEqual
(
date
,
Utils
.
date2Str
(
new
Date
()));
return
Utils
.
isEqual
(
date
,
Utils
.
date2Str
(
new
Date
()));
};
};
...
@@ -496,7 +511,7 @@ export default create({
...
@@ -496,7 +511,7 @@ export default create({
};
};
// 设置月份滚动距离和速度
// 设置月份滚动距离和速度
const
setTransform
=
(
translateY
=
0
,
type
?,
time
=
1000
)
=>
{
const
setTransform
=
(
translateY
=
0
,
type
?
:
string
,
time
=
1000
)
=>
{
if
(
monthsPanel
?.
value
)
{
if
(
monthsPanel
?.
value
)
{
if
(
type
===
'
end
'
)
{
if
(
type
===
'
end
'
)
{
monthsPanel
.
value
.
style
.
webkitTransition
=
`transform
${
time
}
ms cubic-bezier(0.19, 1, 0.22, 1)`
;
monthsPanel
.
value
.
style
.
webkitTransition
=
`transform
${
time
}
ms cubic-bezier(0.19, 1, 0.22, 1)`
;
...
@@ -514,7 +529,7 @@ export default create({
...
@@ -514,7 +529,7 @@ export default create({
};
};
// 计算滚动方向和距离
// 计算滚动方向和距离
const
setMove
=
(
move
,
type
?,
time
?
)
=>
{
const
setMove
=
(
move
:
number
,
type
?:
string
,
time
?:
number
)
=>
{
let
updateMove
=
move
+
state
.
transformY
;
let
updateMove
=
move
+
state
.
transformY
;
const
h
=
months
.
value
?.
offsetHeight
||
0
;
const
h
=
months
.
value
?.
offsetHeight
||
0
;
const
offsetHeight
=
monthsPanel
.
value
?.
offsetHeight
||
0
;
const
offsetHeight
=
monthsPanel
.
value
?.
offsetHeight
||
0
;
...
@@ -552,19 +567,19 @@ export default create({
...
@@ -552,19 +567,19 @@ export default create({
};
};
// 监听touch开始
// 监听touch开始
const
touchStart
=
event
=>
{
const
touchStart
=
(
event
:
TouchEvent
)
=>
{
const
changedTouches
=
event
.
changedTouches
[
0
];
const
changedTouches
=
event
.
changedTouches
[
0
];
state
.
touchParams
.
startY
=
changedTouches
.
pageY
;
state
.
touchParams
.
startY
=
changedTouches
.
pageY
;
state
.
touchParams
.
startTime
=
event
.
time
s
tamp
||
Date
.
now
();
state
.
touchParams
.
startTime
=
event
.
time
S
tamp
||
Date
.
now
();
state
.
transformY
=
state
.
scrollDistance
;
state
.
transformY
=
state
.
scrollDistance
;
};
};
// 监听touchmove
// 监听touchmove
const
touchMove
=
event
=>
{
const
touchMove
=
(
event
:
TouchEvent
)
=>
{
//event.preventDefault();
//event.preventDefault();
const
changedTouches
=
event
.
changedTouches
[
0
];
const
changedTouches
=
event
.
changedTouches
[
0
];
state
.
touchParams
.
lastY
=
changedTouches
.
pageY
;
state
.
touchParams
.
lastY
=
changedTouches
.
pageY
;
state
.
touchParams
.
lastTime
=
event
.
time
s
tamp
||
Date
.
now
();
state
.
touchParams
.
lastTime
=
event
.
time
S
tamp
||
Date
.
now
();
const
move
=
state
.
touchParams
.
lastY
-
state
.
touchParams
.
startY
;
const
move
=
state
.
touchParams
.
lastY
-
state
.
touchParams
.
startY
;
if
(
Math
.
abs
(
move
)
<
5
)
{
if
(
Math
.
abs
(
move
)
<
5
)
{
return
false
;
return
false
;
...
@@ -573,10 +588,10 @@ export default create({
...
@@ -573,10 +588,10 @@ export default create({
};
};
// 监听touchend
// 监听touchend
const
touchEnd
=
event
=>
{
const
touchEnd
=
(
event
:
TouchEvent
)
=>
{
const
changedTouches
=
event
.
changedTouches
[
0
];
const
changedTouches
=
event
.
changedTouches
[
0
];
state
.
touchParams
.
lastY
=
changedTouches
.
pageY
;
state
.
touchParams
.
lastY
=
changedTouches
.
pageY
;
state
.
touchParams
.
lastTime
=
event
.
time
s
tamp
||
Date
.
now
();
state
.
touchParams
.
lastTime
=
event
.
time
S
tamp
||
Date
.
now
();
let
move
=
state
.
touchParams
.
lastY
-
state
.
touchParams
.
startY
;
let
move
=
state
.
touchParams
.
lastY
-
state
.
touchParams
.
startY
;
if
(
Math
.
abs
(
move
)
<
5
)
{
if
(
Math
.
abs
(
move
)
<
5
)
{
return
false
;
return
false
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录