payload: {"action":"created","issue":{"url":"https://api.github.com/repos/PanJiaChen/vue-element-admin/issues/293","repository_url":"https://api.github.com/repos/PanJiaChen/vue-element-admin","labels_url":"https://api.github.com/repos/PanJiaChen/vue-element-admin/issues/293/labels{/name}","comments_url":"https://api.github.com/repos/PanJiaChen/vue-element-admin/issues/293/comments","events_url":"https://api.github.com/repos/PanJiaChen/vue-element-admin/issues/293/events","html_url":"https://github.com/PanJiaChen/vue-element-admin/issues/293","id":275946343,"node_id":"MDU6SXNzdWUyNzU5NDYzNDM=","number":293,"title":"请问路由配置可以动态的改变吗?","user":{"login":"gaoshijun1993","id":23435469,"node_id":"MDQ6VXNlcjIzNDM1NDY5","avatar_url":"https://avatars2.githubusercontent.com/u/23435469?v=4","gravatar_id":"","url":"https://api.github.com/users/gaoshijun1993","html_url":"https://github.com/gaoshijun1993","followers_url":"https://api.github.com/users/gaoshijun1993/followers","following_url":"https://api.github.com/users/gaoshijun1993/following{/other_user}","gists_url":"https://api.github.com/users/gaoshijun1993/gists{/gist_id}","starred_url":"https://api.github.com/users/gaoshijun1993/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gaoshijun1993/subscriptions","organizations_url":"https://api.github.com/users/gaoshijun1993/orgs","repos_url":"https://api.github.com/users/gaoshijun1993/repos","events_url":"https://api.github.com/users/gaoshijun1993/events{/privacy}","received_events_url":"https://api.github.com/users/gaoshijun1993/received_events","type":"User","site_admin":false},"labels":[{"id":808855020,"node_id":"MDU6TGFiZWw4MDg4NTUwMjA=","url":"https://api.github.com/repos/PanJiaChen/vue-element-admin/labels/RFC","name":"RFC","color":"65edcf","default":false}],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":37,"created_at":"2017-11-22T05:07:04Z","updated_at":"2019-07-17T12:21:47Z","closed_at":"2017-11-22T05:30:45Z","author_association":"CONTRIBUTOR","body":"我们现在想要增加一个功能,就是管理员可以更改每个菜单的可访问角色列表,我想在进入页面之前从服务器获取每个路由的可访问列表并更改,请问这样子可以实现吗?"},"comment":{"url":"https://api.github.com/repos/PanJiaChen/vue-element-admin/issues/comments/512230720","html_url":"https://github.com/PanJiaChen/vue-element-admin/issues/293#issuecomment-512230720","issue_url":"https://api.github.com/repos/PanJiaChen/vue-element-admin/issues/293","id":512230720,"node_id":"MDEyOklzc3VlQ29tbWVudDUxMjIzMDcyMA==","user":{"login":"Leega0","id":4487765,"node_id":"MDQ6VXNlcjQ0ODc3NjU=","avatar_url":"https://avatars1.githubusercontent.com/u/4487765?v=4","gravatar_id":"","url":"https://api.github.com/users/Leega0","html_url":"https://github.com/Leega0","followers_url":"https://api.github.com/users/Leega0/followers","following_url":"https://api.github.com/users/Leega0/following{/other_user}","gists_url":"https://api.github.com/users/Leega0/gists{/gist_id}","starred_url":"https://api.github.com/users/Leega0/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Leega0/subscriptions","organizations_url":"https://api.github.com/users/Leega0/orgs","repos_url":"https://api.github.com/users/Leega0/repos","events_url":"https://api.github.com/users/Leega0/events{/privacy}","received_events_url":"https://api.github.com/users/Leega0/received_events","type":"User","site_admin":false},"created_at":"2019-07-17T12:21:47Z","updated_at":"2019-07-17T12:21:47Z","author_association":"NONE","body":"> 附一个我完成的PHP的动态方案，主要代码\r\n> \r\n> 首先PHP要返回用户可访问的路由，期望的结果是菜单中可以有一个指向 `/example/sample` 的菜单和路由。\r\n> \r\n> ```\r\n> public function actionMenu()\r\n>     {\r\n>         $data =[\r\n>             [\r\n>                 'path' => '/example',\r\n>                 'component' => 'Layout',\r\n>                 'redirect'=> '',\r\n>                 'name'=> 'ExampleRoot',\r\n>                 'meta'=> [\r\n>                     'title'=>'示例',\r\n>                     'icon'=>'table'\r\n>                 ],\r\n>                 'children'=>[\r\n>                     [\r\n>                         'path' => 'sample',\r\n>                         'component' => '/example/sample',\r\n>                         'name'=> 'ExampleSample',\r\n>                         'meta'=> [\r\n>                             'title'=>'example',\r\n>                             'icon'=>'table'\r\n>                         ],\r\n>                     ]\r\n>                 ]\r\n>             ]\r\n>         ]\r\n>             \r\n>             ;\r\n> \r\n>         return json_encode($data);\r\n>     }\r\n> ```\r\n> \r\n> 然后修改 `src/store/modules/permission.js`\r\n> \r\n> 添加一个方法\r\n> \r\n> ```js\r\n> function dataArrayToRoutes(data) {\r\n>   const res = []\r\n>   data.forEach(item => {\r\n>     const tmp = { ...item }\r\n>     if (tmp.component === 'Layout') {\r\n>       tmp.component = Layout\r\n>     } else {\r\n>       let sub_view = tmp.component\r\n>       sub_view = sub_view.replace(/^\\/*/g, '')\r\n>       tmp.component = () => import(`@/views/${sub_view}`)  //这里很重要，把view动态加载进来，而且似乎我只找到这样的写法，用拼接不行，然后 views 后面没有斜杆也不行\r\n>     }\r\n>     if (tmp.children) {\r\n>       tmp.children = dataArrayToRoutes(tmp.children)\r\n>     }\r\n>     res.push(tmp)\r\n>   })\r\n>   return res\r\n> }\r\n> ```\r\n> \r\n> 然后修改这个文件中的 actions\r\n> \r\n> ```js\r\n> const actions = {\r\n>   generateRoutes({ commit, state }, { roles, menus }) {\r\n>     return new Promise(resolve => {\r\n>       let accessedRoutes\r\n>       // if (roles.includes('admin')) {\r\n>       //   accessedRoutes = asyncRoutes || []\r\n>       // } else {\r\n>       //   accessedRoutes = filterAsyncRoutes(asyncRoutes, roles)\r\n>       // }\r\n>       // commit('SET_ROUTES', accessedRoutes)\r\n> \r\n>       accessedRoutes = dataArrayToRoutes(menus)\r\n> \r\n>       commit('SET_ROUTES', accessedRoutes)\r\n> \r\n>       resolve(accessedRoutes)\r\n>     })\r\n>   }\r\n> }\r\n> ```\r\n> \r\n> 然后新增一个 `user/getMenus` 的 Vuex 的 action\r\n> \r\n> ```js\r\n> const state = {\r\n>   token: getToken(),\r\n>   name: '',\r\n>   avatar: '',\r\n>   introduction: '',\r\n>   roles: [],\r\n>   menus: [] //这个是我新增的\r\n> }\r\n> \r\n> const mutations = {\r\n>   SET_TOKEN: (state, token) => {\r\n>     state.token = token\r\n>   },\r\n>   SET_INTRODUCTION: (state, introduction) => {\r\n>     state.introduction = introduction\r\n>   },\r\n>   SET_NAME: (state, name) => {\r\n>     state.name = name\r\n>   },\r\n>   SET_AVATAR: (state, avatar) => {\r\n>     state.avatar = avatar\r\n>   },\r\n>   SET_ROLES: (state, roles) => {\r\n>     state.roles = roles\r\n>   },\r\n>   SET_MENUS: (state, menus) => { //这里是新增的\r\n>     state.menus = menus\r\n>   }\r\n> }\r\n> \r\n> const actions = {\r\n>     getMenus({ commit, state }) { //这个是新增的action\r\n>     return new Promise((resolve, reject) => {\r\n>       getMenus(state.token).then(response => {  //这里的getMenus是调用request方法从服务端获得路由菜单数据的Promise，类似getInfo\r\n>         const { data } = response\r\n>         console.log(data)\r\n> \r\n>         if (!data) {\r\n>           reject('Verification failed, please Login again.')\r\n>         }\r\n> \r\n>         const menus = data\r\n> \r\n>         // roles must be a non-empty array\r\n>         if (!menus || menus.length <= 0) {\r\n>           reject('getMenus: menus must be a non-null array!')\r\n>         }\r\n> \r\n>         commit('SET_MENUS', menus)\r\n>         resolve(menus)\r\n>       }).catch(error => {\r\n>         reject(error)\r\n>       })\r\n>     })\r\n>   },\r\n> }\r\n> ```\r\n> \r\n> 还有一个文件是 `src/permission.js`\r\n> 要在 `store.dispatch('permission/generateRoutes')` 代码附近要改一下，原先从本地配置+roles获得用户路由，现在改从服务端获得之后再 `addRoutes`\r\n> \r\n> ```\r\n>           const menus = await store.dispatch('user/getMenus')\r\n>           // generate accessible routes map based on roles\r\n>           const accessRoutes = await store.dispatch('permission/generateRoutes', { menus })\r\n>           // dynamically add accessible routes\r\n>           router.addRoutes(accessRoutes)\r\n> ```\r\n> \r\n> 亲测可行……\r\n\r\n`tmp.component = Layout`这段代码在开发的时候直接报错了，Layout未定义，貌似不能直接赋值"}}
other: {"actor":{"display_login":"Leega0"}}