feat: 新闻总页面及逻辑

develop
xjs 2025-02-28 16:55:03 +08:00
parent e38180cd4b
commit b7f984161b
11 changed files with 177 additions and 35 deletions

View File

@ -119,6 +119,8 @@
"useCityNewTop": true,
"useCityNewDetail": true,
"newDetail": true,
"newsDetail": true
"newsDetail": true,
"useNewsList": true,
"newsList": true
}
}

View File

@ -1,5 +1,5 @@
<template>
<wd-fab :draggable="true" :expandable="false" :gap="{ bottom: 170 }">
<wd-fab :draggable="true" :expandable="false" :gap="{ bottom: 100 }">
<template #trigger>
<view class="btn-wrapper" @click="handleClick">
<image

View File

@ -6,7 +6,11 @@
:hover-stop-propagation="false"
>
<text class="text-[32rpx] text-[#333333] font-semibold">高考资讯</text>
<image class="w-[40rpx] h-[40rpx]" src="/static/images/home/right.svg"></image>
<image
class="w-[40rpx] h-[40rpx]"
src="/static/images/home/right.svg"
@click="toNewsPage"
></image>
</view>
<view class="my-[30rpx]" hover-class="none" :hover-stop-propagation="false">
@ -27,14 +31,22 @@
</template>
<script lang="ts" setup>
import { useCityNewTop } from '@/hooks/useCityInfoHook'
import { useCityNewTop, newsList } from '@/hooks/useCityInfoHook'
import { News } from '@/types/app-type'
const { newsList } = useCityNewTop()
onShow(() => {
useCityNewTop()
})
const handleClick = (item: News) => {
uni.navigateTo({
url: `/pages-sub/home/news/index?newsId=${item.id}`,
})
}
const toNewsPage = () => {
uni.navigateTo({
url: '/pages-sub/home/news/newsList',
})
}
</script>

View File

@ -1,4 +1,9 @@
import { getNewsTop, getVolunteerInitialization, getNewsDetailInfo } from '@/service/index/api'
import {
getNewsTop,
getVolunteerInitialization,
getNewsDetailInfo,
getNewsList,
} from '@/service/index/api'
import { useCityStore } from '@/store/city'
import { useUserStore } from '@/store/user'
import { City, News, NewsDetail } from '@/types/app-type'
@ -48,9 +53,8 @@ const groupByFirstLetter = (lis: Province[]): { letter: string; provinces: Provi
.map((key) => ({ letter: key, provinces: grouped[key] }))
}
export const newsList = ref([])
export const useCityNewTop = () => {
const newsList = ref([])
const fetchNewTopFun = (provinceCode) => {
getNewsTop({ Top: 2, CategoryId: 1, provinceCode }).then((res) => {
if (res.code === 200) {
@ -68,8 +72,6 @@ export const useCityNewTop = () => {
} else {
fetchNewTopFun(userStore.userInfo.city.code)
}
return { newsList }
}
export const newsDetail = ref<NewsDetail>({

View File

@ -0,0 +1,11 @@
<route lang="json5" type="page">
{
layout: 'page',
style: {
navigationStyle: 'custom',
},
}
</route>
<template></template>
<script setup lang="ts"></script>

View File

@ -0,0 +1,107 @@
<route lang="json5" type="page">
{
layout: 'page',
style: {
navigationStyle: 'custom',
},
}
</route>
<template>
<view class="flex flex-col h-screen">
<z-paging
ref="paging"
use-virtual-list
:force-close-inner-list="true"
cell-height-mode="dynamic"
@virtualListChange="virtualListChange"
@query="queryList"
>
<!-- 需要固定在顶部不滚动的view放在slot="top"的view中如果需要跟着滚动则不要设置slot="top" -->
<template #top>
<view class="relative h-max" hover-class="none" :hover-stop-propagation="false">
<wd-navbar
title="高考头条"
left-arrow
@click-left="navigatorBack"
safeAreaInsetTop
:bordered="false"
custom-class="bg-transparent! z-[99]"
></wd-navbar>
</view>
</template>
<view
class="item-wrapper"
:id="`zp-id-${item.zp_index}`"
:key="item.zp_index"
v-for="item in newsList"
@click="itemClick(item, item.zp_index)"
>
<view class="flex flex-col items-left p-[32rpx] w-full">
<text class="font-semibold text-[28rpx] text-[#1F2329] max-w-full text-left">
{{ item.title }}
</text>
<view
class="mt-[24rpx] flex justify-between items-center text-[#8F959E] font-normal font-normal w-full"
>
<text class="text-[24rpx]">来源:&nbsp;{{ item.source }}</text>
<text class="text-[22rpx]">{{ item.createTime }}</text>
</view>
</view>
<view class="w-full h-[2rpx] bg-[#eee]" hover-class="none"></view>
</view>
</z-paging>
<view class="flex-1 overflow-auto pb-safe"></view>
</view>
</template>
<script lang="ts" setup>
import useNavbarWeixin from '@/hooks/useNavbarWeixin'
import { getNewsList } from '@/service/index/api'
import { useUserStore } from '@/store/user'
const { safeAreaInsets } = useNavbarWeixin()
const navigatorBack = () => {
uni.navigateBack()
}
const userStore = useUserStore()
const newsList = ref([])
const paging = ref(null)
const virtualListChange = (_vList) => {
newsList.value = _vList
}
const itemClick = (item, index) => {
uni.navigateTo({
url: `/pages-sub/home/news/index?newsId=${item.id}`,
})
}
const queryList = (page: number, pageSize: number) => {
getNewsList({
CategoryId: 1,
provinceCode: userStore.userInfo.city.code,
PageIndex: page,
PageSize: pageSize,
}).then((res) => {
paging.value?.complete((res.result as { data: any[] }).data)
})
}
</script>
<style lang="scss" scoped>
.item-wrapper {
position: relative;
display: flex;
flex-direction: column;
align-items: center;
justify-content: space-between;
padding: 0 32rpx;
}
</style>

View File

@ -52,7 +52,7 @@
@change="tabsChange"
ref="tabsRef"
>
<block v-for="item in unSortTypeList" :key="item.type" :name="item.type">
<block v-for="item in unSortTypeList" :key="item.type">
<wd-tab :title="`${item.name}`" :name="item.type">
<!-- <view class="content">内容{{ item}}</view> -->
</wd-tab>
@ -61,7 +61,7 @@
</view>
</template>
<view
class="item"
class="item-wrapper"
:id="`zp-id-${item.zp_index}`"
:key="item.zp_index"
v-for="(item, index) in schoolList"
@ -160,7 +160,7 @@ const virtualListChange = (_vList) => {
background: linear-gradient(270deg, #f2ce95 0%, #f8deba 100%);
}
.item {
.item-wrapper {
position: relative;
display: flex;
flex-direction: column;
@ -170,28 +170,6 @@ const virtualListChange = (_vList) => {
padding: 0 32rpx;
}
.item-content {
flex: 1;
margin-left: 20rpx;
}
.item-detail {
margin-top: 10rpx;
border-radius: 10rpx;
font-size: 28rpx;
color: #aaaaaa;
word-break: break-all;
}
.item-line {
position: absolute;
bottom: 0rpx;
left: 0rpx;
height: 1px;
width: 100%;
background-color: #eeeeee;
}
/* #ifdef H5 */
:deep(.uni-scroll-view-content) {
display: flex;

View File

@ -123,6 +123,14 @@
"navigationStyle": "custom"
}
},
{
"path": "home/aiAutoFill/index",
"type": "page",
"layout": "page",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "home/autoFill/index",
"type": "page",
@ -183,6 +191,14 @@
"navigationStyle": "custom"
}
},
{
"path": "home/news/newsList",
"type": "page",
"layout": "page",
"style": {
"navigationStyle": "custom"
}
},
{
"path": "home/rank/index",
"type": "page"

View File

@ -55,3 +55,12 @@ export const getNewsTop = (params: { Top: number; CategoryId: number; provinceCo
export const getNewsDetailInfo = (params: { id: number }) => {
return http.get('/api/ZyNews/detail', params)
}
export const getNewsList = (params: {
CategoryId: number
provinceCode: string
PageIndex: number
PageSize: number
}) => {
return http.get('/api/ZyNews/newsPage', params)
}

View File

@ -26,6 +26,7 @@ declare global {
const markRaw: typeof import('vue')['markRaw']
const newDetail: typeof import('../hooks/useCityInfoHook')['newDetail']
const newsDetail: typeof import('../hooks/useCityInfoHook')['newsDetail']
const newsList: typeof import('../hooks/useCityInfoHook')['newsList']
const nextTick: typeof import('vue')['nextTick']
const onActivated: typeof import('vue')['onActivated']
const onAddToFavorites: typeof import('@dcloudio/uni-app')['onAddToFavorites']
@ -96,6 +97,7 @@ declare global {
const useModel: typeof import('vue')['useModel']
const useNatureList: typeof import('../hooks/useFilterSchool')['useNatureList']
const useNavbarWeixin: typeof import('../hooks/useNavbarWeixin')['default']
const useNewsList: typeof import('../hooks/useCityInfoHook')['useNewsList']
const useRegionInfo: typeof import('../hooks/useFilterSchool')['useRegionInfo']
const useRequest: typeof import('../hooks/useRequest')['default']
const useRules: typeof import('../hooks/useRules')['useRules']
@ -142,6 +144,7 @@ declare module 'vue' {
readonly isRef: UnwrapRef<typeof import('vue')['isRef']>
readonly markRaw: UnwrapRef<typeof import('vue')['markRaw']>
readonly newsDetail: UnwrapRef<typeof import('../hooks/useCityInfoHook')['newsDetail']>
readonly newsList: UnwrapRef<typeof import('../hooks/useCityInfoHook')['newsList']>
readonly nextTick: UnwrapRef<typeof import('vue')['nextTick']>
readonly onActivated: UnwrapRef<typeof import('vue')['onActivated']>
readonly onAddToFavorites: UnwrapRef<typeof import('@dcloudio/uni-app')['onAddToFavorites']>

View File

@ -11,6 +11,7 @@ interface NavigateToOptions {
"/pages/place/index/index" |
"/pages/ucenter/index/index" |
"/pages-sub/customerService/index/index" |
"/pages-sub/home/aiAutoFill/index" |
"/pages-sub/home/autoFill/index" |
"/pages-sub/home/career/index" |
"/pages-sub/home/city/index" |
@ -22,6 +23,7 @@ interface NavigateToOptions {
"/pages-sub/home/line/index" |
"/pages-sub/home/major/index" |
"/pages-sub/home/news/index" |
"/pages-sub/home/news/newsList" |
"/pages-sub/home/rank/index" |
"/pages-sub/home/schoolRank/index" |
"/components-sub/FilterMenu/FilterMenu" |