Files
xuan-deduct/xuan-deduct-uniapp/src/utils/api.js
T
xuan-bot 91a14ca6d1 feat: 完成记录功能开发
- 添加保存记录API到RecordController
- 修复DeductRecordRepository的HQL语法错误
- 更新前端api.js添加记录API
- 更新八字结果页面保存测算记录
- 完善记录列表页面显示历史记录
2026-03-07 23:50:38 +08:00

238 lines
5.8 KiB
JavaScript

const BASE_URL = 'http://111.230.17.217: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: {
'Content-Type': 'application/json',
...options.header
},
timeout: 30000,
success: (res) => {
if (res.statusCode === 200) {
if (res.data.success) {
resolve(res.data.data)
} else {
reject(new Error(res.data.error || '请求失败'))
}
} else {
reject(new Error('网络请求失败: ' + res.statusCode))
}
},
fail: (err) => {
reject(new Error(err.errMsg || '网络连接失败'))
}
})
})
}
const baziApi = {
paiPan: (data) => {
return request({
url: '/bazi/paipan',
method: 'POST',
data: {
name: data.name || '某人',
sex: data.sex || 1,
date: data.date,
dateType: data.dateType || 0,
leapMonthType: data.leapMonthType || 0,
xuShiSuiType: data.xuShiSuiType || 0,
jieQiType: data.jieQiType || 1,
qiYunLiuPaiType: data.qiYunLiuPaiType || 0,
renYuanType: data.renYuanType || 0,
daYunLunShu: data.daYunLunShu || 10,
yearGanZhiType: data.yearGanZhiType || 2,
monthGanZhiType: data.monthGanZhiType || 1,
dayGanZhiType: data.dayGanZhiType || 0
}
})
}
}
const liuyaoApi = {
paiPan: (data) => {
return request({
url: '/liuyao/paipan',
method: 'POST',
data: {
name: data.name || '某人',
occupy: data.occupy || '某事',
sex: data.sex || 1,
date: data.date,
dateType: data.dateType || 0,
leapMonthType: data.leapMonthType || 0,
xuShiSuiType: data.xuShiSuiType || 0,
jieQiType: data.jieQiType || 1,
yearGanZhiType: data.yearGanZhiType || 2,
monthGanZhiType: data.monthGanZhiType || 1,
dayGanZhiType: data.dayGanZhiType || 0,
paiPanType: data.paiPanType || 0,
liuYaoYaoXiang: data.liuYaoYaoXiang || '—,—,--,--,--,—'
}
})
}
}
const daliurenApi = {
paiPan: (data) => {
return request({
url: '/daliuren/paipan',
method: 'POST',
data: {
name: data.name || '某人',
occupy: data.occupy || '某事',
sex: data.sex || 1,
date: data.date,
dateType: data.dateType || 0,
leapMonthType: data.leapMonthType || 0,
xuShiSuiType: data.xuShiSuiType || 0,
jieQiType: data.jieQiType || 1,
guiRenType: data.guiRenType || 0,
yearGanZhiType: data.yearGanZhiType || 2,
monthGanZhiType: data.monthGanZhiType || 1,
dayGanZhiType: data.dayGanZhiType || 0
}
})
}
}
const qimenApi = {
paiPan: (data) => {
return request({
url: '/qimen/paipan',
method: 'POST',
data: {
name: data.name || '某人',
occupy: data.occupy || '某事',
sex: data.sex || 1,
date: data.date,
dateType: data.dateType || 0,
leapMonthType: data.leapMonthType || 0,
xuShiSuiType: data.xuShiSuiType || 0,
jieQiType: data.jieQiType || 1,
paiPanType: data.paiPanType || 3,
zhiShiType: data.zhiShiType || 0,
yueJiaQiJuType: data.yueJiaQiJuType || 1,
yearGanZhiType: data.yearGanZhiType || 2,
monthGanZhiType: data.monthGanZhiType || 1,
dayGanZhiType: data.dayGanZhiType || 0
}
})
}
}
const ziweiApi = {
paiPan: (data) => {
return request({
url: '/ziwei/paipan',
method: 'POST',
data: {
name: data.name || '某人',
occupy: data.occupy || '某事',
sex: data.sex || 1,
date: data.date,
dateType: data.dateType || 0,
leapMonthType: data.leapMonthType || 0,
xuShiSuiType: data.xuShiSuiType || 0,
jieQiType: data.jieQiType || 1,
wuXingJuType: data.wuXingJuType || 0,
yearGanZhiType: data.yearGanZhiType || 2,
monthGanZhiType: data.monthGanZhiType || 1,
dayGanZhiType: data.dayGanZhiType || 0
}
})
}
}
const zhanxingApi = {
paiPan: (data) => {
return request({
url: '/zhanxing/paipan',
method: 'POST',
data: {
name: data.name || '某人',
date: data.date,
birthTime: data.birthTime || '12:00',
birthPlace: data.birthPlace || '北京'
}
})
}
}
const taLuoApi = {
divine: (data) => {
return request({
url: '/taluo/divine',
method: 'POST',
data: {
question: data.question || '请给我指引',
spreadType: data.spreadType || 'single'
}
})
}
}
const recordApi = {
save: (data) => {
return request({
url: '/records/save',
method: 'POST',
data: {
userId: data.userId || 'default_user',
type: data.type,
name: data.name,
occupy: data.occupy,
sex: data.sex,
inputDate: data.inputDate,
inputData: data.inputData,
resultData: data.resultData,
aiAnalysis: data.aiAnalysis
}
})
},
getList: (userId) => {
return request({
url: '/records/list',
method: 'GET',
data: { userId: userId || 'default_user' }
})
},
getDetail: (id) => {
return request({
url: '/records/detail',
method: 'GET',
data: { id: id }
})
},
delete: (id) => {
return request({
url: '/records/delete',
method: 'DELETE',
data: { id: id }
})
},
clear: (userId) => {
return request({
url: '/records/clear',
method: 'DELETE',
data: { userId: userId || 'default_user' }
})
}
}
export default {
baziApi,
liuyaoApi,
daliurenApi,
qimenApi,
ziweiApi,
zhanxingApi,
taLuoApi,
recordApi,
request
}