news detail 修改完成

This commit is contained in:
LittleBoy 2024-12-23 10:56:03 +08:00
parent 348d23f72c
commit 6d63bdf1a2
4 changed files with 49 additions and 18 deletions

View File

@ -66,6 +66,16 @@ body {
.article-action-icon { .article-action-icon {
@apply cursor-pointer text-gray-500 hover:text-blue-500 block; @apply cursor-pointer text-gray-500 hover:text-blue-500 block;
} }
.news-detail-modal{
.ant-modal-content{
padding-right: 0;
padding-left: 0;
}
}
.news-detail-content-container{
margin-right: -30px;
padding-right: 30px;
}
img { img {
max-width: 100%; max-width: 100%;

View File

@ -1,6 +1,7 @@
import React, {useRef, useState} from "react"; import React, {useRef, useState} from "react";
import {Checkbox, Divider, Empty, Modal, Pagination, Space} from "antd"; import {Checkbox, Divider, Empty, Modal, Space} from "antd";
import {useRequest} from "ahooks"; import {useRequest} from "ahooks";
import {CloseOutlined} from "@ant-design/icons"
import SearchPanel from "@/pages/news/components/search-panel.tsx"; import SearchPanel from "@/pages/news/components/search-panel.tsx";
import {getById, getList} from "@/service/api/news.ts"; import {getById, getList} from "@/service/api/news.ts";
@ -46,7 +47,7 @@ export default function NewsIndex() {
const {update, close} = showLoading('获取新闻详情...') const {update, close} = showLoading('获取新闻详情...')
getById(id).then(res => { getById(id).then(res => {
close() close()
setActiveNews(res) setActiveNews({...res, id})
}).catch(() => { }).catch(() => {
update('获取新闻详情失败', 'info') update('获取新闻详情失败', 'info')
}) })
@ -60,23 +61,46 @@ export default function NewsIndex() {
setCheckedId([]) setCheckedId([])
} }
} }
const scrollerRef = useRef<InfiniteScrollerRef|null>(null) const scrollerRef = useRef<InfiniteScrollerRef | null>(null)
const handleCheckChange = (id: number) => {
if (checkedId.includes(id)) {
setCheckedId(checkedId.filter(id => id != id))
} else {
setCheckedId([...checkedId, id])
}
}
return (<div className={'container pb-5'}> return (<div className={'container pb-5'}>
<SearchPanel onSearch={setParams}/> <SearchPanel onSearch={setParams}/>
{activeNews && <Modal open={true} centered width={1000} footer={null} onCancel={() => setActiveNews(undefined)}> {activeNews && <Modal
<div className="news-detail px-3 pb-5"> rootClassName={'news-detail-modal'}
closeIcon={null} open={true} width={1000}
maskClosable={false}
footer={null} onCancel={() => setActiveNews(undefined)}
>
<div className="news-detail pl-16 pr-1 flex pb-5">
<div className="px-4 py-6 bg-white"> <div className="px-4 py-6 bg-white">
<div className="new-title text-2xl">{activeNews?.title}</div> <div className="new-title text-2xl">{activeNews?.title}</div>
<Divider className={'my-4'}/> <div className="info mt-2 mb-2 text-sm flex gap-3">
<div className="info mt-2 mb-5 text-sm flex gap-3">
<span className="source text-blue-400">{activeNews?.media_name}</span> <span className="source text-blue-400">{activeNews?.media_name}</span>
<span className="create-time text-gray-400">{formatTime(activeNews?.publish_time)}</span> <span className="create-time text-gray-400">{formatTime(activeNews?.publish_time)}</span>
</div> </div>
<div className="overflow-auto leading-7 text-base" <Divider className={'my-2'}/>
<div className="overflow-auto leading-7 text-base news-detail-content-container"
style={{maxHeight: 500}} dangerouslySetInnerHTML={{__html: activeNews?.content || ''}}></div> style={{maxHeight: 500}} dangerouslySetInnerHTML={{__html: activeNews?.content || ''}}></div>
</div> </div>
<div className="actions ml-2">
<div className="close">
<CloseOutlined className="text-xl text-gray-400 hover:text-gray-800"
onClick={() => setActiveNews(undefined)}/>
</div>
<div className="whitespace-nowrap text-sm mt-2">
<Checkbox
checked={checkedId.includes(activeNews!.id)}
onChange={() => handleCheckChange(activeNews!.id)}
><span></span></Checkbox>
</div>
</div>
</div> </div>
</Modal>} </Modal>}
<div className="news-list-container"> <div className="news-list-container">
@ -99,7 +123,7 @@ export default function NewsIndex() {
pagination={data?.pagination} pagination={data?.pagination}
loading={loading} loading={loading}
ref={scrollerRef} ref={scrollerRef}
onScroll={(top)=> setState({showToTop: top > 30})} onScroll={(top) => setState({showToTop: top > 30})}
onCallback={(page) => { onCallback={(page) => {
setParams({...params, pagination: {...params.pagination, page}}) setParams({...params, pagination: {...params.pagination, page}})
}} }}
@ -138,11 +162,7 @@ export default function NewsIndex() {
{item.internal_article_id > 0 ? {item.internal_article_id > 0 ?
<span className={"inline-block w-[16px] "}></span> : <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)) { handleCheckChange(item.id)
setCheckedId(checkedId.filter(id => id != item.id))
} else {
setCheckedId([...checkedId, item.id])
}
}}/>} }}/>}
</div> </div>
</div> </div>
@ -155,7 +175,7 @@ export default function NewsIndex() {
</div> </div>
<div className="page-action"> <div className="page-action">
<ButtonToTop visible={state.showToTop} onClick={()=>scrollerRef.current?.scrollToPosition(0)} /> <ButtonToTop visible={state.showToTop} onClick={() => scrollerRef.current?.scrollToPosition(0)}/>
<div> <div>
<ButtonNewsDownload ids={checkedId}/> <ButtonNewsDownload ids={checkedId}/>
</div> </div>

1
src/types/core.d.ts vendored
View File

@ -35,6 +35,7 @@ declare interface ArticleDetail {
} }
declare interface NewsInfo { declare interface NewsInfo {
id: number;
title: string; title: string;
content: string; content: string;
media_name: string; media_name: string;

View File

@ -6,7 +6,7 @@ import dayjs from "dayjs";
// https://vitejs.dev/config/ // https://vitejs.dev/config/
export default defineConfig(({mode}) => { export default defineConfig(({mode}) => {
const devServerHost = mode == 'test' ? '124.220.14.192' : '192.168.0.231:9999' const devServerHost = mode == 'test' ? 'https://fm-admin.starbitech.com' : 'http://192.168.0.231:9999'
const AUTH_TOKEN_KEY = mode == 'production' ? 'digital-person-token' : `digital-person-token_${mode}` const AUTH_TOKEN_KEY = mode == 'production' ? 'digital-person-token' : `digital-person-token_${mode}`
if (mode !== 'production') { if (mode !== 'production') {
@ -41,7 +41,7 @@ export default defineConfig(({mode}) => {
port: 10021, port: 10021,
proxy: { proxy: {
'/mgmt': { '/mgmt': {
target: `http://${devServerHost}`, // http://124.220.14.192/ 192.168.0.231:9999 target: `${devServerHost}`, // http://124.220.14.192/ 192.168.0.231:9999
changeOrigin: true, changeOrigin: true,
// rewrite: (path) => path.replace(/^\/api/, '') // rewrite: (path) => path.replace(/^\/api/, '')
}, },