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

feat: 编辑者选择的时候显示手机号

上级 b3a5b79c
...@@ -7,12 +7,12 @@ function DebounceSelect({ fetchOptions, debounceTimeout = 800, ...props }) { ...@@ -7,12 +7,12 @@ function DebounceSelect({ fetchOptions, debounceTimeout = 800, ...props }) {
const [options, setOptions] = useState([]) const [options, setOptions] = useState([])
const fetchRef = useRef(0) const fetchRef = useRef(0)
const debounceFetcher = useMemo(() => { const debounceFetcher = useMemo(() => {
const loadOptions = value => { const loadOptions = (value) => {
fetchRef.current += 1 fetchRef.current += 1
const fetchId = fetchRef.current const fetchId = fetchRef.current
setOptions([]) setOptions([])
setFetching(true) setFetching(true)
fetchOptions(value).then(newOptions => { fetchOptions(value).then((newOptions) => {
if (fetchId !== fetchRef.current) { if (fetchId !== fetchRef.current) {
// for fetch callback order // for fetch callback order
return return
...@@ -39,12 +39,14 @@ function DebounceSelect({ fetchOptions, debounceTimeout = 800, ...props }) { ...@@ -39,12 +39,14 @@ function DebounceSelect({ fetchOptions, debounceTimeout = 800, ...props }) {
async function fetchUserList(username) { async function fetchUserList(username) {
console.log('fetching user', username) console.log('fetching user', username)
return getTeacherList({ real_name: username, page_size: 40 }).then(res => { return getTeacherList({ real_name: username, page_size: 40 }).then((res) => {
return res.data.list return res.data.list.map((item) => {
return { ...item, label: `${item.real_name} (${item.tel})` }
})
}) })
} }
const SelectTeacher = props => { const SelectTeacher = (props) => {
const [value, setValue] = useState([]) const [value, setValue] = useState([])
return ( return (
<DebounceSelect <DebounceSelect
...@@ -52,8 +54,8 @@ const SelectTeacher = props => { ...@@ -52,8 +54,8 @@ const SelectTeacher = props => {
value={value} value={value}
placeholder="Select users" placeholder="Select users"
fetchOptions={fetchUserList} fetchOptions={fetchUserList}
fieldNames={{ label: 'real_name', value: 'id' }} fieldNames={{ label: 'label', value: 'id' }}
onChange={newValue => { onChange={(newValue) => {
setValue(newValue) setValue(newValue)
}} }}
style={{ width: '100%' }} style={{ width: '100%' }}
......
...@@ -8,7 +8,7 @@ const EditChapterEditors = ({ chapter = {}, onChange, ...props }) => { ...@@ -8,7 +8,7 @@ const EditChapterEditors = ({ chapter = {}, onChange, ...props }) => {
const [value, setValue] = useState('') const [value, setValue] = useState('')
useEffect(() => { useEffect(() => {
getChapterEditors({ book_id: chapter.book_id, chapter_id: chapter.id }).then(res => { getChapterEditors({ book_id: chapter.book_id, chapter_id: chapter.id }).then((res) => {
setEditors(res.data.editors || []) setEditors(res.data.editors || [])
const value = res.data.selected_editor_ids[0] || '' const value = res.data.selected_editor_ids[0] || ''
setValue(value) setValue(value)
...@@ -26,12 +26,12 @@ const EditChapterEditors = ({ chapter = {}, onChange, ...props }) => { ...@@ -26,12 +26,12 @@ const EditChapterEditors = ({ chapter = {}, onChange, ...props }) => {
<Form labelCol={{ span: 8 }}> <Form labelCol={{ span: 8 }}>
<Form.Item label="当前章节">{chapter.title}</Form.Item> <Form.Item label="当前章节">{chapter.title}</Form.Item>
<Form.Item label="编写者"> <Form.Item label="编写者">
<Radio.Group value={value} onChange={e => setValue(e.target.value)} style={{ marginTop: '6px' }}> <Radio.Group value={value} onChange={(e) => setValue(e.target.value)}>
<Space direction="vertical"> <Space direction="vertical">
{editors.map(item => { {editors.map((item) => {
return ( return (
<Radio value={item.editor_id} key={item.editor_id}> <Radio value={item.editor_id} key={item.editor_id}>
{item.real_name} {item.real_name}({item.tel})
</Radio> </Radio>
) )
})} })}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论