seiminModel.vue 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <!--
  2. * @Author: 廖明明
  3. * @Date: 2022-04-01 17:11:19
  4. * @LastEditors: 廖明明
  5. * @LastEditTime: 2022-04-02 17:03:14
  6. * @Description: 自定义弹窗组件
  7. -->
  8. <template>
  9. <view class="seiminModel seiminModel_mask" v-if="opts.isVisible">
  10. <view
  11. class="seiminModel_container animate__animated animate__fadeIn animate__faster"
  12. >
  13. <view class="seiminModel_header">{{ opts.title }}</view>
  14. <view class="seiminModel_content" v-html="opts.content"></view>
  15. <view class="seiminModel_footer">
  16. <view
  17. class="seiminModel_footer__btn"
  18. v-for="(btn, i) in opts.btns"
  19. :style="{
  20. flex: btn.flex,
  21. color: btn.textColor,
  22. }"
  23. @click="btn.click($event)"
  24. :key="i"
  25. >{{ btn.name }}</view
  26. >
  27. </view>
  28. </view>
  29. </view>
  30. </template>
  31. <script>
  32. export default {
  33. name: "seiminModel",
  34. data() {
  35. return {
  36. // 配置项
  37. opts: {},
  38. };
  39. },
  40. methods: {
  41. // 显示弹窗
  42. show(args = {}) {
  43. // 默认配置项
  44. let defaultOptions = {
  45. skin: "default", //弹窗风格(default|toast|)
  46. isVisible: false, //是否显示弹窗
  47. title: "提示", //标题
  48. content: "", //内容
  49. btns: [
  50. { name: "取消", textColor: "#666", flex: 1, click: this.close },
  51. { name: "确定", textColor: "#666", flex: 1, click: this.close },
  52. ], //弹窗按钮
  53. };
  54. // 根据弹窗风格修改默认配置项
  55. switch (args.skin) {
  56. case "toast":
  57. defaultOptions.btns = [
  58. {
  59. name: "知道了",
  60. textColor: "#49b856",
  61. flex: 1,
  62. click: this.close,
  63. },
  64. ];
  65. break;
  66. }
  67. // 合并配置
  68. this.opts = Object.assign({}, defaultOptions, args, {
  69. isVisible: true,
  70. });
  71. },
  72. // 关闭弹窗
  73. close() {
  74. this.opts.isVisible = false;
  75. },
  76. },
  77. };
  78. </script>
  79. <style lang="scss" scoped>
  80. .seiminModel {
  81. font-size: 36rpx;
  82. color: #000;
  83. line-height: 50rpx;
  84. text-align: center;
  85. &.seiminModel_mask {
  86. background-color: rgba(0, 0, 0, 0.5);
  87. position: fixed;
  88. top: 0;
  89. right: 0;
  90. bottom: 0;
  91. left: 0;
  92. margin: auto;
  93. @include flex(center, center);
  94. .seiminModel_container {
  95. width: 560rpx;
  96. border-radius: 8rpx;
  97. background-color: #fff;
  98. display: flex;
  99. flex-direction: column;
  100. align-content: center;
  101. .seiminModel_header {
  102. height: 100rpx;
  103. @include flex(center, center);
  104. }
  105. .seiminModel_content {
  106. flex: 1;
  107. background-color: #f9fafb;
  108. margin: 0 36rpx 25rpx;
  109. border: 1px solid #e5e9ed;
  110. color: #333;
  111. padding: 76rpx 24rpx;
  112. @include numbersAndLettersNoWrap;
  113. .red {
  114. color: $textColorRed;
  115. }
  116. .green {
  117. color: $defaultColor;
  118. }
  119. }
  120. .seiminModel_footer {
  121. border-top: 1px solid #e5e5e5;
  122. height: 100rpx;
  123. color: #666;
  124. @include flex(center, center);
  125. .seiminModel_footer__btn {
  126. height: 100%;
  127. @include flex(center, center);
  128. position: relative;
  129. &::after {
  130. content: "";
  131. height: 86rpx;
  132. position: absolute;
  133. width: 1px;
  134. bottom: 0;
  135. right: 0;
  136. background-color: #dde1e5;
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. </style>