|
|
@@ -10,20 +10,31 @@
|
|
|
</template>
|
|
|
<template v-if="props.tableData.length > 0">
|
|
|
<el-table :data="props.tableData" stripe style="width: 100%" height="100%">
|
|
|
+ <el-table-column type="index"></el-table-column>
|
|
|
<el-table-column
|
|
|
v-for="column in props.columns"
|
|
|
+ :key="column.key"
|
|
|
:prop="column.dataIndex"
|
|
|
:label="column.title"
|
|
|
+ :width="column.width"
|
|
|
>
|
|
|
</el-table-column>
|
|
|
- <el-table-column label="详情">
|
|
|
+ <el-table-column label="详情" width="60">
|
|
|
<template #default="scope">
|
|
|
- <el-button color="#888" circle @click="openEditor(scope.row.descriptionFile, scope.row.assignmentName)"/>
|
|
|
+ <el-button color="#597d3b" circle @click="openEditor(scope.row.descriptionFile, scope.row.assignmentName)">
|
|
|
+ <el-icon :size="18">
|
|
|
+ <Search />
|
|
|
+ </el-icon>
|
|
|
+ </el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
- <el-table-column :label="role == 'teachers'? '编辑':'写作'">
|
|
|
+ <el-table-column :label="role == 'teachers'? '编辑':'写作'" width="60">
|
|
|
<template #default="scope">
|
|
|
- <el-button color="#888" circle @click="handleFunctionButton(scope.row.assignmentId)" :disabled="props.disabled || isDisabled(scope.row.teacherId)"/>
|
|
|
+ <el-button color="#597d3b" circle @click="handleFunctionButton(scope.row.assignmentId)" :disabled="props.disabled || isDisabled(scope.row.teacherId, scope.row.endDate)">
|
|
|
+ <el-icon :size="18">
|
|
|
+ <Edit />
|
|
|
+ </el-icon>
|
|
|
+ </el-button>
|
|
|
</template>
|
|
|
</el-table-column>
|
|
|
</el-table>
|
|
|
@@ -34,7 +45,7 @@
|
|
|
</el-card>
|
|
|
|
|
|
<el-dialog v-model="dialogConfig.visible" :title="dialogConfig.title">
|
|
|
- <el-form :model="newAssignmentInfo">
|
|
|
+ <el-form :model="newAssignmentInfo" label-width="auto">
|
|
|
<!-- <el-form-item label="课程图片">-->
|
|
|
<el-form-item label="作业名称">
|
|
|
<el-input v-model="newAssignmentInfo.assignmentName" placeholder="请输入名称"></el-input>
|
|
|
@@ -42,18 +53,83 @@
|
|
|
<el-form-item label="作业描述">
|
|
|
<el-input v-model="newAssignmentInfo.description" placeholder="请输入描述"></el-input>
|
|
|
</el-form-item>
|
|
|
- <el-form-item label="描述文件">
|
|
|
- <el-input v-model="newAssignmentInfo.descriptionFile" placeholder="请输入文件地址"></el-input>
|
|
|
- </el-form-item>
|
|
|
- <el-form-item label="课程图片">
|
|
|
- <el-input v-model="newAssignmentInfo.attachments[0]" placeholder="请输入图片链接"></el-input>
|
|
|
- </el-form-item>
|
|
|
<el-form-item label="开始时间">
|
|
|
<el-date-picker v-model="newAssignmentInfo.startTime" type="datetime" placeholder="截止时间" style="width: 180px"/>
|
|
|
</el-form-item>
|
|
|
<el-form-item label="截止时间">
|
|
|
<el-date-picker v-model="newAssignmentInfo.endTime" type="datetime" placeholder="截止时间" style="width: 180px"/>
|
|
|
</el-form-item>
|
|
|
+ <el-form-item label="描述文件" v-if="dialogConfig.type == 'edit'">
|
|
|
+ <el-upload
|
|
|
+ ref="uploadDescribeRef"
|
|
|
+ action= "http://127.0.0.1:8080/api/file"
|
|
|
+ multiple
|
|
|
+ v-model:file-list="describeFileList"
|
|
|
+ :limit="1"
|
|
|
+ :on-success="handleDescribeSuccess"
|
|
|
+ :on-error="handleDescribeError"
|
|
|
+ :on-exceed="handleDescribeExceed"
|
|
|
+ :on-change="handleDescribeChange"
|
|
|
+ accept=".doc, .docx"
|
|
|
+ :auto-upload="false"
|
|
|
+ >
|
|
|
+ <el-button type="primary">点击上传</el-button>
|
|
|
+ <template #tip>
|
|
|
+ <div class="el-upload__tip">
|
|
|
+ doc/docx 文件不大于 500kb
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+ <el-form-item label="附件" v-if="dialogConfig.type == 'edit'">
|
|
|
+ <el-upload
|
|
|
+ ref="uploadPictureRef"
|
|
|
+ action= "http://127.0.0.1:8080/api/file"
|
|
|
+ multiple
|
|
|
+ v-model:file-list="pictureFileList"
|
|
|
+ :limit="1"
|
|
|
+ :on-success="handlePictureSuccess"
|
|
|
+ :on-error="handlePictureError"
|
|
|
+ :on-exceed="handlePictureExceed"
|
|
|
+ :on-change="handlePictureChange"
|
|
|
+ accept=".doc, .docx"
|
|
|
+ :auto-upload="false"
|
|
|
+ >
|
|
|
+ <el-button type="primary">点击上传</el-button>
|
|
|
+ <template #tip>
|
|
|
+ <div class="el-upload__tip">
|
|
|
+ doc/docx 文件不大于 500kb
|
|
|
+ </div>
|
|
|
+ </template>
|
|
|
+ </el-upload>
|
|
|
+ </el-form-item>
|
|
|
+<!-- <el-form-item label="作业图片" v-if="dialogConfig.type == 'edit'">-->
|
|
|
+<!-- <el-upload-->
|
|
|
+<!-- ref="uploadPictureRef"-->
|
|
|
+<!-- drag-->
|
|
|
+<!-- action= "http://127.0.0.1:8080/api/file"-->
|
|
|
+<!-- multiple-->
|
|
|
+<!-- v-model:file-list="pictureFileList"-->
|
|
|
+<!-- :limit="1"-->
|
|
|
+<!-- :on-success="handlePictureSuccess"-->
|
|
|
+<!-- :on-error="handlePictureError"-->
|
|
|
+<!-- :on-exceed="handlePictureExceed"-->
|
|
|
+<!-- :on-change="handlePictureChange"-->
|
|
|
+<!-- list-type="picture-card"-->
|
|
|
+<!-- accept=".png, .jpg"-->
|
|
|
+<!-- :auto-upload="false"-->
|
|
|
+<!-- >-->
|
|
|
+<!-- <el-icon class="el-icon--upload"><upload-filled /></el-icon>-->
|
|
|
+<!-- <div class="el-upload__text">-->
|
|
|
+<!-- 拖拽上传或<em>点击此处上传</em>-->
|
|
|
+<!-- </div>-->
|
|
|
+<!-- <template #tip>-->
|
|
|
+<!-- <div class="el-upload__tip">-->
|
|
|
+<!-- jpg/png 文件不大于 500kb-->
|
|
|
+<!-- </div>-->
|
|
|
+<!-- </template>-->
|
|
|
+<!-- </el-upload>-->
|
|
|
+<!-- </el-form-item>-->
|
|
|
</el-form>
|
|
|
<template #footer>
|
|
|
<div class="dialog-footer">
|
|
|
@@ -72,11 +148,18 @@ import {defineProps, inject, onMounted, reactive, ref} from 'vue';
|
|
|
import router from "@/router";
|
|
|
import type {AssignmentDTO} from "@/types/dto";
|
|
|
import useApis from "@/apis";
|
|
|
- import {ElNotification} from "element-plus";
|
|
|
+ import {
|
|
|
+ ElMessage,
|
|
|
+ ElNotification,
|
|
|
+ type UploadFile,
|
|
|
+ type UploadFiles,
|
|
|
+ type UploadProps,
|
|
|
+ type UploadUserFile
|
|
|
+} from "element-plus";
|
|
|
import {useFormatDate} from "@/hooks/useFormatDate";
|
|
|
- import assignment from "@/apis/assignment";
|
|
|
-import ViewsWordEditor from "@/components/ViewsWordEditor/ViewsWordEditor.vue";
|
|
|
-import {useStore} from "@/store";
|
|
|
+ import ViewsWordEditor from "@/components/ViewsWordEditor/ViewsWordEditor.vue";
|
|
|
+ import {useStore} from "@/store";
|
|
|
+ import {Search, Edit, UploadFilled, Plus} from "@element-plus/icons-vue"
|
|
|
|
|
|
const props = defineProps<{
|
|
|
tableData: IAssignmentTableItem[],
|
|
|
@@ -91,6 +174,81 @@ import {useStore} from "@/store";
|
|
|
const store = useStore()
|
|
|
const doRefresh:Function = inject("reload")
|
|
|
const {formatDate} = useFormatDate()
|
|
|
+ let uploadDescribeRef = ref()
|
|
|
+ let uploadPictureRef = ref()
|
|
|
+
|
|
|
+ // 用于编辑课程展示预览图片
|
|
|
+ const describeFileList = ref<UploadUserFile[]>([])
|
|
|
+ const pictureFileList = ref<UploadUserFile[]>([])
|
|
|
+
|
|
|
+ const handleDescribeSuccess = (response: any, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
|
|
|
+ Object.assign(newAssignmentInfo, {
|
|
|
+ assignmentName: newAssignmentInfo.assignmentName,
|
|
|
+ description: newAssignmentInfo.description,
|
|
|
+ descriptionFile: response.data,
|
|
|
+ attachments: newAssignmentInfo.attachments == null? ['']:newAssignmentInfo.attachments,
|
|
|
+ startTime: newAssignmentInfo.startTime,
|
|
|
+ endTime: newAssignmentInfo.endTime
|
|
|
+ })
|
|
|
+ }
|
|
|
+ const handlePictureSuccess = (response: any, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
|
|
|
+ newAssignmentInfo.attachments[0] = response.data
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleDescribeError: UploadProps['onError'] = (error: Error, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
|
|
|
+ console.log(error, uploadFile, uploadFiles)
|
|
|
+ }
|
|
|
+ const handlePictureError: UploadProps['onError'] = (error: Error, uploadFile: UploadFile, uploadFiles: UploadFiles) => {
|
|
|
+ console.log(error, uploadFile, uploadFiles)
|
|
|
+ }
|
|
|
+
|
|
|
+ const handleDescribeExceed = (files, fileList) => {
|
|
|
+ // console.log(files)
|
|
|
+ uploadDescribeRef.value.clearFiles() //清空上传文件(限制一个,所以直接清空即可)
|
|
|
+ const file = files[0]
|
|
|
+ uploadDescribeRef.value.handleStart(file) //重新上传
|
|
|
+ }
|
|
|
+ const handlePictureExceed = (files, fileList) => {
|
|
|
+ // console.log(files)
|
|
|
+ uploadPictureRef.value.clearFiles() //清空上传文件(限制一个,所以直接清空即可)
|
|
|
+ const file = files[0]
|
|
|
+ uploadPictureRef.value.handleStart(file) //重新上传
|
|
|
+ }
|
|
|
+
|
|
|
+ //选择文件
|
|
|
+ const handleDescribeChange = (file,fileList) => {
|
|
|
+ // console.log(file)
|
|
|
+ const fileImgType = file.name.match(/\.([^\.]+)$/)[1]; //匹配文件格式(最后一个'.'后的格式)或者匹配file.raw.type
|
|
|
+ const isImageType = ['doc','docx'];
|
|
|
+ const isLt500KB = file.size / 1024 < 500; //判断图片格式与大小
|
|
|
+ if (isImageType.indexOf(fileImgType)==-1) {
|
|
|
+ ElMessage.error('文件仅支持png、jpg格式') //限制文件类型
|
|
|
+ uploadDescribeRef.value.clearFiles() //清空上传文件
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!isLt500KB) {
|
|
|
+ ElMessage.error('文件不能超过500kb!') //限制文件大小
|
|
|
+ uploadDescribeRef.value.clearFiles() //清空上传文件
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ const handlePictureChange = (file,fileList) => {
|
|
|
+ // console.log(file)
|
|
|
+ const fileImgType = file.name.match(/\.([^\.]+)$/)[1]; //匹配文件格式(最后一个'.'后的格式)或者匹配file.raw.type
|
|
|
+ // const isImageType = ['png','jpg'];
|
|
|
+ const isImageType = ['doc','docx'];
|
|
|
+ const isLt500KB = file.size / 1024 < 500; //判断图片格式与大小
|
|
|
+ if (isImageType.indexOf(fileImgType)==-1) {
|
|
|
+ ElMessage.error('文件仅支持png、jpg格式') //限制文件类型
|
|
|
+ uploadDescribeRef.value.clearFiles() //清空上传文件
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ if (!isLt500KB) {
|
|
|
+ ElMessage.error('文件不能超过500kb!') //限制文件大小
|
|
|
+ uploadDescribeRef.value.clearFiles() //清空上传文件
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
const dialogConfig = reactive({
|
|
|
type: "",
|
|
|
@@ -183,6 +341,7 @@ const openEditor = (url: string, title: string) => {
|
|
|
startTime: assignment.startTime,
|
|
|
endTime: assignment.endTime
|
|
|
})
|
|
|
+ // console.log("获取作业信息", newAssignmentInfo)
|
|
|
}
|
|
|
|
|
|
// 用于记录当前编辑的作业的id
|
|
|
@@ -194,6 +353,7 @@ const openEditor = (url: string, title: string) => {
|
|
|
apis.getAssignmentById(assignmentId)
|
|
|
.then((res:any) => {
|
|
|
setNewAssignmentInfo(res.data.data)
|
|
|
+ // console.log("功能按钮方法内部",newAssignmentInfo)
|
|
|
IAssignmentId.value = res.data.data.assignmentId
|
|
|
})
|
|
|
changeDialog('edit')
|
|
|
@@ -201,17 +361,22 @@ const openEditor = (url: string, title: string) => {
|
|
|
}
|
|
|
|
|
|
const handleWriting = (assignmentId:number) => {
|
|
|
- router.push(`/home/assignment/${assignmentId}/edit`);
|
|
|
+ router.push(`/home/homeworkDetail/${assignmentId}`);
|
|
|
// Location.reload()
|
|
|
}
|
|
|
|
|
|
|
|
|
- const handleSubmit = () => {
|
|
|
+ const handleSubmit = async () => {
|
|
|
+ // console.log("提交方法最开始",newAssignmentInfo)
|
|
|
newAssignmentInfo.endTime = formatDate(newAssignmentInfo.endTime);
|
|
|
newAssignmentInfo.startTime = formatDate(newAssignmentInfo.startTime);
|
|
|
+ await uploadDescribeRef.value.submit()
|
|
|
+ await uploadPictureRef.value.submit()
|
|
|
+ // console.log("提交方法,请求前",newAssignmentInfo)
|
|
|
if(dialogConfig.type === 'add'){
|
|
|
apis.createAssignment(props.courseId, newAssignmentInfo)
|
|
|
.then((res) => {
|
|
|
+ console.log("新增作业请求内部",newAssignmentInfo)
|
|
|
if(res.data.code===200) {
|
|
|
ElNotification({
|
|
|
title: '新增成功',
|
|
|
@@ -224,20 +389,24 @@ const openEditor = (url: string, title: string) => {
|
|
|
})
|
|
|
}
|
|
|
dialogConfig.visible = false
|
|
|
- cleanNewAssignmentInfo()
|
|
|
-
|
|
|
+ // cleanNewAssignmentInfo()
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
console.log(err)
|
|
|
})
|
|
|
} else if(dialogConfig.type === 'edit'){
|
|
|
+ // console.log("编辑作业请求前一刻",newAssignmentInfo)
|
|
|
apis.updateAssignment(IAssignmentId.value, newAssignmentInfo)
|
|
|
.then((res:any) => {
|
|
|
+ // console.log("编辑作业请求内部",newAssignmentInfo)
|
|
|
if(res.data.code===200) {
|
|
|
ElNotification({
|
|
|
title: '修改成功',
|
|
|
type: 'success',
|
|
|
})
|
|
|
+ // console.log("编辑作业请求内部22",newAssignmentInfo)
|
|
|
+ setTimeout(() => apis.updateAssignment(IAssignmentId.value, newAssignmentInfo), 300)
|
|
|
+ // console.log("编辑作业请求内部33",newAssignmentInfo)
|
|
|
}else {
|
|
|
ElNotification({
|
|
|
title: '修改失败',
|
|
|
@@ -245,7 +414,7 @@ const openEditor = (url: string, title: string) => {
|
|
|
})
|
|
|
}
|
|
|
dialogConfig.visible = false
|
|
|
- cleanNewAssignmentInfo()
|
|
|
+ // cleanNewAssignmentInfo()
|
|
|
})
|
|
|
.catch((err) => {
|
|
|
console.log(err)
|
|
|
@@ -254,8 +423,15 @@ const openEditor = (url: string, title: string) => {
|
|
|
doRefresh();
|
|
|
}
|
|
|
|
|
|
- const isDisabled = (teacherId:string) => {
|
|
|
- return props.role == 'teachers' && +teacherId != store.user.id;
|
|
|
+ const isDisabled = (teacherId: string, endDate: string) => {
|
|
|
+ if(props.role == 'teachers'){// 是教师且不是作业发布人则禁用
|
|
|
+ if(+teacherId != store.user.id){
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ } else { // 是学生且超时则禁用
|
|
|
+ if(new Date() > new Date(endDate)) return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
@@ -268,3 +444,13 @@ export default {
|
|
|
name: "CourseHomeworkTable"
|
|
|
}
|
|
|
</script>
|
|
|
+
|
|
|
+<style scoped>
|
|
|
+ .el-icon.avatar-uploader-icon {
|
|
|
+ font-size: 28px;
|
|
|
+ color: #8c939d;
|
|
|
+ width: 178px;
|
|
|
+ height: 178px;
|
|
|
+ text-align: center;
|
|
|
+ }
|
|
|
+</style>
|