文件
NHCshopro/uniapp/pages/index/all-menu.vue
wikiboss f141d35f1c Add 'uniapp/' from commit '096e31448ca089004c78af69f2006c2b0324d8a4'
git-subtree-dir: uniapp
git-subtree-mainline: b87880e247
git-subtree-split: 096e31448c
2026-11-20 09:08:51 +08:00

235 行
4.8 KiB
Vue

<!-- 全部分类菜单新页面 -->
<template>
<view class="all-menu-wrap">
<!-- 自定义导航栏 -->
<view class="custom-navbar">
<view class="u-status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
<view class="navbar-content u-flex u-col-center u-row-between">
<view class="back-btn u-flex u-row-center u-col-center" @tap.stop="goBack">
<text class="u-iconfont uicon-arrow-left" style="font-size: 38rpx; color: #333;"></text>
</view>
<view class="navbar-title">全部分类</view>
<view class="right-place"></view>
</view>
</view>
<!-- 菜单列表内容区 -->
<view class="menu-content-box u-m-20">
<view class="menu-tab-box u-flex u-flex-wrap">
<view
class="tab-list u-flex-col u-col-center u-row-center"
:style="{ width: '20%' }"
v-for="(item, index) in menuList"
:key="index"
@tap="jump(item)"
>
<image class="tab-img" :src="item.image" mode="aspectFill"></image>
<text class="tab-title">{{ item.name }}</text>
</view>
</view>
</view>
</view>
</template>
<script>
import { mapGetters } from 'vuex';
let systemInfo = uni.getSystemInfoSync();
export default {
data() {
return {
statusBarHeight: systemInfo.statusBarHeight || 0,
menuList: []
};
},
computed: {
...mapGetters(['userInfo', 'homeTemplate'])
},
onLoad() {
this.initData();
},
methods: {
// 返回上一页
goBack() {
let pages = getCurrentPages();
if (pages && pages.length > 1) {
uni.navigateBack({
delta: 1,
fail: () => {
this.$tools.routerTo('/pages/index/index');
}
});
} else {
this.$tools.routerTo('/pages/index/index');
}
},
// 初始化菜单数据
initData() {
let list = uni.getStorageSync('all_grid_menu_list');
if (!list || !list.length) {
// 从首页模板备份数据中读取 menu 项
if (this.homeTemplate && this.homeTemplate.length) {
let menuItem = this.homeTemplate.find(item => item.type === 'menu');
if (menuItem && menuItem.content && menuItem.content.list) {
list = menuItem.content.list;
}
}
}
if (list && list.length) {
// 直播权限过滤
if (this.userInfo && this.userInfo.is_live == 1) {
this.menuList = list;
} else {
this.menuList = list.filter(item => item.name !== '开启直播');
}
}
},
// 页面跳转逻辑
jump(data) {
if (!data) return;
if (data.name === '我的预约' && (!data.path || data.path === '')) {
data.path = '/pages/user/rob-order';
}
if (data.name === '开启直播' && (!data.path || data.path === '')) {
data.path = '/pages/user/live';
}
if (data.name === '在线客服') {
this.openService();
return;
}
if (data.path) {
this.$tools.routerTo(data.path);
}
},
// 在线客服
openService() {
// #ifdef MP-WEIXIN
wx.openCustomerServiceChat({
extInfo: {
url: 'https://work.weixin.qq.com/kfid/kfc5aec53d2111b588a'
},
corpId: 'wwc5f08e271cf73fb2',
success(res) {},
fail(res) {}
});
// #endif
// #ifdef APP-PLUS
plus.share.getServices(
res => {
let wechat = res.find(v => v.id === 'weixin');
if (wechat) {
wechat.openCustomerServiceChat(
{
corpid: 'wwc5f08e271cf73fb2',
url: 'https://work.weixin.qq.com/kfid/kfc5aec53d2111b588a'
},
res => {},
err => {}
);
} else {
uni.showToast({
title: '当前环境不支持微信操作',
icon: 'error'
});
}
},
function(e) {
uni.showToast({
title: '获取服务失败: ' + JSON.stringify(e),
icon: 'none'
});
}
);
// #endif
}
}
};
</script>
<style lang="scss" scoped>
.all-menu-wrap {
min-height: 100vh;
background-color: #f5f6f8;
}
// 导航栏
.custom-navbar {
width: 100%;
background: #ffffff;
border-bottom: 1rpx solid #f0f0f0;
position: sticky;
top: 0;
z-index: 99;
.u-status-bar {
width: 100%;
}
.navbar-content {
height: 88rpx;
padding: 0 20rpx;
position: relative;
}
.back-btn {
width: 70rpx;
height: 70rpx;
border-radius: 50%;
position: relative;
z-index: 100;
cursor: pointer;
&:active {
background: #f0f0f0;
}
}
.navbar-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
position: absolute;
left: 50%;
transform: translateX(-50%);
pointer-events: none;
}
.right-place {
width: 70rpx;
}
}
// 菜单卡片
.menu-content-box {
background: #ffffff;
border-radius: 20rpx;
padding: 20rpx 0;
.menu-tab-box {
.tab-list {
font-size: 26rpx;
font-weight: 500;
color: #333333;
margin: 24rpx 0;
.tab-img {
width: 98rpx;
height: 98rpx;
margin-bottom: 12rpx;
border-radius: 16rpx;
}
.tab-title {
font-size: 26rpx;
font-weight: 500;
color: #333333;
line-height: 32rpx;
}
}
}
}
</style>