|
@@ -1,187 +1,219 @@
|
|
|
<template>
|
|
|
- <div class="base-upload-container">
|
|
|
- <Upload multiple type="drag" action="" :disabled="isLoading" :before-upload="onBeforeUpload" :show-upload-list="false">
|
|
|
- <div style="padding: 40px 0">
|
|
|
- <Icon type="ios-cloud-upload" size="100"
|
|
|
- style="color: #40A8F0;margin: 40px 0;"></Icon>
|
|
|
- <p style="color: #757575">{{ $t("knowledge.import.tip1") }}</p>
|
|
|
- <p style="color: #ddd" v-if="acceptTypes.length">({{ $t("knowledge.import.tip2") }}:{{ acceptTypes.join(' / ') }})</p>
|
|
|
- </div>
|
|
|
- </Upload>
|
|
|
- <div class="file-list-box" v-if="!simpleUpload">
|
|
|
- <div class="file-item" v-for="(item,index) in fileArr" :key="index">
|
|
|
- <p>
|
|
|
- <span>{{ item.name }}</span>
|
|
|
- <span class="tool-remove" v-if="isShowTool">
|
|
|
- <Icon type="md-close" @click="onRemoveFile(index)"/>
|
|
|
- </span>
|
|
|
- </p>
|
|
|
- <Progress :percent="progressArr[index]" :stroke-width="12"/>
|
|
|
- </div>
|
|
|
- </div>
|
|
|
- <Button @click="onConfirmUpload" :loading="isLoading" v-if="!simpleUpload" style="width: 100%;margin: 0 auto;" class="modal-btn" :disabled="!fileArr.length">{{ $t("knowledge.import.tip3") }}</Button>
|
|
|
- </div>
|
|
|
+ <div class="base-upload-container">
|
|
|
+ <Upload multiple type="drag" action="" :disabled="isLoading" :before-upload="onBeforeUpload" :show-upload-list="false">
|
|
|
+ <div style="padding: 40px 0">
|
|
|
+ <Icon type="ios-cloud-upload" size="100" style="color: #40A8F0;margin: 40px 0;"></Icon>
|
|
|
+ <p style="color: #757575">{{ $t("knowledge.import.tip1") }}</p>
|
|
|
+ <p style="color: #ddd" v-if="acceptTypes.length">({{ $t("knowledge.import.tip2") }}:{{ acceptTypes.join(' / ') }})</p>
|
|
|
+ </div>
|
|
|
+ </Upload>
|
|
|
+ <div class="file-list-box" v-if="!simpleUpload">
|
|
|
+ <div class="file-item" v-for="(item,index) in fileArr" :key="index">
|
|
|
+ <p>
|
|
|
+ <span>{{ item.name }}</span>
|
|
|
+ <span class="tool-remove" v-if="isShowTool">
|
|
|
+ <Icon type="md-close" @click="onRemoveFile(index)" />
|
|
|
+ </span>
|
|
|
+ </p>
|
|
|
+ <Progress :percent="progressArr[index]" :stroke-width="12" />
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ <Button @click="onConfirmUpload" :loading="isLoading" v-if="!simpleUpload" style="width: 100%;margin: 0 auto;" class="modal-btn" :disabled="!fileArr.length">{{ $t("knowledge.import.tip3") }}</Button>
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
- import BlobTool from '@/utils/blobTool.js'
|
|
|
- export default {
|
|
|
- props: {
|
|
|
- auth: {
|
|
|
- type: Object,
|
|
|
- default: () => {
|
|
|
- return {
|
|
|
- sas: '',
|
|
|
- url: '',
|
|
|
- name: ''
|
|
|
- }
|
|
|
- }
|
|
|
- },
|
|
|
- scope: {
|
|
|
- type: String,
|
|
|
- default: 'school'
|
|
|
- },
|
|
|
- prefix: {
|
|
|
- type: String,
|
|
|
- default: ''
|
|
|
- },
|
|
|
- simpleUpload:{
|
|
|
- type:Boolean,
|
|
|
- default:false
|
|
|
- },
|
|
|
- acceptTypes:{
|
|
|
- type:Array,
|
|
|
- default:() => []
|
|
|
- }
|
|
|
- },
|
|
|
- data() {
|
|
|
- return {
|
|
|
- isLoading:false,
|
|
|
- isShowTool:true,
|
|
|
- containerClient: null,
|
|
|
- fileArr:[],
|
|
|
- progressArr:[]
|
|
|
- }
|
|
|
- },
|
|
|
- created() {
|
|
|
+import axios from 'axios'
|
|
|
+import BlobTool from '@/utils/blobTool.js'
|
|
|
+export default {
|
|
|
+ props: {
|
|
|
+ auth: {
|
|
|
+ type: Object,
|
|
|
+ default: () => {
|
|
|
+ return {
|
|
|
+ sas: '',
|
|
|
+ url: '',
|
|
|
+ name: ''
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
+ scope: {
|
|
|
+ type: String,
|
|
|
+ default: 'school'
|
|
|
+ },
|
|
|
+ prefix: {
|
|
|
+ type: String,
|
|
|
+ default: ''
|
|
|
+ },
|
|
|
+ simpleUpload: {
|
|
|
+ type: Boolean,
|
|
|
+ default: false
|
|
|
+ },
|
|
|
+ acceptTypes: {
|
|
|
+ type: Array,
|
|
|
+ default: () => []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ data() {
|
|
|
+ return {
|
|
|
+ isLoading: false,
|
|
|
+ isShowTool: true,
|
|
|
+ containerClient: null,
|
|
|
+ fileArr: [],
|
|
|
+ progressArr: []
|
|
|
+ }
|
|
|
+ },
|
|
|
+ created() {
|
|
|
|
|
|
- },
|
|
|
- methods: {
|
|
|
- async onBeforeUpload(file) {
|
|
|
- let nameType = file.name.split('.')[file.name.split('.').length - 1]
|
|
|
- if(this.$GLOBAL.NotSupport.includes(nameType.toUpperCase())){
|
|
|
- this.$Message.warning(this.$t('learnActivity.notSupportType')); // 黑名单文件格式不能上传
|
|
|
- return false
|
|
|
- }
|
|
|
- if(this.simpleUpload){
|
|
|
- this.$emit('uploadFinish',file)
|
|
|
- return
|
|
|
- }
|
|
|
- file.progress = 0
|
|
|
- this.fileArr.push(file)
|
|
|
- this.progressArr.push(0)
|
|
|
- return false
|
|
|
-
|
|
|
- },
|
|
|
-
|
|
|
- onRemoveFile(index){
|
|
|
- this.fileArr.splice(index,1)
|
|
|
- },
|
|
|
-
|
|
|
- async onConfirmUpload(){
|
|
|
- this.isShowTool = false
|
|
|
- let result = []
|
|
|
- let containerClient = this.containerClient
|
|
|
- let list = this.fileArr
|
|
|
- let that = this
|
|
|
- let promiseArr = []
|
|
|
- that.isLoading = true
|
|
|
- for(let i = 0 ; i < list.length; i++){
|
|
|
- let file = list[i]
|
|
|
- promiseArr.push(new Promise(async (r,j) => {
|
|
|
- try{
|
|
|
- let blobFile = await containerClient.upload(file, { path:this.prefix },{
|
|
|
- onProgress: function (e) {
|
|
|
- that.$set(that.progressArr,i,parseInt(e.loadedBytes * 100 / file.size))
|
|
|
- }
|
|
|
- });
|
|
|
- // 如果上传的是视频文件 则需要获取视频的时长信息和MD5信息
|
|
|
- if (blobFile.type === 'video' && blobFile.extension.toLowerCase() === 'mp4') {
|
|
|
- blobFile.duration = await this.$tools.getVideoDuration(file)
|
|
|
- }
|
|
|
- if (blobFile.type === 'video' && blobFile.extension.toLowerCase() !== 'mp4') {
|
|
|
- this.$Message.warning(blobFile.name + this.$t('syllabus.playFailTip'))
|
|
|
- }
|
|
|
- let fileMD5 = await this.$tools.getFileMD5(file)
|
|
|
- blobFile.hash = this.$tools.convertFileMD5ToString(fileMD5)
|
|
|
- console.log('BaseUpload > md5',blobFile.hash);
|
|
|
- r(blobFile)
|
|
|
- }catch(e){
|
|
|
- this.$Message.error(e.spaceError || 'upload Fail')
|
|
|
- j(e)
|
|
|
- }
|
|
|
- }))
|
|
|
- }
|
|
|
-
|
|
|
- Promise.all(promiseArr).then(result => {
|
|
|
- this.$emit('uploadFinish',result)
|
|
|
- }).catch(e => {
|
|
|
- this.$Message.error('upload Fail!')
|
|
|
- }).finally(() => {
|
|
|
- this.fileArr = []
|
|
|
- this.progressArr = []
|
|
|
- that.isLoading = false
|
|
|
- })
|
|
|
-
|
|
|
- }
|
|
|
- },
|
|
|
- mounted() {
|
|
|
- if(this.auth.sas){
|
|
|
- let n = this.auth
|
|
|
- this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
|
|
|
- }
|
|
|
- },
|
|
|
- watch: {
|
|
|
- auth: {
|
|
|
- handler(n, o) {
|
|
|
- this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ methods: {
|
|
|
+ async onBeforeUpload(file) {
|
|
|
+ let nameType = file.name.split('.')[file.name.split('.').length - 1]
|
|
|
+ if (this.$GLOBAL.NotSupport.includes(nameType.toUpperCase())) {
|
|
|
+ this.$Message.warning(this.$t('learnActivity.notSupportType')); // 黑名单文件格式不能上传
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ if (this.simpleUpload) {
|
|
|
+ this.$emit('uploadFinish', file)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ file.progress = 0
|
|
|
+ this.fileArr.push(file)
|
|
|
+ this.progressArr.push(0)
|
|
|
+ return false
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+ onRemoveFile(index) {
|
|
|
+ this.fileArr.splice(index, 1)
|
|
|
+ },
|
|
|
+
|
|
|
+ async onConfirmUpload() {
|
|
|
+ this.isShowTool = false
|
|
|
+ let result = []
|
|
|
+ let containerClient = this.containerClient
|
|
|
+ let list = this.fileArr
|
|
|
+ let that = this
|
|
|
+ let promiseArr = []
|
|
|
+ that.isLoading = true
|
|
|
+ for (let i = 0; i < list.length; i++) {
|
|
|
+ let file = list[i]
|
|
|
+ promiseArr.push(new Promise(async (r, j) => {
|
|
|
+ try {
|
|
|
+ let blobFile = await containerClient.upload(file, { path: this.prefix }, {
|
|
|
+ onProgress: function (e) {
|
|
|
+ that.$set(that.progressArr, i, parseInt(e.loadedBytes * 100 / file.size))
|
|
|
+ }
|
|
|
+ });
|
|
|
+ // 如果上传的是视频文件 则需要获取视频的时长信息和MD5信息
|
|
|
+ if (blobFile.type === 'video' && blobFile.extension.toLowerCase() === 'mp4') {
|
|
|
+ blobFile.duration = await this.$tools.getVideoDuration(file)
|
|
|
+ }
|
|
|
+ if (blobFile.type === 'video' && blobFile.extension.toLowerCase() !== 'mp4') {
|
|
|
+ this.$Message.warning(blobFile.name + this.$t('syllabus.playFailTip'))
|
|
|
+ }
|
|
|
+ let fileMD5 = await this.$tools.getFileMD5(file)
|
|
|
+ blobFile.hash = this.$tools.convertFileMD5ToString(fileMD5)
|
|
|
+ console.log('BaseUpload > md5', blobFile.hash);
|
|
|
+ console.error(blobFile)
|
|
|
+ console.error(this.prefix)
|
|
|
+ // 如果上传的是HTEX文件 则需要访问解压接口后 再删除原压缩包
|
|
|
+ if (blobFile.extension.toLowerCase() === 'htex') {
|
|
|
+ let htexUploadStatus = await this.doUploadHTEX(blobFile)
|
|
|
+ if (htexUploadStatus !== 200) {
|
|
|
+ j(500)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ r(blobFile)
|
|
|
+ } catch (e) {
|
|
|
+ this.$Message.error(e.spaceError || 'upload Fail')
|
|
|
+ j(e)
|
|
|
+ }
|
|
|
+ }))
|
|
|
+ }
|
|
|
+ Promise.all(promiseArr).then(result => {
|
|
|
+ this.$emit('uploadFinish', result)
|
|
|
+ }).catch(e => {
|
|
|
+ this.$Message.error('upload Fail!')
|
|
|
+ }).finally(() => {
|
|
|
+ this.fileArr = []
|
|
|
+ this.progressArr = []
|
|
|
+ that.isLoading = false
|
|
|
+ })
|
|
|
+
|
|
|
+ },
|
|
|
+ /* 处理HTEX文件的上传 */
|
|
|
+ doUploadHTEX(blobFile) {
|
|
|
+ return new Promise(async (r, j) => {
|
|
|
+ axios({
|
|
|
+ method: 'post',
|
|
|
+ url: `${window.location.protocol}//${window.location.host}/import/parse-doc`,
|
|
|
+ data: {
|
|
|
+ file: blobFile.url,
|
|
|
+ scope: this.scope,
|
|
|
+ target: this.prefix,
|
|
|
+ },
|
|
|
+ timeout: 10 * 60 * 1000, //十分钟
|
|
|
+ }).then(
|
|
|
+ parseRes => {
|
|
|
+ r(200)
|
|
|
+ },
|
|
|
+ parseErr => {
|
|
|
+ j(500)
|
|
|
+ }
|
|
|
+ ).finally(() => {
|
|
|
+ this.containerClient.deleteBlob(blobFile.blob)
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+ },
|
|
|
+ mounted() {
|
|
|
+ if (this.auth.sas) {
|
|
|
+ let n = this.auth
|
|
|
+ this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
|
|
|
+ }
|
|
|
+ },
|
|
|
+ watch: {
|
|
|
+ auth: {
|
|
|
+ handler(n, o) {
|
|
|
+ this.containerClient = new BlobTool(n.url, n.name, n.sas, this.scope)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
</script>
|
|
|
|
|
|
<style lang="less">
|
|
|
- .base-upload-container{
|
|
|
- padding-bottom: 40px;
|
|
|
- .file-list-box{
|
|
|
- margin: 20px 5px;
|
|
|
- width: 100%;
|
|
|
- max-height: 200px;
|
|
|
- overflow: auto;
|
|
|
-
|
|
|
- .file-item{
|
|
|
- margin: 10px 0;
|
|
|
-
|
|
|
- .tool-remove{
|
|
|
- color: #b3b3b3;
|
|
|
- margin-left: 15px;
|
|
|
- font-size: 14px;
|
|
|
- cursor: pointer;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- .ivu-progress{
|
|
|
- margin-top: 10px;
|
|
|
- }
|
|
|
-
|
|
|
- .ivu-progress-text-inner{
|
|
|
- color: #ddd;
|
|
|
- }
|
|
|
-
|
|
|
- &::-webkit-scrollbar-thumb{
|
|
|
- background:#dadada !important;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+.base-upload-container {
|
|
|
+ padding-bottom: 40px;
|
|
|
+ .file-list-box {
|
|
|
+ margin: 20px 5px;
|
|
|
+ width: 100%;
|
|
|
+ max-height: 200px;
|
|
|
+ overflow: auto;
|
|
|
+
|
|
|
+ .file-item {
|
|
|
+ margin: 10px 0;
|
|
|
+
|
|
|
+ .tool-remove {
|
|
|
+ color: #b3b3b3;
|
|
|
+ margin-left: 15px;
|
|
|
+ font-size: 14px;
|
|
|
+ cursor: pointer;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ .ivu-progress {
|
|
|
+ margin-top: 10px;
|
|
|
+ }
|
|
|
+
|
|
|
+ .ivu-progress-text-inner {
|
|
|
+ color: #ddd;
|
|
|
+ }
|
|
|
+
|
|
|
+ &::-webkit-scrollbar-thumb {
|
|
|
+ background: #dadada !important;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
</style>
|