文章列表返回时的刷新

v2
一杯沧海 1 year ago
parent 2a29617017
commit b33c7170ea
  1. 1
      src/pages/home/home.tsx
  2. 34
      src/pages/preview/collect/collect.tsx
  3. 2
      src/pages/preview/search/search/components/list.tsx

@ -12,6 +12,7 @@ import {HomeApi, HomeData} from "@/api";
import logo from '@/static/img/logo.svg' import logo from '@/static/img/logo.svg'
import Spin from "@/components/spinner"; import Spin from "@/components/spinner";
import NavigationBar from "@/components/navigationBar/navigationBar"; import NavigationBar from "@/components/navigationBar/navigationBar";
// import {Search} from "./components/search"
const Home: FC = () => { const Home: FC = () => {
const globalData = Taro.getApp().globalData const globalData = Taro.getApp().globalData

@ -23,6 +23,7 @@ const Profession = () => {
const [data, setData] = useState<Map<number, KillData>>(new Map) const [data, setData] = useState<Map<number, KillData>>(new Map)
const [enable, setEnable] = useState(true) const [enable, setEnable] = useState(true)
/** /**
* more * more
*/ */
@ -62,31 +63,31 @@ const Profession = () => {
} }
} }
Taro.useDidShow(useCallback(() => {
if (categoryId) {
let tempMap = new Map()
tempMap.set(categoryId, {
data: [],
total: undefined,
page: 1
})
setData(tempMap)
getData()
}
}, [data]))
useEffect(() => { useEffect(() => {
console.log(categoryId,'categoryId') console.log(categoryId,'categoryId')
categoryId && getData() categoryId && getData()
}, [categoryId]) }, [categoryId])
async function getCategory() { Taro.useDidShow(async () => {
const oldData = new Map<number, KillData>(data)
if (categoryId) {
const data = await userApi.collectList(categoryId!, 1, 10)
oldData.delete(categoryId)
oldData.set(categoryId, {
data: data.list,
total: data.total,
page: 1
})
setData(oldData)
}
})
async function getCategory() {
const res = [{name: '视频', id: 2}, {name: '文章', id: 1}, {name: '课程', id: 3}, {name: '其他', id: 4}] const res = [{name: '视频', id: 2}, {name: '文章', id: 1}, {name: '课程', id: 3}, {name: '其他', id: 4}]
const newTabs = res.map<TabList>(d => ({title: d.name, value: d.id})) const newTabs = res.map<TabList>(d => ({title: d.name, value: d.id}))
setTabs(newTabs) setTabs(newTabs)
setCategoryId(newTabs[0].value as number) setCategoryId(newTabs[0].value as number)
// setEnable(false)
} }
@ -95,7 +96,7 @@ const Profession = () => {
} }
function jumpInfo(info: any) { function jumpInfo(info: any) {
console.log(info, 'info')
if (info.article) { if (info.article) {
Taro.navigateTo({url: `/pages/preview/brand/article/article?id=${info.owner_id}`}) Taro.navigateTo({url: `/pages/preview/brand/article/article?id=${info.owner_id}`})
} else if (info.course) { } else if (info.course) {
@ -105,6 +106,9 @@ const Profession = () => {
} else if (info.brand) { } else if (info.brand) {
Taro.navigateTo({url: `/pages/preview/brand/info/info?id=${info.owner_id}`}) Taro.navigateTo({url: `/pages/preview/brand/info/info?id=${info.owner_id}`})
} }
} }
function swiperChange(e) { function swiperChange(e) {

@ -28,12 +28,14 @@ const SearchList: FC<Props> = ({name, clear}) => {
setLoading(true) setLoading(true)
} }
}, [clear]) }, [clear])
useEffect(() => { useEffect(() => {
if (name && clear) { if (name && clear) {
getData() getData()
} }
}, [page, name, clear]) }, [page, name, clear])
const getData = useCallback(async () => { const getData = useCallback(async () => {
try { try {
const data = await SearchApi.list(page, 10, name) const data = await SearchApi.list(page, 10, name)

Loading…
Cancel
Save