index.vue 2.8 KB

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