Commit cbbd1e6d authored by 徐俊's avatar 徐俊

xujun

parent 6c26da42
...@@ -59,6 +59,9 @@ export default { ...@@ -59,6 +59,9 @@ export default {
asyncUpload (params) { asyncUpload (params) {
return fetch(`/v1/science-admin/com-download/asyncUpload`, params, 'post', 'file') return fetch(`/v1/science-admin/com-download/asyncUpload`, params, 'post', 'file')
}, },
asyncApplyBookUpload (params) {
return fetch(`/v1/science-admin/com-download/asyncApplyBookUpload`, params, 'post', 'file')
},
deletefile (params) { deletefile (params) {
return fetch(`/v1/science-admin/com-download/delete/${params.id}`, params, 'delete', 'json') return fetch(`/v1/science-admin/com-download/delete/${params.id}`, params, 'delete', 'json')
}, },
......
<template> <template>
<div class="upload-container"> <div class="upload-container">
<el-button type="primary" @click="handleClick">选择文件</el-button> <a-button type="primary" @click="handleClick">选择文件</a-button>
<input type="file" ref="fileInput" multiple style="display: none" @change="handleFileChange" /> <input type="file" ref="fileInput" multiple style="display: none" @change="handleFileChange" />
<div class="file-list" v-if="fileList.length"> <div class="file-list" v-if="fileList.length">
<div v-for="(file, index) in fileList" :key="index" class="file-item"> <div v-for="(file, index) in fileList" :key="index" class="file-item">
<span>{{ file.name }}</span> <span>{{ file.name }}</span>
<span>{{ (file.size / 1024 / 1024).toFixed(2) }}MB</span> <span>{{ (file.size / 1024 / 1024).toFixed(2) }}MB</span>
<el-progress :percentage="file.progress || 0" />
</div> </div>
</div> </div>
</div> </div>
...@@ -48,35 +47,25 @@ export default { ...@@ -48,35 +47,25 @@ export default {
} }
} }
}, },
uploadFile (fileItem, index) {
return new Promise((resolve, reject) => { uploadFile (obj, index) {
const formData = new FormData() this.$api.base.asyncApplyBookUpload(this.uploadHandle(obj.file, obj.name)).then(({ data = {} }) => {
formData.append('file', fileItem.file) if (data) {
obj.fileName = files[0].name
// 这里替换成您的实际上传API obj.downloadUrl = data.downloadUrl
const xhr = new XMLHttpRequest() obj.downloadId = data.id
xhr.upload.onprogress = (event) => { } else
if (event.lengthComputable) { this.$message.error('上传失败')
this.$set(this.fileList[index], 'progress', }).catch(() => {
Math.round((event.loaded / event.total) * 100)) this.$message.error('上传失败')
}
}
xhr.onload = () => {
if (xhr.status === 200) {
resolve()
} else {
reject(new Error('上传失败'))
}
}
xhr.onerror = () => reject(new Error('上传失败'))
// 替换成实际的上传地址
xhr.open('POST', '/api/upload')
xhr.send(formData)
}) })
} },
uploadHandle (file, fileName) {
let formData = new FormData()
formData.append('file', file)
formData.append('fileName', fileName)
return formData
},
} }
} }
</script> </script>
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<a-form-item> <a-form-item>
<a-button type="primary" icon="search" @click="search">搜索</a-button> <a-button type="primary" icon="search" @click="search">搜索</a-button>
<a-button icon="reload" style="margin-left: 10px" @click="reset" class="bt-normal">重置</a-button> <a-button icon="reload" style="margin-left: 10px" @click="reset" class="bt-normal">重置</a-button>
<a-button type="primary" icon="upload" style="margin-left: 10px" @click="batchFileUpload">批量上传</a-button>
</a-form-item> </a-form-item>
</a-form> </a-form>
<a-divider style="height: 1px; background-color: #e8e8e8;" /> <a-divider style="height: 1px; background-color: #e8e8e8;" />
...@@ -207,6 +208,9 @@ export default { ...@@ -207,6 +208,9 @@ export default {
}).catch(() => { }).catch(() => {
this.loading = false this.loading = false
}) })
},
batchFileUpload() {
this.visibleFile = true
} }
}, },
watch: { watch: {
......
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