Browse Source

热门推荐布局与接口

template
liruiqiang 2 months ago
parent
commit
f0c91322f7
  1. 84
      src/pages/index/components/HotPanel.vue
  2. 16
      src/pages/index/index.vue
  3. 12
      src/services/home.ts
  4. 16
      src/types/home.d.ts

84
src/pages/index/components/HotPanel.vue

@ -0,0 +1,84 @@
<template>
<!-- 推荐专区 -->
<view class="panel hot">
<view class="item" v-for="item in list" :key="item.id">
<view class="title">
<text class="title-text">{{ item.title }}</text>
<text class="title-desc">{{ item.alt }}</text>
</view>
<navigator hover-class="none" :url="`/pages/hot/hot?type=${item.type}`" class="cards">
<image
v-for="src in item.pictures"
:key="src"
class="image"
mode="aspectFit"
:src="src"
></image>
</navigator>
</view>
</view>
</template>
<script setup lang="ts">
import type { HotItem } from '@/types/home'
// props
defineProps<{
list: HotItem[]
}>()
</script>
<style lang="scss">
/* 热门推荐 */
.hot {
display: flex;
flex-wrap: wrap;
min-height: 508rpx;
margin: 20rpx 20rpx 0;
border-radius: 10rpx;
background-color: #fff;
.title {
display: flex;
align-items: center;
padding: 24rpx 24rpx 0;
font-size: 32rpx;
color: #262626;
position: relative;
.title-desc {
font-size: 24rpx;
color: #7f7f7f;
margin-left: 18rpx;
}
}
.item {
display: flex;
flex-direction: column;
width: 50%;
height: 254rpx;
border-right: 1rpx solid #eee;
border-top: 1rpx solid #eee;
.title {
justify-content: start;
}
&:nth-child(2n) {
border-right: 0 none;
}
&:nth-child(-n + 2) {
border-top: 0 none;
}
.image {
width: 150rpx;
height: 150rpx;
}
}
.cards {
flex: 1;
padding: 15rpx 20rpx;
display: flex;
justify-content: space-between;
align-items: center;
}
}
</style>

16
src/pages/index/index.vue

@ -7,17 +7,20 @@
<XtxSwiper :list="bannerList" />
<!-- 分类面板 -->
<CategoryPanel :list="categoryList" />
<!-- 热门推荐 -->
<HotPanel :list="hotList" />
</view>
</template>
<script setup lang="ts">
import CustomNavbar from './components/CustomNavbar.vue'
import CategoryPanel from './components/CategoryPanel.vue'
import HotPanel from './components/HotPanel.vue'
import XtxSwiper from '../../components/XtxSwiper.vue'
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getHomeBannerAPI, getHomeCategoryAPI } from '@/services/home'
import type { BannerItem, CategoryItem } from '@/types/home'
import { getHomeBannerAPI, getHomeCategoryAPI, getHomeHotAPI } from '@/services/home'
import type { BannerItem, CategoryItem, HotItem } from '@/types/home'
//
const bannerList = ref<BannerItem[]>([])
@ -33,13 +36,20 @@ const getHomeCategoryData = async () => {
categoryList.value = res.result
}
//
const hotList = ref<HotItem[]>([])
const getHomeHotData = async () => {
const res = await getHomeHotAPI()
hotList.value = res.result
}
//
const isLoading = ref(false)
//
onLoad(async () => {
isLoading.value = true
await Promise.all([getHomeBannerData(), getHomeCategoryData()])
await Promise.all([getHomeBannerData(), getHomeCategoryData(), getHomeHotData()])
isLoading.value = false
})
</script>

12
src/services/home.ts

@ -1,6 +1,6 @@
// 请求封装调用
import { http } from '@/utils/http'
import type { BannerItem, CategoryItem } from '@/types/home'
import type { BannerItem, CategoryItem, HotItem } from '@/types/home'
/**
* -广-
* @param distributionSite 广 12 1
@ -24,3 +24,13 @@ export const getHomeCategoryAPI = () => {
url: '/home/category/mutli',
})
}
/**
* --
*/
export const getHomeHotAPI = () => {
return http<HotItem[]>({
method: 'GET',
url: '/home/hot/mutli',
})
}

16
src/types/home.d.ts

@ -19,3 +19,19 @@ export type CategoryItem = {
/** 分类名称 */
name: string
}
/** 首页-热门推荐数据类型 */
export type HotItem = {
/** 说明 */
alt: string
/** id */
id: string
/** 图片集合[ 图片路径 ] */
pictures: string[]
/** 跳转地址 */
target: string
/** 标题 */
title: string
/** 推荐类型 */
type: string
}
Loading…
Cancel
Save