123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491 |
- <template>
- <view
- v-if="visibleSync"
- class="tn-popup-class tn-popup"
- :style="[customStyle, popupStyle, { zIndex: elZIndex - 1}]"
- hover-stop-propagation
- >
-
- <view
- class="tn-popup__mask"
- :class="[{'tn-popup__mask--show': showPopup && mask}]"
- :style="{zIndex: elZIndex - 2}"
- @tap="maskClick"
- @touchmove.stop.prevent = "() => {}"
- hover-stop-propagation
- ></view>
-
- <view
- class="tn-popup__content"
- :class="[
- mode !== 'center' ? backgroundColorClass : '',
- safeAreaInsetBottom ? 'tn-safe-area-inset-bottom' : '',
- 'tn-popup--' + mode,
- showPopup ? 'tn-popup__content--visible' : '',
- zoom && mode === 'center' ? 'tn-popup__content__center--animation-zoom' : ''
- ]"
- :style="[contentStyle]"
- @tap="modeCenterClose"
- @touchmove.stop.prevent
- @tap.stop.prevent
- >
-
- <view
- v-if="mode === 'center'"
- class="tn-popup__content__center_box"
- :class="[backgroundColorClass]"
- :style="[centerStyle]"
- @touchmove.stop.prevent
- @tap.stop.prevent
- >
-
- <view
- v-if="closeBtn"
- class="tn-popup__close"
- :class="[`tn-icon-${closeBtnIcon}`, `tn-popup__close--${closeBtnPosition}`]"
- :style="[closeBtnStyle, {zIndex: elZIndex}]"
- @tap="close"
- ></view>
- <scroll-view class="tn-popup__content__scroll-view">
- <slot></slot>
- </scroll-view>
- </view>
-
-
- <scroll-view v-else class="tn-popup__content__scroll-view">
- <slot></slot>
- </scroll-view>
-
- <view
- v-if="mode !== 'center' && closeBtn"
- class="tn-popup__close"
- :class="[`tn-popup__close--${closeBtnPosition}`]"
- :style="{zIndex: elZIndex}"
- @tap="close"
- >
- <view :class="[`tn-icon-${closeBtnIcon}`]" :style="[closeBtnStyle]"></view>
- </view>
- </view>
- </view>
- </template>
- <script>
- import componentsColorMixin from '../../libs/mixin/components_color.js'
- export default {
- mixins: [componentsColorMixin],
- name: 'tn-popup',
- props: {
- value: {
- type: Boolean,
- default: false
- },
-
-
- mode: {
- type: String,
- default: 'left'
- },
-
- mask: {
- type: Boolean,
- default: true
- },
-
- length: {
- type: [Number, String],
- default: 'auto'
- },
-
-
- width: {
- type: String,
- default: ''
- },
-
-
- height: {
- type: String,
- default: ''
- },
-
- zoom: {
- type: Boolean,
- default: true
- },
-
- safeAreaInsetBottom: {
- type: Boolean,
- default: false
- },
-
- maskCloseable: {
- type: Boolean,
- default: true
- },
-
- customStyle: {
- type: Object,
- default() {
- return {}
- }
- },
-
- borderRadius: {
- type: Number,
- default: 0
- },
-
- zIndex: {
- type: Number,
- default: 0
- },
-
- closeBtn: {
- type: Boolean,
- default: false
- },
-
- closeBtnIcon: {
- type: String,
- default: 'close'
- },
-
-
- closeBtnPosition: {
- type: String,
- default: 'top-right'
- },
-
- closeIconColor: {
- type: String,
- default: '#AAAAAA'
- },
-
- closeIconSize: {
- type: Number,
- default: 30
- },
-
- negativeTop: {
- type: Number,
- default: 0
- },
-
- marginTop: {
- type: Number,
- default: 0
- },
-
-
- popup: {
- type: Boolean,
- default: true
- },
- },
- computed: {
-
- popupStyle() {
- let style = {}
- if ((this.mode === 'top' || this.mode === 'left' || this.mode === 'right') && this.marginTop) {
- style.marginTop = this.$t.string.getLengthUnitValue(this.marginTop, 'px')
- }
-
- return style
- },
-
- contentStyle() {
- let style = {}
-
- if (this.mode === 'left' || this.mode === 'right') {
- style = {
- width: this.width ? this.$t.string.getLengthUnitValue(this.width) : this.$t.string.getLengthUnitValue(this.length),
- height: '100%',
- transform: `translate3D(${this.mode === 'left' ? '-100%' : '100%'}, 0px, 0px)`
- }
- } else if (this.mode === 'top' || this.mode === 'bottom') {
- style = {
- width: '100%',
- height: this.height ? this.$t.string.getLengthUnitValue(this.height) : this.$t.string.getLengthUnitValue(this.length),
- transform: `translate3D(0px, ${this.mode === 'top' ? '-100%': '100%'}, 0px)`
- }
- }
- style.zIndex = this.elZIndex
-
- if (this.borderRadius) {
- switch(this.mode) {
- case 'left':
- style.borderRadius = `0 ${this.borderRadius}rpx ${this.borderRadius}rpx 0`
- break
- case 'top':
- style.borderRadius = `0 0 ${this.borderRadius}rpx ${this.borderRadius}rpx`
- break
- case 'right':
- style.borderRadius = `${this.borderRadius}rpx 0 0 ${this.borderRadius}rpx`
- break
- case 'bottom':
- style.borderRadius = `${this.borderRadius}rpx ${this.borderRadius}rpx 0 0`
- break
- }
- style.overflow = 'hidden'
- }
-
- if (this.backgroundColorStyle && this.mode !== 'center') {
- style.backgroundColor = this.backgroundColorStyle
- }
-
- return style
- },
-
- centerStyle() {
- let style = {}
- style.width = this.width ? this.$t.string.getLengthUnitValue(this.width) : this.$t.string.getLengthUnitValue(this.length)
-
- style.height = this.height ? this.$t.string.getLengthUnitValue(this.height) : 'auto'
- style.zIndex = this.elZIndex
- if (this.negativeTop) {
- style.marginTop = `-${this.$t.string.getLengthUnitValue(this.negativeTop)}`
- }
- if (this.borderRadius) {
- style.borderRadius = `${this.borderRadius}rpx`
- style.overflow='hidden'
- }
- if (this.backgroundColorStyle) {
- style.backgroundColor = this.backgroundColorStyle
- }
- return style
- },
-
- closeBtnStyle() {
- let style = {}
- if (this.closeIconColor) {
- style.color = this.closeIconColor
- }
- if (this.closeIconSize) {
- style.fontSize = this.closeIconSize + 'rpx'
- }
-
- return style
- },
- elZIndex() {
- return this.zIndex ? this.zIndex : this.$t.zIndex.popup
- }
- },
- data() {
- return {
- timer: null,
- visibleSync: false,
- showPopup: false,
- closeFromInner: false
- }
- },
- watch: {
- value(val) {
- if (val) {
-
- if (this.visibleSync) {
- this.visibleSync = false
- return
- }
- this.open()
- } else if (!this.closeFromInner) {
- this.close()
- }
- this.closeFromInner = false
- }
- },
- mounted() {
-
- this.value && this.open()
- },
- methods: {
-
- maskClick() {
- if (!this.maskCloseable) return
- this.close()
- },
- open() {
- this.change('visibleSync', 'showPopup', true)
- },
-
- close() {
-
-
- this.closeFromInner = true
- this.change('showPopup', 'visibleSync', false)
- },
-
-
- modeCenterClose() {
- if (this.mode != 'center' || !this.maskCloseable) return
- this.close()
- },
-
-
- change(param1, param2, status) {
-
- if (this.popup === true) {
- this.$emit('input', status)
- }
- this[param1] = status
- if (status) {
-
- this.timer = setTimeout(() => {
- this[param2] = status
- this.$emit(status ? 'open' : 'close')
- clearTimeout(this.timer)
- }, 10)
-
-
- this.$nextTick(() => {
- this[param2] = status
- this.$emit(status ? 'open' : 'close')
- })
-
- } else {
- this.timer = setTimeout(() => {
- this[param2] = status
- this.$emit(status ? 'open' : 'close')
- clearTimeout(this.timer)
- }, 250)
- }
- }
- }
- }
- </script>
- <style lang="scss" scoped>
-
- .tn-popup {
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- overflow: hidden;
-
- &__content {
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- position: absolute;
- transition: all 0.25s linear;
-
- &--visible {
- transform: translate3D(0px, 0px, 0px) !important;
- &.tn-popup--center {
- transform: scale(1);
- opacity: 1;
- }
- }
-
- &__center_box {
- min-width: 100rpx;
- min-height: 100rpx;
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- position: relative;
- background-color: #FFFFFF;
- }
-
- &__scroll-view {
- width: 100%;
- height: 100%;
- }
-
- &__center--animation-zoom {
- transform: scale(1.15);
- }
- }
-
- &__scroll_view {
- width: 100%;
- height: 100%;
- }
-
- &--left {
- top: 0;
- bottom: 0;
- left: 0;
- background-color: #FFFFFF;
- }
-
- &--right {
- top: 0;
- bottom: 0;
- right: 0;
- background-color: #FFFFFF;
- }
-
- &--top {
- left: 0;
- right: 0;
- top: 0;
- background-color: #FFFFFF;
- }
-
- &--bottom {
- left: 0;
- right: 0;
- bottom: 0;
- background-color: #FFFFFF;
- }
-
- &--center {
- display: flex;
- flex-direction: column;
- bottom: 0;
- top: 0;
- left: 0;
- right: 0;
- justify-content: center;
- align-items: center;
- opacity: 0;
- }
-
- &__close {
- position: absolute;
-
- &--top-left {
- top: 30rpx;
- left: 30rpx;
- }
-
- &--top-right {
- top: 30rpx;
- right: 30rpx;
- }
-
- &--bottom-left {
- bottom: 30rpx;
- left: 30rpx;
- }
-
- &--bottom-right {
- bottom: 30rpx;
- right: 30rpx;
- }
- }
-
- &__mask {
- width: 100%;
- height: 100%;
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- border: 0;
- background-color: $tn-mask-bg-color;
- transition: 0.25s linear;
- transition-property: opacity;
- opacity: 0;
-
- &--show {
- opacity: 1;
- }
- }
- }
- </style>
|