File tree Expand file tree Collapse file tree
apps/example/src/views/component_example/image_upload Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11<script setup lang="ts">
22const files = ref <string []>([])
33
4+ function beforeUpload(file : File ) {
5+ if (! file .type .startsWith (' image/' )) {
6+ faToast .error (' 请选择图片文件' )
7+ return false
8+ }
9+ if (file .size > 200 * 1024 ) {
10+ faToast .error (' 图片大小不能超过 200KB' )
11+ return false
12+ }
13+ return true
14+ }
15+
416function handleSuccess() {
517 faToast .success (' 模拟上传成功' )
618}
@@ -11,11 +23,9 @@ function handleSuccess() {
1123 v-model =" files "
1224 action="/fake/upload"
1325 :after-upload =" (response ) => ` ${response .data .url }?fake=${Math .random ()} ` "
26+ :before-upload =" beforeUpload "
1427 :width =" 200 "
1528 :height =" 130 "
16- :dimension =" { width: 400 , height: 260 } "
17- :ext =" [' png' ] "
18- :size =" 200 * 1024 "
1929 :max =" 0 "
2030 @on-success =" handleSuccess "
2131 >
Original file line number Diff line number Diff line change 1+ <script setup lang="ts">
2+ import type { UploadRequestOptions } from ' @fantastic-admin/components'
3+
4+ const files = ref <string []>([])
5+
6+ async function httpRequest({ file , onProgress }: UploadRequestOptions ) {
7+ onProgress (30 )
8+ await new Promise (resolve => setTimeout (resolve , 300 ))
9+ onProgress (100 )
10+
11+ return {
12+ url: URL .createObjectURL (file ),
13+ name: file .name ,
14+ }
15+ }
16+
17+ function handleSuccess() {
18+ faToast .success (' 自定义上传完成' )
19+ }
20+ </script >
21+
22+ <template >
23+ <FaImageUpload
24+ v-model =" files "
25+ :http-request =" httpRequest "
26+ :after-upload =" response => response .url "
27+ :max =" 3 "
28+ @on-success =" handleSuccess "
29+ />
30+ </template >
Original file line number Diff line number Diff line change 1+ <script setup lang="ts">
2+ const files = ref <string []>([])
3+
4+ function beforeUpload(file : File ) {
5+ return file .type .startsWith (' image/' )
6+ }
7+
8+ async function httpRequest({ file , onProgress }: {
9+ file: File
10+ onProgress: (percent : number ) => void
11+ }) {
12+ onProgress (50 )
13+ await new Promise (resolve => setTimeout (resolve , 200 ))
14+ onProgress (100 )
15+
16+ return {
17+ url: URL .createObjectURL (file ),
18+ name: file .name ,
19+ }
20+ }
21+ </script >
22+
23+ <template >
24+ <FaImageUpload
25+ v-model =" files "
26+ directory
27+ :max =" 0 "
28+ :http-request =" httpRequest "
29+ :before-upload =" beforeUpload "
30+ :after-upload =" response => response .url "
31+ />
32+ </template >
Original file line number Diff line number Diff line change 22import Demo1 from ' ./_demo1.vue'
33import Demo2 from ' ./_demo2.vue'
44import Demo3 from ' ./_demo3.vue'
5+ import Demo4 from ' ./_demo4.vue'
6+ import Demo5 from ' ./_demo5.vue'
57 </script >
68
79<template >
@@ -13,8 +15,14 @@ import Demo3 from './_demo3.vue'
1315 <FaPageMain title="多图上传" main-class="p-4">
1416 <Demo2 />
1517 </FaPageMain >
16- <FaPageMain title="自定义默认内容、容器大小、建议尺寸、限制类型、不限制数量 " main-class="p-4">
18+ <FaPageMain title="上传前校验 " main-class="p-4">
1719 <Demo3 />
1820 </FaPageMain >
21+ <FaPageMain title="自定义上传请求" main-class="p-4">
22+ <Demo4 />
23+ </FaPageMain >
24+ <FaPageMain title="文件夹上传" main-class="p-4">
25+ <Demo5 />
26+ </FaPageMain >
1927 </div >
2028</template >
Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ export { default as FaHoverCard } from './src/hover-card/index.vue'
1717export { default as FaIcon } from './src/icon/index.vue'
1818export * from './src/image-preview/index'
1919export { default as FaImagePreview } from './src/image-preview/index.vue'
20+ export type { UploadRequestOptions } from './src/image-upload/index.vue'
2021export { default as FaImageUpload } from './src/image-upload/index.vue'
2122export { default as FaInputOTP } from './src/input-otp/index.vue'
2223export { default as FaInput } from './src/input/index.vue'
You can’t perform that action at this time.
0 commit comments