|
|
@@ -5,6 +5,7 @@ import type { PropType } from 'vue';
|
|
|
|
|
|
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
|
|
|
|
|
+import { useAppConfig } from '@vben/hooks';
|
|
|
import { useAccessStore } from '@vben/stores';
|
|
|
|
|
|
import { Button, message, Upload } from 'ant-design-vue';
|
|
|
@@ -12,17 +13,11 @@ import { Button, message, Upload } from 'ant-design-vue';
|
|
|
import { FileApi } from '#/api';
|
|
|
import { Icon } from '#/components/icon';
|
|
|
|
|
|
-type UploadParams = {
|
|
|
- allowSuffix: string;
|
|
|
- directory: string;
|
|
|
- folderId: Number | String;
|
|
|
- path: string;
|
|
|
-};
|
|
|
-
|
|
|
defineOptions({
|
|
|
name: 'Upload',
|
|
|
inheritAttrs: false,
|
|
|
});
|
|
|
+
|
|
|
const props = defineProps({
|
|
|
value: {
|
|
|
type: [Number, String] as PropType<number | string>,
|
|
|
@@ -31,7 +26,7 @@ const props = defineProps({
|
|
|
action: {
|
|
|
// 上传的地址
|
|
|
type: String,
|
|
|
- default: `${import.meta.env.VITE_GLOB_API_URL}/file/upload`,
|
|
|
+ default: '',
|
|
|
},
|
|
|
headers: {
|
|
|
// 上传请求的 headers
|
|
|
@@ -64,6 +59,14 @@ const props = defineProps({
|
|
|
},
|
|
|
});
|
|
|
const emits = defineEmits(['update:modelValue']);
|
|
|
+const { apiURL } = useAppConfig(import.meta.env, import.meta.env.PROD);
|
|
|
+type UploadParams = {
|
|
|
+ allowSuffix: string;
|
|
|
+ directory: string;
|
|
|
+ folderId: Number | String;
|
|
|
+ path: string;
|
|
|
+};
|
|
|
+
|
|
|
const accessStore = useAccessStore();
|
|
|
const fileList = ref<UploadFile[]>([]);
|
|
|
// const attrs = useAttrs();
|
|
|
@@ -74,6 +77,10 @@ const bindProps = computed(() => {
|
|
|
name: props.uploadName || 'file',
|
|
|
};
|
|
|
});
|
|
|
+
|
|
|
+const getAction = computed(() => {
|
|
|
+ return props.action ?? `${apiURL}/file/upload`;
|
|
|
+});
|
|
|
const getFileList = async (val: number | string | undefined) => {
|
|
|
if (!val) {
|
|
|
if (fileList.value.length > 0) fileList.value = [];
|
|
|
@@ -160,7 +167,7 @@ onMounted(async () => {
|
|
|
<Upload
|
|
|
v-model:file-list="fileList"
|
|
|
v-bind="bindProps"
|
|
|
- :action="action"
|
|
|
+ :action="getAction"
|
|
|
:data="uploadParams"
|
|
|
:disabled="disabled"
|
|
|
:headers="getHeaders"
|