style: 🎨 aPI 接口统一添加后缀API, 方便识别

This commit is contained in:
jqtmviyu 2025-04-24 11:36:39 +08:00
parent a5b238654d
commit 4271a7a5dd
6 changed files with 44 additions and 17 deletions

View File

@ -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)
// //

View File

@ -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,

View File

@ -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>

View File

@ -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',

View File

@ -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
View 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
}