Commit aadd57cf authored by rocosen's avatar rocosen

权限增加

parent 6d7a74d6
...@@ -2,11 +2,51 @@ import { operation, route } from "@/router"; ...@@ -2,11 +2,51 @@ import { operation, route } from "@/router";
import { useStores } from "@/store"; import { useStores } from "@/store";
import { useCallback } from "react"; import { useCallback } from "react";
const roleList: any[] = [
{ VIEWER: 1 },
{ USER: 2 },
{ MANAGER: 3 },
{ OWNER: 4 }
]
const usePass = () => { const usePass = () => {
const { permissionStore } = useStores(); const { permissionStore } = useStores();
const { currentProjectStore } = useStores();
const isPass = useCallback( const isPass = useCallback(
(key: string, routes?: Array<route | operation>): boolean => { (key: string, role?: "VIEWER" | "USER" | "MANAGER" | "OWNER", routes?: Array<route | operation>): boolean => {
let code = currentProjectStore && currentProjectStore.currentProjectInfo.projectRole
if (role) {
if (code && roleList.filter(e => e[role])[0][role] <= roleList.filter(e => e[code as string])[0][code]) {
if (routes) {
for (let item of routes) {
if (item.id === key) {
return true;
} else if (
item.type === "page" &&
item.children?.length &&
isPass(key, role, item.children)
) {
return true;
}
}
} else {
for (let item of permissionStore.allRoutes) {
if (item.type !== "navigate" && item.id === key) {
return true;
} else if (
item.type === "page" &&
item.children?.length &&
isPass(key, role, item.children)
) {
return true;
}
}
}
} else {
return false
}
} else {
if (routes) { if (routes) {
for (let item of routes) { for (let item of routes) {
if (item.id === key) { if (item.id === key) {
...@@ -14,7 +54,7 @@ const usePass = () => { ...@@ -14,7 +54,7 @@ const usePass = () => {
} else if ( } else if (
item.type === "page" && item.type === "page" &&
item.children?.length && item.children?.length &&
isPass(key, item.children) isPass(key, role, item.children)
) { ) {
return true; return true;
} }
...@@ -26,12 +66,13 @@ const usePass = () => { ...@@ -26,12 +66,13 @@ const usePass = () => {
} else if ( } else if (
item.type === "page" && item.type === "page" &&
item.children?.length && item.children?.length &&
isPass(key, item.children) isPass(key, role, item.children)
) { ) {
return true; return true;
} }
} }
} }
}
return false; return false;
}, },
[permissionStore.allRoutes] [permissionStore.allRoutes]
......
...@@ -8,12 +8,25 @@ import { stores } from "@/store/index"; ...@@ -8,12 +8,25 @@ import { stores } from "@/store/index";
import { MySnackbarProvider } from "@/components/MySnackbar"; import { MySnackbarProvider } from "@/components/MySnackbar";
import "@/mocks/index"; import "@/mocks/index";
import './assets/style/public.css' import './assets/style/public.css'
import { createTheme, ThemeProvider, styled } from '@mui/material/styles';
const root = ReactDOM.createRoot( const root = ReactDOM.createRoot(
document.getElementById("root") as HTMLElement document.getElementById("root") as HTMLElement
); );
const theme = createTheme({
typography: {
fontFamily: ['Roboto', 'Helvetica', 'Tahoma', 'Arial', '"PingFang SC"', '"Hiragino Sans GB"', '"Heiti SC"', '"WenQuanYi Micro Hei"', 'sans-serif', '"Apple Color Emoji"', '"Segoe UI Emoji"', '"Segoe UI Symbol"'].join(','),
},
palette: {
primary: { main: '#136EFA' },
secondary: { main: '#4EB9FB' }
}
});
root.render( root.render(
<React.StrictMode> <React.StrictMode>
<ThemeProvider theme={theme}>
<Provider {...stores}> <Provider {...stores}>
<MySnackbarProvider <MySnackbarProvider
alertSx={{ boxShadow: "0px 2px 4px 0px rgb(0 0 0 / 8%)" }} alertSx={{ boxShadow: "0px 2px 4px 0px rgb(0 0 0 / 8%)" }}
...@@ -21,6 +34,7 @@ root.render( ...@@ -21,6 +34,7 @@ root.render(
<MyRouter></MyRouter> <MyRouter></MyRouter>
</MySnackbarProvider> </MySnackbarProvider>
</Provider> </Provider>
</ThemeProvider>
</React.StrictMode> </React.StrictMode>
); );
......
...@@ -3,6 +3,7 @@ type projectInfo = { ...@@ -3,6 +3,7 @@ type projectInfo = {
id?: string; id?: string;
name?: string; name?: string;
desc?: string; desc?: string;
projectRole?: string;
}; };
type productInfo = { type productInfo = {
......
...@@ -25,7 +25,7 @@ const ProjectWorkbench = observer(() => { ...@@ -25,7 +25,7 @@ const ProjectWorkbench = observer(() => {
useEffect(() => { useEffect(() => {
console.log(isPass("PROJECT_WORKBENCH_FLOES"), "11111111111"); console.log(isPass("PROJECT_WORKBENCH_FLOES_USE",'USER'), "11111111111");
}, []) }, [])
const tabList = useMemo(() => { const tabList = useMemo(() => {
......
import { memo, useCallback, useEffect, useMemo, useState } from "react"; import { memo, useCallback, useEffect, useMemo, useState } from "react";
import styles from "../index.module.css"; import styles from "../index.module.css";
import { Box, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
...@@ -9,39 +7,22 @@ import Dialog from "@/components/mui/Dialog"; ...@@ -9,39 +7,22 @@ import Dialog from "@/components/mui/Dialog";
import OutlinedInput from "@mui/material/OutlinedInput"; import OutlinedInput from "@mui/material/OutlinedInput";
import SearchIcon from "@mui/icons-material/Search"; import SearchIcon from "@mui/icons-material/Search";
import Checkbox from '@mui/material/Checkbox'; import Checkbox from '@mui/material/Checkbox';
import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined'; import CloseOutlinedIcon from '@mui/icons-material/CloseOutlined';
import _ from "lodash"; import _ from "lodash";
const AddTemplate = (props: any) => { const AddTemplate = (props: any) => {
const { openAddTemplate, closeAddTemplateBlock, addTemplateList, templateSelectCallback, selectTemplateData, addTemplateCallback, searchTemplateNameCallback } = props; const { openAddTemplate, closeAddTemplateBlock, addTemplateList, templateSelectCallback, selectTemplateData, addTemplateCallback, searchTemplateNameCallback } = props;
useEffect(() => {
}, []);
// if (!openAddTemplate) return ""
return ( return (
<Box className={styles.addTemplateMask} sx={{ display: openAddTemplate ? 'flex' : 'none' }} > <Box className={styles.addTemplateMask} sx={{ display: openAddTemplate ? 'flex' : 'none' }} >
<Box sx={{ height: '50px', display: 'flex', alignItems: 'center' }} > <Box sx={{ height: '50px', display: 'flex', alignItems: 'center' }} >
<CloseOutlinedIcon sx={{ color: "#ffffff", marginRight: "10px", cursor: "pointer" }} onClick={() => { <CloseOutlinedIcon sx={{ color: "#ffffff", marginRight: "10px", cursor: "pointer" }} onClick={() => {
closeAddTemplateBlock() closeAddTemplateBlock()
}} /> }} />
</Box> </Box>
<Box className={styles.addTemplateBlock}> <Box className={styles.addTemplateBlock}>
<Box sx={{ padding: "24px 32px" }}> <Box sx={{ padding: "24px 32px" }}>
<Typography sx={{ fontSize: '18px', fontWeight: '600', color: "#1E2633" }}>添加工作流模版</Typography> <Typography sx={{ fontSize: '18px', fontWeight: '600', color: "#1E2633" }}>添加工作流模版</Typography>
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: "20px" }}> <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', marginBottom: "20px" }}>
<OutlinedInput <OutlinedInput
onChange={(e: any) => { onChange={(e: any) => {
...@@ -73,53 +54,22 @@ const AddTemplate = (props: any) => { ...@@ -73,53 +54,22 @@ const AddTemplate = (props: any) => {
}} }}
sx={{ border: selectTemplateData.includes(item.id) ? '1px solid #1370FF' : "1px solid #EBEDF0;" }} sx={{ border: selectTemplateData.includes(item.id) ? '1px solid #1370FF' : "1px solid #EBEDF0;" }}
> >
<Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', }}> <Box sx={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', }}>
<Typography sx={{ fontSize: '14px', fontWeight: '600', color: '#1E2633', marginBottom: "4px", overflow: 'hidden', textOverflow: 'ellipsis' }}>{item.title}</Typography>
<Typography sx={{ fontSize: '14px', fontWeight: '600', color: '#1E2633', marginBottom: "4px" }}>{item.title}</Typography>
<Checkbox size="small" sx={{ padding: "0px" }} checked={selectTemplateData.includes(item.id)} /> <Checkbox size="small" sx={{ padding: "0px" }} checked={selectTemplateData.includes(item.id)} />
</Box> </Box>
<Box sx={{ display: 'flex', marginBottom: "8px" }}> <Box sx={{ display: 'flex', marginBottom: "8px" }}>
<Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF', marginRight: "24px" }}>版本:{item.version}</Typography> <Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF', marginRight: "24px" }}>版本:{item.version}</Typography>
<Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF' }}>更新时间:{item.updateTime}</Typography> <Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF' }}>更新时间:{item.updateTime}</Typography>
</Box> </Box>
<Typography className={styles.templateDescText} >{item.description}</Typography>
<Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#8A9099' }}>{item.description}</Typography>
</Box> </Box>
) )
}) })
} }
</Box> </Box>
</Box> </Box>
{/* */}
</Box> </Box>
</Box> </Box>
); );
}; };
......
import { memo, useCallback, useEffect, useMemo, useState } from "react"; import { memo, useCallback, useEffect, useMemo, useState } from "react";
import styles from "../index.module.css"; import styles from "../index.module.css";
import { Box, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import Dialog from "@/components/mui/Dialog"; import Dialog from "@/components/mui/Dialog";
const SimpleDialog = (props: any) => { const SimpleDialog = (props: any) => {
const { openDialog, closeDialog, onConfirm, text, title } = props; const { openDialog, closeDialog, onConfirm, text, title } = props;
useEffect(() => {
}, []);
return ( return (
< > < >
<Dialog <Dialog
open={openDialog} open={openDialog}
onClose={closeDialog} onClose={closeDialog}
...@@ -33,10 +20,6 @@ const SimpleDialog = (props: any) => { ...@@ -33,10 +20,6 @@ const SimpleDialog = (props: any) => {
<Typography sx={{ fontSize: '14px', fontWeight: '400' }}>{text}</Typography> <Typography sx={{ fontSize: '14px', fontWeight: '400' }}>{text}</Typography>
</Box> </Box>
</Dialog> </Dialog>
</> </>
); );
}; };
......
import { memo, useCallback, useEffect, useMemo, useState } from "react"; import { memo, useCallback, useEffect, useMemo, useState } from "react";
import styles from "../index.module.css"; import styles from "../index.module.css";
import { Box, Typography } from "@mui/material"; import { Box, Typography } from "@mui/material";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import usePass from "@/hooks/usePass";
const TemplateBox = (props: any) => { const TemplateBox = (props: any) => {
// const deleteTemplate props
const info = props.data const info = props.data
const isPass = usePass();
useEffect(() => {
}, []);
return ( return (
<Box className={styles.templateBlock} > <Box className={styles.templateBlock} >
<Box> <Box>
<Typography sx={{ fontSize: '14px', fontWeight: '600', color: '#1E2633', marginBottom: "4px" }}>{info.title}</Typography> <Typography sx={{ fontSize: '14px', fontWeight: '600', color: '#1E2633', marginBottom: "4px", overflow: 'hidden', textOverflow: 'ellipsis' }}>{info.title}</Typography>
<Box sx={{ display: 'flex', marginBottom: "8px" }} > <Box sx={{ display: 'flex', marginBottom: "8px" }} >
<Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF', marginRight: "24px" }}>版本:{info.version}</Typography> <Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF', marginRight: "24px" }}>版本:{info.version}</Typography>
<Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF' }}>更新时间:{info.updateTime}</Typography> <Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#1370FF' }}>更新时间:{info.updateTime}</Typography>
</Box> </Box>
<Typography className={styles.templateDescText} >{info.description}</Typography>
<Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#8A9099' }}>{info.description}</Typography>
</Box> </Box>
<Box sx={{ <Box sx={{
display: 'flex', justifyContent: 'end' display: 'flex', justifyContent: 'end'
}} > }} >
<Button {
isPass("PROJECT_WORKBENCH_FLOES_USE", 'MANAGER') && <Button
style={{ backgroundColor: "#F0F2F5", color: "#565C66" }} style={{ backgroundColor: "#F0F2F5", color: "#565C66" }}
variant="contained" variant="contained"
onClick={() => { props.startDialog(info.id) }} onClick={() => { props.startDialog(info.id) }}
...@@ -54,8 +31,9 @@ const TemplateBox = (props: any) => { ...@@ -54,8 +31,9 @@ const TemplateBox = (props: any) => {
> >
删除模版 删除模版
</Button> </Button>
}
<Button {
isPass("PROJECT_WORKBENCH_FLOES_USE", 'USER') && <Button
style={{ backgroundColor: "#1370FF", marginLeft: "12px" }} style={{ backgroundColor: "#1370FF", marginLeft: "12px" }}
variant="contained" variant="contained"
// onClick={addTemplateBlock} // onClick={addTemplateBlock}
...@@ -63,11 +41,8 @@ const TemplateBox = (props: any) => { ...@@ -63,11 +41,8 @@ const TemplateBox = (props: any) => {
> >
使用模版 使用模版
</Button> </Button>
}
</Box> </Box>
</Box> </Box>
); );
}; };
......
...@@ -67,3 +67,28 @@ ...@@ -67,3 +67,28 @@
.addTemplateBox:hover { .addTemplateBox:hover {
box-shadow: 6px 8px 22px 0px rgba(0, 24, 57, 0.08); box-shadow: 6px 8px 22px 0px rgba(0, 24, 57, 0.08);
} }
.templateDescText {
overflow: hidden;
text-overflow: ellipsis;
-webkit-box-orient: vertical;
-webkit-line-clamp: 3;
display: -webkit-box;
height: 54px;
font-size: 12px !important;
font-weight: 400 !important;
color: #8A9099 !important;
}
.addNewTemplate {
width: 380px;
height: 194px;
background: #FFFFFF;
border-radius: 4px;
border: 1px solid #EBEDF0;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
cursor: pointer;
}
\ No newline at end of file
...@@ -13,34 +13,26 @@ import OutlinedInput from "@mui/material/OutlinedInput"; ...@@ -13,34 +13,26 @@ import OutlinedInput from "@mui/material/OutlinedInput";
import SearchIcon from "@mui/icons-material/Search"; import SearchIcon from "@mui/icons-material/Search";
// import Button from "@/components/mui/Button"; // import Button from "@/components/mui/Button";
import Button from "@mui/material/Button"; import Button from "@mui/material/Button";
import Add from "@mui/icons-material/Add"; import Add from "@mui/icons-material/Add";
import useMyRequest from "@/hooks/useMyRequest"; import useMyRequest from "@/hooks/useMyRequest";
import TemplateBox from "./components/templateBox" import TemplateBox from "./components/templateBox"
import SimpleDialog from "./components/simpleDialog" import SimpleDialog from "./components/simpleDialog"
import AddTemplate from "./components/addTemplate" import AddTemplate from "./components/addTemplate"
import noData from '../../../../assets/project/noTemplate.svg' import noData from '../../../../assets/project/noTemplate.svg'
import { import {
getWorkbenchTemplate, getWorkbenchTemplate,
deleteWorkbenchTemplate, deleteWorkbenchTemplate,
getAddWorkbenchTemplate, getAddWorkbenchTemplate,
addWorkbenchTemplate addWorkbenchTemplate
} from "@/api/workbench_api"; } from "@/api/workbench_api";
import _ from "lodash"; import _ from "lodash";
import { IResponse, useHttp } from "@/api/http"; import { IResponse, useHttp } from "@/api/http";
import { useStores } from "@/store"; import { useStores } from "@/store";
import usePass from "@/hooks/usePass";
const ProjectMembers = () => { const ProjectMembers = () => {
const { currentProjectStore } = useStores(); const { currentProjectStore } = useStores();
const isPass = usePass();
/** 搜索模板名称 */ /** 搜索模板名称 */
const [templateName, setTemplateName] = useState(""); const [templateName, setTemplateName] = useState("");
...@@ -57,8 +49,6 @@ const ProjectMembers = () => { ...@@ -57,8 +49,6 @@ const ProjectMembers = () => {
/** 已选择增加的模板列表 */ /** 已选择增加的模板列表 */
const [selectTemplateData, setSelectTemplateData] = useState<string[]>([]); const [selectTemplateData, setSelectTemplateData] = useState<string[]>([]);
// 获取模板列表 // 获取模板列表
const { run: getTemplateInfo } = useMyRequest(getWorkbenchTemplate, { const { run: getTemplateInfo } = useMyRequest(getWorkbenchTemplate, {
onSuccess: (result: any) => { onSuccess: (result: any) => {
...@@ -96,18 +86,12 @@ const ProjectMembers = () => { ...@@ -96,18 +86,12 @@ const ProjectMembers = () => {
}, },
}); });
useEffect(() => { useEffect(() => {
getTemplateInfo({ getTemplateInfo({
projectId: currentProjectStore.currentProjectInfo.id as string, projectId: currentProjectStore.currentProjectInfo.id as string,
}); });
}, [currentProjectStore.currentProjectInfo.id, getTemplateInfo]); }, [currentProjectStore.currentProjectInfo.id, getTemplateInfo]);
/** 点击添加工作流模版 */ /** 点击添加工作流模版 */
const onAddMember = () => { const onAddMember = () => {
// setAddMemberDialog(true); // setAddMemberDialog(true);
...@@ -175,7 +159,6 @@ const ProjectMembers = () => { ...@@ -175,7 +159,6 @@ const ProjectMembers = () => {
} }
useEffect(() => { useEffect(() => {
getTemplateInfo({ getTemplateInfo({
projectId: currentProjectStore.currentProjectInfo.id as string, projectId: currentProjectStore.currentProjectInfo.id as string,
...@@ -183,7 +166,6 @@ const ProjectMembers = () => { ...@@ -183,7 +166,6 @@ const ProjectMembers = () => {
}); });
}, [templateName]); }, [templateName]);
return ( return (
<Box className={styles.headerBox}> <Box className={styles.headerBox}>
...@@ -200,7 +182,8 @@ const ProjectMembers = () => { ...@@ -200,7 +182,8 @@ const ProjectMembers = () => {
endAdornment={<SearchIcon style={{ color: "#8A9099" }} />} endAdornment={<SearchIcon style={{ color: "#8A9099" }} />}
/> />
<Button {
templateList.length > 0 && isPass("PROJECT_WORKBENCH_FLOES_ADD", 'MANAGER') && <Button
style={{ backgroundColor: "#1370FF " }} style={{ backgroundColor: "#1370FF " }}
variant="contained" variant="contained"
onClick={addTemplateBlock} onClick={addTemplateBlock}
...@@ -209,11 +192,12 @@ const ProjectMembers = () => { ...@@ -209,11 +192,12 @@ const ProjectMembers = () => {
> >
添加工作流模版 添加工作流模版
</Button> </Button>
}
</Box> </Box>
{ {
templateList.length === 0 && templateList.length === 0 && !isPass("PROJECT_WORKBENCH_FLOES_ADD", 'MANAGER') &&
<Box sx={{ <Box sx={{
display: 'flex', alignItems: 'center', flexDirection: 'column', minHeight: 'calc(100vh - 376px)', display: 'flex', alignItems: 'center', flexDirection: 'column', minHeight: 'calc(100vh - 376px)',
justifyContent: 'center' justifyContent: 'center'
...@@ -222,15 +206,23 @@ const ProjectMembers = () => { ...@@ -222,15 +206,23 @@ const ProjectMembers = () => {
<Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#8A9099' }}>暂未开启模版</Typography> <Typography sx={{ fontSize: '12px', fontWeight: '400', color: '#8A9099' }}>暂未开启模版</Typography>
</Box> </Box>
} }
{
<Box sx={{ display: "flex", flexWrap: 'wrap', marginLeft: "-8px" }} > templateList.length > 0 && <Box sx={{ display: "flex", flexWrap: 'wrap', marginLeft: "-8px" }} >
{ {
templateList && templateList.length > 0 && templateList.map((item, key) => { templateList && templateList.length > 0 && templateList.map((item, key) => {
return <TemplateBox data={item} startDialog={startDialog} /> return <TemplateBox data={item} startDialog={startDialog} />
}) })
} }
</Box> </Box>
}
{
templateList.length === 0 && isPass("PROJECT_WORKBENCH_FLOES_ADD", 'MANAGER') && <Box className={styles.addNewTemplate}
onClick={addTemplateBlock}
>
<Add sx={{ color: "#565C66", fontSize: "20px", width: "30px", height: '30px' }} />
<Typography sx={{ fontSize: '14px', fontWeight: '400', color: '#8A9099', marginTop: "15px" }}>添加工作流模版</Typography>
</Box>
}
<AddTemplate <AddTemplate
openAddTemplate={openAddTemplate} openAddTemplate={openAddTemplate}
...@@ -242,7 +234,6 @@ const ProjectMembers = () => { ...@@ -242,7 +234,6 @@ const ProjectMembers = () => {
searchTemplateNameCallback={searchTemplateNameCallback} searchTemplateNameCallback={searchTemplateNameCallback}
/> />
<SimpleDialog <SimpleDialog
text={'确认移除该模板吗?'} text={'确认移除该模板吗?'}
title={'删除模板'} title={'删除模板'}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment