index.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. let ARRAY = [];
  2. Component({
  3. externalClasses: ['wr-class'],
  4. options: {
  5. multipleSlots: true,
  6. },
  7. properties: {
  8. disabled: Boolean,
  9. leftWidth: {
  10. type: Number,
  11. value: 0,
  12. },
  13. rightWidth: {
  14. type: Number,
  15. value: 0,
  16. },
  17. asyncClose: Boolean,
  18. },
  19. attached() {
  20. ARRAY.push(this);
  21. },
  22. detached() {
  23. ARRAY = ARRAY.filter((item) => item !== this);
  24. },
  25. /**
  26. * Component initial data
  27. */
  28. data: {
  29. wrapperStyle: '',
  30. asyncClose: false,
  31. closed: true,
  32. },
  33. /**
  34. * Component methods
  35. */
  36. methods: {
  37. open(position) {
  38. this.setData({ closed: false });
  39. this.triggerEvent('close', {
  40. position,
  41. instance: this,
  42. });
  43. },
  44. close() {
  45. this.setData({ closed: true });
  46. },
  47. closeOther() {
  48. ARRAY.filter((item) => item !== this).forEach((item) => item.close());
  49. },
  50. noop() {
  51. return;
  52. },
  53. onClick(event) {
  54. const { key: position = 'outside' } = event.currentTarget.dataset;
  55. this.triggerEvent('click', position);
  56. if (this.data.closed) {
  57. return;
  58. }
  59. if (this.data.asyncClose) {
  60. this.triggerEvent('close', {
  61. position,
  62. instance: this,
  63. });
  64. } else {
  65. this.close();
  66. }
  67. },
  68. },
  69. });