文章列表返回时的刷新

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 Spin from "@/components/spinner";
import NavigationBar from "@/components/navigationBar/navigationBar";
// import {Search} from "./components/search"
const Home: FC = () => {
const globalData = Taro.getApp().globalData

@ -23,6 +23,7 @@ const Profession = () => {
const [data, setData] = useState<Map<number, KillData>>(new Map)
const [enable, setEnable] = useState(true)
/**
* 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(() => {
console.log(categoryId,'categoryId')
categoryId && getData()
}, [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 newTabs = res.map<TabList>(d => ({title: d.name, value: d.id}))
setTabs(newTabs)
setCategoryId(newTabs[0].value as number)
// setEnable(false)
}
@ -95,7 +96,7 @@ const Profession = () => {
}
function jumpInfo(info: any) {
console.log(info, 'info')
if (info.article) {
Taro.navigateTo({url: `/pages/preview/brand/article/article?id=${info.owner_id}`})
} else if (info.course) {
@ -105,6 +106,9 @@ const Profession = () => {
} else if (info.brand) {
Taro.navigateTo({url: `/pages/preview/brand/info/info?id=${info.owner_id}`})
}
}
function swiperChange(e) {

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

Loading…
Cancel
Save