Commit cfc5e138 authored by FangYuePeng's avatar FangYuePeng

修复课程资料下载报错,下载开课模板

parent 652550c1
......@@ -83,3 +83,13 @@ export function batchAddTeaTrialCourse(data) {
}
})
}
// 8.下载导入模板
export function importTemplateTrialCourse(params) {
return request({
url: '/teatrialcourse/importTemplate',
method: 'get',
responseType: 'blob',
params
})
}
......@@ -101,6 +101,15 @@
@click="handleAdd"
>{{ commonField.addName }}</el-button>
</el-form-item>
<!-- //导入按钮-->
<el-button
:class="commonField.importClass"
:type="commonField.typeWarning"
:icon="commonField.importIcon"
:size="commonField.smallSize"
@click="handleImport"
>{{ commonField.importName }}</el-button>
</div>
</el-form>
</div>
......@@ -568,7 +577,39 @@
<el-button class="submitBtn" type="primary" @click="submitForm">确 定</el-button>
</div>
</el-dialog>
<!-- 单位导入对话框 -->
<el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
<el-upload
accept=".xlsx, .xls"
:headers="upload.headers"
:action="upload.url + '?updateSupport=' + upload.updateSupport"
:disabled="upload.isUploading"
:on-progress="handleFileUploadProgress"
:on-success="handleFileSuccess"
:auto-upload="false"
:on-change="employeeUpload"
:on-remove="handleRemove"
:before-remove="beforeRemove"
:on-preview="handlePreview"
:file-list="fileList"
drag
>
<i class="el-icon-upload" />
<div class="el-upload__text">
将文件拖到此处,或
<em>点击上传</em>
</div>
<div slot="tip" class="el-upload__tip">
<el-checkbox v-model="upload.updateSupport" />是否更新已经存在的数据
<el-link type="info" style="font-size:12px" @click="importTemplate">下载模板</el-link>
</div>
<div slot="tip" class="el-upload__tip" style="color:red">提示:仅允许导入“xls”或“xlsx”格式文件!</div>
</el-upload>
<div slot="footer" class="dialog-footer">
<el-button class="cancelBtn" @click="upload.open = false">取 消</el-button>
<el-button class="submitBtn" :loading="importLoading" type="primary" @click="submitFileForm">确 定</el-button>
</div>
</el-dialog>
</div>
</template>
......@@ -583,17 +624,37 @@ import {
import { listCourseAll, listUnitAll } from '@/api/sysUnit'
import {
batchAddTeaTrialCourse,
delTeaTrialCourse, listALLTeaTrialCourse,
delTeaTrialCourse, importTemplateTrialCourse, listALLTeaTrialCourse,
listTeaTrialCourse,
updateTeaTrialCourse
} from '@/api/try/teaTrialCourse'
import dict from '@/views/system/dict/index.vue'
import { getDict } from '@/api/system/dict/data'
import { importExcel, importTemplate, uploadFalseFile } from '@/api/system/user'
import { getToken } from '@/utils/auth'
export default {
name: 'Role',
dicts: ['tec_classify', 'job_classify'],
data() {
return {
// 导入列表
fileList: [],
// 开课导入参数
upload: {
// 是否显示弹出层(开课导入)
open: false,
// 弹出层标题(开课导入)
title: '',
// 是否禁用上传
isUploading: false,
// 是否更新已经存在的用户数据
updateSupport: 0,
// 设置上传的请求头部
headers: { Authorization: 'Bearer ' + getToken() },
// 上传的地址
url: process.env.VUE_APP_BASE_API + '/system/user/importExcel'
},
// 修改页面默认打开的树壮菜单
updateMenu: [],
unitDisplay: false,
......@@ -1079,6 +1140,106 @@ export default {
})
}).catch(function() {
})
},
/** 导入按钮操作 */
handleImport() {
this.upload.title = '用户导入'
this.upload.open = true
},
/** 下载模板操作 */
importTemplate() {
importTemplateTrialCourse().then(response => {
const blob = new Blob([response])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)// 创建下载的链接
downloadElement.href = href
downloadElement.download = '开课模板' + '.xls' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click()// 点击下载
document.body.removeChild(downloadElement)// 下载完成移除元素
window.URL.revokeObjectURL(href)// 释放掉blob对象
// this.download(response.msg);
})
},
// 文件上传中处理
handleFileUploadProgress(event, file, fileList) {
this.upload.isUploading = true
},
// 文件上传成功处理
handleFileSuccess(response, file, fileList) {
this.upload.open = false
this.upload.isUploading = false
this.$refs.upload.clearFiles()
this.$alert(response.msg, '导入结果', { dangerouslyUseHTMLString: true })
this.getList()
},
// 提交上传文件
submitFileForm() {
// this.$refs.upload.submit()
this.importLoading = true
if (this.fileList.length === 0) {
this.$message.warning('请上传文件')
// 导入成功后关闭弹出框
this.importLoading = false
this.upload.open = true
} else { // 根据后台需求数据格式
var formData = new FormData() // 当前为空
formData.append('file', this.fileList)
importExcel(formData).then(res => {
if (res.code === 200) {
if (res.data.filename === null) {
this.$message.success('导入成功')
this.fileList = []
// 导入成功后关闭弹出框
this.importLoading = false
this.upload.open = false
// 导入成功后刷新页面
this.getList()
} else {
uploadFalseFile({ fileName: res.data.filename }).then(res => {
const blob = new Blob([res])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob) // 创建下载的链接
downloadElement.href = href
downloadElement.download = '模板错误提示' + '.txt' // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click() // 点击下载
document.body.removeChild(downloadElement) // 下载完成移除元素
window.URL.revokeObjectURL(href) // 释放掉blob对象
this.importLoading = false
})
}
this.importLoading = false
} else if (res.code === 41020) {
this.$message.info('上传超时,请重新上传')
this.importLoading = false
} else {
this.$message.error(res.message)
this.importLoading = false
}
}).catch(err => {
this.$message.success(err.message)
this.importLoading = false
})
}
},
/** 导入change*/
employeeUpload(file, fileList) {
if (fileList.length > 1) {
fileList.splice(0, 1)
}
this.fileList = fileList[0].raw
},
/** 导入remove操作*/
handleRemove(file, fileList) {
this.fileList = []
},
/** 导入beforeRemove操作*/
beforeRemove(file, fileList) {
this.fileList = []
},
/* 上传文件所需求 */
handlePreview(file) {
}
}
......
......@@ -460,7 +460,7 @@
:http-request="uploadCustom"
:on-remove="removeCover"
drag
multiple
>
<i class="el-icon-upload" />
<div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
......@@ -541,11 +541,12 @@ import {
blessonAdd,
blessonRemove,
excelImport,
defaultUrl, picImport, updateCourseStatus, uploadVideo, uploadZip, findZIpInfo, delZip, downloadZip
defaultUrl, picImport, updateCourseStatus, uploadZip, findZIpInfo, delZip, downloadZip
} from '@/api/courseManagement/indexApi'
import commonField from '@/utils/commonField'
import { getDict } from '@/api/system/dict/data'
import { listAllCmsLecturer } from '@/api/courseManagement/cmsLecturer'
export default {
name: 'Index',
components: {
......@@ -715,8 +716,8 @@ export default {
homeDisplay: '',
flag: '',
schoolQualityLesson: '',
entQualityLesson: '',
lessonTeaName: ''
entQualityLesson: ''
},
coursePlanOptions: [],
// pagination
......@@ -848,8 +849,7 @@ export default {
lessonTeaName: '',
lessonPrice: '',
homeDisplay: '',
flag: '',
lessonTeaName: ''
flag: ''
}
this.loadData()
},
......@@ -1583,20 +1583,34 @@ export default {
},
downloadFile(data) {
console.log('data', data)
const _this = this
const originalName = data.originalName
const params = {
businessId: data.businessId
}
downloadZip(params).then(res => {
if (res.code === 200) {
// _this.success(res)
window.open(res.data)
} else {
_this.warning(res)
}
}).catch((err) => {
_this.error(err)
downloadZip(params).then(response => {
const blob = new Blob([response])
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob)// 创建下载的链接
downloadElement.href = href
downloadElement.download = originalName // 下载后文件名
document.body.appendChild(downloadElement)
downloadElement.click()// 点击下载
document.body.removeChild(downloadElement)// 下载完成移除元素
window.URL.revokeObjectURL(href)// 释放掉blob对象
// this.download(response.msg);
})
// downloadZip(params)
// .then(res => {
// if (res.code === 200) {
// // _this.success(res)
// window.open(res.data)
// } else {
// _this.warning(res)
// }
// }).catch((err) => {
// _this.error(err)
// })
},
// 上传资源
handleChange(file, fileList) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment