[improvement](semantic-fe) Added parameter compatibility for network requests in different modes

This commit is contained in:
tristanliu
2023-06-21 11:10:07 +08:00
parent 693fc03c6f
commit 9c9d7382fe
12 changed files with 42 additions and 42 deletions

View File

@@ -64,7 +64,7 @@
"@antv/layout": "^0.3.20",
"@antv/xflow": "^1.0.55",
"@babel/runtime": "^7.22.5",
"supersonic-chat-sdk": "^0.1.6",
"supersonic-chat-sdk": "^0.1.0",
"@types/numeral": "^2.0.2",
"@types/react-draft-wysiwyg": "^1.13.2",
"@types/react-syntax-highlighter": "^13.5.0",

View File

@@ -12,8 +12,6 @@ import defaultSettings from '../config/defaultSettings';
import settings from '../config/themeSettings';
import { deleteUrlQuery } from './utils/utils';
import { AUTH_TOKEN_KEY, FROM_URL_KEY } from '@/common/constants';
import 'supersonic-chat-sdk/dist/index.css';
import { setToken as setChatSdkToken } from 'supersonic-chat-sdk';
export { request } from './services/request';
import { ROUTE_AUTH_CODES } from '../config/routes';
@@ -52,7 +50,7 @@ const getToken = async () => {
try {
const fromUrl = localStorage.getItem(FROM_URL_KEY);
const res = await queryToken(data.code as string);
localStorage.setItem(TOKEN_KEY, res.data.authToken);
localStorage.setItem(TOKEN_KEY, res.payload);
const newUrl = deleteUrlQuery(window.location.href, 'code');
window.location.href = fromUrl || newUrl;
} catch (err) {
@@ -98,8 +96,6 @@ export async function getInitialState(): Promise<{
await getToken();
}
setChatSdkToken(localStorage.getItem(AUTH_TOKEN_KEY) || '');
const currentUser = await fetchUserInfo();
if (currentUser) {

View File

@@ -1,6 +1,5 @@
// 登陆 token key
export const AUTH_TOKEN_KEY = 'SUPERSONIC_TOKEN';
export const AUTH_TOKEN_KEY = process.env.APP_TARGET === 'inner' ? 'TME_TOKEN' : 'SUPERSONIC_TOKEN';
// 记录上次访问页面
export const FROM_URL_KEY = 'FROM_URL';

View File

@@ -22,11 +22,12 @@ const SelectTMEPerson: FC<Props> = ({ placeholder, value, isMultiple = true, onC
{
fetcher: async () => {
const res = await getAllUser();
if (res.code !== 200) {
if (res.code == 200 || Number(res.code) == 0) {
return res.data || [];
} else {
message.error(res.msg);
throw new Error(res.msg);
}
return res.data || [];
},
updater: (list) => {
const users = list.map((item: UserItem) => {

View File

@@ -17,15 +17,17 @@ const Context: React.FC<Props> = ({ chatContext }) => {
<span className={styles.fieldName}></span>
<span className={styles.fieldValue}>{domainName}</span>
</div>
{dateInfo && (
<div className={styles.field}>
<span className={styles.fieldName}></span>
<span className={styles.fieldValue}>
{dateInfo.text ||
`${moment(dateInfo.endDate).diff(moment(dateInfo.startDate), 'days') + 1}`}
</span>
</div>
)}
{
dateInfo && (
<div className={styles.field}>
<span className={styles.fieldName}></span>
<span className={styles.fieldValue}>
{dateInfo.text ||
`${moment(dateInfo.endDate).diff(moment(dateInfo.startDate), 'days') + 1}`}
</span>
</div>
)
}
{metrics && metrics.length > 0 && (
<div className={styles.field}>
<span className={styles.fieldName}></span>

View File

@@ -10,9 +10,16 @@ import Conversation from './Conversation';
import RightSection from './RightSection';
import ChatFooter from './ChatFooter';
import classNames from 'classnames';
import { DEFAULT_CONVERSATION_NAME, WEB_TITLE } from '@/common/constants';
import { HistoryMsgItemType, MsgDataType, getHistoryMsg, queryContext } from 'supersonic-chat-sdk';
import { AUTH_TOKEN_KEY, DEFAULT_CONVERSATION_NAME, WEB_TITLE } from '@/common/constants';
import {
HistoryMsgItemType,
MsgDataType,
getHistoryMsg,
queryContext,
setToken as setChatSdkToken,
} from 'supersonic-chat-sdk';
import { getConversationContext } from './utils';
import 'supersonic-chat-sdk/dist/index.css';
const Chat = () => {
const [messageList, setMessageList] = useState<MessageItem[]>([]);
@@ -27,6 +34,10 @@ const Chat = () => {
const conversationRef = useRef<any>();
const chatFooterRef = useRef<any>();
useEffect(() => {
setChatSdkToken(localStorage.getItem(AUTH_TOKEN_KEY) || '');
}, []);
const sendHelloRsp = () => {
setMessageList([
{

View File

@@ -12,7 +12,6 @@ import { postUserLogin, userRegister } from './services';
import { AUTH_TOKEN_KEY } from '@/common/constants';
import { queryCurrentUser } from '@/services/user';
import { history, useModel } from 'umi';
// import { setToken as setChatSdkToken } from 'supersonic-chat-sdk';
const { Item } = Form;
const LoginPage: React.FC = () => {
@@ -25,7 +24,6 @@ const LoginPage: React.FC = () => {
const { code, data, msg } = await postUserLogin(values);
if (code === 200) {
localStorage.setItem(AUTH_TOKEN_KEY, data);
// setChatSdkToken(data || '');
const { code: queryUserCode, data: queryUserData } = await queryCurrentUser();
if (queryUserCode === 200) {
const currentUser = {

View File

@@ -26,6 +26,7 @@ type Props = {
const DEFAULT_LEFT_SIZE = '300px';
const DomainManger: React.FC<Props> = ({ domainManger, dispatch }) => {
window.RUNNING_ENV = 'semantic';
const [collapsed, setCollapsed] = useState(false);
const [leftSize, setLeftSize] = useState('');
const { selectDomainId, selectDomainName } = domainManger;

View File

@@ -196,7 +196,6 @@ const DomainManger: React.FC<Props> = ({ domainManger, domainId }) => {
};
// const [visible, setVisible] = useState(false);
useEffect(() => {
console.log(domainId, graphData, 'domainId');
if (!(Array.isArray(graphData.children) && graphData.children.length > 0)) {
return;
}
@@ -356,7 +355,6 @@ const DomainManger: React.FC<Props> = ({ domainManger, domainId }) => {
labelCfg: { style: { fill: '#3c3c3c' } },
};
});
console.log(graphData, 'graphData');
// graph.data(graphData);
graph.changeData(graphData);
graph.render();
@@ -386,7 +384,6 @@ const DomainManger: React.FC<Props> = ({ domainManger, domainId }) => {
value={graphShowType}
onChange={(e) => {
const { value } = e.target;
console.log(value, 'value');
setGraphShowType(value);
changeGraphData(dataSourceListData, value);
}}

View File

@@ -53,14 +53,14 @@ const PermissionTable: React.FC<Props> = ({ domainManger }) => {
const queryDepartmentData = async () => {
const { code, data } = await getDepartmentTree();
if (code === 200) {
if (code === 200 || code === '0') {
setDepartmentTreeData(data);
}
};
const queryTmePersonData = async () => {
const { code, data } = await getAllUser();
if (code === 200) {
if (code === 200 || Number(code) === 0) {
setTmePerson(data);
}
};

View File

@@ -9,7 +9,7 @@ export type LoginParamsType = {
};
export async function queryToken(code: string) {
return request(`${process.env.API_BASE_URL}user/ioaLoginCallback`, {
return request(`/davinciapi/login/tmeloginCallback`, {
params: { code },
});
}

View File

@@ -20,6 +20,7 @@ const authHeaderInterceptor = (url: string, options: RequestOptionsInit) => {
const token = query[TOKEN_KEY] || localStorage.getItem(TOKEN_KEY);
if (token) {
headers.Authorization = `Bearer ${token}`;
headers.auth = `Bearer ${token}`;
localStorage.setItem(TOKEN_KEY, token);
}
@@ -31,25 +32,19 @@ const authHeaderInterceptor = (url: string, options: RequestOptionsInit) => {
};
const responseInterceptor = async (response: Response) => {
const data: Result<any> = await response?.clone()?.json?.();
if (Number(data.code) === 403) {
history.push('/login');
return response;
}
const redirect = response.headers.get('redirect'); // 若HEADER中含有REDIRECT说明后端想重定向
if (redirect === 'REDIRECT') {
localStorage.removeItem(TOKEN_KEY);
let win: any = window;
while (win !== win.top) {
win = win.top;
}
if (!/fromExternal=true/.test(win.location.search)) {
localStorage.setItem(FROM_URL_KEY, win.location.href);
}
const win: any = window;
// 将后端重定向的地址取出来,使用win.location.href去实现重定向的要求
const contextpath = response.headers.get('contextpath');
win.location.href = contextpath;
} else {
const data: Result<any> = await response?.clone()?.json?.();
if (Number(data.code) === 403) {
history.push('/login');
return response;
}
}
return response;