Compare commits

..

No commits in common. "fa21bd6b52e42af12462d89ad12da5a942cca7b8" and "c3ea81e69fb527d53256a751b10e95385ce1aeeb" have entirely different histories.

4 changed files with 46 additions and 50 deletions

View File

@ -18,48 +18,6 @@ const DEFAULT_STATE = {
msgGroup: '',
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) {
const [groups, setGroups] = useState<BlockContent[][]>([]);
@ -91,10 +49,10 @@ export default function ArticleEditModal(props: Props) {
}
useEffect(() => {
setState({...DEFAULT_STATE})
if (typeof(props.id) != 'undefined') {
if (props.id) {
if (props.id > 0) {
article.getById(props.id).then(res => {
setGroups(rebuildGroups(res.content_group))
setGroups(res.content_group)
setTitle(res.title)
})
} else {
@ -107,7 +65,7 @@ export default function ArticleEditModal(props: Props) {
return (<Modal
title={'编辑文章'}
open={props.id != undefined && props.id >= 0}
open={!!props.id && props.id >= 0}
maskClosable={false}
keyboard={false}
width={800}

View File

@ -12,9 +12,47 @@ 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)
}
}
export default function ArticleGroup({groups, editable, onChange, errorMessage}: Props) {
// const groups = rebuildGroups(_groups)
function rebuildGroups(groups: BlockContent[][]) {
const _groups: BlockContent[][] = [];
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

View File

@ -31,7 +31,7 @@ export default function VideoItem(props: VideoItemProps) {
{!props.onLive && <Checkbox onChange={e=>handleCheckedChange(e.target.checked)} />}
</div>
<div className="cover" onClick={props.onClick}>
<img className={'w-full cursor-pointer h-[180px] object-cover'} src={props.videoInfo.cover}/>
<Image className={'w-full cursor-pointer'} preview={false} src={ImageCover}/>
</div>
<div className="text-sm py-2 px-3">
<div className="title my-1 cursor-pointer" onClick={props.onClick}>{props.videoInfo.title}</div>

View File

@ -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
className={`checkbox mt-[2px] mr-2 ${checkedId.includes(item.id) ? '' : 'opacity-0'} group-hover:opacity-100`}>
{item.internal_article_id > 0 ? <span className={"inline-block w-[16px] " }></span> :<Checkbox checked={checkedId.includes(item.id)} onChange={() => {
<Checkbox checked={checkedId.includes(item.id)} onChange={() => {
if (checkedId.includes(item.id)) {
setCheckedId(checkedId.filter(id => id != item.id))
} else {
setCheckedId([...checkedId, item.id])
}
}}/> }
}}/>
</div>
<div className="news-content flex-1">
<div className="flex items-center justify-between">