Browse Source

首页分类布局与接口

template
liruiqiang 2 months ago
parent
commit
4ccd2debea
  1. 52
      src/pages/index/components/CategoryPanel.vue
  2. 17
      src/pages/index/index.vue
  3. 14
      src/services/home.ts
  4. 10
      src/types/home.d.ts

52
src/pages/index/components/CategoryPanel.vue

@ -0,0 +1,52 @@
<template>
<view class="category">
<navigator
class="category-item"
hover-class="none"
url="/pages/index/index"
v-for="item in list"
:key="item.id"
>
<image class="icon" :src="item.icon"></image>
<text class="text">{{ item.name }}</text>
</navigator>
</view>
</template>
<script setup lang="ts">
import type { CategoryItem } from '@/types/home'
// props
defineProps<{
list: CategoryItem[]
}>()
</script>
<style lang="scss">
/* 前台类目 */
.category {
margin: 20rpx 0 0;
padding: 10rpx 0;
display: flex;
flex-wrap: wrap;
min-height: 328rpx;
.category-item {
width: 150rpx;
display: flex;
justify-content: center;
flex-direction: column;
align-items: center;
box-sizing: border-box;
.icon {
width: 100rpx;
height: 100rpx;
}
.text {
font-size: 26rpx;
color: #666;
}
}
}
</style>

17
src/pages/index/index.vue

@ -3,17 +3,21 @@
<!-- 自定义导航栏 -->
<CustomNavbar />
<PageSkeleton v-if="isLoading" />
<!-- 自定义轮播图 -->
<XtxSwiper :list="bannerList" />
<!-- 分类面板 -->
<CategoryPanel :list="categoryList" />
</view>
</template>
<script setup lang="ts">
import CustomNavbar from './components/CustomNavbar.vue'
import CategoryPanel from './components/CategoryPanel.vue'
import XtxSwiper from '../../components/XtxSwiper.vue'
import { ref } from 'vue'
import { onLoad } from '@dcloudio/uni-app'
import { getHomeBannerAPI } from '@/services/home'
import type { BannerItem } from '@/types/home'
import { getHomeBannerAPI, getHomeCategoryAPI } from '@/services/home'
import type { BannerItem, CategoryItem } from '@/types/home'
//
const bannerList = ref<BannerItem[]>([])
@ -22,13 +26,20 @@ const getHomeBannerData = async () => {
bannerList.value = res.result
}
//
const categoryList = ref<CategoryItem[]>([])
const getHomeCategoryData = async () => {
const res = await getHomeCategoryAPI()
categoryList.value = res.result
}
//
const isLoading = ref(false)
//
onLoad(async () => {
isLoading.value = true
await Promise.all([getHomeBannerData()])
await Promise.all([getHomeBannerData(), getHomeCategoryData()])
isLoading.value = false
})
</script>

14
src/services/home.ts

@ -1,8 +1,6 @@
// 请求封装调用
import { http } from '@/utils/http'
// 存放路径: src/services/home.ts
import type { BannerItem } from '@/types/home'
import type { BannerItem, CategoryItem } from '@/types/home'
/**
* -广-
* @param distributionSite 广 12 1
@ -16,3 +14,13 @@ export const getHomeBannerAPI = (distributionSite = 1) => {
},
})
}
/**
* --
*/
export const getHomeCategoryAPI = () => {
return http<CategoryItem[]>({
method: 'GET',
url: '/home/category/mutli',
})
}

10
src/types/home.d.ts

@ -9,3 +9,13 @@ export type BannerItem = {
/** 跳转类型 */
type: number
}
/** 首页-前台类目数据类型 */
export type CategoryItem = {
/** 图标路径 */
icon: string
/** id */
id: string
/** 分类名称 */
name: string
}
Loading…
Cancel
Save