mirror of
https://github.com/zuiidea/antd-admin
synced 2026-11-26 15:54:14 +00:00
Support Stylelint.
Added Prettierrc. Optimize the configuration file .umirc.js, and Added annotations. Replace eslint-plugin-umi to eslint-plugin-react-app as eslint bese plugin. And so on.
This commit is contained in:
+49
-40
@@ -4,12 +4,11 @@
|
||||
/* eslint no-restricted-globals: ["error", "event"] */
|
||||
|
||||
import { routerRedux } from 'dva/router'
|
||||
import { parse } from 'qs'
|
||||
import { parse, stringify } from 'qs'
|
||||
import config from 'config'
|
||||
import { EnumRoleType } from 'enums'
|
||||
import { query, logout } from 'services/app'
|
||||
import * as menusService from 'services/menus'
|
||||
import queryString from 'query-string'
|
||||
|
||||
const { prefix } = config
|
||||
|
||||
@@ -32,14 +31,14 @@ export default {
|
||||
siderFold: window.localStorage.getItem(`${prefix}siderFold`) === 'true',
|
||||
darkTheme: window.localStorage.getItem(`${prefix}darkTheme`) === 'true',
|
||||
isNavbar: document.body.clientWidth < 769,
|
||||
navOpenKeys: JSON.parse(window.localStorage.getItem(`${prefix}navOpenKeys`)) || [],
|
||||
navOpenKeys:
|
||||
JSON.parse(window.localStorage.getItem(`${prefix}navOpenKeys`)) || [],
|
||||
locationPathname: '',
|
||||
locationQuery: {},
|
||||
},
|
||||
subscriptions: {
|
||||
|
||||
setupHistory ({ dispatch, history }) {
|
||||
history.listen((location) => {
|
||||
history.listen(location => {
|
||||
dispatch({
|
||||
type: 'updateState',
|
||||
payload: {
|
||||
@@ -60,26 +59,27 @@ export default {
|
||||
}, 300)
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
effects: {
|
||||
|
||||
* query ({
|
||||
payload,
|
||||
}, { call, put, select }) {
|
||||
*query ({ payload }, { call, put, select }) {
|
||||
const { success, user } = yield call(query, payload)
|
||||
const { locationPathname } = yield select(_ => _.app)
|
||||
if (success && user) {
|
||||
const { list } = yield call(menusService.query)
|
||||
const { permissions } = user
|
||||
let menu = list
|
||||
if (permissions.role === EnumRoleType.ADMIN || permissions.role === EnumRoleType.DEVELOPER) {
|
||||
if (
|
||||
permissions.role === EnumRoleType.ADMIN ||
|
||||
permissions.role === EnumRoleType.DEVELOPER
|
||||
) {
|
||||
permissions.visit = list.map(item => item.id)
|
||||
} else {
|
||||
menu = list.filter((item) => {
|
||||
menu = list.filter(item => {
|
||||
const cases = [
|
||||
permissions.visit.includes(item.id),
|
||||
item.mpid ? permissions.visit.includes(item.mpid) || item.mpid === '-1' : true,
|
||||
item.mpid
|
||||
? permissions.visit.includes(item.mpid) || item.mpid === '-1'
|
||||
: true,
|
||||
item.bpid ? permissions.visit.includes(item.bpid) : true,
|
||||
]
|
||||
return cases.every(_ => _)
|
||||
@@ -94,49 +94,58 @@ export default {
|
||||
},
|
||||
})
|
||||
if (location.pathname === '/login') {
|
||||
yield put(routerRedux.push({
|
||||
pathname: '/dashboard',
|
||||
}))
|
||||
yield put(
|
||||
routerRedux.push({
|
||||
pathname: '/dashboard',
|
||||
})
|
||||
)
|
||||
}
|
||||
} else if (config.openPages && config.openPages.indexOf(locationPathname) < 0) {
|
||||
yield put(routerRedux.push({
|
||||
pathname: '/login',
|
||||
search: queryString.stringify({
|
||||
from: locationPathname,
|
||||
}),
|
||||
}))
|
||||
} else if (
|
||||
config.openPages &&
|
||||
config.openPages.indexOf(locationPathname) < 0
|
||||
) {
|
||||
yield put(
|
||||
routerRedux.push({
|
||||
pathname: '/login',
|
||||
search: stringify({
|
||||
from: locationPathname,
|
||||
}),
|
||||
})
|
||||
)
|
||||
}
|
||||
},
|
||||
|
||||
* logout ({
|
||||
payload,
|
||||
}, { call, put }) {
|
||||
*logout ({ payload }, { call, put }) {
|
||||
const data = yield call(logout, parse(payload))
|
||||
if (data.success) {
|
||||
yield put({ type: 'updateState', payload: {
|
||||
user: {},
|
||||
permissions: { visit: [] },
|
||||
menu: [{
|
||||
id: 1,
|
||||
icon: 'laptop',
|
||||
name: 'Dashboard',
|
||||
router: '/dashboard',
|
||||
}],
|
||||
}})
|
||||
yield put({
|
||||
type: 'updateState',
|
||||
payload: {
|
||||
user: {},
|
||||
permissions: { visit: [] },
|
||||
menu: [
|
||||
{
|
||||
id: 1,
|
||||
icon: 'laptop',
|
||||
name: 'Dashboard',
|
||||
router: '/dashboard',
|
||||
},
|
||||
],
|
||||
},
|
||||
})
|
||||
yield put({ type: 'query' })
|
||||
} else {
|
||||
throw (data)
|
||||
throw data
|
||||
}
|
||||
},
|
||||
|
||||
* changeNavbar (action, { put, select }) {
|
||||
const { app } = yield (select(_ => _))
|
||||
*changeNavbar (action, { put, select }) {
|
||||
const { app } = yield select(_ => _)
|
||||
const isNavbar = document.body.clientWidth < 769
|
||||
if (isNavbar !== app.isNavbar) {
|
||||
yield put({ type: 'handleNavbar', payload: isNavbar })
|
||||
}
|
||||
},
|
||||
|
||||
},
|
||||
reducers: {
|
||||
updateState (state, { payload }) {
|
||||
|
||||
Reference in New Issue
Block a user