<template>
<view
class="u-tips"
:class="['u-' + type, isShow ? 'u-tip-show' : '']"
:style="{
top: navbarHeight + 'px',
zIndex: uZIndex
}"
>{{ title }}</view>
</template>
<script>
export default {
name: 'u-top-tips',
props: {
navbarHeight: {
type: [Number, String],
default: 0,
default: 22
},
zIndex: {
type: [Number, String],
default: ''
}
},
data() {
return {
timer: null,
isShow: false,
title: '',
type: 'primary',
duration: 2000
}
},
computed: {
uZIndex() {
return this.zIndex ? this.zIndex : this.$u.zIndex.topTips
}
},
methods: {
show(config = {}) {
clearTimeout(this.timer)
if (config.duration) this.duration = config.duration
if (config.type) this.type = config.type
this.title = config.title
this.isShow = true
this.timer = setTimeout(() => {
this.isShow = false
clearTimeout(this.timer)
this.timer = null
}, this.duration)
}
}
}
</script>
<style lang="scss" scoped>
@import '../../libs/css/style.components.scss';
view {
box-sizing: border-box;
}
// 顶部弹出类型样式
.u-tips {
width: 100%;
position: fixed;
z-index: 1;
padding: 20rpx 15rpx;
color: #ffffff;
font-size: 14rpx;
left: 0;
right: 0;
display: flex;
align-items: center;
justify-content: center;
opacity: 0;
// 此处为最核心点,translateY(-100%)意味着将其从Y轴隐藏(隐藏到顶部(h5)或者说导航栏(app)下面)
transform: translateY(-100%);
transition: all 0.35s linear;
}
.u-tip-show {
transform: translateY(0);
opacity: 1;
z-index: 99;
}
.u-primary {
background: $u-type-primary;
}
.u-success {
background: $u-type-success;
}
.u-warning {
background: $u-type-warning;
}
.u-error {
background: $u-type-error;
}
.u-info {
background: $u-type-info;
}
</style>