index.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import { Button, Popup } from 'vant';
  2. import { 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. showButton: {
  22. type: Boolean,
  23. default: false
  24. },
  25. buttonText: {
  26. type: String,
  27. default: '确定'
  28. }
  29. },
  30. emits: ['confirm'],
  31. setup(props, { emit }) {
  32. const showPopup = ref(false);
  33. onMounted(() => {
  34. if (!browser().weixin && props.show) {
  35. showPopup.value = true;
  36. return;
  37. }
  38. });
  39. watch(
  40. () => [props.show, props.message],
  41. () => {
  42. if (props.show) {
  43. showPopup.value = true;
  44. } else {
  45. showPopup.value = false;
  46. }
  47. }
  48. );
  49. return () => (
  50. <>
  51. <Popup
  52. v-model:show={showPopup.value}
  53. round
  54. style={{ width: '70%', maxWidth: '520px' }}
  55. closeOnClickOverlay={false}
  56. class={styles.wxPopupDialog}>
  57. <div class={styles.popupContainer}>
  58. <p class={styles.title1}>{props.title}</p>
  59. <p class={styles.popupTips} v-html={props.message}></p>
  60. {props.showButton && (
  61. <Button
  62. round
  63. class={styles.button}
  64. onClick={() => emit('confirm')}>
  65. {props.buttonText}
  66. </Button>
  67. )}
  68. </div>
  69. </Popup>
  70. </>
  71. );
  72. }
  73. });