Skip to content

Commit dcfd2f0

Browse files
holyfataMiles-hxy
andauthored
fix(uploader): 处理非图片文件类型问题 (#3343)
* feat: 处理文件类型问题 * feat: 修复返回逻辑 * feat: 添加批量上传非图片文件的测试用例 * feat: 修复判断逻辑 * feat: 不进行校验图片 * fix: uploader onchange logic * feat: 还原代码展示 --------- Co-authored-by: Alex.hxy <[email protected]>
1 parent 3dbc7bc commit dcfd2f0

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/packages/uploader/__tests__/uploader.spec.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,50 @@ test('should render base uploader other props', () => {
9393
expect(fileItemClick).toBeCalled()
9494
})
9595

96+
test('should render no-image file uploader list', () => {
97+
const App = () => {
98+
const defaultFileList: FileItem[] = [
99+
{
100+
name: '文件1.txt',
101+
url: 'https://m.360buyimg.com/babel/jfs/t1/164410/22/25162/93384/616eac6cE6c711350/0cac53c1b82e1b05.gif',
102+
status: 'success',
103+
message: '上传成功',
104+
type: 'list',
105+
uid: '123',
106+
},
107+
{
108+
name: '文件2.ppt',
109+
url: 'https://m.360buyimg.com/babel/jfs/t1/164410/22/25162/93384/616eac6cE6c711350/0cac53c1b82e1b05.gif',
110+
status: 'error',
111+
message: '上传失败',
112+
type: 'list',
113+
uid: '124',
114+
},
115+
{
116+
name: '文件3.cpp',
117+
url: 'https://m.360buyimg.com/babel/jfs/t1/164410/22/25162/93384/616eac6cE6c711350/0cac53c1b82e1b05.gif',
118+
status: 'uploading',
119+
message: '上传中...',
120+
type: 'list',
121+
uid: '125',
122+
},
123+
]
124+
125+
return (
126+
<Uploader
127+
defaultValue={defaultFileList}
128+
uploadIcon="dongdong"
129+
previewType="list"
130+
/>
131+
)
132+
}
133+
134+
const { container } = render(<App />)
135+
const toast1 = container.querySelectorAll('.list')
136+
expect(toast1).toBeTruthy()
137+
expect(toast1.length).toBe(3)
138+
})
139+
96140
test('should render base uploader list', () => {
97141
const App = () => {
98142
const defaultFileList: FileItem[] = [

src/packages/uploader/uploader.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ const InternalUploader: ForwardRefRenderFunction<
183183
name: file.name,
184184
type: file.type,
185185
}
186-
if (preview && file.type?.includes('image')) {
186+
if (preview) {
187187
const reader = new FileReader()
188188
reader.onload = (event: ProgressEvent<FileReader>) => {
189189
fileListRef.current = [

0 commit comments

Comments
 (0)