Skip to content

Commit d019869

Browse files
committed
feat: docs add ai chat
1 parent 302e07e commit d019869

6 files changed

Lines changed: 139 additions & 2 deletions

File tree

docs_roll/package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,23 @@
1414
"write-heading-ids": "docusaurus write-heading-ids"
1515
},
1616
"dependencies": {
17+
"@ant-design/icons": "^6.0.0",
1718
"@docusaurus/core": "2.4.1",
1819
"@docusaurus/preset-classic": "2.4.1",
1920
"@mdx-js/react": "^1.6.22",
21+
"antd": "^5.26.7",
22+
"axios": "^1.11.0",
2023
"clsx": "^1.2.1",
2124
"prism-react-renderer": "^1.3.5",
2225
"react": "^17.0.2",
2326
"react-dom": "^17.0.2"
2427
},
2528
"devDependencies": {
2629
"@docusaurus/module-type-aliases": "2.4.1",
27-
"@jridgewell/trace-mapping": "0.3.25",
30+
"@jridgewell/gen-mapping": "0.3.8",
2831
"@jridgewell/source-map": "0.3.6",
2932
"@jridgewell/sourcemap-codec": "1.5.0",
30-
"@jridgewell/gen-mapping": "0.3.8"
33+
"@jridgewell/trace-mapping": "0.3.25"
3134
},
3235
"browserslist": {
3336
"production": [
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import React, { useState, useEffect } from 'react';
2+
import axios from 'axios';
3+
import ChatFloatButton from '../ChatFloatButton';
4+
5+
export default function AIChat() {
6+
const [url, setUrl] = useState('');
7+
8+
const getUrl = async () => {
9+
try {
10+
const res = await axios.get('https://roll-dor-iframe-xfxnuxvngr.cn-shanghai.fcapp.run/get_signin_url');
11+
12+
if (res?.data?.result) {
13+
setUrl(res.data.result);
14+
}
15+
} catch (error) {
16+
console.log("error", error);
17+
}
18+
}
19+
20+
useEffect(() => {
21+
getUrl();
22+
}, []);
23+
24+
if (!url) {
25+
return null;
26+
}
27+
28+
return (
29+
<ChatFloatButton
30+
title="智能文档助手"
31+
content={
32+
<div style={{ width: '500px', height: '75vh' }}>
33+
<iframe src={url} frameborder="0" width="100%" height="100%"></iframe>
34+
</div>
35+
}
36+
floatButtonProps={{
37+
style: {
38+
insetInlineEnd: 24,
39+
bottom: 90,
40+
width: 48,
41+
height: 48,
42+
},
43+
}}
44+
/>
45+
);
46+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import React, { useState } from 'react';
2+
import { Popover, FloatButton } from 'antd';
3+
import { CloseOutlined, CommentOutlined } from '@ant-design/icons';
4+
import style from './styles.module.css';
5+
6+
export default ({ title, content, floatButtonProps = {} }) => {
7+
const [open, setOpen] = useState(false);
8+
9+
return (
10+
<Popover
11+
placement="topRight"
12+
title={
13+
<div className={style.header}>
14+
<div>{title}</div>
15+
<CloseOutlined onClick={() => { setOpen(false); }} style={{ padding: '2px' }} />
16+
</div>
17+
}
18+
content={content}
19+
overlayClassName={style.floatButtonOverlay}
20+
open={open}
21+
>
22+
<FloatButton
23+
shape="circle"
24+
type="primary"
25+
className={style.floatButton}
26+
style={{ insetInlineEnd: 94 }}
27+
icon={<CommentOutlined style={{ fontSize: '24px' }} />}
28+
onClick={() => {
29+
setOpen(!open);
30+
}}
31+
tooltip="点击使用智能文档助手"
32+
{...floatButtonProps}
33+
/>
34+
</Popover>
35+
);
36+
};
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
.header{
2+
display: flex;
3+
justify-content: space-between;
4+
}
5+
.floatButtonOverlay{
6+
z-index: 999;
7+
:global{
8+
.ant-popover-inner{
9+
flex-direction: column;
10+
width: 400px;
11+
overflow: hidden;
12+
height: calc(100vh - 200px);
13+
display: flex;
14+
.ant-popover-inner-content{
15+
flex: 1;
16+
overflow: hidden;
17+
}
18+
}
19+
.ant-popover-arrow {
20+
display: none;
21+
}
22+
}
23+
}
24+
25+
.floatButton{
26+
:global{
27+
.ant-float-btn-body {
28+
background-color: #4554e5;
29+
&:hover{
30+
background-color: #4554e5;
31+
}
32+
}
33+
}
34+
}
35+
36+

docs_roll/src/css/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
--ifm-color-primary-lightest: #3cad6e;
1616
--ifm-code-font-size: 95%;
1717
--docusaurus-highlighted-code-line-bg: rgba(0, 0, 0, 0.1);
18+
.ant-float-btn-icon {
19+
width: 24px !important;
20+
height: 24px !important;
21+
}
1822
}
1923

2024
/* For readability concerns, you should choose a lighter palette in dark mode. */
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import React from 'react';
2+
import Layout from '@theme-original/Layout';
3+
import AIChat from '@site/src/components/AIChat';
4+
5+
export default function CustomLayout(props) {
6+
return (
7+
<>
8+
<Layout {...props} />
9+
<AIChat />
10+
</>
11+
);
12+
}

0 commit comments

Comments
 (0)