Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
C
chatGLM
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘坚-丰林-DEV
chatGLM
Commits
b7f9e938
Commit
b7f9e938
authored
Apr 17, 2023
by
文旺-丰林-DEV
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix login expires
parent
977dae7f
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
39 additions
and
16 deletions
+39
-16
access.ts
src/access.ts
+20
-1
app.tsx
src/app.tsx
+0
-1
index.tsx
src/components/loginModal/index.tsx
+2
-0
index.tsx
src/pages/Chat/index.tsx
+17
-14
No files found.
src/access.ts
View file @
b7f9e938
import
{
message
}
from
'antd'
;
import
moment
from
'moment'
;
/**
* @see https://umijs.org/zh-CN/plugins/plugin-access
* */
export
default
function
access
(
initialState
:
{
userInfo
:
{
token
:
''
;
roles
:
[];
name
:
''
;
userName
:
''
};
expires
:
0
;
})
{
c
onsole
.
log
(
'initialState'
,
initialState
);
c
heckIsTokenExpires
(
);
return
initialState
.
userInfo
??
{};
}
export
function
checkIsTokenExpires
()
{
const
expires
=
parseInt
(
localStorage
.
getItem
(
'expires'
)
||
'0'
);
const
now
=
moment
().
unix
();
const
user
=
localStorage
.
getItem
(
'user'
);
if
(
expires
-
now
<=
0
)
{
localStorage
.
removeItem
(
'user'
);
if
(
user
)
{
message
.
error
(
'会话已过期,请重新登录'
);
window
.
location
.
href
=
'/chat'
;
return
true
;
}
}
return
false
;
}
src/app.tsx
View file @
b7f9e938
...
...
@@ -16,7 +16,6 @@ export const initialStateConfig = {
export
async
function
getInitialState
()
{
const
userInfo
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
||
'{}'
);
if
(
isEmpty
(
userInfo
))
{
history
.
push
(
loginPath
);
return
{};
...
...
src/components/loginModal/index.tsx
View file @
b7f9e938
...
...
@@ -5,6 +5,7 @@ import logoSvg from '../../assets/logo.svg';
import
{
useEffect
,
useRef
,
useState
}
from
'react'
;
import
{
loginChatGLM
}
from
'@/services/chatGLM/api'
;
import
{
useModel
}
from
'umi'
;
import
moment
from
'moment'
;
interface
ILoginModalProps
{
open
:
boolean
;
setOpen
:
(
value
:
boolean
)
=>
void
;
...
...
@@ -46,6 +47,7 @@ const LoginModal = (props: ILoginModalProps) => {
if
(
checked
)
{
localStorage
.
setItem
(
'account'
,
JSON
.
stringify
({
username
,
password
,
checked
}));
}
localStorage
.
setItem
(
'expires'
,
moment
().
add
(
11
,
'hour'
).
unix
().
toString
());
setInitialState
({
...
initialState
,
userInfo
:
result
});
localStorage
.
setItem
(
'user'
,
JSON
.
stringify
(
result
));
setLoading
(
false
);
...
...
src/pages/Chat/index.tsx
View file @
b7f9e938
...
...
@@ -18,6 +18,7 @@ import { useWebSocket, useRequest } from 'ahooks';
import
{
GetChatGLMToken
,
GetPromptList
}
from
'@/services/chatGLM/api'
;
import
{
useAccess
}
from
'umi'
;
import
{
PageLoading
}
from
'@ant-design/pro-layout'
;
import
{
checkIsTokenExpires
}
from
'@/access'
;
const
{
useBreakpoint
}
=
Grid
;
const
{
Title
}
=
Typography
;
...
...
@@ -76,20 +77,22 @@ const Chat: React.FC = () => {
return
messageHistory
.
current
;
},
[
answer
]);
async
function
handleSendMessage
()
{
messageHistory
.
current
.
push
({
prompt
:
chat
,
answer
:
''
});
setLoading
(
true
);
sendMessage
&&
glmToken
&&
sendMessage
(
JSON
.
stringify
({
prompt
:
chat
,
max_length
:
2048
,
top_p
:
0.7
,
temperature
:
0.95
,
history
:
[
messageHistory
.
current
.
map
((
h
)
=>
h
.
prompt
)],
token
:
glmToken
,
}),
);
if
(
!
checkIsTokenExpires
())
{
messageHistory
.
current
.
push
({
prompt
:
chat
,
answer
:
''
});
setLoading
(
true
);
sendMessage
&&
glmToken
&&
sendMessage
(
JSON
.
stringify
({
prompt
:
chat
,
max_length
:
2048
,
top_p
:
0.7
,
temperature
:
0.95
,
history
:
[
messageHistory
.
current
.
map
((
h
)
=>
h
.
prompt
)],
token
:
glmToken
,
}),
);
}
}
useEffect
(()
=>
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment