feat: 所有测算模块添加金币消耗功能,每次测算消耗1金币

This commit is contained in:
H1d3rOne committed 2026-03-08 10:07:27 +08:00
1 parent d6d86c4401
commit b1ba066267
11 files changed
+394 -64

No files matched your search

@@ -91,6 +91,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -113,6 +114,11 @@ export default {
async calculate() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.name || this.name.trim() === '') {
uni.showToast({
title: '请输入姓名',
@@ -206,8 +212,41 @@ export default {
console.log('保存到globalData之后')
console.log('getApp().globalData.baziResult:', getApp().globalData.baziResult)
console.log('=== 开始保存测算记录 ===')
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
console.log('用户信息:', userInfo)
const saveResult = await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'bazi',
name: this.name.trim(),
sex: this.gender === '男' ? 1 : 0,
inputDate: dateStr,
inputData: JSON.stringify(payload),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('保存记录结果:', saveResult)
if (saveResult && saveResult.success) {
console.log('测算记录保存成功')
} else {
console.error('测算记录保存失败:', saveResult)
}
} catch (e) {
console.error('保存测算记录异常:', e)
}
console.log('=== 保存测算记录结束 ===')
console.log('准备跳转到结果页面')
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/bazi/result'
})
@@ -115,6 +115,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -139,6 +140,11 @@ export default {
async calculate() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.name || this.name.trim() === '') {
uni.showToast({
title: '请输入姓名',
@@ -194,10 +200,40 @@ export default {
guiRenType: this.guiRenType
})
getApp().globalData.daliurenResult = result.data || result
const resultData = result.data || result
getApp().globalData.daliurenResult = resultData
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'daliuren',
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
inputDate: dateStr,
inputData: JSON.stringify({
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
date: dateStr,
dateType: this.dateType,
guiRenType: this.guiRenType
}),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('测算记录保存成功')
} catch (e) {
console.error('保存测算记录失败:', e)
}
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/daliuren/result'
})
@@ -6,7 +6,7 @@
<text class="sex">{{ result.sex }}</text>
</view>
<view class="date-row">
<text class="date-text">{{ result.solar }}</text>
<text class="date-text">{{ formatSolarTime }}</text>
</view>
<view class="date-row">
<text class="date-text">{{ result.lunar }}</text>
@@ -229,6 +229,27 @@ export default {
markdownHtml() {
if (!this.result.aiAnalysis) return ''
return markdownToHtml(this.result.aiAnalysis)
},
formatSolarTime() {
if (this.result.solar) {
let time = this.result.solar
if (time.includes(':')) {
const parts = time.split(' ')
if (parts.length === 2) {
const datePart = parts[0]
const timePart = parts[1]
const timeComponents = timePart.split(':')
if (timeComponents.length >= 2) {
return `${datePart} ${timeComponents[0]}:${timeComponents[1]}`
}
}
}
if (time.includes('秒')) {
return time.replace(/\d{2}秒$/, '')
}
return time.replace(/:\d{2}$/, '')
}
return '-'
}
},
onLoad() {
+38 -1
View File
@@ -111,6 +111,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -135,6 +136,11 @@ export default {
async calculate() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.name || this.name.trim() === '') {
uni.showToast({
title: '请输入姓名',
@@ -191,10 +197,41 @@ export default {
liuYaoYaoXiang: this.liuYaoYaoXiang
})
getApp().globalData.liuyaoResult = result.data || result
const resultData = result.data || result
getApp().globalData.liuyaoResult = resultData
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'liuyao',
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
inputDate: dateStr,
inputData: JSON.stringify({
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
date: dateStr,
dateType: 0,
paiPanType: this.paiPanType,
liuYaoYaoXiang: this.liuYaoYaoXiang
}),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('测算记录保存成功')
} catch (e) {
console.error('保存测算记录失败:', e)
}
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/liuyao/result'
})
+41 -1
View File
@@ -126,6 +126,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -153,6 +154,11 @@ export default {
async calculate() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.name || this.name.trim() === '') {
uni.showToast({
title: '请输入姓名',
@@ -212,10 +218,44 @@ export default {
shuangShuTwo: this.shuangShuTwo
})
getApp().globalData.meihuaResult = result.data || result
const resultData = result.data || result
getApp().globalData.meihuaResult = resultData
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'meihua',
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
inputDate: dateStr,
inputData: JSON.stringify({
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
date: dateStr,
dateType: 0,
paiPanType: this.paiPanType,
shu: this.shu,
danShu: this.danShu,
shuangShuOne: this.shuangShuOne,
shuangShuTwo: this.shuangShuTwo
}),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('测算记录保存成功')
} catch (e) {
console.error('保存测算记录失败:', e)
}
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/meihua/result'
})
+51 -47
View File
@@ -28,7 +28,7 @@
<view class="ai-card" v-if="result.aiAnalysis">
<view class="card-header">
<view class="card-dot"></view>
<view class="card-dot pink"></view>
<text class="card-title">🤖 AI命理解读</text>
</view>
<view class="ai-content">
@@ -76,30 +76,30 @@
</view>
</view>
<view class="yao-card">
<view class="liuyao-card">
<view class="card-header">
<view class="card-dot"></view>
<text class="card-title">爻象详盘</text>
<view class="card-dot pink"></view>
<text class="card-title">六爻详盘</text>
</view>
<view class="yao-table">
<view class="yao-row yao-header">
<view class="yao-cell header-cell">爻位</view>
<view class="yao-cell header-cell">本卦</view>
<view class="yao-cell header-cell">变卦</view>
<view class="liuyao-table">
<view class="liuyao-row liuyao-header">
<view class="liuyao-cell header-cell">爻位</view>
<view class="liuyao-cell header-cell">本卦</view>
<view class="liuyao-cell header-cell">变卦</view>
</view>
<view v-for="(yao, index) in yaoData" :key="index" class="yao-row">
<view class="yao-cell label-cell">{{ yao.name }}</view>
<view class="yao-cell yao-cell">{{ yao.benYao }}</view>
<view class="yao-cell yao-cell">{{ yao.bianYao }}</view>
<view v-for="(yao, index) in liuYaoData" :key="index" class="liuyao-row">
<view class="liuyao-cell label-cell">{{ yao.benName }}</view>
<view class="liuyao-cell yao-cell">{{ yao.benYao }}</view>
<view class="liuyao-cell yao-cell">{{ yao.bianYao }}</view>
</view>
</view>
</view>
<view class="guaci-card">
<view class="card-header">
<view class="card-dot"></view>
<view class="card-dot pink"></view>
<text class="card-title">卦辞爻辞</text>
</view>
@@ -113,7 +113,7 @@
<text class="guaci-content">{{ result.bianGuaGuaCi || '暂无' }}</text>
</view>
<view class="yaoci-section" v-if="result.benGuaLiuYaoYaoCi && result.benGuaLiuYaoYaoCi.length > 0">
<view class="yaoci-section">
<text class="yaoci-title">本卦爻辞</text>
<view v-for="(yaoCi, index) in result.benGuaLiuYaoYaoCi" :key="index" class="yaoci-item">
<text class="yaoci-name">{{ result.benGuaLiuYaoName[index] }}:</text>
@@ -124,7 +124,7 @@
<view class="extra-card">
<view class="card-header">
<view class="card-dot"></view>
<view class="card-dot pink"></view>
<text class="card-title">其他信息</text>
</view>
@@ -185,13 +185,13 @@ export default {
}
return '-'
},
yaoData() {
liuYaoData() {
if (!this.result.benGuaLiuYaoName || !Array.isArray(this.result.benGuaLiuYaoName)) return []
const data = []
for (let i = 0; i < 6; i++) {
data.push({
name: (this.result.benGuaLiuYaoName && this.result.benGuaLiuYaoName[i]) || '-',
benName: (this.result.benGuaLiuYaoName && this.result.benGuaLiuYaoName[i]) || '-',
benYao: (this.result.benGuaLiuYaoAs && this.result.benGuaLiuYaoAs[i]) || '-',
bianYao: (this.result.bianGuaLiuYaoAs && this.result.bianGuaLiuYaoAs[i]) || '-'
})
@@ -207,7 +207,7 @@ export default {
<style scoped>
page {
background: linear-gradient(180deg, #ecfdf5 0%, #d1fae5 50%, #a7f3d0 100%);
background: linear-gradient(180deg, #FDF2F8 0%, #FCE7F3 50%, #FBCFE8 100%);
min-height: 100vh;
}
@@ -217,11 +217,11 @@ page {
}
.header-card {
background: linear-gradient(135deg, #059669 0%, #047857 100%);
border-radius: 24rpx;
background: linear-gradient(135deg, #f093fb 0%, #f5576c 100%);
border-radius: 32rpx;
padding: 32rpx;
margin-bottom: 24rpx;
box-shadow: 0 8rpx 32rpx rgba(5, 150, 105, 0.3);
box-shadow: 0 16rpx 48rpx rgba(240, 147, 251, 0.25);
}
.header-row {
@@ -268,7 +268,7 @@ page {
border-radius: 24rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 8rpx 32rpx rgba(5, 150, 105, 0.08);
box-shadow: 0 8rpx 32rpx rgba(240, 147, 251, 0.08);
}
.info-row {
@@ -301,26 +301,26 @@ page {
}
.ai-card {
background: rgba(255, 255, 255, 0.9);
background: linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(252, 231, 243, 0.5) 100%);
border-radius: 24rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 8rpx 32rpx rgba(5, 150, 105, 0.08);
border: 2rpx solid #a7f3d0;
box-shadow: 0 8rpx 32rpx rgba(240, 147, 251, 0.08);
border: 2rpx solid #FBCFE8;
}
.ai-content {
padding: 16rpx;
background: #ecfdf5;
background: rgba(255, 255, 255, 0.8);
border-radius: 12rpx;
}
.gua-card, .yao-card, .guaci-card, .extra-card {
.gua-card, .liuyao-card, .guaci-card, .extra-card {
background: rgba(255, 255, 255, 0.9);
border-radius: 24rpx;
padding: 24rpx;
margin-bottom: 24rpx;
box-shadow: 0 8rpx 32rpx rgba(5, 150, 105, 0.08);
box-shadow: 0 8rpx 32rpx rgba(240, 147, 251, 0.08);
}
.card-header {
@@ -332,11 +332,15 @@ page {
.card-dot {
width: 8rpx;
height: 8rpx;
background: #059669;
background: #f093fb;
border-radius: 50%;
margin-right: 12rpx;
}
.card-dot.pink {
background: #f093fb;
}
.card-title {
font-size: 28rpx;
font-weight: 600;
@@ -365,7 +369,7 @@ page {
.gua-symbol {
font-size: 60rpx;
color: #059669;
color: #f093fb;
display: block;
margin-bottom: 10rpx;
}
@@ -388,7 +392,7 @@ page {
}
.gua-grid-item {
background: #ecfdf5;
background: #FDF2F8;
padding: 15rpx;
border-radius: 12rpx;
}
@@ -405,7 +409,7 @@ page {
color: #1F2937;
}
.yao-table {
.liuyao-table {
width: 100%;
overflow-x: auto;
border-radius: 12rpx;
@@ -413,20 +417,20 @@ page {
border: 2rpx solid #F3F4F6;
}
.yao-row {
.liuyao-row {
display: flex;
border-bottom: 2rpx solid #F3F4F6;
}
.yao-row:last-child {
.liuyao-row:last-child {
border-bottom: none;
}
.yao-row.yao-header {
background: #ecfdf5;
.liuyao-row.liuyao-header {
background: #FDF2F8;
}
.yao-cell {
.liuyao-cell {
flex: 1;
min-width: 80rpx;
padding: 16rpx 8rpx;
@@ -435,17 +439,17 @@ page {
color: #1F2937;
}
.yao-cell.header-cell {
.liuyao-cell.header-cell {
font-weight: 600;
color: #059669;
color: #f093fb;
}
.yao-cell.label-cell {
.liuyao-cell.label-cell {
font-weight: 600;
color: #059669;
color: #f093fb;
}
.yao-cell.yao-cell {
.liuyao-cell.yao-cell {
font-size: 28rpx;
font-weight: 700;
color: #1F2937;
@@ -466,7 +470,7 @@ page {
.guaci-title, .yaoci-title {
font-size: 26rpx;
font-weight: 600;
color: #059669;
color: #f093fb;
display: block;
margin-bottom: 12rpx;
}
@@ -480,14 +484,14 @@ page {
.yaoci-item {
margin-bottom: 10rpx;
padding: 12rpx;
background: #ecfdf5;
background: #FDF2F8;
border-radius: 8rpx;
}
.yaoci-name {
font-size: 24rpx;
font-weight: 600;
color: #059669;
color: #f093fb;
}
.yaoci-text {
@@ -502,7 +506,7 @@ page {
}
.extra-item {
background: #ecfdf5;
background: #FDF2F8;
padding: 15rpx;
border-radius: 12rpx;
}
+38 -1
View File
@@ -129,6 +129,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -171,6 +172,11 @@ export default {
async calculate() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.name || this.name.trim() === '') {
uni.showToast({
title: '请输入姓名',
@@ -227,10 +233,41 @@ export default {
zhiShiType: this.zhiShiTypes[this.zhiShiTypeIndex].value
})
getApp().globalData.qimenResult = result.data || result
const resultData = result.data || result
getApp().globalData.qimenResult = resultData
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'qimen',
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
inputDate: dateStr,
inputData: JSON.stringify({
name: this.name || '某人',
occupy: this.occupy || '某事',
sex: this.gender === '男' ? 1 : 0,
date: dateStr,
dateType: this.dateType,
paiPanType: this.paiPanTypes[this.paiPanTypeIndex].value,
zhiShiType: this.zhiShiTypes[this.zhiShiTypeIndex].value
}),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('测算记录保存成功')
} catch (e) {
console.error('保存测算记录失败:', e)
}
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/qimen/result'
})
@@ -57,10 +57,19 @@ export default {
methods: {
async loadRecords() {
try {
console.log('加载测算记录...')
const data = await api.recordApi.getList()
this.records = data || []
console.log('加载记录结果:', data)
if (data && data.success) {
this.records = data.data || []
} else {
this.records = data || []
}
console.log('记录列表:', this.records)
} catch (e) {
console.log('加载记录失败:', e)
console.error('加载记录失败:', e)
this.records = []
}
},
@@ -167,15 +176,26 @@ export default {
success: async (res) => {
if (res.confirm) {
try {
await api.recordApi.delete(id)
this.records.splice(index, 1)
uni.showToast({
title: '删除成功',
icon: 'success'
})
console.log('删除记录ID:', id)
const result = await api.recordApi.delete(id)
console.log('删除结果:', result)
if (result.success) {
this.records.splice(index, 1)
uni.showToast({
title: '删除成功',
icon: 'success'
})
} else {
uni.showToast({
title: result.error || '删除失败',
icon: 'none'
})
}
} catch (e) {
console.error('删除记录失败:', e)
uni.showToast({
title: '删除失败',
title: '删除失败:' + (e.message || '未知错误'),
icon: 'none'
})
}
+32 -1
View File
@@ -57,6 +57,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -78,6 +79,11 @@ export default {
async startDivine() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.question || this.question.trim() === '') {
uni.showToast({
title: '请输入您的问题',
@@ -100,10 +106,35 @@ export default {
spreadType: this.spreadType
})
getApp().globalData.taLuoResult = result.data || result
const resultData = result.data || result
getApp().globalData.taLuoResult = resultData
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'taluo',
name: '塔罗占卜',
occupy: this.question || '请给我指引',
inputDate: new Date().toISOString(),
inputData: JSON.stringify({
question: this.question || '请给我指引',
spreadType: this.spreadType
}),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('测算记录保存成功')
} catch (e) {
console.error('保存测算记录失败:', e)
}
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/taluo/result'
})
@@ -70,6 +70,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -91,6 +92,11 @@ export default {
async calculate() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.name || this.name.trim() === '') {
uni.showToast({
title: '请输入姓名',
@@ -144,10 +150,36 @@ export default {
birthPlace: this.birthPlace || '北京'
})
getApp().globalData.zhanxingResult = result.data || result
const resultData = result.data || result
getApp().globalData.zhanxingResult = resultData
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'zhanxing',
name: this.name || '某人',
inputDate: dateStr,
inputData: JSON.stringify({
name: this.name || '某人',
date: dateStr,
birthTime: this.birthTime,
birthPlace: this.birthPlace || '北京'
}),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('测算记录保存成功')
} catch (e) {
console.error('保存测算记录失败:', e)
}
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/zhanxing/result'
})
+34 -1
View File
@@ -91,6 +91,7 @@
<script>
import api from '@/utils/api.js'
import coinUtils from '@/utils/coinUtils.js'
export default {
data() {
@@ -113,6 +114,11 @@ export default {
async calculate() {
if (this.loading) return
const checkResult = coinUtils.checkCoinsAndConsume()
if (!checkResult.canUse) {
return
}
if (!this.name || this.name.trim() === '') {
uni.showToast({
title: '请输入姓名',
@@ -157,10 +163,37 @@ export default {
dateType: this.dateType
})
getApp().globalData.ziweiResult = result.data || result
const resultData = result.data || result
getApp().globalData.ziweiResult = resultData
try {
const userInfoStr = uni.getStorageSync('userInfo')
const userInfo = userInfoStr ? JSON.parse(userInfoStr) : null
await api.recordApi.save({
userId: userInfo?.userId || 'default_user',
type: 'ziwei',
name: this.name || '某人',
sex: this.gender === '男' ? 1 : 0,
inputDate: dateStr,
inputData: JSON.stringify({
name: this.name || '某人',
sex: this.gender === '男' ? 1 : 0,
date: dateStr,
dateType: this.dateType
}),
resultData: JSON.stringify(resultData),
aiAnalysis: resultData.aiAnalysis || ''
})
console.log('测算记录保存成功')
} catch (e) {
console.error('保存测算记录失败:', e)
}
uni.hideLoading()
await coinUtils.consumeCoin()
uni.navigateTo({
url: '/pages/ziwei/result'
})