换皮test1.2
This commit is contained in:
parent
7678831bab
commit
e30181e92a
|
|
@ -41,6 +41,7 @@
|
|||
</view>
|
||||
<view class="list-scroll">
|
||||
<view class="list">
|
||||
<!-- 导航项目列表 -->
|
||||
<view
|
||||
class="li"
|
||||
v-for="(item, index) in navigationItems"
|
||||
|
|
@ -55,6 +56,11 @@
|
|||
{{ item.subtitle }}
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 空状态提示 -->
|
||||
<view v-if="!loading && navigationItems.length === 0" class="empty-state">
|
||||
<text>暂无功能项目</text>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="bottom">
|
||||
|
|
@ -80,7 +86,6 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import navigationData from "../../enum/navigationData.json";
|
||||
import { navigateToPage } from "../../utils/router.js";
|
||||
import { getHomeConfig } from "../../api/index/index.js";
|
||||
import { getArticleById } from "../../api/article/article.js";
|
||||
|
|
@ -90,21 +95,43 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
return {
|
||||
marqueeX: '', // 初始位置,和marquee-wrap宽度一致
|
||||
timer: null,
|
||||
loading: false,
|
||||
// 默认配置,如果API获取失败则使用本地配置
|
||||
pageConfig: navigationData.pageConfig,
|
||||
navigationItems: navigationData.navigationItems,
|
||||
bottomSection: navigationData.bottomSection
|
||||
loading: true, // 默认为true,等待API数据加载
|
||||
// 页面配置数据,完全依赖API
|
||||
pageConfig: {
|
||||
background: { img: '' },
|
||||
announcement: { icon: '', text: '' },
|
||||
topIcons: {
|
||||
leftIcon: { hidden: false, img: '' },
|
||||
rightIcon: { img: '' },
|
||||
bottomIcon: { img: '' }
|
||||
}
|
||||
},
|
||||
navigationItems: [],
|
||||
bottomSection: {
|
||||
openingTime: {
|
||||
title: '',
|
||||
time: '',
|
||||
decorationImg: ''
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
onLoad() {
|
||||
// 页面加载时获取配置
|
||||
this.loadHomeConfig();
|
||||
},
|
||||
|
||||
// 添加下拉刷新支持
|
||||
onPullDownRefresh() {
|
||||
console.log('用户触发下拉刷新');
|
||||
this.loadHomeConfig().finally(() => {
|
||||
uni.stopPullDownRefresh();
|
||||
});
|
||||
},
|
||||
onShow() {
|
||||
// 如果配置已加载,启动跑马灯
|
||||
if (this.pageConfig && this.pageConfig.announcement) {
|
||||
this.startMarquee();
|
||||
if (this.pageConfig && this.pageConfig.announcement && this.pageConfig.announcement.text) {
|
||||
this.startMarquee();
|
||||
}
|
||||
},
|
||||
onUnload() {
|
||||
|
|
@ -131,13 +158,14 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
try {
|
||||
console.log(`第 ${retryCount + 1} 次尝试获取配置...`);
|
||||
|
||||
// 检查网络状态
|
||||
const isNetworkAvailable = await this.checkNetworkStatus();
|
||||
if (!isNetworkAvailable) {
|
||||
console.error('网络不可用,使用默认配置');
|
||||
this.useDefaultConfig();
|
||||
return;
|
||||
}
|
||||
// 检查网络状态
|
||||
const isNetworkAvailable = await this.checkNetworkStatus();
|
||||
if (!isNetworkAvailable) {
|
||||
console.error('网络不可用,使用默认配置');
|
||||
this.useDefaultConfig();
|
||||
this.loading = false;
|
||||
return;
|
||||
}
|
||||
|
||||
console.log('网络状态正常,开始请求API...');
|
||||
const response = await getHomeConfig();
|
||||
|
|
@ -146,29 +174,25 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
// 检查响应状态
|
||||
if (!response) {
|
||||
console.error('API响应为空');
|
||||
this.useDefaultConfig();
|
||||
return;
|
||||
throw new Error('API响应为空');
|
||||
}
|
||||
|
||||
// 检查响应码
|
||||
if (response.code !== 200) {
|
||||
console.error('API响应码错误:', response.code, response.msg);
|
||||
this.useDefaultConfig();
|
||||
return;
|
||||
throw new Error(`API响应码错误: ${response.code}`);
|
||||
}
|
||||
|
||||
// 检查数据是否存在
|
||||
if (!response.data) {
|
||||
console.error('API响应数据为空');
|
||||
this.useDefaultConfig();
|
||||
return;
|
||||
throw new Error('API响应数据为空');
|
||||
}
|
||||
|
||||
// 检查数据是否为数组且有内容
|
||||
if (!Array.isArray(response.data) || response.data.length === 0) {
|
||||
console.error('API响应数据格式错误或为空数组');
|
||||
this.useDefaultConfig();
|
||||
return;
|
||||
throw new Error('API响应数据格式错误');
|
||||
}
|
||||
|
||||
// 获取第一条配置数据
|
||||
|
|
@ -178,8 +202,7 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
// 检查body字段是否存在
|
||||
if (!configData.body) {
|
||||
console.error('配置数据缺少body字段');
|
||||
this.useDefaultConfig();
|
||||
return;
|
||||
throw new Error('配置数据缺少body字段');
|
||||
}
|
||||
|
||||
// 解析JSON配置
|
||||
|
|
@ -190,8 +213,7 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
// 验证配置数据完整性
|
||||
if (!this.validateConfig(parsedConfig)) {
|
||||
console.error('配置数据验证失败');
|
||||
this.useDefaultConfig();
|
||||
return;
|
||||
throw new Error('配置数据验证失败');
|
||||
}
|
||||
|
||||
// 更新页面配置
|
||||
|
|
@ -206,7 +228,7 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
} catch (parseError) {
|
||||
console.error('解析配置JSON失败:', parseError);
|
||||
console.log('原始body数据:', configData.body);
|
||||
this.useDefaultConfig();
|
||||
throw new Error('解析配置JSON失败: ' + parseError.message);
|
||||
}
|
||||
|
||||
// 如果成功获取到数据,跳出重试循环
|
||||
|
|
@ -237,29 +259,26 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
},
|
||||
|
||||
/**
|
||||
* 使用默认配置
|
||||
* 处理配置加载失败
|
||||
*/
|
||||
useDefaultConfig() {
|
||||
console.log('使用默认配置数据');
|
||||
// 确保默认配置可用
|
||||
if (!this.pageConfig || !this.pageConfig.announcement) {
|
||||
console.error('默认配置数据不完整');
|
||||
uni.showToast({
|
||||
title: '配置数据异常',
|
||||
icon: 'none',
|
||||
duration: 2000
|
||||
});
|
||||
return;
|
||||
}
|
||||
// 启动跑马灯
|
||||
this.stopMarquee();
|
||||
this.startMarquee();
|
||||
console.log('API获取失败,无法加载配置');
|
||||
|
||||
// 不设置任何默认配置,保持初始化的空状态
|
||||
// 数据保持为初始化时的空结构
|
||||
|
||||
// 显示提示信息
|
||||
uni.showToast({
|
||||
title: '使用本地配置',
|
||||
icon: 'none',
|
||||
duration: 1500
|
||||
uni.showModal({
|
||||
title: '加载失败',
|
||||
content: '无法获取页面配置,请检查网络连接后重试',
|
||||
showCancel: true,
|
||||
cancelText: '取消',
|
||||
confirmText: '重试',
|
||||
success: (res) => {
|
||||
if (res.confirm) {
|
||||
this.loadHomeConfig();
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
|
|
@ -549,6 +568,14 @@ import { getArticleById } from "../../api/article/article.js";
|
|||
color: #522510;
|
||||
}
|
||||
}
|
||||
|
||||
.empty-state {
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
padding: 40rpx;
|
||||
color: #999;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
}
|
||||
.hua{
|
||||
width: 100%;
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user