chore: 优化上传组件

This commit is contained in:
AN 2025-04-27 21:14:44 +08:00
parent 63b49f1d40
commit 318abe92cf
2 changed files with 18 additions and 4 deletions

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { ref, useAttrs } from 'vue';
import { ref, useAttrs, watch } from 'vue';
import type { UploadFileInfo, UploadProps } from 'naive-ui';
import { fetchBatchDeleteOss } from '@/service/api/system/oss';
import { getToken } from '@/store/modules/auth/shared';
@ -31,6 +31,16 @@ const attrs: UploadProps = useAttrs();
let fileNum = 0;
const fileList = ref<UploadFileInfo[]>([]);
const needRelaodData = defineModel<boolean>('needRelaodData', {
default: false
});
watch(
() => fileList.value,
newValue => {
needRelaodData.value = newValue.length > 0;
}
);
const isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y';
const { baseURL } = getServiceBaseURL(import.meta.env, isHttpProxy);

View File

@ -1,5 +1,5 @@
<script setup lang="ts">
import { computed, watch } from 'vue';
import { computed, ref, watch } from 'vue';
defineOptions({
name: 'OssUploadModal'
@ -21,6 +21,8 @@ const visible = defineModel<boolean>('visible', {
default: false
});
const needRelaodData = ref<boolean>(false);
const accept = computed(() => {
return props.uploadType === 'file' ? '.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.pdf' : '.jpg,.jpeg,.png,.gif,.bmp,.webp';
});
@ -33,7 +35,9 @@ function closeDrawer() {
function handleClose() {
closeDrawer();
emit('close');
if (needRelaodData.value) {
emit('close');
}
}
watch(visible, () => {
@ -53,7 +57,7 @@ watch(visible, () => {
:bordered="false"
@after-leave="handleClose"
>
<FileUpload :upload-type="uploadType" :accept="accept" />
<FileUpload v-model:need-relaod-data="needRelaodData" :upload-type="uploadType" :accept="accept" />
</NModal>
</template>