上传文件至 /

This commit is contained in:
znnsun 2024-12-20 07:11:28 +00:00
commit 3e81dc0f4e
5 changed files with 847 additions and 0 deletions

150
allHomework.vue Normal file
View File

@ -0,0 +1,150 @@
<template>
<view class="container">
<!-- 页面标题 -->
<view class="header">
<text class="title">作业</text>
</view>
<!-- 作业列表表格 -->
<view class="table-container">
<view class="table">
<!-- 表头 -->
<view class="table-row table-header">
<text class="table-cell">作业标题</text>
<text class="table-cell">详细信息</text>
</view>
<!-- 表格内容 -->
<view v-for="(item, index) in homeworkList" :key="index" class="table-row">
<text class="table-cell">{{ item.title }}</text>
<text class="table-cell">
<button class="detail-button" @click="goToSubmitPage(item)">提交作业</button>
</text>
</view>
</view>
</view>
</view>
</template>
<script>
import {
h
} from "vue";
export default {
data() {
return {
homeworkList: [] //
};
},
methods: {
//
fetchHomeworkList() {
const token = uni.getStorageSync('token'); // token
if (!token) {
uni.showToast({
title: '未登录,请重新登录',
icon: 'none'
});
return;
}
uni.request({
url: `${this.$baseUrl}/homework/homework/list`,
method: 'GET',
header: {
Authorization: `Bearer ${token}` // token Authorization
},
success: (res) => {
if (res.data.code === 200) {
this.homeworkList = res.data.rows; // res.data.rows
} else {
uni.showToast({
title: res.data.message || '获取作业失败',
icon: 'none'
});
}
},
fail: () => {
uni.showToast({
title: '网络错误,请稍后重试',
icon: 'none'
});
}
});
},
//
goToSubmitPage(homework) {
uni.navigateTo({
url: `/pages/allHomework/submitHomework?id=${homework.id}&title=${homework.title}&content=${homework.content}` // ID
});
}
},
onLoad() {
this.fetchHomeworkList(); //
}
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
background-color: #f8f9fa;
height: 100vh;
}
.header {
background-color: #007bff;
padding: 15px;
text-align: center;
}
.title {
color: #fff;
font-size: 24px;
font-weight: bold;
}
.table-container {
margin: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.table {
width: 100%;
}
.table-row {
display: flex;
flex-direction: row;
align-items: center;
border-bottom: 1px solid #ddd;
}
.table-header {
background-color: #f1f1f1;
font-weight: bold;
}
.table-cell {
flex: 1;
padding: 10px;
text-align: center;
font-size: 14px;
}
.detail-button {
background-color: #007bff;
color: #fff;
padding: 8px 12px;
border: none;
border-radius: 5px;
font-size: 14px;
cursor: pointer;
}
.detail-button:hover {
background-color: #0056b3;
}
</style>

158
excellentHomework.vue Normal file
View File

@ -0,0 +1,158 @@
<template>
<view class="container">
<!-- 页面标题 -->
<view class="header">
<text class="title">优秀作业展示</text>
</view>
<!-- 作业列表表格 -->
<view class="table-container">
<view class="table">
<!-- 表头 -->
<view class="table-row table-header">
<text class="table-cell">学生用户名</text>
<text class="table-cell">作业标题</text>
<!-- <text class="table-cell">作业内容</text> -->
<text class="table-cell">分数</text>
<text class="table-cell">教师评语</text>
<text class="table-cell">操作</text>
</view>
<!-- 表格内容 -->
<view v-for="(item, index) in submittedHomework" :key="index" class="table-row">
<text class="table-cell">{{ item.studentUsername }}</text>
<text class="table-cell">{{ item.homeworkTitle }}</text>
<!-- <text class="table-cell">{{ item.homeworkContent }}</text> -->
<text class="table-cell">{{ item.grade }}</text>
<text class="table-cell">{{ item.comment }}</text>
<text class="table-cell">
<button class="detail-button" @click="viewDetail(item.id)">查看详情</button>
</text>
</view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
submittedHomework: [], //
nickName: '' //
};
},
methods: {
//
fetchSubmittedHomework() {
const token = uni.getStorageSync('token'); // token
this.nickName = uni.getStorageSync('nickName'); //
if (!token || !this.nickName) {
uni.showToast({
title: '未登录,请重新登录',
icon: 'none'
});
return;
}
uni.request({
url: `${this.$baseUrl}/homework/studentHomework/excellentlist`,
method: 'GET',
header: {
Authorization: `Bearer ${token}`
},
success: (res) => {
if (res.data.code === 200) {
this.submittedHomework = res.data.data;
} else {
uni.showToast({
title: res.data.message || '获取数据失败',
icon: 'none'
});
}
},
fail: () => {
uni.showToast({
title: '网络错误,请稍后重试',
icon: 'none'
});
}
});
},
//
viewDetail(homeworkId) {
uni.navigateTo({
url: `/pages/excellentHomework/homeworkDetail?id=${homeworkId}` // ID
});
}
},
onLoad() {
this.fetchSubmittedHomework(); //
}
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
background-color: #f8f9fa;
height: 100vh;
}
.header {
background-color: #007bff;
padding: 15px;
text-align: center;
}
.title {
color: #fff;
font-size: 24px;
font-weight: bold;
}
.table-container {
margin: 20px;
background-color: #fff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
overflow: hidden;
}
.table {
width: 100%;
}
.table-row {
display: flex;
flex-direction: row;
align-items: center;
border-bottom: 1px solid #ddd;
}
.table-header {
background-color: #f1f1f1;
font-weight: bold;
}
.table-cell {
flex: 1;
padding: 10px;
text-align: center;
font-size: 14px;
}
.detail-button {
background-color: #007bff;
color: #fff;
padding: 8px 12px;
border: none;
border-radius: 5px;
font-size: 14px;
cursor: pointer;
}
.detail-button:hover {
background-color: #0056b3;
}
</style>

184
homeworkDetail.vue Normal file
View File

@ -0,0 +1,184 @@
<template>
<view class="container">
<!-- 页面标题 -->
<view class="header">
<text class="title">作业详情</text>
</view>
<!-- 作业详情表单 -->
<view class="form-container">
<view class="form-item">
<text class="label">学生姓名</text>
<input v-model="homeworkDetail.studentUsername" class="input disabled" disabled />
</view>
<view class="form-item">
<text class="label">作业标题</text>
<input v-model="homeworkDetail.homeworkTitle" class="input disabled" disabled />
</view>
<view class="form-item">
<text class="label">作业内容</text>
<textarea v-model="homeworkDetail.homeworkContent" class="textarea disabled" disabled></textarea>
</view>
<view class="form-item">
<text class="label">作业评语</text>
<textarea v-model="homeworkDetail.comment" class="textarea disabled" disabled></textarea>
</view>
<view class="form-item">
<text class="label">作业分数</text>
<input v-model="homeworkDetail.grade" class="input disabled" type="number" disabled />
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
homeworkId: null, // ID
homeworkDetail: {
studentUsername: '',
homeworkTitle: '',
homeworkContent: '',
comment: '',
grade: ''
}, //
};
},
onLoad(options) {
this.homeworkId = options.id; // ID
this.fetchHomeworkDetail(); //
},
methods: {
//
fetchHomeworkDetail() {
const token = uni.getStorageSync('token');
if (!token) {
uni.showToast({
title: '未登录,请重新登录',
icon: 'none'
});
return;
}
uni.request({
url: `${this.$baseUrl}/homework/studentHomework/${this.homeworkId}`,
method: 'GET',
header: {
Authorization: `Bearer ${token}`
},
success: (res) => {
if (res.data.code === 200) {
this.homeworkDetail = res.data.data;
} else {
uni.showToast({
title: res.data.message || '获取作业详情失败',
icon: 'none'
});
}
},
fail: () => {
uni.showToast({
title: '网络错误,请稍后重试',
icon: 'none'
});
}
});
},
}
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
background-color: #f8f9fa;
height: 100vh;
}
.header {
background-color: #007bff;
padding: 15px;
text-align: center;
}
.title {
color: #fff;
font-size: 24px;
font-weight: bold;
}
.form-container {
padding: 20px;
background-color: #fff;
margin: 15px;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.form-item {
margin-bottom: 20px;
}
.label {
font-size: 16px;
font-weight: bold;
margin-bottom: 5px;
display: block;
color: #333;
}
.input,
.textarea {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 5px;
}
.textarea {
height: 100px;
resize: none;
}
.input.disabled,
.textarea.disabled {
background-color: #f5f5f5;
/* 灰色背景 */
color: #999;
/* 灰色字体 */
cursor: not-allowed;
}
.update-button {
width: 100%;
padding: 15px;
background-color: #007bff;
color: #fff;
font-size: 18px;
border: none;
border-radius: 5px;
text-align: center;
}
.update-button.disabled {
background-color: #ccc;
cursor: not-allowed;
}
.update-button:hover:not(.disabled) {
background-color: #0056b3;
}
</style>

210
index.vue Normal file
View File

@ -0,0 +1,210 @@
<template>
<view class="container">
<!-- 公告区域 -->
<view class="announcement">
<text class="announcement-title">公告</text>
<text class="announcement-content">{{ announcement }}</text>
</view>
<!-- 按钮功能区 -->
<view class="button-group">
<button class="button" @click="viewAllHomework">查看所有作业</button>
<button class="button" @click="viewMyHomework">查看我提交的作业</button>
<button class="button" @click="viewExcellentHomework">查看优秀作业</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
};
},
onLoad() {
this.fetchUserInfo(); //
},
methods: {
//
fetchUserInfo() {
const token = uni.getStorageSync('token'); // token
if (!token) {
uni.showToast({
title: '未登录,请前往登录登录',
icon: 'none'
});
//
uni.reLaunch({
url: '/pages/login/login'
});
}
uni.request({
url: `${this.$baseUrl}/getInfo`,
method: 'GET',
header: {
Authorization: `Bearer ${token}` // token Authorization
},
success: (res) => {
if (res.data.code === 200) {
this.userInfo = res.data.user;
uni.setStorageSync('nickName', this.userInfo.nickName); //
} else {
uni.showToast({
title: res.data.message || '获取用户信息失败',
icon: 'none'
});
}
},
fail: () => {
uni.showToast({
title: '网络错误,请稍后重试',
icon: 'none'
});
}
});
},
viewAllHomework() {
uni.navigateTo({
url: '/pages/allHomework/allHomework' //
});
},
viewMyHomework() {
uni.navigateTo({
url: '/pages/myHomework/myHomework' //
});
},
viewExcellentHomework() {
uni.navigateTo({
url: '/pages/excellentHomework/excellentHomework' //
});
}
}
};
</script>
<style>
<style>.container {
display: flex;
flex-direction: column;
background-color: #f8f9fa;
height: 100vh;
font-family: Arial, sans-serif;
}
.header {
background-color: #007bff;
padding: 15px;
text-align: center;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.title {
color: #fff;
font-size: 24px;
font-weight: bold;
}
.announcement {
padding: 20px;
background-color: #fef8e1;
border: 1px solid #ffd966;
border-radius: 8px;
margin: 15px 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}
.announcement-title {
font-weight: bold;
font-size: 18px;
color: #333;
margin-bottom: 8px;
}
.announcement-content {
font-size: 14px;
color: #555;
line-height: 1.6;
}
.button-group {
display: flex;
flex-direction: column;
align-items: center;
margin-top: 20px;
}
.button {
width: 90%;
max-width: 300px;
padding: 15px;
background-color: #007bff;
color: #fff;
text-align: center;
border-radius: 8px;
font-size: 16px;
font-weight: bold;
border: none;
margin-bottom: 15px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease-in-out;
}
.button:hover {
background-color: #0056b3;
transform: translateY(-2px);
}
.button:active {
background-color: #004494;
transform: translateY(0);
}
.section-title {
font-size: 18px;
font-weight: bold;
color: #333;
margin: 20px 15px 10px;
}
.homework-section {
padding: 15px;
margin: 0 10px;
background-color: #ffffff;
border-radius: 8px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.homework-item {
padding: 10px 15px;
background-color: #f8f9fa;
border: 1px solid #ddd;
border-radius: 5px;
margin-bottom: 10px;
display: flex;
flex-direction: column;
}
.homework-title {
font-weight: bold;
font-size: 16px;
color: #333;
}
.homework-deadline {
font-size: 14px;
color: #666;
margin-top: 5px;
}
@media screen and (max-width: 768px) {
.button {
width: 100%;
}
}
</style>

145
submitHomework.vue Normal file
View File

@ -0,0 +1,145 @@
<template>
<view class="container">
<view class="header">
<text class="title">提交作业</text>
</view>
<view class="form-container">
<input v-model="title" class="input" placeholder="作业标题" disabled />
<textarea v-model="content" class="textarea" placeholder="作业描述" disabled></textarea>
<textarea v-model="homeworkContent" class="textarea" placeholder="请输入作业内容"></textarea>
<button class="submit-button" @click="submitHomework">提交作业</button>
</view>
</view>
</template>
<script>
export default {
data() {
return {
homeworkId: null, // ID
title: '', //
content: '', //
homeworkContent: '', //
nickName: '',
};
},
onLoad(options) {
this.homeworkId = options.id; // ID
this.title = options.title; // ID
this.content = options.content; // ID
this.nickName = uni.getStorageSync("nickName")
},
methods: {
submitHomework() {
const token = uni.getStorageSync('token'); // token
if (!token) {
uni.showToast({
title: '未登录,请重新登录',
icon: 'none'
});
return;
}
if (!this.title || !this.content) {
uni.showToast({
title: '请填写完整的作业信息',
icon: 'none'
});
return;
}
uni.request({
url: `${this.$baseUrl}/homework/studentHomework`,
method: 'POST',
header: {
Authorization: `Bearer ${token}`
},
data: {
homeworkTitle: this.title,
homeworkContent: this.homeworkContent,
studentUsername: this.nickName,
},
success: (res) => {
if (res.data.code === 200) {
uni.showToast({
title: '提交成功',
icon: 'success'
});
uni.navigateBack(); //
} else {
uni.showToast({
title: res.data.message || '提交失败',
icon: 'none'
});
}
},
fail: () => {
uni.showToast({
title: '网络错误,请稍后重试',
icon: 'none'
});
}
});
}
}
};
</script>
<style>
.container {
display: flex;
flex-direction: column;
background-color: #f8f9fa;
height: 100vh;
}
.header {
background-color: #007bff;
padding: 15px;
text-align: center;
}
.title {
color: #fff;
font-size: 24px;
font-weight: bold;
}
.form-container {
padding: 20px;
}
.input,
.textarea {
width: 100%;
margin-bottom: 20px;
padding: 10px;
font-size: 16px;
border: 1px solid #ddd;
border-radius: 5px;
}
.textarea {
height: 100px;
resize: none;
}
.submit-button {
width: 100%;
padding: 15px;
background-color: #007bff;
color: #fff;
border: none;
border-radius: 5px;
font-size: 18px;
text-align: center;
}
.submit-button:hover {
background-color: #0056b3;
}
</style>