progress.js 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 { unitConvert, getRect } from '../common/utils';
  12. const { prefix } = config;
  13. const name = `${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: name,
  25. colorBar: '',
  26. heightBar: '',
  27. computedStatus: '',
  28. computedProgress: 0,
  29. isIOS: false,
  30. };
  31. this.observers = {
  32. percentage(percentage) {
  33. percentage = Math.max(0, Math.min(percentage, 100));
  34. this.setData({
  35. computedStatus: percentage === 100 ? 'success' : '',
  36. computedProgress: percentage,
  37. });
  38. },
  39. color(color) {
  40. this.setData({
  41. colorBar: getBackgroundColor(color),
  42. colorCircle: typeof color === 'object' ? '' : color,
  43. });
  44. },
  45. strokeWidth(strokeWidth) {
  46. if (!strokeWidth) {
  47. return '';
  48. }
  49. this.setData({
  50. heightBar: unitConvert(strokeWidth),
  51. });
  52. },
  53. theme(theme) {
  54. if (theme === 'circle') {
  55. this.getInnerDiameter();
  56. }
  57. },
  58. trackColor(trackColor) {
  59. this.setData({
  60. bgColorBar: trackColor,
  61. });
  62. },
  63. };
  64. this.methods = {
  65. getInnerDiameter() {
  66. const { strokeWidth } = this.properties;
  67. const wrapID = `.${name}__canvas--circle`;
  68. if (strokeWidth) {
  69. getRect(this, wrapID).then((wrapRect) => {
  70. this.setData({
  71. innerDiameter: wrapRect.width - unitConvert(strokeWidth) * 2,
  72. });
  73. });
  74. }
  75. },
  76. };
  77. }
  78. attached() {
  79. wx.getSystemInfo({
  80. success: (res) => {
  81. const isIOS = !!(res.system.toLowerCase().search('ios') + 1);
  82. this.setData({
  83. isIOS,
  84. });
  85. },
  86. fail: (err) => {
  87. console.error('progress 获取系统信息失败', err);
  88. },
  89. });
  90. }
  91. };
  92. Progress = __decorate([
  93. wxComponent()
  94. ], Progress);
  95. export default Progress;