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

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

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