tipPopup.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <template>
  2. <popup
  3. v-model:show="showValue"
  4. round
  5. class="tip-popup"
  6. :overlay-style="overlayStyle"
  7. :close-on-click-overlay="closeOnClickOverlay"
  8. @click-overlay="handleClickOverlay"
  9. >
  10. <template v-if="type === 'create'">
  11. <img class="tip-icon create-icon" src="@/assets/img/home/create-farm-icon.png" alt="" />
  12. <div class="tip-text">
  13. <div v-for="(line, index) in textLines" :key="index">{{ line }}</div>
  14. </div>
  15. </template>
  16. <template v-else-if="type === 'success'">
  17. <img class="tip-icon success-icon" src="@/assets/img/home/right.png" alt="" />
  18. <div class="tip-text success-text">{{ text }} <span class="highlight-text">{{ highlightText }}</span></div>
  19. </template>
  20. <template v-else>
  21. <img class="tip-icon success-icon" src="@/assets/img/home/create-farm-icon.png" alt="" />
  22. <div class="tip-text success-text">{{ text }} <span class="highlight-text">{{ highlightText }}</span> {{ text2 }}</div>
  23. </template>
  24. <div class="tip-btn" @click.stop="handleBtnClick">
  25. {{ buttonText || (type === "create" ? "去创建农场" : "我知道了") }}
  26. </div>
  27. </popup>
  28. </template>
  29. <script setup>
  30. import { Popup } from "vant";
  31. import { computed } from "vue";
  32. const props = defineProps({
  33. // 控制弹窗显示/隐藏
  34. show: {
  35. type: Boolean,
  36. default: false,
  37. },
  38. // 类型:'create' 或 'success',决定显示哪个图标
  39. type: {
  40. type: String,
  41. default: "create",
  42. validator: (value) => ["create", "success"].includes(value),
  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. width: 80%;
  107. padding: 28px 28px 20px;
  108. display: flex;
  109. flex-direction: column;
  110. align-items: center;
  111. justify-content: center;
  112. .tip-icon {
  113. margin-bottom: 12px;
  114. &.create-icon {
  115. width: 40px;
  116. height: 40px;
  117. }
  118. &.success-icon {
  119. width: 68px;
  120. height: 68px;
  121. }
  122. }
  123. .tip-text {
  124. font-size: 18px;
  125. font-weight: 500;
  126. margin-bottom: 32px;
  127. text-align: center;
  128. &.success-text {
  129. font-size: 22px;
  130. font-weight: 400;
  131. }
  132. .highlight-text {
  133. color: #2199f8;
  134. }
  135. }
  136. .tip-btn {
  137. width: 100%;
  138. box-sizing: border-box;
  139. padding: 8px;
  140. border-radius: 25px;
  141. font-size: 16px;
  142. background: #2199f8;
  143. color: #fff;
  144. text-align: center;
  145. cursor: pointer;
  146. }
  147. }
  148. </style>