index.vue 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <template>
  2. <uni-shadow-root class="vant-notify-index"><van-transition name="slide-down" :show="show" custom-class="van-notify__container" :custom-style="computed.rootStyle({ zIndex, top })" @click.native="onTap">
  3. <view :class="'van-notify van-notify--'+(type)" :style="computed.notifyStyle({ background, color })">
  4. <view v-if="safeAreaInsetTop" :style="'height: '+(statusBarHeight)+'px'"></view>
  5. <text>{{ message }}</text>
  6. </view>
  7. </van-transition></uni-shadow-root>
  8. </template>
  9. <wxs src="../wxs/utils.wxs" module="utils"></wxs><wxs src="./index.wxs" module="computed"></wxs>
  10. <script>
  11. import VanTransition from '../transition/index.vue'
  12. global['__wxVueOptions'] = {components:{'van-transition': VanTransition}}
  13. global['__wxRoute'] = 'vant/notify/index'
  14. import { VantComponent } from '../common/component';
  15. import { WHITE } from '../common/color';
  16. import { getSystemInfoSync } from '../common/utils';
  17. VantComponent({
  18. props: {
  19. message: String,
  20. background: String,
  21. type: {
  22. type: String,
  23. value: 'danger',
  24. },
  25. color: {
  26. type: String,
  27. value: WHITE,
  28. },
  29. duration: {
  30. type: Number,
  31. value: 3000,
  32. },
  33. zIndex: {
  34. type: Number,
  35. value: 110,
  36. },
  37. safeAreaInsetTop: {
  38. type: Boolean,
  39. value: false,
  40. },
  41. top: null,
  42. },
  43. data: {
  44. show: false,
  45. onOpened: null,
  46. onClose: null,
  47. onClick: null,
  48. },
  49. created() {
  50. const { statusBarHeight } = getSystemInfoSync();
  51. this.setData({ statusBarHeight });
  52. },
  53. methods: {
  54. showNotify() {
  55. const { duration, onOpened } = this.data;
  56. clearTimeout(this.timer);
  57. this.setData({ show: true });
  58. wx.nextTick(onOpened);
  59. if (duration > 0 && duration !== Infinity) {
  60. this.timer = setTimeout(() => {
  61. this.hide();
  62. }, duration);
  63. }
  64. },
  65. hide() {
  66. const { onClose } = this.data;
  67. clearTimeout(this.timer);
  68. this.setData({ show: false });
  69. wx.nextTick(onClose);
  70. },
  71. onTap(event) {
  72. const { onClick } = this.data;
  73. if (onClick) {
  74. onClick(event.detail);
  75. }
  76. },
  77. },
  78. });
  79. export default global['__wxComponents']['vant/notify/index']
  80. </script>
  81. <style platform="mp-weixin">
  82. @import '../common/index.css';.van-notify{word-wrap:break-word;font-size:var(--notify-font-size,14px);line-height:var(--notify-line-height,20px);padding:var(--notify-padding,6px 15px);text-align:center}.van-notify__container{box-sizing:border-box;left:0;position:fixed;top:0;width:100%}.van-notify--primary{background-color:var(--notify-primary-background-color,#1989fa)}.van-notify--success{background-color:var(--notify-success-background-color,#07c160)}.van-notify--danger{background-color:var(--notify-danger-background-color,#ee0a24)}.van-notify--warning{background-color:var(--notify-warning-background-color,#ff976a)}
  83. </style>