优化首页、访客可视滚动布局
This commit is contained in:
@@ -1,26 +1,31 @@
|
||||
<template>
|
||||
<view class="visitor-page">
|
||||
<view class="status_bar"></view>
|
||||
<!-- 顶部导航栏 -->
|
||||
<view class="nav-bar">
|
||||
<view class="nav-left" @tap="goBack">
|
||||
<image src="https://wuyeadmin.bugtc.com/images/home/arr-left.png" style="width: 18px; height: 18px;"></image>
|
||||
</view>
|
||||
<view class="nav-title">访客邀请</view>
|
||||
<view class="nav-right"></view>
|
||||
</view>
|
||||
<!-- 状态栏占位 -->
|
||||
<view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
|
||||
|
||||
<!-- 顶部导航栏 -->
|
||||
<view class="nav-bar">
|
||||
<view class="nav-left" @tap="goBack">
|
||||
<image
|
||||
src="https://wuyeadmin.bugtc.com/images/home/arr-left.png"
|
||||
class="back-icon"
|
||||
/>
|
||||
</view>
|
||||
<view class="nav-title">访客邀请</view>
|
||||
<view class="nav-right"></view>
|
||||
</view>
|
||||
|
||||
<!-- 标签切换栏 -->
|
||||
<view class="tab-bar">
|
||||
<view
|
||||
class="tab-item"
|
||||
<view
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'waiting' }"
|
||||
@click="activeTab = 'waiting'"
|
||||
>
|
||||
等待来访
|
||||
</view>
|
||||
<view
|
||||
class="tab-item"
|
||||
<view
|
||||
class="tab-item"
|
||||
:class="{ active: activeTab === 'visited' }"
|
||||
@click="activeTab = 'visited'"
|
||||
>
|
||||
@@ -28,24 +33,31 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 访客列表 -->
|
||||
<scroll-view class="list-container" scroll-y>
|
||||
<!-- 列表项:根据标签切换显示对应数据 -->
|
||||
<view
|
||||
class="visitor-item"
|
||||
v-for="(item, index) in filterdList"
|
||||
<!-- 访客列表 - 固定高度,内部滚动 -->
|
||||
<scroll-view class="list-container" scroll-y :style="{ height: scrollHeight + 'px' }">
|
||||
<view
|
||||
class="visitor-item"
|
||||
v-for="(item, index) in filterdList"
|
||||
:key="index"
|
||||
>
|
||||
<!-- 访客基本信息 -->
|
||||
<view class="item-header">
|
||||
<text class="visitor-name" :class="item.status">来访者:{{ item.visitorName }}</text>
|
||||
<text class="status-tag" :class="item.status">{{ item.statusText }}</text>
|
||||
<text class="visitor-name" :class="item.status">
|
||||
来访者:{{ item.visitorName }}
|
||||
</text>
|
||||
<text class="status-tag" :class="item.status">
|
||||
{{ item.statusText }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- 有效期/到访时间 -->
|
||||
<view class="item-row">
|
||||
<text class="label" :class="item.status">{{ item.status === 'waiting' ? '有效期' : '到访时间' }}:</text>
|
||||
<text class="value" :class="item.status">{{ item.startTime }}至{{item.endTime}}</text>
|
||||
<text class="label" :class="item.status">
|
||||
{{ item.status === "waiting" ? "有效期" : "到访时间" }}:
|
||||
</text>
|
||||
<text class="value" :class="item.status">
|
||||
{{ item.startTime }}至{{ item.endTime }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- 联系方式 -->
|
||||
@@ -62,136 +74,132 @@
|
||||
|
||||
<!-- 时间+查看详情 -->
|
||||
<view class="item-footer">
|
||||
<text class="time-text" :class="item.status">时间:{{ item.createTime }}</text>
|
||||
<text class="time-text" :class="item.status">
|
||||
时间:{{ item.createTime }}
|
||||
</text>
|
||||
<view class="detail-btn" @click="viewDetail(item)">
|
||||
<text>查看详情</text>
|
||||
<uni-icons type="arrowright" size="14"></uni-icons>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<!-- 空状态 -->
|
||||
<view v-if="filterdList.length === 0" class="empty-state">
|
||||
<uni-icons type="info" size="30" color="#ccc"></uni-icons>
|
||||
<text class="empty-text">
|
||||
{{ activeTab === 'waiting' ? '暂无等待到访数据' : '暂无已到访数据' }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- 空状态 -->
|
||||
<view v-if="filterdList.length === 0" class="empty-state">
|
||||
<uni-icons type="info" size="30" color="#ccc"></uni-icons>
|
||||
<text class="empty-text">
|
||||
{{ activeTab === "waiting" ? "暂无等待到访数据" : "暂无已到访数据" }}
|
||||
</text>
|
||||
</view>
|
||||
|
||||
<!-- 底部占位,防止最后一项贴底 -->
|
||||
<view class="list-bottom-space"></view>
|
||||
</scroll-view>
|
||||
|
||||
<!-- 新增邀请按钮 -->
|
||||
<view class="add-btn" @click="addInvitation">
|
||||
<!-- <uni-icons type="plus" size="18" color="#fff"></uni-icons> -->
|
||||
<text class="add-text">新增邀请+</text>
|
||||
<view class="add-btn-wrapper">
|
||||
<view class="add-btn" @click="addInvitation">
|
||||
<text class="add-text">新增邀请+</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, computed } from 'vue'
|
||||
import { onLoad } from '@dcloudio/uni-app'
|
||||
import { getVisitorList } from '../api/api.js'
|
||||
import { ref, computed } from "vue";
|
||||
import { onLoad } from "@dcloudio/uni-app";
|
||||
import { getVisitorList } from "../api/api.js";
|
||||
|
||||
// 激活的标签(waiting=等待来访,visited=已到访)
|
||||
const activeTab = ref('waiting')
|
||||
const activeTab = ref("waiting");
|
||||
const statusBarHeight = ref(0);
|
||||
const scrollHeight = ref(0);
|
||||
const visitorList = ref([]);
|
||||
|
||||
// 访客列表数据
|
||||
const visitorList = ref([])
|
||||
|
||||
// 后端数据映射到前端
|
||||
const mapData = (list) => {
|
||||
if (!Array.isArray(list)) return []
|
||||
return list.map(item => {
|
||||
const status = item.status === 1 || item.status === '1' ? 'visited' : 'waiting'
|
||||
if (!Array.isArray(list)) return [];
|
||||
return list.map((item) => {
|
||||
const status =
|
||||
item.status === 1 || item.status === "1" ? "visited" : "waiting";
|
||||
return {
|
||||
...item,
|
||||
visitorName: item.visitorName,
|
||||
status,
|
||||
statusText: status === 'visited' ? '已到访' : '等待来访',
|
||||
startTime: item.startTime,
|
||||
endTime: item.endTime,
|
||||
statusText: status === "visited" ? "已到访" : "等待来访",
|
||||
phone: item.visitorPhone,
|
||||
carNumber: item.carNum,
|
||||
createTime: item.createTime || ''
|
||||
}
|
||||
})
|
||||
}
|
||||
createTime: item.createTime || "",
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
// 获取访客列表
|
||||
const fetchVisitorList = async () => {
|
||||
const userId = uni.getStorageSync('userId')
|
||||
let params = {userId:userId}
|
||||
const userId = uni.getStorageSync("userId");
|
||||
try {
|
||||
const res = await getVisitorList(params)
|
||||
visitorList.value = mapData(res.data || [])
|
||||
// console.log('222222',visitorList.value)
|
||||
|
||||
const res = await getVisitorList({ userId });
|
||||
visitorList.value = mapData(res.data || []);
|
||||
} catch (err) {
|
||||
uni.showToast({title:err.msg,icon:'none'})
|
||||
uni.showToast({ title: err.msg, icon: "none" });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
onLoad(() => {
|
||||
fetchVisitorList()
|
||||
})
|
||||
const info = uni.getSystemInfoSync();
|
||||
statusBarHeight.value = info.statusBarHeight || 0;
|
||||
|
||||
// rpx 转 px 比例
|
||||
const scale = info.windowWidth / 750;
|
||||
|
||||
// 各固定区域高度(rpx 转 px)
|
||||
const navPx = 90 * scale; // 导航栏
|
||||
const tabPx = 88 * scale; // tab栏
|
||||
const btnPx = 148 * scale; // 底部按钮区域
|
||||
|
||||
// 列表区域可用高度 = 窗口高度 - 状态栏 - 导航栏 - tab栏 - 底部按钮区
|
||||
scrollHeight.value = info.windowHeight - statusBarHeight.value - navPx - tabPx - btnPx;
|
||||
|
||||
fetchVisitorList();
|
||||
});
|
||||
|
||||
// 根据标签筛选列表
|
||||
const filterdList = computed(() => {
|
||||
return visitorList.value.filter(item => item.status === activeTab.value)
|
||||
})
|
||||
// 返回上一页
|
||||
const goBack = () => {
|
||||
if(uni.getStorageSync('sourcePage') === "index"){
|
||||
uni.switchTab({
|
||||
url:"/pages/index/index"
|
||||
})
|
||||
}else if(uni.getStorageSync('sourcePage') === "serviceIndex"){
|
||||
uni.switchTab({
|
||||
url:"/pages/serviceIndex/serviceIndex"
|
||||
})
|
||||
}
|
||||
uni.removeStorageSync('sourcePage')
|
||||
|
||||
}
|
||||
return visitorList.value.filter((item) => item.status === activeTab.value);
|
||||
});
|
||||
|
||||
const goBack = () => {
|
||||
const source = uni.getStorageSync("sourcePage");
|
||||
if (source === "index") {
|
||||
uni.switchTab({ url: "/pages/index/index" });
|
||||
} else if (source === "serviceIndex") {
|
||||
uni.switchTab({ url: "/pages/serviceIndex/serviceIndex" });
|
||||
}
|
||||
uni.removeStorageSync("sourcePage");
|
||||
};
|
||||
|
||||
// 查看详情
|
||||
const viewDetail = (item) => {
|
||||
uni.navigateTo({
|
||||
url: `/pageSubPack/visitor/visitor-detail?id=${item.id}` // 传 id 到详情页
|
||||
})
|
||||
}
|
||||
url: `/pageSubPack/visitor/visitor-detail?id=${item.id}`,
|
||||
});
|
||||
};
|
||||
|
||||
// 新增邀请
|
||||
const addInvitation = () => {
|
||||
uni.navigateTo({
|
||||
url: '/pageSubPack/visitor/visitor-add'
|
||||
})
|
||||
}
|
||||
uni.navigateTo({ url: "/pageSubPack/visitor/visitor-add" });
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
/* 页面整体样式 */
|
||||
/* 页面根容器 */
|
||||
.visitor-page {
|
||||
background: linear-gradient(to bottom left, #E2F0FF 0%, #f9f9f9 50%);
|
||||
min-height: 100vh;
|
||||
padding: 0 40rpx;
|
||||
background: linear-gradient(135deg, #e2f0ff 0%, #f9f9f9 50%);
|
||||
padding: 0 30rpx;
|
||||
}
|
||||
.status_bar {
|
||||
height: var(--status-bar-height);
|
||||
/* height: 32px; */
|
||||
width: 100%;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.status-bar {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
/* 顶部导航栏 */
|
||||
.nav-bar {
|
||||
height: 90rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
/* padding: 0 30rpx; */
|
||||
color: #fff;
|
||||
position: sticky;
|
||||
top: 44px;
|
||||
z-index: 100;
|
||||
margin-bottom: 20px;
|
||||
height: 90rpx;
|
||||
}
|
||||
|
||||
.nav-left {
|
||||
@@ -201,15 +209,16 @@ const addInvitation = () => {
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.back-icon {
|
||||
width: 36rpx;
|
||||
height: 36rpx;
|
||||
}
|
||||
|
||||
.nav-title {
|
||||
flex: 1;
|
||||
text-align: center;
|
||||
font-size: 32rpx;
|
||||
font-weight: 400;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
padding: 0 20rpx;
|
||||
font-weight: 500;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
@@ -220,153 +229,163 @@ const addInvitation = () => {
|
||||
/* 标签切换栏 */
|
||||
.tab-bar {
|
||||
display: flex;
|
||||
border-bottom: 1rpx solid rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
|
||||
.tab-item {
|
||||
/* flex: 1; */
|
||||
display: flex;
|
||||
text-align: left;
|
||||
padding: 20px 40px 0px 0px;
|
||||
font-size: 16px;
|
||||
color: #666;
|
||||
position: relative;
|
||||
padding: 24rpx 0;
|
||||
margin-right: 48rpx;
|
||||
font-size: 30rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.tab-item.active {
|
||||
color: #007aff;
|
||||
color: #2f77fd;
|
||||
font-weight: 500;
|
||||
}
|
||||
/* 激活标签下划线 */
|
||||
|
||||
.tab-item.active::after {
|
||||
content: '';
|
||||
content: "";
|
||||
position: absolute;
|
||||
bottom: -7px;
|
||||
left: 33%;
|
||||
bottom: 8rpx;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
width: 64px;
|
||||
height: 4px;
|
||||
border-radius: 6rpx;
|
||||
background-color: #2F77FD;
|
||||
/* background-color: linear-gradient(to bottom, #2F77FD, #CEDFFF); */
|
||||
width: 126rpx;
|
||||
height: 8rpx;
|
||||
border-radius: 32rpx;
|
||||
/* background-color: #2f77fd; */
|
||||
background: linear-gradient(to bottom, #2F77FD, #CEDFFF);
|
||||
}
|
||||
|
||||
/* 列表容器 */
|
||||
.list-container {
|
||||
height: calc(100vh - 220px); /* 预留导航、标签、按钮高度 */
|
||||
}
|
||||
|
||||
/* 访客列表项 */
|
||||
/* 访客卡片 */
|
||||
.visitor-item {
|
||||
margin-top: 24rpx;
|
||||
padding: 24rpx;
|
||||
background-color: #fff;
|
||||
margin: 25px 0px;
|
||||
padding: 15px;
|
||||
border-radius: 8px;
|
||||
border-radius: 16rpx;
|
||||
box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.04);
|
||||
}
|
||||
/* 列表项头部(姓名+状态) */
|
||||
|
||||
.item-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
.visitor-name {
|
||||
font-size: 16px;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
.visitor-name.visited{
|
||||
color: #999;
|
||||
}
|
||||
.status-tag {
|
||||
font-size: 14px;
|
||||
padding: 2px 8px;
|
||||
border-radius: 12px;
|
||||
}
|
||||
.status-tag.waiting {
|
||||
color: #2F77FD;
|
||||
/* background-color: #fff8e6; */
|
||||
}
|
||||
.status-tag.visited {
|
||||
color: #999999;
|
||||
/* background-color: #e6fffa; */
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
/* 列表项行数据 */
|
||||
.visitor-name {
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.visitor-name.visited {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.status-tag {
|
||||
font-size: 26rpx;
|
||||
}
|
||||
|
||||
.status-tag.waiting {
|
||||
color: #2f77fd;
|
||||
}
|
||||
|
||||
.status-tag.visited {
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 信息行 */
|
||||
.item-row {
|
||||
display: flex;
|
||||
margin-bottom: 8px;
|
||||
font-size: 14px;
|
||||
margin-bottom: 12rpx;
|
||||
font-size: 26rpx;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.label {
|
||||
color: #222;
|
||||
min-width: 80px;
|
||||
min-width: 140rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.value {
|
||||
color: #333;
|
||||
flex: 1;
|
||||
color: #333;
|
||||
}
|
||||
.label.visited{
|
||||
color: #999;
|
||||
|
||||
.label.visited,
|
||||
.value.visited {
|
||||
color: #999;
|
||||
}
|
||||
.value.visited{
|
||||
color: #999;
|
||||
}
|
||||
.time-text.visited{
|
||||
color: #999;
|
||||
}
|
||||
/* 列表项底部(时间+查看详情) */
|
||||
|
||||
/* 底部行 */
|
||||
.item-footer {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
margin-top: 10px;
|
||||
padding-top: 10px;
|
||||
/* border-top: 1px solid #f5f5f5; */
|
||||
margin-top: 16rpx;
|
||||
padding-top: 16rpx;
|
||||
border-top: 1rpx solid #f5f5f5;
|
||||
}
|
||||
|
||||
.time-text {
|
||||
font-size: 28rpx;
|
||||
/* color: #666; */
|
||||
font-size: 24rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
.time-text.visited {
|
||||
color: #bbb;
|
||||
}
|
||||
|
||||
.detail-btn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
font-size: 14px;
|
||||
font-size: 26rpx;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
/* 空状态 */
|
||||
.empty-state {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 100rpx 0;
|
||||
color: #ccc;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 120rpx 0;
|
||||
}
|
||||
|
||||
.empty-text {
|
||||
font-size: 32rpx;
|
||||
color: #999;
|
||||
margin-top: 20rpx;
|
||||
margin-bottom: 10rpx;
|
||||
margin-top: 20rpx;
|
||||
font-size: 28rpx;
|
||||
color: #999;
|
||||
}
|
||||
|
||||
/* 列表底部占位 */
|
||||
.list-bottom-space {
|
||||
height: 24rpx;
|
||||
}
|
||||
|
||||
/* 新增邀请按钮 */
|
||||
.add-btn {
|
||||
position: fixed;
|
||||
bottom: 20px;
|
||||
left: 15px;
|
||||
right: 15px;
|
||||
height: 44px;
|
||||
line-height: 44px;
|
||||
background-color: #007aff;
|
||||
color: #fff;
|
||||
border-radius: 8px;
|
||||
text-align: center;
|
||||
font-size: 16px;
|
||||
.add-btn-wrapper {
|
||||
height: 148rpx;
|
||||
display: flex;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
.add-text {
|
||||
margin-left: 5px;
|
||||
font-size: 28rpx;
|
||||
|
||||
.add-btn {
|
||||
width: 100%;
|
||||
height: 88rpx;
|
||||
line-height: 88rpx;
|
||||
background-color: #2f77fd;
|
||||
color: #fff;
|
||||
border-radius: 16rpx;
|
||||
text-align: center;
|
||||
font-size: 30rpx;
|
||||
font-weight: 500;
|
||||
box-shadow: 0 8rpx 24rpx rgba(47, 119, 253, 0.3);
|
||||
}
|
||||
</style>
|
||||
|
||||
.add-text {
|
||||
font-size: 30rpx;
|
||||
}
|
||||
</style>
|
||||
|
||||
Reference in New Issue
Block a user