新增预警页面
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
<div class="pt-2 lg:flex">
|
||||
<Avatar :src="userinfo.avatarUrl || headerImg" :size="72" class="!mx-auto !block" />
|
||||
<div class="mt-2 flex flex-col justify-center md:ml-6 md:mt-0">
|
||||
<h1 class="text-md md:text-lg">您好, {{ userinfo.userName }}, 开始您一天的工作吧!</h1>
|
||||
<h1 class="text-md md:text-lg">您好, <a @click="handleMyWorkClick">{{ userinfo.userName }}</a>, 开始您一天的工作吧!</h1>
|
||||
<span class="text-secondary"> 今日晴,20℃ - 32℃! </span>
|
||||
</div>
|
||||
<div class="mt-4 flex flex-1 justify-end md:mt-0">
|
||||
@@ -25,9 +25,15 @@
|
||||
<script lang="ts" setup>
|
||||
import { computed } from 'vue';
|
||||
import { Avatar } from 'ant-design-vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { useUserStore } from '@jeesite/core/store/modules/user';
|
||||
import headerImg from '@jeesite/assets/images/header.jpg';
|
||||
|
||||
const router = useRouter();
|
||||
const userStore = useUserStore();
|
||||
const userinfo = computed(() => userStore.getUserInfo);
|
||||
|
||||
const handleMyWorkClick = () => {
|
||||
router.push('/desktop/workbench');
|
||||
};
|
||||
</script>
|
||||
|
||||
@@ -0,0 +1,349 @@
|
||||
<template>
|
||||
<div class="card-container">
|
||||
<button
|
||||
class="control-btn left-btn"
|
||||
@click="scrollCards('left')"
|
||||
:disabled="!canScrollLeft"
|
||||
>
|
||||
<LeftOutlined />
|
||||
</button>
|
||||
<div class="card-scroll-wrapper" ref="scrollWrapper">
|
||||
<div class="card-list" ref="cardList">
|
||||
<Card
|
||||
v-for="(item, index) in cardListData"
|
||||
:key="index"
|
||||
class="custom-card"
|
||||
@click="handleCardClick(item.routePath)"
|
||||
>
|
||||
<div class="card-img-wrapper">
|
||||
<img :src="item.image" :alt="item.name" class="card-img" />
|
||||
</div>
|
||||
<div class="card-name">{{ item.name }}</div>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 右侧控制按钮 -->
|
||||
<button
|
||||
class="control-btn right-btn"
|
||||
@click="scrollCards('right')"
|
||||
:disabled="!canScrollRight"
|
||||
@mousedown="forceUpdateScrollStatus"
|
||||
>
|
||||
<RightOutlined />
|
||||
</button>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted, onUnmounted, watch, nextTick } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { Card } from 'ant-design-vue';
|
||||
import { LeftOutlined, RightOutlined } from '@ant-design/icons-vue';
|
||||
import { bizDataReportListAll, BizDataReport } from '@jeesite/biz/api/biz/dataReport';
|
||||
|
||||
// 路由实例
|
||||
const router = useRouter();
|
||||
|
||||
const scrollWrapper = ref<HTMLDivElement | null>(null);
|
||||
const cardList = ref<HTMLDivElement | null>(null);
|
||||
const isScrolling = ref(false);
|
||||
|
||||
let scrollRafId: number | null = null;
|
||||
let resizeTimer: NodeJS.Timeout | null = null;
|
||||
|
||||
const cardListData = ref<BizDataReport[]>([]);
|
||||
|
||||
// 配置项
|
||||
const scrollStep = 190;
|
||||
const scrollTolerance = 10;
|
||||
const scrollAccuracy = 1;
|
||||
|
||||
const canScrollLeft = ref(false);
|
||||
const canScrollRight = ref(false);
|
||||
|
||||
|
||||
const fetchCardList = async () => {
|
||||
try {
|
||||
// 新增错误处理,避免接口异常导致页面卡死
|
||||
const result = await bizDataReportListAll();
|
||||
cardListData.value = result || []; // 防止返回 null 导致渲染异常
|
||||
} catch (error) {
|
||||
console.error('获取应用列表失败:', error);
|
||||
cardListData.value = []; // 异常时置空列表,显示空状态
|
||||
}
|
||||
};
|
||||
|
||||
const updateScrollStatus = () => {
|
||||
if (!scrollWrapper.value || !cardList.value) {
|
||||
canScrollLeft.value = false;
|
||||
canScrollRight.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const { scrollLeft, clientWidth } = scrollWrapper.value;
|
||||
const listScrollWidth = cardList.value.scrollWidth;
|
||||
|
||||
// 左滚判断
|
||||
canScrollLeft.value = scrollLeft > scrollAccuracy;
|
||||
// 右滚判断
|
||||
const remainingScroll = listScrollWidth - (scrollLeft + clientWidth);
|
||||
canScrollRight.value = remainingScroll > scrollTolerance;
|
||||
};
|
||||
|
||||
|
||||
const debounceUpdate = () => {
|
||||
if (resizeTimer) clearTimeout(resizeTimer);
|
||||
resizeTimer = setTimeout(() => {
|
||||
nextTick(updateScrollStatus);
|
||||
}, 100);
|
||||
};
|
||||
|
||||
const forceUpdateScrollStatus = () => {
|
||||
nextTick(updateScrollStatus);
|
||||
};
|
||||
|
||||
const scrollCards = (direction: 'left' | 'right') => {
|
||||
const wrapper = scrollWrapper.value;
|
||||
const list = cardList.value;
|
||||
|
||||
if (!wrapper || !list || isScrolling.value) return;
|
||||
|
||||
if (scrollRafId !== null) {
|
||||
cancelAnimationFrame(scrollRafId);
|
||||
scrollRafId = null;
|
||||
}
|
||||
|
||||
isScrolling.value = true;
|
||||
updateScrollStatus();
|
||||
|
||||
if (
|
||||
(direction === 'left' && !canScrollLeft.value) ||
|
||||
(direction === 'right' && !canScrollRight.value)
|
||||
) {
|
||||
isScrolling.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
let targetLeft = direction === 'left'
|
||||
? wrapper.scrollLeft - scrollStep
|
||||
: wrapper.scrollLeft + scrollStep;
|
||||
const maxScrollLeft = list.scrollWidth - wrapper.clientWidth;
|
||||
targetLeft = Math.max(0, Math.min(Math.round(targetLeft), maxScrollLeft));
|
||||
|
||||
const supportsSmoothScroll = 'scrollBehavior' in document.documentElement.style;
|
||||
|
||||
if (!supportsSmoothScroll) {
|
||||
wrapper.scrollLeft = targetLeft;
|
||||
isScrolling.value = false;
|
||||
updateScrollStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
wrapper.scrollTo({ left: targetLeft, behavior: 'smooth' });
|
||||
|
||||
const checkScrollEnd = () => {
|
||||
if (!isScrolling.value) {
|
||||
scrollRafId = null;
|
||||
updateScrollStatus();
|
||||
return;
|
||||
}
|
||||
|
||||
const currentLeft = wrapper.scrollLeft;
|
||||
const isAtTarget = Math.abs(currentLeft - targetLeft) <= scrollAccuracy;
|
||||
const isAtEdge = (direction === 'left' && currentLeft <= scrollAccuracy) ||
|
||||
(direction === 'right' && currentLeft >= maxScrollLeft - scrollAccuracy);
|
||||
if (isAtTarget || isAtEdge) {
|
||||
isScrolling.value = false;
|
||||
scrollRafId = null;
|
||||
updateScrollStatus();
|
||||
return;
|
||||
}
|
||||
scrollRafId = requestAnimationFrame(checkScrollEnd);
|
||||
};
|
||||
|
||||
const raf = window.requestAnimationFrame || ((cb) => {
|
||||
const id = setTimeout(cb, 16);
|
||||
return id as unknown as number;
|
||||
});
|
||||
scrollRafId = raf(checkScrollEnd);
|
||||
};
|
||||
|
||||
const handleCardClick = (routePath: string) => {
|
||||
console.log(routePath)
|
||||
router.push(routePath);
|
||||
};
|
||||
|
||||
// 初始化
|
||||
onMounted(() => {
|
||||
fetchCardList()
|
||||
nextTick(() => {
|
||||
const wrapper = scrollWrapper.value;
|
||||
if (wrapper) {
|
||||
wrapper.addEventListener('scroll', updateScrollStatus, { passive: true });
|
||||
updateScrollStatus();
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('resize', debounceUpdate);
|
||||
setTimeout(updateScrollStatus, 200);
|
||||
});
|
||||
|
||||
// 清理资源
|
||||
onUnmounted(() => {
|
||||
if (resizeTimer) clearTimeout(resizeTimer);
|
||||
|
||||
if (scrollRafId !== null) {
|
||||
cancelAnimationFrame(scrollRafId);
|
||||
scrollRafId = null;
|
||||
}
|
||||
|
||||
const wrapper = scrollWrapper.value;
|
||||
if (wrapper) {
|
||||
wrapper.removeEventListener('scroll', updateScrollStatus);
|
||||
}
|
||||
window.removeEventListener('resize', debounceUpdate);
|
||||
});
|
||||
|
||||
watch(isScrolling, () => {
|
||||
nextTick(updateScrollStatus);
|
||||
});
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 样式部分保持不变 */
|
||||
.card-container {
|
||||
width: 100%;
|
||||
height: 18vh;
|
||||
min-height: 160px;
|
||||
background-color: #e6f7ff;
|
||||
padding: 10px 0;
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.control-btn {
|
||||
position: absolute;
|
||||
top: 50%;
|
||||
transform: translateY(-50%);
|
||||
width: 24px !important;
|
||||
min-width: 24px !important;
|
||||
max-width: 24px !important;
|
||||
height: 80%;
|
||||
border-radius: 4px;
|
||||
border: none;
|
||||
background-color: #8cb4f5;
|
||||
color: white;
|
||||
font-size: 14px;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 10;
|
||||
transition: background-color 0.3s ease;
|
||||
box-sizing: border-box;
|
||||
padding: 0;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.left-btn {
|
||||
left: 4px;
|
||||
}
|
||||
.right-btn {
|
||||
right: 4px;
|
||||
}
|
||||
|
||||
.control-btn:disabled {
|
||||
cursor: not-allowed;
|
||||
opacity: 0.4;
|
||||
background-color: #8cb4f5;
|
||||
}
|
||||
|
||||
.control-btn:hover:not(:disabled) {
|
||||
background-color: #8cb4f5;
|
||||
}
|
||||
|
||||
.card-scroll-wrapper {
|
||||
width: calc(100% - 60px);
|
||||
margin: 0 30px;
|
||||
overflow-x: auto;
|
||||
overflow-y: hidden;
|
||||
scrollbar-width: none;
|
||||
height: 100%;
|
||||
flex: 1;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.card-scroll-wrapper::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.card-list {
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
padding: 0 5px;
|
||||
white-space: nowrap;
|
||||
height: 100%;
|
||||
align-items: center;
|
||||
width: fit-content;
|
||||
min-width: 100%;
|
||||
}
|
||||
|
||||
.custom-card {
|
||||
width: 180px;
|
||||
height: calc(100% - 10px);
|
||||
flex-shrink: 0;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
transition: transform 0.3s ease, box-shadow 0.3s ease;
|
||||
border: 1px solid #f0f0f0;
|
||||
overflow: hidden;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.custom-card:hover {
|
||||
transform: translateY(-2px);
|
||||
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
|
||||
}
|
||||
|
||||
.card-img-wrapper {
|
||||
width: 100%;
|
||||
height: 65%;
|
||||
overflow: hidden;
|
||||
border-radius: 6px 6px 0 0;
|
||||
}
|
||||
|
||||
.card-img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
transition: transform 0.3s ease;
|
||||
}
|
||||
|
||||
.custom-card:hover .card-img {
|
||||
transform: scale(1.03);
|
||||
}
|
||||
|
||||
.card-name {
|
||||
width: 100%;
|
||||
height: 35%;
|
||||
padding: 4px 6px;
|
||||
font-size: 12px;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
color: #333;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
line-height: 1.3;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
@@ -1,8 +1,19 @@
|
||||
<template>
|
||||
<PageWrapper title="数据看板">
|
||||
<template #headerContent>
|
||||
<MySchedule />
|
||||
</template>
|
||||
|
||||
<div>
|
||||
ssssss
|
||||
</div>
|
||||
</PageWrapper>
|
||||
</template>
|
||||
<script lang="ts" setup name="AboutPage">
|
||||
import { h } from 'vue';
|
||||
import { Tag } from 'ant-design-vue';
|
||||
import { PageWrapper } from '@jeesite/core/components/Page';
|
||||
|
||||
import MySchedule from './components/MySchedule.vue';
|
||||
|
||||
<script>
|
||||
</script>
|
||||
|
||||
<style>
|
||||
</style>
|
||||
Reference in New Issue
Block a user