index.tsx 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import { Button, Popup } from 'vant';
  2. import { PropType, defineComponent, onMounted, ref, watch } from 'vue';
  3. import styles from './index.module.less';
  4. import { browser } from '@/helpers/utils';
  5. export default defineComponent({
  6. name: 'm-wx-tip',
  7. props: {
  8. // 是否显示微信弹窗
  9. show: {
  10. type: Boolean,
  11. default: true
  12. },
  13. title: {
  14. type: String,
  15. default: '温馨提示'
  16. },
  17. message: {
  18. type: String,
  19. default: '请使用微信打开'
  20. },
  21. messageAlign: {
  22. type: String as PropType<'center' | 'left' | 'right'>,
  23. default: 'center'
  24. },
  25. /** 是否展示取消按钮 */
  26. showCancelButton: {
  27. type: Boolean,
  28. default: false
  29. },
  30. /** 取消按钮文案 */
  31. cancelButtonText: {
  32. type: String,
  33. default: '取消'
  34. },
  35. /** 取消按钮颜色 */
  36. cancelButtonColor: {
  37. type: String,
  38. default: ''
  39. },
  40. /** 是否展示确认按钮 */
  41. showConfirmButton: {
  42. type: Boolean,
  43. default: true
  44. },
  45. /** 确认按钮文案 */
  46. confirmButtonText: {
  47. type: String,
  48. default: '确认'
  49. },
  50. /** 确认按钮颜色 */
  51. confirmButtonColor: {
  52. type: String,
  53. default: ''
  54. },
  55. /** 是否有关闭按钮 */
  56. showCloseButton: {
  57. type: Boolean,
  58. default: true
  59. }
  60. },
  61. emits: ['confirm', 'cancel', 'close'],
  62. setup(props, { emit }) {
  63. const showPopup = ref(false);
  64. onMounted(() => {
  65. if (props.show) {
  66. showPopup.value = true;
  67. }
  68. });
  69. watch(
  70. () => [props.show, props.message],
  71. () => {
  72. if (props.show) {
  73. showPopup.value = true;
  74. } else {
  75. showPopup.value = false;
  76. }
  77. }
  78. );
  79. return () => (
  80. <>
  81. <Popup
  82. v-model:show={showPopup.value}
  83. round
  84. style={{ width: '100%', maxWidth: '520px' }}
  85. closeOnClickOverlay={false}
  86. class={styles.wxPopupDialog} closeable={false}>
  87. <div class={styles.popupContainer}>
  88. {props.showCloseButton && (
  89. <i class={styles.iconClose} onClick={() => emit('close')}></i>
  90. )}
  91. <p class={styles.title1} v-html={props.title}></p>
  92. <p
  93. class={styles.popupTips}
  94. style={{ 'text-align': props.messageAlign }}
  95. v-html={props.message}></p>
  96. {(props.showConfirmButton || props.showConfirmButton) && (
  97. <div class={styles.btnGroup}>
  98. {props.showCancelButton && (
  99. <Button
  100. round
  101. class={[styles.button, styles.cancelBtn]}
  102. color={props.cancelButtonColor}
  103. onClick={() => emit('cancel')}>
  104. {props.cancelButtonText}
  105. </Button>
  106. )}
  107. {props.showConfirmButton && (
  108. <Button
  109. round
  110. class={[styles.button, styles.confirmBtn]}
  111. color={props.confirmButtonColor}
  112. onClick={() => emit('confirm')}>
  113. {props.confirmButtonText}
  114. </Button>
  115. )}
  116. </div>
  117. )}
  118. </div>
  119. </Popup>
  120. </>
  121. );
  122. }
  123. });