|
@@ -21,15 +21,11 @@
|
|
|
import '@/icons/svg/loading3.svg'
|
|
|
import sha1 from 'js-sha1'
|
|
|
import { Array } from 'core-js'
|
|
|
- //require('@/utils/azure-storage-blob.js') //v10
|
|
|
const { BlobServiceClient } = require("@azure/storage-blob")//v12
|
|
|
export default {
|
|
|
data() {
|
|
|
return {
|
|
|
- urlString: '',
|
|
|
- blobContainer: '',
|
|
|
containerURL: undefined,
|
|
|
- sasString: '',
|
|
|
uploadedList: [],
|
|
|
contentTypes: [
|
|
|
['JPG', 'JPEG', 'PNG', 'GIF'],
|
|
@@ -40,32 +36,44 @@
|
|
|
}
|
|
|
},
|
|
|
props: {
|
|
|
+ //默认文件列表
|
|
|
defaultFileList: {
|
|
|
default: () => {
|
|
|
return []
|
|
|
},
|
|
|
type: Array
|
|
|
},
|
|
|
- accountName: {
|
|
|
- default: 'teammodelostest',
|
|
|
+ //文件夹
|
|
|
+ folder: {
|
|
|
+ default: 'res',
|
|
|
type: String
|
|
|
},
|
|
|
- containerName: {
|
|
|
- default: 'teammodelos',
|
|
|
+ //授权信息
|
|
|
+ sasString:{
|
|
|
+ default: 'res',
|
|
|
type: String
|
|
|
},
|
|
|
- pathName: {
|
|
|
+ //blob链接
|
|
|
+ urlString:{
|
|
|
default: '',
|
|
|
type: String
|
|
|
},
|
|
|
+ //容器名称
|
|
|
+ containerName:{
|
|
|
+ default: '',
|
|
|
+ type: String
|
|
|
+ },
|
|
|
+ //缩略图压缩质量
|
|
|
quality: {
|
|
|
default: 0.2,
|
|
|
type: Number
|
|
|
},
|
|
|
+ //文件大小限制
|
|
|
maxSize: {
|
|
|
default: 2 * 1024 * 1024 * 1024,
|
|
|
type: Number
|
|
|
},
|
|
|
+ //文件格式限制
|
|
|
format: {
|
|
|
default: () => {
|
|
|
return []
|
|
@@ -87,13 +95,10 @@
|
|
|
this.$emit('deleteFile', this.uploadedList[index])
|
|
|
this.uploadedList.splice(index, 1)
|
|
|
},
|
|
|
+ //初始化blob
|
|
|
initBlob() {
|
|
|
- /**
|
|
|
- * v12
|
|
|
- * */
|
|
|
- const blobServiceClient = new BlobServiceClient(this.urlString + this.sasString);
|
|
|
- const containerName = this.blobContainer
|
|
|
- this.containerURL = blobServiceClient.getContainerClient(containerName);
|
|
|
+ let blobServiceClient = new BlobServiceClient(this.urlString + this.sasString)
|
|
|
+ this.containerURL = blobServiceClient.getContainerClient(this.containerName)
|
|
|
},
|
|
|
dataURLtoFile(dataurl, filename) {
|
|
|
var arr = dataurl.split(','); var mime = arr[0].match(/:(.*?);/)[1]
|
|
@@ -103,6 +108,7 @@
|
|
|
}
|
|
|
return new File([u8arr], filename, { type: mime })
|
|
|
},
|
|
|
+ //处理图片缩略图和视频封面
|
|
|
compressFile(file, fileInfo) {
|
|
|
if (fileInfo.type == 'picture') {
|
|
|
let reader = new FileReader()
|
|
@@ -120,31 +126,10 @@
|
|
|
let newImgData = canvas.toDataURL(file.type, this.quality)
|
|
|
var resultFile = this.dataURLtoFile(newImgData, file.name)
|
|
|
this.initBlob()
|
|
|
- let options = {
|
|
|
- blockSize: 10 * 1024 * 1024
|
|
|
- }
|
|
|
- /**
|
|
|
- * v10
|
|
|
- * */
|
|
|
- //const compressBlobURL = this.$azblob.BlockBlobURL.fromContainerURL(
|
|
|
- // this.containerURL,
|
|
|
- // 'compress' + file.name
|
|
|
- //)
|
|
|
-
|
|
|
- //this.$azblob.uploadBrowserDataToBlockBlob(
|
|
|
- // this.$azblob.Aborter.none,
|
|
|
- // resultFile,
|
|
|
- // compressBlobURL,
|
|
|
- // options
|
|
|
- //)
|
|
|
-
|
|
|
- /**
|
|
|
- * v12
|
|
|
- * */
|
|
|
- const blockBlobClient = this.containerURL.getBlockBlobClient(this.pathName + "/compress" + file.name)
|
|
|
+ const blockBlobClient = this.containerURL.getBlockBlobClient(this.folder + "/compress" + file.name)
|
|
|
blockBlobClient.uploadBrowserData(resultFile).then(
|
|
|
res => {
|
|
|
- fileInfo['compressUrl'] = this.urlString + '/' + this.blobContainer + '/' + this.pathName + '/compress' + file.name
|
|
|
+ fileInfo['compressUrl'] = this.urlString + '/' + this.containerName + '/' + this.folder + '/compress' + file.name
|
|
|
this.$emit('successData', fileInfo)
|
|
|
},
|
|
|
err => {
|
|
@@ -170,26 +155,10 @@
|
|
|
let resultFile = this.dataURLtoFile(newVideoData, file.name)
|
|
|
this.initBlob()
|
|
|
let posterName = 'compress' + file.name.replace(fileInfo.extension, 'png')
|
|
|
- /**
|
|
|
- * v10
|
|
|
- * */
|
|
|
- //const compressBlobURL = this.$azblob.BlockBlobURL.fromContainerURL(
|
|
|
- // this.containerURL,
|
|
|
- // posterName
|
|
|
- //)
|
|
|
- //this.$azblob.uploadBrowserDataToBlockBlob(
|
|
|
- // this.$azblob.Aborter.none,
|
|
|
- // resultFile,
|
|
|
- // compressBlobURL
|
|
|
- //)
|
|
|
-
|
|
|
- /**
|
|
|
- * v12
|
|
|
- **/
|
|
|
- const blockBlobClient = this.containerURL.getBlockBlobClient(this.pathName + "/" + posterName)
|
|
|
+ const blockBlobClient = this.containerURL.getBlockBlobClient(this.folder + "/" + posterName)
|
|
|
blockBlobClient.uploadBrowserData(resultFile).then(
|
|
|
res => {
|
|
|
- fileInfo['compressUrl'] = this.urlString + '/' + this.blobContainer + '/' + this.pathName + '/' + posterName
|
|
|
+ fileInfo['compressUrl'] = this.urlString + '/'+ this.containerName + '/' + this.folder + '/' + posterName
|
|
|
this.$emit('successData', fileInfo)
|
|
|
},
|
|
|
err => {
|
|
@@ -201,10 +170,9 @@
|
|
|
}
|
|
|
},
|
|
|
uploadToBlob(file) {
|
|
|
- console.log(file)
|
|
|
let fileItem = {}
|
|
|
fileItem['fileName'] = file.name
|
|
|
- fileItem['blobUrl'] = this.urlString + '/' + this.blobContainer + '/' + this.pathName + '/' + file.name
|
|
|
+ fileItem['blobUrl'] = this.urlString + '/' + this.containerName + '/' + this.folder + '/' + file.name
|
|
|
fileItem['extension'] = file.name.substring(file.name.lastIndexOf('.') + 1)
|
|
|
fileItem['size'] = file.size
|
|
|
fileItem['status'] = 0
|
|
@@ -231,19 +199,8 @@
|
|
|
fileItem['type'] = type
|
|
|
this.uploadedList.push(fileItem)
|
|
|
|
|
|
- //v10
|
|
|
- //const blockBlobURL = this.$azblob.BlockBlobURL.fromContainerURL(
|
|
|
- // this.containerURL,
|
|
|
- // file.name
|
|
|
- //)
|
|
|
- //this.$azblob.uploadBrowserDataToBlockBlob(
|
|
|
- // this.$azblob.Aborter.none,
|
|
|
- // file,
|
|
|
- // blockBlobURL
|
|
|
- //)
|
|
|
-
|
|
|
//v12
|
|
|
- const blockBlobClient = this.containerURL.getBlockBlobClient(this.pathName + "/" + file.name)
|
|
|
+ const blockBlobClient = this.containerURL.getBlockBlobClient(this.folder + "/" + file.name)
|
|
|
blockBlobClient.uploadBrowserData(file).then(
|
|
|
res => {
|
|
|
let reader = new FileReader()
|
|
@@ -291,23 +248,9 @@
|
|
|
})
|
|
|
return false
|
|
|
}
|
|
|
-
|
|
|
- this.$api.uploadFile.getContainerSAS().then(
|
|
|
- (res) => {
|
|
|
- if (res.error == null) {
|
|
|
- this.sasString = res.result.data.SAS
|
|
|
- this.blobContainer = res.result.data.Container
|
|
|
- this.urlString = res.result.data.Url
|
|
|
- this.initBlob()
|
|
|
- this.uploadToBlob(file)
|
|
|
- } else {
|
|
|
- alert('API error!')
|
|
|
- }
|
|
|
- },
|
|
|
- (err) => {
|
|
|
- alert('API error!')
|
|
|
- }
|
|
|
- )
|
|
|
+ this.initBlob()
|
|
|
+ this.uploadToBlob(file)
|
|
|
+
|
|
|
return false
|
|
|
},
|
|
|
getIndex(_arr, _obj) {
|
|
@@ -335,7 +278,6 @@
|
|
|
}
|
|
|
},
|
|
|
mounted() {
|
|
|
- //this.uploadedList = []
|
|
|
this.uploadedList = this.defaultFileList
|
|
|
},
|
|
|
created() {
|