123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456 |
- <template>
- <view v-if="visibleSync" :style="[customStyle, {
- zIndex: uZindex - 1
- }]" class="u-drawer" hover-stop-propagation>
- <u-mask :duration="duration" :custom-style="maskCustomStyle" :maskClickAble="maskCloseAble" :z-index="uZindex - 2" :show="showDrawer && mask" @click="maskClick"></u-mask>
- <view
- class="u-drawer-content"
- @tap="modeCenterClose(mode)"
- :class="[
- safeAreaInsetBottom ? 'safe-area-inset-bottom' : '',
- 'u-drawer-' + mode,
- showDrawer ? 'u-drawer-content-visible' : '',
- zoom && mode == 'center' ? 'u-animation-zoom' : ''
- ]"
- @touchmove.stop.prevent
- @tap.stop.prevent
- :style="[style]"
- >
- <view class="u-mode-center-box" @tap.stop.prevent @touchmove.stop.prevent v-if="mode == 'center'" :style="[centerStyle]">
- <u-icon
- @click="close"
- v-if="closeable"
- class="u-close"
- :class="['u-close--' + closeIconPos]"
- :name="closeIcon"
- :color="closeIconColor"
- :size="closeIconSize"
- ></u-icon>
- <scroll-view class="u-drawer__scroll-view" scroll-y="true">
- <slot />
- </scroll-view>
- </view>
- <scroll-view class="u-drawer__scroll-view" scroll-y="true" v-else>
- <slot />
- </scroll-view>
- <view @tap="close" class="u-close" :class="['u-close--' + closeIconPos]">
- <u-icon
- v-if="mode != 'center' && closeable"
- :name="closeIcon"
- :color="closeIconColor"
- :size="closeIconSize"
- ></u-icon>
- </view>
- </view>
- </view>
- </template>
- <script>
- export default {
- name: 'u-popup',
- props: {
-
- show: {
- type: Boolean,
- default: false
- },
-
- mode: {
- type: String,
- default: 'left'
- },
-
- mask: {
- type: Boolean,
- default: true
- },
-
-
- length: {
- type: [Number, String],
- default: 'auto'
- },
-
- zoom: {
- type: Boolean,
- default: true
- },
-
- safeAreaInsetBottom: {
- type: Boolean,
- default: false
- },
-
- maskCloseAble: {
- type: Boolean,
- default: true
- },
-
- customStyle: {
- type: Object,
- default() {
- return {};
- }
- },
- value: {
- type: Boolean,
- default: false
- },
-
-
- popup: {
- type: Boolean,
- default: true
- },
-
- borderRadius: {
- type: [Number, String],
- default: 0
- },
- zIndex: {
- type: [Number, String],
- default: ''
- },
-
- closeable: {
- type: Boolean,
- default: false
- },
-
- closeIcon: {
- type: String,
- default: 'close'
- },
-
- closeIconPos: {
- type: String,
- default: 'top-right'
- },
-
- closeIconColor: {
- type: String,
- default: '#909399'
- },
-
- closeIconSize: {
- type: [String, Number],
- default: '30'
- },
-
-
- width: {
- type: String,
- default: ''
- },
-
-
- height: {
- type: String,
- default: ''
- },
-
- negativeTop: {
- type: [String, Number],
- default: 0
- },
-
- maskCustomStyle: {
- type: Object,
- default() {
- return {}
- }
- },
-
- duration: {
- type: [String, Number],
- default: 250
- }
- },
- data() {
- return {
- visibleSync: false,
- showDrawer: false,
- timer: null,
- closeFromInner: false,
- };
- },
- computed: {
-
- style() {
- let style = {};
-
- if (this.mode == 'left' || this.mode == 'right') {
- style = {
- width: this.width ? this.getUnitValue(this.width) : this.getUnitValue(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.getUnitValue(this.height) : this.getUnitValue(this.length),
- transform: `translate3D(0px,${this.mode == 'top' ? '-100%' : '100%'},0px)`
- };
- }
- style.zIndex = this.uZindex;
-
- 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;
- default:
- }
-
- style.overflow = 'hidden';
- }
- if(this.duration) style.transition = `all ${this.duration / 1000}s linear`;
- return style;
- },
-
- centerStyle() {
- let style = {};
- style.width = this.width ? this.getUnitValue(this.width) : this.getUnitValue(this.length);
-
- style.height = this.height ? this.getUnitValue(this.height) : 'auto';
- style.zIndex = this.uZindex;
- style.marginTop = `-${this.$u.addUnit(this.negativeTop)}`;
- if (this.borderRadius) {
- style.borderRadius = `${this.borderRadius}rpx`;
-
- style.overflow = 'hidden';
- }
- return style;
- },
-
- uZindex() {
- return this.zIndex ? this.zIndex : this.$u.zIndex.popup;
- }
- },
- watch: {
- value(val) {
- if (val) {
- this.open();
- } else if(!this.closeFromInner) {
- this.close();
- }
- this.closeFromInner = false;
- }
- },
- mounted() {
-
- this.value && this.open();
- },
- methods: {
-
- getUnitValue(val) {
- if(/(%|px|rpx|auto)$/.test(val)) return val;
- else return val + 'rpx'
- },
-
- maskClick() {
- this.close();
- },
- close() {
-
-
- this.closeFromInner = true;
- this.change('showDrawer', 'visibleSync', false);
- },
-
-
- modeCenterClose(mode) {
- if (mode != 'center' || !this.maskCloseAble) return;
- this.close();
- },
- open() {
- this.change('visibleSync', 'showDrawer', true);
- },
-
-
- 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');
- }, 50);
-
-
- this.$nextTick(() => {
- this[param2] = status;
- this.$emit(status ? 'open' : 'close');
- })
-
- } else {
- this.timer = setTimeout(() => {
- this[param2] = status;
- this.$emit(status ? 'open' : 'close');
- }, this.duration);
- }
- }
- }
- };
- </script>
- <style scoped lang="scss">
- @import "../../libs/css/style.components.scss";
- .u-drawer {
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- position: fixed;
- top: 0;
- left: 0;
- right: 0;
- bottom: 0;
- overflow: hidden;
- }
- .u-drawer-content {
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- position: absolute;
- z-index: 1003;
- transition: all 0.25s linear;
- }
- .u-drawer__scroll-view {
- width: 100%;
- height: 100%;
- }
- .u-drawer-left {
- top: 0;
- bottom: 0;
- left: 0;
- background-color: #ffffff;
- }
- .u-drawer-right {
- right: 0;
- top: 0;
- bottom: 0;
- background-color: #ffffff;
- }
- .u-drawer-top {
- top: 0;
- left: 0;
- right: 0;
- background-color: #ffffff;
- }
- .u-drawer-bottom {
- bottom: 0;
- left: 0;
- right: 0;
- background-color: #ffffff;
- }
- .u-drawer-center {
- @include vue-flex;
- flex-direction: column;
- bottom: 0;
- left: 0;
- right: 0;
- top: 0;
- justify-content: center;
- align-items: center;
- opacity: 0;
- z-index: 99999;
- }
- .u-mode-center-box {
- min-width: 100rpx;
- min-height: 100rpx;
- /* #ifndef APP-NVUE */
- display: block;
- /* #endif */
- position: relative;
- background-color: #ffffff;
- }
- .u-drawer-content-visible.u-drawer-center {
- transform: scale(1);
- opacity: 1;
- }
- .u-animation-zoom {
- transform: scale(1.15);
- }
- .u-drawer-content-visible {
- transform: translate3D(0px, 0px, 0px) !important;
- }
- .u-close {
- position: absolute;
- z-index: 3;
- }
- .u-close--top-left {
- top: 30rpx;
- left: 30rpx;
- }
- .u-close--top-right {
- top: 30rpx;
- right: 30rpx;
- }
- .u-close--bottom-left {
- bottom: 30rpx;
- left: 30rpx;
- }
- .u-close--bottom-right {
- right: 30rpx;
- bottom: 30rpx;
- }
- </style>
|