Skip to content

Commit a5fea3f

Browse files
committed
可以解除用户绑定
1 parent cbdcc8b commit a5fea3f

File tree

3 files changed

+56
-2
lines changed

3 files changed

+56
-2
lines changed

serve/route/index/tree/node/user/attach.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ func Attach(g *echo.Group, code int) {
1515
group.Use(acl.AllowWrite(code))
1616

1717
group.PUT("/add", add)
18+
group.DELETE("/delete", del)
1819
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package user
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/labstack/echo/v4"
7+
8+
"github.com/lucky-byte/reactgo/serve/ctx"
9+
"github.com/lucky-byte/reactgo/serve/db"
10+
)
11+
12+
// 解除用户绑定
13+
func del(c echo.Context) error {
14+
cc := c.(*ctx.Context)
15+
16+
uuid := c.QueryParam("uuid")
17+
if len(uuid) == 0 {
18+
return c.NoContent(http.StatusBadRequest)
19+
}
20+
ql := `delete from tree_bind where uuid = ?`
21+
22+
if err := db.ExecOne(ql, uuid); err != nil {
23+
cc.ErrLog(err).Error("解除用户绑定错")
24+
return c.NoContent(http.StatusInternalServerError)
25+
}
26+
return c.NoContent(http.StatusOK)
27+
}

web/src/route/tree/node/user.jsx

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,23 @@ import Collapse from '@mui/material/Collapse';
3131
import FormControlLabel from '@mui/material/FormControlLabel';
3232
import Switch from '@mui/material/Switch';
3333
import AddIcon from '@mui/icons-material/Add';
34+
import RemoveCircleOutlineIcon from '@mui/icons-material/RemoveCircleOutline';
3435
import { useHotkeys } from 'react-hotkeys-hook';
3536
import { useSnackbar } from 'notistack';
37+
import { useConfirm } from 'material-ui-confirm';
3638
import dayjs from 'dayjs';
3739
import SearchInput from '~/comp/search-input';
3840
import OutlinedPaper from "~/comp/outlined-paper";
3941
import progressState from "~/state/progress";
4042
import titleState from "~/state/title";
4143
import usePageData from '~/hook/pagedata';
42-
import { post, put } from '~/rest';
44+
import { post, put, del } from '~/rest';
4345

4446
export default function User() {
4547
const navigate = useNavigate();
4648
const location = useLocation();
4749
const { enqueueSnackbar } = useSnackbar();
50+
const confirm = useConfirm();
4851
const setTitle = useSetRecoilState(titleState);
4952
const [progress, setProgress] = useRecoilState(progressState);
5053
const [pageData, setPageData] = usePageData();
@@ -105,6 +108,25 @@ export default function User() {
105108
setPageData('rowsPerPage', rows);
106109
}
107110

111+
// 解除绑定
112+
const onRemoveClick = async row => {
113+
try {
114+
await confirm({
115+
description: `确定要解除 ${row.user_name} 的绑定吗?`,
116+
confirmationText: '确定',
117+
confirmationButtonProps: { color: 'warning' },
118+
contentProps: { p: 8 },
119+
});
120+
const params = new URLSearchParams({ uuid: row.uuid });
121+
await del('/tree/node/user/delete?' + params.toString());
122+
setReload(true);
123+
} catch (err) {
124+
if (err) {
125+
enqueueSnackbar(err.message);
126+
}
127+
}
128+
}
129+
108130
// uuid 从上个页面通过 state 传入,如果为空,则可能是直接输入 url 进入该页面
109131
if (!node?.uuid) {
110132
return <Navigate to='..' replace />;
@@ -147,7 +169,11 @@ export default function User() {
147169
<TableCell align="center">
148170
{dayjs(row.create_at).format('YYYY/MM/DD HH:mm:ss')}
149171
</TableCell>
150-
<TableCell padding='checkbox'></TableCell>
172+
<TableCell padding='checkbox'>
173+
<IconButton color='error' onClick={() => onRemoveClick(row)}>
174+
<RemoveCircleOutlineIcon />
175+
</IconButton>
176+
</TableCell>
151177
</TableRow>
152178
))}
153179
</TableBody>

0 commit comments

Comments
 (0)