steps.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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/step-item': {
  17. type: 'child',
  18. linked(child) {
  19. this.updateChildren();
  20. const { readonly } = this.data;
  21. child.setData({
  22. readonly,
  23. });
  24. },
  25. unlinked() {
  26. this.updateLastChid();
  27. },
  28. },
  29. };
  30. this.externalClasses = [`${prefix}-class`];
  31. this.properties = props;
  32. this.controlledProps = [
  33. {
  34. key: 'current',
  35. event: 'change',
  36. },
  37. ];
  38. this.data = {
  39. prefix,
  40. classPrefix: name,
  41. };
  42. this.observers = {
  43. current() {
  44. this.updateChildren();
  45. },
  46. };
  47. this.methods = {
  48. updateChildren() {
  49. const { current, currentStatus, readonly, theme, layout } = this.data;
  50. const items = this.$children;
  51. items.forEach((item, index) => {
  52. item.updateStatus(current, currentStatus, index, theme, layout, items, readonly);
  53. });
  54. },
  55. updateLastChid() {
  56. const items = this.$children;
  57. items.forEach((child, index) => child.setData({ isLastChild: index === items.length - 1 }));
  58. },
  59. handleClick(index) {
  60. if (!this.data.readonly) {
  61. const preIndex = this.data.current;
  62. this._trigger('change', {
  63. previous: preIndex,
  64. current: index,
  65. });
  66. }
  67. },
  68. };
  69. }
  70. };
  71. Steps = __decorate([
  72. wxComponent()
  73. ], Steps);
  74. export default Steps;