customModal.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. <template>
  2. <view style="border-radius: 16upx">
  3. <view class="modal-box" style="padding-right: 16px;padding-left: 16px"
  4. :class="[isVisibility?'show':'', buttom?'bottom-modal':'' ]" @tap="ClickMaskClose"
  5. @touchmove.stop.prevent="moveHandleStop">
  6. <!-- 默认弹窗 -->
  7. <view class="dialog" v-if="!buttom" @tap.stop="contentClick">
  8. <view :class="contentClass">
  9. <slot></slot>
  10. </view>
  11. <view class="simple-bar has-bordert" v-if="showConfirmButton == true || showCancelButton == true">
  12. <view class='action has-mg-0 flex-sub text-green' v-if="showCancelButton == true"
  13. @tap.stop='handleClose'>{{cancelButtonText}}
  14. </view>
  15. <view class='action has-mg-0 flex-sub has-borderl' v-if="showConfirmButton == true"
  16. @tap.stop='handleConfirm'>{{confirmButtonText}}
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 底部弹窗 -->
  21. <view class="dialog" v-if="buttom" @tap.stop="contentClick">
  22. <view class="simple-bar has-bordert" v-if="showConfirmButton == true || showCancelButton == true">
  23. <view class='action is-black' v-if="showCancelButton == true" @tap.stop='handleClose'>
  24. {{cancelButtonText}}
  25. </view>
  26. <view class='action is-blue' v-if="showConfirmButton == true" @tap.stop='handleConfirm'>
  27. {{confirmButtonText}}
  28. </view>
  29. </view>
  30. <view :class="contentClass">
  31. <slot></slot>
  32. </view>
  33. </view>
  34. </view>
  35. </view>
  36. </template>
  37. <script>
  38. /**
  39. * 自定义弹窗内容组件
  40. * 使用方法:
  41. * 1.引入组件:import simpleModal from '@/components/simple-pro/customModal.vue';
  42. * 2.定义:components ,simpleModal
  43. * 3.页面使用:<simpleModal ref="simpleModal">这里面可以写你的自定义内容哟~</simpleModal>
  44. * 4.指定方法 this.$refs.simpleModal.func();
  45. *
  46. * 自定义方法:
  47. * 1. alert() ; 支持在方法中传入 object 更改内容 该方法仅弹出一个按钮 (如果传入了object参数 其中的参数值优先级最高)
  48. * 2. hide();
  49. */
  50. export default {
  51. props: {
  52. buttom: {
  53. // 是否底部弹出
  54. type: Boolean,
  55. default: false
  56. },
  57. contentClass: {
  58. // 弹窗默认样式
  59. type: String,
  60. default: "has-bg-white"
  61. }
  62. },
  63. data() {
  64. return {
  65. showConfirmButton: true, // 确认按钮
  66. showCancelButton: false, // 取消按钮
  67. confirmButtonText: "确定",// 确定按钮文字
  68. cancelButtonText: "取消",//取消按钮文字
  69. isVisibility: false, //是否显示
  70. };
  71. },
  72. methods: {
  73. __setconfig: function (options) {
  74. if (options != undefined && (typeof options == "object")) {
  75. if (options['showConfirmButton'] != undefined) this.showConfirmButton = options['showConfirmButton'];
  76. if (options['showCancelButton'] != undefined) this.showCancelButton = options['showCancelButton'];
  77. if (options['confirmButtonText'] != undefined) this.confirmButtonText = options['confirmButtonText'];
  78. if (options['cancelButtonText'] != undefined) this.cancelButtonText = options['cancelButtonText'];
  79. if (options['isVisibility'] != undefined) this.isVisibility = options['isVisibility'];
  80. if (options['contentClass'] != undefined) this.contentClass = options['contentClass'];
  81. }
  82. },
  83. show: function (options) {
  84. // 传入 object 参数 动态修改
  85. this.__setconfig(options);
  86. this.isVisibility = true;
  87. },
  88. hide: function () {
  89. this.isVisibility = false;
  90. },
  91. handleClose: function () {
  92. this.isVisibility = false;
  93. this.$emit('cancelButton');
  94. },
  95. handleConfirm: function () {
  96. this.$emit('confirmButton');
  97. },
  98. ClickMaskClose: function () {
  99. // 点击背景 or 内容时执行关闭 有坑 点击内容的时候也会关闭,
  100. this.$emit('maskClose');
  101. },
  102. contentClick: function (e) {
  103. this.$emit('contentClick');
  104. },
  105. moveHandleStop: function () {
  106. }
  107. }
  108. }
  109. </script>
  110. <style>
  111. </style>