Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
WebPublic
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
前端开发小组
WebPublic
Commits
9174bbb9
提交
9174bbb9
authored
12月 14, 2021
作者:
钟是志
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
附件上传组件增加对图片大小的限制
上级
4b542b71
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
80 行增加
和
47 行删除
+80
-47
UploadCom.js
one_stop_public/libs/UploadCom.js
+79
-46
UploadComDiyForQnZy.js
one_stop_public/libs/UploadComDiyForQnZy.js
+1
-1
没有找到文件。
one_stop_public/libs/UploadCom.js
浏览文件 @
9174bbb9
import
React
from
"react"
;
import
React
from
'react'
;
import
{
Button
,
Icon
,
message
,
Modal
,
Upload
}
from
"antd"
;
import
{
Button
,
Icon
,
message
,
Modal
,
Upload
}
from
'antd'
;
import
{
queryApiActionPath
}
from
"../utils/queryConfig"
;
import
{
queryApiActionPath
}
from
'../utils/queryConfig'
;
import
config
from
"@/webPublic/one_stop_public/config"
;
import
config
from
'@/webPublic/one_stop_public/config'
;
import
styles
from
"./style.less"
;
import
styles
from
'./style.less'
;
import
UploadComDiyForQnZy
from
"@/webPublic/one_stop_public/libs/UploadComDiyForQnZy"
;
import
UploadComDiyForQnZy
from
'@/webPublic/one_stop_public/libs/UploadComDiyForQnZy'
;
export
function
checkIsImage
(
path
)
{
export
function
checkIsImage
(
path
)
{
if
(
!
path
)
{
if
(
!
path
)
{
return
false
;
return
false
;
}
}
let
p
=
path
.
toLowerCase
();
let
p
=
path
.
toLowerCase
();
let
find
=
[
'.jpg'
,
'.png'
,
'.jpeg'
,
'.bmp'
,
'.gif'
,
'.bmp'
,
'.svg'
].
find
(
(
x
)
=>
{
let
find
=
[
'.jpg'
,
'.png'
,
'.jpeg'
,
'.bmp'
,
'.gif'
,
'.bmp'
,
'.svg'
].
find
(
x
=>
{
return
path
.
indexOf
(
x
)
>
-
1
;
return
path
.
indexOf
(
x
)
>
-
1
;
});
});
return
!!
find
;
return
!!
find
;
}
}
export
default
function
index
(
props
)
{
export
default
function
index
(
props
)
{
if
(
window
.
location
.
href
.
indexOf
(
"jy/geren/subsidy"
)
>
-
1
)
{
if
(
window
.
location
.
href
.
indexOf
(
'jy/geren/subsidy'
)
>
-
1
)
{
return
(
<
UploadComDiyForQnZy
{...
props
}
/>
)
;
return
<
UploadComDiyForQnZy
{...
props
}
/>
;
}
else
{
}
else
{
return
<
UploadCom
{...
props
}
/>
;
return
<
UploadCom
{...
props
}
/>
;
}
}
...
@@ -32,21 +31,20 @@ class UploadCom extends React.Component {
...
@@ -32,21 +31,20 @@ class UploadCom extends React.Component {
this
.
state
=
{
this
.
state
=
{
files
:
value
.
files
,
files
:
value
.
files
,
previewVisible
:
false
,
previewVisible
:
false
,
previewImage
:
""
,
previewImage
:
''
,
};
};
this
.
otherProps
=
{};
console
.
log
(
props
);
console
.
log
(
props
);
if
(
props
.
json
?.
otherProps
)
{
if
(
props
.
json
?.
otherProps
)
{
this
.
otherProps
=
props
.
json
?.
otherProps
;
this
.
otherProps
=
props
.
json
?.
otherProps
;
try
{
try
{
this
.
otherProps
=
new
Function
(
this
.
otherProps
);
this
.
otherProps
=
new
Function
(
this
.
otherProps
)
()
;
console
.
log
(
this
.
otherProps
);
console
.
log
(
this
.
otherProps
);
}
catch
(
e
)
{
}
catch
(
e
)
{}
}
}
}
}
}
triggerChange
=
(
changedValue
)
=>
{
triggerChange
=
changedValue
=>
{
// Should provide an event to pass value to Form.
// Should provide an event to pass value to Form.
const
onChange
=
this
.
props
.
onChange
;
const
onChange
=
this
.
props
.
onChange
;
if
(
onChange
)
{
if
(
onChange
)
{
...
@@ -54,28 +52,61 @@ class UploadCom extends React.Component {
...
@@ -54,28 +52,61 @@ class UploadCom extends React.Component {
}
}
};
};
//图片上传之前进行判断
beforeUpload
=
file
=>
{
return
this
.
isSize
(
file
).
then
(
res
=>
{
message
.
info
(
'正在上传中,请等待'
);
return
true
;
});
};
//检测尺寸
isSize
=
file
=>
{
const
{
limitWarnningMessage
}
=
this
.
otherProps
;
return
new
Promise
((
resolve
,
reject
)
=>
{
let
{
width
,
height
}
=
this
.
otherProps
.
limitImageSize
;
let
_URL
=
window
.
URL
||
window
.
webkitURL
;
let
img
=
new
Image
();
img
.
onload
=
function
()
{
let
valid
=
img
.
width
>=
width
&&
img
.
height
>=
height
;
valid
?
resolve
()
:
reject
();
};
img
.
src
=
_URL
.
createObjectURL
(
file
);
}).
then
(
()
=>
{
return
file
;
},
()
=>
{
message
.
error
(
file
.
name
+
limitWarnningMessage
,
);
return
Promise
.
reject
();
},
);
};
componentWillReceiveProps
(
nextProps
)
{
componentWillReceiveProps
(
nextProps
)
{
// Should be a controlled component.
// Should be a controlled component.
if
(
"value"
in
nextProps
)
{
if
(
'value'
in
nextProps
)
{
const
value
=
nextProps
.
value
;
const
value
=
nextProps
.
value
;
this
.
setState
(
value
);
this
.
setState
(
value
);
}
}
}
}
changeUrl
=
(
info
)
=>
{
changeUrl
=
info
=>
{
if
(
info
.
file
.
status
===
"done"
)
{
if
(
info
.
file
.
status
===
'done'
)
{
message
.
success
(
`
${
info
.
file
.
name
}
上传成功`
);
message
.
success
(
`
${
info
.
file
.
name
}
上传成功`
);
const
files
=
this
.
state
.
files
;
const
files
=
this
.
state
.
files
;
files
.
push
({
path
:
info
.
file
.
response
,
name
:
info
.
file
.
name
});
files
.
push
({
path
:
info
.
file
.
response
,
name
:
info
.
file
.
name
});
if
(
!
(
"value"
in
this
.
props
))
{
if
(
!
(
'value'
in
this
.
props
))
{
this
.
setState
({
files
});
this
.
setState
({
files
});
}
}
this
.
triggerChange
({
files
});
this
.
triggerChange
({
files
});
}
else
if
(
info
.
file
.
status
===
"error"
)
{
}
else
if
(
info
.
file
.
status
===
'error'
)
{
message
.
error
(
`
${
info
.
file
.
name
}
上传失败`
);
message
.
error
(
`
${
info
.
file
.
name
}
上传失败`
);
}
}
};
};
remove
=
(
path
)
=>
{
remove
=
path
=>
{
const
files
=
this
.
state
.
files
;
const
files
=
this
.
state
.
files
;
for
(
var
i
=
0
;
i
<
files
.
length
;
i
++
)
{
for
(
var
i
=
0
;
i
<
files
.
length
;
i
++
)
{
if
(
files
[
i
].
path
==
path
)
{
if
(
files
[
i
].
path
==
path
)
{
...
@@ -83,42 +114,43 @@ class UploadCom extends React.Component {
...
@@ -83,42 +114,43 @@ class UploadCom extends React.Component {
break
;
break
;
}
}
}
}
if
(
!
(
"value"
in
this
.
props
))
{
if
(
!
(
'value'
in
this
.
props
))
{
this
.
setState
({
files
});
this
.
setState
({
files
});
}
}
this
.
triggerChange
({
files
});
this
.
triggerChange
({
files
});
};
};
render
()
{
render
()
{
const
{
files
,
previewVisible
,
previewImage
}
=
this
.
state
;
const
{
files
,
previewVisible
,
previewImage
}
=
this
.
state
;
const
{
isMultiple
,
accept
,
btnName
,
disabled
}
=
this
.
props
;
const
{
isMultiple
,
accept
,
btnName
,
disabled
}
=
this
.
props
;
const
props
=
{
const
props
=
{
name
:
"file"
,
name
:
'file'
,
multiple
:
isMultiple
,
multiple
:
isMultiple
,
accept
:
accept
,
accept
:
accept
,
action
:
config
.
uploadUrl
,
action
:
config
.
uploadUrl
,
showUploadList
:
false
,
showUploadList
:
false
,
onChange
:
this
.
changeUrl
onChange
:
this
.
changeUrl
,
beforeUpload
:
this
.
otherProps
?.
limitImageSize
?
this
.
beforeUpload
:
undefined
,
};
};
return
(
return
(
<
div
>
<
div
>
{
" "
}
{
' '
}
<
Upload
{...
props
}
disabled
=
{
disabled
}
>
<
Upload
{...
props
}
disabled
=
{
disabled
}
>
{
!
disabled
&&
(
{
!
disabled
&&
(
<
Button
>
<
Button
>
<
Icon
type
=
"upload"
/>
<
Icon
type
=
"upload"
/>
{
btnName
?
btnName
:
"上传附件"
}
{
btnName
?
btnName
:
'上传附件'
}
<
/Button
>
<
/Button
>
)}
)}
<
/Upload
>
<
/Upload
>
<
ul
style
=
{{
paddingLeft
:
8
,
display
:
"flex"
}}
>
<
ul
style
=
{{
paddingLeft
:
8
,
display
:
'flex'
}}
>
{(
files
||
[]).
map
(
(
f
)
=>
{
{(
files
||
[]).
map
(
f
=>
{
if
(
f
.
path
&&
checkIsImage
(
f
.
path
))
{
if
(
f
.
path
&&
checkIsImage
(
f
.
path
))
{
return
(
return
(
<
li
key
=
{
f
.
path
}
className
=
{
styles
.
preview_img
}
>
<
li
key
=
{
f
.
path
}
className
=
{
styles
.
preview_img
}
>
<
div
className
=
{
styles
.
preview_div
}
>
<
div
className
=
{
styles
.
preview_div
}
>
<
img
<
img
style
=
{{
width
:
'100px'
,
height
:
'auto'
}}
style
=
{{
width
:
'100px'
,
height
:
'auto'
}}
className
=
{
styles
.
img
}
className
=
{
styles
.
img
}
src
=
{
queryApiActionPath
()
+
f
.
path
}
src
=
{
queryApiActionPath
()
+
f
.
path
}
/
>
/
>
...
@@ -128,15 +160,16 @@ class UploadCom extends React.Component {
...
@@ -128,15 +160,16 @@ class UploadCom extends React.Component {
// window.open(queryApiActionPath() + f.path);
// window.open(queryApiActionPath() + f.path);
this
.
setState
({
this
.
setState
({
previewVisible
:
true
,
previewVisible
:
true
,
previewImage
:
queryApiActionPath
()
+
f
.
path
previewImage
:
queryApiActionPath
()
+
f
.
path
,
});
});
}}
>
}}
<
Icon
type
=
"eye"
className
=
{
styles
.
icon_eye
}
/
>
>
<
Icon
type
=
"eye"
className
=
{
styles
.
icon_eye
}
/
>
<
/div
>
<
/div
>
<
/div
>
<
/div
>
{
!
disabled
&&
(
{
!
disabled
&&
(
<
Icon
<
Icon
style
=
{{
marginLeft
:
10
}}
style
=
{{
marginLeft
:
10
}}
type
=
"delete"
type
=
"delete"
onClick
=
{
this
.
remove
.
bind
(
this
,
f
.
path
)}
onClick
=
{
this
.
remove
.
bind
(
this
,
f
.
path
)}
/
>
/
>
...
@@ -148,10 +181,10 @@ class UploadCom extends React.Component {
...
@@ -148,10 +181,10 @@ class UploadCom extends React.Component {
<
li
key
=
{
f
.
path
}
>
<
li
key
=
{
f
.
path
}
>
<
a
target
=
"_blank"
key
=
{
f
.
path
}
href
=
{
queryApiActionPath
()
+
f
.
path
}
>
<
a
target
=
"_blank"
key
=
{
f
.
path
}
href
=
{
queryApiActionPath
()
+
f
.
path
}
>
{
f
.
name
}
{
f
.
name
}
<
/a>{
" "
}
<
/a>{
' '
}
{
!
disabled
&&
(
{
!
disabled
&&
(
<
Icon
<
Icon
style
=
{{
marginLeft
:
10
}}
style
=
{{
marginLeft
:
10
}}
type
=
"delete"
type
=
"delete"
onClick
=
{
this
.
remove
.
bind
(
this
,
f
.
path
)}
onClick
=
{
this
.
remove
.
bind
(
this
,
f
.
path
)}
/
>
/
>
...
@@ -163,10 +196,10 @@ class UploadCom extends React.Component {
...
@@ -163,10 +196,10 @@ class UploadCom extends React.Component {
<
Modal
<
Modal
visible
=
{
previewVisible
}
visible
=
{
previewVisible
}
footer
=
{
null
}
footer
=
{
null
}
onCancel
=
{()
=>
this
.
setState
({
previewVisible
:
false
})}
onCancel
=
{()
=>
this
.
setState
({
previewVisible
:
false
})}
width
=
{
'90vw'
}
width
=
{
'90vw'
}
>
>
<
img
alt
=
"example"
style
=
{{
width
:
"100%"
,
height
:
'auto'
}}
src
=
{
previewImage
}
/
>
<
img
alt
=
"example"
style
=
{{
width
:
'100%'
,
height
:
'auto'
}}
src
=
{
previewImage
}
/
>
<
/Modal
>
<
/Modal
>
<
/div
>
<
/div
>
);
);
...
...
one_stop_public/libs/UploadComDiyForQnZy.js
浏览文件 @
9174bbb9
...
@@ -102,7 +102,7 @@ export default class UploadComDiyForQnZy extends React.Component {
...
@@ -102,7 +102,7 @@ export default class UploadComDiyForQnZy extends React.Component {
action
:
config
.
uploadUrl
,
action
:
config
.
uploadUrl
,
showUploadList
:
false
,
showUploadList
:
false
,
onChange
:
this
.
changeUrl
,
onChange
:
this
.
changeUrl
,
beforeUpload
:
this
.
beforeUpload
beforeUpload
:
this
.
beforeUpload
,
};
};
return
(
return
(
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论