Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wisdom-components
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ReactWeb5
wisdom-components
Commits
b6d48803
Commit
b6d48803
authored
Aug 15, 2022
by
周宏民
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: 富文件编辑器上传附件对附件名有特殊字段处理
parent
3bfaaf53
Pipeline
#57669
failed with stages
in 8 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
98 additions
and
96 deletions
+98
-96
fileListItem.js
packages/base-components/RichText/src/fileListItem.js
+91
-93
index.js
packages/base-components/RichText/src/index.js
+7
-3
No files found.
packages/base-components/RichText/src/fileListItem.js
View file @
b6d48803
...
...
@@ -3,101 +3,99 @@
* @Author: hongmye
* @Date: 2022-03-21 14:44:49
*/
import
React
,
{
useState
,
useEffect
,
useContext
}
from
'react'
;
import
{
FileTwoTone
,
DeleteOutlined
,
FileImageTwoTone
,
DownloadOutlined
,
PictureOutlined
}
from
'@ant-design/icons'
;
import
{
DeleteOutlined
,
DownloadOutlined
,
PictureOutlined
}
from
'@ant-design/icons'
;
import
{
Button
,
ConfigProvider
}
from
'antd'
;
import
{
useContext
,
useEffect
,
useState
}
from
'react'
;
import
iconFile
from
'./icon_file.png'
;
function
f
ileListItem
(
props
)
{
const
[
fileList
,
setFileList
]
=
useState
([]);
const
{
getPrefixCls
}
=
useContext
(
ConfigProvider
.
ConfigContext
);
const
prefixCls
=
getPrefixCls
();
function
F
ileListItem
(
props
)
{
const
[
fileList
,
setFileList
]
=
useState
([]);
const
{
getPrefixCls
}
=
useContext
(
ConfigProvider
.
ConfigContext
);
const
prefixCls
=
getPrefixCls
();
const
imgType
=
[
'image/png'
,
'image/jpg'
,
'image/jpeg'
];
const
onPreview
=
item
=>
{
props
.
onPreview
(
item
);
};
const
onDownLoad
=
item
=>
{
const
a
=
document
.
createElement
(
'a'
);
a
.
setAttribute
(
'download'
,
item
.
name
);
a
.
setAttribute
(
'href'
,
item
.
path
);
document
.
documentElement
.
appendChild
(
a
);
a
.
target
=
'_black'
;
a
.
click
();
};
useEffect
(()
=>
{
setFileList
(
props
.
list
||
[]);
},
[
props
.
list
]);
return
(
<>
{
fileList
.
map
((
item
,
index
)
=>
{
return
(
<
div
key
=
{
index
}
className
=
{
`
${
prefixCls
}
-upload-list
${
prefixCls
}
-upload-list-picture`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-picture-container`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-item`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-item-info`
}
>
<
span
className
=
{
`
${
prefixCls
}
-upload-span`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-item-thumbnail
${
prefixCls
}
-upload-list-item-file`
}
>
{
/* {imgType.includes(item.type) ? <FileImageTwoTone /> : <FileTwoTone />} */
}
<
img
src
=
{
iconFile
}
/
>
<
/div
>
<
span
className
=
{
`
${
prefixCls
}
-upload-list-item-name`
}
title
=
{
item
.
name
}
style
=
{{
cursor
:
'pointer'
}}
>
{
item
.
name
}
<
/span
>
<
span
className
=
{
`
${
prefixCls
}
-upload-list-item-card-actions picture`
}
>
{
imgType
.
includes
(
item
.
type
)
&&
(
<
Button
title
=
"预览"
type
=
"text"
onClick
=
{
e
=>
{
e
&&
e
.
stopPropagation
();
onPreview
(
item
);
}}
style
=
{{
padding
:
'4px 8px'
}}
>
<
PictureOutlined
/>
<
/Button
>
)}
<
Button
title
=
"下载"
type
=
"text"
onClick
=
{
e
=>
{
e
&&
e
.
stopPropagation
();
onDownLoad
(
item
);
}}
style
=
{{
padding
:
'4px 8px'
}}
>
<
DownloadOutlined
/>
<
/Button
>
{
props
.
type
===
'edit'
&&
(
<
Button
title
=
"删除文件"
type
=
"text"
onClick
=
{
e
=>
{
e
&&
e
.
stopPropagation
();
props
.
onDel
(
item
);
}}
style
=
{{
padding
:
'4px 8px'
}}
>
<
DeleteOutlined
/>
<
/Button
>
)}
<
/span
>
<
/span
>
<
/div
>
<
/div
>
<
/div
>
const
imgType
=
[
'image/png'
,
'image/jpg'
,
'image/jpeg'
];
const
onPreview
=
(
item
)
=>
{
props
.
onPreview
(
item
);
};
const
onDownLoad
=
(
item
)
=>
{
const
a
=
document
.
createElement
(
'a'
);
a
.
setAttribute
(
'download'
,
item
.
name
);
a
.
setAttribute
(
'href'
,
item
.
path
);
document
.
documentElement
.
appendChild
(
a
);
a
.
target
=
'_black'
;
a
.
click
();
};
useEffect
(()
=>
{
setFileList
(
props
.
list
||
[]);
},
[
props
.
list
]);
return
(
<>
{
fileList
.
map
((
item
,
index
)
=>
{
return
(
<
div
key
=
{
index
}
className
=
{
`
${
prefixCls
}
-upload-list
${
prefixCls
}
-upload-list-picture`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-picture-container`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-item`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-item-info`
}
>
<
span
className
=
{
`
${
prefixCls
}
-upload-span`
}
>
<
div
className
=
{
`
${
prefixCls
}
-upload-list-item-thumbnail
${
prefixCls
}
-upload-list-item-file`
}
>
{
/* {imgType.includes(item.type) ? <FileImageTwoTone /> : <FileTwoTone />} */
}
<
img
src
=
{
iconFile
}
/
>
<
/div
>
);
})}
<
/
>
);
<
span
className
=
{
`
${
prefixCls
}
-upload-list-item-name`
}
title
=
{
item
.
name
}
style
=
{{
cursor
:
'pointer'
}}
>
{
item
.
name
}
<
/span
>
<
span
className
=
{
`
${
prefixCls
}
-upload-list-item-card-actions picture`
}
>
{
imgType
.
includes
(
item
.
type
)
&&
(
<
Button
title
=
"预览"
type
=
"text"
onClick
=
{(
e
)
=>
{
e
&&
e
.
stopPropagation
();
onPreview
(
item
);
}}
style
=
{{
padding
:
'4px 8px'
}}
>
<
PictureOutlined
/>
<
/Button
>
)}
<
Button
title
=
"下载"
type
=
"text"
onClick
=
{(
e
)
=>
{
e
&&
e
.
stopPropagation
();
onDownLoad
(
item
);
}}
style
=
{{
padding
:
'4px 8px'
}}
>
<
DownloadOutlined
/>
<
/Button
>
{
props
.
type
===
'edit'
&&
(
<
Button
title
=
"删除文件"
type
=
"text"
onClick
=
{(
e
)
=>
{
e
&&
e
.
stopPropagation
();
props
.
onDel
(
item
);
}}
style
=
{{
padding
:
'4px 8px'
}}
>
<
DeleteOutlined
/>
<
/Button
>
)}
<
/span
>
<
/span
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
);
})}
<
/
>
);
}
export
default
f
ileListItem
;
export
default
F
ileListItem
;
packages/base-components/RichText/src/index.js
View file @
b6d48803
...
...
@@ -370,9 +370,13 @@ const RichText = forwardRef((props, ref) => {
};
const
addFile
=
(
e
)
=>
{
if
(
e
.
target
)
{
const
file
=
e
.
target
.
files
[
0
];
let
file
=
e
.
target
.
files
[
0
];
const
pattern
=
/
[
`~!@#$^
\-
&*()+=|{}':;',
\\\[\]\<
>
\/
?~!@#¥……&*()——|{}【】';:""'。,、?
\s]
/g
;
let
name
=
file
.
name
.
replace
(
pattern
,
''
);
const
renameFile
=
new
File
([
file
],
name
);
const
formData
=
new
FormData
();
formData
.
append
(
'file'
,
f
ile
);
formData
.
append
(
'file'
,
renameF
ile
);
setLoading
(
true
);
request
(
API
.
POST_UPLOADERFILES
,
{
method
:
'POST'
,
...
...
@@ -392,7 +396,7 @@ const RichText = forwardRef((props, ref) => {
props
.
onChangeFile
(
arr
);
setLoading
(
false
);
}
else
{
message
.
error
(
res
.
msg
);
res
&&
message
.
error
(
res
.
msg
);
setLoading
(
false
);
}
})
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment