CustomModal.vue 2.1 KB

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