123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <template>
- <div class="page">
- <div class="header-view">
- <div class="view_item" v-for="(item, index) in headerList" :key="index">{{ item }}</div>
- </div>
- <div class="warning-view">
- <div class="scroll-view" ref="scrollViewRef" @mouseenter="onMouseenter" @mouseleave="onMouseleave">
- <div ref="listRef" class="list" v-for="(p, n) in count" :key="n">
- <div class="item" v-for="(item, index) in data" :key="index">
- <div class="content view_item">{{ item.Name }}</div>
- <!-- 运行/停止/故障 -->
- <div class="time view_item" :class="item.State == 0 ? 'blue_title' : 'red_title'">
- {{ item.State == 0 ? '运行' : '停止' }}
- </div>
- <div class="time view_item">{{ item.Date }}</div>
- </div>
- </div>
- </div>
- </div>
- </div>
- </template>
- <script setup>
- import { ref, onBeforeMount, onMounted, onBeforeUnmount, nextTick } from "vue";
- const props = defineProps({
- resultData: {
- type: Array,
- default: []
- }
- })
- const headerList = ref(['名称', '状态', '时间'])
- const data = ref(); //列表数据
- const listRef = ref(); //列表dom
- const scrollViewRef = ref(); //滚动区域dom
- const count = ref(1); //列表个数
- let intervalId = null;
- let isAutoScrolling = true; //是否自动滚动标识
- //获取列表数据
- const getData = () => {
- //模拟接口请求列表数据
- return new Promise((resolve, reject) => {
- setTimeout(() => {
- //生成10条数据
- let list = new Array(30).fill().map((item, index) => index);
- resolve(list);
- }, 100);
- });
- };
- watch(() => props.resultData, (newVal) => {
- if (newVal) {
- // data.value = await getData();
- data.value = newVal;
- intervalId && clearInterval(intervalId);
- nextTick(() => {
- //判断列表是否生成滚动条
- count.value = hasScrollBar() ? 2 : 1;
- //有滚动条开始自动滚动
- if (count.value == 2) {
- autoScrolling();
- }
- });
- }
- }, { deep: true, immediate: true } // 开启深度监听
- )
- onMounted(() => {
- })
- //判断列表是否有滚动条
- const hasScrollBar = () => {
- return scrollViewRef.value.scrollHeight > scrollViewRef.value.clientHeight;
- };
- //设置自动滚动
- const autoScrolling = () => {
- intervalId = setInterval(() => {
- if (scrollViewRef.value.scrollTop < listRef.value[0].clientHeight) {
- scrollViewRef.value.scrollTop += isAutoScrolling ? 1 : 0;
- } else {
- scrollViewRef.value.scrollTop = 0;
- }
- }, 20);
- };
- onBeforeUnmount(() => {
- //离开页面清理定时器
- intervalId && clearInterval(intervalId);
- });
- //鼠标进入,停止滚动
- const onMouseenter = () => {
- isAutoScrolling = false;
- };
- //鼠标移出,继续滚动
- const onMouseleave = () => {
- isAutoScrolling = true;
- };
- </script>
- <style scoped lang="scss">
- .page {
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- justify-content: center;
- align-items: center;
- overflow: hidden;
- }
- .header-view {
- margin-top: 10px;
- width: 100%;
- display: flex;
- align-items: center;
- justify-content: space-between;
- padding: 10px 10px 10px 20px;
- background-color: rgba(16, 40, 92, 1);
- }
- .view_item {
- flex: 1;
- // display: flex;
- // align-items: center;
- // justify-content: flex-start;
- white-space: nowrap;
- text-overflow: ellipsis;
- overflow: hidden;
- }
- .warning-view {
- width: 100%;
- height: calc(100% - 51px);
- display: flex;
- flex-direction: column;
- }
- .label {
- color: #fff;
- padding: 20px;
- font-size: 22px;
- }
- .scroll-view {
- flex: 1;
- height: 0;
- width: 100%;
- overflow-y: auto;
- }
- .list {
- width: 100%;
- box-sizing: border-box;
- }
- .item {
- padding: 0px 10px 0px 20px;
- width: 100%;
- height: 50px;
- min-height: 50px;
- font-size: 15px;
- display: flex;
- align-items: center;
- justify-content: space-between;
- color: #eee;
- }
- .item:nth-child(even) {
- background: rgba(16, 40, 92, 0.4);
- }
- .item:hover {
- cursor: pointer;
- background-image: linear-gradient(to right, #168cdb, transparent);
- }
- /*隐藏滚动条
- */
- ::-webkit-scrollbar {
- display: none;
- }
- .blue_title {
- color: #67C23A;
- }
- .red_title {
- color: #F56C6C;
- }
- </style>
|