|
@@ -11,6 +11,7 @@ import { Document } from '@element-plus/icons-vue'
|
|
import styles from './index.module.less'
|
|
import styles from './index.module.less'
|
|
import iconVideo from './images/icon_video.png'
|
|
import iconVideo from './images/icon_video.png'
|
|
import request from '@/helpers/request'
|
|
import request from '@/helpers/request'
|
|
|
|
+import { getUploadSign, onOnlyFileUpload } from '@/helpers/oss-file-upload'
|
|
|
|
|
|
export default defineComponent({
|
|
export default defineComponent({
|
|
name: 'col-upload-video',
|
|
name: 'col-upload-video',
|
|
@@ -72,31 +73,66 @@ export default defineComponent({
|
|
},
|
|
},
|
|
fileList: [] as any,
|
|
fileList: [] as any,
|
|
tempUrls: {} as any,
|
|
tempUrls: {} as any,
|
|
|
|
+ uploadFileLength: 0, // 上传文件数量
|
|
responseList: [] as any, // 请求成功之后的数据
|
|
responseList: [] as any, // 请求成功之后的数据
|
|
btnLoading: false,
|
|
btnLoading: false,
|
|
loading: null as any
|
|
loading: null as any
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
- handleSuccess(response: any, uploadFile: any, uploadFiles: any) {
|
|
|
|
- this.loading?.close()
|
|
|
|
|
|
+ async handleSuccess(info: any, uploadFiles: any) {
|
|
|
|
+ // console.log(info, uploadFiles, 'uploadFiles')
|
|
|
|
+ try {
|
|
|
|
+ const obj = {
|
|
|
|
+ policy: info.data.policy,
|
|
|
|
+ signature: info.data.signature,
|
|
|
|
+ key: info.data.key,
|
|
|
|
+ KSSAccessKeyId: info.data.kssAccessKeyId,
|
|
|
|
+ acl: 'public-read',
|
|
|
|
+ name: info.data.key,
|
|
|
|
+ file: info.file
|
|
|
|
+ }
|
|
|
|
+ const url = await onOnlyFileUpload(this.ossUploadUrl, obj)
|
|
|
|
|
|
|
|
+ if (this.multiple) {
|
|
|
|
+ this.responseList.push(url)
|
|
|
|
+ // if (uploadFile.status === 'success') {
|
|
|
|
+ // this.responseList.push(this.tempUrls[uploadFile.uid])
|
|
|
|
+ // }
|
|
|
|
+ // // 说明已经上传完成
|
|
|
|
+ // // console.log(uploadFiles, 'uploadFiles')
|
|
|
|
+ // // console.log(this.responseList, 'responseList')
|
|
|
|
+ if (this.uploadFileLength === this.responseList.length) {
|
|
|
|
+ this.btnLoading = false
|
|
|
|
+ this.multipleModel(this.responseList)
|
|
|
|
+ this.responseList = [] as any
|
|
|
|
+ this.fileList = [] as any
|
|
|
|
+ }
|
|
|
|
+ return this.responseList
|
|
|
|
+ } else {
|
|
|
|
+ this.$emit('update:modelValue', url)
|
|
|
|
+ return url
|
|
|
|
+ }
|
|
|
|
+ } catch {
|
|
|
|
+ //
|
|
|
|
+ }
|
|
|
|
+ this.loading?.close()
|
|
// 多文件上传,每个文件上传成功后,将文件的url添加到fileList
|
|
// 多文件上传,每个文件上传成功后,将文件的url添加到fileList
|
|
- console.log(this.fileList, 'fileList')
|
|
|
|
- console.log(response, uploadFile, uploadFiles, 'response')
|
|
|
|
|
|
+ // console.log(this.fileList, 'fileList')
|
|
|
|
+ // console.log(response, uploadFile, uploadFiles, 'response')
|
|
if (this.multiple) {
|
|
if (this.multiple) {
|
|
- if (uploadFile.status === 'success') {
|
|
|
|
- this.responseList.push(this.tempUrls[uploadFile.uid])
|
|
|
|
- }
|
|
|
|
- // 说明已经上传完成
|
|
|
|
- // console.log(uploadFiles, 'uploadFiles')
|
|
|
|
- // console.log(this.responseList, 'responseList')
|
|
|
|
- if (uploadFiles.length === this.responseList.length) {
|
|
|
|
- this.btnLoading = false
|
|
|
|
- this.multipleModel(this.responseList)
|
|
|
|
- this.responseList = [] as any
|
|
|
|
- this.fileList = [] as any
|
|
|
|
- }
|
|
|
|
|
|
+ // if (uploadFile.status === 'success') {
|
|
|
|
+ // this.responseList.push(this.tempUrls[uploadFile.uid])
|
|
|
|
+ // }
|
|
|
|
+ // // 说明已经上传完成
|
|
|
|
+ // // console.log(uploadFiles, 'uploadFiles')
|
|
|
|
+ // // console.log(this.responseList, 'responseList')
|
|
|
|
+ // if (uploadFiles.length === this.responseList.length) {
|
|
|
|
+ // this.btnLoading = false
|
|
|
|
+ // this.multipleModel(this.responseList)
|
|
|
|
+ // this.responseList = [] as any
|
|
|
|
+ // this.fileList = [] as any
|
|
|
|
+ // }
|
|
} else {
|
|
} else {
|
|
const url = this.ossUploadUrl + this.dataObj.key
|
|
const url = this.ossUploadUrl + this.dataObj.key
|
|
this.$emit('update:modelValue', url)
|
|
this.$emit('update:modelValue', url)
|
|
@@ -105,13 +141,14 @@ export default defineComponent({
|
|
handleRemove() {
|
|
handleRemove() {
|
|
console.log('remove')
|
|
console.log('remove')
|
|
},
|
|
},
|
|
- handleChange() {
|
|
|
|
- console.log('handleChange')
|
|
|
|
|
|
+ handleChange(file, fileList) {
|
|
|
|
+ // console.log('handleChange', file, fileList)
|
|
|
|
+ this.uploadFileLength = fileList.length
|
|
// this.responseList = []
|
|
// this.responseList = []
|
|
// this.tempUrls = []
|
|
// this.tempUrls = []
|
|
},
|
|
},
|
|
handleProgress(e) {
|
|
handleProgress(e) {
|
|
- console.log('handleProgress', e)
|
|
|
|
|
|
+ // console.log('handleProgress', e)
|
|
},
|
|
},
|
|
handleError() {
|
|
handleError() {
|
|
this.btnLoading = false
|
|
this.btnLoading = false
|
|
@@ -119,7 +156,7 @@ export default defineComponent({
|
|
},
|
|
},
|
|
async beforeUpload(file: any) {
|
|
async beforeUpload(file: any) {
|
|
// beforeUpload
|
|
// beforeUpload
|
|
- console.log(file)
|
|
|
|
|
|
+ // console.log(file)
|
|
// let fileType = true
|
|
// let fileType = true
|
|
// if (props.rules.type && props.rules.type.length > 0) {
|
|
// if (props.rules.type && props.rules.type.length > 0) {
|
|
// const fileExtension = file.name.split('.').pop().toUpperCase()
|
|
// const fileExtension = file.name.split('.').pop().toUpperCase()
|
|
@@ -157,28 +194,28 @@ export default defineComponent({
|
|
})
|
|
})
|
|
}
|
|
}
|
|
try {
|
|
try {
|
|
- let fileName = file.name.replaceAll(' ', '_')
|
|
|
|
- let key = new Date().getTime() + fileName
|
|
|
|
- let obj = {
|
|
|
|
- filename: fileName,
|
|
|
|
|
|
+ const fileName = file.name.replaceAll(' ', '_')
|
|
|
|
+ const key = new Date().getTime() + fileName
|
|
|
|
+ const obj = {
|
|
|
|
+ filename: key,
|
|
bucketName: this.bucket,
|
|
bucketName: this.bucket,
|
|
postData: {
|
|
postData: {
|
|
- filename: fileName,
|
|
|
|
|
|
+ filename: key,
|
|
acl: 'public-read',
|
|
acl: 'public-read',
|
|
- key: key,
|
|
|
|
- unknowValueField: []
|
|
|
|
|
|
+ key: key
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- const { data } = await request.post('/api-website/getUploadSign', {
|
|
|
|
- data: obj
|
|
|
|
- })
|
|
|
|
|
|
+ // const { data } = await request.post('/api-website/getUploadSign', {
|
|
|
|
+ // data: obj
|
|
|
|
+ // })
|
|
|
|
+ const { data } = await getUploadSign(obj)
|
|
this.dataObj = {
|
|
this.dataObj = {
|
|
policy: data.policy,
|
|
policy: data.policy,
|
|
signature: data.signature,
|
|
signature: data.signature,
|
|
key: key,
|
|
key: key,
|
|
KSSAccessKeyId: data.kssAccessKeyId,
|
|
KSSAccessKeyId: data.kssAccessKeyId,
|
|
acl: 'public-read',
|
|
acl: 'public-read',
|
|
- name: fileName
|
|
|
|
|
|
+ name: key
|
|
}
|
|
}
|
|
this.tempUrls[file.uid] = this.ossUploadUrl + this.dataObj.key
|
|
this.tempUrls[file.uid] = this.ossUploadUrl + this.dataObj.key
|
|
} catch (e) {
|
|
} catch (e) {
|
|
@@ -203,7 +240,7 @@ export default defineComponent({
|
|
disabled={this.disabled || this.btnLoading}
|
|
disabled={this.disabled || this.btnLoading}
|
|
action={this.ossUploadUrl}
|
|
action={this.ossUploadUrl}
|
|
data={this.dataObj}
|
|
data={this.dataObj}
|
|
- onSuccess={this.handleSuccess}
|
|
|
|
|
|
+ httpRequest={this.handleSuccess}
|
|
onRemove={this.handleRemove}
|
|
onRemove={this.handleRemove}
|
|
onChange={this.handleChange}
|
|
onChange={this.handleChange}
|
|
onProgress={this.handleProgress}
|
|
onProgress={this.handleProgress}
|