TipsPopup.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <template>
  2. <view v-if="visible" class="tips-popup-overlay" @click="handleCancel">
  3. <view class="tips-popup-content" @click.stop="preventClose">
  4. <view class="tips-header">
  5. <text class="tips-title">提示</text>
  6. </view>
  7. <view class="tips-body">
  8. <text class="tips-text">{{ content }}</text>
  9. <textarea
  10. v-if="showInput"
  11. v-model="reason"
  12. class="tips-input"
  13. :placeholder="inputPlaceholder"
  14. :maxlength="200"
  15. />
  16. </view>
  17. <view class="tips-footer">
  18. <view class="tips-btn cancel-btn" @click="handleCancel">
  19. <text class="tips-btn-text">取消</text>
  20. </view>
  21. <view class="tips-btn confirm-btn" @click="handleConfirm">
  22. <text class="tips-btn-text confirm-btn-text">确定</text>
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. </template>
  28. <script lang="ts" setup>
  29. import { ref } from 'vue'
  30. const visible = ref(false)
  31. const content = ref('')
  32. const showInput = ref(false)
  33. const reason = ref('')
  34. const inputPlaceholder = ref('请输入作废理由')
  35. let confirmCallback: ((reason?: string) => void) | null = null
  36. let cancelCallback: (() => void) | null = null
  37. interface PopupOptions {
  38. text: string
  39. confirm?: (reason?: string) => void
  40. cancel?: () => void
  41. showInput?: boolean
  42. inputPlaceholder?: string
  43. }
  44. const show = (options: PopupOptions) => {
  45. content.value = options.text
  46. confirmCallback = options.confirm || null
  47. cancelCallback = options.cancel || null
  48. showInput.value = options.showInput || false
  49. inputPlaceholder.value = options.inputPlaceholder || '请输入作废理由'
  50. reason.value = ''
  51. visible.value = true
  52. }
  53. const hide = () => {
  54. visible.value = false
  55. content.value = ''
  56. confirmCallback = null
  57. cancelCallback = null
  58. showInput.value = false
  59. reason.value = ''
  60. }
  61. const handleConfirm = () => {
  62. if (confirmCallback) {
  63. confirmCallback(reason.value)
  64. }
  65. hide()
  66. }
  67. const handleCancel = () => {
  68. if (cancelCallback) {
  69. cancelCallback()
  70. }
  71. hide()
  72. }
  73. const preventClose = () => {}
  74. defineExpose({
  75. show,
  76. hide
  77. })
  78. </script>
  79. <style lang="scss" scoped>
  80. .tips-popup-overlay {
  81. position: fixed;
  82. top: 0;
  83. left: 0;
  84. right: 0;
  85. bottom: 0;
  86. background-color: rgba(0, 0, 0, 0.5);
  87. display: flex;
  88. justify-content: center;
  89. align-items: center;
  90. z-index: 9999;
  91. }
  92. .tips-popup-content {
  93. width: 80%;
  94. max-width: 320px;
  95. background-color: #fff;
  96. border-radius: 8px;
  97. overflow: hidden;
  98. }
  99. .tips-header {
  100. padding: 20px 15px 15px;
  101. text-align: center;
  102. border-bottom: 1px solid #f0f0f0;
  103. }
  104. .tips-title {
  105. font-size: 18px;
  106. font-weight: 600;
  107. color: #333;
  108. }
  109. .tips-body {
  110. padding: 20px 15px;
  111. text-align: center;
  112. }
  113. .tips-text {
  114. font-size: 15px;
  115. color: #666;
  116. line-height: 1.5;
  117. }
  118. .tips-input {
  119. width: 100%;
  120. height: 80px;
  121. margin-top: 12px;
  122. padding: 8px 10px;
  123. font-size: 14px;
  124. color: #333;
  125. background-color: #f5f5f5;
  126. border: 1px solid #ddd;
  127. border-radius: 4px;
  128. box-sizing: border-box;
  129. }
  130. .tips-footer {
  131. display: flex;
  132. flex-direction: row;
  133. border-top: 1px solid #f0f0f0;
  134. }
  135. .tips-btn {
  136. flex: 1;
  137. padding: 15px;
  138. text-align: center;
  139. cursor: pointer;
  140. }
  141. .cancel-btn {
  142. border-right: 1px solid #f0f0f0;
  143. }
  144. .tips-btn-text {
  145. font-size: 16px;
  146. color: #666;
  147. }
  148. .confirm-btn {
  149. background-color: #fff;
  150. }
  151. .confirm-btn-text {
  152. color: #4B8CD9;
  153. font-weight: 500;
  154. }
  155. </style>