back-top.js 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. const { icon } = this.properties;
  39. this.setIcon(icon);
  40. },
  41. };
  42. this.methods = {
  43. setIcon(v) {
  44. this.setData({
  45. _icon: calcIcon(v, 'backtop'),
  46. });
  47. },
  48. toTop() {
  49. var _a;
  50. this.triggerEvent('to-top');
  51. if (this.$parent) {
  52. (_a = this.$parent) === null || _a === void 0 ? void 0 : _a.setScrollTop(0);
  53. }
  54. else {
  55. wx.pageScrollTo({
  56. scrollTop: 0,
  57. duration: 300,
  58. });
  59. }
  60. },
  61. };
  62. }
  63. };
  64. BackTop = __decorate([
  65. wxComponent()
  66. ], BackTop);
  67. export default BackTop;