seiminModel.vue 3.9 KB

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