首页 > 其他分享 >uni-app 4.13开发弹出层组件(二)弹出关闭功能

uni-app 4.13开发弹出层组件(二)弹出关闭功能

时间:2022-10-14 16:02:42浏览次数:64  
标签:4.13 vue return default app free noreadnum uni data


index.nuve页面

<template>
<view class="">
<free-nav-bar :title="'微信'" :noreadnum="1" :fixed='true' @openExtend="openExtend">
<template v-slot="title"></template>
</free-nav-bar>

<!-- 列表 -->
<block v-for="(item,index) in list" :key="index">
<free-media-list :item="item" :index="index"></free-media-list>
</block>

<!-- 弹出层 -->
<free-popup ref="extend">
<view style="width: 300rpx;height: 400rpx;"></view>
</free-popup>
</view>
</template>

<script>
import freeNavBar from '@/components/free-ui/free-nav-bar.vue';
import freeMediaList from '@/components/free-ui/free-media-list.vue';
import freePopup from '@/components/free-ui/free-popup.vue';
export default {
components: {
freeNavBar,
freeMediaList,
freePopup
},
data() {
return {
list:[
{
avatar:"/static/images/demo/demo6.jpg",
nickname:"昵称",
update_time:1628069958,
data:"你好啊,哈哈哈",
noreadnum:1
},
{
avatar:"/static/images/demo/demo6.jpg",
nickname:"昵称",
update_time:1628069958,
data:"你好啊,哈哈哈",
noreadnum:12
},
{
avatar:"/static/images/demo/demo6.jpg",
nickname:"昵称",
update_time:1628069958,
data:"你好啊,哈哈哈",
noreadnum:2
},
{
avatar:"/static/images/demo/demo6.jpg",
nickname:"昵称",
update_time:1628069958,
data:"你好啊,哈哈哈",
noreadnum:10
}
]
}
},
onl oad() {

},
methods: {
openExtend(){
this.$refs.extend.show();
}
},
}
</script>

<style>

</style>

free-pupop.vue

<template>
<div style="z-index:9999;overflow:hidden;" v-if="status">
<!-- 蒙版 -->
<view class="position-fixed top-0 left-0 right-0 bottom-0" style="background:rgba(0,0,0,0.5);" @click="hide"></view>
<!-- 弹出框内容 -->
<div class="position-fixed bg-white" style="left: 100rpx;top: 100rpx;">
<slot></slot>
</div>
</div>
</template>

<script>
export default {
props: {
// 是否开启蒙版颜色
maskColor: {
type: Boolean,
default: false
},

},
data() {
return {
status: false,
x:-1,
y:1,
maxX:0,
maxY:0
}
},
mounted() {
try {
const res = uni.getSystemInfoSync();
this.maxX = res.windowWidth - uni.upx2px(this.bodyWidth)
this.maxY = res.windowHeight - uni.upx2px(this.bodyHeight) - uni.upx2px(this.tabbarHeight)
} catch (e) {
// error
}
},
computed: {
getMaskColor() {
let i = this.maskColor ? 0.5 : 0
return `background-color: rgba(0,0,0,${i});`
},
getBodyClass(){
if(this.center){
return 'left-0 right-0 bottom-0 top-0 flex align-center justify-center'
}
let bottom = this.bottom ? 'left-0 right-0 bottom-0' : 'rounded border'
return `${this.bodyBgColor} ${bottom}`
},
getBodyStyle(){
let left = this.x > -1 ? `left:${this.x}px;` : ''
let top = this.y > -1 ? `top:${this.y}px;` : ''
return left + top
}
},
methods:{
show(){
this.status = true
},
hide(){
this.status = false
}
}
}
</script>

<style scoped>
.free-animated{
/* #ifdef APP-PLUS-NVUE */
/* transform: scale(0,0);
opacity: 0; */
/* #endif */
}
.z-index{
/* #ifndef APP-NVUE */
z-index: 9999;
/* #endif */
}
</style>

free-nav-bar.vue

<template>
<view>
<view class="bg-light" :class="fixed?'fixed-top':''">
<!-- 状态栏 -->
<view :style="'height:'+statusBarHeight+'px;'"></view>
<!-- 导航 -->
<view class="w-100 flex align-center justify-between" style="height: 90rpx;">
<!-- 左边 -->
<view class="flex align-center">
<!-- 标题 -->
<text v-if="title" class="font-md ml-3" >{{getTitle}}</text>
</view>
<!-- 右边 -->
<view class="flex align-center">
<free-icon-button @click="search"><text class="iconfont font-md"></text></free-icon-button>
<free-icon-button @click="openExtend"><text class="iconfont font-md"></text></free-icon-button>
</view>
<!--\ue6e3 \ue682 -->
</view>
</view>

<!-- 站位 -->
<view v-if="fixed" :style="fixedStyle"></view>
</view>
</template>

<script>
import freeIconButton from './free-icon-button.vue';
export default {
components: {
freeIconButton,
},
props: {
title: {
type: String,
default: ''
},
fixed:{
type:Boolean,
default:false
},
noreadnum:{
type:Number,
default:0
}
},
data() {
return {
statusBarHeight: 0,
navBarHeight: 0,
}
},
mounted() {
// 获取任务栏高度
// #ifdef APP-PLUS-NVUE
this.statusBarHeight = plus.navigator.getStatusbarHeight()
// #endif
this.navBarHeight = this.statusBarHeight + uni.upx2px(90)
},
computed: {
fixedStyle() {
return `height:${this.navBarHeight}px`;
},
getTitle(){
let noreadnum = this.noreadnum>0 ? '('+this.noreadnum+')' : '';
return this.title + noreadnum;
}
},
methods:{
openExtend(){
this.$emit('openExtend');
}
}
}
</script>

<style>

</style>

页面如下

uni-app 4.13开发弹出层组件(二)弹出关闭功能_#ifdef

感谢大家观看,下期再见


标签:4.13,vue,return,default,app,free,noreadnum,uni,data
From: https://blog.51cto.com/u_15565664/5757138

相关文章

  • uni-app 5.1~5.3 通讯录列表页开发
    通讯录列表页面email.nvue<template><view><!--导航栏--><free-nav-bartitle="通讯录"></free-nav-bar><!--通讯录列表--><free-list-itemv-for=......
  • uni-app 6发现页搭建
    find.nvue文件<template><viewclass="page"><!--导航栏--><free-nav-bartitle="发现"></free-nav-bar><free-list-itemtitle="朋友圈"showRight>......
  • uni-app 16用户投诉开发
    用户投诉user-report.nvue<template><viewclass="page"><!--导航栏--><free-nav-bartitle="用户投诉"showBack:showRight="true"bgColor="bg-white">......
  • uni-app 8聊天页开发
    主文件chat.nvue<template><view><!--导航栏--><free-nav-bartitle="呵呵呵呵":noreadnum="1"showBack><free-icon-buttonslot="right"><textclass......
  • uni-app 7个人中心页开发
    my.nvue内容如下<template><viewclass="page"><free-nav-barbgColor="bg-white"><free-icon-buttonslot="right"><textclass="iconfontfont-md"></text......
  • uni-app 9.2聊天信息设置页(二)
    主页面chat-set.nvue<template><viewstyle="background-color:#EDEDED;"><!--导航栏--><free-nav-bartitle="聊天信息"showBack:showRight="false"></free......
  • MAPPO学习笔记(2) —— 从MAPPO论文入手
    在有了上一节一些有关PPO算法的概念作为基础后,我们就可以正式开始对于MAPPO这一算法的学习。那么,既然要学习一个算法,就不得不去阅读提出这一算法的论文。那么本篇博客将从......
  • 高校垃圾分类APP技术服务支持
      高校垃圾分类app有助于创造更加美好的生活学习环境,培养学生的责任心和环保意识;有利于推动高校的生态文明建设,构建“绿色校园”,提升学校形象;有利于环境的保护,实现绿......
  • SpringBoot中Server层以及Mapper层常用注解
    4.Service层注解@Service注解一般写在业务层的接口实现类上,而不是接口上。4.1@Service@Service:@Service注解用于类上,标记当前类是一个service类,加上该注解会将当......
  • Unity 在模型上展示标签UI
    voidUpdate(){this.transform.LookAt(Camera.main.transform);}   在主摄像机下设置一个子摄像机,主摄像机CullingMask去掉显示UI。子摄像机Cul......