custom-modal.vue 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <script>
  2. export default {
  3. name: 'custom-modal',
  4. props: {
  5. content: String,
  6. cancelText: {
  7. type: String,
  8. default: '取消'
  9. },
  10. confirmText: {
  11. type: String,
  12. default: '确定'
  13. },
  14. // 主题色
  15. color: String,
  16. showBtn: {
  17. type: Boolean,
  18. default: true
  19. },
  20. showCancel: {
  21. type: Boolean,
  22. default: true
  23. },
  24. closeOnClickOverlay: {
  25. type: Boolean,
  26. default: true
  27. },
  28. modalWidth: {
  29. type: String,
  30. default: '500rpx'
  31. },
  32. zIndex: {
  33. type: [String, Number],
  34. default: 10075
  35. },
  36. overlayZIndex: {
  37. type: [Number, String],
  38. default: 10070
  39. },
  40. // 向上偏移
  41. offsetY: {
  42. type: Number,
  43. default: 0
  44. }
  45. },
  46. data() {
  47. return {
  48. show: false
  49. }
  50. },
  51. methods: {}
  52. }
  53. </script>
  54. <template>
  55. <u-popup
  56. :safeAreaInsetBottom="false"
  57. :show="show"
  58. round="10px"
  59. mode="center"
  60. @close="show = false"
  61. :customStyle="`padding:40rpx; width:${modalWidth};transform:translateY(-${offsetY}rpx)`"
  62. :zIndex="zIndex"
  63. :overlayZIndex="overlayZIndex"
  64. :closeOnClickOverlay="closeOnClickOverlay"
  65. >
  66. <slot>
  67. <u-text :text="content" size="30rpx" align="center" margin="60rpx 0"></u-text>
  68. </slot>
  69. <view class="flex flex-around" v-if="showBtn">
  70. <u-button
  71. v-if="showCancel"
  72. :text="cancelText"
  73. shape="circle"
  74. plain
  75. customStyle="width:210rpx;height:75rpx"
  76. @click="show = false"
  77. ></u-button>
  78. <u-button
  79. :style="{ flex: showCancel ? '' : '1' }"
  80. :color="color || 'var(--theme)'"
  81. :text="confirmText"
  82. shape="circle"
  83. customStyle="width:210rpx;height:75rpx"
  84. @click="$emit('confirm')"
  85. ></u-button>
  86. </view>
  87. </u-popup>
  88. </template>
  89. <style></style>