swipe-cell.js 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
  8. function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
  9. return new (P || (P = Promise))(function (resolve, reject) {
  10. function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
  11. function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
  12. function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
  13. step((generator = generator.apply(thisArg, _arguments || [])).next());
  14. });
  15. };
  16. import dom from '../behaviors/dom';
  17. import { SuperComponent, wxComponent } from '../common/src/index';
  18. import config from '../common/config';
  19. import props from './props';
  20. let ARRAY = [];
  21. const { prefix } = config;
  22. let SwiperCell = class SwiperCell extends SuperComponent {
  23. constructor() {
  24. super(...arguments);
  25. this.behaviors = [dom];
  26. this.externalClasses = ['t-class'];
  27. this.options = {
  28. multipleSlots: true,
  29. };
  30. this.properties = props;
  31. this.data = {
  32. wrapperStyle: '',
  33. closed: true,
  34. opened: false,
  35. classPrefix: `.${prefix}-swipe-cell`,
  36. };
  37. }
  38. attached() {
  39. ARRAY.push(this);
  40. wx.nextTick(() => {
  41. this.setSwipeWidth();
  42. });
  43. }
  44. setSwipeWidth() {
  45. return __awaiter(this, void 0, void 0, function* () {
  46. const rightRect = yield this.gettingBoundingClientRect(`${this.data.classPrefix}__right`);
  47. const leftRect = yield this.gettingBoundingClientRect(`${this.data.classPrefix}__left`);
  48. this.setData({
  49. leftWidth: leftRect.width,
  50. rightWidth: rightRect.width,
  51. });
  52. });
  53. }
  54. detached() {
  55. ARRAY = ARRAY.filter((item) => item !== this);
  56. }
  57. open() {
  58. this.setData({ opened: true });
  59. }
  60. close() {
  61. this.setData({ opened: false });
  62. }
  63. closeOther() {
  64. ARRAY.filter((item) => item !== this).forEach((item) => item.close());
  65. }
  66. onTap() {
  67. this.close();
  68. }
  69. onActionTap(event) {
  70. const { currentTarget: { dataset: { action }, }, } = event;
  71. this.triggerEvent('click', action);
  72. }
  73. };
  74. SwiperCell = __decorate([
  75. wxComponent()
  76. ], SwiperCell);
  77. export default SwiperCell;
  78. //# sourceMappingURL=swipe-cell.js.map