Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
京东前端
nutui-react
提交
45744196
N
nutui-react
项目概览
京东前端
/
nutui-react
通知
0
Star
2
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
N
nutui-react
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
45744196
编写于
11月 08, 2021
作者:
Y
yewenwen3
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feat: 返回顶部增加动画过渡
上级
f49cfaa7
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
284 addition
and
34 deletion
+284
-34
src/packages/backtop/backtop.tsx
src/packages/backtop/backtop.tsx
+4
-7
src/packages/toast/Notification-copy.tsx
src/packages/toast/Notification-copy.tsx
+144
-0
src/packages/toast/Notification.tsx
src/packages/toast/Notification.tsx
+3
-3
src/packages/toast/toast-copy.tsx
src/packages/toast/toast-copy.tsx
+119
-0
src/packages/toast/toast.tsx
src/packages/toast/toast.tsx
+14
-24
未找到文件。
src/packages/backtop/backtop.tsx
浏览文件 @
45744196
...
...
@@ -52,8 +52,8 @@ export const BackTop: FunctionComponent<Partial<BackTopProps>> = (props) => {
}
const
[
backTop
,
SetBackTop
]
=
useState
(
false
)
const
[
scrollTop
,
SetScrollTop
]
=
useState
(
0
)
const
[
startTime
,
SetStartTime
]
=
useState
(
0
)
let
scrollEl
:
any
=
elId
?
useRef
<
HTMLElement
>
(
document
.
getElementById
(
elId
)
)
:
(
window
as
Window
)
let
startTime
=
0
let
scrollEl
:
any
=
elId
?
document
.
getElementById
(
elId
)
:
(
window
as
Window
)
//初始化
useEffect
(()
=>
{
init
()
...
...
@@ -85,9 +85,7 @@ export const BackTop: FunctionComponent<Partial<BackTopProps>> = (props) => {
if
(
scrollEl
instanceof
Window
)
{
window
.
scrollTo
(
0
,
y
)
}
else
{
let
dom
=
document
.
getElementById
(
elId
)
dom
?.
scrollTo
(
0
,
y
)
// scrollEl.scrollTop = y
scrollEl
.
scrollTop
=
y
}
}
...
...
@@ -95,7 +93,6 @@ export const BackTop: FunctionComponent<Partial<BackTopProps>> = (props) => {
let
cid
=
requestAniFrame
()(
function
fn
()
{
var
t
=
duration
-
Math
.
max
(
0
,
startTime
-
+
new
Date
()
+
duration
)
var
y
=
(
t
*
-
scrollTop
)
/
duration
+
scrollTop
// console.log('animi', t, y, startTime, duration, scrollTop)
scroll
(
y
)
cid
=
requestAniFrame
()(
fn
)
if
(
t
==
duration
||
y
==
0
)
{
...
...
@@ -132,7 +129,7 @@ export const BackTop: FunctionComponent<Partial<BackTopProps>> = (props) => {
const
goTop
=
(
e
:
any
)
=>
{
backTopClick
(
e
)
let
otime
=
+
new
Date
()
SetStartTime
(
otime
)
startTime
=
otime
isAnimation
&&
duration
>
0
?
scrollAnimation
()
:
scroll
()
}
...
...
src/packages/toast/Notification-copy.tsx
0 → 100644
浏览文件 @
45744196
import
*
as
React
from
'
react
'
import
*
as
ReactDOM
from
'
react-dom
'
import
bem
from
'
@/utils/bem
'
import
Icon
from
'
../icon/index
'
import
'
./toast.scss
'
export
interface
NotificationProps
{
prefixCls
?:
string
style
?:
React
.
CSSProperties
icon
?:
string
msg
:
string
|
React
.
ReactNode
bottom
?:
boolean
duration
?:
number
center
:
boolean
type
:
string
customClass
:
string
size
:
string
|
number
textAlignCenter
:
boolean
loadingRotate
:
boolean
bgColor
:
string
cover
:
boolean
coverColor
:
string
closeOnClickOverlay
:
boolean
onClose
:
()
=>
void
className
?:
string
}
interface
State
{
show
:
boolean
}
export
default
class
Notification
extends
React
.
PureComponent
<
NotificationProps
,
State
>
{
static
defaultProps
=
{
// prefixCls: 'nut-toast',
style
:
{},
show
:
false
,
duration
:
3
,
msg
:
''
,
id
:
''
,
center
:
true
,
// 未实现
type
:
'
text
'
,
customClass
:
''
,
// 未实现
bottom
:
30
,
// 未实现
size
:
'
base
'
,
// 未实现
icon
:
null
,
// 未实现
textAlignCenter
:
true
,
// 未实现
loadingRotate
:
true
,
// 未实现
bgColor
:
'
rgba(0, 0, 0, .8)
'
,
onClose
:
null
,
// 未实现
cover
:
false
,
//透明遮罩层 // 未实现
coverColor
:
'
rgba(0, 0, 0, 0)
'
,
// 未实现
closeOnClickOverlay
:
false
,
// 未实现
}
private
closeTimer
:
number
|
undefined
static
newInstance
:
(
properties
:
NotificationProps
,
callback
:
any
)
=>
void
constructor
(
props
:
NotificationProps
)
{
super
(
props
)
this
.
close
=
this
.
close
.
bind
(
this
)
this
.
startCloseTimer
=
this
.
startCloseTimer
.
bind
(
this
)
this
.
clearCloseTimer
=
this
.
clearCloseTimer
.
bind
(
this
)
this
.
close
=
this
.
close
.
bind
(
this
)
this
.
state
=
{
show
:
true
,
}
}
close
()
{
this
.
setState
({
show
:
false
,
})
this
.
clearCloseTimer
()
this
.
props
.
onClose
()
}
startCloseTimer
()
{
const
{
duration
}
=
this
.
props
if
(
duration
)
{
this
.
closeTimer
=
window
.
setTimeout
(()
=>
{
this
.
close
()
},
duration
*
1000
)
}
}
clearCloseTimer
()
{
if
(
this
.
closeTimer
)
{
clearTimeout
(
this
.
closeTimer
)
this
.
closeTimer
=
-
1
}
}
componentDidMount
()
{
this
.
startCloseTimer
()
}
componentWillUnmount
()
{
this
.
clearCloseTimer
()
}
render
()
{
const
{
style
,
icon
,
msg
,
bottom
}
=
this
.
props
const
{
show
}
=
this
.
state
const
toastBem
=
bem
(
'
toast
'
)
return
(
<>
<
div
className
=
{
toastBem
()
}
style
=
{
{
bottom
:
'
auto
'
,
backgroundColor
:
'
rgba(0, 0, 0, 0)
'
}
}
>
<
div
className
=
{
toastBem
(
'
inner
'
)
}
style
=
{
{
bottom
:
'
auto
'
,
backgroundColor
:
'
rgba(0, 0, 0, .8)
'
}
}
>
{
icon
?
(
<
p
className
=
{
toastBem
(
'
icon-wrapper
'
)
}
>
<
Icon
name
=
{
icon
?
icon
:
''
}
size
=
"20"
/>
</
p
>
)
:
null
}
<
span
className
=
{
toastBem
(
'
text
'
)
}
>
{
msg
}
</
span
>
</
div
>
</
div
>
</>
)
}
}
Notification
.
newInstance
=
(
properties
,
callback
)
=>
{
const
element
=
document
.
createElement
(
'
div
'
)
document
.
body
.
appendChild
(
element
)
let
called
=
false
function
ref
(
instance
:
any
)
{
if
(
called
)
{
return
}
called
=
true
callback
({
component
:
instance
,
destroy
()
{
ReactDOM
.
unmountComponentAtNode
(
element
)
element
&&
element
.
parentNode
&&
element
.
parentNode
.
removeChild
(
element
)
},
})
}
ReactDOM
.
render
(<
Notification
{
...
properties
}
ref
=
{
ref
}
/>,
element
)
}
src/packages/toast/Notification.tsx
浏览文件 @
45744196
...
...
@@ -7,7 +7,7 @@ export interface NotificationProps {
prefixCls
?:
string
style
?:
React
.
CSSProperties
icon
?:
string
m
essage
:
string
|
React
.
ReactNode
m
sg
:
string
|
React
.
ReactNode
bottom
?:
boolean
duration
?:
number
onClose
:
()
=>
void
...
...
@@ -72,7 +72,7 @@ export default class Notification extends React.PureComponent<NotificationProps,
}
render
()
{
const
{
style
,
icon
,
m
essage
,
bottom
}
=
this
.
props
const
{
style
,
icon
,
m
sg
,
bottom
}
=
this
.
props
const
{
show
}
=
this
.
state
const
toastBem
=
bem
(
'
toast
'
)
return
(
...
...
@@ -88,7 +88,7 @@ export default class Notification extends React.PureComponent<NotificationProps,
</
p
>
)
:
null
}
<
span
className
=
{
toastBem
(
'
text
'
)
}
>
{
m
essage
}
</
span
>
<
span
className
=
{
toastBem
(
'
text
'
)
}
>
{
m
sg
}
</
span
>
</
div
>
</
div
>
</>
...
...
src/packages/toast/toast-copy.tsx
0 → 100644
浏览文件 @
45744196
import
*
as
React
from
'
react
'
import
Icon
from
'
../icon/index
'
import
Notification
,
{
NotificationProps
}
from
'
./Notification
'
import
classNames
from
'
classnames
'
// const { JiaZai } = Icon
let
messageInstance
:
any
=
null
interface
IToastOptions
{
id
:
string
msg
:
string
duration
:
number
center
:
boolean
type
:
string
customClass
:
string
bottom
:
number
size
:
string
|
number
icon
:
string
textAlignCenter
:
boolean
loadingRotate
:
boolean
bgColor
:
string
onClose
:
Function
cover
:
boolean
coverColor
:
string
closeOnClickOverlay
:
boolean
}
// const SHORT = 3//展示秒数
const
options
:
IToastOptions
=
{
msg
:
''
,
id
:
''
,
duration
:
1.5
,
center
:
true
,
// 未实现
type
:
'
text
'
,
customClass
:
''
,
// 未实现
bottom
:
30
,
// 未实现
size
:
'
base
'
,
// 未实现
icon
:
''
,
// 未实现
textAlignCenter
:
true
,
// 未实现
loadingRotate
:
true
,
// 未实现
bgColor
:
'
rgba(0, 0, 0, .8)
'
,
onClose
:
()
=>
{},
// 未实现
cover
:
false
,
//透明遮罩层 // 未实现
coverColor
:
'
rgba(0, 0, 0, 0)
'
,
// 未实现
closeOnClickOverlay
:
false
,
// 未实现
}
function
getInstance
(
props
:
NotificationProps
,
callback
:
(
notification
:
any
)
=>
void
)
{
if
(
messageInstance
)
{
messageInstance
.
destroy
()
messageInstance
=
null
}
Notification
.
newInstance
(
props
,
(
notification
:
any
)
=>
{
return
callback
&&
callback
(
notification
)
})
}
function
notice
(
msg
:
string
|
React
.
ReactNode
,
icon
:
any
,
duration
=
options
.
duration
,
onClose
:
(()
=>
void
)
|
undefined
|
null
)
{
function
close
()
{
if
(
messageInstance
)
{
messageInstance
.
destroy
()
messageInstance
=
null
}
if
(
onClose
)
{
onClose
()
}
}
getInstance
(
{
msg
,
icon
,
duration
,
onClose
:
close
,
},
(
notification
:
any
)
=>
{
messageInstance
=
notification
}
)
}
export
default
{
text
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
null
,
duration
,
onClose
)
},
success
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
icon
?
icon
:
'
success
'
,
duration
,
onClose
)
},
fail
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
icon
?
icon
:
'
failure
'
,
duration
,
onClose
)
},
loading
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
icon
?
icon
:
'
loading
'
,
duration
,
onClose
)
},
warn
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
icon
?
icon
:
'
tips
'
,
duration
,
onClose
)
},
customIcon
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
icon
?
icon
:
null
,
duration
,
onClose
)
},
hide
()
{
if
(
messageInstance
)
{
messageInstance
.
destroy
()
messageInstance
=
null
}
},
config
(
option
:
Partial
<
IToastOptions
>
=
{})
{
const
{
duration
=
2
}
=
option
options
.
duration
=
duration
},
}
src/packages/toast/toast.tsx
浏览文件 @
45744196
...
...
@@ -23,7 +23,7 @@ function getInstance(props: NotificationProps, callback: (notification: any) =>
}
function
notice
(
m
essage
:
string
|
React
.
ReactNode
,
m
sg
:
string
|
React
.
ReactNode
,
icon
:
any
,
duration
=
options
.
duration
,
onClose
:
(()
=>
void
)
|
undefined
|
null
...
...
@@ -40,7 +40,7 @@ function notice(
getInstance
(
{
m
essage
,
m
sg
,
icon
,
duration
,
onClose
:
close
,
...
...
@@ -54,38 +54,28 @@ function notice(
export
default
{
SHORT
,
LONG
:
8
,
text
(
m
essage
:
string
|
React
.
ReactNode
,
duration
?:
number
,
onClose
?:
()
=>
void
)
{
return
notice
(
m
essage
,
null
,
duration
,
onClose
)
text
(
m
sg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
onClose
?:
()
=>
void
)
{
return
notice
(
m
sg
,
null
,
duration
,
onClose
)
},
success
(
message
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
message
,
icon
?
icon
:
'
success
'
,
duration
,
onClose
)
success
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
icon
?
icon
:
'
success
'
,
duration
,
onClose
)
},
fail
(
m
essage
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
m
essage
,
icon
?
icon
:
'
failure
'
,
duration
,
onClose
)
fail
(
m
sg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
m
sg
,
icon
?
icon
:
'
failure
'
,
duration
,
onClose
)
},
loading
(
message
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
message
,
icon
?
icon
:
'
loading
'
,
duration
,
onClose
)
loading
(
msg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
msg
,
icon
?
icon
:
'
loading
'
,
duration
,
onClose
)
},
warn
(
m
essage
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
m
essage
,
icon
?
icon
:
'
tips
'
,
duration
,
onClose
)
warn
(
m
sg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
m
sg
,
icon
?
icon
:
'
tips
'
,
duration
,
onClose
)
},
customIcon
(
m
essage
:
string
|
React
.
ReactNode
,
m
sg
:
string
|
React
.
ReactNode
,
duration
?:
number
,
icon
?:
string
,
onClose
?:
()
=>
void
)
{
return
notice
(
m
essage
,
icon
?
icon
:
null
,
duration
,
onClose
)
return
notice
(
m
sg
,
icon
?
icon
:
null
,
duration
,
onClose
)
},
hide
()
{
if
(
messageInstance
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录