index.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import zIndex from '../behaviors/zIndex';
  2. import watchShow from '../behaviors/watchShow';
  3. Component({
  4. behaviors: [zIndex, watchShow],
  5. externalClasses: ['l-class', 'l-image-class'],
  6. properties: {
  7. show: Boolean,
  8. icon: String,
  9. iconColor: {
  10. type: String,
  11. value: '#fff'
  12. },
  13. iconSize: {
  14. type: String,
  15. value: '28'
  16. },
  17. image: String,
  18. content: String,
  19. type: {
  20. type: String,
  21. value: 'primary'
  22. },
  23. duration: {
  24. type: Number,
  25. value: 1500
  26. },
  27. openApi: {
  28. type: Boolean,
  29. value: true
  30. }
  31. },
  32. data: {
  33. status: false
  34. },
  35. // 解决 addListener undefined 的错误
  36. observers: {
  37. 'icon': function () {}
  38. },
  39. attached() {
  40. this.initMessage();
  41. },
  42. pageLifetimes: {
  43. show() {
  44. this.initMessage();
  45. },
  46. },
  47. methods: {
  48. initMessage() {
  49. wx.lin = wx.lin || {};
  50. wx.lin.showMessage = (options = {}) => {
  51. const {
  52. content = '',
  53. icon = '',
  54. image = '',
  55. type = 'primary',
  56. duration = 1500,
  57. success = null
  58. } = options;
  59. this.data.success = success;
  60. this.setData({
  61. content,
  62. icon,
  63. image,
  64. duration,
  65. type
  66. });
  67. this.changeStatus();
  68. return this;
  69. };
  70. wx.lin.hideMessage = ()=>{
  71. this.setData({
  72. status: false
  73. });
  74. };
  75. }
  76. }
  77. });