|
| 1 | +import validator from '../behaviors/validator'; |
| 2 | +import zIndex from '../behaviors/zIndex'; |
| 3 | +const detail = true; |
| 4 | +const option = { bubbles: true, composed: true }; |
| 5 | + |
| 6 | +Component({ |
| 7 | + /** |
| 8 | + * 组件的属性列表 |
| 9 | + */ |
| 10 | + behaviors: [zIndex, validator], |
| 11 | + externalClasses: ['l-class', 'l-panel-class', 'l-bg-class'], |
| 12 | + properties: { |
| 13 | + // 显示与隐藏 |
| 14 | + show: { |
| 15 | + type: Boolean, |
| 16 | + value: false |
| 17 | + }, |
| 18 | + // 最大高度 |
| 19 | + maxHeight: { |
| 20 | + type: Number, |
| 21 | + value: 600 |
| 22 | + }, |
| 23 | + // 最小高度 |
| 24 | + minHeight: { |
| 25 | + type: Number, |
| 26 | + value: 200 |
| 27 | + }, |
| 28 | + // 顶部弧度 |
| 29 | + arcRadius: { |
| 30 | + type: Number, |
| 31 | + value: 18 |
| 32 | + }, |
| 33 | + // 动画效果的显示和隐藏 |
| 34 | + transition: { |
| 35 | + type: Boolean, |
| 36 | + value: true |
| 37 | + }, |
| 38 | + // 锁定 |
| 39 | + locked: { |
| 40 | + type: Boolean, |
| 41 | + value: false |
| 42 | + }, |
| 43 | + // 背景透明度 |
| 44 | + opacity: { |
| 45 | + type: Number, |
| 46 | + value: 0.4 |
| 47 | + }, |
| 48 | + // 弹出方向 |
| 49 | + direction: { |
| 50 | + type: String, |
| 51 | + options: ['top', 'bottom'], |
| 52 | + value: 'bottom' |
| 53 | + } |
| 54 | + }, |
| 55 | + |
| 56 | + /** |
| 57 | + * 组件的初始数据 |
| 58 | + */ |
| 59 | + data: { |
| 60 | + _arcRadiusTop: 12, |
| 61 | + _ardRadiusBottom: 18, |
| 62 | + arcStyle: '' |
| 63 | + }, |
| 64 | + |
| 65 | + /** |
| 66 | + * 侦听器 |
| 67 | + */ |
| 68 | + observers: { |
| 69 | + 'show': function (show) { |
| 70 | + if (show) { |
| 71 | + this.triggerEvent('linshow', detail, option); |
| 72 | + this.getArcPopupStyle(); |
| 73 | + } else { |
| 74 | + this.triggerEvent('linclose', detail, option); |
| 75 | + } |
| 76 | + }, |
| 77 | + 'arcRadius': function (arcRadius) { |
| 78 | + if (this.properties.direction === 'top') { |
| 79 | + this.data._arcRadiusTop = arcRadius |
| 80 | + } else { |
| 81 | + this.data._ardRadiusBottom = arcRadius |
| 82 | + } |
| 83 | + this.getArcPopupStyle(); |
| 84 | + } |
| 85 | + }, |
| 86 | + |
| 87 | + pageLifetimes: { |
| 88 | + show() { |
| 89 | + this._init(); |
| 90 | + }, |
| 91 | + }, |
| 92 | + |
| 93 | + /** |
| 94 | + * 组件的方法列表 |
| 95 | + */ |
| 96 | + methods: { |
| 97 | + _init() { |
| 98 | + wx.lin = wx.lin || {}; |
| 99 | + wx.lin.showArcPopup = (options) => { |
| 100 | + const { |
| 101 | + zIndex = 99, |
| 102 | + tranistion = true, |
| 103 | + direction = 'bottom', |
| 104 | + locked = false |
| 105 | + } = { ...options }; |
| 106 | + this.setData({ |
| 107 | + zIndex, |
| 108 | + tranistion, |
| 109 | + direction, |
| 110 | + locked, |
| 111 | + show: true |
| 112 | + }); |
| 113 | + }; |
| 114 | + wx.lin.hideArcPopup = () => { |
| 115 | + this.setData({ |
| 116 | + show: false |
| 117 | + }); |
| 118 | + }; |
| 119 | + }, |
| 120 | + getArcPopupStyle() { |
| 121 | + const direction = this.properties.direction |
| 122 | + const arcRadiusTop = this.data._arcRadiusTop |
| 123 | + const ardRadiusBottom = this.data._ardRadiusBottom |
| 124 | + const maxHeight = this.properties.maxHeight |
| 125 | + const minHeight = this.properties.minHeight |
| 126 | + const style = ` |
| 127 | + border-bottom-left-radius:${direction === 'top' ? arcRadiusTop : 0}rpx; |
| 128 | + border-bottom-right-radius:${direction === 'top' ? arcRadiusTop : 0}rpx; |
| 129 | + border-top-left-radius:${direction === 'bottom' ? ardRadiusBottom : 0}rpx; |
| 130 | + border-top-right-radius:${direction === 'bottom' ? ardRadiusBottom : 0}rpx; |
| 131 | + max-height:${maxHeight}rpx; |
| 132 | + min-height:${minHeight}rpx; |
| 133 | + ` |
| 134 | + this.setData({ |
| 135 | + arcStyle: style |
| 136 | + }) |
| 137 | + }, |
| 138 | + onArcPopupTap() { |
| 139 | + if (this.data.locked) { |
| 140 | + return |
| 141 | + } |
| 142 | + if (this.properties.show) { |
| 143 | + this.setData({ |
| 144 | + show: false |
| 145 | + }) |
| 146 | + } |
| 147 | + } |
| 148 | + }, |
| 149 | + |
| 150 | + ready() { |
| 151 | + this.getArcPopupStyle(); |
| 152 | + } |
| 153 | +}) |
0 commit comments