Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
C
CivManage
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
CivManage
Commits
f2921cb8
Commit
f2921cb8
authored
Dec 03, 2020
by
张烨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: 优化图片库加载
parent
7245db0b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
19 deletions
+72
-19
app.js
src/app.js
+4
-1
context.js
src/components/Upload/context.js
+28
-0
index.tsx
src/components/Upload/index.tsx
+40
-18
No files found.
src/app.js
View file @
f2921cb8
...
...
@@ -18,6 +18,7 @@ import configureStore from './configureStore';
import
App
from
'./containers/App'
;
import
history
from
'./utils/history'
;
import
config
from
'./routes/config'
;
import
{
PictureWallProvider
}
from
'@/components/Upload/context'
;
const
initialState
=
Immutable
.
Map
();
const
store
=
configureStore
(
initialState
,
history
);
const
MOUNT_NODE
=
document
.
getElementById
(
'app'
);
...
...
@@ -27,7 +28,9 @@ const render = () => {
<
Provider
store
=
{
store
}
>
<
ConnectedRouter
history
=
{
history
}
>
<
ConfigProvider
locale
=
{
zhCN
}
>
<
App
routesConfig
=
{
config
}
/
>
<
PictureWallProvider
>
<
App
routesConfig
=
{
config
}
/
>
<
/PictureWallProvider
>
<
/ConfigProvider
>
<
/ConnectedRouter
>
<
/Provider>
,
...
...
src/components/Upload/context.js
0 → 100644
View file @
f2921cb8
import
{
getImageBases
}
from
'@/services/common/api'
;
import
React
,
{
useEffect
,
useState
}
from
'react'
;
const
UploadContext
=
React
.
createContext
();
const
PictureWallProvider
=
props
=>
{
const
{
children
,
...
rest
}
=
props
;
const
[
imgBed
,
setImgBed
]
=
useState
([]);
const
update
=
()
=>
{
getImageBases
(
''
).
then
(
res
=>
{
if
(
res
.
code
===
0
)
{
setImgBed
(
res
.
data
);
}
});
};
useEffect
(()
=>
{
update
();
},
[]);
return
(
<
UploadContext
.
Provider
value
=
{{
imgBed
,
update
}}
>
{
children
}
<
/UploadContext.Provider
>
);
};
export
{
UploadContext
as
default
,
PictureWallProvider
};
src/components/Upload/index.tsx
View file @
f2921cb8
...
...
@@ -8,6 +8,7 @@ import { uuid } from '@/utils/tools';
import
{
get
,
PUBLISH_SERVICE
}
from
'@/services'
;
import
styles
from
'./index.less'
;
import
{
getImageBases
}
from
'@/services/common/api'
;
import
UploadContext
from
'./context.js'
const
{
TabPane
}
=
Tabs
;
...
...
@@ -17,6 +18,12 @@ const wallCateName: any = {
bg
:
'背景'
,
uploaded
:
'上传'
,
};
const
tabNames
:
any
=
{
CityTemp
:
'用户上传'
,
icon
:
'图标'
,
androidMenu
:
'安卓图标'
,
menuNew
:
'应用图标'
}
function
getBase64
(
file
:
File
|
Blob
)
{
return
new
Promise
<
string
>
((
resolve
,
reject
)
=>
{
...
...
@@ -38,6 +45,7 @@ interface PicturesWallType {
isCrop
?:
boolean
;
type
?:
'CityTemp'
|
'icon'
|
'androidMenu'
|
'menuNew'
,
value
?:
string
|
string
[],
uploadContext
:
any
,
}
class
PicturesWall
extends
React
.
Component
<
PicturesWallType
>
{
...
...
@@ -46,7 +54,7 @@ class PicturesWall extends React.Component<PicturesWallType> {
previewImage
:
''
,
wallModalVisible
:
false
,
previewTitle
:
''
,
imgBed
:
[],
imgBed
:
this
.
props
.
uploadContext
?.
imgBed
||
[],
curSelectedImg
:
''
,
prevProps
:{},
fileList
:
this
.
props
.
value
?
Array
.
isArray
(
this
.
props
.
value
)
?
this
.
props
.
value
.
map
((
v
)
=>
({
...
...
@@ -63,24 +71,32 @@ class PicturesWall extends React.Component<PicturesWallType> {
};
static
getDerivedStateFromProps
=
(
props
,
state
)
=>
{
const
{
value
,
uploadContext
=
{}}
=
props
;
const
{
imgBed
,
update
}
=
uploadContext
;
const
fileList
=
state
.
fileList
;
const
shouldUpdate
=
props
.
value
&&
fileList
.
every
(
f
=>
Array
.
isArray
(
props
.
value
)
?
!
props
.
value
.
some
(
v
=>
f
.
url
===
v
)
:
f
.
url
!==
props
.
value
)
if
(
props
.
value
!==
state
.
prevProps
.
value
&&
shouldUpdate
){
const
shouldUpdate
=
value
&&
fileList
.
every
(
f
=>
Array
.
isArray
(
value
)
?
!
value
.
some
(
v
=>
f
.
url
===
v
)
:
f
.
url
!==
value
)
if
(
value
!==
state
.
prevProps
.
value
&&
shouldUpdate
){
return
{
pr
o
vProps
:
props
,
fileList
:
Array
.
isArray
(
props
.
value
)
?
props
.
value
.
map
((
v
)
=>
({
pr
e
vProps
:
props
,
fileList
:
Array
.
isArray
(
value
)
?
value
.
map
((
v
)
=>
({
url
:
v
,
uid
:
uuid
(
8
,
16
),
name
:
'熊猫运维中台系统'
,
status
:
'done'
,
}))
as
UploadFile
<
any
>
[]:
[{
url
:
props
.
value
,
url
:
value
,
uid
:
uuid
(
8
,
16
),
name
:
'熊猫运维中台系统'
,
status
:
'done'
,
}]
as
UploadFile
<
any
>
[]
}
}
if
(
imgBed
!=
state
.
prevProps
.
uploadContext
?.
imgBed
){
return
{
prevProps
:
props
,
imgBed
}
}
return
{
prevProps
:
props
};
...
...
@@ -153,16 +169,17 @@ class PicturesWall extends React.Component<PicturesWallType> {
};
handleChange
=
({
file
,
fileList
}:
UploadChangeParam
<
UploadFile
<
any
>>
)
=>
{
const
{
maxLen
=
1
}
=
this
.
props
;
const
{
maxLen
=
1
,
uploadContext
}
=
this
.
props
;
this
.
setState
({
fileList
});
if
(
file
.
status
===
'done'
)
{
const
files
=
fileList
.
map
(
item
=>
{
const
{
status
,
data
,
name
,
thumbUrl
}
=
item
;
const
{
status
,
name
,
thumbUrl
}
=
item
;
const
url
=
item
.
response
&&
item
.
response
.
data
||
thumbUrl
;
return
{
uid
:
uuid
(
8
,
16
),
name
,
status
,
url
};
});
this
.
setState
({
fileList
:
files
})
this
.
props
.
onChange
&&
this
.
props
.
onChange
(
maxLen
===
1
?
files
[
0
].
url
:
files
.
map
(
f
=>
f
.
url
));
uploadContext
?.
update
&&
uploadContext
.
update
()
}
};
...
...
@@ -182,14 +199,14 @@ class PicturesWall extends React.Component<PicturesWallType> {
return
isJpgOrPng
&&
isLt2M
;
};
componentDidMount
()
{
const
{
type
=
''
}
=
this
.
props
;
getImageBases
(
type
).
then
(
res
=>
{
if
(
res
.
code
===
0
){
this
.
setState
({
imgBed
:
res
.
data
})
}
})
}
//
componentDidMount() {
//
const { type = ''} = this.props;
//
getImageBases(type).then(res => {
//
if(res.code === 0){
//
this.setState({imgBed: res.data})
//
}
//
})
//
}
getImageUrl
(
path
){
if
(
path
&&
path
.
indexOf
(
'http'
)
===
0
){
...
...
@@ -302,7 +319,7 @@ class PicturesWall extends React.Component<PicturesWallType> {
<
Tabs
defaultActiveKey=
{
imgBed
[
0
]?.
moduleName
}
tabPosition=
"left"
style=
{
{
height
:
520
}
}
>
{
imgBed
.
map
((
item
,
i
)
=>
{
return
(
<
TabPane
tab=
{
item
.
moduleName
}
key=
{
item
.
moduleName
}
>
<
TabPane
tab=
{
tabNames
[
item
.
moduleName
]
}
key=
{
item
.
moduleName
}
>
<
div
className=
{
styles
.
imgBox
}
>
{
item
.
child
?.
map
(
m
=>
m
.
fileUrls
).
flat
(
Infinity
).
map
((
item
:
string
,
i
:
number
)
=>
{
return
(
...
...
@@ -335,4 +352,9 @@ class PicturesWall extends React.Component<PicturesWallType> {
}
}
export
default
PicturesWall
;
const
PicturesWallWrapper
=
(
props
:
any
)
=>
{
return
<
UploadContext
.
Consumer
>
{
(
uploadContext
)
=>
<
PicturesWall
{
...
props
}
uploadContext=
{
uploadContext
}
/>
}
</
UploadContext
.
Consumer
>
}
export
default
PicturesWallWrapper
;
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