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