换皮test1.3

公告,时间,背景图,已经可以使用temple/index接口进行修改
This commit is contained in:
minimaxagent1 2025-08-06 14:12:33 +08:00
parent e30181e92a
commit 69c05c4911
2 changed files with 90 additions and 171 deletions

View File

@ -5,8 +5,8 @@ import { get, request } from '@/utils/request'
* 获取寺庙介绍信息 * 获取寺庙介绍信息
* @returns {Promise} 返回寺庙介绍数据 * @returns {Promise} 返回寺庙介绍数据
*/ */
export function getTempleInfo() { export function getTempleIndex() {
return get('/app/temple/introduced', {}, { return get('/app/temple/index', {}, {
timeout: 10000, timeout: 10000,
showLoading: false showLoading: false
}) })

View File

@ -8,13 +8,13 @@
</view> </view>
<!-- 背景图 --> <!-- 背景图 -->
<image class="bj" :src="pageConfig.background.img" mode="aspectFill"></image> <image class="bj" :src="templeData.imgUrl" mode="aspectFill"></image>
<!-- 公告 --> <!-- 公告 -->
<view class="announcement"> <view class="announcement">
<image class="ggimg" :src="pageConfig.announcement.icon" mode="" /> <image class="ggimg" :src="pageConfig.announcement.icon" mode="" />
<view class="marquee-wrap"> <view class="marquee-wrap">
<view class="marquee" :style="{ transform: `translateX(${marqueeX}rpx)` }"> <view class="marquee" :style="{ transform: `translateX(${marqueeX}rpx)` }">
{{ pageConfig.announcement.text }} {{ templeData.bulletinContent }}
</view> </view>
</view> </view>
</view> </view>
@ -34,7 +34,7 @@
<image :src="bottomSection.openingTime.decorationImg" mode=""></image> <text>{{ bottomSection.openingTime.title }}</text> <image :src="bottomSection.openingTime.decorationImg" mode=""></image> <image :src="bottomSection.openingTime.decorationImg" mode=""></image> <text>{{ bottomSection.openingTime.title }}</text> <image :src="bottomSection.openingTime.decorationImg" mode=""></image>
</view> </view>
<view class="time"> <view class="time">
{{ bottomSection.openingTime.time }} {{ templeData.startTime }} - {{ templeData.endTime }}
</view> </view>
<view class="hua"> <view class="hua">
<image src="https://api.ccttiot.com/smartmeter/img/static/uyz1LDPTjPqeOzBMjLZ7" mode=""></image> <image src="https://api.ccttiot.com/smartmeter/img/static/uyz1LDPTjPqeOzBMjLZ7" mode=""></image>
@ -87,7 +87,7 @@
<script> <script>
import { navigateToPage } from "../../utils/router.js"; import { navigateToPage } from "../../utils/router.js";
import { getHomeConfig } from "../../api/index/index.js"; import { getHomeConfig,getTempleIndex } from "../../api/index/index.js";
import { getArticleById } from "../../api/article/article.js"; import { getArticleById } from "../../api/article/article.js";
export default { export default {
@ -113,42 +113,51 @@ import { getArticleById } from "../../api/article/article.js";
time: '', time: '',
decorationImg: '' decorationImg: ''
} }
} },
templeData: {
imgUrl: '',
bulletinContent: '',
startTime: '',
endTime: '',
audioUrl: ''
},
isAudioPlaying: false,
audioContext: null
} }
}, },
onLoad() { onLoad() {
// //
this.loadHomeConfig(); this.loadHomeConfig();
//
this.loadTempleData();
}, },
// //
onPullDownRefresh() { onPullDownRefresh() {
console.log('用户触发下拉刷新'); console.log('用户触发下拉刷新');
this.loadHomeConfig().finally(() => { Promise.all([
this.loadHomeConfig(),
this.loadTempleData()
]).finally(() => {
uni.stopPullDownRefresh(); uni.stopPullDownRefresh();
}); });
}, },
onShow() { onShow() {
// //
if (this.pageConfig && this.pageConfig.announcement && this.pageConfig.announcement.text) {
this.startMarquee(); this.startMarquee();
}
}, },
onUnload() { onUnload() {
this.stopMarquee(); this.stopMarquee();
//
this.stopAudio();
}, },
methods: { methods: {
/** /**
* 获取首页配置 * 获取首页配置
*/ */
async loadHomeConfig() { async loadHomeConfig() {
//
console.log('=== 开始获取首页配置 ===');
console.log('当前时间:', new Date().toISOString());
console.log('页面路径:', this.$mp?.page?.route || 'unknown');
this.loading = true;
console.log('开始获取首页配置...'); console.log('开始获取首页配置...');
this.loading = true;
// //
const maxRetries = 3; const maxRetries = 3;
@ -158,63 +167,12 @@ import { getArticleById } from "../../api/article/article.js";
try { try {
console.log(`${retryCount + 1} 次尝试获取配置...`); console.log(`${retryCount + 1} 次尝试获取配置...`);
//
const isNetworkAvailable = await this.checkNetworkStatus();
if (!isNetworkAvailable) {
console.error('网络不可用,使用默认配置');
this.useDefaultConfig();
this.loading = false;
return;
}
console.log('网络状态正常开始请求API...');
const response = await getHomeConfig(); const response = await getHomeConfig();
console.log('API响应:', response); console.log('API响应:', response);
// //
if (!response) { if (response?.code === 200 && response?.data?.[0]?.body) {
console.error('API响应为空'); const parsedConfig = JSON.parse(response.data[0].body);
throw new Error('API响应为空');
}
//
if (response.code !== 200) {
console.error('API响应码错误:', response.code, response.msg);
throw new Error(`API响应码错误: ${response.code}`);
}
//
if (!response.data) {
console.error('API响应数据为空');
throw new Error('API响应数据为空');
}
//
if (!Array.isArray(response.data) || response.data.length === 0) {
console.error('API响应数据格式错误或为空数组');
throw new Error('API响应数据格式错误');
}
//
const configData = response.data[0];
console.log('配置数据:', configData);
// body
if (!configData.body) {
console.error('配置数据缺少body字段');
throw new Error('配置数据缺少body字段');
}
// JSON
try {
const parsedConfig = JSON.parse(configData.body);
console.log('解析后的配置数据:', parsedConfig);
//
if (!this.validateConfig(parsedConfig)) {
console.error('配置数据验证失败');
throw new Error('配置数据验证失败');
}
// //
this.updatePageConfig(parsedConfig); this.updatePageConfig(parsedConfig);
@ -224,38 +182,27 @@ import { getArticleById } from "../../api/article/article.js";
this.startMarquee(); this.startMarquee();
console.log('配置加载成功'); console.log('配置加载成功');
} catch (parseError) {
console.error('解析配置JSON失败:', parseError);
console.log('原始body数据:', configData.body);
throw new Error('解析配置JSON失败: ' + parseError.message);
}
//
break; break;
} else {
throw new Error('API响应数据无效');
}
} catch (error) { } catch (error) {
retryCount++; retryCount++;
console.error(`${retryCount} 次尝试失败:`, error); console.error(`${retryCount} 次尝试失败:`, error.message);
console.error('错误详情:', {
message: error.message,
stack: error.stack,
name: error.name
});
if (retryCount >= maxRetries) { if (retryCount >= maxRetries) {
console.error('所有重试都失败了,使用默认配置'); console.error('所有重试都失败了');
this.useDefaultConfig(); this.useDefaultConfig();
break; break;
} else { } else {
console.log(`等待 ${retryCount * 1000}ms 后重试...`);
await new Promise(resolve => setTimeout(resolve, retryCount * 1000)); await new Promise(resolve => setTimeout(resolve, retryCount * 1000));
} }
} }
} }
this.loading = false; this.loading = false;
console.log('配置加载完成loading状态:', this.loading); console.log('配置加载完成');
}, },
/** /**
@ -282,102 +229,74 @@ import { getArticleById } from "../../api/article/article.js";
}); });
}, },
/**
* 验证配置数据完整性
*/
validateConfig(config) {
if (!config) {
console.error('配置对象为空');
return false;
}
//
const requiredFields = ['pageConfig', 'navigationItems', 'bottomSection'];
for (const field of requiredFields) {
if (!config[field]) {
console.error(`配置缺少必需字段: ${field}`);
return false;
}
}
// pageConfig
const requiredPageConfigFields = ['background', 'announcement', 'topIcons'];
for (const field of requiredPageConfigFields) {
if (!config.pageConfig[field]) {
console.error(`pageConfig缺少必需字段: ${field}`);
return false;
}
}
// announcement
if (!config.pageConfig.announcement.text) {
console.error('announcement缺少text字段');
return false;
}
console.log('配置数据验证通过');
return true;
},
/** /**
* 更新页面配置 * 更新页面配置
*/ */
updatePageConfig(parsedConfig) { updatePageConfig(parsedConfig) {
if (parsedConfig.pageConfig) { // 使undefined
this.pageConfig = parsedConfig.pageConfig; this.pageConfig = parsedConfig.pageConfig || this.pageConfig;
console.log('更新pageConfig成功'); this.navigationItems = parsedConfig.navigationItems || [];
} this.bottomSection = parsedConfig.bottomSection || this.bottomSection;
if (parsedConfig.navigationItems) { console.log('配置更新完成');
this.navigationItems = parsedConfig.navigationItems;
console.log('更新navigationItems成功');
}
if (parsedConfig.bottomSection) {
this.bottomSection = parsedConfig.bottomSection;
console.log('更新bottomSection成功');
}
}, },
/** /**
* 检查网络状态 * 获取寺庙数据
*/ */
checkNetworkStatus() { async loadTempleData() {
return new Promise((resolve) => { try {
uni.getNetworkType({ console.log('开始获取寺庙数据...');
success: (res) => { const response = await getTempleIndex();
console.log('网络类型:', res.networkType); console.log('寺庙数据API响应:', response);
if (res.networkType === 'none') {
console.error('网络连接不可用'); if (response?.code === 200 && response?.data) {
resolve(false); this.templeData = {
imgUrl: response.data.imgUrl || '',
bulletinContent: response.data.bulletinContent || '',
startTime: response.data.startTime || '',
endTime: response.data.endTime || '',
audioUrl: response.data.audioUrl || ''
};
//
this.stopMarquee();
this.startMarquee();
console.log('寺庙数据加载成功');
} else { } else {
resolve(true); throw new Error('寺庙数据API响应无效');
} }
}, } catch (error) {
fail: () => { console.error('获取寺庙数据失败:', error);
console.error('获取网络状态失败'); uni.showToast({
resolve(false); title: '获取寺庙数据失败',
icon: 'none'
});
} }
});
});
}, },
startMarquee() { startMarquee() {
// //
if (!this.pageConfig || !this.pageConfig.announcement || !this.pageConfig.announcement.text) { const announcementText = this.templeData?.bulletinContent || this.pageConfig?.announcement?.text;
console.warn('配置数据不完整,无法启动跑马灯'); if (!announcementText) {
return; return;
} }
// //
this.stopMarquee(); this.stopMarquee();
// 24rpx // 24rpx
const textWidth = this.pageConfig.announcement.text.length * 24; const textWidth = announcementText.length * 24;
this.timer = setInterval(() => { this.timer = setInterval(() => {
this.marqueeX--; this.marqueeX--;
if (this.marqueeX < -textWidth) { if (this.marqueeX < -textWidth) {
this.marqueeX = 600; this.marqueeX = 600;
} }
}, 16); // 60 }, 16);
}, },
stopMarquee() { stopMarquee() {