steps.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  2. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  4. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  5. return c > 3 && r && Object.defineProperty(target, key, r), r;
  6. };
  7. import { wxComponent, SuperComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. const { prefix } = config;
  11. const name = `${prefix}-steps`;
  12. let Steps = class Steps extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.relations = {
  16. './step-item': {
  17. type: 'descendant',
  18. linked(child) {
  19. this.updateChildren();
  20. const { readonly, layout } = this.data;
  21. let isLarge = false;
  22. if (!readonly && layout === 'horizontal' && child.data.icon !== 'slot') {
  23. isLarge = !!child.data.icon;
  24. }
  25. child.setData({
  26. readonly,
  27. isLarge,
  28. });
  29. },
  30. },
  31. };
  32. this.externalClasses = [`${prefix}-class`];
  33. this.properties = props;
  34. this.controlledProps = [
  35. {
  36. key: 'current',
  37. event: 'change',
  38. },
  39. ];
  40. this.data = {
  41. prefix,
  42. classPrefix: name,
  43. };
  44. this.observers = {
  45. current() {
  46. this.updateChildren();
  47. },
  48. };
  49. this.methods = {
  50. updateChildren() {
  51. const items = this.getRelationNodes('./step-item');
  52. const len = items.length;
  53. const { current, currentStatus, readonly } = this.data;
  54. if (len) {
  55. items.forEach((item, index) => {
  56. item.updateStatus(current, currentStatus, index, this.data.theme, this.data.layout, items, readonly);
  57. });
  58. }
  59. },
  60. handleClick(index) {
  61. if (this.data.layout === 'vertical') {
  62. return;
  63. }
  64. if (!this.data.readonly) {
  65. const preIndex = this.data.current;
  66. this._trigger('change', {
  67. previous: preIndex,
  68. current: index,
  69. });
  70. }
  71. },
  72. };
  73. }
  74. };
  75. Steps = __decorate([
  76. wxComponent()
  77. ], Steps);
  78. export default Steps;