CustomModal.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <template>
  2. <u-modal :show="visible" :show-cancel-button="false" :show-confirm-button="false">
  3. <view class="modal-content">
  4. <view class="modal-header">
  5. <text class="modal-title">{{ title }}</text>
  6. </view>
  7. <view class="modal-body">
  8. <u-input v-model="localValue" :placeholder="placeholder" class="modal-input"></u-input>
  9. </view>
  10. <view class="modal-footer">
  11. <text @click="handleCancel" class="btn cancel-btn">取消</text>
  12. <text @click="handleConfirm" class="btn confirm-btn">确定</text>
  13. </view>
  14. </view>
  15. </u-modal>
  16. </template>
  17. <script>
  18. export default {
  19. name: 'CustomModal',
  20. props: {
  21. visible: {
  22. type: Boolean,
  23. default: false
  24. },
  25. title: {
  26. type: String,
  27. default: ''
  28. },
  29. value: {
  30. type: String,
  31. default: ''
  32. },
  33. placeholder: {
  34. type: String,
  35. default: ''
  36. }
  37. },
  38. data() {
  39. return {
  40. localValue: this.value
  41. }
  42. },
  43. watch: {
  44. value(newVal) {
  45. this.localValue = newVal
  46. },
  47. visible(newVal) {
  48. if (newVal) {
  49. this.localValue = this.value
  50. }
  51. }
  52. },
  53. methods: {
  54. handleCancel() {
  55. this.$emit('cancel')
  56. },
  57. handleConfirm() {
  58. this.$emit('confirm', this.localValue)
  59. }
  60. }
  61. }
  62. </script>
  63. <style scoped>
  64. .modal-content {
  65. display: flex;
  66. flex-direction: column;
  67. gap: 30rpx;
  68. padding: 20rpx;
  69. }
  70. .modal-header {
  71. display: flex;
  72. justify-content: center;
  73. padding: 10rpx 0;
  74. }
  75. .modal-title {
  76. font-size: 32rpx;
  77. font-weight: bold;
  78. color: #333;
  79. }
  80. .modal-body {
  81. padding: 10rpx 0;
  82. }
  83. .modal-input {
  84. border: 2rpx solid #e0e0e0;
  85. border-radius: 10rpx;
  86. padding: 20rpx;
  87. font-size: 28rpx;
  88. }
  89. .modal-footer {
  90. display: flex;
  91. justify-content: space-between;
  92. gap: 20rpx;
  93. padding: 10rpx 0;
  94. }
  95. .btn {
  96. flex: 1;
  97. text-align: center;
  98. padding: 20rpx;
  99. border-radius: 10rpx;
  100. font-size: 28rpx;
  101. font-weight: 500;
  102. }
  103. .cancel-btn {
  104. background-color: #f5f5f5;
  105. color: #666;
  106. }
  107. .confirm-btn {
  108. background-color: blueviolet;
  109. color: white;
  110. }
  111. </style>