Files
hzdyjs/mobile/src/pages/index/index.vue
T

1023 lines
32 KiB
Vue

<template>
<view class="page-container">
<!-- 统一头部 -->
<view class="unified-header">
<!-- 学校logo和标题 -->
<view class="school-banner-section">
<!-- <image class="school-logo" src="/static/logo-2.png" mode="aspectFit" /> -->
<text class="school-title">杭州第一技师学院智慧校园</text>
</view>
<!-- 用户信息区域 -->
<view class="user-section">
<!-- 左侧用户信息 -->
<view class="user-info" @click="handleUserClick">
<image
class="user-avatar"
:src="userInfo.avatar || '/static/default-avatar.png'"
mode="aspectFill"
/>
<view class="user-details">
<text class="user-name">{{ userInfo.name }}</text>
<text class="user-dept">{{ userInfo.deptName || '未设置部门' }}</text>
</view>
</view>
<!-- 右侧退出登录 -->
<view class="logout-btn" @click="handleLogout">
<text class="iconfont icon-logout logout-icon"></text>
</view>
</view>
</view>
<!-- 主要内容区域 -->
<scroll-view class="main-content" scroll-y enhanced :show-scrollbar="false">
<!-- 图片轮播 -->
<view class="banner-container">
<swiper
class="banner-swiper"
:indicator-dots="true"
:autoplay="true"
:interval="4000"
:duration="500"
indicator-color="rgba(255, 255, 255, 0.5)"
indicator-active-color="#ffffff"
circular
:disable-touch="false"
>
<swiper-item
v-for="(item, index) in bannerList"
:key="index"
class="banner-item"
>
<image
:src="item.src"
:alt="item.alt"
mode="aspectFill"
class="banner-image"
:lazy-load="true"
:fade-show="true"
@load="handleImageLoad"
@error="handleImageError"
/>
<view v-if="item.title" class="banner-title">
{{ item.title }}
</view>
</swiper-item>
</swiper>
</view>
<!-- 学工管理 -->
<Card v-if="hasStudentServices">
<template #header>
<view class="section-header">
<u-icon name="account" size="18" color="#1890ff" />
<text class="card-title">学工管理</text>
</view>
</template>
<GridLayout :columns="3" gap="16px">
<ServiceItem
v-if="hasPermi(['student:info:list'])"
title="学生信息"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="account" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['student:dorm:list'])"
title="宿舍管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="home" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['student:leave:list'])"
title="学生请假"
@click="gotoStudentLeave"
>
<template #icon>
<u-icon name="calendar" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['student:psychology:list'])"
title="心理健康"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="heart" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['student:club:list'])"
title="社团管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="star" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['student:counsel:list'])"
title="心理咨询"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="chat" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['student:info:edit'])"
title="学生信息完善"
@click="gotoStudentInfoComplete"
>
<template #icon>
<u-icon name="edit-pen" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 后勤管理 -->
<Card v-if="hasLogisticsServices">
<template #header>
<view class="section-header">
<u-icon name="setting" size="18" color="#52c41a" />
<text class="card-title">后勤管理</text>
</view>
</template>
<GridLayout :columns="3" gap="16px">
<ServiceItem
v-if="hasPermi(['logistics:repair:list'])"
title="物业报修"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="tools" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['logistics:venue:list'])"
title="场地预约"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="map" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['logistics:hall:list'])"
title="报告厅预约"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="play-circle" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['logistics:survey:list'])"
title="满意度调查"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="list" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['logistics:canteen:list'])"
title="食堂管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="rmb-circle" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['logistics:property:list'])"
title="物业管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="shop" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 招生就业 -->
<Card v-if="hasRecruitmentServices">
<template #header>
<view class="section-header">
<u-icon name="trophy" size="18" color="#fa8c16" />
<text class="card-title">招生就业</text>
</view>
</template>
<GridLayout :columns="3" gap="16px">
<ServiceItem
v-if="hasPermi(['recruitment:student:list'])"
title="学生管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="account" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['recruitment:graduate:list'])"
title="毕业生信息"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="star" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['recruitment:job:list'])"
title="就业信息"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="bag" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 人事管理 -->
<Card v-if="hasHRServices">
<template #header>
<view class="section-header">
<u-icon name="friends" size="18" color="#722ed1" />
<text class="card-title">人事管理</text>
</view>
</template>
<GridLayout :columns="3" gap="16px">
<ServiceItem
v-if="hasPermi(['hr:staff:list'])"
title="员工管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="account-circle" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['hr:abroad:list'])"
title="出国申请"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="plane" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['hr:training:list'])"
title="培训管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="bookmark" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 财务管理 -->
<Card v-if="hasFinanceServices">
<template #header>
<view class="section-header">
<u-icon name="rmb-circle" size="18" color="#13c2c2" />
<text class="card-title">财务管理</text>
</view>
</template>
<GridLayout :columns="3" gap="16px">
<ServiceItem
v-if="hasPermi(['finance:budget:list'])"
title="预算管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="money-circle" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['finance:expense:list'])"
title="费用报销"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="file-text" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['finance:invoice:list'])"
title="发票管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="order" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 系统管理 -->
<Card v-if="hasSystemServices">
<template #header>
<view class="section-header">
<u-icon name="setting" size="18" color="#f5222d" />
<text class="card-title">系统管理</text>
</view>
</template>
<GridLayout :columns="3" gap="16px">
<ServiceItem
v-if="hasPermi(['system:user:list'])"
title="用户管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="account-circle" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['system:role:list'])"
title="角色管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="lock" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['system:menu:list'])"
title="菜单管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="list" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['system:dept:list'])"
title="部门管理"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="home" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['system:config:list'])"
title="参数设置"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="setting" size="24" />
</template>
</ServiceItem>
<ServiceItem
v-if="hasPermi(['monitor:online:list'])"
title="在线用户"
@click="handleServiceClick"
>
<template #icon>
<u-icon name="wifi" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 工作流 -->
<Card v-if="hasWorkflowServices">
<template #header>
<view class="section-header">
<u-icon name="share" size="18" color="#eb2f96" />
<text class="card-title">工作流</text>
</view>
</template>
<GridLayout :columns="2" gap="16px">
<ServiceItem title="我发起的" @click="gotoMyDocument">
<template #icon>
<u-icon name="edit-pen" size="24" />
</template>
</ServiceItem>
<ServiceItem title="我的待办" @click="gotoAllTaskWaiting">
<template #icon>
<u-icon name="clock" size="24" />
</template>
</ServiceItem>
<ServiceItem title="我的已办" @click="gotoTaskFinish">
<template #icon>
<u-icon name="checkmark-circle" size="24" />
</template>
</ServiceItem>
<ServiceItem title="抄送我的" @click="gotoTaskCopyList">
<template #icon>
<u-icon name="copy" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 微信SDK测试 -->
<Card v-if="hasWechatTestAccess">
<template #header>
<view class="section-header">
<u-icon name="chat" size="18" color="#07c160" />
<text class="card-title">微信SDK测试</text>
</view>
</template>
<GridLayout :columns="2" gap="16px">
<ServiceItem title="JS-SDK测试" @click="gotoWechatSDKTest">
<template #icon>
<u-icon name="tools" size="24" />
</template>
</ServiceItem>
<ServiceItem title="功能检测" @click="gotoWechatSDKTest">
<template #icon>
<u-icon name="scan" size="24" />
</template>
</ServiceItem>
</GridLayout>
</Card>
<!-- 底部间距 -->
<view class="bottom-spacer"></view>
</scroll-view>
</view>
</template>
<script>
import Card from '@/components/Card.vue';
import ServiceItem from '@/components/ServiceItem.vue';
import GridLayout from '@/components/GridLayout.vue';
import { userManager, userState } from '@/utils/user';
import { api } from '@/common/request';
import { hasPermi, permissionMixin } from '@/utils/permission';
import RouterManager from '@/utils/router';
export default {
name: 'HomePage',
components: {
Card,
ServiceItem,
GridLayout,
},
mixins: [permissionMixin],
data() {
return {
userInfo: {
name: '用户',
avatar: '',
deptName: '',
},
// 轮播图片数据
bannerList: [
{
src: '/static/xx03.jpg',
alt: '校园风景1',
title: '西溪校区',
},
{
src: '/static/xx01.jpg',
alt: '校园风景1',
title: '临安校区',
},
{
src: '/static/xx02.jpg',
alt: '校园风景2',
title: '临安校区',
},
],
};
},
computed: {
// 检查各模块是否有权限
hasStudentServices() {
return (
this.hasPermi(['student:info:list']) ||
this.hasPermi(['student:dorm:list']) ||
this.hasPermi(['student:leave:list']) ||
this.hasPermi(['student:psychology:list']) ||
this.hasPermi(['student:club:list']) ||
this.hasPermi(['student:counsel:list']) ||
this.hasPermi(['student:info:edit'])
);
},
hasLogisticsServices() {
return (
this.hasPermi(['logistics:repair:list']) ||
this.hasPermi(['logistics:venue:list']) ||
this.hasPermi(['logistics:hall:list']) ||
this.hasPermi(['logistics:survey:list']) ||
this.hasPermi(['logistics:canteen:list']) ||
this.hasPermi(['logistics:property:list'])
);
},
hasRecruitmentServices() {
return (
this.hasPermi(['recruitment:student:list']) ||
this.hasPermi(['recruitment:graduate:list']) ||
this.hasPermi(['recruitment:job:list'])
);
},
hasHRServices() {
return (
this.hasPermi(['hr:staff:list']) ||
this.hasPermi(['hr:abroad:list']) ||
this.hasPermi(['hr:training:list'])
);
},
hasFinanceServices() {
return (
this.hasPermi(['finance:budget:list']) ||
this.hasPermi(['finance:expense:list']) ||
this.hasPermi(['finance:invoice:list'])
);
},
hasSystemServices() {
return (
this.hasPermi(['system:user:list']) ||
this.hasPermi(['system:role:list']) ||
this.hasPermi(['system:menu:list']) ||
this.hasPermi(['system:dept:list']) ||
this.hasPermi(['system:config:list']) ||
this.hasPermi(['monitor:online:list'])
);
},
hasWorkflowServices() {
return true; // 工作流基础功能总是显示
},
hasWechatTestAccess() {
return true; // 微信SDK测试功能总是显示(开发测试用)
},
},
onLoad() {
this.checkLoginStatus();
this.loadUserInfo();
},
methods: {
// 全局权限校验方法
hasPermi(permissions) {
return hasPermi(permissions);
},
// 检查登录状态
checkLoginStatus() {
if (!userState.autoLoginCheck()) {
return;
}
},
// 加载用户信息
loadUserInfo() {
const displayUser = userManager.formatUserForDisplay();
if (displayUser) {
this.userInfo.name = displayUser.name;
this.userInfo.avatar = displayUser.avatar;
this.userInfo.deptName = displayUser.deptName;
}
},
// 点击用户头像
handleUserClick() {
const info = userManager.getUserInfoString();
uni.showModal({
title: '个人信息',
content: info,
showCancel: false,
});
},
// 退出登录
async handleLogout() {
try {
// 显示确认对话框
const confirmed = await this.showConfirm('确认退出', '确定注销并退出系统吗?');
if (!confirmed) return;
// 显示加载提示
uni.showLoading({ title: '退出中...' });
// 调用后端退出接口
try {
await api.logout();
console.log('✅ 后端退出接口调用成功');
} catch (error) {
console.warn('⚠️ 调用退出接口失败,将继续本地清理:', error);
// 即使后端接口失败,也继续本地清理
}
// 清理本地数据
await userState.handleLogout();
// 隐藏加载提示
uni.hideLoading();
// 显示退出成功提示
uni.showToast({
title: '退出成功',
icon: 'success',
duration: 1500,
});
} catch (error) {
// 隐藏加载提示
uni.hideLoading();
console.error('退出登录失败:', error);
uni.showToast({
title: '退出失败',
icon: 'error',
duration: 2000,
});
}
},
// 服务点击处理
handleServiceClick(service) {
// 使用路由管理工具进行跳转
RouterManager.navigateToService(service.title, {
onSuccess: () => {
console.log(`✅ 成功跳转到服务: ${service.title}`);
},
onCreatePage: (serviceName, route) => {
// 可以在这里添加页面创建逻辑
console.log(`📝 创建页面: ${serviceName} -> ${route}`);
},
});
},
// 跳转到我发起的(新版)
gotoMyDocument() {
uni.navigateTo({
url: '/pages/task/myDocument',
});
},
// 跳转到我的待办
gotoAllTaskWaiting() {
uni.navigateTo({
url: '/pages/task/allTaskWaiting',
});
},
// 跳转到我的已办
gotoTaskFinish() {
uni.navigateTo({
url: '/pages/task/taskFinish',
});
},
// 跳转到我的抄送
gotoTaskCopyList() {
uni.navigateTo({
url: '/pages/task/taskCopyList',
});
},
// 跳转到微信SDK测试页面
gotoWechatSDKTest() {
uni.navigateTo({
url: '/pages/wechat/js-sdk-test',
});
},
// 跳转到学生信息完善页面
gotoStudentInfoComplete() {
uni.navigateTo({
url: '/pages/xg/xsjcxx/xsws/index',
});
},
// 跳转到学生请假页面
gotoStudentLeave() {
uni.navigateTo({
url: '/pages/xg/xsjcxx/xsqj/leave/index',
});
},
// 图片加载成功处理
handleImageLoad(event) {
console.log('✅ 轮播图片加载成功:', event.detail);
},
// 图片加载失败处理
handleImageError(event) {
console.error('❌ 轮播图片加载失败:', event.detail);
uni.showToast({
title: '图片加载失败',
icon: 'none',
duration: 2000,
});
},
// 确认对话框
showConfirm(title, content) {
return new Promise((resolve) => {
uni.showModal({
title,
content,
success: (res) => {
resolve(res.confirm);
},
fail: () => {
resolve(false);
},
});
});
},
},
};
</script>
<style lang="scss" scoped>
.page-container {
min-height: 100vh;
background-color: #f5f5f5;
display: flex;
flex-direction: column;
}
/* 统一头部 */
.unified-header {
background: linear-gradient(135deg, #007aff, #0051d9); /* 渐变色背景 */
padding: calc(var(--status-bar-height) + 12px) 16px 16px;
box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
display: flex;
flex-direction: column;
gap: 16px;
}
.school-banner-section {
display: flex;
align-items: center;
justify-content: center;
gap: 12px;
}
.school-logo {
width: 36px;
height: 36px;
border-radius: 8px;
background-color: rgba(255, 255, 255, 0.1);
padding: 2px;
}
.school-title {
font-size: 18px;
font-weight: 600;
color: #ffffff;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.3);
letter-spacing: 1px;
}
.user-section {
display: flex;
justify-content: space-between;
align-items: center;
}
.user-info {
display: flex;
align-items: center;
flex: 1;
cursor: pointer;
}
.user-avatar {
width: 48px;
height: 48px;
border-radius: 50%;
border: 2px solid rgba(255, 255, 255, 0.3);
margin-right: 12px;
}
.user-details {
display: flex;
flex-direction: column;
}
.user-name {
font-size: 18px;
font-weight: 600;
color: #ffffff;
margin-bottom: 2px;
}
.user-dept {
font-size: 14px;
color: rgba(255, 255, 255, 0.8);
}
.logout-btn {
width: 40px;
height: 40px;
border-radius: 50%;
display: flex;
align-items: center;
justify-content: center;
transition: all 0.3s ease;
&:active {
background: rgba(255, 255, 255, 0.25);
transform: scale(0.95);
}
}
/* 退出登录图标样式 */
.logout-icon {
width: 20px;
height: 20px;
font-size: 20px;
color: #ffffff !important;
line-height: 1;
display: flex;
align-items: center;
justify-content: center;
/* 使用filter将SVG图标转换为白色 */
filter: brightness(0) saturate(100%) invert(100%) sepia(0%) saturate(0%) hue-rotate(0deg)
brightness(100%) contrast(100%) !important;
}
/* 主要内容区域 */
.main-content {
flex: 1;
width: 100%;
padding: 16px;
padding-bottom: calc(20px + env(safe-area-inset-bottom));
box-sizing: border-box;
}
/* 轮播图容器 */
.banner-container {
margin: 0 0 20px 0;
border-radius: 12px;
overflow: hidden;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
background-color: #ffffff;
width: 100%;
box-sizing: border-box;
/* 确保容器不会超出父元素边界 */
max-width: 100%;
}
.banner-swiper {
height: 200px;
border-radius: 12px;
width: 100%;
box-sizing: border-box;
/* 确保轮播器不会超出容器边界 */
max-width: 100%;
overflow: hidden;
}
.banner-item {
position: relative;
border-radius: 12px;
overflow: hidden;
width: 100%;
height: 100%;
box-sizing: border-box;
}
.banner-image {
width: 100%;
height: 100%;
border-radius: 12px;
object-fit: cover;
transition: all 0.3s ease;
display: block;
box-sizing: border-box;
/* 确保图片不会超出容器边界 */
max-width: 100%;
max-height: 100%;
}
.banner-title {
position: absolute;
bottom: 0;
left: 0;
right: 0;
background: linear-gradient(transparent, rgba(0, 0, 0, 0.7));
color: #ffffff;
padding: 20px 16px 16px;
font-size: 16px;
font-weight: 600;
text-shadow: 1px 1px 3px rgba(0, 0, 0, 0.5);
letter-spacing: 0.5px;
}
/* 分组标题 */
.section-header {
display: flex;
align-items: center;
gap: 8px;
}
.card-title {
font-size: 18px;
font-weight: 600;
color: #333333;
}
/* 底部间距 */
.bottom-spacer {
height: 20px;
}
/* 页面进入动画 */
.page-container {
animation: fadeInUp 0.6s ease-out;
}
@keyframes fadeInUp {
from {
opacity: 0;
transform: translateY(20px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
/* 响应式设计 */
@media (max-width: 375px) {
.unified-header {
padding-left: 12px;
padding-right: 12px;
}
.main-content {
padding: 8px 12px;
width: 100%;
box-sizing: border-box;
}
.user-avatar {
width: 40px;
height: 40px;
}
.user-name {
font-size: 16px;
}
/* 小屏幕轮播图优化 */
.banner-container {
margin: 0 0 12px 0;
width: 100%;
box-sizing: border-box;
max-width: 100%;
}
.banner-swiper {
height: 160px;
width: 100%;
box-sizing: border-box;
}
.banner-title {
font-size: 14px;
padding: 16px 12px 12px;
}
}
</style>