提交 8a3ce594 authored 作者: vipcxj's avatar vipcxj

improve: 改进切换作用域的逻辑

上级 c9bca7e6
import { routerRedux } from 'dva/router'; import { routerRedux } from 'dva/router';
import { fetchDomains, switchDomain, currentDomain } from '../services/domain'; import { fetchDomains, switchDomain, getInfo, currentDomain } from '../services/domain';
import { getDomain, histories, setDomain } from '../utils/auth'; import { getDomain, histories, setDomain } from '../utils/auth';
import config from '../utils/config'; import config from '../utils/config';
...@@ -20,7 +20,13 @@ export default { ...@@ -20,7 +20,13 @@ export default {
effects: { effects: {
*fetch(ignored, { put, call }) { *fetch(ignored, { put, call }) {
const domain = yield call(getDomain); const domain = yield call(getDomain);
const init = domain ? domain.path : undefined; let init;
if (domain && domain.path) {
init = yield call(getInfo, domain.path);
}
if (!init) {
init = yield call(currentDomain);
}
const list = yield call(fetchDomains, '/', true); const list = yield call(fetchDomains, '/', true);
yield put({ type: 'queryInit', payload: init }); yield put({ type: 'queryInit', payload: init });
yield put({ type: 'queryList', payload: list }); yield put({ type: 'queryList', payload: list });
......
...@@ -38,10 +38,10 @@ class Domain extends React.Component { ...@@ -38,10 +38,10 @@ class Domain extends React.Component {
{ required: true }, { required: true },
], ],
}; };
if (!currentDomain) { if (!currentDomain || !currentDomain.path) {
selectOptions.placeholder = '请选择项目...'; selectOptions.placeholder = '请选择项目...';
} else { } else {
decoratorOptions.initialValue = currentDomain; decoratorOptions.initialValue = currentDomain.path;
} }
return ( return (
<div className={styles.canvas}> <div className={styles.canvas}>
......
...@@ -30,6 +30,10 @@ export async function fetchDomains(basePath, withRoot = false) { ...@@ -30,6 +30,10 @@ export async function fetchDomains(basePath, withRoot = false) {
return infoList; return infoList;
} }
export async function getInfo(dmPath) {
return request(`${config.apiContextPath}/api/domain/user/info`, { dmPath });
}
export async function switchDomain(path) { export async function switchDomain(path) {
await post(`${config.apiContextPath}/api/domain/user/path`, { dmPath: path }); await post(`${config.apiContextPath}/api/domain/user/path`, { dmPath: path });
histories.pushHistory('domain', path); histories.pushHistory('domain', path);
......
import React from 'react'; import React from 'react';
import { message, Modal } from 'antd'; import { message, Modal } from 'antd';
import debounce from 'lodash/debounce';
import { push } from '../services/route'; import { push } from '../services/route';
import { errors as errorCodes } from './config'; import { errors as errorCodes } from './config';
...@@ -12,18 +13,27 @@ const errStyle = { ...@@ -12,18 +13,27 @@ const errStyle = {
marginTop: '24px', marginTop: '24px',
}; };
const msgError = debounce((msg) => {
message.error(msg);
}, 500);
export function processError(err) { export function processError(err) {
if (err) { if (err) {
if (err.data && err.data.errorCode) { if (err.data && err.data.errorCode) {
const data = err.data; const data = err.data;
switch (data.errorCode) { switch (data.errorCode) {
case errorCodes.no_such_user: case errorCodes.no_such_user:
message.error('用户不存在!'); msgError('用户不存在!');
break; break;
case errorCodes.invalid_token: case errorCodes.invalid_token:
case errorCodes.token_missing: case errorCodes.token_missing:
msgError('无效或过期的登录令牌,请重新登录!');
push('/login'); push('/login');
break; break;
case errorCodes.no_domain_right:
msgError('没有该区域的访问权限,请重新选择区域!');
push('/domain');
break;
default: default:
showError(err); showError(err);
} }
...@@ -44,7 +54,7 @@ function showError(err) { ...@@ -44,7 +54,7 @@ function showError(err) {
msg = err.message; msg = err.message;
} }
if (msg && msg.length < 256) { if (msg && msg.length < 256) {
message.error(msg); msgError(msg);
} else { } else {
Modal.error({ Modal.error({
title: '服务器内部错误', title: '服务器内部错误',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论