Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
W
web
概览
概览
详情
活动
周期分析
版本库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
统计图
问题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程表
图表
维基
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
iuav
web
Commits
49abf5dd
提交
49abf5dd
authored
5月 30, 2023
作者:
翁进城
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
增加其它组件调用登录modal的方法
上级
8be05b97
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
80 行增加
和
20 行删除
+80
-20
index.tsx
components/NavHeader/index.tsx
+13
-2
userProvider.tsx
lib/userProvider.tsx
+22
-2
index.page.tsx
pages/forum/index.page.tsx
+45
-16
没有找到文件。
components/NavHeader/index.tsx
浏览文件 @
49abf5dd
...
...
@@ -43,7 +43,8 @@ const items: TabsProps["items"] = [
export
default
function
NavHeader
()
{
const
router
=
useRouter
();
const
[
currentPath
,
setCurrentPath
]
=
useState
(
""
);
const
{
userInfo
,
testLogin
,
logout
}
=
useContext
(
UserContext
);
const
{
userInfo
,
testLogin
,
logout
,
setNeedLogin
,
needLogin
}
=
useContext
(
UserContext
);
useEffect
(()
=>
{
setCurrentPath
(
router
.
route
);
...
...
@@ -92,6 +93,13 @@ export default function NavHeader() {
}
}
//从其它组件通知需要登录
useEffect
(()
=>
{
if
(
needLogin
)
{
setOpenLoginModal
(
true
);
}
},
[
needLogin
]);
return
(
<
div
className=
{
styles
.
navHeader
}
>
<
div
className=
{
styles
.
nav
}
>
...
...
@@ -138,7 +146,10 @@ export default function NavHeader() {
</
div
>
<
LoginModal
open=
{
openLoginModal
}
onCancel=
{
()
=>
setOpenLoginModal
(
false
)
}
onCancel=
{
()
=>
{
setOpenLoginModal
(
false
);
setNeedLogin
(
false
);
}
}
></
LoginModal
>
<
PublishModal
open=
{
openPublishModal
}
...
...
lib/userProvider.tsx
浏览文件 @
49abf5dd
import
React
,
{
createContext
,
Dispatch
,
SetStateAction
,
useEffect
,
useState
}
from
"react"
;
import
React
,
{
createContext
,
Dispatch
,
SetStateAction
,
useEffect
,
useState
,
}
from
"react"
;
import
api
,
{
UserInfoResp
}
from
"~/api"
;
export
const
UserContext
=
createContext
<
{
...
...
@@ -6,11 +12,15 @@ export const UserContext = createContext<{
logout
:
()
=>
void
;
userInfo
:
UserInfoResp
|
null
;
setUserInfo
:
Dispatch
<
SetStateAction
<
UserInfoResp
|
null
>>
;
needLogin
:
Boolean
;
setNeedLogin
:
Dispatch
<
SetStateAction
<
Boolean
>>
;
}
>
({
testLogin
()
{},
logout
()
{},
userInfo
:
null
,
setUserInfo
()
{},
needLogin
:
false
,
setNeedLogin
()
{},
});
type
Props
=
{
...
...
@@ -18,6 +28,7 @@ type Props = {
};
const
UserProvider
=
({
children
}:
Props
)
=>
{
const
[
userInfo
,
setUserInfo
]
=
useState
<
UserInfoResp
|
null
>
(
null
);
const
[
needLogin
,
setNeedLogin
]
=
useState
<
Boolean
>
(
false
);
//用于通知登录modal需要打开
useEffect
(()
=>
{
try
{
...
...
@@ -48,7 +59,16 @@ const UserProvider = ({ children }: Props) => {
}
return
(
<
UserContext
.
Provider
value=
{
{
userInfo
,
setUserInfo
,
testLogin
,
logout
}
}
>
<
UserContext
.
Provider
value=
{
{
userInfo
,
setUserInfo
,
testLogin
,
logout
,
needLogin
,
setNeedLogin
,
}
}
>
{
children
}
</
UserContext
.
Provider
>
);
...
...
pages/forum/index.page.tsx
浏览文件 @
49abf5dd
...
...
@@ -13,11 +13,12 @@ import Layout from "~/components/layout";
import
styles
from
"./index.module.scss"
;
import
errImg
from
"~/assets/errImg"
;
import
{
RightOutlined
}
from
"@ant-design/icons"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
use
Context
,
use
Effect
,
useState
}
from
"react"
;
import
PublishMessage
from
"./components/publishMessage"
;
import
api
,
{
ByDynamicParams
,
Dynamic
}
from
"./api"
;
import
InfiniteScroll
from
"react-infinite-scroll-component"
;
import
{
useUser
}
from
"~/lib/hooks"
;
import
{
UserContext
}
from
"~/lib/userProvider"
;
interface
Item
extends
Dynamic
{
openComment
?:
boolean
;
//是否开启评论
...
...
@@ -32,8 +33,8 @@ export default function Forum() {
pageNo
:
1
,
pageSize
:
16
,
});
const
[
count
,
setCount
]
=
useState
(
0
);
//动态总数
const
userInfo
=
useUser
();
//获取信息
const
[
count
,
setCount
]
=
useState
(
0
);
//动态总数
const
{
userInfo
,
setNeedLogin
}
=
useContext
(
UserContext
);
useEffect
(()
=>
{
api
...
...
@@ -56,7 +57,11 @@ export default function Forum() {
* 展示发布模态框
*/
const
showModal
=
()
=>
{
setIsModalOpen
(
true
);
if
(
userInfo
)
{
setIsModalOpen
(
true
);
}
else
{
setNeedLogin
(
true
);
}
};
/**
...
...
@@ -78,16 +83,26 @@ export default function Forum() {
//评论内容
const
onComment
=
(
values
:
any
,
id
:
number
,
i
:
number
)
=>
{
api
.
comment
({
content
:
values
.
content
,
dynamicId
:
id
,
userId
:
userInfo
!
.
id
,
}).
then
(
res
=>
{
if
(
res
.
code
===
'200'
){
}
});
api
.
comment
({
content
:
values
.
content
,
dynamicId
:
id
,
userId
:
userInfo
!
.
id
,
})
.
then
((
res
)
=>
{
if
(
res
.
code
===
"200"
)
{
}
});
};
//评论内容
const
onCommentContent
=
()
=>
{
if
(
userInfo
){
}
else
{
setNeedLogin
(
true
);
}
}
return
(
<
Layout
>
<
div
className=
{
styles
.
forum
}
>
...
...
@@ -165,8 +180,17 @@ export default function Forum() {
</
Space
>
{
item
.
openComment
&&
(
<
div
className=
{
styles
.
commentWrap
}
>
<
Form
onFinish=
{
(
values
)
=>
{
onComment
(
values
,
item
.
id
,
i
)}
}
>
<
Form
.
Item
name=
"content"
rules=
{
[{
required
:
true
}]
}
help=
""
style=
{
{
marginBottom
:
0
}
}
>
<
Form
onFinish=
{
(
values
)
=>
{
onComment
(
values
,
item
.
id
,
i
);
}
}
>
<
Form
.
Item
name=
"content"
rules=
{
[{
required
:
true
}]
}
help=
""
style=
{
{
marginBottom
:
0
}
}
>
<
div
className=
{
styles
.
draftWrap
}
>
<
div
className=
{
styles
.
commentHeadImg
}
>
自已
</
div
>
<
Input
...
...
@@ -176,7 +200,12 @@ export default function Forum() {
</
div
>
</
Form
.
Item
>
<
div
className=
{
styles
.
btnCommentWrap
}
>
<
Button
type=
"primary"
htmlType=
"submit"
className=
"btnComment"
>
<
Button
type=
"primary"
htmlType=
"submit"
className=
"btnComment"
onClick=
{
onCommentContent
}
>
评论
</
Button
>
</
div
>
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论