swipe-out.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. let Siblings: CustomComponent[] = []
  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. Siblings.push(this)
  21. },
  22. detached() {
  23. Siblings = Siblings.filter((item) => item !== this)
  24. },
  25. data: {
  26. wrapperStyle: '',
  27. asyncClose: false,
  28. closed: true,
  29. },
  30. methods: {
  31. open(position: number) {
  32. this.setData({ closed: false })
  33. this.triggerEvent('close', {
  34. position,
  35. instance: this,
  36. })
  37. },
  38. close() {
  39. this.setData({ closed: true })
  40. },
  41. closeOther() {
  42. Siblings.filter((item) => item !== this).forEach((item) => item.close())
  43. },
  44. noop() {
  45. return
  46. },
  47. onClick(event: WechatMiniprogram.BaseEvent) {
  48. const { key: position = 'outside' } = event.currentTarget.dataset
  49. this.triggerEvent('click', position)
  50. if (this.data.closed) {
  51. return
  52. }
  53. if (this.data.asyncClose) {
  54. this.triggerEvent('close', {
  55. position,
  56. instance: this,
  57. })
  58. } else {
  59. this.close()
  60. }
  61. },
  62. },
  63. })