添加后端api及前端菜单
This commit is contained in:
parent
886846486a
commit
2dd22eebfa
@ -3,6 +3,7 @@ package v1
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/api/v1/example"
|
||||
"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)
|
||||
@ -10,4 +11,5 @@ var ApiGroupApp = new(ApiGroup)
|
||||
type ApiGroup struct {
|
||||
SystemApiGroup system.ApiGroup
|
||||
ExampleApiGroup example.ApiGroup
|
||||
UserApiGroup user.ApiGroup
|
||||
}
|
||||
|
5
admin/server/api/v1/user/enter.go
Normal file
5
admin/server/api/v1/user/enter.go
Normal file
@ -0,0 +1,5 @@
|
||||
package user
|
||||
|
||||
type ApiGroup struct {
|
||||
UserApi
|
||||
}
|
38
admin/server/api/v1/user/user.go
Normal file
38
admin/server/api/v1/user/user.go
Normal file
@ -0,0 +1,38 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"game/common/model/user"
|
||||
"game/common/proto/pb"
|
||||
"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{}
|
||||
|
||||
func (e *UserApi) 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)
|
||||
return
|
||||
}
|
||||
|
||||
var code pb.ErrCode
|
||||
gameUser, code = us.GetUser(gameUser.ID)
|
||||
if code != pb.ErrCode_OK {
|
||||
global.GVA_LOG.Error("查询失败!", zap.Error(fmt.Errorf(code.String())))
|
||||
response.FailWithMessage("查询失败", c)
|
||||
return
|
||||
}
|
||||
response.OkWithData(gin.H{"user": gameUser}, c)
|
||||
}
|
@ -7,7 +7,7 @@ aliyun-oss:
|
||||
base-path: yourBasePath
|
||||
autocode:
|
||||
web: web/src
|
||||
root: C:\workspace\go\admin
|
||||
root: C:\workspace\go\game\admin
|
||||
server: server
|
||||
module: github.com/flipped-aurora/gin-vue-admin/server
|
||||
ai-path: ""
|
||||
@ -84,7 +84,7 @@ hua-wei-obs:
|
||||
access-key: you-access-key
|
||||
secret-key: you-secret-key
|
||||
jwt:
|
||||
signing-key: 3998a6da-c0c0-4901-a052-18bb92b78c1e
|
||||
signing-key: 17b6d687-48ea-412b-aa57-55fe4af4c2ca
|
||||
expires-time: 7d
|
||||
buffer-time: 1d
|
||||
issuer: qmPlus
|
||||
|
@ -53,6 +53,7 @@ func Routers() *gin.Engine {
|
||||
|
||||
systemRouter := router.RouterGroupApp.System
|
||||
exampleRouter := router.RouterGroupApp.Example
|
||||
userRouter := router.RouterGroupApp.User
|
||||
// 如果想要不使用nginx代理前端网页,可以修改 web/.env.production 下的
|
||||
// VUE_APP_BASE_API = /
|
||||
// VUE_APP_BASE_PATH = http://localhost
|
||||
@ -109,6 +110,10 @@ func Routers() *gin.Engine {
|
||||
|
||||
}
|
||||
|
||||
{
|
||||
userRouter.InitUserRouter(PrivateGroup, PublicGroup)
|
||||
}
|
||||
|
||||
//插件路由安装
|
||||
InstallPlugin(PrivateGroup, PublicGroup, Router)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package router
|
||||
import (
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/example"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/system"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/router/user"
|
||||
)
|
||||
|
||||
var RouterGroupApp = new(RouterGroup)
|
||||
@ -10,4 +11,5 @@ var RouterGroupApp = new(RouterGroup)
|
||||
type RouterGroup struct {
|
||||
System system.RouterGroup
|
||||
Example example.RouterGroup
|
||||
User user.RouterGroup
|
||||
}
|
||||
|
11
admin/server/router/user/enter.go
Normal file
11
admin/server/router/user/enter.go
Normal file
@ -0,0 +1,11 @@
|
||||
package user
|
||||
|
||||
import api "github.com/flipped-aurora/gin-vue-admin/server/api/v1"
|
||||
|
||||
type RouterGroup struct {
|
||||
UserRouter
|
||||
}
|
||||
|
||||
var (
|
||||
userApi = api.ApiGroupApp.UserApiGroup.UserApi
|
||||
)
|
18
admin/server/router/user/user.go
Normal file
18
admin/server/router/user/user.go
Normal file
@ -0,0 +1,18 @@
|
||||
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) // 获取玩家信息
|
||||
}
|
||||
|
||||
}
|
21
admin/server/router/user/user_test.go
Normal file
21
admin/server/router/user/user_test.go
Normal file
@ -0,0 +1,21 @@
|
||||
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())
|
||||
}
|
17
admin/server/service/user/user.go
Normal file
17
admin/server/service/user/user.go
Normal file
@ -0,0 +1,17 @@
|
||||
package user
|
||||
|
||||
import (
|
||||
"game/common/model/user"
|
||||
"game/common/proto/pb"
|
||||
"game/common/rpc"
|
||||
"github.com/flipped-aurora/gin-vue-admin/server/servicex"
|
||||
)
|
||||
|
||||
//const (
|
||||
// timeout = time.Second * 30
|
||||
//)
|
||||
|
||||
// 获取玩家数据
|
||||
func GetUser(uid int64) (*user.GameUser, pb.ErrCode) {
|
||||
return rpc.RpcGetGameUser(servicex.GetService(), uid)
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "vite --port 520",
|
||||
"test": "node openDocument.js && vite --host --mode development",
|
||||
"serve": "node openDocument.js && vite --host --mode development",
|
||||
"build": "vite build --mode production",
|
||||
"build-test": "vite build --mode test",
|
||||
|
11
admin/web/src/api/gameUser.js
Normal file
11
admin/web/src/api/gameUser.js
Normal file
@ -0,0 +1,11 @@
|
||||
import request from '@/utils/request'
|
||||
|
||||
|
||||
|
||||
export function getUserById(params) {
|
||||
return request({
|
||||
url: '/user/getUserById',
|
||||
method: 'get',
|
||||
data: params
|
||||
})
|
||||
}
|
@ -18,6 +18,8 @@
|
||||
"/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",
|
||||
"/src/view/layout/aside/asideComponent/index.vue": "AsideComponent",
|
||||
@ -68,6 +70,7 @@
|
||||
"/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"
|
||||
|
26
admin/web/src/view/gameuser/index.vue
Normal file
26
admin/web/src/view/gameuser/index.vue
Normal file
@ -0,0 +1,26 @@
|
||||
<!--<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>-->
|
||||
|
||||
<template>
|
||||
<div>
|
||||
test
|
||||
</div>
|
||||
</template>
|
Loading…
x
Reference in New Issue
Block a user