Commit e18f4fdd by 张立顺

组件调整

1 parent a69ee4d4
Showing 21 changed files with 412 additions and 4 deletions
{
"component": true,
"usingComponents": { "switch-block": "/components/switchBlock/switchBlock", "tab-popup": "/components/tabPopup/tabPopup" }
}
{ {
"navigationStyle": "custom", "navigationStyle": "custom",
"usingComponents": { "usingComponents": {
"switch-popup": "/components/switchPopup/switchPopup" "switch-popup": "../../components/switchPopup/switchPopup"
} }
} }
// components/show-modal/index.js
let app = getApp()
/****
* 功能名称:自定义弹框 (支持三个按钮)
* show:false @description 默认false,true弹框展示
* custom:false @description 默认false,true弹框内容自定义
* title:'' @description 弹框内容文案
* btns:[] @description 弹框按钮文案,最多支持三个
* cntMarginTop:550 @description 弹框距离顶部的距离rpx
* btnBorder:true
* btnTextColor:[] @description 弹框按钮字体颜色,最多支持三个
* tapTitle:"" 顶部标题
* tabTitleShow:false 顶部标题是否展示
* binddidClickBtn="onClickModalBtn" 外面通过e.detail获取,值为按钮所在位置的索引 0/1/2
* onClickModalBtn(e) {
console.log(e.detail)
}
*
*
* 案例
* <show-modal show="{{canShow}}" title="这是一个弹框" btns="{{['取消','确定']}}" binddidClickBtn="onClickModalBtn"></show-modal>
*
* 案例 custom:true
<show-modal show="{{canShow}}" custom="{{true}}" btns="{{['取消','确定']}}" binddidClickBtn="onClickModalBtn">
<view>这是一个弹框</view>
</show-modal>
*/
Component({
// 属性
properties: {
// 弹层开关
show: {
type: Boolean, //目前接受的类型包括:String, Number, Boolean, Object, Array, null(表示任意类型)
value: false, // 默认值
observer(newVal, oldVal) {
if (newVal) {
this.createMaskAnimate(true)
} else {
this.createMaskAnimate(false)
}
}
},
// 是否内容自定义
custom: {
type: Boolean,
value: false
},
// 弹框内容
title: {
type: String,
value: '这是一个弹框'
},
// 按钮文字内容
btns: {
type: Array,
value: ['取消', '确定'] // 默认值
},
// 弹框距离顶部距离
cntMarginTop: {
type: Number,
value: 550 // 默认值
},
// 按钮文字颜色
btnTextColor: {
type: Array,
value: ['#A2A2A8', '#333333', '#303030'], // 默认值
observer(newVal, oldVal) {
if (!newVal && !newVal.length && newVal.length != 3) {
this._btnTextColor = ['#A2A2A8', '#333333', '#303030']
} else {
this._btnTextColor = newVal
}
}
},
// 按钮边框线
btnBorder: {
type: Boolean,
value: true
},
//标题是否显示
tabTitleShow: {
type: Boolean,
value: true
},
// 标题
tapTitle: {
type: String,
value: '提示信息'
}
},
// 初始化数据
data: {
_show: false,
_btnTextColor: ['#A2A2A8', '#333333', '#303030'],
maskAnimate: [],
frameAnimate: [],
title: '', // 提示弹框
success: () => {}, // 成功
error: () => {} // 失败
},
lifetimes: {
attached: function () {
function success() {} // 成功
function error() {}
},
detached: function () {
// 在组件实例被从页面节点树移除时执行
}
},
methods: {
selectMask: function (e) {
this.setData({
show: !this.data.show
})
},
shareBtn: function (e) {
let type = e.currentTarget.dataset.type
const that = this
console.log(type)
this.triggerEvent('didClickBtn', type) // 外面通过e.detail获取index的值
},
// 选中底部的按钮
selectBtn: function (e) {
let that = this
this.setData(
{
show: false
},
() => {
that.data.success()
}
)
// if (index == 0) {
// this.setData(
// {
// show: false
// },
// () => {
// that.data.error()
// }
// )
// } else {
// }
},
move: function () {
return
},
showModal: function (params) {
let { success, error } = this
this.setData({
show: !this.data.show,
title: params.title,
tabTitleShow: params.tabTitleShow,
success: params.success || function () {},
error: params.error || function () {}
})
},
//动画-遮罩层淡入淡出
createMaskAnimate(currentStatu) {
if (currentStatu) {
this.setData({
_show: currentStatu
})
this.createframeAnimate(true)
} else {
setTimeout(() => {
this.setData({
_show: false
})
}, 300)
this.createframeAnimate(false)
}
let maskAnimate = wx.createAnimation({
duration: 300,
timingFunction: 'ease-in-out',
delay: 0
})
this.maskAnimate = maskAnimate
maskAnimate.opacity(currentStatu ? 0.7 : 0).step()
setTimeout(() => {
this.setData({
maskAnimate: maskAnimate.export()
})
}, 50)
},
//动画-弹层内容Q弹
createframeAnimate(currentStatu) {
// return
let frameAnimate = wx.createAnimation({
duration: 300,
timingFunction: 'ease',
delay: 0
})
this.frameAnimate = frameAnimate
frameAnimate
.translate('-50%', '-50%')
.opacity(currentStatu ? 0.5 : 1)
.step()
// .scale(currentStatu ? 1.05 : 1)
this.setData({
frameAnimate: frameAnimate.export()
})
setTimeout(() => {
// 执行第二组动画
frameAnimate
.opacity(currentStatu ? 1 : 0)
.scale(currentStatu ? 1 : 0.9)
.step()
// 给数据对象储存的第一组动画,更替为执行完第二组动画的动画对象
this.setData({
frameAnimate: frameAnimate.export()
})
}, 150)
}
}
})
{ {
"component": true, "component": true,
"usingComponents": { "switch-block": "../switchBlock/switchBlock", "tab-popup": "../tabPopup/tabPopup" } "usingComponents": {}
} }
\ No newline at end of file \ No newline at end of file
<!-- components/show-modal/index.wxml -->
<view wx:if="{{_show}}" class='popV' catchtouchmove="move">
<view class='popV-mask' bindtap="selectMask" animation='{{maskAnimate}}' />
<!-- 动态修改top -->
<view class='popV-content' animation='{{frameAnimate}}'>
<view class="tap_title" wx:if="{{tabTitleShow}}">{{tapTitle}}</view>
<view class="popV-title" wx:if="{{title}}">{{title}}</view>
<slot wx:if="{{custom}}" />
<view class="popV-content-btm {{btnBorder?'border':''}}">
<!-- style="color:{{btnTextColor[index]?btnTextColor[index]:''}};" -->
<view class='popV-item' bindtap='shareBtn' data-type="wx">
<image class="img wximg " src="./images/wxIcon.png" />
转发
</view>
<view class='popV-item' bindtap='shareBtn' data-type="download">
<image class="img" src="./images/downloadIcon.png" />
保存
</view>
<!-- <view
wx:for="{{btns}}"
wx:key="index"
data-index="{{index}}"
class='popV-item'
hover-class='popV-hover'
bindtap='selectBtn'>
{{item}}
</view> -->
</view>
<image
class="closeIcon"
src="./images/closeIcon.png"
data-type="close"
bindtap='selectBtn'
bindload="" />
</view>
</view>
/* components/show-modal/index.wxss */
.popV {
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
z-index: 999;
width: 100vw;
height: 100vh;
}
.popV-mask {
position: absolute;
width: 100%;
height: 100%;
background: rgba(0, 0, 0);
opacity: 0;
display: block;
}
.popV-content {
position: absolute;
top: 50%;
left: 50%;
transform: translateY(-50%);
transform: translate(-50%);
/* width: 640rpx; */
background: white;
border-radius: 24rpx;
z-index: 1000;
display: flex;
flex-direction: column;
/* overflow: hidden; */
opacity: 1;
}
.popV-title {
box-sizing: border-box;
height: 100rpx;
/* height: 205rpx; */
/* line-height: 48rpx; */
border-bottom: 2rpx solid #EBEDF0;
display: flex;
justify-content: center;
align-items: center;
font-family: PingFangSC-Regular;
font-size: 32rpx;
color: #333333;
letter-spacing: -0rpx;
padding: 0 48rpx;
text-align: center;
}
/* 底部 */
.popV-content-btm {
height: 97rpx;
width: 100%;
left: 0;
bottom: 0;
display: flex;
flex-direction: row;
align-items: center;
padding: 48rpx;
box-sizing: border-box;
/* margin-bottom: 48rpx; */
}
.popV-content-btm.border {
border-top: 1px solid #EBEDF0;
}
.popV-item {
background: #F7F7F7;
border-radius: 36rpx;
padding: 16rpx 20rpx;
font-size: 28rpx;
color: #666666;
}
.img {
width: 40rpx;
height: 40rpx;
margin-right: 8rpx;
}
.wximg {
width: 50rpx;
}
.popV-item:nth-last-child(1) {
margin-left: 20rpx;
}
.closeIcon {
position: absolute;
width: 60rpx;
height: 60rpx;
bottom: -90rpx;
left: 50%;
transform: translateX(-50%);
}
/* .popV-item {
flex: 1;
font-size: 32rpx;
color: #333333;
opacity: 1;
height: 97rpx;
line-height: 97rpx;
font-family: PingFangSC-Medium;
text-align: center;
letter-spacing: 0;
box-sizing: border-box;
overflow: hidden;
align-items: center;
}
.border .popV-item:nth-last-child(1) {
border-left: 1px solid #EBEDF0;
}
.popV-item:nth-last-child(1) {
color: #3582EE;
} */
/* .popV-item~.popV-item {
margin-left: 48rpx;
} */
/* .popV-hover {
background: #DDD;
} */
.tap_title {
text-align: center;
font-family: PingFangSC-Medium;
font-size: 36rpx;
color: #303030;
letter-spacing: 0;
margin-top: 64rpx;
font-weight: 700;
}
\ No newline at end of file \ No newline at end of file
{ {
"navigationStyle": "custom", "navigationStyle": "custom",
"usingComponents": { "usingComponents": {
"shareModal": "../components/shareModal/shareModal" "shareModal": "../../components/shareModal/shareModal"
} }
} }
{ {
"navigationStyle": "custom", "navigationStyle": "custom",
"usingComponents": { "usingComponents": {
"CalendarMonth": "../components/CalendarMonth/CalendarMonth" "CalendarMonth": "../../components/CalendarMonth/CalendarMonth"
} }
} }
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!