Files
lucky_shop/pages_goods/category.vue
ZF sun 30cda71749 refactor(http,lang): 重构请求逻辑并新增多语言错误提示
1.  新增网络相关错误的多语言翻译配置
2.  重写http请求层,添加自动重试机制与错误分类提示
3.  优化鸿蒙平台下的组件渲染兼容性与数据更新逻辑
4.  调整部分页面的模板结构与请求配置
2026-07-13 15:45:15 +08:00

179 lines
4.3 KiB
Vue

<template>
<view :style="themeColor">
<view v-show="diyData && diyData.value && diyData.value.length">
<block v-for="(item, index) in diyData.value" :key="index">
<view v-if="item.componentName == 'GoodsCategory'">
<diy-category @tologin="toLogin" ref="category" :value="item"></diy-category>
</view>
</block>
</view>
<ns-login ref="login"></ns-login>
<loading-cover ref="loadingCover"></loading-cover>
<!-- 隐私弹窗 -->
<privacy-popup ref="privacyPopup"></privacy-popup>
<!-- 底部tabBar -->
<view id="tab-bar">
<diy-bottom-nav></diy-bottom-nav>
</view>
</view>
</template>
<script>
export default {
data() {
return {
diyData: { value: [] },
mpShareData: null //小程序分享数据
};
},
onLoad() {
this.$util.hideHomeButton();
//刷新多语言
this.$langConfig.refresh();
this.getDiyInfo();
},
onShow() {
this.$util.hideHomeButton();
try {
// 鸿蒙元服务 JSVM 下 $refs.category 可能为 undefined, 需防御
if (this.$refs.category && this.$refs.category[0]) {
this.$refs.category[0].pageShow();
}
} catch (e) {
console.warn('onShow pageShow failed', e);
}
//小程序分享
// #ifdef MP-WEIXIN
this.$util.getMpShare('/pages_goods/category').then(res => {
this.mpShareData = res;
}).catch(err => {
// 如果后台没配置,用默认值
this.mpShareData = {
appMessage: {
title: this.$lang('goods.category.shareTitle'),
path: '/pages_goods/category'
},
timeLine: {
title: this.$lang('goods.category.shareTitle'),
query: '/pages_goods/category'
}
};
});
// #endif
},
onUnload() {
try {
if (!this.storeToken && this.$refs.login && typeof this.$refs.login.cancelCompleteInfo === 'function') {
this.$refs.login.cancelCompleteInfo();
}
} catch (e) {
console.warn('onUnload cancelCompleteInfo failed', e);
}
},
methods: {
getDiyInfo() {
// 避免重复请求导致布局抖动
if (this._diyInfoLoading) return;
this._diyInfoLoading = true;
this.$api.sendRequest({
url: '/api/diyview/info',
data: {
name: 'DIY_VIEW_GOODS_CATEGORY'
},
success: res => {
if (res.code == 0 && res.data) {
const newData = res.data.value ? JSON.parse(res.data.value) : res.data;
// 仅在数据真正变化时赋值,避免鸿蒙元服务下频繁 re-render 造成频闪
if (JSON.stringify(newData) !== JSON.stringify(this.diyData)) {
this.diyData = newData;
}
} else {
this.$util.showToast({
title: this.$lang('diy.noDiyData')
});
}
},
fail: err => {
console.error('getDiyInfo request failed', err);
this.$util.showToast({
title: this.$lang('diy.networkError')
});
},
complete: () => {
this._diyInfoLoading = false;
if (this.$refs.loadingCover) this.$refs.loadingCover.hide();
uni.stopPullDownRefresh();
}
});
},
toLogin() {
this.redirectTologin('/pages_goods/category');
}
},
onPullDownRefresh() {
uni.hideTabBar();
this.getDiyInfo();
},
onShareAppMessage() {
return this.mpShareData?.appMessage || {
title: this.$lang('goods.category.shareTitle'),
path: '/pages_goods/category'
};
},
onShareTimeline() {
return this.mpShareData?.timeLine || {
title: this.$lang('goods.category.shareTitle'),
query: '/pages_goods/category'
};
},
onAddToFavorites() {
return {
title: this.$lang('goods.category.shareTitle'),
path: '/pages_goods/category'
};
}
};
</script>
<style lang="scss">
::v-deep .uni-popup__wrapper.uni-center {
background: rgba(0, 0, 0, 0.6);
}
::v-deep .uni-popup__wrapper-box {
border-radius: 0 !important;
}
::v-deep .uni-popup__wrapper.uni-custom.center .uni-popup__wrapper-box {
overflow-y: visible;
}
::v-deep .loading-layer {
background: #fff !important;
}
// 分类四一级展开
::v-deep .category-template-4 .template-four .uni-popup__wrapper-box {
border-radius: 0px 0px 14px 14px !important;
overflow: hidden;
}
::v-deep .category-template-4 .content-wrap .categoty-goods-wrap .goods-list {
margin-top: 30rpx;
}
::v-deep .category-template-4 .content-wrap .goods-list .goods-item .footer-wrap .right-wrap .num-action {
width: 46rpx;
height: 46rpx;
}
::v-deep .uni-page-refresh-inner .uni-page-refresh__path {
stroke: rgb(1, 1, 1) !important;
}
</style>