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
6ed561ee
Commit
6ed561ee
authored
Apr 16, 2023
by
Ylg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replace loacalStorage with access
parent
5ac257d2
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
16 additions
and
11 deletions
+16
-11
access.ts
src/access.ts
+4
-4
app.tsx
src/app.tsx
+5
-3
index.tsx
src/pages/Chat/index.tsx
+6
-3
api.ts
src/services/chatGLM/api.ts
+1
-1
No files found.
src/access.ts
View file @
6ed561ee
/**
/**
* @see https://umijs.org/zh-CN/plugins/plugin-access
* @see https://umijs.org/zh-CN/plugins/plugin-access
* */
* */
export
default
function
access
(
initialState
:
{
currentUser
?:
API
.
CurrentUser
}
|
undefined
)
{
export
default
function
access
(
initialState
:
{
userInfo
:
{
token
:
''
};
}
)
{
console
.
log
(
initialState
)
console
.
log
(
'initialState'
,
initialState
)
const
{
currentUser
}
=
initialState
??
{};
const
{
token
}
=
initialState
.
userInfo
??
{};
return
{
return
{
canAdmin
:
currentUser
&&
currentUser
.
access
===
'admin'
,
token
};
};
}
}
src/app.tsx
View file @
6ed561ee
...
@@ -13,15 +13,17 @@ export const initialStateConfig = {
...
@@ -13,15 +13,17 @@ export const initialStateConfig = {
/**
/**
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state
* @see https://umijs.org/zh-CN/plugins/plugin-initial-state
* */
* */
export
async
function
getInitialState
()
{
export
async
function
getInitialState
()
{
const
user
Message
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
);
const
user
Info
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
||
'{}'
);
if
(
isEmpty
(
user
Message
))
{
if
(
isEmpty
(
user
Info
))
{
history
.
push
(
loginPath
);
history
.
push
(
loginPath
);
return
{};
return
{};
}
}
return
{
user
Message
};
return
{
user
Info
};
}
}
// ProLayout 支持的api https://procomponents.ant.design/components/layout
// ProLayout 支持的api https://procomponents.ant.design/components/layout
...
...
src/pages/Chat/index.tsx
View file @
6ed561ee
...
@@ -17,6 +17,7 @@ import LoginModal from '@/components/loginModal';
...
@@ -17,6 +17,7 @@ import LoginModal from '@/components/loginModal';
import
NewSession
from
'@/components/newSession'
;
import
NewSession
from
'@/components/newSession'
;
import
{
useWebSocket
,
useRequest
}
from
'ahooks'
;
import
{
useWebSocket
,
useRequest
}
from
'ahooks'
;
import
{
GetChatGLMToken
}
from
'@/services/chatGLM/api'
;
import
{
GetChatGLMToken
}
from
'@/services/chatGLM/api'
;
import
{
useAccess
}
from
'umi'
;
const
{
useBreakpoint
}
=
Grid
;
const
{
useBreakpoint
}
=
Grid
;
const
{
Title
}
=
Typography
;
const
{
Title
}
=
Typography
;
...
@@ -41,6 +42,8 @@ const Chat: React.FC = () => {
...
@@ -41,6 +42,8 @@ const Chat: React.FC = () => {
const
[
open
,
setOpen
]
=
useState
(
false
);
const
[
open
,
setOpen
]
=
useState
(
false
);
const
tabShow
=
showSider
&&
!
isMobile
;
const
tabShow
=
showSider
&&
!
isMobile
;
const
access
=
useAccess
();
const
messageHistory
=
useRef
<
IHistory
[]
>
([]);
const
messageHistory
=
useRef
<
IHistory
[]
>
([]);
const
{
sendMessage
}
=
useWebSocket
(
'wss://glm-api.baibaomen.com/ws'
,
{
const
{
sendMessage
}
=
useWebSocket
(
'wss://glm-api.baibaomen.com/ws'
,
{
onMessage
:
(
event
)
=>
{
onMessage
:
(
event
)
=>
{
...
@@ -83,15 +86,15 @@ const Chat: React.FC = () => {
...
@@ -83,15 +86,15 @@ const Chat: React.FC = () => {
messageHistory
.
current
.
push
({
prompt
:
chat
,
answer
:
''
});
messageHistory
.
current
.
push
({
prompt
:
chat
,
answer
:
''
});
}
}
cons
t
user
=
JSON
.
parse
(
JSON
.
stringify
(
localStorage
.
getItem
(
'user'
)
||
''
)
);
cons
ole
.
log
(
'access'
,
access
);
useEffect
(()
=>
{
useEffect
(()
=>
{
if
(
user
?.
token
)
{
if
(
access
?.
token
)
{
setOpen
(
false
);
setOpen
(
false
);
}
else
{
}
else
{
setOpen
(
true
);
setOpen
(
true
);
}
}
},
[
user
]);
},
[
access
]);
const
onSend
=
()
=>
{
const
onSend
=
()
=>
{
form
.
setFieldValue
(
'chatInput'
,
''
);
form
.
setFieldValue
(
'chatInput'
,
''
);
...
...
src/services/chatGLM/api.ts
View file @
6ed561ee
...
@@ -9,7 +9,7 @@ interface ILoginParams {
...
@@ -9,7 +9,7 @@ interface ILoginParams {
const
request
=
extend
({});
const
request
=
extend
({});
request
.
interceptors
.
request
.
use
((
url
,
options
)
=>
{
request
.
interceptors
.
request
.
use
((
url
,
options
)
=>
{
const
token
=
JSON
.
parse
(
JSON
.
stringify
(
localStorage
.
getItem
(
'user'
)
||
''
)
)?.
token
;
const
token
=
JSON
.
parse
(
localStorage
.
getItem
(
'user'
)
||
'{}'
)?.
token
;
const
authHeader
=
{
const
authHeader
=
{
Authorization
:
`Bearer
${
token
||
''
}
`
,
Authorization
:
`Bearer
${
token
||
''
}
`
,
'Content-Type'
:
'application/json'
,
'Content-Type'
:
'application/json'
,
...
...
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