减少请求次数

This commit is contained in:
xixi 2024-08-01 08:36:15 +08:00
parent 08fd4dcb80
commit 7aa44b6ca0
2 changed files with 72 additions and 42 deletions

View File

@ -32,32 +32,32 @@ import SoftwareManagementShow from '../../route/proj/edit/ProjConfigModListShow.
import DisplayOrder from '../../route/proj/edit/ProjConfigMenuList.tsx' import DisplayOrder from '../../route/proj/edit/ProjConfigMenuList.tsx'
import DisplayOrderShow from '../../route/proj/edit/ProjConfigMenuListShow.tsx' import DisplayOrderShow from '../../route/proj/edit/ProjConfigMenuListShow.tsx'
export default function CardProj(props: any) { export default function CardProj(props: any) {
// 选项数组 // // 选项数组
const [tagArray, setTagArray] = useState([]) // const [tagArray, setTagArray] = useState([])
// 获取标签 // // 获取标签
const getTag = () => { // const getTag = () => {
get({ // get({
messageApi, // messageApi,
url: `/api/proj/tag/list-tag`, // url: `/api/proj/tag/list-tag`,
onBefore() { // onBefore() {
}, // },
onSuccess(data: any) { // onSuccess(data: any) {
// console.log('标签信息', data); // // console.log('标签信息', data);
const newarrty: any = (data.data).map((item: any) => ({ // const newarrty: any = (data.data).map((item: any) => ({
value: item.key, // value: item.key,
label: item.value // label: item.value
})); // }));
// console.log('标签信息', newarrty); // // console.log('标签信息', newarrty);
setTagArray(newarrty) // setTagArray(newarrty)
}, // },
onFinally() { // onFinally() {
} // }
}) // })
} // }
// 更新标签状态 // 更新标签状态
const upTag = (dataId:string,projId:string) => { const upTag = (dataId:string,projId:string) => {
post<any>({ post<any>({
@ -73,6 +73,7 @@ export default function CardProj(props: any) {
onSuccess() { onSuccess() {
// console.log(data); // console.log(data);
// props.upData // props.upData
// props.updata()
}, },
onFinally() { onFinally() {
@ -107,11 +108,11 @@ export default function CardProj(props: any) {
const isShow = data.pay.chargeAdditionals.includes('PKG') || data.pay.charge.includes('ALL') const isShow = data.pay.chargeAdditionals.includes('PKG') || data.pay.charge.includes('ALL')
const [messageApi, messageContext] = useMessage(); const [messageApi, messageContext] = useMessage();
const [projCategoryId, setProjCategoryId] = useState(data.projCategoryId); // const [projCategoryId, setProjCategoryId] = useState(data.projCategoryId);
const [projCategoryName, setProjCategoryName] = useState(data.projCategoryName); // const [projCategoryName, setProjCategoryName] = useState(data.projCategoryName);
const [charge, setCharge] = useState(''); const [charge, setCharge] = useState('');
const [payCharge, setPayCharge] = useState(''); const [payCharge, setPayCharge] = useState('');
const indexListContext = useContext(IndexListContext); // const indexListContext = useContext(IndexListContext);
/** /**
* *
*/ */
@ -164,7 +165,7 @@ export default function CardProj(props: any) {
// console.log('额外收费视频',videoDemoValue); // console.log('额外收费视频',videoDemoValue);
// console.log('额外收费加急',URGENTvalue); // console.log('额外收费加急',URGENTvalue);
// console.log('基础服务费',basicsValue); // console.log('基础服务费',basicsValue);
getTag() // getTag()
}, []) }, [])
return ( return (
@ -185,7 +186,7 @@ export default function CardProj(props: any) {
<div className='cp-time'> <div className='cp-time'>
{data.gmtCreate} {data.gmtCreate}
</div> </div>
{tagArray.map((item:any) => { {props.tagArray.map((item:any) => {
return ( return (
<div className='proj-progress' key={item.value} style={{ <div className='proj-progress' key={item.value} style={{
background:(data.tagDataIds).includes(item.value)?'#ff7b00':'', background:(data.tagDataIds).includes(item.value)?'#ff7b00':'',

View File

@ -91,7 +91,35 @@ export default function ListProj() {
} }
}) })
} }
// 选项数组
const [tagArray, setTagArray] = useState([])
// 获取标签
const getTag = () => {
get({
messageApi,
url: `/api/proj/tag/list-tag`,
onBefore() {
},
onSuccess(data: any) {
// console.log('标签信息', data);
const newarrty: any = (data.data).map((item: any) => ({
value: item.key,
label: item.value
}));
// console.log('标签信息', newarrty);
setTagArray(newarrty)
},
onFinally() {
}
})
}
useEffect(()=>{
getTag()
},[])
// 更新数据 // 更新数据
const upreqData = () => { const upreqData = () => {
get<IListPage<IProj>>({ get<IListPage<IProj>>({
@ -144,6 +172,7 @@ export default function ListProj() {
<div className='projListBox' key={new Date().getTime() + ':' + item.projId}> <div className='projListBox' key={new Date().getTime() + ':' + item.projId}>
<CardProj item={item} <CardProj item={item}
updata={upreqData} updata={upreqData}
tagArray={tagArray}
/> />
</div> </div>
) )