Files
xl-mobile/src/components/XNoticeBar.vue

130 lines
2.7 KiB
Vue
Raw Normal View History

2025-03-28 15:34:00 +08:00
<script setup>
2025-06-13 21:01:33 +08:00
import {onMounted, ref, watch} from "vue";
2025-03-28 15:34:00 +08:00
import warn from '../static/icons/warn.png';
2025-04-07 18:04:39 +08:00
import success from '../static/icons/info.png';
const STATUS = {
error: {
bg: 'x-notice-box-error',
context: 'context-error'
},
success: {
bg: 'x-notice-box-success',
context: 'context-success'
},
};
2025-05-21 15:45:10 +08:00
const {text, status, tile, textColor} = defineProps({
2025-04-07 18:04:39 +08:00
text: {
type: String,
default: '提示请在规定时间内按要求提交回填1。以免影响收益。哈哈哈哈哈哈哈哈哈哈'
},
2025-05-21 15:45:10 +08:00
textColor: {
type: String,
default: '#000'
},
2025-04-07 18:04:39 +08:00
status: {
type: String,
default: 'error'
2025-04-14 17:26:40 +08:00
},
tile: {
type: Boolean,
default: false,
2025-04-07 18:04:39 +08:00
}
});
2025-03-28 15:34:00 +08:00
const XNoticeBox = ref();
const Context = ref();
const roll = ref(false);
2025-06-13 21:01:33 +08:00
watch(
() => text,
() => {
if (!tile) {
if (
Context.value.$el.clientWidth
>
XNoticeBox.value.$el.clientWidth
) {
roll.value = true;
}
}
},
{deep: true}
)
2025-03-28 15:34:00 +08:00
onMounted(() => {
2025-04-14 17:26:40 +08:00
if (!tile) {
if (
Context.value.$el.clientWidth
>
XNoticeBox.value.$el.clientWidth
) {
roll.value = true;
}
2025-03-28 15:34:00 +08:00
}
});
</script>
<template>
2025-04-07 18:04:39 +08:00
<view ref="XNoticeBox" :class="['x-notice-box', STATUS[status].bg]">
2025-04-14 17:26:40 +08:00
<view ref="Context" :class="['context', roll ? 'roll' : '', STATUS[status].context]"
:style="{alignItems: tile ? 'start' : 'center'}">
2025-04-07 18:04:39 +08:00
<image v-if="status==='error'" class="!size-[26rpx] flex-shrink-0" :src="warn"></image>
<image v-else class="!size-[26rpx] flex-shrink-0" :src="success"></image>
2025-06-13 21:01:33 +08:00
<text v-if="!tile" class="!whitespace-nowrap flex-shrink-0" :style="{color: textColor}"
v-html="text"></text>
<text v-else :style="{color: textColor}" v-html="text">
2025-04-14 17:26:40 +08:00
</text>
2025-03-28 15:34:00 +08:00
</view>
</view>
</template>
<style scoped lang="scss">
2025-04-07 18:04:39 +08:00
.x-notice-box-error {
background-color: #FFF7E8;
}
.x-notice-box-success {
background-color: #E8F3FF;
}
.context-error {
color: rgb(255, 87, 34);
}
.context-success {
color: rgb(29, 33, 41);
}
2025-03-28 15:34:00 +08:00
.x-notice-box {
padding: 18rpx 24rpx;
2025-04-07 18:04:39 +08:00
width: 100%;
overflow: hidden;
2025-03-28 15:34:00 +08:00
}
.context {
font-size: 24rpx;
font-weight: 400;
line-height: 22px;
letter-spacing: 0;
text-align: left;
white-space: nowrap;
display: inline-flex;
gap: 18rpx;
}
.roll {
animation: 10s Roll linear infinite forwards;
}
@keyframes Roll {
0% {
transform: translateX(100%);
}
100% {
transform: translateX(-100%);
}
}
</style>