|
@@ -4,6 +4,29 @@ export default {
|
|
|
isHttp(path) {
|
|
|
return path.startsWith('http') || path.startsWith('https')
|
|
|
},
|
|
|
+ uuid(len = 16) {
|
|
|
+ const chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('')
|
|
|
+ const uuid = []
|
|
|
+
|
|
|
+ if (len) {
|
|
|
+
|
|
|
+ for (let i = 0; i < len; i++) uuid[i] = chars[0 | Math.random() * chars.length]
|
|
|
+ } else {
|
|
|
+ let r
|
|
|
+
|
|
|
+ uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-'
|
|
|
+ uuid[14] = '4'
|
|
|
+
|
|
|
+ for (let i = 0; i < 36; i++) {
|
|
|
+ if (!uuid[i]) {
|
|
|
+ r = 0 | Math.random() * 16
|
|
|
+ uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return uuid.join('')
|
|
|
+ },
|
|
|
upload(data) {
|
|
|
return uni.uploadFile({
|
|
|
url: this.isHttp(data.url) ? data.url : config.apiBaseUrl + data.url,
|
|
@@ -28,10 +51,11 @@ export default {
|
|
|
return this[methods](chooseParam).then(file => {
|
|
|
file.filePaths.forEach((filePath, index) => {
|
|
|
if (isCloud) {
|
|
|
+ const fileArr = filePath.split('.')
|
|
|
uploadArr.push(this.uploadCloud({
|
|
|
- filePath,
|
|
|
- cloudPath: file.tempFiles[index].name,
|
|
|
- fileType: file.tempFiles[index].type
|
|
|
+ filePath,
|
|
|
+ cloudPath: this.uuid() + '.' + fileArr[fileArr.length - 1],
|
|
|
+ fileType: (methods === 'chooseImage' ? 'image/' : 'video/') + fileArr[fileArr.length - 1]
|
|
|
}).then(res => {
|
|
|
if (res.success) {
|
|
|
return {
|