实现了 标题,内容和按钮设置,可动态设置按钮,以及按钮点击事件的回调

可作为component 使用

直接上代码

//遮罩的代码
<viewclass="uiComponent uiComponent_mask uiComponent_mask_{{uiComponent.mask.show &&'active'}}" style="{{uiComponent.mask.style}}" ></view>
 
//dialog的代码
<view wx:if="{{uiComponent.dialog.show}}" class="uiComponent uiComponent-dialog uiComponent-dialog_{{ uiComponent.dialog.show &&'active' }}"
style="{{uiComponent.dialog.style}}"
>
<view class='uiComponent-dialog-title txt-nowrap' wx:if="{{ uiComponent.dialog.title }}">{{ uiComponent.dialog.title }}</view>
<view class='uiComponent-dialog-content' wx:if="{{ uiComponent.dialog.content }}">{{ uiComponent.dialog.content }}</view>
<view class='uiComponent-dialog-btns' wx:if="{{ uiComponent.dialog.btns.length>0 }}">
<view bindtap='uiComponent_dialog_btnclick' class='uiComponent-dialog-btn txt-nowrap' wx:for="{{uiComponent.dialog.btns}}" wx:key="{{index}}" data-index="{{index}}" style="width:{{1/uiComponent.dialog.btns.length*99.99999}}%;{{item.style}}"><view>{{item.text}}</view></view>
</view>
</view>
/**显示或隐藏mask */
UIComponent.mask = function (show=false,style='') {
var self = this;
self.setData({
'uiComponent.mask.show': show,
'uiComponent.mask.style': style
});
} /** dialog
* 按照界面,这里可排布的大概也就3个左右
* btns:[
* {
* text: "确定",
* style: "",
* click: function(e, idx, btn){
*
* }
* }
* ]
*
*
* 调用例子
self.dialog({ show: true, title: "111", content: "2222", btns: [
{
text: "确定" ,
click: function (e, idx, btn){
self.toast(`选中了第${idx}个按钮`)
}
},
{
text: "样式",
style:"color:white;background-color:green;"
} ,
{
text: "不能取消",
click:function(e,idx,btn){ self.toast("不满足条件,不能取消")
return false;
}
}
]
})
* self.dialog({show:false})
*/
UIComponent.dialog = function (opt={}) {
var self = this;
let app = getApp();
opt = app.util.extend({},{
//默认有遮罩
mask:true,
show:false ,
//按钮组
btns:[ ],
title:"",
content:""
},opt); if (opt.mask){
self.mask(opt.show)
}
if(opt.show){
if (!opt.btns || opt.btns.length==0){
opt.btns=[
{
text:"确定"
}
];
}
}
self.setData({
'uiComponent.dialog.show': opt.show,
'uiComponent.dialog.style': opt.style,
'uiComponent.dialog.btns': opt.btns,
'uiComponent.dialog.title': opt.title,
'uiComponent.dialog.content': opt.content
}); }
/**
* 所有的按钮touch事件都关注到这里
*/
UIComponent.uiComponent_dialog_btnclick=function(e){
var self = this;
var index = e.currentTarget.dataset.index;
var btns = self.data.uiComponent.dialog.btns;
var btn = btns[index];
var func = btn.click;
if (typeof func=="function"){
var ret= func.apply(self, [e, index, btn]);
if(ret!==false){ //click事件可返false禁止关闭dialog
self.dialog({
show: false
});
}
}else{
self.dialog({
show:false
});
}
}
/**截断为1行文字,超出...*/

.txt-nowrap {
text-overflow: -o-ellipsis-lastline;
overflow: hidden;
text-overflow: ellipsis;
display: -webkit-box;
-webkit-line-clamp:;
-webkit-box-orient: vertical;
}
/* 遮罩层 */
.uiComponent_mask{
height:;width:;transform:translateZ(0) translateY(-1);
transition: all .1s ;
}
.uiComponent_mask_active{
height:100vh;width:100%;display:block;position:fixed;top:;left:;z-index:;
background-color: rgba(0,0,0,.6);transform:translateZ(0) translateY(0); transition: all .01s ;
} /** dialog */
.uiComponent-dialog{
display:none;
}
.uiComponent-dialog_active{
display:block;background-color: white;border-radius:8rpx;
width:70%;position:fixed;top:30%;left:15%;min-height:50px;
}
.uiComponent-dialog-title{
text-align: center;font-size: 14px;color:#808080;
padding:10px 5rpx 0 5rpx; }
.uiComponent-dialog-content{
text-align: center;font-size: 16px;color:#202020;
padding:10px 5rpx; }
.uiComponent-dialog-btns{
display:flex;align-items: center;text-align: center;justify-content: space-around;border-top: 1px solid #ccc;
}
.uiComponent-dialog-btn:first-child{
border-left:;
}
.uiComponent-dialog-btn{
font-size: 14px;padding:10rpx 0; border-left: 1px solid #ccc;
}

微信小程序 - dialog的更多相关文章

  1. 微信小程序-实战巩固(二)

    刚刚写了小程序入门没几天,小程序就开放个人开发者资格,感觉为我而来啊 \(≧▽≦)/.迫不及待的去注册,准备将之前的处女作传上去体验一把,结果卡在了服务器配置上:免费的果然不靠谱/(ㄒoㄒ)/~~,后 ...

  2. 小程序开发过程中常见问题[微信小程序、支付宝小程序]

    目录 一.样式中如何使用background-image呢? 二.使用自适应单位rpx类似于rem,布局尽量使用flex布局 三.万能的{{双大括号,用于在模版中输出变量 四.你想要的基础组件和API ...

  3. 微信小程序自定义组件

    要做自定义组件,我们先定一个小目标,比如说我们在小程序中实现一下 WEUI 中的弹窗组件,基本效果图如下. Step1 我们初始化一个小程序(本示例基础版本库为 1.7 ),删掉里面的示例代码,并新建 ...

  4. 微信小程序中的组件

    前言 之前做小程序开发的时候,对于开发来说比较头疼的莫过于自定义组件了,当时官方对这方面的文档也只是寥寥几句,一笔带过而已,所以写起来真的是非常非常痛苦!! 好在微信小程序的库从 1.6.3 开始,官 ...

  5. 5个最优秀的微信小程序UI组件库

    开发微信小程序的过程中,选择一款好用的组件库,可以达到事半功倍的效果.自从微信小程序面世以来,不断有一些开源组件库出来,下面5款就是排名比较靠前,用户使用量与关注度比较高的小程序UI组件库.还没用到它 ...

  6. 微信小程序--成语猜猜看

    原文链接:https://mp.weixin.qq.com/s/p6OMCbTHOYGJsjGOINpYvQ 1 概述 微信最近有很多火爆的小程序.成语猜猜看算得上前十火爆的了.今天我们就分享这样的小 ...

  7. 从微信小程序开发者工具源码看实现原理(二)- - 小程序技术实现

    wxml与wxss的转换 1.wxml使用wcc转换 2.wxss使用wcsc转换 开发者工具主入口 视图层页面的实现 视图层页面实现技术细节 视图层快速打开原理 视图层新打开页面流程 业务逻辑层页面 ...

  8. 6个最优秀的微信小程序UI组件库

    开发微信小程序的过程中,选择一款好用的组件库,可以达到事半功倍的效果.自从微信小程序面世以来,不断有一些开源组件库出来,下面6款就是排名比较靠前,用户使用量与关注度比较高的小程序UI组件库.还没用到它 ...

  9. 微信小程序自定义组件,提示组件

    微信小程序自定义组件,这里列举了一个常用的提示自定义组件,调用自定义组件中的方法和字段.仅供参考和学习. 编写组件: 在根目录下添加“components”目录,然后像添加Page页面一样添加自定义组 ...

随机推荐

  1. jQuery几个经典表单应用整理回想

    1.文本框获得(失去)焦点 当文本框获得输入焦点时,将该文本框高亮显示,算不得一个应用.仅仅是一个小技巧,能够提高用户体验. [html] view plaincopy <span style= ...

  2. Google POI下载工具破解之路

    我是GIS初学者,爱好二次开发,像初恋一样.最近对编译感兴趣,每当成功获取一点信息,就有一种快感,感觉马上就要成功了……其实,还早! 01.初次反编译 今天在微创业工作室找到了Google POI下载 ...

  3. 如何使用angularjs实现抓取页面内容

    <html ng-app="myApp"> <head> <title>angularjs-ajax</title> <scr ...

  4. PHP Filter函数

    PHP Filter 函数 PHP Filter 简介 PHP 过滤器用于对来自非安全来源的数据(比如用户输入)进行验证和过滤. 安装 Filter 函数是 PHP 核心的组成部分.无需安装即可使用这 ...

  5. MQTT---HiveMQ源代码具体解释(十八)Cluster-kryo与Serializer

    源博客地址:http://blog.csdn.net/pipinet123 MQTT交流群:221405150 既然是Cluster,node之间肯定是须要交互的,那么肯定是须要序列化和反序列化.Hi ...

  6. 微信群的id

    今天网速慢了,竟然把微信群的id卡出来了,记录一下. 格式应该是一个像QQ群一样的数字,然后+@chatroom 看图!   文章来源:刘俊涛的博客 欢迎关注,有问题一起学习欢迎留言.评论.

  7. How to add a button in the seletions "More"

    <?xml version="1.0" encoding="utf-8"?> <openerp> <data> <re ...

  8. oracle 存储过程 调用动态sql

      oracle 存储过程 调用动态sql CreationTime--2018年8月16日11点25分 Author:Marydon 1.错误实现方式 --开始时间拼接' 00:00:00' V_S ...

  9. javascript 的继承实例

    shape.prototype = { getEdge:function(){ return this.edge; }, getArea:function(){ return this.a*this. ...

  10. CentOS7——gitlab本地git仓库搭建 以及web hook配置

    整个搭建用的都是各种默认设置,所以没有用到高深的的东西,比较简单,比较傻瓜式,这篇也仅仅是一个入门. 另外本文具有时效性,浏览本文请注意发表时间,为防止过时产生误导,本文尽量把 “如何得知应该这样做” ...