Commit 607bca32 by 前端

BUG修复以及修改文件上传方式为阿里云OSS上传

1 parent 5d844dc1
......@@ -21,7 +21,7 @@
"@sentry/tracing": "^7.3.0",
"@sentry/vue": "^7.3.0",
"@sentry/webpack-plugin": "^1.18.9",
"ali-oss": "^6.20.0",
"ali-oss": "^6.22.0",
"axios": "^0.18.0",
"better-scroll": "^1.15.2",
"bignumber.js": "^9.1.1",
......
import { baseConfig } from "@/main"
const OSS = require("ali-oss")
export default {
/**
* 阿里云oss sdk文件上传 dir 上传到的文件位置
* @param {*} file 文件流
* @param {*} successCallback 成功回调
* @param {*} errCallBack 失败回调
* @param {*} bucketName 阿里云桶名(可以指定多个桶名)
* @param {*} dir 上传文件夹路径 譬如images
*/
bucketUpload(
file,
successCallback = new Function(),
errCallBack = new Function(),
bucketName = "zzl-filerepostorypublic",
dir = "image"
) {
const fileName = file.name // 先获取上传要的资料签名
// 实例化一个上传客户端
const client = new OSS({
// yourRegion填写Bucket所在地域。Region填写为oss-cn-hangzhou。
// region: "oss-cn-beijing", //我的存储是北京,可根据具体配置自行修改
// region: "oss-cn-shanghai",
// 从STS服务获取的临时访问密钥(AccessKey ID和AccessKey Secret)。)(后台接口返回)
accessKeyId: baseConfig.alyOss.accessKeyId,
accessKeySecret: baseConfig.alyOss.accessKeySecret,
// 从STS服务获取的安全令牌(SecurityToken)。
// stsToken: obj.securityToken,
// 填写Bucket名称。
bucket: baseConfig.alyOss.bucket,
endpoint: baseConfig.alyOss.endpoint
})
try {
// 为保证唯一性,可以通过uuid将文件名替换
// let uuid = uuidv4() + fileName.substring(fileName.lastIndexOf('.'))if (dir.substring(dir.length - 1, 1) !== '/') {
dir += "/"
const result = client.put(dir + fileName, file)
result
.then((res) => {
console.log(res, "返回文件名和文件地址")
const size =
file.size > 1000000
? parseFloat(file.size / 1000000).toFixed(2) + "M"
: parseFloat(file.size / 1000).toFixed(2) + "KB"
successCallback({
attachment: fileName,
aliyunAddress: res.url,
size: size
})
})
.catch((err) => {
errCallBack(err)
})
} catch (e) {
console.log(e)
}
}
}
......@@ -76,7 +76,7 @@
<div class="footer">
<el-button @click="submitForm"
type="primary"
:loading="$store.state.d2admin.loading.value">下一步</el-button>
:loading="btLoading">下一步</el-button>
<el-button @click="routerBack">取消</el-button>
</div>
<div class="describe">
......@@ -115,6 +115,7 @@ import { deepClone } from "@/common/util"
// import selectStoreDialog from "./components/selectStoreDialog"
import { teaching_supportTypeOpt } from '@/common/constants.js'
import { getImportTask, detailExcelImport, receiptImport } from '@api/theAssetData'
import alyOss from '@/common/oss.js'
export default {
name: "ImportOne",
components: {
......@@ -145,7 +146,8 @@ export default {
storeTableData: [],
supportTypeOpt: deepClone(teaching_supportTypeOpt),
// loadDivVisible: false
taskId: ''
taskId: '',
btLoading: false
}
},
computed: {
......@@ -198,6 +200,7 @@ export default {
// 上传银行流水明细文件,转码为base64
importDetailFile(e) {
this.btLoading = true
const fileName = e.target.files[0].name
if (
!fileName.includes(".xlsx") &&
......@@ -207,62 +210,76 @@ export default {
message: "文件格式不支持上传",
type: "error"
})
this.btLoading = false
return false
}
const size = e.target.files[0].size / 1024 / 1024
if (size < 100) {
this.$set(this.infoForm, "detailFileName", fileName)
// // 转码base64
const reader = new FileReader()
reader.readAsDataURL(e.target.files[0])
reader.onload = (event) => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(",")
// this.fileInfo = fileName.split('.')[fileName.split('.')?.length - 1] + '@' + arrBase64[1]
this.$set(
this.infoForm,
"detailFileInfo",
fileName.split(".")[
fileName.split(".")?.length - 1
] +
"@" +
arrBase64[1]
)
document.getElementById("fileUpload-detail").value = ""
this.handleDetailImport()
}
// const reader = new FileReader()
// reader.readAsDataURL(e.target.files[0])
// reader.onload = (event) => {
// const imgFile = event.target.result
// const arrBase64 = imgFile.split(",")
// this.fileInfo = fileName.split('.')[fileName.split('.')?.length - 1] + '@' + arrBase64[1]
// this.$set(
// this.infoForm,
// "detailFileInfo",
// fileName.split(".")[
// fileName.split(".")?.length - 1
// ] +
// "@" +
// arrBase64[1]
// )
this.$set(
this.infoForm,
"detailFileInfo",
e.target.files[0]
)
document.getElementById("fileUpload-detail").value = ""
this.handleDetailImport()
// }
} else {
this.notice.errorTips("上传文件不可超过10M")
this.notice.errorTips("上传文件不可超过100M")
document.getElementById("fileUpload-detail").value = ""
this.btLoading = false
}
},
handleDetailImport() {
var params = {
file: this.infoForm.detailFileInfo,
fileName: this.infoForm.detailFileName,
fileType: this.infoForm.detailFileName.substr(this.infoForm.detailFileName.lastIndexOf('.') + 1),
taskId: this.taskId
}
detailExcelImport(params).then(res => {
console.log('res', res)
if (res) {
// // 异步处理文件上传 把id传入处理轮询
// const list = [...this.updateList, {
// name: this.fileForm.fileName,
// ifSuccess: false,
// uuid: res,
// type: 'upload'
// }]
// this.actionSetDownloadList({ list, type: 'updateList' })
this.notice.okTips('上传成功')
}
})
const bucketName = 'zzl-filerepostorypublic' // 桶名
const file = this.infoForm.detailFileInfo
const fileType = this.infoForm.detailFileName.substr(this.infoForm.detailFileName.lastIndexOf('.') + 1)
alyOss.bucketUpload(
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
)
},
// 上传回单文件,转码为base64
importReceiptFile(e) {
this.btLoading = true
const fileName = e.target.files[0].name
if (
!fileName.includes(".rar") &&
......@@ -273,49 +290,71 @@ export default {
message: "文件格式不支持上传",
type: "error"
})
this.btLoading = true
return false
}
const size = e.target.files[0].size / 1024 / 1024
if (size < 100) {
this.$set(this.infoForm, "receiptFileName", fileName)
// // 转码base64
const reader = new FileReader()
reader.readAsDataURL(e.target.files[0])
reader.onload = (event) => {
const imgFile = event.target.result
const arrBase64 = imgFile.split(",")
// this.fileInfo = e.target.files[0].name.split('.')[e.target.files[0].name.split('.')?.length - 1] + '@' + arrBase64[1]
this.$set(
this.infoForm,
"receiptFileInfo",
fileName.split(".")[
fileName.split(".")?.length - 1
] +
"@" +
arrBase64[1]
)
document.getElementById("fileUpload-receipt").value = ""
this.handleReceiptImport()
}
// const reader = new FileReader()
// reader.readAsDataURL(e.target.files[0])
// reader.onload = (event) => {
// const imgFile = event.target.result
// const arrBase64 = imgFile.split(",")
// this.fileInfo = e.target.files[0].name.split('.')[e.target.files[0].name.split('.')?.length - 1] + '@' + arrBase64[1]
// this.$set(
// this.infoForm,
// "receiptFileInfo",
// fileName.split(".")[
// fileName.split(".")?.length - 1
// ] +
// "@" +
// arrBase64[1]
// )
this.$set(
this.infoForm,
"receiptFileInfo",
e.target.files[0]
)
document.getElementById("fileUpload-receipt").value = ""
this.handleReceiptImport()
// }
} else {
this.notice.errorTips("上传文件不可超过10M")
this.notice.errorTips("上传文件不可超过100M")
document.getElementById("fileUpload-receipt").value = ""
this.btLoading = true
}
},
handleReceiptImport() {
var params = {
file: this.infoForm.receiptFileInfo,
fileName: this.infoForm.receiptFileName,
fileType: this.infoForm.receiptFileName.substr(this.infoForm.receiptFileName.lastIndexOf('.') + 1),
taskId: this.taskId
}
receiptImport(params).then(res => {
console.log('res', res)
if (res) {
this.notice.okTips('上传成功')
}
})
const bucketName = 'zzl-filerepostorypublic' // 桶名
const file = this.infoForm.receiptFileInfo
const fileType = this.infoForm.receiptFileName.substr(this.infoForm.receiptFileName.lastIndexOf('.') + 1)
alyOss.bucketUpload(
file,
(res) => {
var params = {
fileUrl: res.aliyunAddress,
fileName: res.attachment,
fileType: res.attachment.substr(res.attachment.lastIndexOf('.') + 1),
taskId: this.taskId
}
receiptImport(params).then(res => {
console.log('res', res)
if (res) {
this.notice.okTips('上传成功')
}
this.btLoading = false
})
},
(err) => {
console.log(err)
this.btLoading = false
},
bucketName,
fileType
)
},
validateForm() {
......@@ -355,13 +394,9 @@ export default {
cancelButtonText: "取消",
beforeClose: (action, instance, done) => {
if (action === "confirm") {
// const query = {}
// query.taskId = this.taskId
this.setTaskIdRefesh(this.taskId)
this.close({ tagName: "/importDetailControl" })
this.$router.push({
name: "theAssetData"
// query
})
done()
} else {
......
......@@ -19,7 +19,7 @@
共导入{{ taskInfo.receiptResultSuccessCount }}条回单,成功关联{{ receiptCount }}条,可通过筛选项查询具体数据。</p>
<p class="describe-text-red"
v-if="taskInfo.receiptResultSuccessCount != 0">*
注:回单成功关联数据,使用导入明细为基础二次匹配,因此列表筛选结果与提示数可能不一致,为正常情况
注:回单成功关联数据,使用导入明细为基础二次匹配,因此列表筛选结果与提示数可能不一致,为正常情况;手动上传回单时,需符合回单命名规则且为单文件。
</p>
</div>
<div class="footer">
......@@ -64,15 +64,15 @@
:has-page="false"
:search-form="searchFormSearch"
:table-params="tableParams">
<div slot="postScriptHtml"
<div slot="absHtml"
slot-scope="scope">
<span>
<el-tooltip class="item"
effect="dark"
:content="scope.scope.detail.postScript"
:content="scope.scope.detail.abs"
placement="right">
<span>
{{ scope.scope.detail.postScript ? (scope.scope.detail.postScript.length > 15 ? (scope.scope.detail.postScript.slice(0, 15) + '...') : scope.scope.detail.postScript) : '' }}
{{ scope.scope.detail.abs ? (scope.scope.detail.abs.length > 15 ? (scope.scope.detail.abs.slice(0, 15) + '...') : scope.scope.detail.abs) : '' }}
</span>
</el-tooltip>
</span>
......@@ -185,15 +185,15 @@ export default {
optionsName: 'jdSyncOpt',
changeAttr: (value, targetItem) => {
console.log("value", value)
console.log("this.tableData", this.tableData)
// console.log("this.tableData_filter", this.tableData_filter)
console.log("this.allData", this.allData)
if (value == 0) {
this.tableData = this.allData.filter(item => !item.receipt)
} else if (value == 1) {
this.tableData = this.allData.filter(item => item.receipt)
}
this.total = this.tableData.length
console.log("this.tableData", this.tableData)
// this.total = this.tableData.length
this.paginatedData(this.tableData) // 重新计算分页数据
}
}],
// getListApi: nbcbAccDetailPage,
......@@ -276,9 +276,9 @@ export default {
}
}, {
label: '备注',
prop: 'postScript',
prop: 'abs',
width: '200px',
addHtml: "postScriptHtml"
addHtml: "absHtml"
}, {
label: '关联状态',
prop: 'jdSync',
......@@ -382,13 +382,17 @@ export default {
},
// 前端处理数据分页
paginatedData() {
paginatedData(filterData) {
this.total = this.allData.length
// this.total = this.tableData.length
// this.tableData_filter = deepClone(this.tableData) // 用来筛选数据的备份
const start = (this.page.currentPage - 1) * this.page.pageSize
const end = start + this.page.pageSize
this.tableData = this.allData.slice(start, end)
if (filterData) {
this.tableData = filterData.slice(start, end)
} else {
this.tableData = this.allData.slice(start, end)
}
console.log('start', start)
console.log('end', end)
console.log('this.tableData', this.tableData)
......
......@@ -482,7 +482,7 @@ export default {
taskStatus: {
handler(newVal) {
console.log('newVal', newVal)
if (newVal == 1 || newVal == 2) { // 任务失败或者成功时代表解析已完成,应该停止轮询
if (newVal == 1 || newVal == 2 || newVal == 3) { // 任务失败、成功、过期时,应该停止轮询
this.stopPolling()
}
if (newVal == 2 || newVal == 3) { // 任务失败或者过期时,应销毁任务ID,结束此次任务
......@@ -797,6 +797,7 @@ export default {
this.printForm.usage = this.usageList[0].confId
},
// 批量打印
handleBatchPrint() {
var selectedData = []
if (this.$refs.recordTable.mutiSelectArr.transferAccounts) {
......@@ -817,9 +818,10 @@ export default {
},
handlePrintConfirm() {
let params = deepClone(this.printForm)
params.detailIds = this.printIds
if (this.printIds.length == 0) {
params = { ...params, ...deepClone(this.searchFormSearch) }
} else {
params.detailIds = this.printIds
}
// return console.log('params', params)
batchPrinting(params).then(res => {
......
......@@ -33,10 +33,8 @@
<el-input v-model="infoForm[item.controlId]"
type="textarea"
rows="4"
maxlength="200"
placeholder="请输入"
:style="{ width: formDefaultObj.defaultWidth }"
show-word-limit
clearable />
</template>
<template v-else-if="item.inputType == 3 || item.inputType == 4">
......
......@@ -38,6 +38,7 @@ const isDev = process.env.NODE_ENV !== "development"
// 基础路径 注意发布之前要先修改这里
// const publicPath = '/dj-carlife-web/'
const publicPath = process.env.VUE_APP_PUBLIC_PATH
// const publicPath = "/dj-carlife-web-wangql/"
// const publicPath = '/'
// const CDN_DOMAIN = 'https://cdn.bootcss.com'
const CDN_DOMAIN = "https://img02.glsx.com.cn/dj-carlife-web"
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!