|
|
@@ -1,20 +1,25 @@
|
|
|
<template>
|
|
|
<div class="tab">
|
|
|
- <h1 class="title">新建幻灯片</h1>
|
|
|
+ <h1 class="title">上传文件</h1>
|
|
|
+ <div class="type-bar mb-24">
|
|
|
+ <c-button block :right="6" @click="isSlide = true" :theme="isSlide ? 'blue' : 'normal'">课件</c-button>
|
|
|
+ <c-button block :left="6" @click="isSlide = false" :theme="isSlide ? 'normal' : 'green'">附件</c-button>
|
|
|
+ </div>
|
|
|
<div class="sub-title">所属课程:</div>
|
|
|
<c-select v-model="selectedCourseId" class="mb-16"
|
|
|
:list="this.courses.map(course => ({value: course.id, display: course.name}))"></c-select>
|
|
|
- <div class="sub-title">课件名称:</div>
|
|
|
- <c-input class="mb-16"
|
|
|
- v-model="slideName"
|
|
|
- placeholder="请勿与同课程课件重名"
|
|
|
+ <div class="sub-title" v-if="isSlide">{{isSlide ? '课件' : '附件'}}名称:</div>
|
|
|
+ <c-input class="mb-16" v-if="isSlide"
|
|
|
+ v-model="slideName"
|
|
|
+ placeholder="请勿与同课程下文件重名"
|
|
|
/>
|
|
|
- <div class="sub-title">课件文件
|
|
|
- <c-tag theme="green">目前支持 PDF 格式</c-tag>
|
|
|
+ <div class="sub-title">{{isSlide ? '课件' : '附件'}}文件
|
|
|
+ <c-tag :theme="isSlide ? 'blue' : 'green'">{{isSlide ? '课件文件目前支持 PDF 格式' : '附件将直接提供链接供下载'}}</c-tag>
|
|
|
</div>
|
|
|
- <file-uploader accept="application/pdf" class="mb-16" @change="handleFileChanged"/>
|
|
|
- <c-button theme="blue" block :no-click-warn="!formChecked()" @click="handleSubmit">
|
|
|
- 添加
|
|
|
+ <file-uploader :accept="isSlide ? 'application/pdf' : null" class="mb-16" @change="handleFileChanged"/>
|
|
|
+ <c-button standout :theme="isSlide ? 'blue' : 'green'" block :no-click-warn="!formChecked()" @click="handleSubmit"
|
|
|
+ icon="add">
|
|
|
+ 确认上传{{isSlide ? '课件' : '附件'}}
|
|
|
</c-button>
|
|
|
</div>
|
|
|
</template>
|
|
|
@@ -27,6 +32,7 @@ import { teacherGetCourses } from '@/server/course'
|
|
|
import { createSlide } from '@/server/slide'
|
|
|
import CTag from '@/components/Basic/CTag'
|
|
|
import CSelect from '@/components/Basic/CSelect'
|
|
|
+import { uploadCourseFile } from '@/server/course-file'
|
|
|
|
|
|
export default {
|
|
|
components: { CSelect, CTag, FileUploader, CButton, CInput },
|
|
|
@@ -36,7 +42,8 @@ export default {
|
|
|
selectedCourseId: '',
|
|
|
slideName: '',
|
|
|
file: null,
|
|
|
- message: ''
|
|
|
+ message: '',
|
|
|
+ isSlide: true
|
|
|
}
|
|
|
},
|
|
|
mounted () {
|
|
|
@@ -52,12 +59,12 @@ export default {
|
|
|
this.message = '请选择所属课程'
|
|
|
return false
|
|
|
}
|
|
|
- if (!this.slideName) {
|
|
|
+ if (this.isSlide && !this.slideName) {
|
|
|
this.message = '请输入课件的名称'
|
|
|
return false
|
|
|
}
|
|
|
if (!this.file) {
|
|
|
- this.message = '请上传课件文件'
|
|
|
+ this.message = '请选择文件上传'
|
|
|
return false
|
|
|
}
|
|
|
return true
|
|
|
@@ -68,18 +75,30 @@ export default {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- this.$setInfoMessage('上传课件可能比较耗时,请稍等片刻')
|
|
|
+ this.$setInfoMessage('上传文件可能比较耗时,请稍等片刻')
|
|
|
const interval = setInterval(() => {
|
|
|
- this.$setInfoMessage('上传课件可能比较耗时,请稍等片刻')
|
|
|
+ this.$setInfoMessage('上传文件可能比较耗时,请稍等片刻')
|
|
|
}, 500)
|
|
|
- createSlide({ courseId: this.selectedCourseId, name: this.slideName, file: this.file }).then(res => {
|
|
|
- clearInterval(interval)
|
|
|
- this.$setSuccessMessage('创建课件成功!')
|
|
|
- this.$router.push({ name: 'teacher-explore' })
|
|
|
- }).catch(err => {
|
|
|
- clearInterval(interval)
|
|
|
- this.$setErrorMessage(err.response.data.msg)
|
|
|
- })
|
|
|
+
|
|
|
+ if (this.isSlide) {
|
|
|
+ createSlide({ courseId: this.selectedCourseId, name: this.slideName, file: this.file }).then(res => {
|
|
|
+ clearInterval(interval)
|
|
|
+ this.$setSuccessMessage('上传课件成功!')
|
|
|
+ this.$router.push({ name: 'teacher-explore' })
|
|
|
+ }).catch(err => {
|
|
|
+ clearInterval(interval)
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uploadCourseFile({ courseId: this.selectedCourseId, file: this.file }).then(res => {
|
|
|
+ clearInterval(interval)
|
|
|
+ this.$setSuccessMessage('上传附件成功!')
|
|
|
+ this.$router.push({ name: 'teacher-explore' })
|
|
|
+ }).catch(err => {
|
|
|
+ clearInterval(interval)
|
|
|
+ this.$setErrorMessage(err.response.data.msg)
|
|
|
+ })
|
|
|
+ }
|
|
|
},
|
|
|
handleFileChanged (file) {
|
|
|
this.file = file || null
|
|
|
@@ -89,4 +108,8 @@ export default {
|
|
|
</script>
|
|
|
<style lang="scss" scoped>
|
|
|
@import "~@/views/shared/tab-common";
|
|
|
+
|
|
|
+.type-bar {
|
|
|
+ display: flex;
|
|
|
+}
|
|
|
</style>
|