feat: ✨️ 新增推送视频状态控制及国际化支持,优化热点新闻数据加载逻辑
This commit is contained in:
parent
64ee960846
commit
500c849140
@ -15,6 +15,7 @@ type Props = {
|
|||||||
id?: number;
|
id?: number;
|
||||||
type: 'news' | 'video';
|
type: 'news' | 'video';
|
||||||
onClose?: (saved?: boolean) => void;
|
onClose?: (saved?: boolean) => void;
|
||||||
|
onRefresh?: ()=>void
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEFAULT_STATE = {
|
const DEFAULT_STATE = {
|
||||||
@ -106,7 +107,7 @@ function checkHotNewsValid(hotNews: HotNewsData,modal:ModalHookAPI,t:TFunction<"
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default function ArticleEditModal(props: Props) {
|
export default function ArticleEditModal(props: Props) {
|
||||||
const {t} = useTranslation()
|
const {t,i18n} = useTranslation()
|
||||||
const {modal} = App.useApp()
|
const {modal} = App.useApp()
|
||||||
const [groups, setGroups] = useState<BlockContent[][]>([]);
|
const [groups, setGroups] = useState<BlockContent[][]>([]);
|
||||||
const [title, setTitle] = useState('')
|
const [title, setTitle] = useState('')
|
||||||
@ -116,7 +117,8 @@ export default function ArticleEditModal(props: Props) {
|
|||||||
})
|
})
|
||||||
const [state, setState] = useSetState({
|
const [state, setState] = useSetState({
|
||||||
...DEFAULT_STATE,
|
...DEFAULT_STATE,
|
||||||
generating:false
|
generating:false,
|
||||||
|
pushed: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
// 保存数据
|
// 保存数据
|
||||||
@ -159,7 +161,7 @@ export default function ArticleEditModal(props: Props) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
const handlePush2Video = async () =>{
|
const handlePush2Video = async () =>{
|
||||||
//
|
if(state.pushed) return;
|
||||||
if (!title) {
|
if (!title) {
|
||||||
// setState({msgTitle: '请输入标题内容'});
|
// setState({msgTitle: '请输入标题内容'});
|
||||||
return;
|
return;
|
||||||
@ -187,6 +189,9 @@ export default function ArticleEditModal(props: Props) {
|
|||||||
})
|
})
|
||||||
push2video([props.id]).then(() => {
|
push2video([props.id]).then(() => {
|
||||||
showToast(t('news.push_stream_success'), 'success')
|
showToast(t('news.push_stream_success'), 'success')
|
||||||
|
setState({pushed:true})
|
||||||
|
props.onClose?.(true)
|
||||||
|
// props.onRefresh?.();
|
||||||
// navigate('/create?state=push-success',{
|
// navigate('/create?state=push-success',{
|
||||||
// state: 'push-success'
|
// state: 'push-success'
|
||||||
// })
|
// })
|
||||||
@ -201,13 +206,15 @@ export default function ArticleEditModal(props: Props) {
|
|||||||
// 如果传入了id则获取数据
|
// 如果传入了id则获取数据
|
||||||
if (props.id > 0) {
|
if (props.id > 0) {
|
||||||
article.getById(props.id).then(res => {
|
article.getById(props.id).then(res => {
|
||||||
const len = res.hot_news.length
|
if(res.hot_news){
|
||||||
const list = len >= 3 ? res.hot_news :res.hot_news.concat(Array(3 - len).fill(''))
|
const len = res.hot_news.length
|
||||||
const mode = res.hot_news && res.hot_news.filter(s=>s.length > 0).length == 3 ?'manual':'auto';
|
const list = len >= 3 ? res.hot_news :res.hot_news.concat(Array(3 - len).fill(''))
|
||||||
setHotNews({
|
const mode = res.hot_news && res.hot_news.filter(s=>s.length > 0).length == 3 ?'manual':'auto';
|
||||||
list,
|
setHotNews({
|
||||||
mode
|
list,
|
||||||
})
|
mode
|
||||||
|
})
|
||||||
|
}
|
||||||
setGroups(rebuildGroups([[{content: res.metahuman_text, type: "text"}], ...res.content_group]))
|
setGroups(rebuildGroups([[{content: res.metahuman_text, type: "text"}], ...res.content_group]))
|
||||||
setTitle(res.title)
|
setTitle(res.title)
|
||||||
})
|
})
|
||||||
@ -260,7 +267,7 @@ export default function ArticleEditModal(props: Props) {
|
|||||||
</div>
|
</div>
|
||||||
<div className="modal-control-footer flex justify-end">
|
<div className="modal-control-footer flex justify-end">
|
||||||
<div className="flex gap-10 ">
|
<div className="flex gap-10 ">
|
||||||
{props.type == 'news' && props.id ? <button className="text-gray-400 hover:text-gray-800" onClick={handlePush2Video}>{t('news.edit_generate_video')}{state.generating?'推送中...':''}</button> : null}
|
{props.type == 'news' && props.id ? <button className="text-gray-400 hover:text-gray-800" onClick={handlePush2Video}>{t('news.edit_generate_video')}{state.pushed?`${i18n.language == 'zh-CN'?'中':''}...`:(state.generating?`${i18n.language == 'zh-CN'?'推送中':'Pushing'}...`:'')}</button> : null}
|
||||||
<button className="text-gray-400 hover:text-gray-800" onClick={() => props.onClose?.()}>{t('cancel')}</button>
|
<button className="text-gray-400 hover:text-gray-800" onClick={() => props.onClose?.()}>{t('cancel')}</button>
|
||||||
<button onClick={handleSave} className="text-gray-800 hover:text-blue-500">{props.type == 'news' ? t('confirm_text') : t('news.edit_generate_again')}</button>
|
<button onClick={handleSave} className="text-gray-800 hover:text-blue-500">{props.type == 'news' ? t('confirm_text') : t('news.edit_generate_again')}</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -179,6 +179,7 @@ export default function NewEdit() {
|
|||||||
<ArticleEditModal
|
<ArticleEditModal
|
||||||
type="news"
|
type="news"
|
||||||
id={editId}
|
id={editId}
|
||||||
|
onRefresh={refresh}
|
||||||
onClose={(saved) => {
|
onClose={(saved) => {
|
||||||
setEditId(-1)
|
setEditId(-1)
|
||||||
if (saved) refresh()
|
if (saved) refresh()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user