progress.js 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 { SuperComponent, wxComponent } from '../common/src/index';
  8. import config from '../common/config';
  9. import props from './props';
  10. import { getBackgroundColor } from './utils';
  11. import { isNumber } from '../common/utils';
  12. const { prefix } = config;
  13. const classPrefix = `${prefix}-progress`;
  14. let Progress = class Progress extends SuperComponent {
  15. constructor() {
  16. super(...arguments);
  17. this.externalClasses = [`${prefix}-class`, `${prefix}-class-bar`, `${prefix}-class-label`];
  18. this.options = {
  19. multipleSlots: true,
  20. };
  21. this.properties = props;
  22. this.data = {
  23. prefix,
  24. classPrefix,
  25. colorBar: '',
  26. heightBar: '',
  27. computedStatus: '',
  28. computedProgress: 0,
  29. };
  30. this.observers = {
  31. percentage(percentage) {
  32. percentage = Math.max(0, Math.min(percentage, 100));
  33. this.setData({
  34. computedStatus: percentage === 100 ? 'success' : '',
  35. computedProgress: percentage,
  36. });
  37. },
  38. color(color) {
  39. this.setData({
  40. colorBar: getBackgroundColor(color),
  41. });
  42. },
  43. strokeWidth(strokeWidth) {
  44. if (!strokeWidth) {
  45. return '';
  46. }
  47. const height = isNumber(strokeWidth) ? `${strokeWidth}px` : strokeWidth;
  48. this.setData({ heightBar: height });
  49. },
  50. };
  51. }
  52. };
  53. Progress = __decorate([
  54. wxComponent()
  55. ], Progress);
  56. export default Progress;