提交 abae3de5 authored 作者: vipcxj's avatar vipcxj

记录历史区域选择,在存在历史选择的情况下,登录后直接跳转到主页面,并切换到历史区域

上级 48734dd4
import { histories } from '../utils/auth';
const data = {
app: null,
};
export function initApp(app) {
export async function initApp(app) {
data.app = app;
await histories.init();
return data.app;
}
export function getApp() {
......
......@@ -19,8 +19,6 @@ const app = dva({
},
});
initApp(app);
app.model(appModel);
// 2. Plugins
......@@ -35,4 +33,4 @@ app.use(createLoading({
app.router(routerConfig);
// 5. Start
app.start('#root');
initApp(app).then(theApp => theApp.start('#root'));
import { routerRedux } from 'dva/router';
import { login, userInfo } from '../services/login';
import { fullPath } from '../utils/helper';
import { setToken, setUser } from '../utils/auth';
import { setToken, setUser, setDomain, histories } from '../utils/auth';
import { switchDomain, currentDomain } from '../services/domain';
import { errors } from '../utils/error';
export default {
......@@ -32,7 +33,15 @@ export default {
yield call(setToken, tokenId);
const uInfo = yield call(userInfo);
yield call(setUser, uInfo.id, uInfo.name);
yield put(routerRedux.push(fullPath('/domain')));
const path = yield call(histories.getLatest, 'domain');
if (!path) {
yield put(routerRedux.push(fullPath('/domain')));
} else {
yield call(switchDomain, path);
const { name } = yield call(currentDomain);
yield call(setDomain, name, path);
yield put(routerRedux.push(fullPath('/main')));
}
},
},
subscriptions: {},
......
......@@ -87,7 +87,7 @@ export default {
effects: {
*fetchDomain(ignored, { put, call }) {
const domain = getDomain();
const domain = yield call(getDomain);
let domainName;
if (!domain) {
const { path, name } = yield call(currentDomain);
......
......@@ -2,7 +2,7 @@
import request from '../utils/request';
import post from '../utils/post';
import config from '../utils/config';
import { getDomain } from '../utils/auth';
import { getDomain, histories } from '../utils/auth';
export async function fetchDomains(basePath, withRoot = false) {
if (!basePath) {
......@@ -31,7 +31,8 @@ export async function fetchDomains(basePath, withRoot = false) {
}
export async function switchDomain(path) {
return post(`${config.apiContextPath}/api/domain/user/path`, { dmPath: path });
await post(`${config.apiContextPath}/api/domain/user/path`, { dmPath: path });
histories.pushHistory('domain', path);
}
export async function currentDomain() {
......
......@@ -148,4 +148,7 @@ export const histories = {
}
return db.set(`history.${name}`, history).write();
},
async init() {
return db.read();
},
};
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论