index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { __awaiter, __generator } from "tslib";
  2. import { PaginationDefaultProps } from './props';
  3. import '../_util/assert-component2';
  4. Component({
  5. props: PaginationDefaultProps,
  6. data: {
  7. pageDeg: 0,
  8. supportSjs: my.canIUse('sjs.event'),
  9. },
  10. wrapWidth: 0,
  11. methods: {
  12. clacWidth: function () {
  13. return __awaiter(this, void 0, void 0, function () {
  14. var _this = this;
  15. return __generator(this, function (_a) {
  16. return [2 /*return*/, new Promise(function (resolve) {
  17. my.createSelectorQuery()
  18. .select("#ant-pageInfinite-".concat(_this.$id))
  19. .boundingClientRect()
  20. .exec(function (ret) {
  21. if (ret && ret[0]) {
  22. _this.wrapWidth = ret[0].width;
  23. }
  24. resolve(_this.wrapWidth);
  25. });
  26. })];
  27. });
  28. });
  29. },
  30. onScroll: function (e) {
  31. return __awaiter(this, void 0, void 0, function () {
  32. var _a, scrollLeft, scrollWidth, viewWidth;
  33. return __generator(this, function (_b) {
  34. switch (_b.label) {
  35. case 0:
  36. _a = e.detail, scrollLeft = _a.scrollLeft, scrollWidth = _a.scrollWidth;
  37. return [4 /*yield*/, this.clacWidth()];
  38. case 1:
  39. viewWidth = _b.sent();
  40. if (viewWidth) {
  41. this.setData({
  42. pageDeg: Math.ceil((scrollLeft / (scrollWidth - viewWidth)) * 100),
  43. });
  44. }
  45. return [2 /*return*/];
  46. }
  47. });
  48. });
  49. },
  50. },
  51. });