index.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. import zIndex from '../behaviors/zIndex';
  2. import hover from '../behaviors/hover';
  3. Component({
  4. behaviors: [zIndex,hover],
  5. externalClasses: ['l-class-title', 'l-class-item', 'l-class-cancel','l-title-class','l-item-class','l-cancel-class'],
  6. properties: {
  7. locked: Boolean,
  8. showCancel: Boolean,
  9. show: Boolean,
  10. itemList: Array,
  11. cancelText: {
  12. type: String,
  13. value: '取消'
  14. },
  15. title: String,
  16. zIndex:{
  17. type:Number,
  18. value: 777
  19. },
  20. openApi: {
  21. type: Boolean,
  22. value: true,
  23. }
  24. },
  25. data: {
  26. success: '',
  27. fail: '',
  28. isIphoneX: false
  29. },
  30. attached() {
  31. if (this.data.openApi) {
  32. this.initActionSheet();
  33. }
  34. this.initUIAdapter();
  35. },
  36. pageLifetimes: {
  37. show() {
  38. if (this.data.openApi) {
  39. this.initActionSheet();
  40. }
  41. },
  42. },
  43. methods: {
  44. /**
  45. * 区分UI尺寸
  46. */
  47. initUIAdapter() {
  48. wx.getSystemInfo({
  49. success: (res) => {
  50. this.setData({
  51. isIphoneX: res.model == 'iPhone X' ? true : false,
  52. });
  53. }
  54. });
  55. },
  56. initActionSheet() {
  57. wx.lin = wx.lin || {};
  58. wx.lin.showActionSheet = (options={}) => {
  59. const {
  60. itemList = [],
  61. success = null,
  62. fail = null,
  63. title = '',
  64. locked = false,
  65. cancelText = '取消',
  66. showCancel = false,
  67. } = options;
  68. this.setData({
  69. itemList: itemList.slice(0, 10),
  70. success,
  71. fail,
  72. title,
  73. locked,
  74. cancelText,
  75. showCancel,
  76. show: true,
  77. });
  78. return this;
  79. };
  80. },
  81. handleClickItem(e) {
  82. const {
  83. success
  84. } = this.data;
  85. success && success({ ...e.currentTarget.dataset });
  86. this.triggerEvent('linitemtap', { ...e.currentTarget.dataset },{ bubbles: true, composed: true });
  87. this._hideActionSheet();
  88. },
  89. _showActionSheet() {
  90. this.setData({
  91. show: true
  92. });
  93. },
  94. _hideActionSheet() {
  95. this.setData({
  96. show: false
  97. });
  98. },
  99. handleClickCancel() {
  100. const {
  101. fail
  102. } = this.data;
  103. fail && fail({
  104. errMsg: 'showactionsheet:fail cancel'
  105. });
  106. this.triggerEvent('lincancel', {
  107. errMsg: 'showactionsheet:fail cancel'
  108. },{ bubbles: true, composed: true });
  109. this._hideActionSheet();
  110. },
  111. handleClickPopUp() {
  112. if (!this.data.locked) {
  113. this.handleClickCancel();
  114. }
  115. },
  116. }
  117. });