tipPopup.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <popup
  3. v-model:show="showValue"
  4. round
  5. class="tip-popup"
  6. :overlay-style="overlayStyle"
  7. teleport="body"
  8. :close-on-click-overlay="closeOnClickOverlay"
  9. @click-overlay="handleClickOverlay"
  10. >
  11. <template v-if="type === 'create'">
  12. <img class="tip-icon create-icon" src="@/assets/img/home/create-farm-icon.png" alt="" />
  13. <div class="tip-text">
  14. <div v-for="(line, index) in textLines" :key="index">{{ line }}</div>
  15. </div>
  16. </template>
  17. <template v-else-if="type === 'success'">
  18. <img class="tip-icon success-icon" src="@/assets/img/home/right.png" alt="" />
  19. <div class="tip-text success-text">{{ text }} <span class="highlight-text">{{ highlightText }}</span></div>
  20. </template>
  21. <template v-else>
  22. <img class="tip-icon success-icon" src="@/assets/img/home/create-farm-icon.png" alt="" />
  23. <div class="tip-text success-text">{{ text }} <span class="highlight-text">{{ highlightText }}</span> {{ text2 }}</div>
  24. </template>
  25. <div class="tip-btn" @click.stop="handleBtnClick">
  26. {{ buttonText || (type === "create" ? "去创建农场" : "我知道了") }}
  27. </div>
  28. </popup>
  29. </template>
  30. <script setup>
  31. import { Popup } from "vant";
  32. import { computed } from "vue";
  33. const props = defineProps({
  34. // 控制弹窗显示/隐藏
  35. show: {
  36. type: Boolean,
  37. default: false,
  38. },
  39. // 类型:'create' 或 'success' 或 'warning',决定显示哪个图标
  40. type: {
  41. type: String,
  42. default: "create",
  43. },
  44. // 提示文字内容
  45. text: {
  46. type: [String, Array],
  47. default: "",
  48. },
  49. // 按钮文字,如果不传则根据type自动决定
  50. buttonText: {
  51. type: String,
  52. default: "",
  53. },
  54. // 遮罩层样式
  55. overlayStyle: {
  56. type: Object,
  57. default: () => ({}),
  58. },
  59. // 是否在点击遮罩层后关闭弹窗
  60. closeOnClickOverlay: {
  61. type: Boolean,
  62. default: true,
  63. },
  64. // 高亮文字
  65. highlightText: {
  66. type: String,
  67. default: "",
  68. },
  69. // 第二行文字
  70. text2: {
  71. type: String,
  72. default: "",
  73. },
  74. });
  75. const emit = defineEmits(["update:show", "confirm", "handleClickOverlay"]);
  76. // 处理v-model双向绑定
  77. const showValue = computed({
  78. get: () => props.show,
  79. set: (value) => emit("update:show", value),
  80. });
  81. // 将文字内容转换为数组,支持多行显示
  82. const textLines = computed(() => {
  83. if (Array.isArray(props.text)) {
  84. return props.text;
  85. }
  86. if (typeof props.text === "string") {
  87. return props.text.split("\n").filter((line) => line.trim());
  88. }
  89. return [];
  90. });
  91. const handleBtnClick = () => {
  92. emit("confirm");
  93. if(props.buttonText !== "分享微信"){
  94. emit("update:show", false);
  95. }
  96. };
  97. const handleClickOverlay = () => {
  98. emit("handleClickOverlay");
  99. if(props.closeOnClickOverlay){
  100. emit("update:show", false);
  101. }
  102. };
  103. </script>
  104. <style scoped lang="scss">
  105. .tip-popup {
  106. z-index: 10000 !important;
  107. width: 80%;
  108. padding: 28px 28px 20px;
  109. display: flex;
  110. flex-direction: column;
  111. align-items: center;
  112. justify-content: center;
  113. .tip-icon {
  114. margin-bottom: 12px;
  115. &.create-icon {
  116. width: 40px;
  117. height: 40px;
  118. }
  119. &.success-icon {
  120. width: 68px;
  121. height: 68px;
  122. }
  123. }
  124. .tip-text {
  125. font-size: 18px;
  126. font-weight: 500;
  127. margin-bottom: 32px;
  128. text-align: center;
  129. &.success-text {
  130. font-size: 22px;
  131. font-weight: 400;
  132. }
  133. .highlight-text {
  134. color: #2199f8;
  135. }
  136. }
  137. .tip-btn {
  138. width: 100%;
  139. box-sizing: border-box;
  140. padding: 8px;
  141. border-radius: 25px;
  142. font-size: 16px;
  143. background: #2199f8;
  144. color: #fff;
  145. text-align: center;
  146. cursor: pointer;
  147. }
  148. }
  149. </style>