客户管理附件oss上传
This commit is contained in:
@@ -29,7 +29,7 @@
|
||||
<!-- 文件列表 -->
|
||||
<transition-group ref="uploadFileList" class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
|
||||
<li :key="file.uid" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList">
|
||||
<el-link :href="`${baseUrl}${file.url}`" underline="never" target="_blank">
|
||||
<el-link :href="resolveFileHref(file.url)" underline="never" target="_blank">
|
||||
<span class="el-icon-document"> {{ getFileName(file.name) }} </span>
|
||||
</el-link>
|
||||
<div class="ele-upload-list__item-content-action">
|
||||
@@ -200,6 +200,14 @@ function getFileName(name) {
|
||||
}
|
||||
}
|
||||
|
||||
// oss:// 存储的文件经后端鉴权接口转发下载,本地路径保持原样
|
||||
function resolveFileHref(url) {
|
||||
if (url && url.indexOf("oss://") === 0) {
|
||||
return `${baseUrl}/common/download/resource?resource=` + encodeURIComponent(url)
|
||||
}
|
||||
return `${baseUrl}${url}`
|
||||
}
|
||||
|
||||
// 对象转成指定字符串分隔
|
||||
function listToString(list, separator) {
|
||||
let strs = ""
|
||||
|
||||
@@ -116,7 +116,10 @@ watch(() => props.modelValue, val => {
|
||||
// 然后将数组转为对象数组
|
||||
fileList.value = list.map(item => {
|
||||
if (typeof item === "string") {
|
||||
if (item.indexOf(baseUrl) === -1 && !isExternal(item)) {
|
||||
if (item.indexOf("oss://") === 0) {
|
||||
// oss:// 存储标识:经后端鉴权接口转发预览,原值保留在 name 供回传
|
||||
item = { name: item, url: ossResourceUrl(item), oss: true }
|
||||
} else if (item.indexOf(baseUrl) === -1 && !isExternal(item)) {
|
||||
item = { name: baseUrl + item, url: baseUrl + item }
|
||||
} else {
|
||||
item = { name: item, url: item }
|
||||
@@ -173,7 +176,11 @@ function handleExceed() {
|
||||
// 上传成功回调
|
||||
function handleUploadSuccess(res, file) {
|
||||
if (res.code === 200) {
|
||||
uploadList.value.push({ name: res.fileName, url: res.fileName })
|
||||
if (res.fileName && res.fileName.indexOf("oss://") === 0) {
|
||||
uploadList.value.push({ name: res.fileName, url: ossResourceUrl(res.fileName), oss: true })
|
||||
} else {
|
||||
uploadList.value.push({ name: res.fileName, url: res.fileName })
|
||||
}
|
||||
uploadedSuccessfully()
|
||||
} else {
|
||||
number.value--
|
||||
@@ -217,13 +224,19 @@ function handlePictureCardPreview(file) {
|
||||
dialogVisible.value = true
|
||||
}
|
||||
|
||||
// oss:// 存储的图片经后端鉴权接口转发预览/下载
|
||||
function ossResourceUrl(key) {
|
||||
return baseUrl + "/common/download/resource?resource=" + encodeURIComponent(key)
|
||||
}
|
||||
|
||||
// 对象转成指定字符串分隔
|
||||
function listToString(list, separator) {
|
||||
let strs = ""
|
||||
separator = separator || ","
|
||||
for (let i in list) {
|
||||
if (undefined !== list[i].url && list[i].url.indexOf("blob:") !== 0) {
|
||||
strs += list[i].url.replace(baseUrl, "") + separator
|
||||
// oss:// 项回传原始存储标识,其余去掉 baseUrl 前缀
|
||||
strs += (list[i].oss ? list[i].name : list[i].url.replace(baseUrl, "")) + separator
|
||||
}
|
||||
}
|
||||
return strs != "" ? strs.substr(0, strs.length - 1) : ""
|
||||
|
||||
@@ -311,6 +311,7 @@
|
||||
:show-file-list="false"
|
||||
:action="uploadFileUrl"
|
||||
:headers="uploadHeaders"
|
||||
:data="{ module: 'customer' }"
|
||||
:before-upload="handleBeforeAttachmentUpload"
|
||||
:on-success="handleAttachmentUploadSuccess"
|
||||
:on-error="handleAttachmentUploadError"
|
||||
@@ -506,12 +507,12 @@
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="营业执照" prop="businessLicenseUrl">
|
||||
<image-upload v-model="companyForm.businessLicenseUrl" :limit="1" :size="5" />
|
||||
<image-upload v-model="companyForm.businessLicenseUrl" :limit="1" :size="5" :action="ossUploadAction" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="其他附件" prop="attachmentIds">
|
||||
<file-upload v-model="companyForm.attachmentIds" :limit="10" :size="50" accept=".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.zip,.rar" />
|
||||
<file-upload v-model="companyForm.attachmentIds" :limit="10" :size="50" accept=".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.zip,.rar" :action="ossUploadAction" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
@@ -905,7 +906,9 @@ function handleUserChange(uid, user, nameField) {
|
||||
|
||||
/* ---------------- 附件上传 ---------------- */
|
||||
const baseUrl = import.meta.env.VITE_APP_BASE_API
|
||||
const uploadFileUrl = ref(baseUrl + '/common/upload')
|
||||
const uploadFileUrl = ref(baseUrl + '/common/upload/oss')
|
||||
// OSS 上传端点(相对路径,组件内部会拼 VITE_APP_BASE_API)
|
||||
const ossUploadAction = '/common/upload/oss'
|
||||
const uploadHeaders = ref({ Authorization: 'Bearer ' + getToken() })
|
||||
const attachmentTypeOptions = ref([
|
||||
{ value: '0', label: '附件资料' },
|
||||
|
||||
@@ -726,6 +726,7 @@
|
||||
:show-file-list="false"
|
||||
:action="uploadFileUrl"
|
||||
:headers="uploadHeaders"
|
||||
:data="{ module: 'receipt' }"
|
||||
:before-upload="handleBeforeUpload"
|
||||
:on-success="handleUploadSuccess"
|
||||
:on-error="handleUploadError"
|
||||
@@ -2194,7 +2195,7 @@ watch(activeTab, (tab) => {
|
||||
})
|
||||
|
||||
/* ================= 附件上传 ================= */
|
||||
const uploadFileUrl = ref(baseUrl + "/common/upload")
|
||||
const uploadFileUrl = ref(baseUrl + "/common/upload/oss")
|
||||
const uploadHeaders = ref({ Authorization: "Bearer " + getToken() })
|
||||
const ATTACHMENT_SIZE_LIMIT = 50
|
||||
const ATTACHMENT_EXTENSIONS = ["pdf", "jpg", "jpeg", "png", "gif", "doc", "docx", "xls", "xlsx", "zip", "rar"]
|
||||
|
||||
@@ -275,6 +275,7 @@
|
||||
:show-file-list="false"
|
||||
:action="uploadFileUrl"
|
||||
:headers="uploadHeaders"
|
||||
:data="{ module: 'supplier' }"
|
||||
:before-upload="handleBeforeAttachmentUpload"
|
||||
:on-success="handleAttachmentUploadSuccess"
|
||||
:on-error="handleAttachmentUploadError"
|
||||
@@ -470,12 +471,12 @@
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="营业执照" prop="businessLicenseUrl">
|
||||
<image-upload v-model="companyForm.businessLicenseUrl" :limit="1" :size="5" />
|
||||
<image-upload v-model="companyForm.businessLicenseUrl" :limit="1" :size="5" :action="ossUploadAction" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
<el-form-item label="其他附件" prop="attachmentIds">
|
||||
<file-upload v-model="companyForm.attachmentIds" :limit="10" :size="50" accept=".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.zip,.rar" />
|
||||
<file-upload v-model="companyForm.attachmentIds" :limit="10" :size="50" accept=".pdf,.jpg,.jpeg,.png,.doc,.docx,.xls,.xlsx,.zip,.rar" :action="ossUploadAction" />
|
||||
</el-form-item>
|
||||
</el-col>
|
||||
<el-col :span="24">
|
||||
@@ -720,7 +721,9 @@ function handleUserChange(uid, user, nameField) {
|
||||
|
||||
/* ---------------- 附件上传 ---------------- */
|
||||
const baseUrl = import.meta.env.VITE_APP_BASE_API
|
||||
const uploadFileUrl = ref(baseUrl + '/common/upload')
|
||||
const uploadFileUrl = ref(baseUrl + '/common/upload/oss')
|
||||
// OSS 上传端点(相对路径,组件内部会拼 VITE_APP_BASE_API)
|
||||
const ossUploadAction = '/common/upload/oss'
|
||||
const uploadHeaders = ref({ Authorization: 'Bearer ' + getToken() })
|
||||
const attachmentTypeOptions = ref([
|
||||
{ value: '0', label: '附件资料' },
|
||||
|
||||
Reference in New Issue
Block a user