mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-08 20:42:30 +08:00
feat: prevent the user from entering the knowledge base if he is not logged in (#45)
This commit is contained in:
@ -1,109 +1,131 @@
|
||||
import React, { useEffect, useState, } from 'react';
|
||||
import { useNavigate, connect, Dispatch } from 'umi'
|
||||
import { Card, List, Popconfirm, message, FloatButton, Row, Col } from 'antd';
|
||||
import { MinusSquareOutlined, DeleteOutlined, PlusOutlined } from '@ant-design/icons';
|
||||
import styles from './index.less'
|
||||
import { formatDate } from '@/utils/date'
|
||||
import type { knowledgeModelState } from './model'
|
||||
import { formatDate } from '@/utils/date';
|
||||
import {
|
||||
DeleteOutlined,
|
||||
MinusSquareOutlined,
|
||||
PlusOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { Card, Col, FloatButton, Popconfirm, Row } from 'antd';
|
||||
import React, { useEffect } from 'react';
|
||||
import { Dispatch, connect, useNavigate } from 'umi';
|
||||
import styles from './index.less';
|
||||
import type { knowledgeModelState } from './model';
|
||||
interface KnowledgeProps {
|
||||
dispatch: Dispatch;
|
||||
knowledgeModel: knowledgeModelState
|
||||
knowledgeModel: knowledgeModelState;
|
||||
}
|
||||
const Index: React.FC<KnowledgeProps> = ({ knowledgeModel, dispatch }) => {
|
||||
const navigate = useNavigate()
|
||||
const navigate = useNavigate();
|
||||
// const [datas, setDatas] = useState(data)
|
||||
const { data = [] } = knowledgeModel
|
||||
console.log(knowledgeModel)
|
||||
const { data = [] } = knowledgeModel;
|
||||
console.log(knowledgeModel);
|
||||
|
||||
// const x = useSelector((state) => state.knowledgeModel);
|
||||
|
||||
const confirm = (id: string) => {
|
||||
dispatch({
|
||||
type: 'knowledgeModel/rmKb',
|
||||
payload: {
|
||||
kb_id: id
|
||||
kb_id: id,
|
||||
},
|
||||
callback: () => {
|
||||
dispatch({
|
||||
type: 'knowledgeModel/getList',
|
||||
payload: {
|
||||
|
||||
}
|
||||
payload: {},
|
||||
});
|
||||
}
|
||||
},
|
||||
});
|
||||
};
|
||||
const handleAddKnowledge = () => {
|
||||
navigate(`add/setting?activeKey=setting`);
|
||||
}
|
||||
};
|
||||
const handleEditKnowledge = (id: string) => {
|
||||
navigate(`add/setting?activeKey=file&id=${id}`);
|
||||
}
|
||||
};
|
||||
useEffect(() => {
|
||||
dispatch({
|
||||
type: 'knowledgeModel/getList',
|
||||
payload: {
|
||||
|
||||
}
|
||||
payload: {},
|
||||
});
|
||||
}, [])
|
||||
return (<>
|
||||
<div className={styles.knowledge}>
|
||||
<FloatButton onClick={handleAddKnowledge} icon={<PlusOutlined />} type="primary" style={{ right: 24, top: 100 }} />
|
||||
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}>
|
||||
{
|
||||
data.map((item: any) => {
|
||||
return (<Col className="gutter-row" key={item.name} xs={24} sm={12} md={8} lg={6}>
|
||||
<Card className={styles.card}
|
||||
onClick={() => { handleEditKnowledge(item.id) }}
|
||||
}, []);
|
||||
return (
|
||||
<>
|
||||
<div className={styles.knowledge}>
|
||||
<FloatButton
|
||||
onClick={handleAddKnowledge}
|
||||
icon={<PlusOutlined />}
|
||||
type="primary"
|
||||
style={{ right: 24, top: 100 }}
|
||||
/>
|
||||
<Row gutter={{ xs: 8, sm: 16, md: 24, lg: 32 }}>
|
||||
{data.map((item: any) => {
|
||||
return (
|
||||
<Col
|
||||
className="gutter-row"
|
||||
key={item.name}
|
||||
xs={24}
|
||||
sm={12}
|
||||
md={8}
|
||||
lg={6}
|
||||
>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.content}>
|
||||
<span className={styles.context}>
|
||||
{item.name}
|
||||
</span>
|
||||
<span className={styles.delete}>
|
||||
<Popconfirm
|
||||
title="Delete the task"
|
||||
description="Are you sure to delete this task?"
|
||||
onConfirm={(e: any) => {
|
||||
e.stopPropagation();
|
||||
e.nativeEvent.stopImmediatePropagation()
|
||||
confirm(item.id)
|
||||
|
||||
}}
|
||||
okText="Yes"
|
||||
cancelText="No"
|
||||
>
|
||||
<DeleteOutlined onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
e.nativeEvent.stopImmediatePropagation()
|
||||
}} />
|
||||
</Popconfirm>
|
||||
|
||||
</span>
|
||||
<Card
|
||||
className={styles.card}
|
||||
onClick={() => {
|
||||
handleEditKnowledge(item.id);
|
||||
}}
|
||||
>
|
||||
<div className={styles.container}>
|
||||
<div className={styles.content}>
|
||||
<span className={styles.context}>{item.name}</span>
|
||||
<span className={styles.delete}>
|
||||
<Popconfirm
|
||||
title="Delete the task"
|
||||
description="Are you sure to delete this task?"
|
||||
onConfirm={(e: any) => {
|
||||
e.stopPropagation();
|
||||
e.nativeEvent.stopImmediatePropagation();
|
||||
confirm(item.id);
|
||||
}}
|
||||
okText="Yes"
|
||||
cancelText="No"
|
||||
>
|
||||
<DeleteOutlined
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
e.nativeEvent.stopImmediatePropagation();
|
||||
}}
|
||||
/>
|
||||
</Popconfirm>
|
||||
</span>
|
||||
</div>
|
||||
<div className={styles.footer}>
|
||||
<span className={styles.text}>
|
||||
<MinusSquareOutlined />
|
||||
{item.doc_num}文档
|
||||
</span>
|
||||
<span className={styles.text}>
|
||||
<MinusSquareOutlined />
|
||||
{item.chunk_num}个
|
||||
</span>
|
||||
<span className={styles.text}>
|
||||
<MinusSquareOutlined />
|
||||
{item.token_num}千字符
|
||||
</span>
|
||||
<span style={{ float: 'right' }}>
|
||||
{formatDate(item.update_date)}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.footer}>
|
||||
<span className={styles.text}>
|
||||
<MinusSquareOutlined />{item.doc_num}文档
|
||||
</span>
|
||||
<span className={styles.text}>
|
||||
<MinusSquareOutlined />{item.chunk_num}个
|
||||
</span>
|
||||
<span className={styles.text}>
|
||||
<MinusSquareOutlined />{item.token_num}千字符
|
||||
</span>
|
||||
<span style={{ float: 'right' }}>
|
||||
{formatDate(item.update_date)}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Card>
|
||||
</Col>)
|
||||
})
|
||||
}
|
||||
</Row>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
</Card>
|
||||
</Col>
|
||||
);
|
||||
})}
|
||||
</Row>
|
||||
</div>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default connect(({ knowledgeModel, loading }) => ({ knowledgeModel, loading }))(Index);
|
||||
export default connect(({ knowledgeModel, loading }) => ({
|
||||
knowledgeModel,
|
||||
loading,
|
||||
}))(Index);
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import kbService from '@/services/kbService';
|
||||
import { Effect, Reducer, Subscription } from 'umi';
|
||||
import { Effect, Reducer } from 'umi';
|
||||
|
||||
export interface knowledgeModelState {
|
||||
loading: boolean;
|
||||
@ -15,7 +15,7 @@ export interface knowledgegModelType {
|
||||
reducers: {
|
||||
updateState: Reducer<knowledgeModelState>;
|
||||
};
|
||||
subscriptions: { setup: Subscription };
|
||||
// subscriptions: { setup: Subscription };
|
||||
}
|
||||
const Model: knowledgegModelType = {
|
||||
namespace: 'knowledgeModel',
|
||||
@ -23,13 +23,13 @@ const Model: knowledgegModelType = {
|
||||
loading: false,
|
||||
data: [],
|
||||
},
|
||||
subscriptions: {
|
||||
setup({ dispatch, history }) {
|
||||
history.listen((location) => {
|
||||
console.log(location);
|
||||
});
|
||||
},
|
||||
},
|
||||
// subscriptions: {
|
||||
// setup({ dispatch, history }) {
|
||||
// history.listen((location) => {
|
||||
// console.log(location);
|
||||
// });
|
||||
// },
|
||||
// },
|
||||
effects: {
|
||||
*rmKb({ payload = {}, callback }, { call, put }) {
|
||||
const { data, response } = yield call(kbService.rmKb, payload);
|
||||
|
||||
Reference in New Issue
Block a user