fix: 修复api.js文件,恢复测算结果页面数据
- 恢复api.js文件并添加userApi - 更新测算页面添加金币检查逻辑
This commit is contained in:
1 parent
e3f2f5f149
commit
624afe92e0
1 file changed
+314
-26
@@ -1,31 +1,319 @@
|
||||
/**
|
||||
* 检查金币并消耗
|
||||
* @param {callback} 消耗后的回调
|
||||
* @param {showModal} 是否显示弹窗
|
||||
* @param {title} 标题
|
||||
* @param {content} 内容
|
||||
* @param {confirmText} 确认按钮文字
|
||||
uni.navigateTo({ url: '/pages/mine/coins' })
|
||||
}
|
||||
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) {
|
||||
resolve(res.data)
|
||||
} 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: {
|
||||
userId: data.userId || 'default_user',
|
||||
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
|
||||
}
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
coins -= 1
|
||||
uni.setStorageSync('userCoins', coins)
|
||||
|
||||
try {
|
||||
const userInfoStr = uni.getStorageSync('userInfo')
|
||||
if (userInfoStr) {
|
||||
const userInfo = JSON.parse(userInfoStr)
|
||||
await api.userApi.updateCoins(userInfo.userId, coins)
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('更新金币失败:', e)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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: 'POST',
|
||||
data: { id: id }
|
||||
})
|
||||
},
|
||||
clear: (userId) => {
|
||||
return request({
|
||||
url: '/records/clear',
|
||||
method: 'POST',
|
||||
data: { userId: userId || 'default_user' }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const toolApi = {
|
||||
lunar: (data) => {
|
||||
return request({
|
||||
url: '/tools/lunar',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
},
|
||||
ganzhi: (data) => {
|
||||
return request({
|
||||
url: '/tools/ganzhi',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
},
|
||||
shengxiao: (data) => {
|
||||
return request({
|
||||
url: '/tools/shengxiao',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
},
|
||||
xingzuo: (data) => {
|
||||
return request({
|
||||
url: '/tools/xingzuo',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
},
|
||||
wuxing: (data) => {
|
||||
return request({
|
||||
url: '/tools/wuxing',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
},
|
||||
jiri: (data) => {
|
||||
return request({
|
||||
url: '/tools/jiri',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
const userApi = {
|
||||
loginOrRegister: (data) => {
|
||||
return request({
|
||||
url: '/user/login',
|
||||
method: 'POST',
|
||||
data: data
|
||||
})
|
||||
},
|
||||
getUserInfo: (userId) => {
|
||||
return request({
|
||||
url: '/user/info',
|
||||
method: 'GET',
|
||||
data: { userId: userId }
|
||||
})
|
||||
},
|
||||
updateVipLevel: (userId, vipLevel) => {
|
||||
return request({
|
||||
url: '/user/vip',
|
||||
method: 'POST',
|
||||
data: { userId: userId, vipLevel: vipLevel }
|
||||
})
|
||||
},
|
||||
updateCoins: (userId, coins) => {
|
||||
return request({
|
||||
url: '/user/coins',
|
||||
method: 'POST',
|
||||
data: { userId: userId, coins: coins }
|
||||
})
|
||||
},
|
||||
updatePhone: (userId, phone) => {
|
||||
return request({
|
||||
url: '/user/phone',
|
||||
method: 'POST',
|
||||
data: { userId: userId, phone: phone }
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export default {
|
||||
baziApi,
|
||||
liuyaoApi,
|
||||
daliurenApi,
|
||||
qimenApi,
|
||||
ziweiApi,
|
||||
zhanxingApi,
|
||||
taLuoApi,
|
||||
recordApi,
|
||||
toolApi,
|
||||
userApi,
|
||||
request
|
||||
}
|
||||
Reference in new issue
Block a user