diff --git a/mock/role.js b/mock/role.js index 96e80e1..d5d05ec 100644 --- a/mock/role.js +++ b/mock/role.js @@ -83,6 +83,14 @@ function getFakeTree(req, res) { return res.json(json); } +function getFakeRoutes(req, res) { + const json = { code: 200, success: true, msg: '操作成功' }; + json.data = { + '/form/advanced-form': { authority: ['admin', 'user'] }, + }; + return res.json(json); +} + function fakeSuccess(req, res) { const json = { code: 200, success: true, msg: '操作成功' }; return res.json(json); @@ -92,6 +100,7 @@ const proxy = { 'GET /api/blade-system/role/list': getFakeList, 'GET /api/blade-system/role/detail': getFakeDetail, 'GET /api/blade-system/role/tree': getFakeTree, + 'GET /api/blade-system/role/auth-routes': getFakeRoutes, 'POST /api/blade-system/role/submit': fakeSuccess, 'POST /api/blade-system/role/remove': fakeSuccess, 'POST /api/blade-system/role/grant': fakeSuccess, diff --git a/mock/route.js b/mock/route.js deleted file mode 100644 index 3a8bc51..0000000 --- a/mock/route.js +++ /dev/null @@ -1,11 +0,0 @@ -function getFakeRoutes(req, res) { - const json = { code: 200, success: true, msg: '操作成功' }; - json.data = { - '/form/advanced-form': { authority: ['admin', 'user'] }, - }; - return res.json(json); -} - -export default { - '/api/auth_routes': getFakeRoutes(), -}; diff --git a/src/app.js b/src/app.js index 5b8f7f7..27ff35d 100644 --- a/src/app.js +++ b/src/app.js @@ -1,4 +1,4 @@ -import fetch from 'dva/fetch'; +import { routesAuthority } from './services/role'; export const dva = { config: { @@ -32,17 +32,10 @@ export function patchRoutes(routes) { } export function render(oldRender) { - fetch('/api/auth_routes') - .then(res => res.json()) - .then( - ret => { - if (ret.code === 200) { - authRoutes = ret.data; - } - oldRender(); - }, - () => { - oldRender(); - } - ); + routesAuthority().then(response => { + if (response) { + authRoutes = response.data; + } + oldRender(); + }); } diff --git a/src/services/role.js b/src/services/role.js index e1cd02d..2cdfcaf 100644 --- a/src/services/role.js +++ b/src/services/role.js @@ -12,6 +12,10 @@ export async function tree(params) { return request(`/api/blade-system/role/tree?${stringify(params)}`); } +export async function routesAuthority() { + return request('/api/blade-system/role/auth-routes'); +} + export async function grant(params) { return request('/api/blade-system/role/grant', { method: 'POST',