Confirm.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <div class="xtx-confirm">
  3. <div class="wrapper" ref="target">
  4. <div class="header" v-if="options.title">
  5. <h3>{{ options.title }}</h3>
  6. <a href="JavaScript:;" class="iconfont icon-close-new" @click="cancelCallback"></a>
  7. </div>
  8. <div class="body">
  9. <div class="typeImg">
  10. <img
  11. style="height: 48px; width: 48px"
  12. v-if="options.type == 'success'"
  13. src="@/assets/images/icon/success.png"
  14. alt=""
  15. />
  16. <img
  17. style="height: 48px; width: 48px"
  18. v-else-if="options.type == 'warn'"
  19. src="@/assets/images/icon/warn.png"
  20. alt=""
  21. />
  22. <img
  23. style="height: 48px; width: 48px"
  24. v-else
  25. src="@/assets/images/icon/error.png"
  26. alt=""
  27. />
  28. </div>
  29. <span>{{ options.text }}</span>
  30. </div>
  31. <div class="footer">
  32. <!-- <button @click="cancelCallback" size="mini" type="gray">取消</button> -->
  33. <button @click="confirmCallback" size="mini" type="primary">{{t('confirm')}}</button>
  34. </div>
  35. </div>
  36. </div>
  37. </template>
  38. <script lang="ts">
  39. // 注意:当前组件不是在 #app 下进行渲染,无法使用 #app 下的环境(全局组件,全局指令,原型属性函数)
  40. import { ref } from 'vue'
  41. import { useI18n } from 'vue-i18n'
  42. // import { onClickOutside } from '@vueuse/core'
  43. export default {
  44. name: 'showConfirm',
  45. props: {
  46. type: {
  47. type: String,
  48. default: 'success'
  49. },
  50. options: {
  51. type: Object,
  52. default: () => {
  53. return {
  54. title: '',
  55. text: '',
  56. type: 'success',
  57. callback: () => {}
  58. }
  59. }
  60. },
  61. // 关闭方法
  62. close: {
  63. type: Function,
  64. default: () => {}
  65. },
  66. // 取消按钮
  67. // cancelCallback: {
  68. // type: Function,
  69. // default: () => {}
  70. // }
  71. },
  72. setup(props) {
  73. // 点击 target 目标元素外部相当于点击了取消
  74. const { t } = useI18n()
  75. const target = ref(null)
  76. // onClickOutside(target, () => {
  77. // props.cancelCallback()
  78. // })
  79. function cancelCallback() {
  80. props.close()
  81. }
  82. function confirmCallback() {
  83. props.options.callback()
  84. props.close()
  85. }
  86. return { options:props.options,target,confirmCallback,cancelCallback, t }
  87. }
  88. }
  89. </script>
  90. <style scoped lang="less">
  91. .xtx-confirm {
  92. position: fixed;
  93. left: 0;
  94. top: 0;
  95. width: 100%;
  96. height: 100%;
  97. z-index: 8888;
  98. background: rgba(0, 0, 0, 0.5);
  99. .wrapper {
  100. width: calc(100% - 40px);
  101. max-width: 400px;
  102. border-radius: 10px 10px 10px 10px;
  103. background: #fff;
  104. border-radius: 4px;
  105. position: absolute;
  106. top: 50%;
  107. left: 50%;
  108. transform: translate(-50%, -50%);
  109. .header,
  110. .footer {
  111. height: 50px;
  112. line-height: 50px;
  113. padding: 0 20px;
  114. text-align: center;
  115. }
  116. .body {
  117. padding: 30px 40px;
  118. font-size: 16px;
  119. font-family: PingFang SC-Regular, PingFang SC;
  120. font-weight: 400;
  121. color: #202020;
  122. line-height: 19px;
  123. text-align: center;
  124. .icon-warning {
  125. color: red;
  126. margin-right: 3px;
  127. font-size: 16px;
  128. }
  129. .typeImg {
  130. margin-bottom: 20px;
  131. }
  132. }
  133. .footer {
  134. // text-align: right;
  135. border-top: 1px solid #ebebeb;
  136. padding: 20px;
  137. .xtx-button {
  138. margin-left: 20px;
  139. }
  140. button {
  141. height: 40px;
  142. background: #29b2ff;
  143. border-radius: 4px 4px 4px 4px;
  144. opacity: 1;
  145. font-size: 14px;
  146. font-family: PingFang SC-Regular, PingFang SC;
  147. font-weight: 400;
  148. color: #ffffff;
  149. border: none;
  150. padding: 10px 50px;
  151. text-align: center;
  152. margin: 0 15px;
  153. }
  154. }
  155. .header {
  156. position: relative;
  157. h3 {
  158. font-weight: normal;
  159. font-size: 18px;
  160. }
  161. a {
  162. position: absolute;
  163. right: 15px;
  164. top: 15px;
  165. font-size: 20px;
  166. width: 20px;
  167. height: 20px;
  168. line-height: 20px;
  169. text-align: center;
  170. color: #999;
  171. &:hover {
  172. color: #666;
  173. }
  174. }
  175. }
  176. }
  177. }
  178. </style>