每日菜品独立页

This commit is contained in:
weiwei committed 2025-03-16 19:58:52 +08:00
1 parent c1893adb3c
commit fed99fb0a7
2 files changed
+432 -11

No files matched your search

+1 -11
View File
@@ -55,12 +55,7 @@
<td v-if="!loading" class="text-center" @click="addFood(3)">晚餐</td>
<div class="food_list">
<td class="food_list_item" v-for="(item, index) in foodData3" :key="index" @click="delteData(item.tid)">
<el-image
style="width: 80px; height: 80px"
loading="lazy"
:src="imageBaseUrl + item.picUrl"
fit="cover"
/>
<el-image style="width: 80px; height: 80px" loading="lazy" :src="imageBaseUrl + item.picUrl" fit="cover" />
<div class="w-full flex justify-around items-center text-black mt-2">
<span>{{ item.name }}</span>
<span class="mx-1">|</span>
@@ -160,14 +155,9 @@ const selectTimeFood = async () => {
time: timedata,
merchantId: merchantId.value,
}
//最大长度
let count = 0
loading.value = true
const result = await selectTimeFoodApi(params).finally(() => (loading.value = false))
result.data.forEach((r: any) => {
if (r.dailyMenuVOS.length > count) {
count = r.dailyMenuVOS.length
}
switch (r.hourType) {
case 1:
foodData1.value = r.dailyMenuVOS
+431
View File
@@ -0,0 +1,431 @@
<template>
<div class="layout-padding">
<div class="layout-padding-view">
<div
ref="containerRef"
class="border-flow-container relative flex h-screen w-full flex-col overflow-hidden bg-gradient-to-br from-[#1a2942] to-[#121e2d] p-4"
>
<!-- 背景装饰 -->
<div class="pointer-events-none absolute inset-0 bg-pattern opacity-10"></div>
<div class="pointer-events-none absolute inset-0 pattern-dots opacity-[0.08]"></div>
<!-- 圆形云纹装饰 -->
<div class="ink-cloud absolute left-4 top-4 h-64 w-64 opacity-20"></div>
<div class="ink-cloud absolute right-4 top-4 h-64 w-64 rotate-90 opacity-20"></div>
<div class="ink-cloud absolute bottom-4 left-4 h-64 w-64 -rotate-90 opacity-20"></div>
<div class="ink-cloud absolute bottom-4 right-4 h-64 w-64 rotate-180 opacity-20"></div>
<!-- 随机位置云纹装饰 -->
<div class="ink-cloud absolute left-[30%] top-[20%] h-48 w-48 opacity-15 rotate-45"></div>
<div class="ink-cloud absolute right-[25%] top-[40%] h-40 w-40 opacity-15 rotate-[120deg]"></div>
<div class="ink-cloud absolute left-[45%] bottom-[30%] h-56 w-56 opacity-15 rotate-[220deg]"></div>
<div class="ink-cloud absolute right-[40%] bottom-[15%] h-44 w-44 opacity-15 rotate-[300deg]"></div>
<!-- 顶部区域 -->
<div class="relative mb-2 flex items-center justify-center">
<!-- 左侧条纹 -->
<div class="continuous-flow-stripe absolute left-0 flex h-2 w-[calc(50%-8rem)] items-center">
<div class="h-full w-full rounded-full bg-gradient-to-r from-transparent via-[#4a88ff]/30 to-transparent"></div>
</div>
<div class="flex flex-col items-center">
<h1 class="gradient-text relative text-2xl font-bold tracking-wider">今日菜品</h1>
<div class="flow-text mt-2 text-lg font-medium text-[#8ab4ff] drop-shadow-lg">{{ currentDate }} {{ currentTime }}</div>
</div>
<!-- 右侧条纹 -->
<div class="continuous-flow-stripe absolute right-0 flex h-2 w-[calc(50%-8rem)] items-center">
<div class="h-full w-full rounded-full bg-gradient-to-r from-transparent via-[#4a88ff]/30 to-transparent"></div>
</div>
<!-- 全屏按钮 -->
<el-tooltip :content="isFullscreen ? '退出全屏' : '全屏'" placement="bottom" effect="dark">
<button
@click="toggleFullScreen"
class="absolute right-0 flex h-8 w-8 items-center justify-center rounded-xl bg-[#4a88ff]/20 transition-all hover:scale-110 hover:bg-[#4a88ff]/40"
>
<el-icon class="icon h-10 w-10 font-bold bg-contain bg-center bg-no-repeat"><FullScreen /></el-icon>
</button>
</el-tooltip>
</div>
<!-- 菜品展示区域 -->
<div class="flex-1 px-4" :style="containerStyle">
<div class="grid h-full w-full gap-3" :style="gridStyle">
<template v-for="hourType in foodData" :key="hourType">
<div
v-for="dish in hourType"
:key="dish.id"
class="group relative flex flex-col overflow-hidden rounded-xl border border-[#4a88ff]/10 bg-[#1d2b45]/60 transition-all duration-500 hover:scale-[1.02] hover:-translate-y-1 hover:bg-[#1d2b45]/80 hover:shadow-[0_0_20px_rgba(74,136,255,0.1)]"
>
<div class="relative h-32 overflow-hidden">
<div class="absolute inset-0 bg-gradient-to-b from-transparent via-transparent to-[#1d2b45]/90"></div>
<img
:src="imageBaseUrl + dish.picUrl"
:alt="dish.name"
class="h-full w-full object-cover transition-transform duration-500 group-hover:scale-110"
/>
<div class="absolute left-2 top-2 rounded-lg">
<dict-tag
:options="daily_menu"
:value="canteenCategoryOption?.find((v: any) => v.id == dish.categoryId)?.categoryType?.split(',')"
/>
</div>
<div class="absolute right-1 top-2 rounded-lg px-2 py-0.5 text-sm">
<el-tag type="primary">
{{ canteenCategoryOption?.find((v: any) => v.id == dish.categoryId)?.name }}
</el-tag>
</div>
</div>
<div class="flex flex-col justify-between gap-1 bg-[#1d2b45]/40 p-3 backdrop-blur-sm">
<div class="flex items-center justify-between">
<h3 class="text-2xl font-bold text-[#8ab4ff] drop-shadow-lg transition-colors group-hover:text-white line-clamp-1">
{{ dish.name }}
</h3>
<p class="text-3xl font-bold text-[#4a88ff] drop-shadow-lg whitespace-nowrap ml-4">¥{{ displayPrice(dish.price) }}</p>
</div>
<!-- <span class="text-base text-[#8ab4ff]/80 line-clamp-1">{{ dish.name }}</span> -->
</div>
<div class="absolute inset-px rounded-xl border border-[#4a88ff]/10 pointer-events-none"></div>
</div>
</template>
</div>
</div>
<!-- 底部区域 -->
<div class="mt-4 flex items-center justify-center gap-8 pb-2 text-sm text-[#8ab4ff]/60">
<div class="h-[1px] w-32 bg-gradient-to-r from-transparent via-[#4a88ff]/20 to-transparent"></div>
<span>智慧食堂</span>
<div class="h-[1px] w-32 bg-gradient-to-r from-transparent via-[#4a88ff]/20 to-transparent"></div>
</div>
</div>
</div>
</div>
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted, computed } from "vue"
import dayjs from "dayjs"
import { ElTooltip } from "element-plus"
import { selectTimeFoodApi } from "/@/api/canteen/canteenDailyMenu"
import { getAllSimple as getCanteenCategory } from "/@/api/canteen/canteenCategory"
import { useDict } from "/@/hooks/dict"
import { displayPrice } from "/@/utils/formatMoney"
const { daily_menu } = useDict("daily_menu")
const containerRef = ref<HTMLElement | null>(null)
const currentDate = ref(dayjs().format("YYYY年MM月DD日"))
const currentTime = ref(dayjs().format("HH:mm:ss"))
const isFullscreen = ref(false)
const imageBaseUrl = import.meta.env.VITE_IMAGE_BASE_PATH
const canteenCategoryOption = ref<
| {
id: string
categoryType: string
name: string
[key: string]: any
}[]
| null
>()
interface FoodItem {
categoryId: string
hourType: number
id: string
name: string
picUrl: string
price: number
tid: string
}
const foodData = reactive<{
breakfast: FoodItem[] | []
lunch: FoodItem[] | []
dinner: FoodItem[] | []
}>({
breakfast: [],
lunch: [],
dinner: [],
})
// 根据时段获取菜品
const getDishByType = async () => {
const result = await selectTimeFoodApi({
// time: dayjs().format("YYYY-MM-DD"),
// time: "2025-03-14",
// time: "2025-03-16",
time: "2025-02-07",
merchantId: "1887400193644199937",
hourType: 2,
})
if (result.code === 0) {
result.data.forEach((r: any) => {
switch (r.hourType) {
case 1:
foodData.breakfast = r.dailyMenuVOS
break
case 2:
foodData.lunch = r.dailyMenuVOS
break
case 3:
foodData.dinner = r.dailyMenuVOS
break
}
})
}
}
// 更新时间
let timer: number
const updateTime = () => {
currentTime.value = dayjs().format("HH:mm:ss")
}
onMounted(async () => {
timer = setInterval(updateTime, 1000)
await getDishByType()
try {
// 获取菜品分类
const res = await getCanteenCategory()
if (res.code === 0) {
canteenCategoryOption.value = res.data
}
} catch (error) {
canteenCategoryOption.value = []
}
// 监听全屏变化事件
const handleFullscreenChange = () => {
isFullscreen.value = !!(
document.fullscreenElement ||
(document as any).webkitFullscreenElement ||
(document as any).mozFullScreenElement ||
(document as any).msFullscreenElement
)
}
// 全屏api兼容性
document.addEventListener("fullscreenchange", handleFullscreenChange)
document.addEventListener("webkitfullscreenchange", handleFullscreenChange)
document.addEventListener("mozfullscreenchange", handleFullscreenChange)
document.addEventListener("MSFullscreenChange", handleFullscreenChange)
onUnmounted(() => {
clearInterval(timer)
document.removeEventListener("fullscreenchange", handleFullscreenChange)
document.removeEventListener("webkitfullscreenchange", handleFullscreenChange)
document.removeEventListener("mozfullscreenchange", handleFullscreenChange)
document.removeEventListener("MSFullscreenChange", handleFullscreenChange)
})
})
// 全屏切换
const toggleFullScreen = async () => {
const element = containerRef.value
if (!element) return
try {
if (!isFullscreen.value) {
if (element.requestFullscreen) {
await element.requestFullscreen()
} else if ((element as any).webkitRequestFullscreen) {
await (element as any).webkitRequestFullscreen()
} else if ((element as any).msRequestFullscreen) {
await (element as any).msRequestFullscreen()
} else if ((element as any).mozRequestFullScreen) {
await (element as any).mozRequestFullScreen()
}
isFullscreen.value = true
} else {
if (document.exitFullscreen) {
await document.exitFullscreen()
} else if ((document as any).webkitExitFullscreen) {
await (document as any).webkitExitFullscreen()
} else if ((document as any).msExitFullscreen) {
await (document as any).msExitFullscreen()
} else if ((document as any).mozCancelFullScreen) {
await (document as any).mozCancelFullScreen()
}
isFullscreen.value = false
}
} catch (err) {
console.error("全屏切换失败:", err)
}
}
// 计算容器和网格布局
const containerStyle = computed(() => {
const headerHeight = 120
const footerHeight = 50
const padding = 32
const extraOffset = isFullscreen.value ? 0 : 60 // 非全屏状态下额外偏移量
return {
height: `calc(100vh - ${headerHeight + footerHeight + padding + extraOffset}px)`,
marginBottom: isFullscreen.value ? "0" : "60px", // 非全屏状态添加底部边距
}
})
const gridStyle = computed(() => {
const totalItems = foodData.breakfast.length + foodData.lunch.length + foodData.dinner.length
if (totalItems === 0) return {}
// 计算行列数
const aspectRatio = window.innerWidth / window.innerHeight
let columns = Math.ceil(Math.sqrt(totalItems * aspectRatio)) - 4
let rows = Math.ceil(totalItems / columns)
// 占满屏幕
while (rows * columns < totalItems) {
columns++
}
return {
gridTemplateColumns: `repeat(${columns}, 1fr)`,
gridTemplateRows: `repeat(${rows}, 1fr)`,
}
})
</script>
<style scoped lang="scss">
.bg-pattern {
background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.828-1.415 1.415L51.8 0h2.827zM5.373 0l-.83.828L5.96 2.243 8.2 0H5.374zM48.97 0l3.657 3.657-1.414 1.414L46.143 0h2.828zM11.03 0L7.372 3.657 8.787 5.07 13.857 0H11.03zm32.284 0L49.8 6.485 48.384 7.9l-7.9-7.9h2.83zM16.686 0L10.2 6.485 11.616 7.9l7.9-7.9h-2.83zm20.97 0l9.315 9.314-1.414 1.414L34.828 0h2.83zM22.344 0L13.03 9.314l1.414 1.414L25.172 0h-2.83zM32 0l12.142 12.142-1.414 1.414L30 .828 17.272 13.556l-1.414-1.414L28 0h4zM.284 0l28 28-1.414 1.414L0 2.544V0h.284zM0 5.373l25.456 25.455-1.414 1.415L0 8.2V5.374zm0 5.656l22.627 22.627-1.414 1.414L0 13.86v-2.83zm0 5.656l19.8 19.8-1.415 1.413L0 19.514v-2.83zm0 5.657l16.97 16.97-1.414 1.415L0 25.172v-2.83zM0 28l14.142 14.142-1.414 1.414L0 30.828V28zm0 5.657L11.314 44.97 9.9 46.386l-9.9-9.9v-2.828zm0 5.657L8.485 47.8 7.07 49.212 0 42.143v-2.83zm0 5.657l5.657 5.657-1.414 1.415L0 47.8v-2.83zm0 5.657l2.828 2.83-1.414 1.413L0 53.456v-2.83zM54.627 60L30 35.373 5.373 60H8.2L30 38.2 51.8 60h2.827zm-5.656 0L30 41.03 11.03 60h2.828L30 43.858 46.142 60h2.83zm-5.656 0L30 46.686 16.686 60h2.83L30 49.515 40.485 60h2.83zm-5.657 0L30 52.343 22.344 60h2.83L30 55.172 34.828 60h2.83zM32 60l-2-2-2 2h4zM59.716 0l-28 28 1.414 1.414L60 2.544V0h-.284zM60 5.373L34.544 30.828l1.414 1.415L60 8.2V5.374zm0 5.656L37.373 33.656l1.414 1.414L60 13.86v-2.83zm0 5.656l-19.8 19.8 1.415 1.413L60 19.514v-2.83zm0 5.657l-16.97 16.97 1.414 1.415L60 25.172v-2.83zM60 28L45.858 42.142l1.414 1.414L60 30.828V28zm0 5.657L48.686 44.97l1.415 1.415 9.9-9.9v-2.828zm0 5.657L51.515 47.8l1.414 1.413 7.07-7.07v-2.83zm0 5.657l-5.657 5.657 1.414 1.415L60 47.8v-2.83zm0 5.657l-2.828 2.83 1.414 1.413L60 53.456v-2.83zM39.9 16.385l1.414-1.414L30 3.658 18.686 14.97l1.415 1.415 9.9-9.9 9.9 9.9zm-2.83 2.828l1.415-1.414L30 9.313 21.515 17.8l1.414 1.413L30 11.8l7.07 7.414v-.002zm-2.827 2.83l1.414-1.416L30 14.97l-5.657 5.657 1.414 1.415L30 17.8l4.243 4.242zm-2.83 2.827l1.415-1.414L30 20.626l-2.828 2.83 1.414 1.414L30 23.456l1.414 1.414zM56.87 59.414L58.284 58 30 29.716 1.716 58l1.414 1.414L30 32.544l26.87 26.87z' fill='%234a88ff' fill-opacity='0.05' fill-rule='evenodd'/%3E%3C/svg%3E");
}
.pattern-dots {
background-image: radial-gradient(#4a88ff 1px, transparent 1px);
background-size: calc(10 * 1px) calc(10 * 1px);
}
.gradient-text {
background: linear-gradient(-45deg, #4a88ff, #1d4ed8, #2563eb, #3b82f6);
background-size: 200% 200%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: gradientBG 6s ease infinite;
}
.flow-text {
position: relative;
overflow: hidden;
&::before {
content: "";
position: absolute;
left: -100%;
top: 0;
width: 100%;
height: 100%;
background: linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, 0.2) 50%, transparent 100%);
animation: flowLight 3s infinite linear;
}
}
@keyframes flowLight {
0% {
left: -100%;
}
100% {
left: 100%;
}
}
.continuous-flow-stripe {
position: relative;
overflow: hidden;
&::before {
content: "";
position: absolute;
top: 0;
left: -100%;
width: 200%;
height: 100%;
background: linear-gradient(
90deg,
transparent 0%,
rgba(74, 136, 255, 0.1) 20%,
rgba(74, 136, 255, 0.3) 30%,
rgba(74, 136, 255, 0.3) 40%,
rgba(74, 136, 255, 0.1) 50%,
transparent 60%
);
animation: continuousFlow 3s linear infinite;
}
}
@keyframes gradientBG {
0% {
background-position: 0% 50%;
}
50% {
background-position: 100% 50%;
}
100% {
background-position: 0% 50%;
}
}
.ink-cloud {
background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath fill='%234a88ff' d='M50,0C36.7,0,25,11.7,25,25c0,13.3,11.7,25,25,25s25-11.7,25-25C75,11.7,63.3,0,50,0z M50,40c-8.3,0-15-6.7-15-15s6.7-15,15-15s15,6.7,15,15S58.3,40,50,40z'%3E%3CanimateTransform attributeName='transform' type='rotate' from='0 50 50' to='360 50 50' dur='20s' repeatCount='indefinite'/%3E%3C/path%3E%3C/svg%3E");
background-size: contain;
background-repeat: no-repeat;
background-position: center;
filter: blur(2px);
}
@keyframes continuousFlow {
from {
transform: translateX(-50%);
}
to {
transform: translateX(50%);
}
}
.border-flow-container {
position: relative;
&::before {
content: "";
position: absolute;
inset: 0;
background: linear-gradient(90deg, #4a88ff 50%, transparent 50%);
background-size: 200% 100%;
animation: borderFlow 4s linear infinite;
mask: linear-gradient(#fff 0 0) content-box, linear-gradient(#fff 0 0);
mask-composite: exclude;
padding: 1px;
border-radius: 4px;
}
}
@keyframes borderFlow {
0% {
background-position: 0% 0%;
}
100% {
background-position: 200% 0%;
}
}
.group {
display: grid;
grid-template-rows: auto 1fr;
min-height: 0;
}
.relative.h-32 {
height: auto;
aspect-ratio: 16/9;
}
.flex-1 {
min-height: 0;
display: grid;
grid-template-rows: auto 1fr;
overflow-y: auto;
scroll-behavior: smooth;
scrollbar-width: none;
-ms-overflow-style: none;
}
</style>