pray动态第一版
This commit is contained in:
parent
ebddc7168d
commit
bafeb4736f
49
api/pray/pray.js
Normal file
49
api/pray/pray.js
Normal 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 }
|
||||
})
|
||||
}
|
||||
|
|
@ -38,17 +38,17 @@
|
|||
<view class="form-item">
|
||||
<text class="label">为他人祈福</text>
|
||||
<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>
|
||||
<view class="radio-button" :class="{ 'checked': formData.forOthers }">
|
||||
<text v-if="formData.forOthers" class="checkmark">✓</text>
|
||||
<view class="radio-button" :class="{ 'checked': formData.forOthers === 1 }">
|
||||
<text v-if="formData.forOthers === 1" class="checkmark">✓</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
<view class="radio-item" @click="formData.forOthers = false">
|
||||
<view class="radio-item" @click="formData.forOthers = 2">
|
||||
<text class="radio-text">否</text>
|
||||
<view class="radio-button" :class="{ 'checked': !formData.forOthers }">
|
||||
<text v-if="!formData.forOthers" class="checkmark">✓</text>
|
||||
<view class="radio-button" :class="{ 'checked': formData.forOthers === 2 }">
|
||||
<text v-if="formData.forOthers === 2" class="checkmark">✓</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
|
|
@ -82,6 +82,7 @@
|
|||
<script>
|
||||
import CommonEnum from "../../enum/common";
|
||||
import CustomNavbar from "../../components/custom-navbar/custom-navbar.vue";
|
||||
import { submitPrayer } from "@/api/pray/pray";
|
||||
|
||||
export default {
|
||||
components: {
|
||||
|
|
@ -93,12 +94,19 @@ export default {
|
|||
loading: false,
|
||||
formData: {
|
||||
name: '',
|
||||
prayerType: '个人祈福', // 默认祈福类型
|
||||
forOthers: false, // 默认不为他人祈福
|
||||
prayerType: '1', // 默认祈福类型
|
||||
forOthers: 2, // 默认不为他人祈福
|
||||
wish: ''
|
||||
},
|
||||
prayerTypes: ['学业', '健康', '姻缘', '财运', '消灾'],
|
||||
prayerTypes: [
|
||||
{ label: '学业', value: 1 },
|
||||
{ label: '健康', value: 2 },
|
||||
{ label: '姻缘', value: 3 },
|
||||
{ label: '财运', value: 4 },
|
||||
{ label: '消灾', value: 5 }
|
||||
],
|
||||
selectedPrayerType: '学业',
|
||||
selectedPrayerTypeValue: 1,
|
||||
showPicker: false
|
||||
}
|
||||
},
|
||||
|
|
@ -126,62 +134,74 @@ export default {
|
|||
// 提交祈福
|
||||
submitPrayer() {
|
||||
// 表单验证
|
||||
if (!this.formData.name.trim()) {
|
||||
uni.showToast({
|
||||
title: '请输入祈福人姓名',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (!this.formData.wish.trim()) {
|
||||
uni.showToast({
|
||||
title: '请填写心愿内容',
|
||||
icon: 'none'
|
||||
})
|
||||
return
|
||||
if (!this.validateForm()) {
|
||||
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({
|
||||
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: '确认敬香',
|
||||
cancelText: '修改信息',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.performPrayer()
|
||||
this.performPrayer();
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
},
|
||||
|
||||
// 执行祈福
|
||||
async performPrayer() {
|
||||
uni.showLoading({
|
||||
title: '正在敬香...'
|
||||
})
|
||||
uni.showLoading({ title: '正在敬香...' });
|
||||
|
||||
try {
|
||||
// 模拟API调用
|
||||
await new Promise(resolve => setTimeout(resolve, 2000))
|
||||
const response = await submitPrayer({
|
||||
name: this.formData.name.trim(),
|
||||
type: this.selectedPrayerTypeValue,
|
||||
isOthers: this.formData.forOthers,
|
||||
content: this.formData.wish.trim()
|
||||
});
|
||||
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '祈福成功!',
|
||||
icon: 'success',
|
||||
duration: 2000
|
||||
})
|
||||
uni.hideLoading();
|
||||
|
||||
// 重置表单
|
||||
this.resetForm()
|
||||
if (response.code === 200) {
|
||||
uni.showToast({ title: '祈福成功!', icon: 'success' });
|
||||
this.resetForm();
|
||||
} else {
|
||||
uni.showToast({ title: response.msg || '祈福失败,请重试', icon: 'none' });
|
||||
}
|
||||
|
||||
} catch (error) {
|
||||
uni.hideLoading()
|
||||
uni.showToast({
|
||||
title: '祈福失败,请重试',
|
||||
icon: 'none'
|
||||
})
|
||||
console.error('祈福请求失败:', error);
|
||||
uni.hideLoading();
|
||||
uni.showToast({ title: '网络错误,请重试', icon: 'none' });
|
||||
}
|
||||
},
|
||||
|
||||
|
|
@ -189,38 +209,28 @@ export default {
|
|||
resetForm() {
|
||||
this.formData = {
|
||||
name: '',
|
||||
prayerType: '学业',
|
||||
forOthers: false,
|
||||
prayerType: '1',
|
||||
forOthers: 2,
|
||||
wish: ''
|
||||
}
|
||||
this.selectedPrayerType = '学业'
|
||||
this.selectedPrayerTypeValue = 1
|
||||
},
|
||||
|
||||
// 显示祈福类型选择器
|
||||
showPrayerTypePicker() {
|
||||
console.log('开始显示祈福类型选择器');
|
||||
console.log('可选项:', this.prayerTypes);
|
||||
|
||||
uni.showActionSheet({
|
||||
itemList: this.prayerTypes,
|
||||
itemList: this.prayerTypes.map(item => item.label),
|
||||
success: (res) => {
|
||||
console.log('选择器回调参数:', res);
|
||||
console.log('选择的索引:', res.tapIndex);
|
||||
|
||||
if (res.tapIndex !== undefined && res.tapIndex >= 0 && res.tapIndex < this.prayerTypes.length) {
|
||||
const selectedType = this.prayerTypes[res.tapIndex];
|
||||
console.log('选择的祈福类型:', selectedType);
|
||||
|
||||
// 更新选中的祈福类型
|
||||
this.selectedPrayerType = selectedType;
|
||||
this.selectedPrayerType = selectedType.label;
|
||||
this.selectedPrayerTypeValue = selectedType.value;
|
||||
|
||||
// 同步更新表单数据
|
||||
this.formData.prayerType = selectedType;
|
||||
|
||||
console.log('更新后的selectedPrayerType:', this.selectedPrayerType);
|
||||
console.log('更新后的formData.prayerType:', this.formData.prayerType);
|
||||
} else {
|
||||
console.error('无效的选择索引:', res.tapIndex);
|
||||
this.formData.prayerType = selectedType.value;
|
||||
}
|
||||
},
|
||||
fail: (res) => {
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ import {
|
|||
// 环境配置
|
||||
const ENV_CONFIG = {
|
||||
develop: { // 开发环境
|
||||
baseUrl: 'http://192.168.2.112:4501',
|
||||
baseUrl: 'http://192.168.2.136:4501',
|
||||
},
|
||||
trial: { // 体验版
|
||||
baseUrl: 'https://testlu.chuangtewl.com/prod-api',
|
||||
|
|
@ -54,7 +54,13 @@ console.log('HTTP配置:', {
|
|||
* @returns {Object} 请求头对象
|
||||
*/
|
||||
function getRequestHeaders(customHeader = {}) {
|
||||
const token = uni.getStorageSync('token')
|
||||
let token = uni.getStorageSync('token')
|
||||
|
||||
// 开发环境使用临时token
|
||||
if (shouldUseTempToken() && !token) {
|
||||
token = getTempToken()
|
||||
}
|
||||
|
||||
let authorization = token
|
||||
|
||||
// 平台差异化处理
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user