|
|
@@ -6,23 +6,27 @@ const props = withDefaults(
|
|
|
templateUrl?: string
|
|
|
templateName?: string
|
|
|
isAlertError?: boolean
|
|
|
+ showUpdateCheckbox?: boolean // 是否显示 更新复选框
|
|
|
accept?: string
|
|
|
headers?: any
|
|
|
title?: string
|
|
|
+ params?: object | (() => {})
|
|
|
appendToBody?: boolean
|
|
|
}>(),
|
|
|
{
|
|
|
title: "",
|
|
|
headers: () => {
|
|
|
return {
|
|
|
- Authorization: "Bearer " + getToken()
|
|
|
+ Authorization: "Bearer " + getToken(),
|
|
|
+ ClientId: import.meta.env.VITE_APP_CLIENT_ID
|
|
|
}
|
|
|
},
|
|
|
accept: ".xlsx, .xls",
|
|
|
templateUrl: "",
|
|
|
templateName: "",
|
|
|
isAlertError: true,
|
|
|
- appendToBody: true
|
|
|
+ appendToBody: true,
|
|
|
+ showUpdateCheckbox: false
|
|
|
}
|
|
|
)
|
|
|
const emits = defineEmits<{
|
|
|
@@ -34,19 +38,40 @@ const emits = defineEmits<{
|
|
|
}>()
|
|
|
const uploadModalRef = ref()
|
|
|
const uploadRef = ref()
|
|
|
-const uploadUpdateSupport = ref(true)
|
|
|
+const uploadUpdateSupport = ref(false)
|
|
|
const isUploading = ref(false)
|
|
|
const opts = ref<any>({})
|
|
|
+
|
|
|
+const url = computed(() => {
|
|
|
+ let queryParams = `?updateSupport=${uploadUpdateSupport.value}`
|
|
|
+ if (opts.value.params) {
|
|
|
+ const data =
|
|
|
+ typeof opts.value.params === "function"
|
|
|
+ ? opts.value.params()
|
|
|
+ : typeof opts.value.params === "object"
|
|
|
+ ? props.params
|
|
|
+ : {}
|
|
|
+ for (const key in data) {
|
|
|
+ if (data.hasOwnProperty(key)) {
|
|
|
+ queryParams += `&${key}=${data[key]}`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return `${opts.value.url}${queryParams}}`
|
|
|
+})
|
|
|
+
|
|
|
function submitUpload() {
|
|
|
uploadRef.value.submit()
|
|
|
emits("onConfirm")
|
|
|
}
|
|
|
+
|
|
|
/** 文件上传中处理 */
|
|
|
function handleFileUploadProgress(event: any, file: any, fileList: any) {
|
|
|
isUploading.value = true
|
|
|
message.loading()
|
|
|
emits("onProgress", event, file, fileList)
|
|
|
}
|
|
|
+
|
|
|
/** 文件上传成功处理 */
|
|
|
function handleFileSuccess(response: any, file: any, fileList: any) {
|
|
|
isUploading.value = false
|
|
|
@@ -63,7 +88,7 @@ function handleFileSuccess(response: any, file: any, fileList: any) {
|
|
|
}
|
|
|
function handleFileError(error: Error, file: any, fileList: any) {
|
|
|
message.closeLoading()
|
|
|
- if (opts.isAlertError) {
|
|
|
+ if (opts.value.isAlertError) {
|
|
|
message.msgError(error.message)
|
|
|
}
|
|
|
emits("onError", error, file, fileList)
|
|
|
@@ -99,7 +124,7 @@ defineExpose({ show })
|
|
|
:limit="1"
|
|
|
:accept="opts.accept"
|
|
|
:headers="opts.headers"
|
|
|
- :action="opts.url + '?updateSupport=' + uploadUpdateSupport"
|
|
|
+ :action="url"
|
|
|
:disabled="isUploading"
|
|
|
:on-progress="handleFileUploadProgress"
|
|
|
:on-success="handleFileSuccess"
|
|
|
@@ -114,7 +139,7 @@ defineExpose({ show })
|
|
|
<template #tip>
|
|
|
<div class="el-upload__tip text-center">
|
|
|
<div class="el-upload__tip">
|
|
|
- <el-checkbox v-model="uploadUpdateSupport" />
|
|
|
+ <el-checkbox v-if="opts.showUpdateCheckbox" v-model="uploadUpdateSupport" />
|
|
|
是否更新已经存在的数据
|
|
|
</div>
|
|
|
<span>仅允许导入{{ opts.accept }}格式文件。</span>
|