提交 c392e6b8 authored 作者: 王鹏飞's avatar 王鹏飞

feat: 关联知识图谱对接接口

上级 a7fb05b3
......@@ -44,3 +44,13 @@ export function getChapterEditors(data) {
export function updateChapterEditors(data) {
return axios.post('/api/book/teacher/chapter/saveEditors', data)
}
// 知识图谱列表
export function getTagList(params) {
return axios.get('/api/resource/v1/course/course/tag-list', { params })
}
// 知识图谱关联书籍章节
export function bindTag(data) {
return axios.post('/api/resource/v1/course/course/tag-add-book', data)
}
import { useState, useEffect } from 'react'
import { Modal, TreeSelect, App } from 'antd'
import { getChapterEditors, updateChapterEditors } from '../api'
import { useState, useEffect, useCallback } from 'react'
import { Modal, Tree, App, Button, Flex } from 'antd'
import { getTagList, bindTag } from '../api'
const EditChapterEditors = ({ chapter = {}, onOk, ...props }) => {
function getIds(nodes) {
let ids = []
nodes.forEach(node => {
ids.push(node.id)
if (node.children && node.children.length > 0) {
ids = ids.concat(getIds(node.children))
}
})
return ids
}
const BindKnowledgeGraph = ({ chapter = {}, ...props }) => {
const { message } = App.useApp()
const [value, setValue] = useState('')
const [treeData, setTreeData] = useState([
{
id: '1',
name: '项目一:初识商务数据分析',
children: [
{
id: '1-1',
name: '任务一:人人都需要商务数据分析',
children: [
{
id: '1-1-1',
name: ' 商务数据分析就业情况',
children: [
{
id: '1-1-1-1',
name: ' 商务数据分析师岗位'
},
{
id: '1-1-1-2',
name: ' 商务数据分析师的市场优势'
},
{
id: '1-1-1-3',
name: ' 商务数据分析师的工作职责'
}
]
}
]
}
]
}
])
useEffect(() => {
getChapterEditors({ book_id: chapter.book_id, chapter_id: chapter.id }).then(res => {
const value = res.data.selected_editor_ids[0] || ''
setValue(value)
const [treeData, setTreeData] = useState([])
const [expandedKeys, setExpandedKeys] = useState([])
const fetchList = useCallback(() => {
getTagList({ type: 2, parent_id: chapter.book_id, chapter_id: chapter.id }).then(res => {
setTreeData(res.data)
setExpandedKeys(getIds(res.data))
})
}, [chapter])
const handleSubmit = async () => {
message.success('关联成功')
onOk?.()
useEffect(() => {
fetchList()
}, [fetchList])
const toggleBind = async node => {
await bindTag({
tag_id: node.id,
book_id: chapter.book_id,
chapter_id: chapter.id,
option_type: node.is_checked ? 'delete' : 'add'
})
message.success('操作成功')
fetchList()
}
const titleRender = node => {
return (
<Flex justify="space-between">
<span>{node.name}</span>
<Button color="primary" variant="link" size="small" onClick={() => toggleBind(node)}>
{node.is_checked ? '取消关联' : '关联'}
</Button>
</Flex>
)
}
return (
<Modal title="关联知识图谱" centered {...props} onOk={handleSubmit}>
<TreeSelect
<Modal title="关联知识图谱" centered {...props} footer={null}>
<Tree
blockNode
selectable={false}
treeData={treeData}
fieldNames={{ title: 'name', key: 'id' }}
expandedKeys={expandedKeys}
titleRender={titleRender}
/>
{/* <TreeSelect
multiple
showSearch
treeDefaultExpandAll
value={value}
treeData={treeData}
fieldNames={{ label: 'name', value: 'id' }}
style={{ width: '100%' }}></TreeSelect>
onChange={setValue}
style={{ width: '100%' }}></TreeSelect> */}
</Modal>
)
}
export default EditChapterEditors
export default BindKnowledgeGraph
......@@ -90,7 +90,7 @@ httpRequest.interceptors.response.use(
}
return Promise.reject(data)
}
if (data.code !== 200) {
if (data.code !== 200 && data.code !== 0) {
notification.error({ message: data.message || '请求错误' })
return Promise.reject(data)
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论