| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <template>
- <div class="nut-actionsheet">
- <transition :name="isAnimation?'nutFade':''" v-if="isShowMask">
- <div class="nut-actionsheet-mask"
- @click="clickActionSheetMask"
- v-show="isVisible"
- ></div>
- </transition>
- <transition :name="isAnimation?'nutSlideUp':''">
- <div class="nut-actionsheet-panel"
- v-show="isVisible"
- >
- <div class="nut-actionsheet-custom" slot-scope>
- <slot name="custom" ></slot>
- </div>
- <dl class="nut-actionsheet-modal" v-if="$slots.title || $slots.subTitle ">
- <dt class="nut-actionsheet-title"><slot name="title" slot-scope></slot></dt>
- <dd class="nut-actionsheet-sub-title"><slot name="sub-title" slot-scope></slot></dd>
- </dl>
- <ul class="nut-actionsheet-menu" >
- <li class="nut-actionsheet-item"
- :class="{'nut-actionsheet-item-active': isHighlight(item), 'nut-actionsheet-item-disabled': item.disable}"
- v-for="(item, index) of menuItems"
- :key="index"
- @click="chooseItem(item, index)"
- >{{item[optionTag]}}</li>
- </ul>
- <div class="nut-actionsheet-cancel"
- v-if="cancelTxt"
- @click="cancelActionSheet"
- >{{cancelTxt}}</div>
- </div>
- </transition>
- </div>
- </template>
- <script>
- export default {
- name:'nut-actionsheet',
- props: {
- isAnimation: {
- type: Boolean,
- default: true
- },
- isLockBgScroll: {
- type: Boolean,
- default: false
- },
- isVisible: {
- type: Boolean,
- default: false
- },
- isShowMask: {
- type: Boolean,
- default: true
- },
- isClickChooseClose: {
- type: Boolean,
- default: true
- },
- isClickCloseMask: {
- type: Boolean,
- default: true
- },
- cancelTxt: {
- type: String,
- default: ''
- },
- optionTag: {
- type: String,
- default: 'name'
- },
- chooseTagValue: {
- type: String,
- default: ''
- },
- menuItems: {
- type: Array,
- default: () => []
- }
- },
- data() {
- return {};
- },
- watch: {
- isVisible (value) {
- !!value && this.$emit('open');
- if (this.isLockBgScroll) {
- if (value) {
- document.body.classList.add('nut-overflow-hidden');
- } else {
- document.body.classList.remove('nut-overflow-hidden');
- }
- }
- }
- },
- methods: {
- isHighlight(item) {
- return (this.chooseTagValue && this.chooseTagValue == item[this.optionTag]) || this.chooseTagValue === 0;
- },
- closeActionSheet() {
- this.$emit('close');
- },
- cancelActionSheet() {
- this.closeActionSheet();
- this.$emit('cancel');
- },
- clickActionSheetMask() {
- this.isClickCloseMask && this.closeActionSheet();
- },
- chooseItem(item, index) {
- if (!item.disable) {
- if (this.isClickChooseClose) {
- this.closeActionSheet();
- }
- this.$emit('choose', item, index);
- }
- }
- }
- }
- </script>
|