Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
dinky
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
wangpeng
dinky
Commits
1fe0d107
Unverified
Commit
1fe0d107
authored
Aug 15, 2023
by
yqwoe
Committed by
GitHub
Aug 15, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Block permission control (#2218)
* feat: use-service hooks * feat: 区块权限控制
parent
5d5790da
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
91 additions
and
12 deletions
+91
-12
package.json
dinky-web/package.json
+1
-0
app.tsx
dinky-web/src/app.tsx
+3
-2
useAccess.tsx
dinky-web/src/hooks/useAccess.tsx
+70
-0
index.tsx
dinky-web/src/pages/Home/index.tsx
+15
-10
dinky-mysql.sql
script/sql/dinky-mysql.sql
+2
-0
No files found.
dinky-web/package.json
View file @
1fe0d107
...
@@ -59,6 +59,7 @@
...
@@ -59,6 +59,7 @@
"lodash"
:
"^4.17.21"
,
"lodash"
:
"^4.17.21"
,
"million"
:
"^2.5.1-beta.3"
,
"million"
:
"^2.5.1-beta.3"
,
"moment"
:
"^2.29.4"
,
"moment"
:
"^2.29.4"
,
"monaco-editor"
:
"^0.41.0"
,
"omit.js"
:
"^2.0.2"
,
"omit.js"
:
"^2.0.2"
,
"rc-menu"
:
"^9.8.4"
,
"rc-menu"
:
"^9.8.4"
,
"rc-util"
:
"^5.33.0"
,
"rc-util"
:
"^5.33.0"
,
...
...
dinky-web/src/app.tsx
View file @
1fe0d107
...
@@ -32,6 +32,7 @@ import {persistStore, persistReducer} from 'redux-persist';
...
@@ -32,6 +32,7 @@ import {persistStore, persistReducer} from 'redux-persist';
import
storage
from
'redux-persist/lib/storage'
;
import
storage
from
'redux-persist/lib/storage'
;
import
{
Reducer
,
StoreEnhancer
}
from
'redux'
;
import
{
Reducer
,
StoreEnhancer
}
from
'redux'
;
import
{
API
}
from
"./services/data"
;
import
{
API
}
from
"./services/data"
;
import
{
AccessContextProvider
}
from
'@/hooks/useAccess'
;
// const isDev = process.env.NODE_ENV === "development";
// const isDev = process.env.NODE_ENV === "development";
const
loginPath
=
API_CONSTANTS
.
LOGIN_PATH
;
const
loginPath
=
API_CONSTANTS
.
LOGIN_PATH
;
...
@@ -146,9 +147,9 @@ export const layout: RunTimeLayoutConfig = ({initialState}) => {
...
@@ -146,9 +147,9 @@ export const layout: RunTimeLayoutConfig = ({initialState}) => {
childrenRender
:
(
children
)
=>
{
childrenRender
:
(
children
)
=>
{
if
(
initialState
?.
loading
)
return
<
PageLoading
/>;
if
(
initialState
?.
loading
)
return
<
PageLoading
/>;
return
(
return
(
<>
<
AccessContextProvider
currentUser=
{
initialState
?.
currentUser
}
>
{
children
}
{
children
}
</>
</
AccessContextProvider
>
);
);
},
},
...
initialState
?.
settings
,
...
initialState
?.
settings
,
...
...
dinky-web/src/hooks/useAccess.tsx
0 → 100644
View file @
1fe0d107
import
{
createContext
,
ReactElement
,
useContext
}
from
'react'
/***
* 按钮的path和name
*/
export
type
Block
=
{
path
:
string
;
name
:
string
;
}
export
type
AccessContextProps
=
{
isAdmin
:
boolean
;
blocks
:
Block
[];
}
export
const
AccessContext
=
createContext
<
AccessContextProps
>
(
null
!
);
type
AuthorizedProps
=
{
path
:
string
;
denied
?:
ReactElement
|
null
;
children
?:
ReactElement
|
null
;
}
export
function
Authorized
({
path
,
denied
=
null
,
children
=
null
,
}:
AuthorizedProps
)
{
const
{
isAdmin
,
blocks
=
[]}
=
useContext
(
AccessContext
);
if
(
isAdmin
)
return
children
if
(
!
blocks
.
length
)
return
denied
;
const
authority
=
blocks
.
some
(
block
=>
block
.
path
===
path
)
return
authority
?
children
:
denied
;
}
export
const
AccessContextProvider
=
({
children
,
currentUser
})
=>
{
const
isAdmin
=
currentUser
?.
user
?.
superAdminFlag
let
blocks
:
Block
[]
=
[]
const
flatTree
=
(
menus
)
=>
{
menus
.
forEach
(({
path
,
children
,
name
,
type
})
=>
{
if
(
type
===
'F'
){
blocks
.
push
({
path
,
name
})
}
if
(
children
.
length
){
flatTree
(
children
)
}
})
}
flatTree
(
currentUser
?.
menuList
)
return
<
AccessContext
.
Provider
value=
{
{
isAdmin
,
blocks
}
}
>
{
children
}
</
AccessContext
.
Provider
>
}
export
const
useAccess
=
()
=>
useContext
(
AccessContext
)
dinky-web/src/pages/Home/index.tsx
View file @
1fe0d107
...
@@ -16,6 +16,7 @@
...
@@ -16,6 +16,7 @@
* limitations under the License.
* limitations under the License.
*
*
*/
*/
import
{
Authorized
}
from
'@/hooks/useAccess'
;
import
DevOverView
from
'@/pages/Home/DevOverView'
;
import
DevOverView
from
'@/pages/Home/DevOverView'
;
import
JobOverView
from
'@/pages/Home/JobOverView'
;
import
JobOverView
from
'@/pages/Home/JobOverView'
;
import
{
PageContainer
}
from
'@ant-design/pro-components'
;
import
{
PageContainer
}
from
'@ant-design/pro-components'
;
...
@@ -24,16 +25,20 @@ import { Col, Row } from 'antd';
...
@@ -24,16 +25,20 @@ import { Col, Row } from 'antd';
export
default
()
=>
{
export
default
()
=>
{
return
(
return
(
<
PageContainer
title=
{
false
}
>
<
PageContainer
title=
{
false
}
>
<
Row
style=
{
{
marginTop
:
'5px'
,
marginBottom
:
'10px'
}
}
>
<
Authorized
path=
"/home/jobOverView"
>
<
Col
span=
{
24
}
>
<
Row
style=
{
{
marginTop
:
'5px'
,
marginBottom
:
'10px'
}
}
>
<
JobOverView
/>
<
Col
span=
{
24
}
>
</
Col
>
<
JobOverView
/>
</
Row
>
</
Col
>
<
Row
>
</
Row
>
<
Col
span=
{
24
}
>
</
Authorized
>
<
DevOverView
/>
<
Authorized
path=
"/home/devOverView"
>
</
Col
>
<
Row
>
</
Row
>
<
Col
span=
{
24
}
>
<
DevOverView
/>
</
Col
>
</
Row
>
</
Authorized
>
</
PageContainer
>
</
PageContainer
>
);
);
};
};
script/sql/dinky-mysql.sql
View file @
1fe0d107
...
@@ -1196,6 +1196,8 @@ INSERT INTO `dinky_sys_menu` VALUES (28, 9, 'cluster-instance', '/registration/c
...
@@ -1196,6 +1196,8 @@ INSERT INTO `dinky_sys_menu` VALUES (28, 9, 'cluster-instance', '/registration/c
INSERT
INTO
`dinky_sys_menu`
VALUES
(
29
,
12
,
'group'
,
'/registration/alert/group'
,
'./RegCenter/Alert/AlertGroup'
,
NULL
,
NULL
,
'C'
,
0
,
NULL
,
'2023-08-11 14:06:55'
,
'2023-08-11 14:06:55'
,
NULL
);
INSERT
INTO
`dinky_sys_menu`
VALUES
(
29
,
12
,
'group'
,
'/registration/alert/group'
,
'./RegCenter/Alert/AlertGroup'
,
NULL
,
NULL
,
'C'
,
0
,
NULL
,
'2023-08-11 14:06:55'
,
'2023-08-11 14:06:55'
,
NULL
);
INSERT
INTO
`dinky_sys_menu`
VALUES
(
30
,
9
,
'cluster-config'
,
'/registration/cluster/config'
,
'./RegCenter/Cluster/Configuration'
,
NULL
,
NULL
,
'C'
,
0
,
NULL
,
'2023-08-11 14:06:55'
,
'2023-08-11 14:06:55'
,
NULL
);
INSERT
INTO
`dinky_sys_menu`
VALUES
(
30
,
9
,
'cluster-config'
,
'/registration/cluster/config'
,
'./RegCenter/Cluster/Configuration'
,
NULL
,
NULL
,
'C'
,
0
,
NULL
,
'2023-08-11 14:06:55'
,
'2023-08-11 14:06:55'
,
NULL
);
INSERT
INTO
`dinky_sys_menu`
VALUES
(
31
,
12
,
'instance'
,
'/registration/alert/instance'
,
'./RegCenter/Alert/AlertInstance'
,
NULL
,
NULL
,
'C'
,
0
,
NULL
,
'2023-08-11 14:06:55'
,
'2023-08-11 14:06:55'
,
NULL
);
INSERT
INTO
`dinky_sys_menu`
VALUES
(
31
,
12
,
'instance'
,
'/registration/alert/instance'
,
'./RegCenter/Alert/AlertInstance'
,
NULL
,
NULL
,
'C'
,
0
,
NULL
,
'2023-08-11 14:06:55'
,
'2023-08-11 14:06:55'
,
NULL
);
INSERT
INTO
`dinky_sys_menu`
VALUES
(
32
,
1
,
'作业监控'
,
'/home/jobOverView'
,
'Row'
,
'show'
,
'AntCloudOutlined'
,
'F'
,
0
,
NULL
,
'2023-08-15 16:52:59'
,
'2023-08-15 18:20:23'
,
NULL
);
INSERT
INTO
`dinky_sys_menu`
VALUES
(
33
,
1
,
'数据开发'
,
'/home/devOverView'
,
'DevOverView'
,
'show'
,
'AimOutlined'
,
'F'
,
0
,
NULL
,
'2023-08-15 16:54:47'
,
'2023-08-15 18:22:49'
,
NULL
);
COMMIT
;
COMMIT
;
-- ----------------------------
-- ----------------------------
...
...
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