又优化了很多

This commit is contained in:
likun 2025-05-16 15:51:22 +08:00
parent 20a6efe559
commit a06bd65ce6
7 changed files with 47 additions and 27 deletions

View File

@ -7,6 +7,7 @@ import (
"admin/apps/game/model" "admin/apps/game/model"
"admin/internal/errcode" "admin/internal/errcode"
"admin/internal/model/dto" "admin/internal/model/dto"
"admin/lib/xlog"
"gorm.io/gorm" "gorm.io/gorm"
) )
@ -83,7 +84,8 @@ func (svc *ProjectService) GetAllItems(projectId int) ([]*dto.CommonDtoFieldChoi
handler := projects.GetProjectValueChoicesGetHook(projectEt.Po.ProjectType) handler := projects.GetProjectValueChoicesGetHook(projectEt.Po.ProjectType)
if handler == nil { if handler == nil {
return nil, errcode.New(errcode.ServerError, "not found project %v items handler", projectEt.Po.ProjectType) xlog.Warnf("project %+v not found choices hook", projectEt.Po)
return make([]*dto.CommonDtoFieldChoice, 0), nil
} }
return handler.GetItems(projectEt) return handler.GetItems(projectEt)

View File

@ -6,6 +6,8 @@ import (
"admin/internal/consts" "admin/internal/consts"
) )
var debugDisableAllHook = false // 调试用关闭所有项目钩子调用可以在没有远程游戏api服务器时调一些gm后台本地的增删改查等逻辑
// 注册各个项目所有gm资源操作后的回调例如后台添加了白名单可以在回调里加上通知项目内的服务 // 注册各个项目所有gm资源操作后的回调例如后台添加了白名单可以在回调里加上通知项目内的服务
var projectsResourceHookMgr = map[string]map[string]any{ var projectsResourceHookMgr = map[string]map[string]any{
// 神魔大陆项目注册的资源钩子回调 // 神魔大陆项目注册的资源钩子回调
@ -26,6 +28,9 @@ var projectsValueChoicesGetHook = map[string]IGetAllValueChoicesHook{
} }
func GetProjectResourceHook(project *entity.Project, resource string) any { func GetProjectResourceHook(project *entity.Project, resource string) any {
if debugDisableAllHook {
return nil
}
projectResourceHooks, find := projectsResourceHookMgr[project.Po.ProjectType] projectResourceHooks, find := projectsResourceHookMgr[project.Po.ProjectType]
if !find { if !find {
return nil return nil
@ -34,5 +39,8 @@ func GetProjectResourceHook(project *entity.Project, resource string) any {
} }
func GetProjectValueChoicesGetHook(projectId string) IGetAllValueChoicesHook { func GetProjectValueChoicesGetHook(projectId string) IGetAllValueChoicesHook {
if debugDisableAllHook {
return nil
}
return projectsValueChoicesGetHook[projectId] return projectsValueChoicesGetHook[projectId]
} }

View File

@ -32,7 +32,7 @@ func (items *Items) GetItems(projectInfo *entity.Project) ([]*dto.CommonDtoField
rsp := &RspData{} rsp := &RspData{}
err := httpclient.Request(alisrvAddr+"/items", "get", nil, rsp) err := httpclient.Request(alisrvAddr+"/items", "get", nil, rsp)
if err != nil { if err != nil {
return nil, err return make([]*dto.CommonDtoFieldChoice, 0), nil
} }
return rsp.Data.List, nil return rsp.Data.List, nil
} }

View File

@ -12,6 +12,14 @@ import (
) )
func Request(addr string, method string, body interface{}, resData interface{}) error { func Request(addr string, method string, body interface{}, resData interface{}) error {
err := request(addr, method, body, resData)
if err != nil {
xlog.Errorf("访问远程地址:%v 方法: %v 参数:%+v发生错误%v", addr, method, body, err)
}
return err
}
func request(addr string, method string, body interface{}, resData interface{}) error {
removeUrl := checkUrl(addr) removeUrl := checkUrl(addr)
//xlog.Debugf("-->req url: %v", removeUrl) //xlog.Debugf("-->req url: %v", removeUrl)
@ -22,7 +30,6 @@ func Request(addr string, method string, body interface{}, resData interface{})
if body != nil { if body != nil {
bodyBytes, err := json.Marshal(body) bodyBytes, err := json.Marshal(body)
if err != nil { if err != nil {
xlog.Warnf(err)
return errcode.New(errcode.ServerError, "数据解析失败:%v", err) return errcode.New(errcode.ServerError, "数据解析失败:%v", err)
} }
bodyReader = strings.NewReader(string(bodyBytes)) bodyReader = strings.NewReader(string(bodyBytes))
@ -32,13 +39,11 @@ func Request(addr string, method string, body interface{}, resData interface{})
} }
req, err := http.NewRequest(method, removeUrl, bodyReader) req, err := http.NewRequest(method, removeUrl, bodyReader)
if err != nil { if err != nil {
xlog.Warnf(err)
return errcode.New(errcode.ServerError, "数据请求创建失败:%v", err) return errcode.New(errcode.ServerError, "数据请求创建失败:%v", err)
} }
res, err = client.Do(req) res, err = client.Do(req)
if err != nil { if err != nil {
xlog.Warnf(err)
return errcode.New(errcode.ServerError, "数据请求失败:%v", err) return errcode.New(errcode.ServerError, "数据请求失败:%v", err)
} }
} else { } else {
@ -76,13 +81,11 @@ func Request(addr string, method string, body interface{}, resData interface{})
req, err := http.NewRequest("get", removeUrl, nil) req, err := http.NewRequest("get", removeUrl, nil)
if err != nil { if err != nil {
xlog.Warnf(err)
return errcode.New(errcode.ServerError, "数据请求创建失败:%v", err) return errcode.New(errcode.ServerError, "数据请求创建失败:%v", err)
} }
res, err = client.Do(req) res, err = client.Do(req)
if err != nil { if err != nil {
xlog.Warnf(err)
return errcode.New(errcode.ServerError, "数据请求失败:%v", err) return errcode.New(errcode.ServerError, "数据请求失败:%v", err)
} }
} }
@ -92,7 +95,6 @@ func Request(addr string, method string, body interface{}, resData interface{})
resBody, err := io.ReadAll(res.Body) resBody, err := io.ReadAll(res.Body)
if err != nil { if err != nil {
xlog.Warnf(err)
return errcode.New(errcode.ServerError, "数据解析失败:%v", err) return errcode.New(errcode.ServerError, "数据解析失败:%v", err)
} }

View File

@ -12,7 +12,7 @@ router.beforeEach((to, from, next) => {
if (to.path === '/login') { if (to.path === '/login') {
// 有token 跳过登录 // 有token 跳过登录
console.log("有token走登录跳过登录", token) console.log("有token走登录跳过登录", token)
next({path: '/'}) next({path: '/welcome'})
} else { } else {
console.log("跳到页面:" + to.path + ",当前所有路由:", router.getRoutes()) console.log("跳到页面:" + to.path + ",当前所有路由:", router.getRoutes())
@ -20,17 +20,25 @@ router.beforeEach((to, from, next) => {
if (!userStore().hasGetUserInfo()) { if (!userStore().hasGetUserInfo()) {
// console.log("访问页面获取用户信息。。。", to.path) // console.log("访问页面获取用户信息。。。", to.path)
userStore().getUserInfo().then(() => { userStore().getUserInfo().then(() => {
// console.log("获取用户信息成功,继续:", to.path) console.log("获取用户信息成功,继续:", to.path)
next({...to, replace: true}) if (to.path === "/") {
next({path: '/welcome'})
} else {
next({...to, replace: true})
}
}).catch(err => { }).catch(err => {
userStore().logout().then(() => { userStore().logout().then(() => {
ElMessage.error(err) ElMessage.error(err)
next({path: '/'}) next({path: '/login'})
}) })
}) })
} else { } else {
console.log("获取过用户数据,跳过获取。。。") console.log("获取过用户数据,跳过获取。。。")
next() if (to.path === "/") {
next({path: '/welcome'})
} else {
next()
}
} }
} }
} else { } else {

View File

@ -123,12 +123,12 @@ function logout() {
<el-dropdown class="right-menu-item hover-effect" trigger="click" @command="handleCommand"> <el-dropdown class="right-menu-item hover-effect" trigger="click" @command="handleCommand">
<!-- 头像 --> <!-- 头像 -->
<div class="avatar-wrapper"> <span style="font-size: 20px">
<span style="font-size: 20px">{{ nickName }}</span> {{ nickName }}
<el-icon color="black" size="20"> <el-icon color="black" size="10">
<ArrowDownBold/> <arrow-down/>
</el-icon> </el-icon>
</div> </span>
<!-- 头像操作下拉菜单 --> <!-- 头像操作下拉菜单 -->

View File

@ -26,13 +26,13 @@
<el-button class="theme-button" type="primary" @click="submitForm(loginForm)" @keydown.enter="keyDown()"> <el-button class="theme-button" type="primary" @click="submitForm(loginForm)" @keydown.enter="keyDown()">
</el-button> </el-button>
<p class="forget" <!-- <p class="forget"-->
@click=" <!-- @click="-->
currentModel = !currentModel; <!-- currentModel = !currentModel;-->
isForget = true; <!-- isForget = true;-->
"> <!-- ">-->
--- Forget Passwoed---- <!-- -&#45;&#45; Forget Passwoed&#45;&#45;&#45;&#45;-->
</p> <!-- </p>-->
<!-- </el-form-item>--> <!-- </el-form-item>-->
</el-form> </el-form>
@ -80,7 +80,7 @@ const submitForm = (formEl) => {
if (valid) { if (valid) {
userStore().login(loginForm.value.user, loginForm.value.password).then(() => { userStore().login(loginForm.value.user, loginForm.value.password).then(() => {
console.log("登录成功,推送首页。。") console.log("登录成功,推送首页。。")
router.push({path: "/"}) router.push({path: "/welcome"})
}, (res) => { }, (res) => {
}).catch(() => { }).catch(() => {