You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

140 lines
5.8 KiB

import Setting from '@/setting'
import util from '@/libs/util'
export default {
data() {
return {
maxSize: Setting.upload.maxSize
}
},
mounted() {
this.insertScript()
},
methods: {
initMedia(item){
if(item.videoAudio && !item.player){
this.$get(`${this.api.getPlayAuth}/${item.videoAudio}`).then(res => {
let playAuth = res.data.playAuth
this.$nextTick(() => {
item.player = new Aliplayer({
id: item.mediaEleId,
width: '100%',
autoplay: false,
vid : item.videoAudio,
playauth : playAuth,
encryptType:1, //当播放私有加密流时需要设置。
})
})
}).catch(res => {})
}
},
updateProgress(item,isFillBlank){
let subjects = this.subjects
let singleAnswered = []
let multipleAnswered = []
let judgeAnswered = []
let fillBlankAnswered = []
let briefAnswerAnswered = []
if(isFillBlank){
let index = item.getAttribute('data-index')
if([...item.parentElement.querySelectorAll('input')].some(n => n.value)){
subjects[3][index].hadAnswer = 1
}else{
subjects[3][index].hadAnswer = 0
}
this.fillBlankAnsweredCount = subjects[3].filter(n => n.hadAnswer).length
subjects[3].map((n,i) => {
n.hadAnswer && fillBlankAnswered.push(i)
})
this.fillBlankAnswered = fillBlankAnswered
}else{
this.singleAnsweredCount = subjects[0].filter(n => n.val).length
this.multipleAnsweredCount = subjects[1].filter(n => n.val.length).length
this.judgeAnsweredCount = subjects[2].filter(n => n.val).length
this.briefAnswerAnsweredCount = subjects[4].filter(n => n.val).length
subjects[0].map((n,i) => {
n.val && singleAnswered.push(i)
})
subjects[1].map((n,i) => {
n.val.length && multipleAnswered.push(i)
})
subjects[2].map((n,i) => {
n.val && judgeAnswered.push(i)
})
subjects[4].map((n,i) => {
n.val && briefAnswerAnswered.push(i)
})
this.singleAnswered = singleAnswered
this.multipleAnswered = multipleAnswered
this.judgeAnswered = judgeAnswered
this.briefAnswerAnswered = briefAnswerAnswered
}
let answered = this.singleAnsweredCount + this.multipleAnsweredCount + this.judgeAnsweredCount + this.fillBlankAnsweredCount + this.briefAnswerAnsweredCount
this.progress = this.totalLen ? Math.floor((answered / this.totalLen * 100)) : 0
},
insertScript(){
const linkTag = document.createElement('link')
linkTag.id = 'aliplayerLink'
linkTag.rel = 'stylesheet'
linkTag.href = 'https://g.alicdn.com/de/prismplayer/2.8.2/skins/default/aliplayer-min.css'
document.body.appendChild(linkTag)
const scriptTag = document.createElement('script')
scriptTag.id = 'aliplayerScript'
scriptTag.type = 'text/javascript'
scriptTag.src = 'https://g.alicdn.com/de/prismplayer/2.8.2/aliplayer-min.js'
document.body.appendChild(scriptTag)
this.$once('hook:beforeDestroy', function () {
document.body.removeChild(document.querySelector('#aliplayerLink'))
document.body.removeChild(document.querySelector('#aliplayerScript'))
})
},
handleExceed(files, fileList) {
util.warningMsg(`当前限制选择 1 个文件,如需更换,请删除上一个文件再重新选择!` )
},
beforeUpload(file,item){
let ext = util.getFileExt(file.name)
if(util.isDoc(ext) && (file.size / 1024 / 1024) > this.maxSize){
util.errorMsg(`请上传${this.maxSize}M以内的文件`)
return false
}
item.uploading = true
},
uploadSuccess(res, file, fileList, item) {
let ext = file.response.data.filesResult.fileType
if(util.isVideo(ext)){
item.video[file.name] = res.data.filesResult.fileId
}else{
item.fileUrl[file.name] = res.data.filesResult.fileUrl
}
item.uploading = false
},
uploadError(err, file, fileList) {
this.$message({
message: "上传出错,请重试!",
type: "error",
center: true
})
item.uploading = false
},
beforeRemove(file, fileList) {
return this.$confirm(`确定移除 ${file.name}`)
},
handleRemove(file, fileList, item) {
if(util.isVideo(util.getFileExt(file.name))){
this.$del(`${this.api.removeVideo}/${item.video[file.name]}`).then(res => {
delete item.video[file.name]
}).catch(res => {})
}else{
let fileName = item.fileUrl[file.name].replace('https://cj-oss.oss-cn-guangzhou.aliyuncs.com/','')
this.$del(`${this.api.fileDeletion}?keys=${fileName}`).then(res => {
delete item.fileUrl[file.name]
}).catch(res => {})
}
},
}
}