steps.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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') {
  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. // 组件的内部数据
  41. this.data = {
  42. prefix,
  43. classPrefix: name,
  44. };
  45. this.observers = {
  46. current() {
  47. this.updateChildren();
  48. },
  49. };
  50. this.methods = {
  51. updateChildren() {
  52. const items = this.getRelationNodes('./step-item');
  53. const len = items.length;
  54. const { current, currentStatus, readonly } = this.data;
  55. if (len) {
  56. items.forEach((item, index) => {
  57. item.updateStatus(current, currentStatus, index, this.data.theme, this.data.layout, items, readonly);
  58. });
  59. }
  60. },
  61. handleClick(index) {
  62. if (this.data.layout === 'vertical') {
  63. return;
  64. }
  65. if (!this.data.readonly) {
  66. const preIndex = this.data.current;
  67. this._trigger('change', {
  68. previous: preIndex,
  69. current: index,
  70. });
  71. }
  72. },
  73. };
  74. }
  75. };
  76. Steps = __decorate([
  77. wxComponent()
  78. ], Steps);
  79. export default Steps;
  80. //# sourceMappingURL=steps.js.map