index.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/libs/classNames'
  3. import styleToCssString from '../helpers/libs/styleToCssString'
  4. import { isPresetColor } from '../helpers/colors'
  5. baseComponent({
  6. properties: {
  7. prefixCls: {
  8. type: String,
  9. value: 'wux-spin',
  10. },
  11. classNames: {
  12. type: null,
  13. value: 'wux-animate--fadeIn',
  14. },
  15. tip: {
  16. type: String,
  17. value: '',
  18. },
  19. size: {
  20. type: String,
  21. value: 'default',
  22. },
  23. spinning: {
  24. type: Boolean,
  25. value: true,
  26. observer: 'updated',
  27. },
  28. nested: {
  29. type: Boolean,
  30. value: false,
  31. },
  32. spinColor: {
  33. type: String,
  34. value: 'default',
  35. observer: 'setStyles',
  36. },
  37. },
  38. data: {
  39. spinVisible: true,
  40. dotStyle: '',
  41. tipStyle: '',
  42. },
  43. computed: {
  44. classes: ['prefixCls, size, nested, tip, spinVisible', function(prefixCls, size, nested, showText, spinVisible) {
  45. const wrap = classNames(prefixCls, {
  46. [`${prefixCls}--${size}`]: size,
  47. [`${prefixCls}--nested`]: nested,
  48. [`${prefixCls}--show-text`]: showText,
  49. })
  50. const anim = !nested ? `${prefixCls}__spinning` : `${prefixCls}__spinning--nested`
  51. const dots = `${prefixCls}__dots`
  52. const dot = `${prefixCls}__dot`
  53. const tip = `${prefixCls}__tip`
  54. const container = classNames(`${prefixCls}__container`, {
  55. [`${prefixCls}__container--blur`]: spinVisible,
  56. })
  57. return {
  58. wrap,
  59. anim,
  60. dots,
  61. dot,
  62. tip,
  63. container,
  64. }
  65. }],
  66. },
  67. methods: {
  68. updated(spinVisible) {
  69. if (this.data.nested) {
  70. this.setData({
  71. spinVisible,
  72. })
  73. }
  74. },
  75. setStyles(spinColor) {
  76. const inputColor = isPresetColor(spinColor)
  77. const dotStyle = inputColor !== 'default' ? styleToCssString({ backgroundColor: inputColor }) : ''
  78. const tipStyle = inputColor !== 'default' ? styleToCssString({ color: inputColor }) : ''
  79. if (
  80. this.data.dotStyle !== dotStyle ||
  81. this.data.tipStyle !== tipStyle
  82. ) {
  83. this.setData({
  84. dotStyle,
  85. tipStyle,
  86. })
  87. }
  88. },
  89. attached() {
  90. this.setStyles(this.data.spinColor)
  91. },
  92. },
  93. })