tips.js 835 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. let timer;
  2. Component({
  3. externalClasses: ['tui-tips-class'],
  4. properties: {
  5. //top bottom center
  6. position: {
  7. type: String,
  8. value: "top"
  9. }
  10. },
  11. data: {
  12. show: false,
  13. msg: "无法连接到服务器~",
  14. //translucent,primary,green,warning,danger
  15. type: "translucent"
  16. },
  17. lifetimes: {
  18. detached: function() {
  19. clearTimeout(timer);
  20. timer = null;
  21. }
  22. },
  23. methods: {
  24. showTips: function(options) {
  25. const {type = 'translucent', duration = 2000} = options;
  26. clearTimeout(timer);
  27. this.setData({
  28. show: true,
  29. type: type,
  30. msg: options.msg
  31. }, () => {
  32. timer = setTimeout(() => {
  33. this.setData({
  34. show: false
  35. }, () => {
  36. timer = null;
  37. })
  38. }, duration)
  39. })
  40. }
  41. }
  42. })