Skip to content

Commit 1f3cd3d

Browse files
committed
Initial commit
0 parents  commit 1f3cd3d

File tree

13 files changed

+275
-0
lines changed

13 files changed

+275
-0
lines changed

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

app.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//app.js
2+
App({
3+
onLaunch: function () {
4+
5+
},
6+
globalData: {
7+
8+
}
9+
})

app.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"pages":[
3+
"pages/index/index"
4+
],
5+
"window":{
6+
"backgroundTextStyle":"light",
7+
"navigationBarBackgroundColor": "#fff",
8+
"navigationBarTitleText": "WeChat",
9+
"navigationBarTextStyle":"black"
10+
}
11+
}

app.wxss

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**app.wxss**/
2+
.container {
3+
height: 100%;
4+
display: flex;
5+
flex-direction: column;
6+
align-items: center;
7+
justify-content: space-between;
8+
padding: 200rpx 0;
9+
box-sizing: border-box;
10+
}

components/pop/pop.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
// components/pop.js
2+
Component({
3+
options: {
4+
multipleSlots: true // 在组件定义时的选项中启用多slot支持
5+
},
6+
/**
7+
* 组件的属性列表
8+
* 用于组件自定义设置
9+
*/
10+
properties: {
11+
// 弹窗标题
12+
title: { // 属性名
13+
type: String, // 类型(必填),目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
14+
value: '标题' // 属性初始值(可选),如果未指定则会根据类型选择一个
15+
},
16+
// 弹窗内容
17+
content: { type: String, value: '弹窗内容' },
18+
// 弹窗取消按钮文字
19+
cancelText: { type: String, value: '取消' },
20+
// 弹窗确认按钮文字
21+
confirmText: { type: String, value: '确定' }
22+
},
23+
/**
24+
* 私有数据,组件的初始数据
25+
* 可用于模版渲染
26+
*/
27+
data: { // 弹窗显示控制
28+
isShow: false
29+
},
30+
/**
31+
* 组件的方法列表
32+
* 更新属性和数据的方法与更新页面数据的方法类似
33+
*/
34+
methods: {
35+
/**
36+
* 公有方法
37+
*/
38+
//隐藏弹框
39+
hideDialog() {
40+
this.setData({
41+
isShow: !this.data.isShow
42+
})
43+
},
44+
//展示弹框
45+
showDialog() {
46+
this.setData({
47+
isShow: !this.data.isShow
48+
})
49+
},
50+
/**
51+
* 内部私有方法建议以下划线开头
52+
* triggerEvent 用于触发事件
53+
*/
54+
_cancelEvent() { //触发取消回调
55+
this.triggerEvent("cancelEvent")
56+
},
57+
_confirmEvent() { //触发成功回调
58+
this.triggerEvent("confirmEvent");
59+
}
60+
}
61+
})

components/pop/pop.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"component": true,
3+
"usingComponents": {}
4+
}

components/pop/pop.wxml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!--components/pop.wxml-->
2+
<view class='wx_dialog' hidden="{{!isShow}}">
3+
<view class='wx-mask'></view>
4+
<view class='wx-dialog-content'>
5+
<view class='wx-dialog-title'>{{ title }}</view>
6+
<view class='wx-dialog-contents'>{{ content }}</view>
7+
<view class='wx-dialog-footer'>
8+
<view class='wx-dialog-btn' catchtap='_cancelEvent'>{{ cancelText }}</view>
9+
<view class='wx-dialog-btn' catchtap='_confirmEvent'>{{ confirmText }}</view>
10+
</view>
11+
</view>
12+
</view>

components/pop/pop.wxss

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* components/pop.wxss */
2+
.wx_dialog {
3+
position: fixed;
4+
left: 0;
5+
right: 0;
6+
top: 0;
7+
bottom: 0;
8+
}
9+
.wx-mask {
10+
position: absolute;
11+
left: 0;
12+
right: 0;
13+
top: 0;
14+
bottom: 0;
15+
background: rgba(0, 0, 0, .3);
16+
z-index: 99;
17+
}
18+
.wx-dialog-content {
19+
position: absolute;
20+
background: #fff;
21+
left: 50%;
22+
top: 50%;
23+
transform: translate(-50%, -50%);
24+
width: 80%;
25+
/* height: 200px; */
26+
padding-bottom: 60px;
27+
z-index: 100;
28+
border-radius: 5px;
29+
}
30+
.wx-dialog-contents {
31+
padding: 10px;
32+
}
33+
.wx-dialog-title {
34+
padding: 5px 10px;
35+
font-size: 14px;
36+
}
37+
.wx-dialog-footer {
38+
position: absolute;
39+
left: 0;
40+
right: 0;
41+
bottom: 0;
42+
font-size: 14px;
43+
height: 40px;
44+
line-height: 40px;
45+
border-top: 1px solid #eee;
46+
}
47+
.wx-dialog-btn {
48+
display: inline-block;
49+
width: 49%;
50+
cursor: pointer;
51+
text-align: center;
52+
}
53+
.wx-dialog-btn:first-child {
54+
border-right: 1px solid #eee;
55+
}

pages/index/index.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
//index.js
2+
//获取应用实例
3+
const app = getApp()
4+
5+
Page({
6+
data: {},
7+
onLoad: function() {},
8+
onReady: function() {
9+
// 实例化弹窗1
10+
this.dialog1 = this.selectComponent("#dialog1");
11+
12+
// 实例化弹窗2
13+
this.dialog2 = this.selectComponent("#dialog2");
14+
},
15+
16+
/**
17+
* 弹窗1
18+
*/
19+
showDialog1() {
20+
this.dialog1.showDialog();
21+
},
22+
cancelDialog1() {
23+
console.log('你点击了取消');
24+
this.dialog1.hideDialog();
25+
},
26+
confirmDialog1() {
27+
console.log('你点击了确定');
28+
this.dialog1.hideDialog();
29+
},
30+
31+
/**
32+
* 弹窗2
33+
*/
34+
showDialog2() {
35+
this.dialog2.showDialog();
36+
},
37+
cancelDialog2() {
38+
console.log('2你点击了取消');
39+
this.dialog2.hideDialog();
40+
},
41+
confirmDialog2() {
42+
console.log('2你点击了确定');
43+
this.dialog2.hideDialog();
44+
},
45+
46+
})

pages/index/index.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"usingComponents": {
3+
"pop": "/components/pop/pop"
4+
}
5+
}

0 commit comments

Comments
 (0)