index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. baseComponent({
  4. properties: {
  5. prefixCls: {
  6. type: String,
  7. value: 'wux-spin',
  8. },
  9. classNames: {
  10. type: null,
  11. value: 'wux-animate--fadeIn',
  12. },
  13. tip: {
  14. type: String,
  15. value: '',
  16. },
  17. size: {
  18. type: String,
  19. value: 'default',
  20. },
  21. spinning: {
  22. type: Boolean,
  23. value: true,
  24. observer: 'updated',
  25. },
  26. nested: {
  27. type: Boolean,
  28. value: false,
  29. },
  30. },
  31. data: {
  32. spinVisible: true,
  33. },
  34. computed: {
  35. classes: ['prefixCls, size, nested, tip, spinVisible', function(prefixCls, size, nested, showText, spinVisible) {
  36. const wrap = classNames(prefixCls, {
  37. [`${prefixCls}--${size}`]: size,
  38. [`${prefixCls}--nested`]: nested,
  39. [`${prefixCls}--show-text`]: showText,
  40. })
  41. const anim = !nested ? `${prefixCls}__spinning` : `${prefixCls}__spinning--nested`
  42. const dots = `${prefixCls}__dots`
  43. const dot = `${prefixCls}__dot`
  44. const tip = `${prefixCls}__tip`
  45. const container = classNames(`${prefixCls}__container`, {
  46. [`${prefixCls}__container--blur`]: spinVisible,
  47. })
  48. return {
  49. wrap,
  50. anim,
  51. dots,
  52. dot,
  53. tip,
  54. container,
  55. }
  56. }],
  57. },
  58. methods: {
  59. updated(spinVisible) {
  60. if (this.data.nested) {
  61. if(spinVisible) {
  62. this.setData({
  63. spinVisible,
  64. })
  65. } else {
  66. setTimeout(() => {
  67. this.setData({
  68. spinVisible,
  69. })
  70. }, 500);
  71. }
  72. }
  73. },
  74. },
  75. })