@@ -1,40 +1,66 @@
< template >
< div class = "notice-bar" : style = "{ background, height: `${height}px` }" v-show = "!isMode" >
< div
class = "notice-bar"
: style = "{ background, height: `${height}px` }"
v-show = "!isMode"
>
< div class = "notice-bar-warp" : style = "{ color, fontSize: `${size}px` }" >
< lay-icon v-if = "leftIcon" class="notice-bar-warp-left-icon" :type="leftIcon" > < / lay -icon >
< lay-icon
v-if = "leftIcon"
class = "notice-bar-warp-left-icon"
:type = "leftIcon"
> < / lay-icon >
< div class = "notice-bar-warp-text-box" ref = "noticeBarWarpRef" >
< div class = "notice-bar-warp-text" ref = "noticeBarTextRef" v-if = "!scrollable" > {{ text }} < / div >
< div
class = "notice-bar-warp-text"
ref = "noticeBarTextRef"
v-if = "!scrollable"
>
{ { text } }
< / div >
< div class = "notice-bar-warp-slot" v-else > < slot / > < / div >
< / div >
< lay-icon :type = "rightIcon" v-if = "rightIcon" class="notice-bar-warp-right-icon" @click="onRightIconClick" > < / lay -icon >
< lay-icon
:type = "rightIcon"
v-if = "rightIcon"
class = "notice-bar-warp-right-icon"
@click ="onRightIconClick"
> < / lay-icon >
< / div >
< / div >
< / template >
< script lang = "ts" >
import { toRefs , reactive , defineComponent , ref , onMounted , nextTick } from 'vue' ;
import {
toRefs ,
reactive ,
defineComponent ,
ref ,
onMounted ,
nextTick ,
} from "vue" ;
export default defineComponent ( {
name : ' LayNoticeBar' ,
name : " LayNoticeBar" ,
props : {
// 选值为 closeable link
mode : {
type : String ,
default : ( ) => '' ,
default : ( ) => "" ,
} ,
// 通知文本内容
text : {
type : String ,
default : ( ) => '' ,
default : ( ) => "" ,
} ,
// 通知文本颜色
color : {
type : String ,
default : ( ) => ' var(--color-warning)' ,
default : ( ) => " var(--color-warning)" ,
} ,
// 通知背景色
background : {
type : String ,
default : ( ) => ' var(--color-warning-light-9)' ,
default : ( ) => " var(--color-warning-light-9)" ,
} ,
// 字体大小, 单位px
size : {
@@ -64,12 +90,12 @@ export default defineComponent({
// 自定义左侧图标
leftIcon : {
type : String ,
default : ( ) => '' ,
default : ( ) => "" ,
} ,
// 自定义右侧图标
rightIcon : {
type : String ,
default : ( ) => '' ,
default : ( ) => "" ,
} ,
} ,
setup ( props , { emit } ) {
@@ -88,8 +114,12 @@ export default defineComponent({
nextTick ( ( ) => {
state . warpOWidth = noticeBarWarpRef . value . offsetWidth ;
state . textOWidth = noticeBarTextRef . value . offsetWidth ;
document . styleSheets [ 0 ] . insertRule ( ` @keyframes oneAnimation {0% {left: 0px;} 100% {left: - ${ state . textOWidth } px;}} ` ) ;
document . styleSheets [ 0 ] . insertRule ( ` @keyframes two Animation {0% {left: ${ state . warpOWidth } px;} 100% {left: - ${ state . textOWidth } px;}} ` ) ;
document . styleSheets [ 0 ] . insertRule (
` @keyframes one Animation {0% {left: 0 px;} 100% {left: - ${ state . textOWidth } px;}} `
) ;
document . styleSheets [ 0 ] . insertRule (
` @keyframes twoAnimation {0% {left: ${ state . warpOWidth } px;} 100% {left: - ${ state . textOWidth } px;}} `
) ;
computeAnimationTime ( ) ;
setTimeout ( ( ) => {
changeAnimation ( ) ;
@@ -113,7 +143,7 @@ export default defineComponent({
// 监听 animation 动画的结束
const listenerAnimationend = ( ) => {
noticeBarTextRef . value . addEventListener (
' animationend' ,
" animationend" ,
( ) => {
changeAnimation ( ) ;
} ,
@@ -123,11 +153,11 @@ export default defineComponent({
// 右侧 icon 图标点击
const onRightIconClick = ( ) => {
if ( ! props . mode ) return false ;
if ( props . mode === ' closeable' ) {
if ( props . mode === " closeable" ) {
state . isMode = true ;
emit ( ' close' ) ;
} else if ( props . mode === ' link' ) {
emit ( ' link' ) ;
emit ( " close" ) ;
} else if ( props . mode === " link" ) {
emit ( " link" ) ;
}
} ;
// 页面加载时
@@ -175,7 +205,11 @@ export default defineComponent({
width : 100 % ;
white - space : nowrap ;
}
. notice - bar . notice - bar - warp . notice - bar - warp - text - box . notice - bar - warp - slot : : v - deep ( . el - carousel _ _item ) {
. notice - bar
. notice - bar - warp
. notice - bar - warp - text - box
. notice - bar - warp - slot
: : v - deep ( . el - carousel _ _item ) {
display : flex ;
align - items : center ;
}