c-modal.vue 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. <template>
  2. <u-modal
  3. v-model="visible"
  4. :show-confirm-button="false"
  5. :show-cancel-button="false"
  6. :show-title="false"
  7. :mask-close-able="maskCloseAble"
  8. @close="handleClose"
  9. >
  10. <view class="modal-container">
  11. <view class="wrapper">
  12. <view class="title" v-if="showTitle">{{ title }}</view>
  13. <view class="content">
  14. <slot></slot>
  15. </view>
  16. </view>
  17. <view class="buttons flex align-center justify-between">
  18. <view class="button cancel-button" v-if="showCancelButton" @click="handleCancel">{{ cancelButtonText }}</view>
  19. <view class="button confirm-button" v-if="showConfirmButton" @click="handleConfirm">{{ confirmButtonText }}</view>
  20. </view>
  21. </view>
  22. </u-modal>
  23. </template>
  24. <script>
  25. export default {
  26. name:"c-modal",
  27. props: {
  28. value: {
  29. type: Boolean,
  30. default: false
  31. },
  32. confirmButtonText: {
  33. type: String,
  34. default: '确定'
  35. },
  36. cancelButtonText: {
  37. type: String,
  38. default: '取消'
  39. },
  40. showConfirmButton: {
  41. type: Boolean,
  42. default: true
  43. },
  44. showCancelButton: {
  45. type: Boolean,
  46. default: true
  47. },
  48. title: {
  49. type: String,
  50. default: '提示'
  51. },
  52. showTitle: {
  53. type: Boolean,
  54. default: true
  55. },
  56. maskCloseAble: {
  57. type: Boolean,
  58. default: false
  59. }
  60. },
  61. computed: {
  62. // 处理 v-model 双向绑定
  63. visible: {
  64. get() {
  65. return this.value;
  66. },
  67. set(val) {
  68. this.$emit("input", val);
  69. }
  70. }
  71. },
  72. data() {
  73. return {};
  74. },
  75. methods: {
  76. handleCancel() {
  77. this.$emit('cancel')
  78. },
  79. handleConfirm() {
  80. this.$emit('confirm')
  81. },
  82. handleClose() {
  83. // 只有在mask-close-able未true时,点击遮罩才生效
  84. this.$emit('close')
  85. }
  86. }
  87. }
  88. </script>
  89. <style lang="scss" scoped>
  90. .modal-container {
  91. font-family: DM Sans;
  92. padding: 38rpx 40rpx 28rpx;
  93. .wrapper {
  94. .title {
  95. color: rgba(31, 44, 55, 1);
  96. font-size: 28rpx;
  97. font-weight: 500;
  98. line-height: 44rpx;
  99. margin-bottom: 16rpx;
  100. }
  101. .content {
  102. color: rgba(158, 158, 158, 1);
  103. font-size: 28rpx;
  104. font-weight: 400;
  105. line-height: 36rpx;
  106. min-height: 120rpx;
  107. margin-bottom: 40rpx;
  108. }
  109. }
  110. .buttons {
  111. gap: 16rpx;
  112. .button {
  113. flex: 1;
  114. height: 80rpx;
  115. border-radius: 80rpx;
  116. font-size: 32rpx;
  117. font-weight: 400;
  118. line-height: 80rpx;
  119. text-align: center;
  120. }
  121. .cancel-button {
  122. color: rgba(1, 107, 246, 1);
  123. background: rgba(1, 107, 246, 0.1);
  124. }
  125. .confirm-button {
  126. color: #fff;
  127. background: linear-gradient(90.00deg, rgba(13, 39, 247, 1),rgba(19, 193, 234, 1));
  128. }
  129. }
  130. }
  131. </style>