运维小程序
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

swipe-cell.js 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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 { getRect } from '../common/utils';
  11. import { getObserver } from '../common/wechat';
  12. let ARRAY = [];
  13. const { prefix } = config;
  14. const name = `${prefix}-swipe-cell`;
  15. const ContainerClass = `.${name}`;
  16. let SwiperCell = class SwiperCell extends SuperComponent {
  17. constructor() {
  18. super(...arguments);
  19. this.externalClasses = [`${prefix}-class`];
  20. this.options = {
  21. multipleSlots: true,
  22. };
  23. this.properties = props;
  24. this.data = {
  25. prefix,
  26. wrapperStyle: '',
  27. closed: true,
  28. classPrefix: name,
  29. };
  30. this.observers = {
  31. 'left, right'() {
  32. this.setSwipeWidth();
  33. },
  34. };
  35. this.lifetimes = {
  36. attached() {
  37. ARRAY.push(this);
  38. },
  39. ready() {
  40. this.setSwipeWidth();
  41. },
  42. detached() {
  43. ARRAY = ARRAY.filter((item) => item !== this);
  44. },
  45. };
  46. }
  47. setSwipeWidth() {
  48. Promise.all([getRect(this, `${ContainerClass}__left`), getRect(this, `${ContainerClass}__right`)]).then(([leftRect, rightRect]) => {
  49. if (leftRect.width === 0 && rightRect.width === 0 && !this._hasObserved) {
  50. this._hasObserved = true;
  51. getObserver(this, `.${name}`).then(() => {
  52. this.setSwipeWidth();
  53. });
  54. }
  55. this.setData({
  56. leftWidth: leftRect.width,
  57. rightWidth: rightRect.width,
  58. });
  59. });
  60. }
  61. open() {
  62. this.setData({ opened: true });
  63. }
  64. close() {
  65. this.setData({ opened: false });
  66. }
  67. closeOther() {
  68. ARRAY.filter((item) => item !== this).forEach((item) => item.close());
  69. }
  70. onTap() {
  71. this.close();
  72. }
  73. onActionTap(event) {
  74. const { currentTarget: { dataset: { action }, }, } = event;
  75. this.triggerEvent('click', action);
  76. }
  77. };
  78. SwiperCell = __decorate([
  79. wxComponent()
  80. ], SwiperCell);
  81. export default SwiperCell;