import req from 'editorReq'; import { useQuery } from 'react-query'; import { IResponce, TResponce1 } from 'src/type'; import { API_CMS_ADMIN, API_SPECIAL } from './config'; import _ from 'lodash'; import { useState } from 'react'; import { tablePageSize } from 'editorSrc/pages/config/table'; export const LANDING_PAGE_GET_ALL = (page: number, pageSize: number) => { return `${API_CMS_ADMIN}/pageUri/list/${pageSize}/${page}/created_at/desc/complex?is_dir=0&is_valid=1`; }; export const LANDING_PAGE_URL = `${API_SPECIAL}/wxapp/proxy/url`; export async function getAll(url: string, id: string, title: string) { return req({ url, method: 'GET', data: _.pickBy( { id, title, }, _.identity, ), }) as Promise>; } export async function getLandingPageUrl(id: string) { return req({ url: LANDING_PAGE_URL, method: 'GET', data: { id }, }) as Promise>; } export interface ISearchParam { id: string; title: string; _id: string; } const defaultSearchParam = { id: '', title: '', _id: '' }; export function useLandingPage() { const [searchParam, setSearchParam] = useState(defaultSearchParam); const { id, title } = searchParam; const [page, setPage] = useState(1); const [pageSize, setPageSize] = useState(tablePageSize); const url = LANDING_PAGE_GET_ALL(page, pageSize); const { data, ...rest } = useQuery([url, id, title], () => getAll(url, id, title)); const onSearch = (searchParam: ISearchParam) => { setPage(1); setSearchParam(searchParam); }; const reset = () => { setSearchParam({ ...defaultSearchParam }); setPage(1); }; return { data, onSearch, setPageSize, setPage, reset, ...rest, }; } export interface ILandingPage { cover: string; created_at: string; deleted_at: null | string; file_sign: null | string; folder: string; have_pc: number; have_wap: number; html_content: string; id: string; key: string; status: number; style: string; system: string; title: string; type_wap: number; updated_at: string; user_id: string; user_name: string; uri:string; _id: string; } export interface ILandingPages { firstPage: boolean; hasNextPage: boolean; hasPrePage: boolean; items: ILandingPage[]; lastPage: boolean; limit: number; nextPage: number; page: number; prePage: number; totalCount: number; totalPages: number; }