steps.js 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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 items = this.$children;
  50. items.forEach((item, index) => {
  51. item.updateStatus(Object.assign({ index, items }, this.data));
  52. });
  53. },
  54. updateLastChid() {
  55. const items = this.$children;
  56. items.forEach((child, index) => child.setData({ isLastChild: index === items.length - 1 }));
  57. },
  58. handleClick(index) {
  59. if (!this.data.readonly) {
  60. const preIndex = this.data.current;
  61. this._trigger('change', {
  62. previous: preIndex,
  63. current: index,
  64. });
  65. }
  66. },
  67. };
  68. }
  69. };
  70. Steps = __decorate([
  71. wxComponent()
  72. ], Steps);
  73. export default Steps;