all files / packages/dialog/src/ dialog.vue

32% Statements 8/25
28.57% Branches 4/14
20% Functions 1/5
15.79% Lines 3/19
1 branch Ignored     
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86                                                                                                                                                                       
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
//
 
import Popup from 'src/mixins/popup';
 
const CANCEL_TEXT = '取消';
const CONFIRM_TEXT = '确认';
 
export default {
  name: 'zan-dialog',
 
  mixins: [Popup],
 
  props: {
    overlay: {
      default: true
    },
    closeOnClickOverlay: {
      default: true
    },
    lockOnScroll: {
      default: true
    }
  },
 
  data() {
    return {
      title: '',
      message: '',
      type: '',
      showConfirmButton: true,
      showCancelButton: false,
      confirmButtonText: CONFIRM_TEXT,
      cancelButtonText: CANCEL_TEXT,
      callback: null
    };
  },
 
  methods: {
    handleAction(action) {
      this.value = false;
      this.callback && this.callback(action);
    },
 
    close() {
      if (this.closing) return;
 
      this.closing = true;
 
      this.value = false;
 
      if (this.lockOnScroll) {
        setTimeout(() => {
          if (this.modal && this.bodyOverflow !== 'hidden') {
            document.body.style.overflow = this.bodyOverflow;
            document.body.style.paddingRight = this.bodyPaddingRight;
          }
          this.bodyOverflow = null;
          this.bodyPaddingRight = null;
        }, 200);
      }
 
      this.opened = false;
      this.doAfterClose();
    }
  }
};