loading.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. const { prefix } = config;
  11. const name = `${prefix}-loading`;
  12. let Loading = class Loading extends SuperComponent {
  13. constructor() {
  14. super(...arguments);
  15. this.externalClasses = [`${prefix}-class`, `${prefix}-class-text`, `${prefix}-class-indicator`];
  16. this.data = {
  17. prefix,
  18. classPrefix: name,
  19. show: true,
  20. };
  21. this.options = {
  22. multipleSlots: true,
  23. };
  24. this.properties = Object.assign({}, props);
  25. this.timer = null;
  26. this.observers = {
  27. loading(cur) {
  28. const { delay } = this.properties;
  29. if (this.timer) {
  30. clearTimeout(this.timer);
  31. }
  32. if (cur) {
  33. if (delay) {
  34. this.timer = setTimeout(() => {
  35. this.setData({ show: cur });
  36. this.timer = null;
  37. }, delay);
  38. }
  39. else {
  40. this.setData({ show: cur });
  41. }
  42. }
  43. else {
  44. this.setData({ show: cur });
  45. }
  46. },
  47. };
  48. this.lifetimes = {
  49. detached() {
  50. clearTimeout(this.timer);
  51. },
  52. };
  53. }
  54. refreshPage() {
  55. this.triggerEvent('reload');
  56. }
  57. };
  58. Loading = __decorate([
  59. wxComponent()
  60. ], Loading);
  61. export default Loading;