Commit 2a72d262 by wangzhihui

阿里云上传

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