提交 295c43c4 authored 作者: vipcxj's avatar vipcxj

去掉domain相关页面和models

上级 3b9bb58a
import { routerRedux } from 'dva/router';
import { fetchDomains, switchDomain, currentDomain } from '../services/domain';
import { fullPath } from '../utils/helper';
import { getDomain, setDomain } from '../utils/auth';
export default {
namespace: 'domain',
state: {
init: undefined,
list: [],
},
subscriptions: {
setup({ dispatch }) { // eslint-disable-line
},
},
effects: {
*fetch(ignored, { put, call }) {
const domain = yield call(getDomain);
const init = domain ? domain.path : undefined;
const list = yield call(fetchDomains, '/', true);
yield put({ type: 'queryInit', payload: init });
yield put({ type: 'queryList', payload: list });
},
*switch({ payload: domainPath }, { put, call }) {
yield call(switchDomain, domainPath);
const { path, name } = yield call(currentDomain);
yield call(setDomain, name, path);
yield put({ type: 'queryInit', payload: path });
yield put(routerRedux.push(fullPath('/main')));
},
},
reducers: {
queryInit(state, { payload: init }) {
return {
...state,
init,
};
},
queryList(state, { payload: list }) {
return {
...state,
list,
};
},
},
};
......@@ -22,7 +22,7 @@ export default {
yield call(setToken, tokenId);
const uInfo = yield call(userInfo);
yield call(setUser, uInfo.id, uInfo.name);
yield put(routerRedux.push(fullPath('/domain')));
yield put(routerRedux.push(fullPath('/main')));
},
},
subscriptions: {},
......
import { routerRedux } from 'dva/router';
import { isString } from 'lodash';
import { logout } from '../../services/main';
import { fetchDomains, switchDomain, currentDomain } from '../../services/domain';
import { getMenus, getModuleInfo } from '../../data/modules';
import { fullPath } from '../../utils/helper';
import { delToken, getDomain, setDomain, delDomain, getUser, delUser } from '../../utils/auth';
import { delToken, getUser, delUser } from '../../utils/auth';
const createMenu = async (configure) => {
const menu = {
......@@ -75,8 +74,6 @@ export default {
state: {
user: '',
domain: '',
domainList: [],
menus: [],
},
......@@ -86,29 +83,6 @@ export default {
},
effects: {
*fetchDomain(ignored, { put, call }) {
const domain = getDomain();
let domainName;
if (!domain) {
const { path, name } = yield call(currentDomain);
yield call(setDomain, name, path);
domainName = name;
} else {
domainName = domain.name;
}
yield put({ type: 'switchDomainSuccess', payload: domainName });
},
*fetchDomains(ignored, { put, call }) {
const list = yield call(fetchDomains, '/', true);
yield put({ type: 'queryDomainsSuccess', payload: list });
},
*switchDomain({ payload: domainId }, { put, call }) {
yield call(switchDomain, domainId);
const { path, name } = yield call(currentDomain);
yield call(setDomain, name, path);
yield put({ type: 'switchDomainSuccess', payload: name });
yield put(routerRedux.push(fullPath('/main')));
},
*fetchUser(ignored, { put, call }) {
const user = yield call(getUser);
if (!user) {
......@@ -125,7 +99,6 @@ export default {
yield call(logout);
yield call(delToken);
yield call(delUser);
yield call(delDomain);
yield put(routerRedux.push(fullPath('/login')));
},
},
......@@ -137,18 +110,6 @@ export default {
user,
};
},
queryDomainsSuccess(state, { payload: list }) {
return {
...state,
domainList: list,
};
},
switchDomainSuccess(state, { payload: domain }) {
return {
...state,
domain,
};
},
queryMenusSuccess(state, { payload: menus }) {
return {
...state,
......
......@@ -3,7 +3,7 @@ import PropTypes from 'prop-types';
import { Router } from 'dva/router';
import _ from 'lodash';
import config from './utils/config';
import { isAuthed, hasDomain } from './utils/auth';
import { isAuthed } from './utils/auth';
import { fullPath, makePromise0 } from './utils/helper';
import { processError } from './utils/error';
import App from './routes/app';
......@@ -25,15 +25,8 @@ const maybeLogin = async (replace) => {
}
};
const maybeSwitch = async (replace) => {
if (!(await hasDomain())) {
return replace(fullPath('/domain'));
}
};
const authenticated = async (replace) => {
await maybeLogin(replace);
await maybeSwitch(replace);
};
const createRoute = async (app, { name, showName, modules, children }) => {
......@@ -117,18 +110,6 @@ function RouterConfig({ history, app }) {
}, 'login');
},
},
{
path: 'domain',
onEnter: (ignored, replace, cb) => {
maybeLogin(replace).then(() => cb()).catch(err => cb(err));
},
getComponent(ignored, cb) {
require.ensure([], (require) => {
registerModel(app, require('./models/domain'));
cb(null, require('./routes/domain'));
}, 'domain');
},
},
{
path: 'main',
onEnter: (ignored, replace, cb) => {
......
import React from 'react';
import PropTypes from 'prop-types';
import { Form, Select, Button } from 'antd';
import { connect } from 'dva';
import styles from './index.less';
const FormItem = Form.Item;
class Domain extends React.Component {
constructor(props, context) {
super(props, context);
this.handleSubmit = this::this.handleSubmit;
}
componentDidMount() {
this.props.dispatch({ type: 'domain/fetch' });
}
handleSubmit(e) {
e.preventDefault();
this.props.form.validateFields((err, values) => {
if (!err) {
this.props.dispatch({
type: 'domain/switch',
payload: values.domain,
});
}
});
}
render() {
const { form, domain, loading } = this.props;
const currentDomain = domain.init;
const selectOptions = {};
const decoratorOptions = {
rules: [
{ required: true },
],
};
if (!currentDomain) {
selectOptions.placeholder = '请选择项目...';
} else {
decoratorOptions.initialValue = currentDomain;
}
return (
<div className={styles.canvas}>
<div className={styles.container}>
<Form onSubmit={this.handleSubmit}>
<FormItem>
{
form.getFieldDecorator('domain', decoratorOptions)(
<Select {...selectOptions}>
{domain.list.map(({ path, name }) => {
return <Select.Option value={path} key={path}>{name}</Select.Option>;
})}
</Select>,
)
}
</FormItem>
<FormItem>
<Button type="primary" htmlType="submit" className={styles.submit} loading={loading}>
确定
</Button>
</FormItem>
</Form>
</div>
</div>
);
}
}
Domain.propTypes = {
domain: PropTypes.object,
loading: PropTypes.bool,
form: PropTypes.object,
};
const mapStateToProps = ({ domain, loading }) => {
return {
domain,
loading: loading.effects['domain/switch'],
};
};
export default connect(mapStateToProps)(Form.create()(Domain));
.canvas {
width: 100%;
height: 100%;
position: relative;
background-color: #555555;
}
.container {
width: 320px;
height: 160px;
position: absolute;
background-color: white;
top: 50%;
left: 50%;
padding: 36px;
margin: -80px 0 0 -160px;
box-shadow: 0 0 100px rgba(0,0,0,.08);
}
.submit {
width: 100%;
}
......@@ -18,24 +18,16 @@ class HeaderPane extends React.Component {
dispatch({ type: 'main/fetchDomains' });
}
render() {
const { dispatch, user, domain, domainList, routes, params } = this.props;
const { dispatch, user, routes, params } = this.props;
const userTitle = (
<span>
<Icon type="user" />
{ user }
</span>
);
const domainTitle = (
<span>
<Icon type="home" />
{ domain }
</span>
);
const onClick = ({ keyPath }) => {
if (keyPath[1] === 'user' && keyPath[0] === 'logout') {
dispatch({ type: 'main/logout' });
} else if (keyPath[1] === 'domain') {
dispatch({ type: 'main/switchDomain', payload: keyPath[0] });
}
};
const breadsProps = {
......@@ -72,15 +64,6 @@ class HeaderPane extends React.Component {
</span>
</MenuItem>
</SubMenu>
<SubMenu title={domainTitle} key="domain">
{
domainList.map(dm => (
<MenuItem key={dm.path}>
{ dm.name }
</MenuItem>
))
}
</SubMenu>
</Menu>
</div>
);
......@@ -90,18 +73,11 @@ class HeaderPane extends React.Component {
HeaderPane.propTypes = {
dispatch: PropTypes.func,
user: PropTypes.string,
domain: PropTypes.string,
domainList: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.number,
name: PropTypes.string,
})),
};
const mapStateToProps = ({ main }) => {
return {
user: main.user,
domain: main.domain,
domainList: main.domainList,
};
};
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论