Compare commits
3 Commits
c3ea81e69f
...
fa21bd6b52
Author | SHA1 | Date | |
---|---|---|---|
fa21bd6b52 | |||
e0af5de13c | |||
79129f9167 |
@ -18,6 +18,48 @@ const DEFAULT_STATE = {
|
|||||||
msgGroup: '',
|
msgGroup: '',
|
||||||
error:''
|
error:''
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function pushBlocksToGroup(blocks: BlockContent[],groups: BlockContent[][]){
|
||||||
|
const lastGroup = groups[groups.length - 1]
|
||||||
|
if (lastGroup && lastGroup.filter(s=>s.type == 'text').length == 0) {
|
||||||
|
// 如果上一个group中没有文本则直接合并
|
||||||
|
lastGroup.push(...blocks)
|
||||||
|
} else {
|
||||||
|
groups.push(blocks)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function rebuildGroups(groups: BlockContent[][]) {
|
||||||
|
const _groups: BlockContent[][] = [];
|
||||||
|
if (!groups || groups.length == 0) return _groups;
|
||||||
|
groups.forEach((blocks,index) => {
|
||||||
|
if(!blocks) return;
|
||||||
|
blocks = blocks.filter(s=>!!s).sort((a,b) => {
|
||||||
|
if(a.type == 'text' && b.type == 'text') return 1;
|
||||||
|
return a.type == 'text' ? -1 : 1
|
||||||
|
})
|
||||||
|
if (blocks.length == 1) {
|
||||||
|
if(index == 0) _groups.push(blocks)
|
||||||
|
else pushBlocksToGroup(blocks,_groups)
|
||||||
|
} else {
|
||||||
|
if(index == 0){
|
||||||
|
_groups.push([blocks[0]])
|
||||||
|
_groups.push(blocks.slice(1))
|
||||||
|
}else{
|
||||||
|
pushBlocksToGroup(blocks,_groups)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (_groups.length < 2) {
|
||||||
|
Array(2 - _groups.length).fill([{type: 'text', content: ''}]).forEach((it) => {
|
||||||
|
_groups.push(it)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
console.log('rebuildGroups', _groups)
|
||||||
|
return _groups;
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
export default function ArticleEditModal(props: Props) {
|
export default function ArticleEditModal(props: Props) {
|
||||||
|
|
||||||
const [groups, setGroups] = useState<BlockContent[][]>([]);
|
const [groups, setGroups] = useState<BlockContent[][]>([]);
|
||||||
@ -49,10 +91,10 @@ export default function ArticleEditModal(props: Props) {
|
|||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setState({...DEFAULT_STATE})
|
setState({...DEFAULT_STATE})
|
||||||
if (props.id) {
|
if (typeof(props.id) != 'undefined') {
|
||||||
if (props.id > 0) {
|
if (props.id > 0) {
|
||||||
article.getById(props.id).then(res => {
|
article.getById(props.id).then(res => {
|
||||||
setGroups(res.content_group)
|
setGroups(rebuildGroups(res.content_group))
|
||||||
setTitle(res.title)
|
setTitle(res.title)
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
@ -65,7 +107,7 @@ export default function ArticleEditModal(props: Props) {
|
|||||||
|
|
||||||
return (<Modal
|
return (<Modal
|
||||||
title={'编辑文章'}
|
title={'编辑文章'}
|
||||||
open={!!props.id && props.id >= 0}
|
open={props.id != undefined && props.id >= 0}
|
||||||
maskClosable={false}
|
maskClosable={false}
|
||||||
keyboard={false}
|
keyboard={false}
|
||||||
width={800}
|
width={800}
|
||||||
|
@ -12,47 +12,9 @@ type Props = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function pushBlocksToGroup(blocks: BlockContent[],groups: BlockContent[][]){
|
|
||||||
const lastGroup = groups[groups.length - 1]
|
|
||||||
if (lastGroup && lastGroup.filter(s=>s.type == 'text').length == 0) {
|
|
||||||
// 如果上一个group中没有文本则直接合并
|
|
||||||
lastGroup.push(...blocks)
|
|
||||||
} else {
|
|
||||||
groups.push(blocks)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function rebuildGroups(groups: BlockContent[][]) {
|
export default function ArticleGroup({groups, editable, onChange, errorMessage}: Props) {
|
||||||
const _groups: BlockContent[][] = [];
|
// const groups = rebuildGroups(_groups)
|
||||||
if (!groups || groups.length == 0) return _groups;
|
|
||||||
groups.forEach((blocks,index) => {
|
|
||||||
if(!blocks) return;
|
|
||||||
blocks.sort((a) => a.type == 'text' ? -1 : 1)
|
|
||||||
if (blocks.length == 1) {
|
|
||||||
if(index == 0) _groups.push(blocks)
|
|
||||||
else pushBlocksToGroup(blocks,_groups)
|
|
||||||
} else {
|
|
||||||
if(index == 0){
|
|
||||||
_groups.push([blocks[0]])
|
|
||||||
_groups.push(blocks.slice(1))
|
|
||||||
}else{
|
|
||||||
pushBlocksToGroup(blocks,_groups)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if (_groups.length < 2) {
|
|
||||||
Array(2 - _groups.length).fill([{type: 'text', content: ''}]).forEach((it) => {
|
|
||||||
_groups.push(it)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
console.log('rebuildGroups', _groups)
|
|
||||||
return _groups;
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function ArticleGroup({groups: _groups, editable, onChange, errorMessage}: Props) {
|
|
||||||
const groups = rebuildGroups(_groups)
|
|
||||||
/**
|
/**
|
||||||
* 添加一个组
|
* 添加一个组
|
||||||
* @param insertIndex 插入的位置,-1表示插入到末尾
|
* @param insertIndex 插入的位置,-1表示插入到末尾
|
||||||
|
@ -31,7 +31,7 @@ export default function VideoItem(props: VideoItemProps) {
|
|||||||
{!props.onLive && <Checkbox onChange={e=>handleCheckedChange(e.target.checked)} />}
|
{!props.onLive && <Checkbox onChange={e=>handleCheckedChange(e.target.checked)} />}
|
||||||
</div>
|
</div>
|
||||||
<div className="cover" onClick={props.onClick}>
|
<div className="cover" onClick={props.onClick}>
|
||||||
<Image className={'w-full cursor-pointer'} preview={false} src={ImageCover}/>
|
<img className={'w-full cursor-pointer h-[180px] object-cover'} src={props.videoInfo.cover}/>
|
||||||
</div>
|
</div>
|
||||||
<div className="text-sm py-2 px-3">
|
<div className="text-sm py-2 px-3">
|
||||||
<div className="title my-1 cursor-pointer" onClick={props.onClick}>{props.videoInfo.title}</div>
|
<div className="title my-1 cursor-pointer" onClick={props.onClick}>{props.videoInfo.title}</div>
|
||||||
|
@ -82,13 +82,13 @@ export default function NewsIndex() {
|
|||||||
<div key={item.id} className={`py-3 flex items-start border-b border-gray-100 group`}>
|
<div key={item.id} className={`py-3 flex items-start border-b border-gray-100 group`}>
|
||||||
<div
|
<div
|
||||||
className={`checkbox mt-[2px] mr-2 ${checkedId.includes(item.id) ? '' : 'opacity-0'} group-hover:opacity-100`}>
|
className={`checkbox mt-[2px] mr-2 ${checkedId.includes(item.id) ? '' : 'opacity-0'} group-hover:opacity-100`}>
|
||||||
<Checkbox checked={checkedId.includes(item.id)} onChange={() => {
|
{item.internal_article_id > 0 ? <span className={"inline-block w-[16px] " }></span> :<Checkbox checked={checkedId.includes(item.id)} onChange={() => {
|
||||||
if (checkedId.includes(item.id)) {
|
if (checkedId.includes(item.id)) {
|
||||||
setCheckedId(checkedId.filter(id => id != item.id))
|
setCheckedId(checkedId.filter(id => id != item.id))
|
||||||
} else {
|
} else {
|
||||||
setCheckedId([...checkedId, item.id])
|
setCheckedId([...checkedId, item.id])
|
||||||
}
|
}
|
||||||
}}/>
|
}}/> }
|
||||||
</div>
|
</div>
|
||||||
<div className="news-content flex-1">
|
<div className="news-content flex-1">
|
||||||
<div className="flex items-center justify-between">
|
<div className="flex items-center justify-between">
|
||||||
|
Loading…
x
Reference in New Issue
Block a user