-
- {title === 'login' ? 'Sign in' : 'Create an account'}
-
-
- {title === 'login' ? 'We’re so excited to see you again!' : 'Glad to have you on board!'}
+ {title === 'login' ? 'Sign in' : 'Create an account'}
+
+ {title === 'login'
+ ? 'We’re so excited to see you again!'
+ : 'Glad to have you on board!'}
-
-
+
- {
- title === 'register' &&
-
+
- }
+ )}
-
+
- {
- title === 'login' &&
+ {title === 'login' && (
+
Remember me
- }
- {
- title === 'login' && (
- Don’t have an account?
-
-
)
- }
- {
- title === 'register' && (
+ )}
+
+ {' '}
+ {title === 'login' && (
+
+ Don’t have an account?
+
+
+ )}
+ {title === 'register' && (
+
Already have an account?
-
)
- }
+
+ )}
-
-
-
-
+
);
};
-export default connect(({ loginModel, loading }) => ({ loginModel, loading }))(View);
+export default connect(({ loginModel, loading }) => ({ loginModel, loading }))(
+ View,
+);
diff --git a/web/src/pages/login/model.ts b/web/src/pages/login/model.ts
index d95187e9..0ce6150c 100644
--- a/web/src/pages/login/model.ts
+++ b/web/src/pages/login/model.ts
@@ -1,6 +1,8 @@
-import { Effect, Reducer, Subscription } from 'umi'
-import { message } from 'antd';
+import { Authorization } from '@/constants/authorization';
import userService from '@/services/userService';
+import authorizationUtil from '@/utils/authorizationUtil';
+import { message } from 'antd';
+import { Effect, Reducer, Subscription } from 'umi';
export interface loginModelState {
list: any[];
@@ -28,49 +30,52 @@ const Model: logingModelType = {
},
subscriptions: {
setup({ dispatch, history }) {
- history.listen(location => { });
- }
+ history.listen((location) => {});
+ },
},
effects: {
*login({ payload = {} }, { call, put }) {
- console.log(111, payload)
+ console.log(111, payload);
const { data, response } = yield call(userService.login, payload);
- const { retcode, data: res, retmsg } = data
- console.log()
- const Authorization = response.headers.get('Authorization')
+ const { retcode, data: res, retmsg } = data;
+ console.log();
+ const authorization = response.headers.get(Authorization);
if (retcode === 0) {
message.success('登录成功!');
const token = res.access_token;
const userInfo = {
avatar: res.avatar,
name: res.nickname,
- email: res.email
+ email: res.email,
};
- localStorage.setItem('token', token)
- localStorage.setItem('userInfo', JSON.stringify(userInfo))
- localStorage.setItem('Authorization', Authorization)
- setTimeout(() => {
- window.location.href = '/file';
- }, 300);
+ authorizationUtil.setItems({
+ Authorization: authorization,
+ userInfo: JSON.stringify(userInfo),
+ Token: token,
+ });
+ // setTimeout(() => {
+ // window.location.href = '/file';
+ // }, 300);
}
+ return data;
},
*register({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(userService.register, payload);
- console.log()
- const { retcode, data: res, retmsg } = data
+ console.log();
+ const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
message.success('注册成功!');
- callback && callback()
+ callback && callback();
}
- }
+ },
},
reducers: {
updateState(state, { payload }) {
return {
...state,
- ...payload
+ ...payload,
};
- }
- }
+ },
+ },
};
export default Model;
diff --git a/web/src/pages/setting/index.tsx b/web/src/pages/setting/index.tsx
index fdf15429..98855294 100644
--- a/web/src/pages/setting/index.tsx
+++ b/web/src/pages/setting/index.tsx
@@ -1,90 +1,105 @@
-import { connect, Dispatch } from 'umi';
+import { Button, FloatButton } from 'antd';
import i18n from 'i18next';
-import { useTranslation, Trans } from 'react-i18next'
-import { Button, FloatButton } from 'antd'
-
+import { useTranslation } from 'react-i18next';
+import { Dispatch, connect } from 'umi';
+import authorizationUtil from '@/utils/authorizationUtil';
+import { FC, useEffect } from 'react';
+import CPwModal from './CPwModal';
+import List from './List';
+import SAKModal from './SAKModal';
+import SSModal from './SSModal';
+import TntModal from './TntModal';
import styles from './index.less';
-import CPwModal from './CPwModal'
-import SAKModal from './SAKModal'
-import TntModal from './TntModal'
-import SSModal from './SSModal'
-import List from './List'
-import { useEffect, useState, FC } from 'react';
interface CPwModalProps {
- dispatch: Dispatch;
- settingModel: any
+ dispatch: Dispatch;
+ settingModel: any;
}
const Index: FC
= ({ settingModel, dispatch }) => {
- // const [llm_factory, set_llm_factory] = useState('')
- const { t } = useTranslation()
- const userInfo = JSON.parse(localStorage.getItem('userInfo') || '')
- const changeLang = (val: string) => { // 改变状态里的 语言 进行切换
- i18n.changeLanguage(val);
- }
- useEffect(() => {
- dispatch({
- type: 'settingModel/getTenantInfo',
- payload: {
- }
- });
- }, [])
- const showCPwModal = () => {
- dispatch({
- type: 'settingModel/updateState',
- payload: {
- isShowPSwModal: true
- }
- });
- };
- const showTntModal = () => {
- dispatch({
- type: 'settingModel/updateState',
- payload: {
- isShowTntModal: true
- }
- });
- };
- const showSSModal = () => {
- dispatch({
- type: 'settingModel/updateState',
- payload: {
- isShowSSModal: true
- }
- });
- // dispatch({
- // type: 'settingModel/getTenantInfo',
- // payload: {
- // }
- // });
- };
- return (
-
-
-

-
-
账号:{userInfo.name}
-
密码:******修改密码
-
-
-
-
-
- 租户
-
-
- 系统模型设置
-
-
-
-
-
-
-
-
i18n.changeLanguage(i18n.language == 'en' ? 'zh' : 'en')} type="default" style={{ right: 94, fontSize: 14 }} />
-
-
-
- );
-}
-export default connect(({ settingModel, loading }) => ({ settingModel, loading }))(Index);
+ // const [llm_factory, set_llm_factory] = useState('')
+ const { t } = useTranslation();
+ const userInfo = authorizationUtil.getUserInfoObject();
+ const changeLang = (val: string) => {
+ // 改变状态里的 语言 进行切换
+ i18n.changeLanguage(val);
+ };
+ useEffect(() => {
+ dispatch({
+ type: 'settingModel/getTenantInfo',
+ payload: {},
+ });
+ }, []);
+ const showCPwModal = () => {
+ dispatch({
+ type: 'settingModel/updateState',
+ payload: {
+ isShowPSwModal: true,
+ },
+ });
+ };
+ const showTntModal = () => {
+ dispatch({
+ type: 'settingModel/updateState',
+ payload: {
+ isShowTntModal: true,
+ },
+ });
+ };
+ const showSSModal = () => {
+ dispatch({
+ type: 'settingModel/updateState',
+ payload: {
+ isShowSSModal: true,
+ },
+ });
+ // dispatch({
+ // type: 'settingModel/getTenantInfo',
+ // payload: {
+ // }
+ // });
+ };
+ return (
+
+
+

+
+
账号:{userInfo.name}
+
+ 密码:******
+
+ 修改密码
+
+
+
+
+
+
+ 租户
+
+
+ 系统模型设置
+
+
+
+
+
+
+
+
i18n.changeLanguage(i18n.language == 'en' ? 'zh' : 'en')}
+ type="default"
+ style={{ right: 94, fontSize: 14 }}
+ />
+
+ );
+};
+export default connect(({ settingModel, loading }) => ({
+ settingModel,
+ loading,
+}))(Index);
diff --git a/web/src/pages/setting/model.ts b/web/src/pages/setting/model.ts
index 4800ff1a..0971b31e 100644
--- a/web/src/pages/setting/model.ts
+++ b/web/src/pages/setting/model.ts
@@ -1,6 +1,7 @@
-import { Effect, Reducer, Subscription } from 'umi';
-import { message } from 'antd';
import userService from '@/services/userService';
+import authorizationUtil from '@/utils/authorizationUtil';
+import { message } from 'antd';
+import { Effect, Reducer, Subscription } from 'umi';
export interface settingModelState {
isShowPSwModal: boolean;
@@ -9,10 +10,10 @@ export interface settingModelState {
isShowSSModal: boolean;
llm_factory: string;
loading: boolean;
- tenantIfo: any,
- llmInfo: any,
- myLlm: any[],
- factoriesList: any[]
+ tenantIfo: any;
+ llmInfo: any;
+ myLlm: any[];
+ factoriesList: any[];
}
export interface settingModelType {
@@ -45,32 +46,31 @@ const Model: settingModelType = {
tenantIfo: {},
llmInfo: {},
myLlm: [],
- factoriesList: []
+ factoriesList: [],
},
subscriptions: {
setup({ dispatch, history }) {
- history.listen(location => {
- });
- }
+ history.listen((location) => {});
+ },
},
effects: {
*setting({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(userService.setting, payload);
- const { retcode, data: res, retmsg } = data
+ const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
message.success('密码修改成功!');
- callback && callback()
+ callback && callback();
}
},
*getUserInfo({ payload = {} }, { call, put }) {
const { data, response } = yield call(userService.user_info, payload);
- const { retcode, data: res, retmsg } = data
+ const { retcode, data: res, retmsg } = data;
const userInfo = {
avatar: res.avatar,
name: res.nickname,
- email: res.email
+ email: res.email,
};
- localStorage.setItem('userInfo', JSON.stringify(userInfo))
+ authorizationUtil.setUserInfo(userInfo);
if (retcode === 0) {
// localStorage.setItem('userInfo',res.)
}
@@ -79,91 +79,100 @@ const Model: settingModelType = {
yield put({
type: 'updateState',
payload: {
- loading: true
- }
+ loading: true,
+ },
});
- const { data, response } = yield call(userService.get_tenant_info, payload);
- const { retcode, data: res, retmsg } = data
+ const { data, response } = yield call(
+ userService.get_tenant_info,
+ payload,
+ );
+ const { retcode, data: res, retmsg } = data;
// llm_id 对应chat_id
// asr_id 对应speech2txt
yield put({
type: 'updateState',
payload: {
- loading: false
- }
+ loading: false,
+ },
});
if (retcode === 0) {
- res.chat_id = res.llm_id
- res.speech2text_id = res.asr_id
+ res.chat_id = res.llm_id;
+ res.speech2text_id = res.asr_id;
yield put({
type: 'updateState',
payload: {
- tenantIfo: res
- }
+ tenantIfo: res,
+ },
});
}
},
*set_tenant_info({ payload = {} }, { call, put }) {
- const { data, response } = yield call(userService.set_tenant_info, payload);
- const { retcode, data: res, retmsg } = data
+ const { data, response } = yield call(
+ userService.set_tenant_info,
+ payload,
+ );
+ const { retcode, data: res, retmsg } = data;
// llm_id 对应chat_id
// asr_id 对应speech2txt
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
- isShowSSModal: false
- }
+ isShowSSModal: false,
+ },
});
yield put({
- type: 'getTenantInfo'
- })
+ type: 'getTenantInfo',
+ });
}
},
*factories_list({ payload = {} }, { call, put }) {
- const { data, response } = yield call(userService.factories_list, payload);
- const { retcode, data: res, retmsg } = data
+ const { data, response } = yield call(
+ userService.factories_list,
+ payload,
+ );
+ const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
- factoriesList: res
- }
+ factoriesList: res,
+ },
});
}
},
*llm_list({ payload = {} }, { call, put }) {
const { data, response } = yield call(userService.llm_list, payload);
- const { retcode, data: res, retmsg } = data
+ const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
- llmInfo: res
- }
+ llmInfo: res,
+ },
});
}
},
*my_llm({ payload = {} }, { call, put }) {
const { data, response } = yield call(userService.my_llm, payload);
- const { retcode, data: res, retmsg } = data
+ const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
yield put({
type: 'updateState',
payload: {
- myLlm: res
- }
+ myLlm: res,
+ },
});
}
},
*set_api_key({ payload = {}, callback }, { call, put }) {
const { data, response } = yield call(userService.set_api_key, payload);
- const { retcode, data: res, retmsg } = data
+ const { retcode, data: res, retmsg } = data;
if (retcode === 0) {
message.success('设置API KEY成功!');
- callback && callback()
+ callback && callback();
}
},
},
@@ -171,9 +180,9 @@ const Model: settingModelType = {
updateState(state, { payload }) {
return {
...state,
- ...payload
+ ...payload,
};
- }
- }
+ },
+ },
};
export default Model;
diff --git a/web/src/routes.ts b/web/src/routes.ts
new file mode 100644
index 00000000..547404bd
--- /dev/null
+++ b/web/src/routes.ts
@@ -0,0 +1,43 @@
+const routes = [
+ {
+ path: '/login',
+ component: '@/pages/login',
+ layout: false,
+ },
+ {
+ path: '/',
+ component: '@/layouts',
+ layout: false,
+ wrappers: ['@/wrappers/auth'],
+ routes: [
+ { path: '/', redirect: '/knowledge' },
+ {
+ path: '/knowledge',
+ component: '@/pages/knowledge',
+ },
+ {
+ path: '/knowledge/add/*',
+ component: '@/pages/add-knowledge',
+ },
+ {
+ path: '/chat',
+ component: '@/pages/chat',
+ },
+ {
+ path: '/setting',
+ component: '@/pages/setting',
+ },
+ {
+ path: '/file',
+ component: '@/pages/file',
+ },
+ ],
+ },
+ {
+ path: '/*',
+ component: '@/pages/404',
+ layout: false,
+ },
+];
+
+export default routes;
diff --git a/web/src/utils/authorizationUtil.ts b/web/src/utils/authorizationUtil.ts
new file mode 100644
index 00000000..a2b3d069
--- /dev/null
+++ b/web/src/utils/authorizationUtil.ts
@@ -0,0 +1,43 @@
+import { Authorization, Token, UserInfo } from '@/constants/authorization';
+
+const KeySet = [Authorization, Token, UserInfo];
+
+const storage = {
+ getAuthorization: () => {
+ return localStorage.getItem(Authorization);
+ },
+ getToken: () => {
+ return localStorage.getItem(Token);
+ },
+ getUserInfo: () => {
+ return localStorage.getItem(UserInfo);
+ },
+ getUserInfoObject: () => {
+ return JSON.parse(localStorage.getItem('userInfo') || '');
+ },
+ setAuthorization: (value: string) => {
+ localStorage.setItem(Authorization, value);
+ },
+ setToken: (value: string) => {
+ localStorage.setItem(Token, value);
+ },
+ setUserInfo: (value: string | Object) => {
+ let valueStr = typeof value !== 'string' ? JSON.stringify(value) : value;
+ localStorage.setItem(UserInfo, valueStr);
+ },
+ setItems: (pairs: Record) => {
+ Object.entries(pairs).forEach(([key, value]) => {
+ localStorage.setItem(key, value);
+ });
+ },
+ removeAuthorization: () => {
+ localStorage.removeItem(Authorization);
+ },
+ removeAll: () => {
+ KeySet.forEach((x) => {
+ localStorage.removeItem(x);
+ });
+ },
+};
+
+export default storage;
diff --git a/web/src/utils/history.ts b/web/src/utils/history.ts
new file mode 100644
index 00000000..f529e5d6
--- /dev/null
+++ b/web/src/utils/history.ts
@@ -0,0 +1,3 @@
+import { createBrowserHistory } from 'history';
+
+export const history = createBrowserHistory();
diff --git a/web/src/utils/request.ts b/web/src/utils/request.ts
index 781ea67f..60fae733 100644
--- a/web/src/utils/request.ts
+++ b/web/src/utils/request.ts
@@ -1,14 +1,14 @@
-
+import { message, notification } from 'antd';
import { extend } from 'umi-request';
-import { notification, message } from 'antd';
+import { Authorization } from '@/constants/authorization';
import api from '@/utils/api';
+import authorizationUtil from '@/utils/authorizationUtil';
+
const { login } = api;
const ABORT_REQUEST_ERR_MESSAGE = 'The user aborted a request.'; // 手动中断请求。errorHandler 抛出的error message
-
-
const retcodeMessage = {
200: '服务器成功返回请求的数据。',
201: '新建或修改数据成功。',
@@ -24,7 +24,7 @@ const retcodeMessage = {
500: '服务器发生错误,请检查服务器。',
502: '网关错误。',
503: '服务不可用,服务器暂时过载或维护。',
- 504: '网关超时。'
+ 504: '网关超时。',
};
type retcode =
| 200
@@ -49,16 +49,20 @@ interface responseType {
retcode: number;
data: any;
retmsg: string;
- status: number
+ status: number;
}
-const errorHandler = (error: { response: Response, message: string }): Response => {
+const errorHandler = (error: {
+ response: Response;
+ message: string;
+}): Response => {
const { response } = error;
// 手动中断请求 abort
if (error.message === ABORT_REQUEST_ERR_MESSAGE) {
console.log('user abort request');
} else {
if (response && response.status) {
- const errorText = retcodeMessage[response.status as retcode] || response.statusText;
+ const errorText =
+ retcodeMessage[response.status as retcode] || response.statusText;
const { status, url } = response;
notification.error({
message: `请求错误 ${status}: ${url}`,
@@ -80,21 +84,21 @@ const errorHandler = (error: { response: Response, message: string }): Response
const request = extend({
errorHandler, // 默认错误处理
timeout: 3000000,
- getResponse: true
+ getResponse: true,
});
request.interceptors.request.use((url: string, options: any) => {
- const Authorization = localStorage.getItem('Authorization')
+ const authorization = authorizationUtil.getAuthorization();
return {
url,
options: {
...options,
headers: {
- ...(options.skipToken ? undefined : { Authorization }),
- ...options.headers
+ ...(options.skipToken ? undefined : { [Authorization]: authorization }),
+ ...options.headers,
},
- interceptors: true
- }
+ interceptors: true,
+ },
};
});
@@ -103,7 +107,7 @@ request.interceptors.request.use((url: string, options: any) => {
* */
request.interceptors.response.use(async (response: any, request) => {
- console.log(response, request)
+ console.log(response, request);
const data: responseType = await response.clone().json();
// response 拦截
@@ -113,6 +117,8 @@ request.interceptors.response.use(async (response: any, request) => {
description: data.retmsg,
duration: 3,
});
+ authorizationUtil.removeAll();
+ // history.push('/login'); // Will not jump to the login page
} else if (data.retcode !== 0) {
if (data.retcode === 100) {
message.error(data.retmsg);
@@ -126,7 +132,6 @@ request.interceptors.response.use(async (response: any, request) => {
return response;
} else {
-
return response;
}
});
diff --git a/web/src/wrappers/auth.tsx b/web/src/wrappers/auth.tsx
index 5ad888ca..2f0b8037 100644
--- a/web/src/wrappers/auth.tsx
+++ b/web/src/wrappers/auth.tsx
@@ -1,12 +1,11 @@
-import { Navigate, Outlet } from 'umi'
+import { useAuth } from '@/hooks/authHook';
+import { Navigate, Outlet } from 'umi';
-export default (props) => {
- // const { isLogin } = useAuth();
- console.log(props)
- const isLogin = false
- if (isLogin) {
- return ;
- } else {
- return ;
- }
-}
\ No newline at end of file
+export default () => {
+ const { isLogin } = useAuth();
+ if (isLogin) {
+ return ;
+ } else {
+ return ;
+ }
+};