index.vue 1.9KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <template>
  2. <uni-shadow-root class="vant-notify-index"><van-transition name="slide-down" :show="show" custom-class="van-notify" :custom-style="'background-color:'+(backgroundColor)+'; color: '+(color)+'; z-index: '+(zIndex)+';'">
  3. <view v-if="safeAreaInsetTop" class="van-notify__safe-top" :style="'padding-top: '+(statusBarHeight)+'px'"></view>
  4. {{ text }}
  5. </van-transition></uni-shadow-root>
  6. </template>
  7. <script>
  8. import VanTransition from '../transition/index.vue'
  9. global['__wxVueOptions'] = {components:{'van-transition': VanTransition}}
  10. global['__wxRoute'] = 'vant/notify/index'
  11. import { VantComponent } from '../common/component';
  12. import { RED } from '../common/color';
  13. import { safeArea } from '../mixins/safe-area';
  14. VantComponent({
  15. mixins: [safeArea()],
  16. props: {
  17. text: String,
  18. color: {
  19. type: String,
  20. value: '#fff'
  21. },
  22. backgroundColor: {
  23. type: String,
  24. value: RED
  25. },
  26. duration: {
  27. type: Number,
  28. value: 3000
  29. },
  30. zIndex: {
  31. type: Number,
  32. value: 110
  33. }
  34. },
  35. methods: {
  36. showNotify() {
  37. const { duration } = this.data;
  38. clearTimeout(this.timer);
  39. this.set({
  40. show: true
  41. });
  42. if (duration > 0 && duration !== Infinity) {
  43. this.timer = setTimeout(() => {
  44. this.hide();
  45. }, duration);
  46. }
  47. },
  48. hide() {
  49. clearTimeout(this.timer);
  50. this.set({
  51. show: false
  52. });
  53. }
  54. }
  55. });
  56. export default global['__wxComponents']['vant/notify/index']
  57. </script>
  58. <style platform="mp-weixin">
  59. @import '../common/index.css';.van-notify{position:fixed;top:0;width:100%;padding:6px 15px;font-size:14px;line-height:20px;text-align:center;word-break:break-all;box-sizing:border-box}.van-notify__safe-top{height:44px}
  60. </style>