fixed: push error message
This commit is contained in:
parent
8c384d5723
commit
098791edf4
@ -58,11 +58,22 @@ function rebuildGroups(groups: BlockContent[][]) {
|
||||
_groups.push(it)
|
||||
})
|
||||
}
|
||||
console.log('rebuildGroups', _groups)
|
||||
// console.log('rebuildGroups', _groups)
|
||||
return _groups;
|
||||
|
||||
|
||||
}
|
||||
function groupHasImageAndText(blocks: BlockContent[]) {
|
||||
return blocks.some(s=>s.type == 'image' && s.content.trim().length > 0) && blocks.some(s=>s.type == 'text' && s.content.trim().length > 0)
|
||||
}
|
||||
// 验证分组数据是否合法
|
||||
function checkGroupsValid(groups: BlockContent[][]) {
|
||||
if (groups.length == 1) return true;
|
||||
for (const group of groups) {
|
||||
if(!groupHasImageAndText(group)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
export default function ArticleEditModal(props: Props) {
|
||||
const {t} = useTranslation()
|
||||
@ -73,6 +84,7 @@ export default function ArticleEditModal(props: Props) {
|
||||
...DEFAULT_STATE,
|
||||
generating:false
|
||||
})
|
||||
|
||||
// 保存数据
|
||||
const handleSave = () => {
|
||||
setState({error: ''})
|
||||
@ -81,15 +93,25 @@ export default function ArticleEditModal(props: Props) {
|
||||
return;
|
||||
}
|
||||
if (groups.length == 0 || groups[0].length == 0 || !groups[0][0].content) {
|
||||
// setState({msgGroup: '请输入正文文本内容'});
|
||||
setState({msgGroup: t('news.edit_empty_human_content')});
|
||||
return;
|
||||
}
|
||||
// 验证图文都存在时,文图是否匹配
|
||||
if(!checkGroupsValid(groups)) {
|
||||
// 获取图文设置不正确的数据
|
||||
setState({msgGroup: t('news.edit_empty_group_content')});
|
||||
return;
|
||||
}
|
||||
// if (groups.length == 0 || groups[0].length == 0 || !groups[0][0].content) {
|
||||
// // setState({msgGroup: '请输入正文文本内容'});
|
||||
// return;
|
||||
// }
|
||||
const save = props.type == 'news' ? article.save : regenerate
|
||||
setState({loading: true})
|
||||
save(title, groups[0][0].content, groups.slice(1), props.id && props.id > 0 ? props.id : undefined).then(() => {
|
||||
props.onClose?.(true)
|
||||
}).catch(e => {
|
||||
setState({error: e.data || t('news.edit_save_failed')})
|
||||
setState({error: e.message || t('news.edit_save_failed')})
|
||||
}).finally(() => {
|
||||
setState({loading: false})
|
||||
});
|
||||
@ -104,16 +126,10 @@ export default function ArticleEditModal(props: Props) {
|
||||
return;
|
||||
}
|
||||
// 验证图文都存在时,文图是否匹配
|
||||
if(groups.length > 1) {
|
||||
if(!checkGroupsValid(groups)) {
|
||||
// 获取图文设置不正确的数据
|
||||
const group = groups.filter((it,idx)=>{
|
||||
return idx > 0 && (it.length < 2 || it.some(s=>s.content.trim().length == 0))
|
||||
})
|
||||
console.log('xxx',group)
|
||||
if(group.length > 0){
|
||||
setState({msgGroup: t('news.edit_empty_group_content')});
|
||||
return;
|
||||
}
|
||||
setState({msgGroup: t('news.edit_empty_group_content')});
|
||||
return;
|
||||
}
|
||||
if(!props.id || state.generating) return;
|
||||
setState({generating:true})
|
||||
@ -173,7 +189,7 @@ export default function ArticleEditModal(props: Props) {
|
||||
errorMessage={state.msgGroup} editable groups={groups}
|
||||
onChange={list => {
|
||||
setGroups(() => list)
|
||||
setState({msgGroup: (list.length == 0 || list[0].length == 0 || !list[0][0].content) ? t('news.edit_notice_enter_article_content') : ''});
|
||||
setState({msgGroup: (list.length == 0 || list[0].length == 0 || !list[0][0].content) ? t('news.edit_empty_human_content') : ''});
|
||||
}}
|
||||
/>
|
||||
<div className="text-red-500">{state.msgGroup}</div>
|
||||
|
Loading…
x
Reference in New Issue
Block a user