chore:加购商品时购物车出现在页面下面

This commit is contained in:
2026-09-07 09:56:03 +08:00
parent f37633525f
commit 50cd3081e6
3 changed files with 36 additions and 15 deletions

View File

@@ -559,12 +559,13 @@ export default {
};
},
computed: {
// 后台新增开关:加购按钮;未下发时兼容旧字段 quickBuy
// 后台新增开关:加购按钮
// 后台开启就显示, 关闭就不显示; 未下发新字段时兼容旧字段 quickBuy
showAddCart() {
const v = this.value;
if (v.showAddCart !== undefined) return v.showAddCart;
if (v.show_add_cart !== undefined) return v.show_add_cart;
return v.quickBuy;
const t = this.getDiyToggle(['showAddCart', 'show_add_cart']);
if (t !== undefined) return t;
const legacy = this.getDiyToggle(['quickBuy', 'quick_buy']);
return legacy !== undefined ? legacy : false;
},
/**
* 当前分类层级 (参考 template 2 的 goodsLevel 模式)

View File

@@ -1,6 +1,8 @@
<template>
<view data-component-name="diy-category" :class="['category-page-wrap', 'category-template-' + value.template]"
:style="{ height: 'calc(100vh - ' + tabBarHeight + ')' }">
:style="{ height: 'calc(100vh - var(--window-top, 0px) - ' + tabBarHeight + ')' }">
<!-- 高度说明: 100vh - H5顶部导航栏(--window-top, 小程序为0) - 底部导航高度(tabBarHeight),
保证底部购物车结算栏始终落在可视区内, 点击加购后无需向下翻即可看到 -->
<!-- 模板4: 顶部搜索框(图片样式) -->
<view class="search-box search-box-template-4" v-if="value.template == 4 && value.search"
@tap.stop="onClickSearch()">
@@ -324,18 +326,19 @@ export default {
let money = parseFloat(this.cartMoney).toFixed(2);
return money.split('.');
},
// 后台新增开关:显示购物车及结算按钮 / 加购按钮;未下发时兼容旧字段 quickBuy
// 后台新增开关:快捷购买(显示购物车及结算按钮) / 加购按钮
// 后台开启哪个就显示哪个, 关闭哪个就不显示哪个; 未下发新字段时兼容旧字段 quickBuy
showCartSettlement() {
const v = this.value;
if (v.showCartSettlement !== undefined) return v.showCartSettlement;
if (v.show_cart_settlement !== undefined) return v.show_cart_settlement;
return v.quickBuy;
const t = this.getDiyToggle(['showCartSettlement', 'show_cart_settlement']);
if (t !== undefined) return t;
const legacy = this.getDiyToggle(['quickBuy', 'quick_buy']);
return legacy !== undefined ? legacy : false;
},
showAddCart() {
const v = this.value;
if (v.showAddCart !== undefined) return v.showAddCart;
if (v.show_add_cart !== undefined) return v.show_add_cart;
return v.quickBuy;
const t = this.getDiyToggle(['showAddCart', 'show_add_cart']);
if (t !== undefined) return t;
const legacy = this.getDiyToggle(['quickBuy', 'quick_buy']);
return legacy !== undefined ? legacy : false;
},
// 转换字符数值为真正的数值
navbarHeight() {

View File

@@ -1,5 +1,22 @@
export default {
methods: {
/**
* 读取后台装修下发的布尔开关
* 依次取 names 中的字段, 兼容 1/0、"1"/"0"、true/false、"true"/"false" 等值类型
* 命中返回 true/false; 所有字段都未下发时返回 undefined (由调用方决定兜底)
*/
getDiyToggle(names) {
const v = this.value || {};
for (let i = 0; i < names.length; i++) {
const val = v[names[i]];
if (val === undefined || val === null || val === '') continue;
if (val === true || val === 1 || val === '1' || val === 'true') return true;
if (val === false || val === 0 || val === '0' || val === 'false') return false;
return !!val;
}
return undefined;
},
// 异步触发事件
async __$emitEvent(payload = {eventName: '__unnamedEvent', data: {}, promiseCallback: null}) {
await this.$eventBus.emit(payload.eventName, payload.data, payload.promiseCallback)