菜单路由动态加载
This commit is contained in:
parent
d47287adb4
commit
ca90eee8f3
|
@ -10,6 +10,7 @@ var (
|
||||||
UsernameOrPasswordError = gin.H{"errorCode": 10003, "msg": "用户名或密码错误"}
|
UsernameOrPasswordError = gin.H{"errorCode": 10003, "msg": "用户名或密码错误"}
|
||||||
NoOperationPermissionError = gin.H{"errorCode": 10004, "msg": "无操作权限"}
|
NoOperationPermissionError = gin.H{"errorCode": 10004, "msg": "无操作权限"}
|
||||||
NoLoginError = gin.H{"errorCode": 10005, "msg": "未登录"}
|
NoLoginError = gin.H{"errorCode": 10005, "msg": "未登录"}
|
||||||
|
SystemInnerError = gin.H{"errorCode": 10006, "msg": "系统内部错误"}
|
||||||
)
|
)
|
||||||
|
|
||||||
func Fail(errorCode int, data interface{}) gin.H {
|
func Fail(errorCode int, data interface{}) gin.H {
|
||||||
|
|
|
@ -37,7 +37,11 @@ func (AuthController) Login(c *gin.Context) {
|
||||||
c.JSON(http.StatusBadRequest, resp.PasswordError)
|
c.JSON(http.StatusBadRequest, resp.PasswordError)
|
||||||
return
|
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)
|
redistool.Set(rediskey.AUTH_TOKEN+":"+json.Username, token, time.Hour*20)
|
||||||
context.SetUser(c, user)
|
context.SetUser(c, user)
|
||||||
c.JSON(http.StatusOK, resp.Success(map[string]string{
|
c.JSON(http.StatusOK, resp.Success(map[string]string{
|
||||||
|
|
|
@ -91,4 +91,9 @@ this.login()
|
||||||
web/src/api/service.js
|
web/src/api/service.js
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### 加载顺序
|
||||||
|
```text
|
||||||
|
router > api
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ import faker from 'faker/locale/zh_CN'
|
||||||
import { service, request, serviceForMock, requestForMock, mock } from './service'
|
import { service, request, serviceForMock, requestForMock, mock } from './service'
|
||||||
import * as tools from './tools'
|
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)
|
const generators = files.keys().map(key => files(key).default)
|
||||||
|
|
||||||
export default assign({}, ...map(generators, generator => generator({
|
export default assign({}, ...map(generators, generator => generator({
|
||||||
|
|
|
@ -5,7 +5,7 @@ export default ({ service, request, tools }) => ({
|
||||||
queryAllMenus (data = {}) {
|
queryAllMenus (data = {}) {
|
||||||
// 接口请求
|
// 接口请求
|
||||||
return request({
|
return request({
|
||||||
url: '/queryAllMenus',
|
url: '/api/v1/queryAllMenus',
|
||||||
method: 'post',
|
method: 'post',
|
||||||
data
|
data
|
||||||
})
|
})
|
|
@ -3,7 +3,7 @@ import layoutHeaderAside from '@/layout/header-aside'
|
||||||
// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
|
// 由于懒加载页面太多的话会造成webpack热更新太慢,所以开发环境不使用懒加载,只有生产环境使用懒加载
|
||||||
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
|
const _import = require('@/libs/util.import.' + process.env.NODE_ENV)
|
||||||
|
|
||||||
console.log('================= 路由加载')
|
console.log('================= 刷新会导致路由重新加载')
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在主框架内显示
|
* 在主框架内显示
|
||||||
|
|
|
@ -27,7 +27,10 @@ export default {
|
||||||
util.cookies.set('username', res.username)
|
util.cookies.set('username', res.username)
|
||||||
util.cookies.set('name', res.name)
|
util.cookies.set('name', res.name)
|
||||||
util.cookies.set('token', res.token)
|
util.cookies.set('token', res.token)
|
||||||
console.log('=============== 设置用户token')
|
// 设置路由菜单
|
||||||
|
console.log('========= 设置路由菜单')
|
||||||
|
const menuTree = await api.queryAllMenus({})
|
||||||
|
console.log('========= ', menuTree)
|
||||||
// 设置 vuex 用户信息
|
// 设置 vuex 用户信息
|
||||||
await dispatch('d2admin/user/set', { name: res.name }, { root: true })
|
await dispatch('d2admin/user/set', { name: res.name }, { root: true })
|
||||||
// 用户登录后从持久化数据加载一系列的设置
|
// 用户登录后从持久化数据加载一系列的设置
|
||||||
|
|
|
@ -119,8 +119,8 @@ export default {
|
||||||
// 表单
|
// 表单
|
||||||
formLogin: {
|
formLogin: {
|
||||||
username: 'admin',
|
username: 'admin',
|
||||||
password: 'admin',
|
password: 'admin'
|
||||||
code: 'v9am'
|
// code: 'v9am'
|
||||||
},
|
},
|
||||||
// 表单校验
|
// 表单校验
|
||||||
rules: {
|
rules: {
|
||||||
|
@ -137,14 +137,14 @@ export default {
|
||||||
message: '请输入密码',
|
message: '请输入密码',
|
||||||
trigger: 'blur'
|
trigger: 'blur'
|
||||||
}
|
}
|
||||||
],
|
|
||||||
code: [
|
|
||||||
{
|
|
||||||
required: true,
|
|
||||||
message: '请输入验证码',
|
|
||||||
trigger: 'blur'
|
|
||||||
}
|
|
||||||
]
|
]
|
||||||
|
// code: [
|
||||||
|
// {
|
||||||
|
// required: true,
|
||||||
|
// message: '请输入验证码',
|
||||||
|
// trigger: 'blur'
|
||||||
|
// }
|
||||||
|
// ]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue