后台添加查询玩家数据的功能
This commit is contained in:
parent
2dd22eebfa
commit
06b6123855
@ -2,14 +2,14 @@ package v1
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/gameUser"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/user"
|
||||
)
|
||||
|
||||
var ApiGroupApp = new(ApiGroup)
|
||||
|
||||
type ApiGroup struct {
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
UserApiGroup user.ApiGroup
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
GameUserApiGroup gameUser.ApiGroup
|
||||
}
|
||||
|
5
admin/server/api/v1/gameUser/enter.go
Normal file
5
admin/server/api/v1/gameUser/enter.go
Normal file
@ -0,0 +1,5 @@
|
||||
package gameUser
|
||||
|
||||
type ApiGroup struct {
|
||||
GameUserApi
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package user
|
||||
package gameUser
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
@ -7,23 +7,21 @@ import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
||||
us "github.com/flipped-aurora/gin-vue-admin/server/service/user"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/utils"
|
||||
"github.com/gin-gonic/gin"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
type UserApi struct{}
|
||||
type GameUserApi struct{}
|
||||
|
||||
func (e *UserApi) GetUserById(c *gin.Context) {
|
||||
func (e *GameUserApi) GetUserById(c *gin.Context) {
|
||||
var gameUser = &user.GameUser{}
|
||||
err := c.ShouldBindJSON(&gameUser)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
return
|
||||
}
|
||||
err = utils.Verify(gameUser, utils.IdVerify)
|
||||
if err != nil {
|
||||
response.FailWithMessage(err.Error(), c)
|
||||
if gameUser.ID < 1 {
|
||||
response.FailWithMessage(fmt.Sprintf("玩家id不能为0"), c)
|
||||
return
|
||||
}
|
||||
|
@ -1,5 +0,0 @@
|
||||
package user
|
||||
|
||||
type ApiGroup struct {
|
||||
UserApi
|
||||
}
|
@ -53,7 +53,7 @@ func Routers() *gin.Engine {
|
||||
|
||||
systemRouter := router.RouterGroupApp.System
|
||||
exampleRouter := router.RouterGroupApp.Example
|
||||
userRouter := router.RouterGroupApp.User
|
||||
gameUserRouter := router.RouterGroupApp.GameUser
|
||||
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
|
||||
// VUE_APP_BASE_API = /
|
||||
// VUE_APP_BASE_PATH = http://localhost
|
||||
@ -111,7 +111,7 @@ func Routers() *gin.Engine {
|
||||
}
|
||||
|
||||
{
|
||||
userRouter.InitUserRouter(PrivateGroup, PublicGroup)
|
||||
gameUserRouter.InitGameUserRouter(PrivateGroup, PublicGroup)
|
||||
}
|
||||
|
||||
//插件路由安装
|
||||
|
@ -2,14 +2,14 @@ package router
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/gameUser"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/user"
|
||||
)
|
||||
|
||||
var RouterGroupApp = new(RouterGroup)
|
||||
|
||||
type RouterGroup struct {
|
||||
System system.RouterGroup
|
||||
Example example.RouterGroup
|
||||
User user.RouterGroup
|
||||
System system.RouterGroup
|
||||
Example example.RouterGroup
|
||||
GameUser gameUser.GameUserRouter
|
||||
}
|
||||
|
@ -1,11 +1,11 @@
|
||||
package user
|
||||
package gameUser
|
||||
|
||||
import api "github.com/flipped-aurora/gin-vue-admin/server/api/v1"
|
||||
|
||||
type RouterGroup struct {
|
||||
UserRouter
|
||||
GameUserRouter
|
||||
}
|
||||
|
||||
var (
|
||||
userApi = api.ApiGroupApp.UserApiGroup.UserApi
|
||||
gameUserApi = api.ApiGroupApp.GameUserApiGroup.GameUserApi
|
||||
)
|
18
admin/server/router/gameUser/user.go
Normal file
18
admin/server/router/gameUser/user.go
Normal file
@ -0,0 +1,18 @@
|
||||
package gameUser
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type GameUserRouter struct{}
|
||||
|
||||
func (s *GameUserRouter) InitGameUserRouter(Router *gin.RouterGroup, RouterPub *gin.RouterGroup) {
|
||||
_ = RouterPub
|
||||
router := Router.Group("gameUser").Use(middleware.OperationRecord())
|
||||
|
||||
{
|
||||
router.PUT("getUserById", gameUserApi.GetUserById) // 获取玩家信息
|
||||
}
|
||||
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/middleware"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type UserRouter struct{}
|
||||
|
||||
func (s *UserRouter) InitUserRouter(Router *gin.RouterGroup, RouterPub *gin.RouterGroup) {
|
||||
_ = RouterPub
|
||||
router := Router.Group("user").Use(middleware.OperationRecord())
|
||||
|
||||
{
|
||||
router.GET("getUserById", userApi.GetUserById) // 获取玩家信息
|
||||
}
|
||||
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGetUserById(t *testing.T) {
|
||||
r := gin.Default()
|
||||
r.GET("/user/getUser", userApi.GetUserById)
|
||||
|
||||
req, _ := http.NewRequest("GET", "/user/getUser?id=123", nil)
|
||||
w := httptest.NewRecorder()
|
||||
r.ServeHTTP(w, req)
|
||||
|
||||
assert.Equal(t, http.StatusOK, w.Code)
|
||||
t.Logf("Response: %s", w.Body.String())
|
||||
}
|
@ -2,6 +2,7 @@ package servicex
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/gameService"
|
||||
"game/common/proto/pb"
|
||||
"game/common/serviceName"
|
||||
config "github.com/flipped-aurora/gin-vue-admin/server/configx"
|
||||
@ -13,7 +14,7 @@ import (
|
||||
var servers []*AdminService
|
||||
|
||||
type AdminService struct {
|
||||
*service.NatsService
|
||||
*gameService.GameService
|
||||
}
|
||||
|
||||
func GetService() *AdminService {
|
||||
@ -42,11 +43,10 @@ func Stop() {
|
||||
}
|
||||
|
||||
func newService(serviceId int) *AdminService {
|
||||
var err error
|
||||
s := new(AdminService)
|
||||
|
||||
sName := fmt.Sprintf("%v-%d", serviceName.Admin, serviceId)
|
||||
if s.NatsService, err = service.NewNatsService(&service.InitNatsServiceParams{
|
||||
s.GameService = gameService.NewGameService(&service.InitNatsServiceParams{
|
||||
EtcdAddress: config.Cfg.Etcd.Address,
|
||||
EtcdUsername: "",
|
||||
EtcdPassword: "",
|
||||
@ -56,10 +56,7 @@ func newService(serviceId int) *AdminService {
|
||||
OnFunc: s,
|
||||
TypeId: int(pb.ServiceTypeId_STI_Admin),
|
||||
Version: config.Cfg.BuildDate,
|
||||
}); err != nil {
|
||||
log.Fatal(err.Error())
|
||||
return nil
|
||||
}
|
||||
}, &config.Cfg.Redis)
|
||||
|
||||
//s.initRpcProcessor()
|
||||
s.OnInit()
|
||||
|
@ -4,8 +4,8 @@ import request from '@/utils/request'
|
||||
|
||||
export function getUserById(params) {
|
||||
return request({
|
||||
url: '/user/getUserById',
|
||||
method: 'get',
|
||||
url: '/gameUser/getUserById',
|
||||
method: 'put',
|
||||
data: params
|
||||
})
|
||||
}
|
@ -18,7 +18,6 @@
|
||||
"/src/view/example/index.vue": "Example",
|
||||
"/src/view/example/upload/scanUpload.vue": "scanUpload",
|
||||
"/src/view/example/upload/upload.vue": "Upload",
|
||||
"/src/view/gameuser/gggg/user.vue": "User",
|
||||
"/src/view/gameuser/index.vue": "Index",
|
||||
"/src/view/init/index.vue": "Init",
|
||||
"/src/view/layout/aside/asideComponent/asyncSubmenu.vue": "AsyncSubmenu",
|
||||
@ -70,7 +69,6 @@
|
||||
"/src/view/systemTools/installPlugin/index.vue": "Index",
|
||||
"/src/view/systemTools/pubPlug/pubPlug.vue": "PubPlug",
|
||||
"/src/view/systemTools/system/system.vue": "Config",
|
||||
"/src/view/test/test.vue": "Test",
|
||||
"/src/plugin/announcement/form/info.vue": "InfoForm",
|
||||
"/src/plugin/announcement/view/info.vue": "Info",
|
||||
"/src/plugin/email/view/index.vue": "Email"
|
||||
|
@ -1,26 +1,146 @@
|
||||
<!--<template>-->
|
||||
<!-- <div>-->
|
||||
<!-- <router-view v-slot="{ Component }">-->
|
||||
<!-- <transition mode="out-in" name="el-fade-in-linear">-->
|
||||
<!-- <keep-alive :include="routerStore.keepAliveRouters">-->
|
||||
<!-- <component :is="Component" />-->
|
||||
<!-- </keep-alive>-->
|
||||
<!-- </transition>-->
|
||||
<!-- </router-view>-->
|
||||
<!-- </div>-->
|
||||
<!--</template>-->
|
||||
|
||||
<!--<script setup>-->
|
||||
<!-- import { useRouterStore } from '@/pinia/modules/router'-->
|
||||
<!-- const routerStore = useRouterStore()-->
|
||||
|
||||
<!-- defineOptions({-->
|
||||
<!-- name: 'User'-->
|
||||
<!-- })-->
|
||||
<!--</script>-->
|
||||
|
||||
<!-- src/views/UserManagement.vue -->
|
||||
<template>
|
||||
<div>
|
||||
test
|
||||
<div class="user-management">
|
||||
<div class="gva-search-box">
|
||||
<!-- 这里将放置搜索表单 -->
|
||||
<el-form :inline="true" class="search-form" :model="searchInfo">
|
||||
<el-form-item label="用户id">
|
||||
<el-input v-model="searchInfo.id" placeholder=""></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item label="用户昵称">
|
||||
<el-input v-model="searchInfo.nickname" placeholder="昵称"></el-input>
|
||||
</el-form-item>
|
||||
<el-form-item>
|
||||
<el-button type="primary" @click="onGetUser">查询</el-button>
|
||||
</el-form-item>
|
||||
</el-form>
|
||||
</div>
|
||||
<div class="gva-search-box">
|
||||
<!-- 这里将放置用户表格 -->
|
||||
<el-table :data="userList" border style="width: 100%">
|
||||
<el-table-column prop="id" label="id" align="left" min-width="150"></el-table-column>
|
||||
<el-table-column prop="nickname" label="用户昵称" align="left" min-width="150"></el-table-column>
|
||||
<el-table-column prop="gold" label="金币" align="left" min-width="150"></el-table-column>
|
||||
<el-table-column prop="status" label="状态" align="left" min-width="150">
|
||||
<template #default="scope">
|
||||
{{statusMap[scope.row.status]|| '未知状态' }}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column label="操作" width="200">
|
||||
<template #default="scope">
|
||||
<el-button size="small" type="danger">封号|解封</el-button>
|
||||
<el-button size="small">添加资源</el-button>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
||||
<script>
|
||||
import {getUserById} from "@/api/gameUser";
|
||||
|
||||
export default {
|
||||
name: 'UserManagement',
|
||||
data() {
|
||||
return {
|
||||
searchInfo :{
|
||||
id: 0,
|
||||
nickname: '',
|
||||
},
|
||||
statusMap : {
|
||||
0: '正常',
|
||||
1: '禁用',
|
||||
2:'白名单',
|
||||
},
|
||||
userList: [
|
||||
// {
|
||||
// id: 1,
|
||||
// nickname: '赵今麦',
|
||||
// gold: 1501,
|
||||
// status:0,
|
||||
// },
|
||||
// {
|
||||
// id: 2,
|
||||
// nickname: '高圆圆',
|
||||
// gold: 1502,
|
||||
// status:1,
|
||||
// },
|
||||
// {
|
||||
// id: 3,
|
||||
// nickname: '刘亦菲',
|
||||
// gold: 1502,
|
||||
// status:2,
|
||||
// },
|
||||
]
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
async onGetUser(){
|
||||
// 显示加载状态
|
||||
const loading = this.$loading({
|
||||
lock: true,
|
||||
text: '加载中...',
|
||||
spinner: 'el-icon-loading',
|
||||
background: 'rgba(0, 0, 0, 0.7)'
|
||||
})
|
||||
try {
|
||||
// this.userList = [
|
||||
// {
|
||||
// id: 1,
|
||||
// nickname: '赵今麦',
|
||||
// gold: 1501,
|
||||
// status:0,
|
||||
// },
|
||||
// {
|
||||
// id: 2,
|
||||
// nickname: '高圆圆',
|
||||
// gold: 1502,
|
||||
// status:1,
|
||||
// },
|
||||
// {
|
||||
// id: 3,
|
||||
// nickname: '刘亦菲',
|
||||
// gold: 1502,
|
||||
// status:2,
|
||||
// },
|
||||
// ]
|
||||
const id = this.searchInfo.id // 或者从其他地方获取ID
|
||||
if (id) {
|
||||
const response = await getUserById({id:+id})
|
||||
if (response.code !== 0) {
|
||||
console.error('获取玩家数据失败:', response.msg || `请求失败,错误码: ${response.code}`)
|
||||
this.$message.error('获取用户数据失败:'+(response.msg || `请求失败,错误码: ${response.code}`))
|
||||
return
|
||||
}
|
||||
console.error('获取玩家数据:', response.data.user)
|
||||
this.userList = [
|
||||
{
|
||||
id:response.data.user.id,
|
||||
nickname:response.data.user.nickname,
|
||||
gold:response.data.user.gold,
|
||||
status:response.data.user.status,
|
||||
},
|
||||
]
|
||||
} else {
|
||||
this.$message.warning('请输入用户ID')
|
||||
}
|
||||
}catch (error){
|
||||
console.error('获取玩家数据失败:', error)
|
||||
this.$message.error('获取用户数据失败:'+error)
|
||||
}finally {
|
||||
// 关闭加载状态
|
||||
loading.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.user-management {
|
||||
padding: 20px;
|
||||
}
|
||||
</style>
|
||||
|
||||
|
@ -20,7 +20,7 @@ type UserAccount struct {
|
||||
DeviceID string `gorm:"type:varchar(64);index" json:"device_id"` // 设备ID
|
||||
LastLoginIP string `gorm:"type:varchar(45)" json:"last_login_ip"` // 最后登录IP(支持IPv6)
|
||||
LastLoginTime time.Time `json:"last_login_time"` // 最后登录时间
|
||||
Status int `gorm:"type:tinyint;default:1" json:"status"` // 账号状态 1-正常 2-冻结 3-封禁
|
||||
Status int `gorm:"type:tinyint;default:1" json:"status"` // 账号状态 1:正常 2:冻结 3:封禁 4:白名单
|
||||
RegisterIP string `gorm:"type:varchar(45)" json:"register_ip"` // 注册IP
|
||||
RegisterTime time.Time `gorm:"type:TIMESTAMP;default:CURRENT_TIMESTAMP" json:"register_time"` // 注册时间
|
||||
}
|
||||
|
@ -4,8 +4,8 @@ import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"game/common/model"
|
||||
"game/common/model/user"
|
||||
"game/common/modelOperator"
|
||||
"game/common/proto/pb"
|
||||
"game/common/serialization"
|
||||
"game/common/utils"
|
||||
@ -19,7 +19,7 @@ type UserAccountOp struct {
|
||||
logDb *gorm.DB
|
||||
db *gorm.DB
|
||||
accountRedis *redis.Client
|
||||
accountOp *model.TableOp[user.UserAccount]
|
||||
accountOp *modelOperator.TableOp[user.UserAccount]
|
||||
}
|
||||
|
||||
func NewUserAccountOp() *UserAccountOp {
|
||||
@ -27,7 +27,7 @@ func NewUserAccountOp() *UserAccountOp {
|
||||
logDb: LogDB,
|
||||
db: UserDB,
|
||||
accountRedis: AccountRedis,
|
||||
accountOp: model.NewTableOp[user.UserAccount](UserDB, AccountRedis),
|
||||
accountOp: modelOperator.NewTableOp[user.UserAccount](UserDB, AccountRedis),
|
||||
}
|
||||
}
|
||||
|
||||
@ -48,7 +48,7 @@ func (s *UserAccountOp) GetUserAccount(username string) (*user.UserAccount, pb.E
|
||||
// 从db中查到后写入redis,并建立索引
|
||||
if us.Username != "" && us.ID > 0 {
|
||||
_, _ = s.accountOp.Update(us.ID, serialization.StructToMap(us))
|
||||
_ = s.accountRedis.Set(context.Background(), s.redisKey(username), us.ID, model.TableExpire).Err()
|
||||
_ = s.accountRedis.Set(context.Background(), s.redisKey(username), us.ID, modelOperator.TableExpire).Err()
|
||||
}
|
||||
return us, pb.ErrCode_OK
|
||||
} else {
|
||||
@ -80,7 +80,7 @@ func (s *UserAccountOp) CreateUserAccount(us *user.UserAccount) (*user.UserAccou
|
||||
return nil, code
|
||||
}
|
||||
// 建立索引
|
||||
_ = s.accountRedis.Set(context.Background(), s.redisKey(us.Username), us.ID, model.TableExpire).Err()
|
||||
_ = s.accountRedis.Set(context.Background(), s.redisKey(us.Username), us.ID, modelOperator.TableExpire).Err()
|
||||
return us, pb.ErrCode_OK
|
||||
}
|
||||
|
||||
@ -95,7 +95,7 @@ func (s *UserAccountOp) UpdateUserPassword(us *user.UserAccount) (*user.UserAcco
|
||||
var code pb.ErrCode
|
||||
us, code = s.accountOp.Update(us.ID, map[string]any{"password": hashedPassword})
|
||||
if code != pb.ErrCode_OK {
|
||||
_ = s.accountRedis.Expire(context.Background(), s.redisKey(us.Username), model.TableExpire).Err()
|
||||
_ = s.accountRedis.Expire(context.Background(), s.redisKey(us.Username), modelOperator.TableExpire).Err()
|
||||
}
|
||||
return us, code
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user