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
3beb940c
Commit
3beb940c
authored
Nov 03, 2020
by
张烨
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: add authority components
parent
210d1741
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
111 additions
and
15 deletions
+111
-15
.env
.env
+2
-1
webpack.base.babel.js
internals/webpack/webpack.base.babel.js
+4
-0
Authorized.js
src/components/Authorized/Authorized.js
+20
-7
AuthorizedRoute.js
src/components/Authorized/AuthorizedRoute.js
+20
-4
index.js
src/components/Authorized/index.js
+11
-0
renderAuthorize.js
src/components/Authorized/renderAuthorize.js
+1
-1
index.js
src/containers/App/index.js
+0
-2
authority.js
src/utils/authority.js
+47
-0
checklogin.js
src/utils/checklogin.js
+6
-0
No files found.
.env
View file @
3beb940c
# PUBLIC_PATH = reactOMS
PROXY = http://
192.168.19.102
:8005/
PROXY = http://
localhost
:8005/
HOST = localhost
PORT = 3001
\ No newline at end of file
internals/webpack/webpack.base.babel.js
View file @
3beb940c
...
...
@@ -171,6 +171,10 @@ module.exports = options => ({
modules
:
[
'node_modules'
,
'src'
],
extensions
:
[
'.js'
,
'.jsx'
,
'.react.js'
],
mainFields
:
[
'browser'
,
'jsnext:main'
,
'main'
],
alias
:
{
'@'
:
path
.
resolve
(
process
.
cwd
(),
'./src'
),
components
:
path
.
resolve
(
process
.
cwd
(),
'./src/components'
),
},
},
devtool
:
options
.
devtool
,
target
:
'web'
,
// Make web variables accessible to webpack, e.g. window
...
...
src/components/Authorized/Authorized.js
View file @
3beb940c
//
import React from 'react';
//
import { Result } from 'antd';
//
import check from './CheckPermissions';
import
React
from
'react'
;
import
{
Result
}
from
'antd'
;
import
check
from
'./CheckPermissions'
;
// const Authorized = {
// children,
// authority,
// };
const
Authorized
=
({
children
,
authority
,
noMatch
=
(
<
Result
status
=
"403"
title
=
"403"
subTitle
=
"Sorry, you are not authorized to access this page."
/>
),
})
=>
{
const
childrenRender
=
typeof
children
===
'undefined'
?
null
:
children
;
const
dom
=
check
(
authority
,
childrenRender
,
noMatch
);
return
<>
{
dom
}
<
/>
;
};
export
default
Authorized
;
src/components/Authorized/AuthorizedRoute.js
View file @
3beb940c
// import React from 'react';
import
{
Route
,
Redirect
}
from
'react-router-dom'
;
import
React
from
'react'
;
import
Authorized
from
'./Authorized'
;
const
AuthorizedRoute
=
({
component
,
component
:
Component
,
render
,
authority
,
redirectPath
,
// eslint-disable-next-line no-unused-vars
...
rest
})
=>
{};
})
=>
(
<
Authorized
authority
=
{
authority
}
noMatch
=
{
<
Route
{...
rest
}
render
=
{()
=>
<
Redirect
to
=
{{
pathname
:
redirectPath
}}
/>
}
/>
}
>
<
Route
{...
rest
}
render
=
{
props
=>
(
Component
?
<
Component
{...
props
}
/> : render
(
props
))
}
/>
<
/Authorized
>
);
export
default
AuthorizedRoute
;
src/components/Authorized/index.js
View file @
3beb940c
import
Authorized
from
'./Authorized'
;
import
Secured
from
'./Secured'
;
import
check
from
'./CheckPermissions'
;
import
renderAuthorize
from
'./renderAuthorize'
;
Authorized
.
Secured
=
Secured
;
Authorized
.
check
=
check
;
const
RenderAuthorize
=
renderAuthorize
(
Authorized
);
export
default
RenderAuthorize
;
src/components/Authorized/renderAuthorize.js
View file @
3beb940c
...
...
@@ -23,4 +23,4 @@ const renderAuthorize = Authorized => currentAuthority => {
};
export
{
CURRENT
};
export
default
Authorized
=>
renderAuthorize
(
Authorized
)
;
export
default
renderAuthorize
;
src/containers/App/index.js
View file @
3beb940c
import
React
from
'react'
;
import
{
Helmet
}
from
'react-helmet'
;
import
{
renderRoutes
}
from
'react-router-config'
;
import
{
BrowserRouter
as
Router
,
Switch
}
from
'react-router-dom'
;
import
config
from
'../../routes/config'
;
export
default
function
App
()
{
...
...
src/utils/authority.js
0 → 100644
View file @
3beb940c
import
RenderAuthorize
from
'@/components/Authorized'
;
/* eslint-disable eslint-comments/disable-enable-pair */
/* eslint-disable import/no-mutable-exports */
let
Authorized
=
RenderAuthorize
(
getAuthority
());
// Reload the rights component
const
reloadAuthorized
=
()
=>
{
Authorized
=
RenderAuthorize
(
getAuthority
());
};
/**
* hard code
* block need it。
*/
window
.
reloadAuthorized
=
reloadAuthorized
;
export
{
reloadAuthorized
};
export
default
Authorized
;
// use localStorage to store the authority info, which might be sent from server in actual project.
export
function
getAuthority
(
str
)
{
const
authorityString
=
typeof
str
===
'undefined'
&&
localStorage
?
localStorage
.
getItem
(
'panda-oms-authority'
)
:
str
;
// authorityString could be admin, "admin", ["admin"]
let
authority
;
try
{
if
(
authorityString
)
{
authority
=
JSON
.
parse
(
authorityString
);
}
}
catch
(
e
)
{
authority
=
authorityString
;
}
if
(
typeof
authority
===
'string'
)
{
return
[
authority
];
}
return
authority
;
}
export
function
setAuthority
(
authority
)
{
const
proAuthority
=
typeof
authority
===
'string'
?
[
authority
]
:
authority
;
localStorage
.
setItem
(
'panda-oms-authority'
,
JSON
.
stringify
(
proAuthority
));
// auto reload
reloadAuthorized
();
}
src/utils/checklogin.js
0 → 100644
View file @
3beb940c
export
default
(...
routerProps
)
=>
new
Promise
((
resolve
,
reject
)
=>
{
setTimeout
(()
=>
{
resolve
();
},
1500
);
}).
then
(()
=>
{});
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