feat: image upload
This commit is contained in:
parent
19b6b2c325
commit
93912efc67
51
apps/web-antd/src/views/system/oss/image-upload-modal.vue
Normal file
51
apps/web-antd/src/views/system/oss/image-upload-modal.vue
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import { computed, ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { Alert } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { ImageUpload } from '#/components/upload';
|
||||||
|
|
||||||
|
const emit = defineEmits<{ reload: [] }>();
|
||||||
|
|
||||||
|
const fileList = ref<string[]>([]);
|
||||||
|
const [BasicModal, modalApi] = useVbenModal({
|
||||||
|
onOpenChange: (isOpen) => {
|
||||||
|
if (isOpen) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (fileList.value.length > 0) {
|
||||||
|
fileList.value = [];
|
||||||
|
emit('reload');
|
||||||
|
modalApi.close();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
const accept = ref(['jpg', 'jpeg', 'png', 'gif', 'webp']);
|
||||||
|
const maxNumber = ref(3);
|
||||||
|
|
||||||
|
const message = computed(() => {
|
||||||
|
return `支持 [${accept.value.join(', ')}] 格式,最多上传 ${maxNumber.value} 张图片`;
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<BasicModal
|
||||||
|
:close-on-click-modal="false"
|
||||||
|
:footer="false"
|
||||||
|
:fullscreen-button="false"
|
||||||
|
title="图片上传"
|
||||||
|
>
|
||||||
|
<div class="flex flex-col gap-4">
|
||||||
|
<Alert :message="message" show-icon type="info">aaa</Alert>
|
||||||
|
<ImageUpload
|
||||||
|
v-model:value="fileList"
|
||||||
|
:accept="accept"
|
||||||
|
:max-number="maxNumber"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</BasicModal>
|
||||||
|
</template>
|
@ -4,7 +4,7 @@ import type { Recordable } from '@vben/types';
|
|||||||
import { onMounted, ref } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { useRouter } from 'vue-router';
|
import { useRouter } from 'vue-router';
|
||||||
|
|
||||||
import { Page, type VbenFormProps } from '@vben/common-ui';
|
import { Page, useVbenModal, type VbenFormProps } from '@vben/common-ui';
|
||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
import { getPopupContainer } from '@vben/utils';
|
import { getPopupContainer } from '@vben/utils';
|
||||||
|
|
||||||
@ -26,6 +26,7 @@ import { ossDownload, ossList, ossRemove } from '#/api/system/oss';
|
|||||||
import { downloadByData } from '#/utils/file/download';
|
import { downloadByData } from '#/utils/file/download';
|
||||||
|
|
||||||
import { columns, querySchema } from './data';
|
import { columns, querySchema } from './data';
|
||||||
|
import imageUploadModal from './image-upload-modal.vue';
|
||||||
|
|
||||||
const formOptions: VbenFormProps = {
|
const formOptions: VbenFormProps = {
|
||||||
commonConfig: {
|
commonConfig: {
|
||||||
@ -153,6 +154,9 @@ function isImageFile(ext: string) {
|
|||||||
const supportList = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
const supportList = ['jpg', 'jpeg', 'png', 'gif', 'webp'];
|
||||||
return supportList.some((item) => ext.toLocaleLowerCase().includes(item));
|
return supportList.some((item) => ext.toLocaleLowerCase().includes(item));
|
||||||
}
|
}
|
||||||
|
const [ImageUploadModal, imageUploadApi] = useVbenModal({
|
||||||
|
connectedComponent: imageUploadModal,
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -181,7 +185,12 @@ function isImageFile(ext: string) {
|
|||||||
>
|
>
|
||||||
{{ $t('pages.common.delete') }}
|
{{ $t('pages.common.delete') }}
|
||||||
</a-button>
|
</a-button>
|
||||||
<a-button v-access:code="['system:oss:upload']"> 上传 没做 </a-button>
|
<a-button
|
||||||
|
v-access:code="['system:oss:upload']"
|
||||||
|
@click="imageUploadApi.open"
|
||||||
|
>
|
||||||
|
图片上传
|
||||||
|
</a-button>
|
||||||
</Space>
|
</Space>
|
||||||
</template>
|
</template>
|
||||||
<template #url="{ row }">
|
<template #url="{ row }">
|
||||||
@ -217,5 +226,6 @@ function isImageFile(ext: string) {
|
|||||||
</Space>
|
</Space>
|
||||||
</template>
|
</template>
|
||||||
</BasicTable>
|
</BasicTable>
|
||||||
|
<ImageUploadModal @reload="tableApi.query" />
|
||||||
</Page>
|
</Page>
|
||||||
</template>
|
</template>
|
||||||
|
Loading…
Reference in New Issue
Block a user