index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Component({
  2. properties: {
  3. },
  4. /**
  5. * 组件的初始数据
  6. */
  7. data: {
  8. state: false,
  9. img: ''
  10. },
  11. lifetimes: {
  12. attached: function () {
  13. if (wx.getPrivacySetting) {
  14. wx.getPrivacySetting({
  15. success: res => {
  16. if (res.needAuthorization) {
  17. this.setData({
  18. state: true
  19. })
  20. if (typeof this.getTabBar === 'function') {
  21. this.getTabBar().setData({
  22. mask: true
  23. })
  24. }
  25. } else {
  26. this.triggerEvent("agree")
  27. }
  28. },
  29. fail: () => {},
  30. complete: () => {},
  31. })
  32. } else {
  33. // 低版本基础库不支持 wx.getPrivacySetting 接口,隐私接口可以直接调用
  34. this.triggerEvent("agree")
  35. }
  36. },
  37. },
  38. methods: {
  39. handleAgree(e) {
  40. this.triggerEvent("agree")
  41. this.setData({
  42. state: false
  43. })
  44. this.getTabBar().setData({
  45. mask: false
  46. })
  47. },
  48. openPrivacyContract() {
  49. wx.openPrivacyContract({
  50. success: res => {
  51. console.log('openPrivacyContract success')
  52. },
  53. fail: res => {
  54. console.error('openPrivacyContract fail', res)
  55. }
  56. })
  57. }
  58. }
  59. })