Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

index.js 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import baseComponent from '../helpers/baseComponent'
  2. import classNames from '../helpers/classNames'
  3. const defaultStatus = ['wait', 'process', 'finish', 'error']
  4. const defaultIcon = 'ios-checkmark'
  5. baseComponent({
  6. relations: {
  7. '../steps/index': {
  8. type: 'parent',
  9. },
  10. },
  11. properties: {
  12. prefixCls: {
  13. type: String,
  14. value: 'wux-step',
  15. },
  16. status: {
  17. type: String,
  18. value: '',
  19. },
  20. title: {
  21. type: String,
  22. value: '',
  23. },
  24. content: {
  25. type: String,
  26. value: '',
  27. },
  28. icon: {
  29. type: String,
  30. value: '',
  31. },
  32. },
  33. data: {
  34. width: '100%',
  35. length: 1,
  36. index: 0,
  37. current: 0,
  38. direction: 'horizontal',
  39. },
  40. computed: {
  41. classes: ['prefixCls, direction', function(prefixCls, direction) {
  42. const wrap = classNames(prefixCls, {
  43. [`${prefixCls}--${direction}`]: direction,
  44. })
  45. const hd = `${prefixCls}__hd`
  46. const icon = `${prefixCls}__icon`
  47. const thumb = `${prefixCls}__thumb`
  48. const bd = `${prefixCls}__bd`
  49. const title = `${prefixCls}__title`
  50. const content = `${prefixCls}__content`
  51. const ft = `${prefixCls}__ft`
  52. return {
  53. wrap,
  54. hd,
  55. icon,
  56. thumb,
  57. bd,
  58. title,
  59. content,
  60. ft,
  61. }
  62. }],
  63. },
  64. methods: {
  65. updateCurrent(opts = {}) {
  66. const width = opts.direction === 'horizontal' ? 100 / opts.length + '%' : '100%'
  67. const index = defaultStatus.indexOf(this.data.status)
  68. const hasIcon = opts.index < opts.current || this.data.icon
  69. const thumb = this.data.icon || defaultIcon
  70. const suffix = index !== -1 ? defaultStatus[index] : opts.index < opts.current ? 'finish' : opts.index === opts.current ? 'process' : ''
  71. const className = `${this.data.prefixCls}--${suffix}`
  72. const options = Object.assign({
  73. width,
  74. className,
  75. hasIcon,
  76. thumb,
  77. }, opts)
  78. this.setData(options)
  79. },
  80. },
  81. attached() {
  82. this.updateCurrent(this.data)
  83. },
  84. })