Browse Source

feat(student): 学生端增加作业提交功能并优化作业上传逻辑

- 新增 xy_assignmentSubmitObj 接口用于提交作业
- 修改作业上传逻辑,支持图片和视频上传
- 优化作业提交数据结构,增加学生资源 ID 和内容文本字段
- 调整作业列表页面样式,移除视频边框
master
liutong 1 year ago
parent
commit
7be4dbaa1f
  1. 12
      api/apiRoute.js
  2. 37
      pages/student/index/index.vue

12
api/apiRoute.js

@ -555,7 +555,7 @@ export default {
})
},
//学生端--
//学生端-获取作业列表
xy_assignment(data = {}) {
let url = '/xy/assignment'
return http.get(url, data).then(res => {
@ -563,6 +563,16 @@ export default {
})
},
//学生端-提交作业
xy_assignmentSubmitObj(data = {}) {
let url = '/xy/assignment/submitObj'
return http.get(url, data).then(res => {
return res;
})
},

37
pages/student/index/index.vue

@ -149,8 +149,8 @@
//上传接口地址
uploadApiUrl: ``,
uploadImageApiUrl: `${Api_url}/file/image`,
uploadVideoApiUrl: `${Api_url}/file/video`,
uploadImageApiUrl: `${Api_url}/memberUploadImage`,//图片上传接口
uploadVideoApiUrl: `${Api_url}/memberUploadVideo`,//视频上传接口
member_info: {},//学生信息
@ -386,15 +386,15 @@
// 上传作业
async submitJob(item) {
let type = item.content_type // 作业类型1图片2视频
let type = item.content_type // 作业类型1图片2视频3文本
try {
// 等待上传文件的返回结果
let uploadRes = await this.uploadFile(type)
// console.log('上传结果', uploadRes)
console.log('上传结果', uploadRes)
// 检查上传结果
if (!uploadRes.data.path) {
if (!uploadRes.data.url) {
return
}
@ -402,22 +402,28 @@
let data = {
id: item.id, // 作业列表id
student_file: uploadRes.data.path, // 附件
student_file_type: type, // 作业类型1图片2视频
student_content: '', // 内容
resources_id:this.member_info.id, // 学生资源id
content_text:uploadRes.data.url
}
// 提交作业
await this.assignmentsSubmit(data)
} catch (error) {
console.error('上传或提交作业失败:', error)
alert('上传或提交作业失败')
//alert('上传或提交作业失败')
//提示
uni.showToast({
title: '上传或提交作业失败',
icon: 'none'
})
}
},
// 上传单文件(视频/图片) type=作业类型1图片2视频
// 上传单文件(视频/图片) type=作业类型1图片2视频3文本
async uploadFile(type) {
return new Promise((resolve, reject) => {
if (type == 1) {
//图片作业
this.uploadApiUrl = this.uploadImageApiUrl
uni.chooseImage({
count: 1,
@ -437,7 +443,8 @@
reject(error)
}
})
} else {
} else if(type == 2){
//视频作业
this.uploadApiUrl = this.uploadVideoApiUrl
uni.chooseVideo({
count: 1,
@ -506,12 +513,11 @@
// 提交作业接口
async assignmentsSubmit(item) {
let data = {
id: item.id, // 作业列表id
student_file: item.student_file, // 附件
student_file_type: item.student_file_type, // 作业类型1图片2视频
student_content: item.student_content, // 内容
resources_id:item.resources_id, // 学生资源id
id:item.id,
content_text:item.content_text
}
let res = await memberApi.assignmentsSubmit(data)
let res = await apiRoute.xy_assignmentSubmitObj(data)
if (res.code != 1) {
uni.showToast({
title: res.msg,
@ -832,7 +838,6 @@
margin-top: 20rpx;
border-radius: 15rpx;
.video{
border: 1px solid red;
width: 100%;
border-radius: 15rpx;
}

Loading…
Cancel
Save