back-top.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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 { calcIcon } from '../common/utils';
  11. const { prefix } = config;
  12. const name = `${prefix}-back-top`;
  13. let BackTop = class BackTop extends SuperComponent {
  14. constructor() {
  15. super(...arguments);
  16. this.externalClasses = [`${prefix}-class`, `${prefix}-class-icon`, `${prefix}-class-text`];
  17. this.options = {
  18. multipleSlots: true,
  19. };
  20. this.properties = props;
  21. this.relations = {
  22. '../pull-down-refresh/pull-down-refresh': {
  23. type: 'ancestor',
  24. },
  25. };
  26. this.data = {
  27. prefix,
  28. classPrefix: name,
  29. _icon: null,
  30. };
  31. this.observers = {
  32. icon() {
  33. this.setIcon();
  34. },
  35. };
  36. this.lifetimes = {
  37. ready() {
  38. this.setIcon();
  39. },
  40. };
  41. this.methods = {
  42. setIcon(v) {
  43. this.setData({
  44. _icon: calcIcon(v, 'backtop'),
  45. });
  46. },
  47. toTop() {
  48. var _a;
  49. this.triggerEvent('to-top');
  50. if (this.$parent) {
  51. (_a = this.$parent) === null || _a === void 0 ? void 0 : _a.setScrollTop(0);
  52. }
  53. else {
  54. wx.pageScrollTo({
  55. scrollTop: 0,
  56. duration: 300,
  57. });
  58. }
  59. },
  60. };
  61. }
  62. };
  63. BackTop = __decorate([
  64. wxComponent()
  65. ], BackTop);
  66. export default BackTop;