parent
55ae01c536
commit
41fda26248
@ -0,0 +1 @@
|
||||
export { default as ImageUpload } from './src/image-upload.vue';
|
||||
@ -0,0 +1,32 @@
|
||||
export function checkFileType(file: File, accepts: string[]) {
|
||||
let reg;
|
||||
if (!accepts || accepts.length === 0) {
|
||||
reg = /.(?:jpg|jpeg|png|gif|webp)$/i;
|
||||
} else {
|
||||
const newTypes = accepts.join('|');
|
||||
reg = new RegExp(`${String.raw`\.(` + newTypes})$`, 'i');
|
||||
}
|
||||
return reg.test(file.name);
|
||||
}
|
||||
|
||||
export function checkImgType(file: File) {
|
||||
return isImgTypeByName(file.name);
|
||||
}
|
||||
|
||||
export function isImgTypeByName(name: string) {
|
||||
return /\.(?:jpg|jpeg|png|gif|webp)$/i.test(name);
|
||||
}
|
||||
|
||||
export function getBase64WithFile(file: File) {
|
||||
return new Promise<{
|
||||
file: File;
|
||||
result: string;
|
||||
}>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
reader.addEventListener('load', () =>
|
||||
resolve({ result: reader.result as string, file }),
|
||||
);
|
||||
reader.addEventListener('error', (error) => reject(error));
|
||||
});
|
||||
}
|
||||
@ -0,0 +1,37 @@
|
||||
import type { Recordable } from '@vben/types';
|
||||
|
||||
export enum UploadResultStatus {
|
||||
DONE = 'done',
|
||||
ERROR = 'error',
|
||||
SUCCESS = 'success',
|
||||
UPLOADING = 'uploading',
|
||||
}
|
||||
|
||||
export interface FileItem {
|
||||
thumbUrl?: string;
|
||||
name: string;
|
||||
size: number | string;
|
||||
type?: string;
|
||||
percent: number;
|
||||
file: File;
|
||||
status?: UploadResultStatus;
|
||||
response?: { fileName: string; ossId: string; url: string } | Recordable<any>;
|
||||
uuid: string;
|
||||
}
|
||||
|
||||
export interface Wrapper {
|
||||
record: FileItem;
|
||||
uidKey: string;
|
||||
valueKey: string;
|
||||
}
|
||||
|
||||
export interface BaseFileItem {
|
||||
uid: number | string;
|
||||
url: string;
|
||||
name?: string;
|
||||
}
|
||||
export interface PreviewFileItem {
|
||||
url: string;
|
||||
name: string;
|
||||
type: string;
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
<script setup lang="ts">
|
||||
import { ref } from 'vue';
|
||||
|
||||
import { JsonPreview, Page } from '@vben/common-ui';
|
||||
|
||||
import { RadioGroup } from 'ant-design-vue';
|
||||
|
||||
import { ImageUpload } from '#/components/upload';
|
||||
|
||||
const resultField = ref<'ossId' | 'url'>('ossId');
|
||||
|
||||
const fileList = ref([]);
|
||||
const fieldOptions = [
|
||||
{ label: 'ossId', value: 'ossId' },
|
||||
{ label: '链接地址', value: 'url' },
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Page class="flex flex-col gap-[8px]">
|
||||
<div class="bg-background flex flex-col gap-[12px] rounded-lg p-6">
|
||||
<div class="flex gap-[8px]">
|
||||
<span>返回字段: </span>
|
||||
<RadioGroup v-model:value="resultField" :options="fieldOptions" />
|
||||
</div>
|
||||
<ImageUpload v-model:value="fileList" :result-field="resultField" />
|
||||
<JsonPreview :data="fileList" />
|
||||
</div>
|
||||
</Page>
|
||||
</template>
|
||||
Loading…
Reference in new issue