储能智慧云小程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 { SuperComponent, wxComponent } from '../../common/src/index';
  17. import config from '../../common/config';
  18. import props from './props';
  19. import { getRect } from '../../common/utils';
  20. const systemInfo = wx.getSystemInfoSync();
  21. const { prefix } = config;
  22. const name = `${prefix}-draggable`;
  23. let Draggable = class Draggable extends SuperComponent {
  24. constructor() {
  25. super(...arguments);
  26. this.properties = props;
  27. this.externalClasses = [`${prefix}-class`];
  28. this.data = {
  29. prefix,
  30. classPrefix: name,
  31. };
  32. this.lifetimes = {
  33. ready() {
  34. this.computedRect();
  35. },
  36. };
  37. this.methods = {
  38. onTouchStart(e) {
  39. if (this.properties.direction === 'none')
  40. return;
  41. this.startX = e.touches[0].clientX + systemInfo.windowWidth - this.rect.right;
  42. this.startY = e.touches[0].clientY + systemInfo.windowHeight - this.rect.bottom;
  43. this.triggerEvent('start', { startX: this.startX, startY: this.startY, rect: this.rect, e });
  44. },
  45. onTouchMove(e) {
  46. if (this.properties.direction === 'none')
  47. return;
  48. let x = this.startX - e.touches[0].clientX;
  49. let y = this.startY - e.touches[0].clientY;
  50. if (this.properties.direction === 'vertical') {
  51. x = systemInfo.windowWidth - this.rect.right;
  52. }
  53. if (this.properties.direction === 'horizontal') {
  54. y = systemInfo.windowHeight - this.rect.bottom;
  55. }
  56. this.triggerEvent('move', { x, y, rect: this.rect, e });
  57. },
  58. onTouchEnd(e) {
  59. return __awaiter(this, void 0, void 0, function* () {
  60. if (this.properties.direction === 'none')
  61. return;
  62. yield this.computedRect();
  63. this.triggerEvent('end', { rect: this.rect, e });
  64. });
  65. },
  66. computedRect() {
  67. return __awaiter(this, void 0, void 0, function* () {
  68. this.rect = { right: 0, bottom: 0, width: 0, height: 0 };
  69. this.rect = yield getRect(this, `.${this.data.classPrefix}`);
  70. });
  71. },
  72. };
  73. }
  74. };
  75. Draggable = __decorate([
  76. wxComponent()
  77. ], Draggable);
  78. export default Draggable;