cmodel.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view>
  3. <view class='modal-mask' v-if='show' @click='clickMask'>
  4. <view class='modal-content'>
  5. <view class='modal-header'>
  6. {{title}}
  7. </view>
  8. <scroll-view scroll-y class='main-content'>
  9. <slot></slot>
  10. </scroll-view>
  11. <view class='modal-footer'>
  12. <view v-if='!single' class='cancel-btn' @click='cancel'>取消</view>
  13. <view class='confirm-btn' @click='confirm'>确定 </view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </template>
  19. <script>
  20. export default {
  21. name: "cmodel",
  22. components: {
  23. },
  24. props: {
  25. //是否显示modal弹窗
  26. show: {
  27. type: Boolean,
  28. value: false
  29. },
  30. //控制底部是一个按钮还是两个按钮,默认两个
  31. single: {
  32. type: Boolean,
  33. value: false
  34. },
  35. title: {
  36. type: String,
  37. value: '提示'
  38. }
  39. },
  40. data() {
  41. return {
  42. }
  43. },
  44. mounted() {
  45. console.log(this.show);
  46. },
  47. methods: {
  48. clickMask() {
  49. },
  50. // 点击取消按钮的回调函数
  51. cancel() {
  52. this.$emit('update:show', false);
  53. this.$emit('cancel');
  54. },
  55. // 点击确定按钮的回调函数
  56. confirm() {
  57. this.$emit('update:show', false);
  58. this.$emit('confirm');
  59. }
  60. }
  61. };
  62. </script>
  63. <style lang="scss" scoped>
  64. /*遮罩层*/
  65. .modal-mask{
  66. display: flex;
  67. justify-content: center;
  68. align-items: center;
  69. position: fixed;
  70. left: 0;
  71. right: 0;
  72. top: 0;
  73. bottom: 0;
  74. background-color: rgba(0,0,0,0.5);
  75. z-index: 999;
  76. }
  77. /*遮罩内容*/
  78. .modal-content{
  79. display: flex;
  80. flex-direction: column;
  81. width: 80%;
  82. background-color: #fff;
  83. border-radius: 10rpx;
  84. padding: 20rpx;
  85. text-align: left;
  86. }
  87. /*中间内容*/
  88. .main-content{
  89. flex: 1;
  90. height: 100%;
  91. min-height: 100rpx;
  92. max-height: 400rpx;
  93. overflow-y: hidden;
  94. }
  95. .modal-header{
  96. height: 80rpx;
  97. line-height: 80rpx;
  98. text-align: center;
  99. margin-bottom: 30rpx;
  100. border-bottom: 1rpx solid #D2D3D5;
  101. }
  102. /*底部按钮*/
  103. .modal-footer{
  104. display: flex;
  105. flex-direction: row;
  106. height: 80rpx;
  107. line-height: 80rpx;
  108. border-top: 1rpx solid #D2D3D5;
  109. margin-top: 30rpx;
  110. text-align: center;
  111. }
  112. .cancel-btn, .confirm-btn{
  113. flex: 1;
  114. height: 100rpx;
  115. line-height: 100rpx;
  116. text-align: center;
  117. font-size: 32rpx;
  118. }
  119. .cancel-btn{
  120. color: #000;
  121. border-right: 1rpx solid #D2D3D5;
  122. }
  123. .confirm-btn {
  124. color: var(--themeColor)
  125. }
  126. </style>