feat: 自定义accept显示
This commit is contained in:
parent
60c398df39
commit
3655cae900
@ -56,7 +56,7 @@ const ossIdList = defineModel<string | string[]>('value', {
|
|||||||
|
|
||||||
const {
|
const {
|
||||||
customRequest,
|
customRequest,
|
||||||
acceptFormat,
|
acceptStr,
|
||||||
handleChange,
|
handleChange,
|
||||||
handleRemove,
|
handleRemove,
|
||||||
beforeUpload,
|
beforeUpload,
|
||||||
@ -117,7 +117,7 @@ const {
|
|||||||
class="text-primary mx-1 font-medium"
|
class="text-primary mx-1 font-medium"
|
||||||
:class="{ 'upload-text__disabled': disabled }"
|
:class="{ 'upload-text__disabled': disabled }"
|
||||||
>
|
>
|
||||||
{{ acceptFormat }}
|
{{ acceptStr }}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</I18nT>
|
</I18nT>
|
||||||
|
@ -15,7 +15,7 @@ import { computed, ref, watch } from 'vue';
|
|||||||
import { $t } from '@vben/locales';
|
import { $t } from '@vben/locales';
|
||||||
|
|
||||||
import { message, Modal } from 'ant-design-vue';
|
import { message, Modal } from 'ant-design-vue';
|
||||||
import { isFunction } from 'lodash-es';
|
import { isFunction, isString } from 'lodash-es';
|
||||||
|
|
||||||
import { ossInfo } from '#/api/system/oss';
|
import { ossInfo } from '#/api/system/oss';
|
||||||
|
|
||||||
@ -88,7 +88,16 @@ export function useUpload(
|
|||||||
// 组件内部维护fileList
|
// 组件内部维护fileList
|
||||||
const innerFileList = ref<UploadFile[]>([]);
|
const innerFileList = ref<UploadFile[]>([]);
|
||||||
|
|
||||||
const acceptFormat = computed(() => {
|
const acceptStr = computed(() => {
|
||||||
|
// string类型
|
||||||
|
if (isString(props.acceptFormat)) {
|
||||||
|
return props.acceptFormat;
|
||||||
|
}
|
||||||
|
// 函数类型
|
||||||
|
if (isFunction(props.acceptFormat)) {
|
||||||
|
return props.acceptFormat(props.accept!);
|
||||||
|
}
|
||||||
|
// 默认 会对拓展名做处理
|
||||||
return props.accept
|
return props.accept
|
||||||
?.split(',')
|
?.split(',')
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
@ -272,6 +281,6 @@ export function useUpload(
|
|||||||
beforeUpload,
|
beforeUpload,
|
||||||
customRequest,
|
customRequest,
|
||||||
innerFileList,
|
innerFileList,
|
||||||
acceptFormat,
|
acceptStr,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ const ossIdList = defineModel<string | string[]>('value', {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const {
|
const {
|
||||||
acceptFormat,
|
acceptStr,
|
||||||
handleChange,
|
handleChange,
|
||||||
handleRemove,
|
handleRemove,
|
||||||
beforeUpload,
|
beforeUpload,
|
||||||
@ -113,7 +113,7 @@ function currentPreview(file: UploadFile) {
|
|||||||
class="text-primary mx-1 font-medium"
|
class="text-primary mx-1 font-medium"
|
||||||
:class="{ 'upload-text__disabled': disabled }"
|
:class="{ 'upload-text__disabled': disabled }"
|
||||||
>
|
>
|
||||||
{{ acceptFormat }}
|
{{ acceptStr }}
|
||||||
</span>
|
</span>
|
||||||
</template>
|
</template>
|
||||||
</I18nT>
|
</I18nT>
|
||||||
|
@ -24,6 +24,11 @@ export interface BaseUploadProps {
|
|||||||
* 同antdv参数
|
* 同antdv参数
|
||||||
*/
|
*/
|
||||||
accept?: string;
|
accept?: string;
|
||||||
|
/**
|
||||||
|
* 你可能使用的是application/pdf这种mime类型, 但是这样用户可能看不懂, 在这里自定义逻辑
|
||||||
|
* @default 原始accept
|
||||||
|
*/
|
||||||
|
acceptFormat?: ((accept: string) => string) | string;
|
||||||
/**
|
/**
|
||||||
* 附带的请求参数
|
* 附带的请求参数
|
||||||
*/
|
*/
|
||||||
|
@ -20,6 +20,13 @@ function handlePreview(file: UploadFile) {
|
|||||||
maskClosable: true,
|
maskClosable: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function customAccept(accept: string) {
|
||||||
|
return accept
|
||||||
|
.split(',')
|
||||||
|
.map((str) => str.toUpperCase())
|
||||||
|
.join(',');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -82,12 +89,14 @@ function handlePreview(file: UploadFile) {
|
|||||||
当前绑定值: {{ multipleFileId }}
|
当前绑定值: {{ multipleFileId }}
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card title="图片禁用上传" size="small">
|
<Card title="禁用上传" size="small">
|
||||||
<ImageUpload :disabled="true" :max-count="3" :help-message="false" />
|
<ImageUpload :disabled="true" :max-count="3" :help-message="false" />
|
||||||
</Card>
|
<FileUpload
|
||||||
|
class="mt-3"
|
||||||
<Card title="文件禁用上传" size="small">
|
:disabled="true"
|
||||||
<FileUpload :disabled="true" :max-count="3" :help-message="false" />
|
:max-count="3"
|
||||||
|
:help-message="false"
|
||||||
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card title="文件夹上传/自定义helpMessage" size="small">
|
<Card title="文件夹上传/自定义helpMessage" size="small">
|
||||||
@ -101,7 +110,17 @@ function handlePreview(file: UploadFile) {
|
|||||||
<div>自定义helpMessage: {{ JSON.stringify(slotProps) }}</div>
|
<div>自定义helpMessage: {{ JSON.stringify(slotProps) }}</div>
|
||||||
</template>
|
</template>
|
||||||
</FileUpload>
|
</FileUpload>
|
||||||
当前绑定值: {{ multipleFileId }}
|
</Card>
|
||||||
|
|
||||||
|
<Card title="自定义accept显示" size="small">
|
||||||
|
<ImageUpload
|
||||||
|
v-model:value="singleImageId"
|
||||||
|
:accept-format="customAccept"
|
||||||
|
/>
|
||||||
|
<ImageUpload
|
||||||
|
v-model:value="singleImageId"
|
||||||
|
accept-format="自定义显示允许的文件类型"
|
||||||
|
/>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
</Page>
|
</Page>
|
||||||
|
Loading…
Reference in New Issue
Block a user