myDialog.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <uni-popup ref="dialog" type="center" :is-mask-click="closeOnClickOverlay" :safe-area='false'>
  3. <view class="inputDialog">
  4. <view class="inputDialog-head">{{title}}</view>
  5. <view class="inputDialog-body">
  6. <slot name="dialogBody"></slot>
  7. </view>
  8. <view class="inputDialog-footer">
  9. <view class="inputDialog-footer-btn" @tap="onCancel">{{cancelText}}</view>
  10. <view class="inputDialog-footer-btn inputDialog-footer-l" @tap="onConfirm">{{confirmText}}</view>
  11. </view>
  12. </view>
  13. </uni-popup>
  14. </template>
  15. <script>
  16. export default {
  17. name: "myDialog",
  18. props: {
  19. title: {
  20. type: String,
  21. default: ""
  22. },
  23. // 取消文案
  24. cancelText: {
  25. type: String,
  26. default: "取消"
  27. },
  28. // 确认文案
  29. confirmText: {
  30. type: String,
  31. default: "确定"
  32. },
  33. // 是否允许点击遮罩关闭modal
  34. closeOnClickOverlay: {
  35. type: Boolean,
  36. default: true
  37. },
  38. },
  39. data() {
  40. return {
  41. }
  42. },
  43. methods: {
  44. open() {
  45. this.$refs.dialog.open()
  46. },
  47. close() {
  48. this.$refs.dialog.close()
  49. },
  50. onCancel() {
  51. this.$emit("cancel")
  52. },
  53. onConfirm(val) {
  54. this.$emit("confirm")
  55. },
  56. }
  57. }
  58. </script>
  59. <style lang="scss" scoped>
  60. .inputDialog {
  61. width: 600rpx;
  62. border-radius: 22rpx;
  63. background-color: #fff;
  64. overflow: hidden;
  65. &-head {
  66. padding-top: 50rpx;
  67. display: flex;
  68. flex-direction: row;
  69. justify-content: center;
  70. font-size: 32rpx;
  71. font-weight: 500;
  72. color: #333;
  73. }
  74. &-body {
  75. padding: 24rpx;
  76. }
  77. &-footer {
  78. display: flex;
  79. flex-direction: row;
  80. border-top: 1rpx solid #f5f5f5;
  81. &-btn {
  82. display: flex;
  83. flex: 1;
  84. flex-direction: row;
  85. justify-content: center;
  86. align-items: center;
  87. height: 45px;
  88. font-size: 16px;
  89. color: #333;
  90. }
  91. &-l {
  92. color: #007aff;
  93. border-left-color: #f0f0f0;
  94. border-left-style: solid;
  95. border-left-width: 1rpx;
  96. }
  97. }
  98. }
  99. </style>