UNIAPP实战项目笔记55 自定义Tabbar并使用Tabbar事件拦截未登录跳转到登录页面

news2024/9/22 19:40:41

UNIAPP实战项目笔记55 自定义Tabbar并使用Tabbar拦截未登录跳转到登录页面

点击购物车和我的的时候需要拦截并验证登录
通过验证的直接跳转,为通过验证的跳转到登录页面
通过自定义tabbar来实现

实际案例图片

  • 正常跳转
    在这里插入图片描述

  • 拦截跳转
    在这里插入图片描述

代码 pages.json

页面配置

{
	"pages": [ //pages数组中第一项表示应用启动页,参考:https://uniapp.dcloud.io/collocation/pages
		{
			"path": "pages/index/index",
			"style": {
				"navigationBarTitleText": "百年奥莱",
                "navigationBarBackgroundColor": "#fff",
                // "navigationStyle": "custom",
                "app-plus": {
                    "scrollIndicator": "none",
                    "titleNView": {
                        /* 使用字体图标时 unicode 字符表示必须 '\u' 开头,如 "\ue123"(注意不能写成"\e123")*/
                        "buttons": [
                            {
                                "float": "left",
                                "fontSrc": "./static/iconfont/iconfont.ttf",
                                "text": "\ue616"
                            },{
                                "float": "right",
                                "fontSrc": "./static/iconfont/iconfont.ttf",
                                "text": "\ue711"
                            }
                        ]
                    }
                }
			}
		}
	    ,{
            "path" : "pages/my/my",
            "style" :                                                                                    
            {
				"navigationBarTitleText": "",
                "navigationBarBackgroundColor": "#fff",
                "app-plus": {
                    "titleNView": false,
                    "scrollIndicator": "none"
                }
            }
            
        }
        ,{
            "path" : "pages/shopcart/shopcart",
            "style" :                                                                                    
            {
                "app-plus": {
                    "titleNView": false,
                    "scrollIndicator": "none"
                },
                "mp-weixin": {                    
                    "navigationStyle": "custom"
                }
            }
        }
        ,{
            "path" : "pages/list/list",
            "style" :                                                                                    
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "app-plus": {
                    "scrollIndicator": "none",
                    "titleNView": {
                        "searchInput": {
                            "placeholder": "请输入关键字",
                            "disabled": true,
                            "align": "left",
                            "autoFocus": false,
                            "borderRadius": "15px",
                            "backgroundColor": "#F7F7F7",
                            "placeholderColor": "#B3B3B3"
                        }
                    }
                },
                "mp-weixin": {                    
                    "navigationBarTitleText": "商品分类"
                }
            }
        }
        ,{
            "path" : "pages/search/search",
            "style" :
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "app-plus": {
                    "scrollIndicator": "none",
                    "titleNView": {
                        "searchInput": {
                            "placeholder": "nike",
                            "disabled": false,
                            "align": "left",
                            "autoFocus": true,
                            "borderRadius": "15px",
                            "backgroundColor": "#F7F7F7",
                            "placeholderColor": "#B3B3B3"
                        },
                        "buttons": [
                            {
                                "float": "right",
                                "color": "#636263",
                                "text": "搜索",
                                "fontSize": "16px",
                                "width":"60px"
                            }
                        ]
                    }
                }
            }
            
        }
        ,{
            "path" : "pages/search-list/search-list",
            "style" :                                                                                    
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "app-plus": {
                    "scrollIndicator": "none",
                    "titleNView": {
                        "searchInput": {
                            "placeholder": "nike",
                            "disabled": true,
                            "align": "left",
                            "autoFocus": false,
                            "borderRadius": "15px",
                            "backgroundColor": "#F7F7F7",
                            "placeholderColor": "#B3B3B3"
                        },
                        "buttons": [
                            {
                                "float": "right",
                                "color": "#636263",
                                "text": "筛选",
                                "fontSize": "16px",
                                "width":"60px"
                            }
                        ]
                    }
                }
            }
            
        }
        ,{
            "path" : "pages/details/details",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "商品详情",
                "app-plus": {
                    "scrollIndicator": "none",
                    "titleNView": {
                        "type": "transparent",
                        "buttons": [
                            {
                                "type": "menu"
                            },
                            {
                                "type": "share"
                            }
                        ]
                    }
                }
            }
        }
        ,{
            "path" : "pages/my-config/my-config",
            "style" :                                                                                    
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "navigationBarTitleText": "设置",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/my-path-list/my-path-list",
            "style" :                                                                                    
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "navigationBarTitleText": "地址管理",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/my-add-path/my-add-path",
            "style" :                                                                                    
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "navigationBarTitleText": "新增地址",
                "app-plus": {
                    "scrollIndicator": "none",
                    "titleNView": {
                        "buttons": [
                            {
                                "float": "right",
                                "color": "#636263",
                                "text": "保存",
                                "fontSize": "16px",
                                "width":"60px"
                            }
                        ]
                    }
                }
            }
            
        }
        ,{
            "path" : "pages/my-order/my-order",
            "style" :                                                                                    
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "navigationBarTitleText": "我的订单",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/confirm-order/confirm-order",
            "style" :                                                                                    
            {
                "navigationBarBackgroundColor": "#FFFFFF",
                "navigationBarTitleText": "确认订单",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/qianzi/qianzi",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "签字",
                "enablePullDownRefresh": false
            }
            
        }
        ,{
            "path" : "pages/payment/payment",
            "style" :                                                                                    
            {
                "app-plus": {
                    "titleNView": false,
                    "scrollIndicator": "none"
                }
            }
            
        }
        ,{
            "path" : "pages/payment-success/payment-success",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "支付成功",
                "enablePullDownRefresh": false,
                "navigationBarBackgroundColor": "#fff"
            }
            
        }
        ,{
            "path" : "pages/login/login",
            "style" :                                                                                    
            {
                "app-plus": {
                    "titleNView": false,
                    "scrollIndicator": "none"
                }
            }
            
        }
        ,{
            "path" : "pages/login-tel/login-tel",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "输入手机号",
                "navigationBarBackgroundColor": "#fff"
            }
            
        }
        ,{
            "path" : "pages/login-code/login-code",
            "style" :                                                                                    
            {
                "navigationBarTitleText": "输入验证码",
                "navigationBarBackgroundColor": "#fff"
            }
            
        }
    ],
	"globalStyle": {
		"navigationBarTextStyle": "black",
		"navigationBarTitleText": "uni-app",
		"navigationBarBackgroundColor": "#F8F8F8",
		"backgroundColor": "#F8F8F8"
	}
    // "tabBar": {
    //     "color": "#636263",
    //     "selectedColor": "#636263",
    //     "backgroundColor": "#fff",
    //     "spacing": "5px",
    //     "list": [
    //         {
    //             "pagePath": "pages/index/index",
    //             "iconPath": "static/tabbar/index.png",
    //             "selectedIconPath": "static/tabbar/indexSelected.png",
    //             "text": "首页"
    //         },{
    //             "pagePath": "pages/list/list",
    //             "iconPath": "static/tabbar/list.png",
    //             "selectedIconPath": "static/tabbar/listSelected.png",
    //             "text": "分类"
    //         },{
    //             "pagePath": "pages/shopcart/shopcart",
    //             "iconPath": "static/tabbar/shop.png",
    //             "selectedIconPath": "static/tabbar/shopSelected.png",
    //             "text": "购物车"
    //         },{
    //             "pagePath": "pages/my/my",
    //             "iconPath": "static/tabbar/index.png",
    //             "selectedIconPath": "static/tabbar/indexSelected.png",
    //             "text": "我的"
    //         }
    //     ]
    // }
    
}

代码 main.js

主配置文件
增加 权限跳转 代码段 用于拦截未登录的跳转

import App from './App'

// #ifndef VUE3
import Vue from 'vue'
Vue.config.productionTip = false

// 引入状态机
import store from 'store/index.js'
Vue.prototype.$store = store;

// 权限跳转,未登录的跳转到登录
Vue.prototype.navigateTo = (options)=>{
    if (!store.state.user.loginStatus) {
        uni.showToast({
            title:"请先登录",
            icon:'none'
        })
        uni.navigateTo({
            url:"/pages/login/login"
        })
        return 
    }
    uni.navigateTo(options);
}

App.mpType = 'app'
const app = new Vue({
    ...App,
    store  // 挂载状态机
})
app.$mount()
// #endif

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif

代码 Tabbar.vue组件

自定义的Tabbar组件页面
购物车和我的页面单独设置需要跳转验证

<template>
    <view class="tabbar">
        <view class="tab" 
            v-for="(item,index) in tabbarList" 
            :key="index"
            @tap="navigatorTo(item.pagePath)"
        >
            <image class="tabimg" v-if="item.pagePath === currentPage " :src="item.selectedIconPath" mode=""></image>
            <image class="tabimg" v-else :src="item.iconPath" mode=""></image>
            <view class="text">{{item.text}}</view>
        </view>
    </view>
</template>

<script>
    export default {
        props:{
            currentPage:{
                type:String,
                default:'index'
            }
        },
        data() {
            return {
                tabbarList:[
                    {
                        "pagePath": "index",
                        "iconPath": "/static/tabbar/index.png",
                        "selectedIconPath": "/static/tabbar/indexSelected.png",
                        "text": "首页"
                    },{
                        "pagePath": "list",
                        "iconPath": "/static/tabbar/list.png",
                        "selectedIconPath": "/static/tabbar/listSelected.png",
                        "text": "分类"
                    },{
                        "pagePath": "shopcart",
                        "iconPath": "/static/tabbar/shop.png",
                        "selectedIconPath": "/static/tabbar/shopSelected.png",
                        "text": "购物车"
                    },{
                        "pagePath": "my",
                        "iconPath": "/static/tabbar/my.png",
                        "selectedIconPath": "/static/tabbar/mySelected.png",
                        "text": "我的"
                    }
                ]
            };
        },
        methods:{
            navigatorTo(e){
                
                if( e=='shopcart' || e=='my' ){
                
                    let u1 = `/pages/${e}/${e}`;
                    
                    console.log(u1);
                    
                    this.navigateTo({
                        url:u1,
                        animationType:'fade-in',
                        animationDuration:0
                    })
                }else{
                    let u2 = `/page/${e}/${e}`;
                    console.log(u2);
                    uni.reLaunch({
                        url: `/pages/${e}/${e}`,
                    });
                }
            }
        }
    }
</script>

<style lang="scss">
.tabbar{
    border-top: 2rpx solid #636263;
    background-color: #fff;
    z-index: 9999;
    position: fixed;
    left: 0;
    bottom: 0;
    width: 100%;
    height: 120rpx;
    display: flex;
    justify-content: space-around;
    align-items: center;
}
.tab{
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.tabimg{
    width: 40rpx;
    height: 40rpx;
}
.text{
    font-size: 24rpx;
}
</style>

代码 index.vue页面

首页页面,引入自定义组件Tabbar

<template>
	<view class="content">
        <view class="index">
            
            <scroll-view scroll-x="true" :scroll-into-view="scrollIntoIndex" class="scroll-content" >
                <view
                :id="'top'+index"
                    class="scroll-item"
                    v-for="(item,index) in topBar"
                    :key="index"
                    @tap="changeTab(index)"
                >
                    <text :class="topBarIndex===index?'f-active-color':'f-color'">{{item.name}}</text>
                </view>
            </scroll-view>
            
            <swiper @change="onChangeTab" :current="topBarIndex" :style="'height:'+clentHeight+'px'">
                <swiper-item
                    v-for="(item,index) in newTopBar"
                    :key="index"
                >
                    
                    <scroll-view @scrolltolower="loadMore(index)" scroll-y="true" :style="'height:'+clentHeight+'px;'">
                        <block v-if="item.data.length > 0">                            
                            <block v-for="(k,i) in item.data" :key="i">
                                <!-- 推荐 -->
                                <IndexSwiper v-if="k.type==='swiperList'" :dataList='k.data'></IndexSwiper>
                                <template v-if="k.type==='recommendList'">
                                    <Recommend :dataList='k.data'></Recommend>
                                    <Card cardTitle='猜你喜欢'></Card>
                                    <!-- 卡片要在下面显示,但是位置要放到上面 template 表示一个整体循环 -->
                                </template>
                                
                                <!-- 运动户外... -->
                                <Banner v-if="k.type==='bannerList'" :dataList='k.imgUrl'></Banner>
                                
                                <template v-if="k.type==='iconsList'">
                                    <Icons :dataList='k.data'></Icons>
                                    <Card cardTitle="热销商品"></Card>
                                </template>
                                
                                <template v-if="k.type==='hotList'">
                                    <Hot :dataList='k.data'></Hot>
                                    <Card cardTitle="推荐店铺"></Card>
                                </template>

                                <template v-if="k.type==='shopList'">
                                    <Shop :dataList='k.data'></Shop>
                                    <Card cardTitle="为您推荐"></Card>
                                </template>
                                
                                <CommodityList v-if="k.type==='commodityList'" :dataList='k.data'></CommodityList>
                                
                            
                            </block>
                        </block>
                        <view v-else>
                            暂无数据...
                        </view>
                        <view class="load-text f-color">
                            {{item.loadText}}
                        </view>
                    </scroll-view>
                    
                </swiper-item>
            </swiper>
            
            
            
            <!-- 推荐模板 -->
            <!-- <IndexSwiper></IndexSwiper>
            <Recommend></Recommend>
            <Card cardTitle='猜你喜欢'></Card>
            <CommodityList></CommodityList> -->
            
            <!-- 其他模板: 运动户外 美妆... -->
            <!-- <Card cardTitle='运动户外'></Card>
            <Banner></Banner>
            <Icons></Icons>
            <Card cardTitle='热销爆品'></Card>
            <Hot></Hot>
            <Card cardTitle='店铺推荐'></Card>
            <Shop></Shop>
            <Card cardTitle="为您推荐"></Card>
            <CommodityList></CommodityList>
            -->
        </view>
        
        <!-- <view class="f-active-color">
            文字
        </view>
        <view class="iconfont icon-xiaoxi"></view>
		<view class="text-area">
			<text class="title">{{title}}</text>
		</view> -->
        <Tabbar currentPage='index'></Tabbar>
	</view>
</template>

<script>
    import $http from '@/common/api/request.js'
    import IndexSwiper from '@/components/index/indexSwiper.vue';//引入
    import Recommend from '@/components/index/Recommend.vue';//引入
    import Card from '@/components/common/Card.vue';//引入
    import CommodityList from '@/components/common/CommodityList.vue';//引入
    import Banner from '@/components/index/Banner.vue';//引入
    import Icons from '@/components/index/Icons.vue';//引入
    import Hot from '@/components/index/Hot.vue';//引入
    import Shop from '@/components/index/Shop.vue';//引入
    import Tabbar from '@/components/common/Tabbar.vue';//引入
	export default {
		data() {
			return {
                // 选中的索引
                topBarIndex:0,
                // 顶栏跟随的索引id值
                scrollIntoIndex:'top0',
                // 内容块的高度
                clentHeight:0,
                // 顶栏数据
                topBar:[],
                // 承载数据
                newTopBar:[],
				title: 'Hello'
			}
		},
        components:{
            IndexSwiper, //注册
            Recommend,
            Card,
            CommodityList,
            Banner,
            Icons,
            Hot,
            Shop,
            Tabbar
        },
		onLoad() {
            // 请求接口数据
            this.__init();
            
		},
        // 标题栏按钮点击
		onNavigationBarButtonTap(e) {
            if(e.float == 'left'){
                uni.navigateTo({
                    url:'/pages/search/search'
                })
            }
		},
        onReady() { // 初步渲染完后执行
            uni.getSystemInfo({
                success: (res) => {
                    // console.log(res);
                    // 可视区域高度 减去头部高度
                    // this.clentHeight = res.windowHeight - uni.upx2px(80) - this.getClientHeight();
                    this.clentHeight = res.windowHeight - this.getClientHeight();
                }
            })
            /* let view = uni.createSelectorQuery().select(".home-data"); // 获取dom节点对象
            // 获取节点对象数据
            view.boundingClientRect(data=>{
                // 动态获取内容块的高度,动态渲染swiper高度
                // 不要去试图计算可视区域的高度,在ios下有bug
                this.clentHeight = 2000;
                // this.clentHeight = data.height;
            }).exec(); */
            // this.getClientHeight();
		},
		methods: {
            // 请求首页数据
            __init(){
                $http.request({
                    url:'/index_list/data'
                }).then((res)=>{
                    this.topBar = res.topBar;
                    this.newTopBar = this.initData(res);
                }).catch(()=>{
                    uni.showToast({
                        title:'请求失败',
                        icon:'none'
                    })
                })
            },
            // 添加数据
            initData(res){
                let arr = [];
                for (var i = 0; i < this.topBar.length; i++) {
                    let obj = {
                        data:[],
                        load:"first",
                        loadText:"上拉加载更多..."
                    }
                    // 获取首次数据
                    if (i==0) {
                        obj.data = res.data
                    }
                    arr.push(obj)
                }
                return arr;
            },
            // 点击顶栏
            changeTab(index){
                if (this.topBarIndex === index) {
                    return;
                }
                this.topBarIndex = index
                this.scrollIntoIndex = 'top'+index
                
                // 每一次滑动 load赋值为first
                if(this.newTopBar[this.topBarIndex].load == 'first'){
                    this.addData();
                }
            },
            // 对应滑动
            onChangeTab(e){
                this.changeTab(e.detail.current)
            },
            // 获取可视区域高度【兼容】
            getClientHeight(){
                const res = uni.getSystemInfoSync();
                console.log(res.platform,res.statusBarHeight);
                const system = res.platform;
                if ( system === 'iso') {
                    return 44 + res.statusBarHeight;
                }else if( system === 'android' ){
                    return 48 + res.statusBarHeight;
                } else{
                    return 0;
                }
            },
            // 对应显示不同数据
            addData(callback){
                // 拿到索引
                let index = this.topBarIndex;
                // 拿到id
                let id = this.topBar[index].id;
                // 计算页码
                let page = Math.ceil(this.newTopBar[index].data.length/5) + 1;
                // console.log(page);
                // 请求不同的数据
                $http.request({
                    url:`/index_list/${id}/data/${page}`
                }).then((res)=>{
                    this.newTopBar[index].data = [...this.newTopBar[index].data,...res]
                }).catch(()=>{
                    uni.showToast({
                        title:'请求失败',
                        icon:'none'
                    })
                })
                // 请求结束后重新赋值
                this.newTopBar[index].load = 'last';
                
                if(typeof callback === 'function'){
                    callback();
                }
            },
            // 上拉加载更多
            loadMore(index){
                this.newTopBar[index].loadText = '加载中...';
                
                // 请求完数据,文字提示信息又换成【上拉加载更多...】
                this.addData(()=>{
                    this.newTopBar[index].loadText = '上拉加载更多...';
                })
            }
		}
	}
</script>

<style>

.load-text{
    border-top: 2rpx solid #636263;
    line-height: 60rpx;
    text-align: center;
}
.scroll-content{
    width: 100%;
    height: 80rpx;
    white-space: nowrap;
}
.scroll-item{
    display: inline-block;
    padding: 10rpx 30rpx;
    font-size: 32rpx;
}
.f-active-color{
    padding: 10rpx 0;
    border-bottom: 6rpx solid #49BDFB;
}
.index{
    width: 100%;
}
.content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

.logo {
    height: 200rpx;
    width: 200rpx;
    margin-top: 200rpx;
    margin-left: auto;
    margin-right: auto;
    margin-bottom: 50rpx;
}

.text-area {
    display: flex;
    justify-content: center;
}

.title {
    font-size: 36rpx;
    color: #8f8f94;
}
</style>

代码 list.vue页面

商品列表页面,引入自定义组件Tabbar

<template>
    <view class="">
        <Lines />
        <view class="list">
            <!-- 左侧滑动 -->
            <scroll-view scroll-y="true" class="list-left" :style="'height:'+clentHeight+'px'">
                <view 
                    v-for="(item,index) in leftData"
                     @tap="changeLeftTab(index,item.id)" 
                     class="left-item"
                 >
                    <view 
                        class= "left-name"
                        :class='activeIndex===index?"left-name-active":""'
                    >{{item.name}}</view>
                </view>
            </scroll-view>
            <!-- 右侧滑动 -->
            <scroll-view scroll-y="true" class="list-right" :style="'height:'+clentHeight+'px'">
                <view 
                    class="right-list" 
                    v-for="(item,index) in rightData"
                    :key="index"
                >
                    <block v-for="(k,i) in item">
                        <view class="list-title">{{k.name}}</view>
                        <view class="right-content">
                            <view class="right-item" v-for="(j,idx) in k.list">
                                <image class="right-img" :src="j.imgUrl" mode=""></image>
                                <view class="right-name">
                                    {{j.name}}
                                </view>
                            </view>
                        </view>
                    </block>
                </view>
            </scroll-view>
        </view>
        <Tabbar currentPage='list'></Tabbar>
    </view>
</template>

<script>
    import $http from '@/common/api/request.js'
    import Lines from "@/components/common/Lines.vue"
    import Tabbar from '@/components/common/Tabbar.vue';//引入
    export default {
        data() {
            return {
                clentHeight:0,
                activeIndex:0,
                // 左侧数据
                leftData:[],
                rightData:[],
            }
        },
        components:{
            Lines,
            Tabbar
        },
        onLoad() {
            this.getData();
        },
        onReady() { // 初步渲染完后执行
            // 获取可视高度
            uni.getSystemInfo({
                success: (res) => {
                    // 可视区域高度 减去头部高度
                    this.clentHeight = res.windowHeight - this.getClientHeight();
                }
            })
		},
        methods: {
            // 请求数据方法
            getData(id){
                if(id === this.activeIndex+1){
                    return;
                }
                $http.request({
                    url:'/goods/list'
                }).then((res)=>{
                    let leftData = [];
                    let rightData = [];
                    res.forEach(v=>{
                        leftData.push({
                            id:v.id,
                            name:v.name
                        })
                        // 如果点击的id值相投
                        if(v.id=== (this.activeIndex+1)){
                            rightData.push(v.data);
                        }
                    })
                    this.leftData = leftData;
                    this.rightData = rightData;
                    console.log(rightData);
                }).catch(()=>{
                    uni.showToast({
                        title:'请求失败',
                        icon:'none'
                    })
                })
            },
            
            // 获取可视区域高度【兼容】
            getClientHeight(){
                const res = uni.getSystemInfoSync();
                console.log(res.platform,res.statusBarHeight);
                const system = res.platform;
                if ( system === 'iso') {
                    return 44 + res.statusBarHeight;
                }else if( system === 'android' ){
                    return 48 + res.statusBarHeight;
                } else{
                    return 0;
                }
            },
            // 左侧点击事件
            changeLeftTab(index,id){
                this.getData(id);
                this.activeIndex = index;
            },
        },
        // input 输入框dia点击事件
        onNavigationBarSearchInputClicked() {
            uni.navigateTo({
                url:'/pages/search/search'
            })
        }
    }
</script>

<style lang="scss">
.list{
    display: flex;
}
.list-left{
    width: 200rpx;
}
.left-item{
    border-bottom:2rpx solid #ffffff;
    font-size: 28rpx;
    font-weight: bold;
    background-color: #F7F7F7;
}
.left-name{
    padding: 30rpx 6rpx;
    text-align: center;
}
.left-name-active{
    border-left:8rpx solid #49bdfb;
    background-color: #ffffff;
}
.list-right{
    flex: 1;
}
.list-title{
    font-weight: bold;
    padding: 30rpx 0;
}
.right-content{
    display: flex;
    flex-wrap: wrap;
}
.right-item{
    width: 150rpx;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 10rpx;
}
.right-name{
    padding:16rpx 0;
}
.right-img{
    width: 150rpx;
    height: 150rpx;
}
</style>

代码 my.vue页面

我的页面,引入自定义组件Tabbar

<template>
    <view class="my">
        <!-- 头部 -->
        <view class="my-header">
            <view class="header-main">
                <view class="header-config" @tap="goConfig">
                    <image class="config-img" src="../../static/tabbar/list.png" mode=""></image>
                </view>
                <view class="header-logo">
                    <image class="logo-img" :src="loginStatus ? userInfo.imgUrl :'../../static/tabbar/mySelected.png'" mode=""></image>
                    <view class="logo-name" @tap="goLogin">{{loginStatus ? userInfo.nickName : '用户昵称'}}</view>
                </view>
            </view>
        </view>
        <!-- 我的订单 -->
        <view class="order">
            <view class="order-title" @tap="goOrder">
                <view class="">我的订单</view>
                <view class="">全部订单 > </view>
            </view>
            <view class="order-list">
                <view class="order-item">
                    <image class="order-img" src="../../static/logo.png" mode=""></image>
                    <view class="">待付款</view>
                </view>
                <view class="order-item">
                    <image class="order-img" src="../../static/logo.png" mode=""></image>
                    <view class="">待付款</view>
                </view>
                <view class="order-item">
                    <image class="order-img" src="../../static/logo.png" mode=""></image>
                    <view class="">待付款</view>
                </view>
                <view class="order-item">
                    <image class="order-img" src="../../static/logo.png" mode=""></image>
                    <view class="">待付款</view>
                </view>
                <view class="order-item">
                    <image class="order-img" src="../../static/logo.png" mode=""></image>
                    <view class="" @tap="qianzi">待付款1</view>
                </view>
            </view>
            <!-- 内容列表 -->
            <view class="my-content">
                <view class="my-content-item" v-for="(item,index) in 6">
                    <view class="">
                        我的收藏
                    </view>
                    <view class="">
                        >
                    </view>
                </view>
            </view>
        </view>
        <Tabbar currentPage='my'></Tabbar>
    </view>
</template>

<script>
    import {mapState} from 'vuex'
    import Tabbar from '@/components/common/Tabbar.vue';//引入
    export default {
        data() {
            return {
                
            }
        },
        components:{
            Tabbar
        },
        computed:{
            ...mapState({
                loginStatus:state=>state.user.loginStatus,
                userInfo:state=>state.user.userInfo
            })
        },
        methods: {
            goConfig(){
                uni.navigateTo({
                    url:'../my-config/my-config'
                })
            },
            goOrder(){
                uni.navigateTo({
                    url:'../my-order/my-order'
                })
            },
            qianzi(){
                uni.navigateTo({
                    url:'../qianzi/qianzi'
                })
            },
            goLogin(){
                uni.navigateTo({
                    url:'/pages/login/login'
                })
            }
        }
    }
</script>

<style lang="scss">
.my-header{
    background-color: #eee;
    width: 100%;
    height: 400rpx;
}
.header-main{
    position:relative;
    top: 120rpx;
}
.header-config{
    position: absolute;
    left: 20rpx;
}
.header-logo{
    position: absolute;
    left:50%;
    margin-left:-60rpx;
    width: 120rpx;
}
.config-img{
    width: 40rpx;
    height: 40rpx;
}
.logo-img{
    width: 120rpx;
    height: 120rpx;
    border:2rpx solid #ccc;
    border-radius: 50%;
    background-color: #FFFFFF;
}
.logo-name{
    color: #FFFFFF;
    font-size: 30rpx;
    font-weight: bold;
    text-align: center;
}
.order-title{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx;
}
.order-list{
    padding:20rpx;
    display: flex;
}
.order-item{
    flex:1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
}
.order-img{
    width: 80rpx;
    height: 80rpx;
}
.my-content{
    margin:20rpx 0;
    padding: 0 20rpx;
}
.my-content-item{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20rpx 0;
    border-bottom: 2px solid #ccc;
}
</style>

代码 shopcart.vue页面

购物车页面,引入自定义组件Tabbar

<template>
    <view class="shop-cart">
        <template v-if=" list.length > 0 ">
                
            <!-- 自定义导航栏 -->
            <uniNavBar
                title="购物车"
                :rightText=" isNavBar ? '完成' : '编辑'"
                fixed="true"
                statusBar="true"
                @clickRight=" isNavBar = !isNavBar"
            ></uniNavBar>
            
            <!-- 商品内容 -->
            <view class="shop-item" v-for="(item,index) in list" :key="index">
                <label for="" class="radio" @tap="selectedItem(index)">
                    <radio value="" color="#FF3333" :checked="item.checked" /> <text></text>
                </label>
                <image class="shop-img" :src="item.imgUrl" mode=""></image>
                <view class="shop-text">
                    <view class="shop-name">
                        {{item.name}}
                    </view>
                    <view class="shop-color f-color">
                        {{item.color}}
                    </view>
                    <view class="shop-price">
                        <view class="">{{item.pprice}}
                        </view>
                        <template v-if="!isNavBar">
                            <view>x {{item.num}}</view>
                        </template>
                        <template v-else>
                            <uniNumberBox
                                :value="item.num"
                                min="1"
                                @change="changeNumber($event,index)"
                            ></uniNumberBox>
                        </template>
                    </view>
                </view>
            </view>
            <!-- 底部 -->
            <view class="shop-foot">
                <label for="" class="radio foot-radio" @tap='checkedAllFn'>
                    <radio value="" color="#FF3333" :checked="checkedAll"></radio><text>全选</text>
                </label>
                <template v-if="!isNavBar">
                    <view class="foot-total">
                        <view class="foot-count">
                            合计:
                            <text class="f-active-color">{{totalCount.pprice}}
                            </text>
                        </view>
                        <view class="foot-num" @tap="goConfirmOrder">
                            结算({{totalCount.num}})
                        </view>
                    </view>
                </template>
                <template v-else>
                    <view class="foot-total">
                        <view class="foot-num" style="background-color: black;">
                            移入收藏夹
                        </view>
                        <view class="foot-num" @tap="delGoodsFn">
                            删除
                        </view>
                    </view>
                </template>
            </view>
            
        </template>
        <template v-else>
            <uniNavBar 
                title="购物车"
                fixed="true"
                statusBar="true"
            ></uniNavBar>
            <view class="shop-else-list">
                <text>~ 购物车还是空的~</text>
            </view>
        </template>
        <Tabbar currentPage='shopcart'></Tabbar>
    </view>
</template>

<script>
    import uniNavBar from '@/components/uni/uni-nav-bar/uni-nav-bar.vue'
    import uniNumberBox from '@/components/uni/uni-number-box/uni-number-box.vue'
    import Tabbar from '@/components/common/Tabbar.vue';//引入
    
    // 状态机引入
    import {mapState,mapActions,mapGetters,mapMutations} from 'vuex'
    export default {
        data() {
            return {
                isNavBar:false,
            }
        },
        computed:{
            // 状态机数据处理
            ...mapState({
                list:state=>state.cart.list
            }),
            ...mapGetters(['checkedAll','totalCount'])
        },
        components:{
            uniNavBar,uniNumberBox,Tabbar
        },
        methods: {
            ...mapActions(['checkedAllFn','delGoodsFn']),
            ...mapMutations(['selectedItem']),
            changeNumber(value,index){
                this.list[index].num = value;
            },
            // 进入确认订单
            goConfirmOrder(){
                uni.navigateTo({
                    url:'/pages/confirm-order/confirm-order'
                })
            }
        }
    }
</script>

<style lang="scss">

.shop-list{
    padding-bottom: 100rpx;
}
.shop-else-list{
    position: absolute;
    left: 0;
    top: 0;
    right: 0;
    bottom: 0;
    background-color: #f7f7f7;
    display: flex;
    align-items: center;
    justify-content: center;
}
.shop-item{
    display: flex;
    padding: 20rpx;
    align-items: center;
    background-color: #f7f7f7;
    margin-bottom: 10rpx;
}
.shop-img{
    width: 200rpx;
    height: 200rpx;
}
.shop-text{
    flex: 1;
    padding-left: 20rpx;
}
.shop-color{
    font-size: 24rpx;
}
.shop-price{
    display: flex;
    justify-content: space-between;
}

.shop-foot{
    border-top: 2rpx solid #f7f7f7;
    background-color: #FFFFFF;
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 100rpx;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 100rpx;
}
.foot-radio{
    padding-left: 20rpx;
}
.foot-total{
    display: flex;
}
.foot-count{
    line-height: 100rpx;
    padding: 0 20rpx;
    font-size: 32rpx;
}
.foot-num{
    background-color: #49bdfb;
    color: #FFFFFF;
    padding: 0 60rpx;
    line-height: 100rpx;
}
</style>

目录结构

前端目录结构

  • manifest.json 配置文件: appid、logo…

  • pages.json 配置文件: 导航、 tabbar、 路由

  • main.js vue初始化入口文件

  • App.vue 全局配置:样式、全局监视

  • static 静态资源:图片、字体图标

  • page 页面

    • index
      • index.vue
    • list
      • list.vue
    • my
      • my.vue
    • my-config
      • my-config.vue
    • my-config
      • my-config.vue
    • my-add-path
      • my-add-path.vue
    • my-path-list
      • my-path-list.vue
    • search
      • search.vue
    • search-list
      • search-list.vue
    • shopcart
      • shopcart.vue
    • details
      • details.vue
    • my-order
      • my-order.vue
    • confirm-order
      • confirm-order.vue
    • payment
      • payment.vue
    • payment-success
      • payment-success.vue
    • login
      • login.vue
    • login-tel
      • login-tel.vue
    • login-code
      • login-code.vue
  • components 组件

    • index
      • Banner.vue
      • Hot.vue
      • Icons.vue
      • indexSwiper.vue
      • Recommend.vue
      • Shop.vue
      • Tabbar.vue
    • common
      • Card.vue
      • Commondity.vue
      • CommondityList.vue
      • Line.vue
      • ShopList.vue
    • order
      • order-list.vue
    • uni
      • uni-number-box
        • uni-number-box.vue
      • uni-icons
        • uni-icons.vue
      • uni-nav-bar
        • uni-nav-bar.vue
      • mpvue-citypicker
        • mpvueCityPicker.vue
  • common 公共文件:全局css文件 || 全局js文件

    • api
      • request.js
    • common.css
    • uni.css
  • store vuex状态机文件

    • modules
      • cart.js
      • path.js
      • user.js
    • index.js

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/98900.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

JDBC编程相关知识(实现图书管理系统进阶版)

目录 一、配置MySQL数据库驱动包 二、JDBC常规操作 1、创建数据源 2、建立连接 3、操作数据库&#xff0c;执行sql语句 4、关闭资源 三、JDBC实现图书管理系统 1、建表 2、连接数据库 3、创建实体类 a、Book类 b、BookShelf类 c、User类 d、Administrator类 e、…

jsp+ssm计算机毕业设计大学生足球预约信息【附源码】

项目运行 环境配置&#xff1a; Jdk1.8 Tomcat7.0 Mysql HBuilderX&#xff08;Webstorm也行&#xff09; Eclispe&#xff08;IntelliJ IDEA,Eclispe,MyEclispe,Sts都支持&#xff09;。 项目技术&#xff1a; JSPSSM mybatis Maven等等组成&#xff0c;B/S模式 Mave…

java计算机毕业设计springboot+vue青少年编程在线考试系统

项目介绍 21世纪的今天,随着社会的不断发展与进步,人们对于信息科学化的认识,已由低层次向高层次发展,由原来的感性认识向理性认识提高,管理工作的重要性已逐渐被人们所认识,科学化的管理,使信息存储达到准确、快速、完善,并能提高工作管理效率,促进其发展。 论文主要是对青少…

AIGC stable diffusion完整部署手册 for linux

准备工作 &#xff08; GPU服务器4G显卡 &#xff09;&#xff1a; 1. 建议 Python3.10.7 以上的版本&#xff0c;最低不能低于3.10.5 2. pip pip3的版本升级到最新 pip 22.3.1 3. 安装python3.10.7之前先安装和升级 openssl-1.1.1q 4. yum安装源改成 阿里云 或者 清华 …

English Learning - L1-4 从此没有不会的表达(下) 2022.12.15 周四

English Learning - L1-4 从此没有不会的表达&#xff08;下&#xff09; 2022.12.15 周四5 动名词5.1 动名词都有什么作用作主语做表语做定语动名词做定语有啥讲究&#xff1f;做宾语5.2 动名词的复合结构---成功加入动名词自己的主语逻辑主语动名词复合结构作宾语时用普通格和…

2021年度汇总丨20大热门TWS耳机功能配置汇总解析

疫情下的时间匆匆而过&#xff0c;2021已成为过去&#xff0c;2022年正式开启。在过去的一年中&#xff0c;以TWS耳机为代表的音频市场依旧保持着健康稳定的发展&#xff0c;彰显这一市场超强的活力和朝好的未来发展。 回顾2021&#xff0c;这一年中&#xff0c;我爱音频网365天…

直线检测霍夫变换VS深度学习

1. 引言 直线检测有很多应用&#xff1a;例如&#xff0c;创建矢量化图、端点检测等。在这篇文章中&#xff0c;我们不讨论其具体的应用程序&#xff0c;而是重点关于于如何使用传统算法和深度学习的方法来进行直线检测&#xff0c;这里我们将对二者进行相关比较。 闲话少说&a…

经典算法之异或运算(无进位相加)

目录异或运算的定义异或运算的性质异或运算的应用交换两数翻转指定位寻找单身狗异或运算的定义 众所周知&#xff0c;计算机中的所有数据都是以二进制&#xff08;0或者1&#xff09;的形式存储。而异或运算符&#xff08;^&#xff09;就是将参加运算的两个数据&#xff0c;按…

C语言—数据类型

通过sizeof运算符获取数据类型的大小&#xff0c;int占4个字节&#xff0c;表示一个int变量可以存储32位的数据&#xff1b; vs2022中&#xff0c;sizeof运算符返回的结果是一个64位 (8bytes)的无符号整型的值&#xff0c;所以占位符要使用%lld&#xff1b; #include <std…

【空气起动系统控制】使用PID调节起动机入口压力值

前段时间师傅让做一个空起系统的建模&#xff0c;结果给忘了&#xff0c;现在趁着这几天疫情封控期间在家搞一搞&#xff0c;断断续续搞了五天&#xff0c;空起系统控制的相关资料太少了&#xff0c;还好最后弄出来了&#xff0c;虽然最后还存在点小问题&#xff0c;不过大体上…

【Java编程】SSH:Struts、Spring、Hibernate

SSH&#xff1a;Struts、Spring、HibernateSSH 框架指的是 Struts、Spring 和 Hibernate 三者的集成。集成 SSH 框架的系统从职责上分为表示层、业务逻辑层、数据持久层和域模块层。Struts 属于 MVC 框架的一种&#xff0c;提供了对 MVC 系统底层的支持&#xff0c;负责 MVC 的…

汽车ECU通信相关验证项有哪些?

已剪辑自: https://mp.weixin.qq.com/s/-fIAXkS37r6jvnuA7yIQDA 汽车电子的高速发展决定了基础软件所面临的要求将会更加严格&#xff0c;其要求会覆盖软件的安全性、稳定性、可扩展性等方方面面。为了提高软件质量&#xff0c;降低软件应用风险&#xff0c;构建高安全、高可靠…

什么是网站安全?如何查询网站在百度是否安全?

什么是网站安全&#xff1f; 百度词条的定义为网站安全是指出于防止网站受到黑客入侵者对其网站进行挂马&#xff0c;篡改网站源代码&#xff0c;被窃取数据等行为而做出一系列的安全防御工作&#xff0c;在我的理解中&#xff0c;网站安全就是当有人攻击你的网站时&#x…

Java+SSM社团管理系统(含源码+论文+答辩PPT等)

项目功能简介: 该项目采用的技术实现如下 后台框架&#xff1a;Spring、SpringMVC、MyBatis UI界面&#xff1a;JSP、jQuery 、H-ui 数据库&#xff1a;MySQL 系统功能 本社团管理系统是根据大学社团管理的实际应用而开发的&#xff0c;采用JSP技术&#xff0c;Java编程语言&am…

python调用halcon程序/.hdev文件/直接调用halcon引擎

一、前言 python有两种调用halcon的方法 1、安装halcon的python库&#xff0c;pip install mvtec-halcon20111 然后python代码中主要调用方式为&#xff1a;通过ha来调用halcon中的各种算子&#xff0c;本人不是很喜欢这种方式&#xff0c;后面主要介绍第2种方法。 import …

java计算机毕业设计springboot+vue校园出入管理系统

项目介绍 本论文主要论述了如何使用JAVA语言开发一个校园出入管理系统 ,本系统将严格按照软件开发流程进行各个阶段的工作,采用B/S架构,面向对象编程思想进行项目开发。在引言中,作者将论述校园出入管理系统的当前背景以及系统开发的目的,后续章节将严格按照软件开发流程,对系…

可能你看到的大部分教材里讲的指针和指针变量是一个概念,但是真的是这样吗?看完我这篇文章肯定会颠覆你的认知哦?

指针vs指针变量一、指针和指针变量的含义1、变量的“左值”和“右值”2、什么是指针&#xff1f;3、什么是指针变量&#xff1f;二、如何看待“指针就是指针变量”这种说法三、为什么要存在指针&#xff1f;四、对指针进行解引用操作的本质一、指针和指针变量的含义 1、变量的…

2022云南省职业院校技能大赛(高职组) Web技术(网站设计与开发)赛项规程

2022云南省职业院校技能大赛&#xff08;高职组&#xff09; Web技术&#xff08;网站设计与开发&#xff09;赛项规程 一、赛项名称 赛项名称&#xff1a;Web技术&#xff08;网站设计与开发&#xff09; 赛项组别&#xff1a;高职组 二、竞赛内容 Web技术&#xff08;网站设计…

SA-UNet:用于视网膜血管分割的空间注意力UNet

摘要 在本文中提出了一种名为空间注意力UNet&#xff08;SA-UNet&#xff09;的轻量级网络&#xff0c;它不需要大量的带注释的训练样本&#xff0c;可以以数据增强的方式来更有效的使用可用的带注释的样本。SA-UNet引入一种空间注意模块&#xff0c;这个模块沿着空间维度推断…

[激光原理与应用-61]:激光器 - 种子源 - 1064nm皮秒种子源参数解读

目录 第1章 种子源介绍 1.1 简介 1.2 种子源特点 1.3 皮秒种子源应用 第2章 《瀚盈激光》种子源性能指标解读 2.1 波长&#xff1a;1064nm 》红外 2.2 光谱宽度&#xff08;频率宽度、带宽&#xff09; 2.3 线宽 2.4 脉冲宽度 2.5 重复频率 周期T 2.6 输出功率 2.…