chore: 优化上传组件
This commit is contained in:
parent
63b49f1d40
commit
318abe92cf
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, useAttrs } from 'vue';
|
import { ref, useAttrs, watch } from 'vue';
|
||||||
import type { UploadFileInfo, UploadProps } from 'naive-ui';
|
import type { UploadFileInfo, UploadProps } from 'naive-ui';
|
||||||
import { fetchBatchDeleteOss } from '@/service/api/system/oss';
|
import { fetchBatchDeleteOss } from '@/service/api/system/oss';
|
||||||
import { getToken } from '@/store/modules/auth/shared';
|
import { getToken } from '@/store/modules/auth/shared';
|
||||||
@ -31,6 +31,16 @@ const attrs: UploadProps = useAttrs();
|
|||||||
|
|
||||||
let fileNum = 0;
|
let fileNum = 0;
|
||||||
const fileList = ref<UploadFileInfo[]>([]);
|
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 isHttpProxy = import.meta.env.DEV && import.meta.env.VITE_HTTP_PROXY === 'Y';
|
||||||
const { baseURL } = getServiceBaseURL(import.meta.env, isHttpProxy);
|
const { baseURL } = getServiceBaseURL(import.meta.env, isHttpProxy);
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { computed, watch } from 'vue';
|
import { computed, ref, watch } from 'vue';
|
||||||
|
|
||||||
defineOptions({
|
defineOptions({
|
||||||
name: 'OssUploadModal'
|
name: 'OssUploadModal'
|
||||||
@ -21,6 +21,8 @@ const visible = defineModel<boolean>('visible', {
|
|||||||
default: false
|
default: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const needRelaodData = ref<boolean>(false);
|
||||||
|
|
||||||
const accept = computed(() => {
|
const accept = computed(() => {
|
||||||
return props.uploadType === 'file' ? '.doc,.docx,.xls,.xlsx,.ppt,.pptx,.txt,.pdf' : '.jpg,.jpeg,.png,.gif,.bmp,.webp';
|
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() {
|
function handleClose() {
|
||||||
closeDrawer();
|
closeDrawer();
|
||||||
emit('close');
|
if (needRelaodData.value) {
|
||||||
|
emit('close');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(visible, () => {
|
watch(visible, () => {
|
||||||
@ -53,7 +57,7 @@ watch(visible, () => {
|
|||||||
:bordered="false"
|
:bordered="false"
|
||||||
@after-leave="handleClose"
|
@after-leave="handleClose"
|
||||||
>
|
>
|
||||||
<FileUpload :upload-type="uploadType" :accept="accept" />
|
<FileUpload v-model:need-relaod-data="needRelaodData" :upload-type="uploadType" :accept="accept" />
|
||||||
</NModal>
|
</NModal>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user