feat:"完成页面接口的对接"

This commit is contained in:
2026-01-29 17:58:19 +08:00
parent 2774a539bf
commit 2b69da3c15
98 changed files with 9504 additions and 592 deletions

View File

@@ -55,7 +55,7 @@
<script setup lang="uts">
import { getCaseList } from '@/api/index.uts'
import { SOFA_CATEGORIES, PAGE_SIZE } from '@/utils/config.uts'
import { SOFA_CATEGORIES, PAGE_SIZE, getServiceTypeName } from '@/utils/config.uts'
// 分类类型
type CategoryItem = {
@@ -111,6 +111,7 @@
page.value = 1
caseList.value = []
noMore.value = false
console.log(111)
fetchCaseList()
}
@@ -121,43 +122,56 @@
loading.value = true
try {
const params = {
category: currentCategory.value,
serviceType: currentCategory.value != 'all' ? currentCategory.value : undefined,
page: page.value,
pageSize: PAGE_SIZE
limit: PAGE_SIZE,
status: 'published'
} as UTSJSONObject
const res = await getCaseList(params)
const data = res.data as UTSJSONObject
// 适应后端返回格式:{ items: [], total: 0, page: 1, limit: 10 }
const list = data['items'] as UTSJSONObject[] || []
total.value = data['total'] as number || 0
const newList = list.map((item) : CaseItem => {
return {
id: item['id'] as string,
title: item['title'] as string,
category: item['category'] as string,
categoryName: item['categoryName'] as string,
coverImage: item['coverImage'] as string,
material: item['material'] as string,
duration: item['duration'] as string,
price: item['price'] as string,
views: item['views'] as number,
likes: item['likes'] as number
} as CaseItem
})
if (page.value == 1) {
caseList.value = newList
} else {
caseList.value = [...caseList.value, ...newList]
}
if (caseList.value.length >= total.value) {
noMore.value = true
if (res.code == 0 && res.data != null) {
const data = res.data as UTSJSONObject
// 适应后端返回格式:{ list: [], total: 0, page: 1, pageSize: 10 }
const list = data['list'] as UTSJSONObject[] || []
total.value = data['total'] as number || 0
const newList = list.map((item) : CaseItem => {
// 优先使用images其次afterImages最后beforeImages
const images = item['images'] as string[] || []
const afterImages = item['afterImages'] as string[] || []
const beforeImages = item['beforeImages'] as string[] || []
const coverImage = images.length > 0 ? images[0] : (afterImages.length > 0 ? afterImages[0] : (beforeImages.length > 0 ? beforeImages[0] : ''))
return {
id: String(item['id']),
title: item['title'] as string,
category: item['serviceType'] as string,
categoryName: getServiceTypeName(item['serviceType'] as string),
coverImage: coverImage,
material: item['materials'] as string || '暂无',
duration: (item['duration'] as number || 0) + '天',
price: item['price'] != null ? '¥' + item['price'] : '面议',
views: item['views'] as number || 0,
likes: item['likes'] as number || 0
} as CaseItem
})
if (page.value == 1) {
caseList.value = newList
} else {
caseList.value = [...caseList.value, ...newList]
}
if (caseList.value.length >= total.value) {
noMore.value = true
}
}
} catch (e) {
console.error('获取案例列表失败', e)
uni.showToast({
title: '加载失败',
icon: 'none'
})
}
loading.value = false
}