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

可作为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;
}

最新文章

  1. 首师大附中科创教育平台 我的刷题记录 3120 LJX的校园:入学典礼
  2. 使用Kylin构建企业大数据分析平台的4种部署方式
  3. 中转Http请求
  4. vbox 不识别u盘的问题
  5. CodeIgniter框架入门教程——第三课 URL及ajax
  6. Devexpress treelist 树形控件 实现带三种状态的CheckBox
  7. 高版本jquery尤其是1.10.2的版本设置input radio设置值的最正确的姿势。
  8. HDU4901 The Romantic Hero 计数DP
  9. 用 HTML 编写博客栏目
  10. PHP输出缓冲控制- Output Control 函数应用详解
  11. 贵价的高级衣物清理法小Tipp之观察别人当然要从脚看起咯!
  12. 什么是staging server
  13. PHP - 子类使用父类的构造函数
  14. 详解python命名空间和作用域
  15. Linux系统根目录各文件夹的含义
  16. Vue-router(基础)_滚动行为和history模式
  17. 浏览器将URL变成一个屏幕上显示的网页的过程?
  18. FineUIMvc v4.0.0 发布了,MVC控件库基础版免费!
  19. Vuejs——(13)组件——杂项
  20. 在windows server 2012/2016上,任务管理器性能页面增加磁盘监控的办法

热门文章

  1. [Functional Programming] Monad
  2. 转 SqlServer中如何实现自动备份数据!
  3. hibernate中错误笔记
  4. Android WiFi直连 双向通信
  5. 数据库字符集与排序规则(Character Set And Collation)
  6. Ruby 和 Python 分析器是如何工作的?
  7. centos时间调整的操作(转)
  8. Java类载入器 ClassLoader的解析
  9. Windows7清除图标缓存
  10. mac go环境报警告