c-modal.vue 2.3 KB

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