index.js 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)
  17. if (res.needAuthorization) {
  18. this.setData({
  19. state: true
  20. })
  21. if (typeof this.getTabBar === 'function') {
  22. this.getTabBar().setData({
  23. mask: true
  24. })
  25. }
  26. } else {
  27. this.triggerEvent("agree")
  28. }
  29. },
  30. fail: () => {},
  31. complete: () => {},
  32. })
  33. } else {
  34. // 低版本基础库不支持 wx.getPrivacySetting 接口,隐私接口可以直接调用
  35. this.triggerEvent("agree")
  36. }
  37. },
  38. },
  39. methods: {
  40. handleAgree(e) {
  41. this.triggerEvent("agree")
  42. this.setData({
  43. state: false
  44. })
  45. this.getTabBar().setData({
  46. mask: false
  47. })
  48. },
  49. openPrivacyContract() {
  50. wx.openPrivacyContract({
  51. success: res => {
  52. console.log('openPrivacyContract success')
  53. },
  54. fail: res => {
  55. console.error('openPrivacyContract fail', res)
  56. }
  57. })
  58. }
  59. }
  60. })