换皮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} 返回寺庙介绍数据
*/
export function getTempleInfo() {
return get('/app/temple/introduced', {}, {
export function getTempleIndex() {
return get('/app/temple/index', {}, {
timeout: 10000,
showLoading: false
})

View File

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