pray动态第一版

This commit is contained in:
minimaxagent1 2025-08-05 14:29:08 +08:00
parent ebddc7168d
commit bafeb4736f
3 changed files with 128 additions and 63 deletions

49
api/pray/pray.js Normal file
View File

@ -0,0 +1,49 @@
import request from '@/utils/request'
/**
* 提交祈福
* @param {Object} data 祈福数据
* @param {string} data.name 祈福人姓名
* @param {string} data.type 祈福类型值 (1-学业, 2-健康, 3-姻缘, 4-财运, 5-消灾)
* @param {string} data.isOthers 是否为他人祈福 (1-, 2-)
* @param {string} data.content 心愿内容
* @returns {Promise} API响应
*/
export function submitPrayer(data) {
return request({
url: '/app/pray',
method: 'POST',
data: {
name: String(data.name || ''),
type: String(data.type || ''),
isOthers: String(data.isOthers || ''),
content: String(data.content || '')
}
})
}
/**
* 获取祈福列表如果需要的话
* @param {Object} params 查询参数
* @returns {Promise} API响应
*/
export function getPrayerList(params = {}) {
return request({
url: '/app/pray/list',
method: 'GET',
params: params
})
}
/**
* 获取祈福详情如果需要的话
* @param {string} id 祈福ID
* @returns {Promise} API响应
*/
export function getPrayerDetail(id) {
return request({
url: '/app/pray/detail',
method: 'GET',
params: { id: id }
})
}

View File

@ -38,17 +38,17 @@
<view class="form-item"> <view class="form-item">
<text class="label">为他人祈福</text> <text class="label">为他人祈福</text>
<view class="radio-group"> <view class="radio-group">
<view class="radio-item" @click="formData.forOthers = true"> <view class="radio-item" @click="formData.forOthers = 1">
<text class="radio-text"></text> <text class="radio-text"></text>
<view class="radio-button" :class="{ 'checked': formData.forOthers }"> <view class="radio-button" :class="{ 'checked': formData.forOthers === 1 }">
<text v-if="formData.forOthers" class="checkmark"></text> <text v-if="formData.forOthers === 1" class="checkmark"></text>
</view> </view>
</view> </view>
<view class="radio-item" @click="formData.forOthers = false"> <view class="radio-item" @click="formData.forOthers = 2">
<text class="radio-text"></text> <text class="radio-text"></text>
<view class="radio-button" :class="{ 'checked': !formData.forOthers }"> <view class="radio-button" :class="{ 'checked': formData.forOthers === 2 }">
<text v-if="!formData.forOthers" class="checkmark"></text> <text v-if="formData.forOthers === 2" class="checkmark"></text>
</view> </view>
</view> </view>
@ -82,6 +82,7 @@
<script> <script>
import CommonEnum from "../../enum/common"; import CommonEnum from "../../enum/common";
import CustomNavbar from "../../components/custom-navbar/custom-navbar.vue"; import CustomNavbar from "../../components/custom-navbar/custom-navbar.vue";
import { submitPrayer } from "@/api/pray/pray";
export default { export default {
components: { components: {
@ -93,12 +94,19 @@ export default {
loading: false, loading: false,
formData: { formData: {
name: '', name: '',
prayerType: '个人祈福', // prayerType: '1', //
forOthers: false, // forOthers: 2, //
wish: '' wish: ''
}, },
prayerTypes: ['学业', '健康', '姻缘', '财运', '消灾'], prayerTypes: [
{ label: '学业', value: 1 },
{ label: '健康', value: 2 },
{ label: '姻缘', value: 3 },
{ label: '财运', value: 4 },
{ label: '消灾', value: 5 }
],
selectedPrayerType: '学业', selectedPrayerType: '学业',
selectedPrayerTypeValue: 1,
showPicker: false showPicker: false
} }
}, },
@ -126,62 +134,74 @@ export default {
// //
submitPrayer() { submitPrayer() {
// //
if (!this.formData.name.trim()) { if (!this.validateForm()) {
uni.showToast({ return;
title: '请输入祈福人姓名',
icon: 'none'
})
return
}
if (!this.formData.wish.trim()) {
uni.showToast({
title: '请填写心愿内容',
icon: 'none'
})
return
} }
// //
this.showConfirmation();
},
//
validateForm() {
if (!this.formData.name?.trim()) {
uni.showToast({ title: '请输入祈福人姓名', icon: 'none' });
return false;
}
if (!this.selectedPrayerTypeValue) {
uni.showToast({ title: '请选择祈福类型', icon: 'none' });
return false;
}
if (!this.formData.wish?.trim()) {
uni.showToast({ title: '请填写心愿内容', icon: 'none' });
return false;
}
return true;
},
//
showConfirmation() {
uni.showModal({ uni.showModal({
title: '确认祈福信息', title: '确认祈福信息',
content: `祈福人:${this.formData.name}\n祈福类型${this.selectedPrayerType}\n为他人祈福${this.formData.forOthers ? '是' : '否'}\n心愿内容${this.formData.wish}`, content: `祈福人:${this.formData.name}\n祈福类型${this.selectedPrayerType}\n为他人祈福${this.formData.forOthers === 1 ? '是' : '否'}\n心愿内容${this.formData.wish}`,
confirmText: '确认敬香', confirmText: '确认敬香',
cancelText: '修改信息', cancelText: '修改信息',
success: (res) => { success: (res) => {
if (res.confirm) { if (res.confirm) {
this.performPrayer() this.performPrayer();
} }
} }
}) });
}, },
// //
async performPrayer() { async performPrayer() {
uni.showLoading({ uni.showLoading({ title: '正在敬香...' });
title: '正在敬香...'
})
try { try {
// API const response = await submitPrayer({
await new Promise(resolve => setTimeout(resolve, 2000)) name: this.formData.name.trim(),
type: this.selectedPrayerTypeValue,
isOthers: this.formData.forOthers,
content: this.formData.wish.trim()
});
uni.hideLoading() uni.hideLoading();
uni.showToast({
title: '祈福成功!',
icon: 'success',
duration: 2000
})
// if (response.code === 200) {
this.resetForm() uni.showToast({ title: '祈福成功!', icon: 'success' });
this.resetForm();
} else {
uni.showToast({ title: response.msg || '祈福失败,请重试', icon: 'none' });
}
} catch (error) { } catch (error) {
uni.hideLoading() console.error('祈福请求失败:', error);
uni.showToast({ uni.hideLoading();
title: '祈福失败,请重试', uni.showToast({ title: '网络错误,请重试', icon: 'none' });
icon: 'none'
})
} }
}, },
@ -189,38 +209,28 @@ export default {
resetForm() { resetForm() {
this.formData = { this.formData = {
name: '', name: '',
prayerType: '学业', prayerType: '1',
forOthers: false, forOthers: 2,
wish: '' wish: ''
} }
this.selectedPrayerType = '学业' this.selectedPrayerType = '学业'
this.selectedPrayerTypeValue = 1
}, },
// //
showPrayerTypePicker() { showPrayerTypePicker() {
console.log('开始显示祈福类型选择器');
console.log('可选项:', this.prayerTypes);
uni.showActionSheet({ uni.showActionSheet({
itemList: this.prayerTypes, itemList: this.prayerTypes.map(item => item.label),
success: (res) => { success: (res) => {
console.log('选择器回调参数:', res);
console.log('选择的索引:', res.tapIndex);
if (res.tapIndex !== undefined && res.tapIndex >= 0 && res.tapIndex < this.prayerTypes.length) { if (res.tapIndex !== undefined && res.tapIndex >= 0 && res.tapIndex < this.prayerTypes.length) {
const selectedType = this.prayerTypes[res.tapIndex]; const selectedType = this.prayerTypes[res.tapIndex];
console.log('选择的祈福类型:', selectedType);
// //
this.selectedPrayerType = selectedType; this.selectedPrayerType = selectedType.label;
this.selectedPrayerTypeValue = selectedType.value;
// //
this.formData.prayerType = selectedType; this.formData.prayerType = selectedType.value;
console.log('更新后的selectedPrayerType:', this.selectedPrayerType);
console.log('更新后的formData.prayerType:', this.formData.prayerType);
} else {
console.error('无效的选择索引:', res.tapIndex);
} }
}, },
fail: (res) => { fail: (res) => {

View File

@ -17,7 +17,7 @@ import {
// 环境配置 // 环境配置
const ENV_CONFIG = { const ENV_CONFIG = {
develop: { // 开发环境 develop: { // 开发环境
baseUrl: 'http://192.168.2.112:4501', baseUrl: 'http://192.168.2.136:4501',
}, },
trial: { // 体验版 trial: { // 体验版
baseUrl: 'https://testlu.chuangtewl.com/prod-api', baseUrl: 'https://testlu.chuangtewl.com/prod-api',
@ -54,7 +54,13 @@ console.log('HTTP配置:', {
* @returns {Object} 请求头对象 * @returns {Object} 请求头对象
*/ */
function getRequestHeaders(customHeader = {}) { function getRequestHeaders(customHeader = {}) {
const token = uni.getStorageSync('token') let token = uni.getStorageSync('token')
// 开发环境使用临时token
if (shouldUseTempToken() && !token) {
token = getTempToken()
}
let authorization = token let authorization = token
// 平台差异化处理 // 平台差异化处理