换皮test1.2

This commit is contained in:
minimaxagent1 2025-08-06 12:04:17 +08:00
parent 7678831bab
commit e30181e92a

View File

@ -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, // trueAPI
// 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%;