You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
teamwk/www/static/work1.html

188 lines
6.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>中草药识别</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
padding: 20px;
background-color: #f8f8f8;
color: #333;
}
h1 {
text-align: center;
color: #009688;
}
p {
color: #666;
}
ul {
list-style-type: square;
margin-left: 20px;
}
table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: center;
}
th {
background-color: #f2f2f2;
}
img {
max-width: 100%;
height: auto;
margin-top: 20px;
}
.module {
padding: 10px;
margin: 10px;
border: 1px solid #009688;
background-color: #e0f2f1;
cursor: pointer;
transition: background-color 0.3s;
}
.module:hover {
background-color: #b2dfdb;
}
.return-btn {
display: block;
margin-top: 10px;
padding: 10px;
background-color: #138b5b;
color: #fff;
text-align: center;
text-decoration: none;
cursor: pointer;
border-radius: 5px;
}
.return-btn:hover {
background-color: #517900;
}
</style>
<script>
document.addEventListener('DOMContentLoaded', function() {//从后端获取用户名
var params = new URLSearchParams(window.location.search);
var username = params.get('username');
if (username) {
document.getElementById('username1').textContent = username;
}
});
document.addEventListener('DOMContentLoaded', function() {//从后端获取这个用户的身份user/admin
var params = new URLSearchParams(window.location.search);
var userid = params.get('userid');
if (userid === 'admin') {
document.getElementById('managementBtn').style.display = 'block'; // 显示后台管理按钮
} else {
document.getElementById('managementBtn').style.display = 'none'; // 隐藏后台管理按钮
}
});
</script>
</head>
<body>
<!-- 把后端获取的用户名显示在欢迎标题上 -->
<h1>欢迎您,尊敬的 <span id="username1"></span></h1>
<p>欢迎访问中草药识别系统!</p>
<!-- 按钮列表 -->
<div id="moduleSelection">
<div class="module" onclick="openModule('reservation')">识别查询</div>
<div class="module" onclick="openModule('management')" id="managementBtn" >后台管理</div>
</div>
<div id="reservation" style="display: none;">
<h2>识别模块</h2>
<p>在这里上传你的中草药图片进行识别。</p>
<form id="uploadForm" enctype="multipart/form-data">
<input type="file" id="fileInput" name="image" accept="image/*">
<button type="button" onclick="uploadImage()">上传并识别</button>
</form>
<div id="result"></div>
<a href="#" class="return-btn" onclick="goBack()">返回</a>
</div>
<div id="management" style="display: none;">
<h2>系统后台数据查询与管理模块</h2>
<p>这是后台数据管理模块的内容。</p>
<a href="#" class="return-btn" onclick="goBack()">返回模块选择</a>
</div>
<!-- 页尾的一些用户友好内容 -->
<h2>联系我们</h2>
<p>如有任何关于系统的疑问或建议,请联系我们:</p>
<address>
电子邮件:<a href="mailto:aa893824054@163.com">aa893824054@163.com</a><br>
电话184-7635-1355
</address>
<script>
function openModule(moduleId) {//打开模块的功能
var modules = document.getElementsByClassName('module');
for (var i = 0; i < modules.length; i++) {
modules[i].style.display = 'none';
}
document.getElementById('moduleSelection').style.display = 'none';
document.getElementById(moduleId).style.display = 'block';
}
function uploadImage() {//上传图片的功能
var formData = new FormData(document.getElementById("uploadForm"));
// 更换你的实际服务器端API地址
fetch('your-server-url/api/upload', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
document.getElementById("result").innerHTML = "识别结果: " + data.result;
})
.catch(error => console.error('Error:', error));
}
document.addEventListener('DOMContentLoaded', function() {//监听程序,用来解决:点击返回按钮后重新出现“后台管理”按钮的问题
var params = new URLSearchParams(window.location.search);
var username = params.get('username');//获取用户名
if (username) {
document.getElementById('username1').textContent = username;
}
var userid = params.get('userid');//获取身份
updateManagementButtonDisplay(userid);
})
function updateManagementButtonDisplay(userid) {//根据身份设定“后台管理”按钮是否隐藏
if (userid === 'admin') {
document.getElementById('managementBtn').style.display = 'block';
} else {
document.getElementById('managementBtn').style.display = 'none';
}
}
function goBack() {//返回功能同时也是“不断监测id来决定是否隐藏后台管理按钮”的功能的组成部分
var modules = document.getElementsByClassName('module');
for (var i = 0; i < modules.length; i++) {
modules[i].style.display = 'block';
}
document.getElementById("moduleSelection").style.display = 'block';
document.getElementById("reservation").style.display = 'none';
document.getElementById("management").style.display = 'none';
var params = new URLSearchParams(window.location.search);
var userid = params.get('userid');
updateManagementButtonDisplay(userid);
}
</script>
</body>
</html>