Commit 2a72d262 by wangzhihui

阿里云上传

1 parent 23334e75
...@@ -287,10 +287,12 @@ export default { ...@@ -287,10 +287,12 @@ export default {
}) })
this.$emit("beforeUpload") this.$emit("beforeUpload")
this.uploading = true this.uploading = true
if (this.picOptions.type == "video") { console.log(this.picOptions.type, 6666)
this.uploadVideoFn(e) // if (this.picOptions.type == "video") {
return // console.log(333333)
} // this.uploadVideoFn(e)
// return
// }
// reader.readAsDataURL(file) // reader.readAsDataURL(file)
// reader.onload = (e) => { // reader.onload = (e) => {
// const imgFile = e.target.result // const imgFile = e.target.result
......
...@@ -781,7 +781,6 @@ export default { ...@@ -781,7 +781,6 @@ export default {
setTimeout(() => { setTimeout(() => {
// var reader = new FileReader() // var reader = new FileReader()
const fileInfo = e.raw const fileInfo = e.raw
console.log("fileInfo", fileInfo)
const fileName = fileInfo.name const fileName = fileInfo.name
if ( if (
!fileInfo.name.includes(".pdf") && !fileInfo.name.includes(".pdf") &&
......
...@@ -184,6 +184,8 @@ import { deepClone } from "@/common/util" ...@@ -184,6 +184,8 @@ import { deepClone } from "@/common/util"
import { mapActions, mapState } from "vuex" import { mapActions, mapState } from "vuex"
import { limitPrice } from "@/common/format" import { limitPrice } from "@/common/format"
import { uploadFile } from "@/api/sys.base" import { uploadFile } from "@/api/sys.base"
import { baseConfig } from "@/main"
import GlOssApi from "glsk-oss-jssdk"
export default { export default {
name: "NewSignRefundDialog", name: "NewSignRefundDialog",
data() { data() {
...@@ -673,6 +675,9 @@ export default { ...@@ -673,6 +675,9 @@ export default {
}, },
mounted() { mounted() {
this.GlOssApi = new GlOssApi({
baseConfig
})
this.infoForm.orderType = this.orderType this.infoForm.orderType = this.orderType
// 入口:精品升级、会员权益升级、次新车转化,售后众筹、积分商城 // 入口:精品升级、会员权益升级、次新车转化,售后众筹、积分商城
if (this.detail) { if (this.detail) {
...@@ -869,13 +874,11 @@ export default { ...@@ -869,13 +874,11 @@ export default {
console.log(fileList, "fileList") console.log(fileList, "fileList")
}, },
handleFileChange(file, fileList, targetItem) { handleFileChange(file, fileList, targetItem) {
console.log("file", file)
console.log("fileList", fileList)
console.log("targetItem", targetItem)
// return false // return false
// setTimeout(() => { // setTimeout(() => {
var reader = new FileReader() // var reader = new FileReader()
var fileInfo = file.raw var fileInfo = file.raw
const fileName = fileInfo.name
if ( if (
!fileInfo.name.includes(".xlsx") && !fileInfo.name.includes(".xlsx") &&
!fileInfo.name.includes(".xls") && !fileInfo.name.includes(".xls") &&
...@@ -904,88 +907,82 @@ export default { ...@@ -904,88 +907,82 @@ export default {
}) })
return false return false
} }
reader.readAsDataURL(fileInfo) // reader.readAsDataURL(fileInfo)
reader.onload = (e) => { // reader.onload = (e) => {
// const _attachmentList = this.infoForm.attachmentList // // const _attachmentList = this.infoForm.attachmentList
const _formData = this.infoForm // const _formData = this.infoForm
_formData[targetItem.name].push({ // _formData[targetItem.name].push({
fileUrl: "", // fileUrl: "",
uploadProgress: 0, // uploadProgress: 0,
fileName: fileInfo.name?.substring(0, 128), // fileName: fileInfo.name?.substring(0, 128),
fileSize: fileInfo.size, // fileSize: fileInfo.size,
fileType: 1, // 文件类型(1.申请附件,2.结算凭证) // fileType: 1, // 文件类型(1.申请附件,2.结算凭证)
cancelAxios: {} // cancelAxios: {}
}) // })
const index = _formData[targetItem.name].length - 1 // const index = _formData[targetItem.name].length - 1
const fileData = e.target.result // const fileData = e.target.result
const base64 = // const base64 =
fileInfo.name.split(".")[fileInfo.name.split(".").length - 1] + // fileInfo.name.split(".")[fileInfo.name.split(".").length - 1] +
"@" + // "@" +
fileData.split(",")[1] // fileData.split(",")[1]
// const requestEvent = fileInfo.type == 'application/pdf' ? uploadPDF : uploadExcel // // const requestEvent = fileInfo.type == 'application/pdf' ? uploadPDF : uploadExcel
const fileTypeKey = { // const fileTypeKey = {
"application/pdf": "pdf", // "application/pdf": "pdf",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": // "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
"excel", // "excel",
"application/vnd.ms-excel": "excel", // "application/vnd.ms-excel": "excel",
"application/msword": "doc", // "application/msword": "doc",
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": // "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
"doc", // "doc",
"image/png": "image", // "image/png": "image",
"image/jpeg": "image" // "image/jpeg": "image"
} // }
// this.btnLoding = true // // this.btnLoding = true
uploadFile({ // uploadFile({
file: base64, // file: base64,
fileType: fileTypeKey[fileInfo.type], // fileType: fileTypeKey[fileInfo.type],
onProcess: (e) => { // onProcess: (e) => {
// 上传进度 // // 上传进度
const { loaded, total } = e // const { loaded, total } = e
const uploadPrecent = ((loaded / total) * 100) | 0 // const uploadPrecent = ((loaded / total) * 100) | 0
_formData[targetItem.name][index].uploadProgress = uploadPrecent // _formData[targetItem.name][index].uploadProgress = uploadPrecent
}, // },
cancelFun: _formData[targetItem.name][index].cancelAxios // 取消上传 // cancelFun: _formData[targetItem.name][index].cancelAxios // 取消上传
}) // })
.then((res) => { // .then((res) => {
_formData[targetItem.name][index].fileUrl = res // 文件地址 // _formData[targetItem.name][index].fileUrl = res // 文件地址
}) // })
.catch(() => { // .catch(() => {
this.clearItem(targetItem, index) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标 // this.clearItem(targetItem, index) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标
}) // })
console.log("_formData[targetItem.name]", _formData[targetItem.name]) // console.log("_formData[targetItem.name]", _formData[targetItem.name])
// }
const _formData = this.infoForm
_formData[targetItem.name].push({
fileUrl: "",
uploadProgress: 0,
fileName: fileInfo.name?.substring(0, 128),
fileSize: fileInfo.size,
fileType: 1, // 文件类型(1.申请附件,2.结算凭证)
cancelAxios: {}
})
const index = _formData[targetItem.name].length - 1
const success = (res) => {
_formData[targetItem.name][index].fileUrl = res.aliyunAddress // 文件地址
}
const fail = (err) => {
this.clearItem(targetItem, index)
} }
this.handleOssUpload(fileInfo, fileName, success, fail)
// }, 50) // }, 50)
}, },
uploadFileOss(file, success, error, fileType) { handleOssUpload(file, fileName, success, fail) {
const bucketName = "zzl-filerepostorypublic" // 桶名 const bucketName = "jinrong-huidan-test" // 桶名
this.GlOssApi.multipartUpload( const fileType = fileName.substr(fileName.lastIndexOf(".") + 1)
file, this.GlOssApi.multipartUpload(file, success, fail, bucketName, fileType)
(res) => {
var params = {
fileUrl: res.aliyunAddress,
fileName: res.attachment,
fileType: res.attachment.substr(
res.attachment.lastIndexOf(".") + 1
),
taskId: this.taskId
}
detailExcelImport(params).then((res) => {
if (res) {
this.setTaskIdRefesh(this.taskId) // 导入成功时保存任务ID,用于轮询
this.notice.okTips("上传成功")
}
this.btLoading = false
})
},
(err) => {
console.log(err)
this.btLoading = false
},
bucketName,
fileType
)
}, },
hanldeOnExceed(files, fileList) { hanldeOnExceed(files, fileList) {
this.$message({ this.$message({
message: "最多可上传5个文件", message: "最多可上传5个文件",
......
...@@ -295,7 +295,9 @@ export default { ...@@ -295,7 +295,9 @@ export default {
}, },
mounted() { mounted() {
// this.dialogConfig.title = this.examineType this.GlOssApi = new GlOssApi({
baseConfig
})
this.infoForm = deepClone(this.detailInfo) this.infoForm = deepClone(this.detailInfo)
this.getPlatformMerchant() this.getPlatformMerchant()
this.dealAttachment() this.dealAttachment()
...@@ -405,12 +407,9 @@ export default { ...@@ -405,12 +407,9 @@ export default {
}, },
handleFileChange(file, fileList, targetItem) { handleFileChange(file, fileList, targetItem) {
console.log("file", file) // var reader = new FileReader()
console.log("fileList", fileList) const fileInfo = file.raw
// return false const fileName = fileInfo.name
// setTimeout(() => {
var reader = new FileReader()
var fileInfo = file.raw
if (!fileInfo.name.includes(".png") && !fileInfo.name.includes(".jpg")) { if (!fileInfo.name.includes(".png") && !fileInfo.name.includes(".jpg")) {
this.$message({ this.$message({
message: "文件格式不支持上传", message: "文件格式不支持上传",
...@@ -431,93 +430,70 @@ export default { ...@@ -431,93 +430,70 @@ export default {
}) })
return false return false
} }
reader.readAsDataURL(fileInfo) // reader.readAsDataURL(fileInfo)
reader.onload = (e) => { // reader.onload = (e) => {
// const _attachmentList = this.infoForm.attachmentList // // const _attachmentList = this.infoForm.attachmentList
const _formData = this.infoForm // const _formData = this.infoForm
_formData[targetItem.name].push({ // _formData[targetItem.name].push({
fileUrl: "", // fileUrl: "",
uploadProgress: 0, // uploadProgress: 0,
fileName: fileInfo.name?.substring(0, 128), // fileName: fileInfo.name?.substring(0, 128),
fileSize: fileInfo.size, // fileSize: fileInfo.size,
fileType: 2, // 文件类型(1.申请附件,2.结算凭证) // fileType: 2, // 文件类型(1.申请附件,2.结算凭证)
cancelAxios: {} // cancelAxios: {}
}) // })
const index = _formData[targetItem.name].length - 1 // const index = _formData[targetItem.name].length - 1
const fileData = e.target.result // const fileData = e.target.result
const base64 = // const base64 =
fileInfo.name.split(".")[fileInfo.name.split(".").length - 1] + // fileInfo.name.split(".")[fileInfo.name.split(".").length - 1] +
"@" + // "@" +
fileData.split(",")[1] // fileData.split(",")[1]
// const requestEvent = fileInfo.type == 'application/pdf' ? uploadPDF : uploadExcel // const fileTypeKey = {
const fileTypeKey = { // "image/png": "png",
"image/png": "png", // "image/jpeg": "jpg"
"image/jpeg": "jpg" // }
} // uploadFile({
// this.btnLoding = true // file: base64,
const bucketName = "zzl-filerepostorypublic" // 桶名 // fileType: "image",
// const file = this.fileInfo // onProcess: (e) => {
const fileType = fileInfo.name.substr( // const { loaded, total } = e
fileInfo.name.lastIndexOf(".") + 1 // const uploadPrecent = ((loaded / total) * 100) | 0
) // _formData[targetItem.name][index].uploadProgress = uploadPrecent
GlOssApi.bucketUpload( // },
fileInfo, // cancelFun: _formData[targetItem.name][index].cancelAxios // 取消上传
(res) => { // })
// var params = { // .then((res) => {
// fileUrl: res.aliyunAddress, // _formData[targetItem.name][index].fileUrl = res // 文件地址
// fileName: res.attachment, // })
// fileType: res.attachment.substr(res.attachment.lastIndexOf('.') + 1) // .catch(() => {
// } // this.clearItem(targetItem, index) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标
// receiptImport(params).then(res => { // })
// console.log('res', res) // }
// if (res && res.data && res.data.length > 0) { const _formData = this.infoForm
// this.notice.okTips('上传成功') _formData[targetItem.name].push({
// this.handleImport() fileUrl: "",
// this.tableData.find(item => item === this.currentRow).receipt = res.data[0] uploadProgress: 0,
// this.allData.find(item => item === this.currentRow).receipt = res.data[0] fileName: fileInfo.name?.substring(0, 128),
// // this.statReceiptCount(this.allData) // 重新统计关联数 fileSize: fileInfo.size,
// console.log('this.tableData', this.tableData) fileType: 2, // 文件类型(1.申请附件,2.结算凭证)
// } cancelAxios: {}
// }) })
}, const index = _formData[targetItem.name].length - 1
(err) => {
console.log(err) const success = (res) => {
// this.btLoading = false _formData[targetItem.name][index].fileUrl = res.aliyunAddress // 文件地址
},
bucketName,
fileType
)
// uploadFile({
// file: base64,
// fileType: "image",
// onProcess: (e) => {
// // 上传进度
// const { loaded, total } = e
// const uploadPrecent = ((loaded / total) * 100) | 0
// _formData[targetItem.name][index].uploadProgress = uploadPrecent
// },
// cancelFun: _formData[targetItem.name][index].cancelAxios // 取消上传
// })
// .then((res) => {
// // let allSuc = true
// _formData[targetItem.name][index].fileUrl = res // 文件地址
// // _formData[targetItem.name].forEach(item => {
// // if (item.fileUrl == '') {
// // allSuc = false
// // }
// // })
// // if (allSuc) { // 所有文件上传成功
// // this.btnLoding = false
// // }
// })
// .catch(() => {
// // this.btnLoding = false
// this.clearItem(targetItem, index) // 上传失败将内容清空 不删除数组 防止其它上传进度 找不到对应下标
// })
console.log("_formData[targetItem.name]", _formData[targetItem.name])
} }
const fail = (err) => {
this.clearItem(targetItem, index)
}
this.handleOssUpload(fileInfo, fileName, success, fail)
}, },
handleOssUpload(file, fileName, success, fail) {
const bucketName = "jinrong-huidan-test" // 桶名
const fileType = fileName.substr(fileName.lastIndexOf(".") + 1)
this.GlOssApi.multipartUpload(file, success, fail, bucketName, fileType)
},
handleAddConfirm() { handleAddConfirm() {
this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => { this.$refs.editFormRef.$refs[this.editChildRef].validate((valid) => {
if (valid) { if (valid) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!