From ca90eee8f3b94eedc204020e9e45685b856e94b6 Mon Sep 17 00:00:00 2001 From: Odboy Date: Mon, 5 Feb 2024 10:38:44 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8F=9C=E5=8D=95=E8=B7=AF=E7=94=B1=E5=8A=A8?= =?UTF-8?q?=E6=80=81=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/infra/resp/init.go | 1 + src/modules/system/rest/auth.go | 6 +++++- web/README.zh.md | 5 +++++ web/src/api/index.js | 2 +- .../{system.menu.js => system.menu.service.js} | 2 +- .../{system.user.js => system.user.service.js} | 0 web/src/router/routes.js | 2 +- .../store/modules/d2admin/modules/account.js | 5 ++++- web/src/views/system/login/page.vue | 18 +++++++++--------- 9 files changed, 27 insertions(+), 14 deletions(-) rename web/src/api/modules/{system.menu.js => system.menu.service.js} (85%) rename web/src/api/modules/{system.user.js => system.user.service.js} (100%) diff --git a/src/infra/resp/init.go b/src/infra/resp/init.go index f03a0a8..5cc6126 100644 --- a/src/infra/resp/init.go +++ b/src/infra/resp/init.go @@ -10,6 +10,7 @@ var ( UsernameOrPasswordError = gin.H{"errorCode": 10003, "msg": "用户名或密码错误"} NoOperationPermissionError = gin.H{"errorCode": 10004, "msg": "无操作权限"} NoLoginError = gin.H{"errorCode": 10005, "msg": "未登录"} + SystemInnerError = gin.H{"errorCode": 10006, "msg": "系统内部错误"} ) func Fail(errorCode int, data interface{}) gin.H { diff --git a/src/modules/system/rest/auth.go b/src/modules/system/rest/auth.go index e1303f6..120e764 100644 --- a/src/modules/system/rest/auth.go +++ b/src/modules/system/rest/auth.go @@ -37,7 +37,11 @@ func (AuthController) Login(c *gin.Context) { c.JSON(http.StatusBadRequest, resp.PasswordError) return } - token := jwt.GenToken(json.Username) + token, err := jwt.GenToken(json.Username) + if err != nil { + c.JSON(http.StatusBadRequest, resp.SystemInnerError) + return + } redistool.Set(rediskey.AUTH_TOKEN+":"+json.Username, token, time.Hour*20) context.SetUser(c, user) c.JSON(http.StatusOK, resp.Success(map[string]string{ diff --git a/web/README.zh.md b/web/README.zh.md index 418560d..30bb6f1 100644 --- a/web/README.zh.md +++ b/web/README.zh.md @@ -91,4 +91,9 @@ this.login() web/src/api/service.js ``` +### 加载顺序 +```text +router > api +``` + diff --git a/web/src/api/index.js b/web/src/api/index.js index a713ffd..535be69 100644 --- a/web/src/api/index.js +++ b/web/src/api/index.js @@ -3,7 +3,7 @@ import faker from 'faker/locale/zh_CN' import { service, request, serviceForMock, requestForMock, mock } from './service' import * as tools from './tools' -const files = require.context('./modules', true, /\.api\.js$/) +const files = require.context('./modules', true, /\.service\.js$/) const generators = files.keys().map(key => files(key).default) export default assign({}, ...map(generators, generator => generator({ diff --git a/web/src/api/modules/system.menu.js b/web/src/api/modules/system.menu.service.js similarity index 85% rename from web/src/api/modules/system.menu.js rename to web/src/api/modules/system.menu.service.js index 3be13cb..b020554 100644 --- a/web/src/api/modules/system.menu.js +++ b/web/src/api/modules/system.menu.service.js @@ -5,7 +5,7 @@ export default ({ service, request, tools }) => ({ queryAllMenus (data = {}) { // 接口请求 return request({ - url: '/queryAllMenus', + url: '/api/v1/queryAllMenus', method: 'post', data }) diff --git a/web/src/api/modules/system.user.js b/web/src/api/modules/system.user.service.js similarity index 100% rename from web/src/api/modules/system.user.js rename to web/src/api/modules/system.user.service.js diff --git a/web/src/router/routes.js b/web/src/router/routes.js index 0d100bf..7e3e934 100644 --- a/web/src/router/routes.js +++ b/web/src/router/routes.js @@ -3,7 +3,7 @@ import layoutHeaderAside from '@/layout/header-aside' // 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载 const _import = require('@/libs/util.import.' + process.env.NODE_ENV) -console.log('================= 路由加载') +console.log('================= 刷新会导致路由重新加载') /** * 在主框架内显示 diff --git a/web/src/store/modules/d2admin/modules/account.js b/web/src/store/modules/d2admin/modules/account.js index 7f07f86..be7f06a 100644 --- a/web/src/store/modules/d2admin/modules/account.js +++ b/web/src/store/modules/d2admin/modules/account.js @@ -27,7 +27,10 @@ export default { util.cookies.set('username', res.username) util.cookies.set('name', res.name) util.cookies.set('token', res.token) - console.log('=============== 设置用户token') + // 设置路由菜单 + console.log('========= 设置路由菜单') + const menuTree = await api.queryAllMenus({}) + console.log('========= ', menuTree) // 设置 vuex 用户信息 await dispatch('d2admin/user/set', { name: res.name }, { root: true }) // 用户登录后从持久化数据加载一系列的设置 diff --git a/web/src/views/system/login/page.vue b/web/src/views/system/login/page.vue index 51a749e..823c8af 100644 --- a/web/src/views/system/login/page.vue +++ b/web/src/views/system/login/page.vue @@ -119,8 +119,8 @@ export default { // 表单 formLogin: { username: 'admin', - password: 'admin', - code: 'v9am' + password: 'admin' + // code: 'v9am' }, // 表单校验 rules: { @@ -137,14 +137,14 @@ export default { message: '请输入密码', trigger: 'blur' } - ], - code: [ - { - required: true, - message: '请输入验证码', - trigger: 'blur' - } ] + // code: [ + // { + // required: true, + // message: '请输入验证码', + // trigger: 'blur' + // } + // ] } } },