privacyPopup.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. var app = getApp()
  2. Component({
  3. data: {
  4. title: "用户隐私保护提示",
  5. desc1: "感谢您使用《" + app.globalData.title + "》小程序,您使用本小程序前应当阅并同意",
  6. urlTitle: "《用户隐私保护指引》",
  7. desc2: "当您点击同意并开始时用产品服务时,即表示你已理解并同息该条款内容,该条款将对您产生法律约束力。如您拒绝,将无法进入小程序。",
  8. innerShow: false,
  9. height: 0,
  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.popUp()
  19. } else {
  20. this.triggerEvent("agree")
  21. }
  22. },
  23. fail: () => {},
  24. complete: () => {},
  25. })
  26. } else {
  27. // 低版本基础库不支持 wx.getPrivacySetting 接口,隐私接口可以直接调用
  28. this.triggerEvent("agree")
  29. }
  30. },
  31. },
  32. methods: {
  33. agreeRef() {
  34. return new Promise((resolve, reject) => {
  35. console.log(wx.getPrivacySetting, 'wx.getPrivacySetting')
  36. if (wx.getPrivacySetting) {
  37. wx.getPrivacySetting({
  38. success: res => {
  39. console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)
  40. if (res.needAuthorization) {
  41. this.popUp()
  42. resolve(false)
  43. } else {
  44. this.triggerEvent("agree")
  45. resolve(true)
  46. }
  47. },
  48. fail: () => {},
  49. complete: () => {},
  50. })
  51. } else {
  52. // 低版本基础库不支持 wx.getPrivacySetting 接口,隐私接口可以直接调用
  53. this.triggerEvent("agree")
  54. resolve(true)
  55. }
  56. })
  57. },
  58. handleDisagree(e) {
  59. this.triggerEvent("disagree")
  60. // this.disPopUp()
  61. },
  62. handleAgree(e) {
  63. this.triggerEvent("agree")
  64. this.disPopUp()
  65. },
  66. popUp() {
  67. this.setData({
  68. innerShow: true
  69. })
  70. },
  71. disPopUp() {
  72. this.setData({
  73. innerShow: false
  74. })
  75. },
  76. openPrivacyContract() {
  77. wx.openPrivacyContract({
  78. success: res => {
  79. console.log('openPrivacyContract success')
  80. },
  81. fail: res => {
  82. console.error('openPrivacyContract fail', res)
  83. }
  84. })
  85. }
  86. }
  87. })