style: 🎨 aPI 接口统一添加后缀API, 方便识别
This commit is contained in:
parent
a5b238654d
commit
4271a7a5dd
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import type { GuessItem } from '@/types/home'
|
import type { GuessItem } from '@/types/home'
|
||||||
import { getGuessLike } from '@/services/home'
|
import { getGuessLikeAPI } from '@/services/home'
|
||||||
import { onBeforeMount, ref } from 'vue'
|
import { onBeforeMount, ref } from 'vue'
|
||||||
import type { PageParams } from '@/types/global'
|
import type { PageParams } from '@/types/global'
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ const getGuessList = async () => {
|
|||||||
if (finish.value === true) {
|
if (finish.value === true) {
|
||||||
return uni.showToast({ icon: 'none', title: '没有更多数据~' })
|
return uni.showToast({ icon: 'none', title: '没有更多数据~' })
|
||||||
}
|
}
|
||||||
const res = await getGuessLike(pageParams)
|
const res = await getGuessLikeAPI(pageParams)
|
||||||
// 追加数据
|
// 追加数据
|
||||||
guessList.value.push(...res.result.items)
|
guessList.value.push(...res.result.items)
|
||||||
// 更新分页参数
|
// 更新分页参数
|
||||||
|
@ -52,7 +52,7 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onLoad } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import { getHotRecommend } from '@/services/hot'
|
import { getHotRecommendAPI } from '@/services/hot'
|
||||||
import type { SubTypeItem } from '@/types/hot'
|
import type { SubTypeItem } from '@/types/hot'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
|
|
||||||
@ -84,7 +84,7 @@ const actived = ref(0)
|
|||||||
|
|
||||||
// 获取热门商品, 不传subType, 获取所有分类第一页
|
// 获取热门商品, 不传subType, 获取所有分类第一页
|
||||||
const getRecommend = async () => {
|
const getRecommend = async () => {
|
||||||
const res = await getHotRecommend(currHot!.url, {
|
const res = await getHotRecommendAPI(currHot!.url, {
|
||||||
page: import.meta.env.DEV ? 33 : 1,
|
page: import.meta.env.DEV ? 33 : 1,
|
||||||
pageSize: 10,
|
pageSize: 10,
|
||||||
})
|
})
|
||||||
@ -107,7 +107,7 @@ const onScrollToLower = async () => {
|
|||||||
}
|
}
|
||||||
const nextPage = page + 1
|
const nextPage = page + 1
|
||||||
// 接口被复用了, 没有传的subType, 没有返回 goodsItems 数据
|
// 接口被复用了, 没有传的subType, 没有返回 goodsItems 数据
|
||||||
const res = await getHotRecommend(currHot!.url, {
|
const res = await getHotRecommendAPI(currHot!.url, {
|
||||||
subType: subTypeId,
|
subType: subTypeId,
|
||||||
page: nextPage,
|
page: nextPage,
|
||||||
pageSize,
|
pageSize,
|
||||||
|
@ -31,7 +31,7 @@
|
|||||||
import type { BannerItem, CategoryItem, HotItem } from '@/types/home'
|
import type { BannerItem, CategoryItem, HotItem } from '@/types/home'
|
||||||
import CustomNavbar from './components/CustomNavbar.vue'
|
import CustomNavbar from './components/CustomNavbar.vue'
|
||||||
import { ref } from 'vue'
|
import { ref } from 'vue'
|
||||||
import { getCategory, getHomeBanner, getHomeHot } from '@/services/home'
|
import { getCategoryAPI, getHomeBannerAPI, getHomeHotAPI } from '@/services/home'
|
||||||
import { onLoad } from '@dcloudio/uni-app'
|
import { onLoad } from '@dcloudio/uni-app'
|
||||||
import CategoryPanel from './components/CategoryPanel.vue'
|
import CategoryPanel from './components/CategoryPanel.vue'
|
||||||
import HotPanel from './components/HotPanel.vue'
|
import HotPanel from './components/HotPanel.vue'
|
||||||
@ -44,21 +44,21 @@ const isLoading = ref(true)
|
|||||||
// 获取轮播图数据
|
// 获取轮播图数据
|
||||||
const bannerList = ref<BannerItem[]>([])
|
const bannerList = ref<BannerItem[]>([])
|
||||||
const getBannerList = async () => {
|
const getBannerList = async () => {
|
||||||
const res = await getHomeBanner()
|
const res = await getHomeBannerAPI()
|
||||||
bannerList.value = res.result
|
bannerList.value = res.result
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取分类数据
|
// 获取分类数据
|
||||||
const categoryList = ref<CategoryItem[]>([])
|
const categoryList = ref<CategoryItem[]>([])
|
||||||
const getCategoryList = async () => {
|
const getCategoryAPIList = async () => {
|
||||||
const res = await getCategory()
|
const res = await getCategoryAPI()
|
||||||
categoryList.value = res.result
|
categoryList.value = res.result
|
||||||
}
|
}
|
||||||
|
|
||||||
// 获取热门商品数据
|
// 获取热门商品数据
|
||||||
const hotList = ref<HotItem[]>([])
|
const hotList = ref<HotItem[]>([])
|
||||||
const getHotList = async () => {
|
const getHotList = async () => {
|
||||||
const res = await getHomeHot()
|
const res = await getHomeHotAPI()
|
||||||
hotList.value = res.result
|
hotList.value = res.result
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +78,7 @@ const onRefresh = async () => {
|
|||||||
guessRef.value?.resetData()
|
guessRef.value?.resetData()
|
||||||
await Promise.allSettled([
|
await Promise.allSettled([
|
||||||
getBannerList(),
|
getBannerList(),
|
||||||
getCategoryList(),
|
getCategoryAPIList(),
|
||||||
getHotList(),
|
getHotList(),
|
||||||
guessRef.value?.getMore(),
|
guessRef.value?.getMore(),
|
||||||
])
|
])
|
||||||
@ -88,7 +88,7 @@ const onRefresh = async () => {
|
|||||||
// 页面加载勾子
|
// 页面加载勾子
|
||||||
onLoad(async () => {
|
onLoad(async () => {
|
||||||
isLoading.value = true
|
isLoading.value = true
|
||||||
await Promise.allSettled([getBannerList(), getCategoryList(), getHotList()])
|
await Promise.allSettled([getBannerList(), getCategoryAPIList(), getHotList()])
|
||||||
isLoading.value = false
|
isLoading.value = false
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
|
@ -7,7 +7,7 @@ import { http } from '@/utils/http'
|
|||||||
* @param distributionSite - 广告区域展示位置: 1 为首页(默认值); 2 为商品分类页
|
* @param distributionSite - 广告区域展示位置: 1 为首页(默认值); 2 为商品分类页
|
||||||
* @returns 轮播图数据
|
* @returns 轮播图数据
|
||||||
*/
|
*/
|
||||||
export const getHomeBanner = (distributionSite = 1) => {
|
export const getHomeBannerAPI = (distributionSite = 1) => {
|
||||||
return http<BannerItem[]>({
|
return http<BannerItem[]>({
|
||||||
url: '/home/banner',
|
url: '/home/banner',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -21,7 +21,7 @@ export const getHomeBanner = (distributionSite = 1) => {
|
|||||||
* 获取首页分类
|
* 获取首页分类
|
||||||
* @returns 分类数据
|
* @returns 分类数据
|
||||||
*/
|
*/
|
||||||
export const getCategory = () => {
|
export const getCategoryAPI = () => {
|
||||||
return http<CategoryItem[]>({
|
return http<CategoryItem[]>({
|
||||||
url: '/home/category/mutli',
|
url: '/home/category/mutli',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -32,7 +32,7 @@ export const getCategory = () => {
|
|||||||
* 获取首页热门商品
|
* 获取首页热门商品
|
||||||
* @returns 热门商品数据
|
* @returns 热门商品数据
|
||||||
*/
|
*/
|
||||||
export const getHomeHot = () => {
|
export const getHomeHotAPI = () => {
|
||||||
return http<HotItem[]>({
|
return http<HotItem[]>({
|
||||||
url: '/home/hot/mutli',
|
url: '/home/hot/mutli',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
@ -44,7 +44,7 @@ export const getHomeHot = () => {
|
|||||||
* @param data - 分页参数
|
* @param data - 分页参数
|
||||||
* @returns 猜你喜欢数据
|
* @returns 猜你喜欢数据
|
||||||
*/
|
*/
|
||||||
export const getGuessLike = (data?: PageParams) => {
|
export const getGuessLikeAPI = (data?: PageParams) => {
|
||||||
return http<PageResult<GuessItem>>({
|
return http<PageResult<GuessItem>>({
|
||||||
url: '/home/goods/guessLike',
|
url: '/home/goods/guessLike',
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
@ -9,7 +9,7 @@ type HotParams = PageParams & {
|
|||||||
/**
|
/**
|
||||||
* 获取热门推荐
|
* 获取热门推荐
|
||||||
*/
|
*/
|
||||||
export const getHotRecommend = (url: string, data: HotParams) => {
|
export const getHotRecommendAPI = (url: string, data: HotParams) => {
|
||||||
return http<HotResult>({
|
return http<HotResult>({
|
||||||
url,
|
url,
|
||||||
method: 'GET',
|
method: 'GET',
|
||||||
|
27
src/types/category.d.ts
vendored
Normal file
27
src/types/category.d.ts
vendored
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
import type { GoodsItem } from './global'
|
||||||
|
|
||||||
|
/** 一级分类项 */
|
||||||
|
export type CategoryTopItem = {
|
||||||
|
/** 二级分类集合[ 二级分类项 ] */
|
||||||
|
children: CategoryChildItem[]
|
||||||
|
/** 一级分类id */
|
||||||
|
id: string
|
||||||
|
/** 一级分类图片集[ 一级分类图片项 ] */
|
||||||
|
imageBanners: string[]
|
||||||
|
/** 一级分类名称 */
|
||||||
|
name: string
|
||||||
|
/** 一级分类图片 */
|
||||||
|
picture: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 二级分类项 */
|
||||||
|
export type CategoryChildItem = {
|
||||||
|
/** 商品集合[ 商品项 ] */
|
||||||
|
goods: GoodsItem[]
|
||||||
|
/** 二级分类id */
|
||||||
|
id: string
|
||||||
|
/** 二级分类名称 */
|
||||||
|
name: string
|
||||||
|
/** 二级分类图片 */
|
||||||
|
picture: string
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user