宿舍管理系统代码详解(主页面)

        本篇将对管理系统的主页面的代码进行详细的介绍。

目录

一、主页面前端代码

        1.样式展示

        2.代码详解 

        (1)template部分

        (2)script部分

        (3)路由导航守卫

        (4)在vue中引用vue


一、主页面前端代码

        1.样式展示

        2.代码详解 

        (1)template部分

<template>
	<el-container>
		<el-header style="text-align: right; font-size: 12px">
			<div class="header-title">
				后台管理系统
			</div>
			<el-dropdown>
				<i class="el-icon-setting" style="margin-right: 15px"></i>
				<el-dropdown-menu slot="dropdown">
					<el-dropdown-item>个人信息</el-dropdown-item>
					<el-dropdown-item>修改密码</el-dropdown-item>
					<el-dropdown-item><span @click="logout()">安全退出</span></el-dropdown-item>
				</el-dropdown-menu>
			</el-dropdown>
			<span>{{account}}</span>
		</el-header>
		<el-container>
			<el-aside width="200px" style="background-color: rgb(238, 241, 246)">

				<el-menu :default-openeds="['1', '3']" router>
					<el-submenu index="1">
						<template slot="title"><i class="el-icon-message"></i>导航一</template>
						<el-menu-item-group>
							<el-menu-item index="/majorlist">专业管理</el-menu-item>
							<el-menu-item index="/studentList">学生管理</el-menu-item>
							<el-menu-item index="/BuildList">楼栋管理</el-menu-item>
							<el-menu-item index="/BmList">宿舍员管理</el-menu-item>
							<el-menu-item index="/DormList">宿舍员管理</el-menu-item>
						</el-menu-item-group>
					</el-submenu>
				</el-menu>
			</el-aside>
			<el-main>
				<router-view></router-view>
			</el-main>
		</el-container>
	</el-container>
</template>

        这部分代码依旧是element-UI组件里面的布局代码,从官网上可以直接引用(Element - 全球最流行的 Vue UI 框架)。然后在基础上修改以满足自己需要的内容样式。

注意这部分的导航这部分的代码,在新建导航或者新建导航内的内容时,记得将标签前后都带上。

        (2)script部分

<script>
	export default {
		data() {
			return {
				account: ""
			}
		},
		methods: {
			logout() {
				this.$confirm('您确定要退出吗?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				}).then(() => {
					sessionStorage.clear();
					this.$router.replace("/login");
				})
			}
		},
		mounted() {
			//去除要显示的用户信息
			this.account = sessionStorage.getItem("account");
		}
	}
</script>

        1.account数据需要显示在主页面右上角,所以需要传值

        2.logout()函数:用来退出登录的,直接退出到登录界面

        (3)路由导航守卫

网页有可能会跳过登录界面直接进入到主页面,是不安全的,所以要添加导航守卫,确保在点击其他的内容时吗,进行判断,当用户信息为空时返回到登录界面。

//路由导航守卫,每当前端发生一次路由跳转时,会自动触发beforeEach();
router.beforeEach((to, from, next) => {
	if (to.path == '/login') { //如果访问登录组件,不需要做任何判断,直接放行
		return next(); //放行到目标组件
	} else {
		var account = sessionStorage.getItem("account");
		if (account == null) { //用户信息为空,说明用户没有登录
			return next("/login");
		} else { //说明用户已经登录
			next();
		}
	}
})

        (4)在vue中引用vue

        在vue中调用其他的vue文件,会重新打开一个新的页面来显示新的vue内的东西,我们需要的是在本网页内打开,所以需要使用children方法:

routes: [{
			path: '/',
			component: Login
		},
		{
			path: '/login',
			component: Login
		},
		{
			path: '/Main',
			component: Guanli,
			children: [{
					path: "/majorlist",
					component: MajorList
				},
				{
					path: "/StudentList",
					component: StudentList
				},
				{
					path: "/BuildList",
					component: BuildList
				},
				{
					path: "/BmList",
					component: BmList
				},
				{
					path: "/DormList",
					component: DormList
				}
			]
		}
	]

        vue中引用vue定义是这样定义的,但是还需要进行路由导入

import MajorList from '../views/major/MajorList.vue';
import StudentList from '../views/student/StudentList.vue';
import BuildList from '../views/building/BuildList.vue';
import BmList from '../views/buildmanager/BmList.vue';
import DormList from '../views/dorms/DormList.vue';

        因为主页面只是用来展示,调用其他的导航内容的,所以不需要与后端交互,没有交互的内容,因此没有后端的代码。

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
好的,下面是一个 SWT 的示例代码,演示如何创建和设置 GridLayout 布局管理器: ```java import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; import org.eclipse.swt.widgets.Text; public class LayoutManagerExample { public static void main(String[] args) { Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new GridLayout(2, false)); shell.setText("LayoutManager Example"); shell.setSize(400, 300); Label nameLabel = new Label(shell, SWT.NONE); nameLabel.setText("Name:"); Text nameText = new Text(shell, SWT.BORDER); nameText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Label ageLabel = new Label(shell, SWT.NONE); ageLabel.setText("Age:"); Text ageText = new Text(shell, SWT.BORDER); ageText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false)); Button okButton = new Button(shell, SWT.PUSH); okButton.setText("OK"); okButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); Button cancelButton = new Button(shell, SWT.PUSH); cancelButton.setText("Cancel"); cancelButton.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false)); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) { display.sleep(); } } display.dispose(); } } ``` 在这个示例中,我们创建了一个 SWT 的 Shell,并设置了其布局管理器为 GridLayout。GridLayout 接受两个参数,第一个参数表示行数,第二个参数表示列数。我们将行数设置为 2,列数设置为 false,表示列宽不相等。 接着,我们创建了四个控件,分别是 Label、Text 和 Button,并分别放置在不同的位置上。我们使用 GridData 来设置控件的布局参数。GridData 接受四个参数,分别是水平方向的填充方式、垂直方向的填充方式、是否占据多行、是否占据多列。 最后,我们打开了 Shell,并启动事件循环,以便用户可以与界面进行交互。 希望这个示例可以帮助你理解如何在 SWT 中创建和设置布局管理器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

刘伊珂

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值