back-top.js 2.5 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 { 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. hidden: true,
  31. };
  32. this.observers = {
  33. icon() {
  34. this.setIcon();
  35. },
  36. scrollTop(value) {
  37. const { visibilityHeight } = this.properties;
  38. this.setData({ hidden: value < visibilityHeight });
  39. },
  40. };
  41. this.lifetimes = {
  42. ready() {
  43. const { icon } = this.properties;
  44. this.setIcon(icon);
  45. },
  46. };
  47. this.methods = {
  48. setIcon(v) {
  49. this.setData({
  50. _icon: calcIcon(v, 'backtop'),
  51. });
  52. },
  53. toTop() {
  54. var _a;
  55. this.triggerEvent('to-top');
  56. if (this.$parent) {
  57. (_a = this.$parent) === null || _a === void 0 ? void 0 : _a.setScrollTop(0);
  58. this.setData({ hidden: true });
  59. }
  60. else {
  61. wx.pageScrollTo({
  62. scrollTop: 0,
  63. duration: 300,
  64. });
  65. }
  66. },
  67. };
  68. }
  69. };
  70. BackTop = __decorate([
  71. wxComponent()
  72. ], BackTop);
  73. export default BackTop;