// utils/api.js - uniapp API 封装 const BASE_URL = 'http://localhost:8080/api' // 统一请求封装 const request = (options) => { return new Promise((resolve, reject) => { uni.request({ url: BASE_URL + options.url, method: options.method || 'GET', data: options.data || {}, header: options.header || { 'Content-Type': 'application/json' }, success: (res) => { if (res.statusCode === 200) { resolve(res.data) } else { reject(res) } }, fail: (err) => { reject(err) } }) }) } const get = (url, params = {}) => { return request({ url, method: 'GET', data: params }) } const post = (url, data = {}) => { return request({ url, method: 'POST', data }) } const put = (url, data = {}) => { return request({ url, method: 'PUT', data }) } const del = (url) => { return request({ url, method: 'DELETE' }) } // 图片完整URL export const imgUrl = (path) => { if (!path) return '' if (path.startsWith('http')) return path return `http://localhost:8080${path}` } // 发送验证码 export const sendSms = (phone) => post('/sms/send', { phone }) // 登录 export const login = (phone, code) => post('/user/login', { phone, code }) // 注册老板 export const registerBoss = (data) => post('/user/register-boss', data) // 注册员工 export const registerStaff = (data) => post('/user/register-staff', data) // 预约列表 export const getAppointmentList = (userId) => get('/appointment/list', { userId }) // 创建预约 export const createAppointment = (data) => post('/appointment/create', data) // 开始服务 export const startAppointment = (appointmentId, staffUserId) => post('/appointment/start', { appointmentId, staffUserId }) // 取消预约 export const cancelAppointment = (id) => put(`/appointment/status?id=${id}&status=cancel`) // 提交报告 export const createReport = (data) => post('/report/create', data) // 获取报告(通过token) export const getReportByToken = (token) => get('/report/get', { token }) // 报告列表 export const getReportList = (params) => get('/report/list', params) // 服务类型列表 export const getServiceTypeList = (storeId) => get('/service-type/list', { storeId }) // 创建服务类型 export const createServiceType = (storeId, name) => post('/service-type/create', { storeId, name }) // 删除服务类型 export const deleteServiceType = (id) => del(`/service-type/delete?id=${id}`) // 员工列表 export const getStaffList = (storeId) => get('/user/staff-list', { storeId }) // 添加员工 export const createStaff = (data) => post('/user/create-staff', data) // 删除员工 export const deleteStaff = (staffId) => del(`/user/staff?staffId=${staffId}`) // 更新店铺 export const updateStore = (data) => put('/store/update', data) // 上传图片(uniapp版) export const uploadImage = (filePath) => { return new Promise((resolve, reject) => { uni.uploadFile({ url: BASE_URL + '/upload/image', filePath: filePath, name: 'file', success: (res) => { try { const data = JSON.parse(res.data) resolve(data) } catch (e) { reject(e) } }, fail: (err) => reject(err) }) }) }