Skip to content

Commit

Permalink
优化初始化路由
Browse files Browse the repository at this point in the history
  • Loading branch information
beclass committed Nov 7, 2019
1 parent 0144e87 commit 7ffcd7a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 17 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@
[http://120.55.160.92:8082](http://120.55.160.92:8082)

```
用户:test
用户1:admin
密码:111111
用户2:gust
密码:111111
```

#### 服务端框架
Expand Down
19 changes: 6 additions & 13 deletions src/libs/router-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,13 @@ import parentView from '@/components/parent-view'
import store from '@/store'
let gotRouter
// 初始化路由
export const initRouter = () => {
export const initRouter = async() => {
if (!getToken()) return
let routerData
if (!gotRouter) {
getMenus().then(res => {
routerData = res
localSave('dynamicRouter', JSON.stringify(routerData)) // 存储路由到localStorage
gotRouter = filterAsyncRouter(routerData) // 过滤路由,路由组件转换
store.commit('updateMenuList', gotRouter)
dynamicRouterAdd()
})
} else {
gotRouter = dynamicRouterAdd()
}
const menus = await getMenus();
localSave('dynamicRouter', JSON.stringify(menus)) // 存储路由到localStorage
gotRouter = filterAsyncRouter(menus) // 过滤路由,路由组件转换
store.commit('updateMenuList', gotRouter)
dynamicRouterAdd()
return gotRouter
}
// 加载路由菜单,从localStorage拿到路由,在创建路由时使用
Expand Down
1 change: 1 addition & 0 deletions src/store/module/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export default {
},
updateMenuList (state, routes) {
// 接受前台数组,刷新菜单
console.log('来啊')
router.addRoutes(routes)
state.menuList = routes
},
Expand Down
2 changes: 2 additions & 0 deletions src/store/module/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
restoreTrash
} from '@/api/user'
import { setToken, localSave } from '@/libs/util'
import store from '@/store'
import { initRouter } from '@/libs/router-util' // 引入动态菜单渲染

export default {
Expand Down Expand Up @@ -80,6 +81,7 @@ export default {
commit('setAccess', [])
localSave('dynamicRouter', []) // 清空本地路由
localSave('tagNaveList', []) // 清空localStorage中的tagNaveList记录
store.commit('updateMenuList', [])
},
// 获取用户相关信息
async getUserInfo ({ state, commit }) {
Expand Down
2 changes: 1 addition & 1 deletion src/view/content/article/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Card>
<div>
<Input v-model="filter.search$$title$$all" placeholder="名称" style="width: 200px"/>
<Select v-model="filter.articleType_id" clearable style="width:150px;margin-left:10px">
<Select v-model="filter.article_type_id" clearable style="width:150px;margin-left:10px">
<Option v-for="(item,index) in types" :key="index" :value="item.id">{{item.name}}</Option>
</Select>&nbsp;
<Button @click="search" icon="ios-search" type="primary">搜索</Button>&nbsp;
Expand Down
2 changes: 1 addition & 1 deletion src/view/content/article/modify.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import Editor from '_c/editor'
import Upload from '_c/upload'
const rules = {
title: [{ required: true, message: '标题不能为空', trigger: 'blur' }],
articleType_id: [{ type: 'number', required: true, message: '请选择类型', trigger: 'change' }]
article_type_id: [{ type: 'number', required: true, message: '请选择类型', trigger: 'change' }]
}
export default {
components: {
Expand Down
2 changes: 1 addition & 1 deletion src/view/dashboard/home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<a class="coupon-btn" href="https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=mpd2xfug" target="_blank">立即领取</a>
</div>
<div class="coupon-activity-img">
<a href="https://www.aliyun.com/acts/limit-buy?userCode=mpd2xfug" target="_blank">
<a href="https://dwz.cn/e8atY6gf" target="_blank">
<img src="http://pic.loveyh.com/limit-buy.jpg" width="280" height="118"></a>
</div>
</div>
Expand Down

0 comments on commit 7ffcd7a

Please sign in to comment.