Files
ShaFaFanXin/前端/api/index.uts

192 lines
4.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
* API接口统一管理
*/
import { get, post } from '../utils/request.uts'
/**
* 获取轮播图 (临时从配置获取,后续可从后端获取)
*/
export const getBanners = () => {
// 由于后端暂时没有轮播图API先返回固定数据
return Promise.resolve({
code: 0,
message: 'success',
data: [
{
id: '1',
image: '/static/mock/banner1.svg',
title: '专业沙发翻新服务',
link: '/pages/service/index'
},
{
id: '2',
image: '/static/mock/banner2.svg',
title: '十年品质保证',
link: '/pages/about/index'
},
{
id: '3',
image: '/static/mock/banner3.svg',
title: '免费上门评估',
link: '/pages/booking/index'
}
]
})
}
/**
* 获取案例列表
*/
export const getCaseList = (params ?: UTSJSONObject) => {
// 后端使用page和limit参数需要转换
const queryParams : UTSJSONObject = {
page: params ? (params['page'] || 1) : 1,
limit: params ? (params['pageSize'] || params['limit'] || 10) : 10,
status: 'published' // 只获取已发布的案例
}
// 如果有分类且不是all则添加serviceType参数
if (params && params['category'] && params['category'] != 'all') {
queryParams['serviceType'] = params['category']
}
return get('/cases', queryParams)
}
/**
* 获取案例详情
*/
export const getCaseDetail = (id : string) => {
return get(`/cases/${id}`)
}
/**
* 获取热门案例 (临时使用前4条案例)
*/
export const getHotCases = () => {
return get('/cases', { limit: 4, status: 'published' } as UTSJSONObject)
}
/**
* 获取服务流程 (使用服务列表替代)
*/
export const getServiceProcess = () => {
return get('/services')
}
/**
* 获取有效服务列表
*/
export const getActiveServices = () => {
return get('/services/active')
}
/**
* 获取公司信息(暂时返回固定数据,后续可对接后端)
*/
export const getCompanyInfo = () => {
return Promise.resolve({
code: 0,
message: 'success',
data: {
name: '优艺家沙发翻新',
slogan: '让旧沙发焕发新生',
description: '优艺家专注沙发翻新服务10余年拥有专业的技术团队和丰富的经验。我们提供各类沙发翻新、维修、清洁服务让您的旧沙发重新焕发光彩。',
phone: '400-888-8888',
wechat: 'youyijia2024',
address: '北京市朝阳区XX路XX号',
workTime: '周一至周日 9:00-18:00',
features: [
{ title: '专业团队', desc: '10年以上经验的专业师傅' },
{ title: '品质保证', desc: '使用优质材料,质保一年' },
{ title: '免费上门', desc: '免费上门测量和评估' },
{ title: '快速交付', desc: '3-7天完成翻新服务' }
]
}
})
}
/**
* 提交预约
*/
export const submitBooking = (data : UTSJSONObject) => {
return post('/booking', data)
}
/**
* 获取我的预约列表
*/
export const getMyBookings = (params ?: UTSJSONObject) => {
const queryParams = params ? {
page: params['page'] || 1,
limit: params['limit'] || 10,
status: params['status']
} : {}
return get('/booking/my', queryParams as UTSJSONObject)
}
/**
* 获取预约详情
*/
export const getBookingDetail = (id : string) => {
return get(`/booking/${id}`)
}
/**
* 取消预约
*/
export const cancelBooking = (id : string) => {
return post(`/booking/${id}/cancel`, {} as UTSJSONObject)
}
/**
* 获取用户信息
*/
export const getUserInfo = () => {
return get('/users/profile')
}
/**
* 微信登录
*/
export const wechatLogin = (code : string) => {
return post('/auth/wechat/login', { code: code } as UTSJSONObject)
}
/**
* 微信手机号登录
*/
export const wechatPhoneLogin = (code : string, encryptedData : string, iv : string) => {
return post('/auth/wechat/phone', {
code: code,
encryptedData: encryptedData,
iv: iv
} as UTSJSONObject)
}
/**
* 获取用户收藏列表
*/
export const getFavorites = () => {
return get('/user/favorites')
}
/**
* 添加收藏
*/
export const addFavorite = (caseId : string) => {
return post('/user/favorites', { caseId: caseId } as UTSJSONObject)
}
/**
* 取消收藏
*/
export const removeFavorite = (caseId : string) => {
return post('/user/favorites/remove', { caseId: caseId } as UTSJSONObject)
}
/**
* 获取预约记录
*/
export const getBookingList = () => {
return get('/user/bookings')
}