|
@@ -2,34 +2,60 @@ import { useEffect, useRef, useState } from 'react'
|
|
|
import HeaderFilter from './components/HeaderFilter'
|
|
|
import ContentTable from './components/ContentTable'
|
|
|
import CreateModal from './components/CreateModal'
|
|
|
+import { useGlobalStateUpdate } from '@src/store/globalStates/loadingState'
|
|
|
+import {
|
|
|
+ createAd as createAdRequest,
|
|
|
+ getAdList,
|
|
|
+ openAd,
|
|
|
+ clsoeAd,
|
|
|
+ getAllAppList
|
|
|
+} from './request'
|
|
|
import type {
|
|
|
- RowDataType, PaginationParamsType,
|
|
|
+ RowDataType,
|
|
|
+ PaginationParamsType,
|
|
|
} from './components/ContentTable/types'
|
|
|
-import type { RefType, FormDataType } from './components/CreateModal/types'
|
|
|
-import { useGlobalStateUpdate } from '@src/store/globalStates/loadingState'
|
|
|
+import type {
|
|
|
+ RefType,
|
|
|
+ FormDataType
|
|
|
+} from './components/CreateModal/types'
|
|
|
+import { AllAppListItemType } from './types'
|
|
|
+
|
|
|
|
|
|
|
|
|
export function AdManage(){
|
|
|
const [tableData, setTableData] = useState<RowDataType[]>([])
|
|
|
const [total, setTotal] = useState(0)
|
|
|
const [paginationParams, setPaginationParams] = useState<PaginationParamsType>({ pageNumber: 1, pageSize: 10})
|
|
|
+ const [allAppList, setAllAppList] = useState<AllAppListItemType[]>([])
|
|
|
const createModalRef = useRef<RefType>()
|
|
|
const setloading = useGlobalStateUpdate()
|
|
|
|
|
|
+ useEffect(()=>{
|
|
|
+ getAllAppList().then(res=>{
|
|
|
+ if (res) {
|
|
|
+ setAllAppList(res)
|
|
|
+ }
|
|
|
+ })
|
|
|
+ },[])
|
|
|
+
|
|
|
useEffect(()=>{
|
|
|
getTableData()
|
|
|
},[paginationParams])
|
|
|
|
|
|
const getTableData = async () => {
|
|
|
- // TODO 获取数据
|
|
|
+ setloading(true)
|
|
|
+
|
|
|
+ const {pageNumber,pageSize} = paginationParams
|
|
|
+ const data = await getAdList({
|
|
|
+ pageSize,
|
|
|
+ currentPage: pageNumber,
|
|
|
+ })
|
|
|
+ if (data) {
|
|
|
+ setTableData(data.objs)
|
|
|
+ setTotal(data.totalSize)
|
|
|
+ }
|
|
|
|
|
|
- // setloading(true)
|
|
|
- // const data = await getPlanList(mergeRequestParams(paginationParams, filterParams))
|
|
|
- // if (data) {
|
|
|
- // setTableData(data.objs)
|
|
|
- // setTotal(data.totalSize)
|
|
|
- // }
|
|
|
- // setloading(false)
|
|
|
+ setloading(false)
|
|
|
}
|
|
|
|
|
|
const onPaginationChange =async (params: PaginationParamsType) => {
|
|
@@ -40,15 +66,25 @@ export function AdManage(){
|
|
|
createModalRef.current?.open()
|
|
|
}
|
|
|
|
|
|
- const onSwitchStatus = ({row, checked}:{row:RowDataType, checked:boolean}) => {
|
|
|
+ const onSwitchStatus = async ({row, checked}:{row:RowDataType, checked:boolean}) => {
|
|
|
console.log(row, checked)
|
|
|
- // TODO 切换状态
|
|
|
+ setloading(true)
|
|
|
+ const res = checked ? await openAd(row.id) : await clsoeAd(row.id)
|
|
|
+ setloading(false)
|
|
|
+ if (res) {
|
|
|
+ getTableData()
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- const createAd = (form: FormDataType, cb:EventFunctionType<[]>) => {
|
|
|
- console.log('创建',form)
|
|
|
- // TODO 创建接口
|
|
|
- cb()
|
|
|
+ const createAd = async (form: FormDataType, cb:EventFunctionType<[]>) => {
|
|
|
+ setloading(true)
|
|
|
+ const res = await createAdRequest(form)
|
|
|
+ setloading(false)
|
|
|
+ if (res) {
|
|
|
+ getTableData()
|
|
|
+ cb() // 关闭modal
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
const updateAd = (form: RowDataType, cb:EventFunctionType<[]>) => {
|
|
@@ -70,6 +106,7 @@ export function AdManage(){
|
|
|
/>
|
|
|
<CreateModal
|
|
|
ref={createModalRef}
|
|
|
+ allAppList={allAppList}
|
|
|
onCreate={createAd}
|
|
|
onUpdate={updateAd}
|
|
|
/>
|