|
|
@@ -7,11 +7,51 @@ import { toast } from 'vue-sonner'
|
|
|
import { BASE_URL } from '@/api/index'
|
|
|
|
|
|
|
|
|
-const props = defineProps<{
|
|
|
- // 外部传入的 "当前文件",可以是单个 UploadFile 对象,或 null,或 undefined
|
|
|
- 'modelValue'?: UploadFile | null | undefined
|
|
|
- // 添加其他 props...
|
|
|
-}>()
|
|
|
+
|
|
|
+
|
|
|
+const props = withDefaults(defineProps<{
|
|
|
+ modelValue?: UploadFile | null | undefined
|
|
|
+ action?: string
|
|
|
+ method?: string
|
|
|
+ headers?: Headers | Record<string, any>
|
|
|
+ data?: Record<string, any>
|
|
|
+
|
|
|
+ name?: string
|
|
|
+ afterUpload?: (response: any) => string | Promise<string>
|
|
|
+ multiple?: boolean
|
|
|
+ ext?: string[]
|
|
|
+ max?: number
|
|
|
+ width?: number
|
|
|
+ height?: number
|
|
|
+ dimension?: {
|
|
|
+ width: number
|
|
|
+ height: number
|
|
|
+ }
|
|
|
+ size?: number
|
|
|
+ hideTips?: boolean
|
|
|
+ disabled?: boolean
|
|
|
+}>(), {
|
|
|
+ method: 'post',
|
|
|
+ headers: () => {
|
|
|
+ const userStore = useUserStore()
|
|
|
+ if (userStore.isLogin) {
|
|
|
+ return {
|
|
|
+ accessToken: userStore.token
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return {}
|
|
|
+ },
|
|
|
+ data: () => ({}),
|
|
|
+ name: 'file',
|
|
|
+ multiple: false,
|
|
|
+ ext: () => [],
|
|
|
+ max: 1,
|
|
|
+ width: 100,
|
|
|
+ height: 100,
|
|
|
+ size: 5 * 1024 * 1024,
|
|
|
+ hideTips: false,
|
|
|
+ disabled: false,
|
|
|
+})
|
|
|
|
|
|
|
|
|
const emit = defineEmits<{
|
|
|
@@ -42,6 +82,7 @@ watch(
|
|
|
const loading = ref(false)
|
|
|
|
|
|
|
|
|
+
|
|
|
function handleUploadSuccess(response: any, uploadFile: UploadFile, uploadFiles: UploadFiles) {
|
|
|
console.log('【上传成功】响应:', response)
|
|
|
console.log('【上传成功】文件对象:', uploadFile) // 这是最新的文件对象 (包含 url 等)
|
|
|
@@ -83,6 +124,7 @@ function handleFileChange(file: UploadFile, fileList: UploadFiles) {
|
|
|
:action="`${BASE_URL}/anycall/import`"
|
|
|
:show-file-list="false"
|
|
|
:limit="1"
|
|
|
+ :headers="props.headers"
|
|
|
@success="handleUploadSuccess"
|
|
|
@progress="handleProgress"
|
|
|
@change="handleFileChange"
|