Skip to content

Commit

Permalink
可以解除用户绑定
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyxhu committed Feb 28, 2022
1 parent cbdcc8b commit a5fea3f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 2 deletions.
1 change: 1 addition & 0 deletions serve/route/index/tree/node/user/attach.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ func Attach(g *echo.Group, code int) {
group.Use(acl.AllowWrite(code))

group.PUT("/add", add)
group.DELETE("/delete", del)
}
27 changes: 27 additions & 0 deletions serve/route/index/tree/node/user/del.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package user

import (
"net/http"

"github.com/labstack/echo/v4"

"github.com/lucky-byte/reactgo/serve/ctx"
"github.com/lucky-byte/reactgo/serve/db"
)

// 解除用户绑定
func del(c echo.Context) error {
cc := c.(*ctx.Context)

uuid := c.QueryParam("uuid")
if len(uuid) == 0 {
return c.NoContent(http.StatusBadRequest)
}
ql := `delete from tree_bind where uuid = ?`

if err := db.ExecOne(ql, uuid); err != nil {
cc.ErrLog(err).Error("解除用户绑定错")
return c.NoContent(http.StatusInternalServerError)
}
return c.NoContent(http.StatusOK)
}
30 changes: 28 additions & 2 deletions web/src/route/tree/node/user.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,23 @@ import Collapse from '@mui/material/Collapse';
import FormControlLabel from '@mui/material/FormControlLabel';
import Switch from '@mui/material/Switch';
import AddIcon from '@mui/icons-material/Add';
import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
import { useHotkeys } from 'react-hotkeys-hook';
import { useSnackbar } from 'notistack';
import { useConfirm } from 'material-ui-confirm';
import dayjs from 'dayjs';
import SearchInput from '~/comp/search-input';
import OutlinedPaper from "~/comp/outlined-paper";
import progressState from "~/state/progress";
import titleState from "~/state/title";
import usePageData from '~/hook/pagedata';
import { post, put } from '~/rest';
import { post, put, del } from '~/rest';

export default function User() {
const navigate = useNavigate();
const location = useLocation();
const { enqueueSnackbar } = useSnackbar();
const confirm = useConfirm();
const setTitle = useSetRecoilState(titleState);
const [progress, setProgress] = useRecoilState(progressState);
const [pageData, setPageData] = usePageData();
Expand Down Expand Up @@ -105,6 +108,25 @@ export default function User() {
setPageData('rowsPerPage', rows);
}

// 解除绑定
const onRemoveClick = async row => {
try {
await confirm({
description: `确定要解除 ${row.user_name} 的绑定吗?`,
confirmationText: '确定',
confirmationButtonProps: { color: 'warning' },
contentProps: { p: 8 },
});
const params = new URLSearchParams({ uuid: row.uuid });
await del('/tree/node/user/delete?' + params.toString());
setReload(true);
} catch (err) {
if (err) {
enqueueSnackbar(err.message);
}
}
}

// uuid 从上个页面通过 state 传入,如果为空,则可能是直接输入 url 进入该页面
if (!node?.uuid) {
return <Navigate to='..' replace />;
Expand Down Expand Up @@ -147,7 +169,11 @@ export default function User() {
<TableCell align="center">
{dayjs(row.create_at).format('YYYY/MM/DD HH:mm:ss')}
</TableCell>
<TableCell padding='checkbox'></TableCell>
<TableCell padding='checkbox'>
<IconButton color='error' onClick={() => onRemoveClick(row)}>
<RemoveCircleOutlineIcon />
</IconButton>
</TableCell>
</TableRow>
))}
</TableBody>
Expand Down

0 comments on commit a5fea3f

Please sign in to comment.