|
@ -284,51 +284,24 @@ wxPay(orderData) |
|
|
|
|
|
|
|
|
1. 单文件上传 |
|
|
1. 单文件上传 |
|
|
```javascript |
|
|
```javascript |
|
|
// 在组件中使用 |
|
|
|
|
|
import { uploadFile } from '@/utils/oss-upload' |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
methods: { |
|
|
methods: { |
|
|
async onUpload(file) { |
|
|
|
|
|
try { |
|
|
|
|
|
const result = await uploadFile(file) |
|
|
|
|
|
console.log('上传成功:', result.url) |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('上传失败:', error) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
onUpload(file) { |
|
|
|
|
|
this.$Oss.ossUpload(file.path).then(url => { |
|
|
|
|
|
this.filePath = url |
|
|
|
|
|
}) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
``` |
|
|
``` |
|
|
|
|
|
|
|
|
2. 多文件上传 |
|
|
|
|
|
```javascript |
|
|
|
|
|
// 在组件中使用 |
|
|
|
|
|
import { uploadFiles } from '@/utils/oss-upload' |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
|
|
|
methods: { |
|
|
|
|
|
async onUploadMultiple(files) { |
|
|
|
|
|
try { |
|
|
|
|
|
const results = await uploadFiles(files) |
|
|
|
|
|
results.forEach(result => { |
|
|
|
|
|
console.log('文件上传成功:', result.url) |
|
|
|
|
|
}) |
|
|
|
|
|
} catch (error) { |
|
|
|
|
|
console.error('上传失败:', error) |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
``` |
|
|
|
|
|
|
|
|
|
|
|
3. 在uv-upload组件中使用 |
|
|
|
|
|
|
|
|
2. 在uv-upload组件中使用 |
|
|
```html |
|
|
```html |
|
|
<template> |
|
|
<template> |
|
|
<uv-upload |
|
|
<uv-upload |
|
|
:fileList="fileList" |
|
|
:fileList="fileList" |
|
|
@afterRead="afterRead" |
|
|
@afterRead="afterRead" |
|
|
@delete="deletePic" |
|
|
|
|
|
|
|
|
@delete="deleteImage" |
|
|
name="1" |
|
|
name="1" |
|
|
multiple |
|
|
multiple |
|
|
:maxCount="maxCount" |
|
|
:maxCount="maxCount" |
|
@ -336,8 +309,6 @@ export default { |
|
|
</template> |
|
|
</template> |
|
|
|
|
|
|
|
|
<script> |
|
|
<script> |
|
|
import { uploadFile } from '@/utils/oss-upload' |
|
|
|
|
|
|
|
|
|
|
|
export default { |
|
|
export default { |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
@ -347,30 +318,19 @@ export default { |
|
|
}, |
|
|
}, |
|
|
methods: { |
|
|
methods: { |
|
|
// 新增图片 |
|
|
// 新增图片 |
|
|
async afterRead(event) { |
|
|
|
|
|
let lists = [].concat(event.file) |
|
|
|
|
|
let fileListLen = this.fileList.length |
|
|
|
|
|
lists.map((item) => { |
|
|
|
|
|
this.fileList.push({ |
|
|
|
|
|
...item, |
|
|
|
|
|
status: 'uploading', |
|
|
|
|
|
message: '上传中' |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
for (let i = 0; i < lists.length; i++) { |
|
|
|
|
|
const result = await uploadFile(lists[i]) |
|
|
|
|
|
let item = this.fileList[fileListLen + i] |
|
|
|
|
|
this.fileList.splice(fileListLen + i, 1, Object.assign(item, { |
|
|
|
|
|
status: 'success', |
|
|
|
|
|
message: '', |
|
|
|
|
|
url: result |
|
|
|
|
|
})) |
|
|
|
|
|
} |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
afterRead(e) { |
|
|
|
|
|
e.file.forEach(file => { |
|
|
|
|
|
this.$Oss.ossUpload(file.url).then(url => { |
|
|
|
|
|
this.fileList.push({ |
|
|
|
|
|
url |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
}) |
|
|
|
|
|
}, |
|
|
// 删除图片 |
|
|
// 删除图片 |
|
|
deletePic(event) { |
|
|
|
|
|
this.fileList.splice(event.index, 1) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
deleteImage(e) { |
|
|
|
|
|
this.fileList.splice(e.index, 1) |
|
|
|
|
|
}, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
</script> |
|
|
</script> |
|
|