菜单路由动态加载

This commit is contained in:
骑着蜗牛追导弹 2024-02-05 10:38:44 +08:00
parent d47287adb4
commit ca90eee8f3
9 changed files with 27 additions and 14 deletions

View File

@ -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 {

View File

@ -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{

View File

@ -91,4 +91,9 @@ this.login()
web/src/api/service.js
```
### 加载顺序
```text
router > api
```

View File

@ -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({

View File

@ -5,7 +5,7 @@ export default ({ service, request, tools }) => ({
queryAllMenus (data = {}) {
// 接口请求
return request({
url: '/queryAllMenus',
url: '/api/v1/queryAllMenus',
method: 'post',
data
})

View File

@ -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('================= 刷新会导致路由重新加载')
/**
* 在主框架内显示

View File

@ -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 })
// 用户登录后从持久化数据加载一系列的设置

View File

@ -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'
// }
// ]
}
}
},