index.js 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import zIndex from '../behaviors/zIndex';
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. behaviors: [zIndex],
  7. externalClasses: ['l-bg-class'],
  8. properties: {
  9. // 显示与隐藏
  10. show: {
  11. type: Boolean,
  12. value: false
  13. },
  14. // 动画效果的显示和隐藏
  15. animation: {
  16. type: Boolean,
  17. value: true
  18. },
  19. // slot的位置
  20. contentAlign: {
  21. type: String,
  22. value: 'center'
  23. },
  24. // 锁定
  25. locked: {
  26. type: Boolean,
  27. value: false
  28. }
  29. },
  30. attached() {
  31. this._init();
  32. },
  33. pageLifetimes: {
  34. show() {
  35. this._init();
  36. },
  37. },
  38. /**
  39. * 组件的初始数据
  40. */
  41. data: {
  42. status: 'show'
  43. },
  44. /**
  45. * 组件的方法列表
  46. */
  47. methods: {
  48. _init() {
  49. wx.lin = wx.lin || {};
  50. wx.lin.showPopup = (options) => {
  51. const {
  52. zIndex = 99,
  53. animation = true,
  54. contentAlign = 'center',
  55. locked = false
  56. } = { ...options };
  57. this.setData({
  58. zIndex,
  59. animation,
  60. contentAlign,
  61. locked,
  62. show: true
  63. });
  64. };
  65. wx.lin.hidePopup = () => {
  66. this.setData({
  67. status: 'hide'
  68. });
  69. setTimeout(()=>{
  70. this.setData({
  71. show: false
  72. });
  73. },300);
  74. };
  75. },
  76. // 阻止滑动
  77. doNothingMove() {
  78. // do nothing……
  79. },
  80. doNothingTap() {
  81. // do nathing
  82. },
  83. // 点击事件
  84. onPupopTap() {
  85. let detail = true;
  86. let option = { bubbles: true, composed: true };
  87. if (this.data.locked !== true) {
  88. if(!this.data.show) {
  89. this.setData({
  90. show: true,
  91. status: 'show'
  92. });
  93. } else {
  94. this.setData({
  95. status: 'hide'
  96. });
  97. setTimeout(()=>{
  98. this.setData({
  99. show: false,
  100. status: 'show'
  101. });
  102. },300);
  103. }
  104. // this.setData({
  105. // show: !this.data.show
  106. // });
  107. }
  108. this.triggerEvent('lintap', detail, option);
  109. }
  110. }
  111. });