Commit 607bca32 by 前端

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

1 parent 5d844dc1
...@@ -21,7 +21,7 @@ ...@@ -21,7 +21,7 @@
"@sentry/tracing": "^7.3.0", "@sentry/tracing": "^7.3.0",
"@sentry/vue": "^7.3.0", "@sentry/vue": "^7.3.0",
"@sentry/webpack-plugin": "^1.18.9", "@sentry/webpack-plugin": "^1.18.9",
"ali-oss": "^6.20.0", "ali-oss": "^6.22.0",
"axios": "^0.18.0", "axios": "^0.18.0",
"better-scroll": "^1.15.2", "better-scroll": "^1.15.2",
"bignumber.js": "^9.1.1", "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 @@ ...@@ -76,7 +76,7 @@
<div class="footer"> <div class="footer">
<el-button @click="submitForm" <el-button @click="submitForm"
type="primary" type="primary"
:loading="$store.state.d2admin.loading.value">下一步</el-button> :loading="btLoading">下一步</el-button>
<el-button @click="routerBack">取消</el-button> <el-button @click="routerBack">取消</el-button>
</div> </div>
<div class="describe"> <div class="describe">
...@@ -115,6 +115,7 @@ import { deepClone } from "@/common/util" ...@@ -115,6 +115,7 @@ import { deepClone } from "@/common/util"
// import selectStoreDialog from "./components/selectStoreDialog" // import selectStoreDialog from "./components/selectStoreDialog"
import { teaching_supportTypeOpt } from '@/common/constants.js' import { teaching_supportTypeOpt } from '@/common/constants.js'
import { getImportTask, detailExcelImport, receiptImport } from '@api/theAssetData' import { getImportTask, detailExcelImport, receiptImport } from '@api/theAssetData'
import alyOss from '@/common/oss.js'
export default { export default {
name: "ImportOne", name: "ImportOne",
components: { components: {
...@@ -145,7 +146,8 @@ export default { ...@@ -145,7 +146,8 @@ export default {
storeTableData: [], storeTableData: [],
supportTypeOpt: deepClone(teaching_supportTypeOpt), supportTypeOpt: deepClone(teaching_supportTypeOpt),
// loadDivVisible: false // loadDivVisible: false
taskId: '' taskId: '',
btLoading: false
} }
}, },
computed: { computed: {
...@@ -198,6 +200,7 @@ export default { ...@@ -198,6 +200,7 @@ export default {
// 上传银行流水明细文件,转码为base64 // 上传银行流水明细文件,转码为base64
importDetailFile(e) { importDetailFile(e) {
this.btLoading = true
const fileName = e.target.files[0].name const fileName = e.target.files[0].name
if ( if (
!fileName.includes(".xlsx") && !fileName.includes(".xlsx") &&
...@@ -207,62 +210,76 @@ export default { ...@@ -207,62 +210,76 @@ export default {
message: "文件格式不支持上传", message: "文件格式不支持上传",
type: "error" type: "error"
}) })
this.btLoading = false
return false return false
} }
const size = e.target.files[0].size / 1024 / 1024 const size = e.target.files[0].size / 1024 / 1024
if (size < 100) { if (size < 100) {
this.$set(this.infoForm, "detailFileName", fileName) this.$set(this.infoForm, "detailFileName", fileName)
// // 转码base64 // // 转码base64
const reader = new FileReader() // const reader = new FileReader()
reader.readAsDataURL(e.target.files[0]) // reader.readAsDataURL(e.target.files[0])
reader.onload = (event) => { // reader.onload = (event) => {
const imgFile = event.target.result // const imgFile = event.target.result
const arrBase64 = imgFile.split(",") // const arrBase64 = imgFile.split(",")
// this.fileInfo = fileName.split('.')[fileName.split('.')?.length - 1] + '@' + arrBase64[1] // this.fileInfo = fileName.split('.')[fileName.split('.')?.length - 1] + '@' + arrBase64[1]
this.$set( // this.$set(
this.infoForm, // this.infoForm,
"detailFileInfo", // "detailFileInfo",
fileName.split(".")[ // fileName.split(".")[
fileName.split(".")?.length - 1 // fileName.split(".")?.length - 1
] + // ] +
"@" + // "@" +
arrBase64[1] // arrBase64[1]
) // )
document.getElementById("fileUpload-detail").value = "" this.$set(
this.handleDetailImport() this.infoForm,
} "detailFileInfo",
e.target.files[0]
)
document.getElementById("fileUpload-detail").value = ""
this.handleDetailImport()
// }
} else { } else {
this.notice.errorTips("上传文件不可超过10M") this.notice.errorTips("上传文件不可超过100M")
document.getElementById("fileUpload-detail").value = "" document.getElementById("fileUpload-detail").value = ""
this.btLoading = false
} }
}, },
handleDetailImport() { handleDetailImport() {
var params = { const bucketName = 'zzl-filerepostorypublic' // 桶名
file: this.infoForm.detailFileInfo, const file = this.infoForm.detailFileInfo
fileName: this.infoForm.detailFileName, const fileType = this.infoForm.detailFileName.substr(this.infoForm.detailFileName.lastIndexOf('.') + 1)
fileType: this.infoForm.detailFileName.substr(this.infoForm.detailFileName.lastIndexOf('.') + 1), alyOss.bucketUpload(
taskId: this.taskId file,
} (res) => {
detailExcelImport(params).then(res => { var params = {
console.log('res', res) fileUrl: res.aliyunAddress,
if (res) { fileName: res.attachment,
// // 异步处理文件上传 把id传入处理轮询 fileType: res.attachment.substr(res.attachment.lastIndexOf('.') + 1),
// const list = [...this.updateList, { taskId: this.taskId
// name: this.fileForm.fileName, }
// ifSuccess: false, detailExcelImport(params).then(res => {
// uuid: res, if (res) {
// type: 'upload' this.setTaskIdRefesh(this.taskId) // 导入成功时保存任务ID,用于轮询
// }] this.notice.okTips('上传成功')
}
// this.actionSetDownloadList({ list, type: 'updateList' }) this.btLoading = false
this.notice.okTips('上传成功') })
} },
}) (err) => {
console.log(err)
this.btLoading = false
},
bucketName,
fileType
)
}, },
// 上传回单文件,转码为base64 // 上传回单文件,转码为base64
importReceiptFile(e) { importReceiptFile(e) {
this.btLoading = true
const fileName = e.target.files[0].name const fileName = e.target.files[0].name
if ( if (
!fileName.includes(".rar") && !fileName.includes(".rar") &&
...@@ -273,49 +290,71 @@ export default { ...@@ -273,49 +290,71 @@ export default {
message: "文件格式不支持上传", message: "文件格式不支持上传",
type: "error" type: "error"
}) })
this.btLoading = true
return false return false
} }
const size = e.target.files[0].size / 1024 / 1024 const size = e.target.files[0].size / 1024 / 1024
if (size < 100) { if (size < 100) {
this.$set(this.infoForm, "receiptFileName", fileName) this.$set(this.infoForm, "receiptFileName", fileName)
// // 转码base64 // // 转码base64
const reader = new FileReader() // const reader = new FileReader()
reader.readAsDataURL(e.target.files[0]) // reader.readAsDataURL(e.target.files[0])
reader.onload = (event) => { // reader.onload = (event) => {
const imgFile = event.target.result // const imgFile = event.target.result
const arrBase64 = imgFile.split(",") // const arrBase64 = imgFile.split(",")
// this.fileInfo = e.target.files[0].name.split('.')[e.target.files[0].name.split('.')?.length - 1] + '@' + arrBase64[1] // this.fileInfo = e.target.files[0].name.split('.')[e.target.files[0].name.split('.')?.length - 1] + '@' + arrBase64[1]
this.$set( // this.$set(
this.infoForm, // this.infoForm,
"receiptFileInfo", // "receiptFileInfo",
fileName.split(".")[ // fileName.split(".")[
fileName.split(".")?.length - 1 // fileName.split(".")?.length - 1
] + // ] +
"@" + // "@" +
arrBase64[1] // arrBase64[1]
) // )
document.getElementById("fileUpload-receipt").value = "" this.$set(
this.handleReceiptImport() this.infoForm,
} "receiptFileInfo",
e.target.files[0]
)
document.getElementById("fileUpload-receipt").value = ""
this.handleReceiptImport()
// }
} else { } else {
this.notice.errorTips("上传文件不可超过10M") this.notice.errorTips("上传文件不可超过100M")
document.getElementById("fileUpload-receipt").value = "" document.getElementById("fileUpload-receipt").value = ""
this.btLoading = true
} }
}, },
handleReceiptImport() { handleReceiptImport() {
var params = { const bucketName = 'zzl-filerepostorypublic' // 桶名
file: this.infoForm.receiptFileInfo, const file = this.infoForm.receiptFileInfo
fileName: this.infoForm.receiptFileName, const fileType = this.infoForm.receiptFileName.substr(this.infoForm.receiptFileName.lastIndexOf('.') + 1)
fileType: this.infoForm.receiptFileName.substr(this.infoForm.receiptFileName.lastIndexOf('.') + 1), alyOss.bucketUpload(
taskId: this.taskId file,
} (res) => {
receiptImport(params).then(res => { var params = {
console.log('res', res) fileUrl: res.aliyunAddress,
if (res) { fileName: res.attachment,
this.notice.okTips('上传成功') 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() { validateForm() {
...@@ -355,13 +394,9 @@ export default { ...@@ -355,13 +394,9 @@ export default {
cancelButtonText: "取消", cancelButtonText: "取消",
beforeClose: (action, instance, done) => { beforeClose: (action, instance, done) => {
if (action === "confirm") { if (action === "confirm") {
// const query = {}
// query.taskId = this.taskId
this.setTaskIdRefesh(this.taskId)
this.close({ tagName: "/importDetailControl" }) this.close({ tagName: "/importDetailControl" })
this.$router.push({ this.$router.push({
name: "theAssetData" name: "theAssetData"
// query
}) })
done() done()
} else { } else {
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
共导入{{ taskInfo.receiptResultSuccessCount }}条回单,成功关联{{ receiptCount }}条,可通过筛选项查询具体数据。</p> 共导入{{ taskInfo.receiptResultSuccessCount }}条回单,成功关联{{ receiptCount }}条,可通过筛选项查询具体数据。</p>
<p class="describe-text-red" <p class="describe-text-red"
v-if="taskInfo.receiptResultSuccessCount != 0">* v-if="taskInfo.receiptResultSuccessCount != 0">*
注:回单成功关联数据,使用导入明细为基础二次匹配,因此列表筛选结果与提示数可能不一致,为正常情况 注:回单成功关联数据,使用导入明细为基础二次匹配,因此列表筛选结果与提示数可能不一致,为正常情况;手动上传回单时,需符合回单命名规则且为单文件。
</p> </p>
</div> </div>
<div class="footer"> <div class="footer">
...@@ -64,15 +64,15 @@ ...@@ -64,15 +64,15 @@
:has-page="false" :has-page="false"
:search-form="searchFormSearch" :search-form="searchFormSearch"
:table-params="tableParams"> :table-params="tableParams">
<div slot="postScriptHtml" <div slot="absHtml"
slot-scope="scope"> slot-scope="scope">
<span> <span>
<el-tooltip class="item" <el-tooltip class="item"
effect="dark" effect="dark"
:content="scope.scope.detail.postScript" :content="scope.scope.detail.abs"
placement="right"> placement="right">
<span> <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> </span>
</el-tooltip> </el-tooltip>
</span> </span>
...@@ -185,15 +185,15 @@ export default { ...@@ -185,15 +185,15 @@ export default {
optionsName: 'jdSyncOpt', optionsName: 'jdSyncOpt',
changeAttr: (value, targetItem) => { changeAttr: (value, targetItem) => {
console.log("value", value) console.log("value", value)
console.log("this.tableData", this.tableData)
// console.log("this.tableData_filter", this.tableData_filter)
console.log("this.allData", this.allData) console.log("this.allData", this.allData)
if (value == 0) { if (value == 0) {
this.tableData = this.allData.filter(item => !item.receipt) this.tableData = this.allData.filter(item => !item.receipt)
} else if (value == 1) { } else if (value == 1) {
this.tableData = this.allData.filter(item => item.receipt) 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, // getListApi: nbcbAccDetailPage,
...@@ -276,9 +276,9 @@ export default { ...@@ -276,9 +276,9 @@ export default {
} }
}, { }, {
label: '备注', label: '备注',
prop: 'postScript', prop: 'abs',
width: '200px', width: '200px',
addHtml: "postScriptHtml" addHtml: "absHtml"
}, { }, {
label: '关联状态', label: '关联状态',
prop: 'jdSync', prop: 'jdSync',
...@@ -382,13 +382,17 @@ export default { ...@@ -382,13 +382,17 @@ export default {
}, },
// 前端处理数据分页 // 前端处理数据分页
paginatedData() { paginatedData(filterData) {
this.total = this.allData.length this.total = this.allData.length
// this.total = this.tableData.length // this.total = this.tableData.length
// this.tableData_filter = deepClone(this.tableData) // 用来筛选数据的备份 // this.tableData_filter = deepClone(this.tableData) // 用来筛选数据的备份
const start = (this.page.currentPage - 1) * this.page.pageSize const start = (this.page.currentPage - 1) * this.page.pageSize
const end = start + 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('start', start)
console.log('end', end) console.log('end', end)
console.log('this.tableData', this.tableData) console.log('this.tableData', this.tableData)
......
...@@ -482,7 +482,7 @@ export default { ...@@ -482,7 +482,7 @@ export default {
taskStatus: { taskStatus: {
handler(newVal) { handler(newVal) {
console.log('newVal', newVal) console.log('newVal', newVal)
if (newVal == 1 || newVal == 2) { // 任务失败或者成功时代表解析已完成,应该停止轮询 if (newVal == 1 || newVal == 2 || newVal == 3) { // 任务失败、成功、过期时,应该停止轮询
this.stopPolling() this.stopPolling()
} }
if (newVal == 2 || newVal == 3) { // 任务失败或者过期时,应销毁任务ID,结束此次任务 if (newVal == 2 || newVal == 3) { // 任务失败或者过期时,应销毁任务ID,结束此次任务
...@@ -797,6 +797,7 @@ export default { ...@@ -797,6 +797,7 @@ export default {
this.printForm.usage = this.usageList[0].confId this.printForm.usage = this.usageList[0].confId
}, },
// 批量打印
handleBatchPrint() { handleBatchPrint() {
var selectedData = [] var selectedData = []
if (this.$refs.recordTable.mutiSelectArr.transferAccounts) { if (this.$refs.recordTable.mutiSelectArr.transferAccounts) {
...@@ -817,9 +818,10 @@ export default { ...@@ -817,9 +818,10 @@ export default {
}, },
handlePrintConfirm() { handlePrintConfirm() {
let params = deepClone(this.printForm) let params = deepClone(this.printForm)
params.detailIds = this.printIds
if (this.printIds.length == 0) { if (this.printIds.length == 0) {
params = { ...params, ...deepClone(this.searchFormSearch) } params = { ...params, ...deepClone(this.searchFormSearch) }
} else {
params.detailIds = this.printIds
} }
// return console.log('params', params) // return console.log('params', params)
batchPrinting(params).then(res => { batchPrinting(params).then(res => {
......
...@@ -33,10 +33,8 @@ ...@@ -33,10 +33,8 @@
<el-input v-model="infoForm[item.controlId]" <el-input v-model="infoForm[item.controlId]"
type="textarea" type="textarea"
rows="4" rows="4"
maxlength="200"
placeholder="请输入" placeholder="请输入"
:style="{ width: formDefaultObj.defaultWidth }" :style="{ width: formDefaultObj.defaultWidth }"
show-word-limit
clearable /> clearable />
</template> </template>
<template v-else-if="item.inputType == 3 || item.inputType == 4"> <template v-else-if="item.inputType == 3 || item.inputType == 4">
......
...@@ -38,6 +38,7 @@ const isDev = process.env.NODE_ENV !== "development" ...@@ -38,6 +38,7 @@ const isDev = process.env.NODE_ENV !== "development"
// 基础路径 注意发布之前要先修改这里 // 基础路径 注意发布之前要先修改这里
// const publicPath = '/dj-carlife-web/' // const publicPath = '/dj-carlife-web/'
const publicPath = process.env.VUE_APP_PUBLIC_PATH const publicPath = process.env.VUE_APP_PUBLIC_PATH
// const publicPath = "/dj-carlife-web-wangql/"
// const publicPath = '/' // const publicPath = '/'
// const CDN_DOMAIN = 'https://cdn.bootcss.com' // const CDN_DOMAIN = 'https://cdn.bootcss.com'
const CDN_DOMAIN = "https://img02.glsx.com.cn/dj-carlife-web" 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!