uniApp——个性化组件

一、底部导航栏

在这里插入图片描述

1. 底部导航栏组件

<template>
	<view class="bottom-tab">
		<view :class="item.center==true?'bottom-tab-item-center':'bottom-tab-item-sider' " @click="changeTap(item)" v-for="(item,index) in tabList" :key="index">
			<image v-if="curTab==item.id" class="first-img" :src="item.imgOn"></image>
			<image v-if="curTab!=item.id" class="first-img" :src="item.imgOff"></image>
			<text :class="curTab==item.id?'text-position text-on':'text-position'">{{item.name}}</text>
		</view>
	</view>
</template>

<script>
	export default {
		name:"wyg-bottom-tab-withcenter",
		props:{
			tabIndex: {
				//图片的尺寸
				type: String,
				default: "1"
			},
			tabListParent:{
				type:Array,
				default:[]
			}
		},
		data() {
			return {
				curTab:1,
				tabList:[]
			}
		},
		created(){
			this.curTab=new Number(this.tabIndex);
			if(this.tabListParent.length>0){
				this.tabList=this.tabListParent;
			}
		},
		methods: {
			changeTap(e){
				console.log(e.id)
				this.curTab = e.id
				this.$emit('send', e.id)
			}	
		}
	}
	
</script>

<style lang="scss">
	.bottom-tab{
		position: fixed;
		background-color: #FDFDFD;
		bottom: 0%;
		left:0%;
		width: 100%;
		height: 2.9rem;
		
		display: flex;
		align-items:center;
		justify-content:space-between;
		.bottom-tab-item-center{
			width: 24%;
			display: flex;
			flex-direction: column;
			align-items:center;
			justify-content:center;
			.first-img{
				width: 2.6rem;
				height: 2.6rem;
				margin-top: -0.8rem;
				
				border-radius: 50%;
				border: 0.01rem solid #C0C4CC;
			}
			.text-position{
				margin-top: 0rem;
				font-size: 0.6rem;
				color: #757575;
			}
			.text-on{
				color: #FFB400;
			}
			
		}
		.bottom-tab-item-sider{
			width: 19%;
			display: flex;
			flex-direction: column;
			align-items:center;
			justify-content:center;
			
			.first-img{
				width: 1.5rem;
				height: 1.5rem;
			}
			.text-position{
				margin-top: 0rem;
				font-size: 0.6rem;
				color: #757575;
			}
			.text-on{
				color: #FFB400;
			}
			
		}
	}
	
</style>

2. 组件数据

const LIST = [{
		id: 1,
		name: "首页",
		imgOff: "../../static/wyg-bottom-tab/img/icon_01.png",
		imgOn: "../../static/wyg-bottom-tab/img/icon_01_f.png",
		"url": "/pages/index/index"
	},
	{
		id: 2,
		name: "分类",
		imgOff: "../../static/wyg-bottom-tab/img/icon_02.png",
		imgOn: "../../static/wyg-bottom-tab/img/icon_02_f.png",
		"url": "/pages/sqaure/sqaure"
	},
	{
		id: 3,
		name: "福利",
		imgOff: "../../static/wyg-bottom-tab/img/wel.png",
		imgOn: "../../static/wyg-bottom-tab/img/wel-on.png",
		"url": "/pages/center/index",
		center:true
	},
	{
		id: 4,
		name: "购物车",
		imgOff: "../../static/wyg-bottom-tab/img/icon_03.png",
		imgOn: "../../static/wyg-bottom-tab/img/icon_03_f.png",
		"url": "/pages/message/message"
	},
	{
		id: 5,
		name: "个人中心",
		imgOff: "../../static/wyg-bottom-tab/img/icon_04.png",
		imgOn: "../../static/wyg-bottom-tab/img/icon_04_f.png",
		"url": "/pages/mine/mine"
	}
]

export default LIST;

3. 默认页面添加组件

<template>
    <view :class="vuex_theme">
		<home v-if="showPageId === 1"></home>
		<square v-if="showPageId === 2"></square>
		<message v-if="showPageId === 4"></message>
		<mine v-if="showPageId === 5"></mine>
        <wyg-bottom-tab-withcenter tabIndex=1 :tabListParent="tabList" @send='acceptValue'></wyg-bottom-tab-withcenter>
    </view>
</template>

<script> 
    import wygBottomTabWithcenter from '@/components/wyg-bottom-tab/wyg-bottom-tab-withcenter.vue';
    import TAB_LIST from '@/static/wyg-bottom-tab/js/botoom-list2.js'
	import mine from '@/pages/mine/mine.vue'
	import square from '@/pages/square/square.vue'
	import home from '@/pages/home/home.vue'
	import message from '@/pages/message/message.vue'
    export default {
        components:{wygBottomTabWithcenter, mine, square, home, message},
        data() {
            return {
                tabList:TAB_LIST,
				showPageId: 1
            }
        },
        onLoad() {
        },
        methods: {
			acceptValue(e){
				this.showPageId = e
				console.log(e)
			}
        }
    }
</script>

二、瀑布流布局

<template>
    <view class="water-fill">
        <template v-if="waterList.length != 0">
            <view class="water-wrapper" @touchstart='handletouchstart' @touchmove='handletouchmove'
                @touchend='handletouchend'>
                <!-- <refreshView ref="refreshView" /> -->
                <view class="water-box">
                    <view class="water-sub" v-for="(items,index) in waterList" :key="index">
                        <view class="water-item" v-for="(item,index) in items" :key="index">
                            <view class="water-top">
                                <image :src="item.cover" mode="widthFix"></image>
                                <h3>{{item.title}}</h3>
                            </view>
                            <view class="water-bottom">
                                <view class="water-bottom-item">
                                    <view class="img-box">
                                        <image class="water-avatar" :src="item.photo" mode="widthFix"></image>
                                    </view>
                                    <text class="water-name">{{item.name}}</text>
                                </view>
                                <view class="water-bottom-item">
                                    <image src="@/static/images/like.png" mode="widthFix"></image>
                                    <text>{{item.likeCount}}</text>
                                </view>
                            </view>
                        </view>
                    </view>
                </view>
            </view>
        </template>
        <view class="water-none" v-if="waterList.length == 0">
            <image src="../../static/images/3.jpeg" mode="widthFix"></image>
            <text>暂无数据</text>
        </view>
    </view>
</template>

<script>
    import Vue from 'vue';
    import refreshView from '../Refresh/Refresh.vue'
    export default {
        components: {
            refreshView
        },
        name: 'waterFill',
        data() {
            return {
                waterList: [
                    [{
                            cover: "http://qing.demo.hongcd.com/uploads/20210304/e522390a2607d8f7a92c7196f0fe2d9b.jpg",
                            id: "1084",
                            isLiked: "0",
                            likeCount: 0,
                            name: "笑饮孤鸿",
                            photo: "https://img2.baidu.com/it/u=3189065550,26744168&fm=253&fmt=auto&app=120&f=JPEG?w=804&h=800",
                            title: "虽然你我会下落不明",
                        },
                        {
                            cover: "../../static/images/3.jpeg",
                            id: "1084",
                            isLiked: "0",
                            likeCount: 0,
                            name: "笑饮孤鸿",
                            photo: "https://img2.baidu.com/it/u=3189065550,26744168&fm=253&fmt=auto&app=120&f=JPEG?w=804&h=800",
                            title: "虽然你我会下落不明",
                        },
                        {
                            cover: "https://tse3-mm.cn.bing.net/th/id/OIP-C.RmMBEiuK7jiteaQByZoO2gHaKc?w=182&h=257&c=7&r=0&o=5&dpr=1.25&pid=1.7",
                            id: "1084",
                            isLiked: "0",
                            likeCount: 0,
                            name: "笑饮孤鸿",
                            photo: "https://img2.baidu.com/it/u=3189065550,26744168&fm=253&fmt=auto&app=120&f=JPEG?w=804&h=800",
                            title: "虽然你我会下落不明",
                        }
                    ],
                    [{


                            cover: "https://tse4-mm.cn.bing.net/th/id/OIP-C.3ch3ETbSknC0tCGqriUKbQHaEK?w=294&h=186&c=7&r=0&o=5&dpr=1.25&pid=1.7",
                            id: "1084",
                            isLiked: "0",
                            likeCount: 0,
                            name: "笑饮孤鸿",
                            photo: "https://img2.baidu.com/it/u=3189065550,26744168&fm=253&fmt=auto&app=120&f=JPEG?w=804&h=800",
                            title: "虽然你我会下落不明",
                        },
                        {
                            cover: "http://qing.demo.hongcd.com/uploads/20210304/e522390a2607d8f7a92c7196f0fe2d9b.jpg",
                            id: "1084",
                            isLiked: "0",
                            likeCount: 0,
                            name: "笑饮孤鸿",
                            photo: "https://img2.baidu.com/it/u=3189065550,26744168&fm=253&fmt=auto&app=120&f=JPEG?w=804&h=800",
                            title: "虽然你我会下落不明",
                        },
                        {
                            cover: "https://tse2-mm.cn.bing.net/th/id/OIP-C.Vkj713W8u9S35-geMG1rgwHaE5?w=240&h=180&c=7&r=0&o=5&dpr=1.25&pid=1.7",
                            id: "1084",
                            isLiked: "0",
                            likeCount: 0,
                            name: "笑饮孤鸿",
                            photo: "https://img2.baidu.com/it/u=3189065550,26744168&fm=253&fmt=auto&app=120&f=JPEG?w=804&h=800",
                            title: "虽然你我会下落不明",
                        }
                    ]
                ],
                errorimage: 'this.src="' + require('@/static/images/3.jpeg') + '"'
            }
        },
        methods: {
            // 将数组拆分成可使用状态,减少代码
            groupCut(array, subGroupLength) {
                let index = 0;
                let newArray = [];
                while (index < array.length) {
                    newArray.push(array.slice(index, index += subGroupLength));
                }
                return newArray;
            },
            handleLoad(arr) {
                // 如果arr存在,即在父组件刷新的值  若不存在就是下拉请求刷新
                if (arr) {
                    let length = arr.length;
                    this.waterList = this.groupCut(arr, length / 2)
                } else {
                    console.log('写请求数据接口,将数据赋值给waterList')
                }
                uni.showToast({
                    title: '刷新啦'
                })
            },
            // 监听页面下拉刷新
            //触摸开始
            handletouchstart: function(e) {
                let that = this;
                // that.$refs.refreshView.handletouchstart(e)
            },

            //触摸移动
            handletouchmove: function(e) {
                let that = this;
                // that.$refs.refreshView.handletouchmove(e)
            },
            //触摸结束
            handletouchend: function(e) {
                let that = this;
                // that.$refs.refreshView.handletouchend(e);
                that.handleLoad();
            }
        },
    }
</script>

<style lang="less" scoped>
    .water-fill {
        .water-wrapper {
            .water-box {
                display: flex;
                width: 100%;
                box-sizing: border-box;
                font-size: 0;
                justify-content: space-between;
                background-color: #f5f8f9;
                padding: 10px 5px;

                .water-sub {
                    display: flex;
                    width: 49%;
                    overflow: hidden;
                    flex-direction: column;

                    .water-item {
                        width: 100%;
                        border-radius: 12upx;
                        overflow: hidden;
                        background-color: #FFFFFF;
                        margin-bottom: 10upx;

                        .water-top {
                            image {
                                width: 100%;
                            }

                            h3 {
                                font-family: PingFangHK-Medium;
                                font-size: 28upx;
                                font-weight: 600;
                                line-height: 40upx;
                                color: #333333;
                                text-align: justify;
                                margin: 20upx;
                                .n-ellipsis(2);
                            }
                        }

                        .water-bottom {
                            display: flex;
                            justify-content: space-between;
                            margin: 0 20upx 20upx 20upx;
                            font-size: 24upx;

                            .water-bottom-item {
                                display: flex;
                                align-items: center;

                                .img-box {
                                    display: flex;
                                    align-items: center;
                                    justify-content: center;
                                    width: 50upx;
                                    height: 50upx;
                                    border-radius: 50%;
                                    overflow: hidden;

                                    .water-avatar {
                                        width: 50upx;
                                    }
                                }

                                .water-name {
                                    max-width: 160upx;
                                    overflow: hidden;
                                    white-space: nowrap;
                                    text-overflow: ellipsis;
                                }

                                text {
                                    line-height: 32upx;
                                    font-size: 24upx;
                                    color: #333;
                                    margin-left: 14upx;
                                }

                                image {
                                    width: 28upx;
                                }
                            }
                        }
                    }
                }
            }
        }

        .water-none {
            position: fixed;
            top: 0;
            bottom: 0;
            width: 100%;
            display: flex;
            justify-content: center;
            align-items: center;
            flex-direction: column;

            image {
                width: 200upx;
            }

            text {
                padding-top: 40upx;
                font-size: 24upx;
                color: #999;
            }
        }
    }


    //多行文本省略
    .n-ellipsis(@n) {
        overflow: hidden;
        display: -webkit-box;
        -webkit-line-clamp: @n;
        -webkit-box-orient: vertical;
        text-overflow: ellipsis;
        word-break: break-all;
    }
</style>

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值