#80 网页端支持删除过期用户
This commit is contained in:
parent
e96de94611
commit
dfc8580eb5
|
@ -3,6 +3,7 @@
|
||||||
package web
|
package web
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"database/sql"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/http/httputil"
|
"net/http/httputil"
|
||||||
|
@ -161,6 +162,39 @@ func addUser() gin.HandlerFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getExpiredUser() gin.HandlerFunc {
|
||||||
|
return func(ctx *gin.Context) {
|
||||||
|
failUser, err := model.QueryFailUser()
|
||||||
|
if err != nil {
|
||||||
|
if err == sql.ErrNoRows {
|
||||||
|
ctx.JSON(200, Resp{
|
||||||
|
Code: 200,
|
||||||
|
Message: "",
|
||||||
|
Data: []model.User{},
|
||||||
|
Success: true,
|
||||||
|
Error: "",
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
ctx.JSON(502, Resp{
|
||||||
|
Code: 502,
|
||||||
|
Message: "",
|
||||||
|
Data: []model.User{},
|
||||||
|
Success: false,
|
||||||
|
Error: err.Error(),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
ctx.JSON(200, Resp{
|
||||||
|
Code: 200,
|
||||||
|
Message: "",
|
||||||
|
Data: failUser,
|
||||||
|
Success: true,
|
||||||
|
Error: "",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getUsers() gin.HandlerFunc {
|
func getUsers() gin.HandlerFunc {
|
||||||
return func(ctx *gin.Context) {
|
return func(ctx *gin.Context) {
|
||||||
users, err := model.Query()
|
users, err := model.Query()
|
||||||
|
|
|
@ -112,6 +112,9 @@ func RouterInit() *gin.Engine {
|
||||||
user.POST("", addUser())
|
user.POST("", addUser())
|
||||||
// 获取所以已登陆的用户
|
// 获取所以已登陆的用户
|
||||||
user.GET("", getUsers())
|
user.GET("", getUsers())
|
||||||
|
|
||||||
|
user.GET("/expired", getExpiredUser())
|
||||||
|
|
||||||
// 删除用户
|
// 删除用户
|
||||||
user.DELETE("", deleteUser())
|
user.DELETE("", deleteUser())
|
||||||
|
|
||||||
|
|
|
@ -1,15 +1,15 @@
|
||||||
{
|
{
|
||||||
"files": {
|
"files": {
|
||||||
"main.css": "/static/xxqg/build/static/css/main.6f1e3389.css",
|
"main.css": "/static/xxqg/build/static/css/main.6f1e3389.css",
|
||||||
"main.js": "/static/xxqg/build/static/js/main.b72f3ffd.js",
|
"main.js": "/static/xxqg/build/static/js/main.0f85b682.js",
|
||||||
"static/js/787.273d6ce9.chunk.js": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js",
|
"static/js/787.273d6ce9.chunk.js": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js",
|
||||||
"index.html": "/static/xxqg/build/index.html",
|
"index.html": "/static/xxqg/build/index.html",
|
||||||
"main.6f1e3389.css.map": "/static/xxqg/build/static/css/main.6f1e3389.css.map",
|
"main.6f1e3389.css.map": "/static/xxqg/build/static/css/main.6f1e3389.css.map",
|
||||||
"main.b72f3ffd.js.map": "/static/xxqg/build/static/js/main.b72f3ffd.js.map",
|
"main.0f85b682.js.map": "/static/xxqg/build/static/js/main.0f85b682.js.map",
|
||||||
"787.273d6ce9.chunk.js.map": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js.map"
|
"787.273d6ce9.chunk.js.map": "/static/xxqg/build/static/js/787.273d6ce9.chunk.js.map"
|
||||||
},
|
},
|
||||||
"entrypoints": [
|
"entrypoints": [
|
||||||
"static/css/main.6f1e3389.css",
|
"static/css/main.6f1e3389.css",
|
||||||
"static/js/main.b72f3ffd.js"
|
"static/js/main.0f85b682.js"
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -1 +1 @@
|
||||||
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/xxqg/build/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/static/xxqg/build/logo192.png"/><link rel="manifest" href="/static/xxqg/build/manifest.json"/><title>Study XXQG</title><script defer="defer" src="/static/xxqg/build/static/js/main.b72f3ffd.js"></script><link href="/static/xxqg/build/static/css/main.6f1e3389.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/static/xxqg/build/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/static/xxqg/build/logo192.png"/><link rel="manifest" href="/static/xxqg/build/manifest.json"/><title>Study XXQG</title><script defer="defer" src="/static/xxqg/build/static/js/main.0f85b682.js"></script><link href="/static/xxqg/build/static/css/main.6f1e3389.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
|
@ -3,9 +3,8 @@ import './App.css';
|
||||||
import {Button, Dialog, Divider, Form, Input, List, Modal, NavBar, Popup, TextArea, Toast,} from "antd-mobile";
|
import {Button, Dialog, Divider, Form, Input, List, Modal, NavBar, Popup, TextArea, Toast,} from "antd-mobile";
|
||||||
import {UnorderedListOutline} from "antd-mobile-icons";
|
import {UnorderedListOutline} from "antd-mobile-icons";
|
||||||
import {ListItem} from "antd-mobile/es/components/list/list-item";
|
import {ListItem} from "antd-mobile/es/components/list/list-item";
|
||||||
import {checkQrCode, getLog, getScore, getToken, getUsers, getLink, stopStudy, study, login, checkToken,getAbout,deleteUser} from "./utils/api";
|
import {checkQrCode, getLog, getScore, getToken, getUsers, getLink, stopStudy, study, login, checkToken,getAbout,deleteUser, getExpiredUsers} from "./utils/api";
|
||||||
import QrCode from 'qrcode.react';
|
import QrCode from 'qrcode.react';
|
||||||
import * as util from "util";
|
|
||||||
|
|
||||||
|
|
||||||
class App extends React.Component<any, any> {
|
class App extends React.Component<any, any> {
|
||||||
|
@ -304,7 +303,8 @@ class Users extends Component<any, any>{
|
||||||
constructor(props: any) {
|
constructor(props: any) {
|
||||||
super(props);
|
super(props);
|
||||||
this.state = {
|
this.state = {
|
||||||
users:[]
|
users:[],
|
||||||
|
expired_users:[]
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -316,6 +316,13 @@ class Users extends Component<any, any>{
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
getExpiredUsers().then(users => {
|
||||||
|
console.log(users)
|
||||||
|
this.setState({
|
||||||
|
expired_users: users.data
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
format = (value:any)=> {
|
format = (value:any)=> {
|
||||||
|
@ -426,6 +433,22 @@ class Users extends Component<any, any>{
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < this.state.expired_users.length; i++) {
|
||||||
|
console.log(this.state.expired_users[i].uid)
|
||||||
|
elements.push(
|
||||||
|
<>
|
||||||
|
<ListItem key={this.state.expired_users[i].uid} style={{border:"blue soild 1px",backgroundColor:"#cdced0"}}>
|
||||||
|
<h3>姓名:{this.state.expired_users[i].nick}</h3>
|
||||||
|
<h3>UID: {this.state.expired_users[i].uid}</h3>
|
||||||
|
<h3>登录时间:{this.format(this.state.expired_users[i].login_time)}</h3>
|
||||||
|
<Button style={{display: this.props.level !== 1 ? "none" : "inline"}} onClick={this.delete_user.bind(this,this.state.expired_users[i].uid,this.state.expired_users[i].nick)} color={"danger"} block={true}>删除用户</Button>
|
||||||
|
</ListItem>
|
||||||
|
<Divider />
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
if (this.state.users.length === 0){
|
if (this.state.users.length === 0){
|
||||||
elements.push(<>
|
elements.push(<>
|
||||||
<span style={{color:"red"}}>未获取到有效用户</span>
|
<span style={{color:"red"}}>未获取到有效用户</span>
|
||||||
|
|
|
@ -73,6 +73,12 @@ export async function getUsers(){
|
||||||
return resp.data
|
return resp.data
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export async function getExpiredUsers(){
|
||||||
|
let resp = await http.get(base+"/user/expired");
|
||||||
|
return resp.data
|
||||||
|
}
|
||||||
|
|
||||||
export async function getScore(token) {
|
export async function getScore(token) {
|
||||||
let resp = await http.get(base+"/score?token="+token);
|
let resp = await http.get(base+"/score?token="+token);
|
||||||
return resp.data;
|
return resp.data;
|
||||||
|
|
Loading…
Reference in New Issue