privacyPopup.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. var app = getApp()
  2. Component({
  3. data: {
  4. title: "用户隐私保护提示",
  5. desc1: "感谢您使用《未来GO》小程序,您使用本小程序前应当阅并同意",
  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. wx.showToast({
  61. title: '需同意后才可使用未来GO小程序!',
  62. icon:'none'
  63. })
  64. // this.disPopUp()
  65. },
  66. handleAgree(e) {
  67. this.triggerEvent("agree")
  68. this.disPopUp()
  69. },
  70. popUp() {
  71. this.setData({
  72. innerShow: true
  73. })
  74. },
  75. disPopUp() {
  76. this.setData({
  77. innerShow: false
  78. })
  79. },
  80. openPrivacyContract() {
  81. wx.openPrivacyContract({
  82. success: res => {
  83. console.log('openPrivacyContract success')
  84. },
  85. fail: res => {
  86. console.error('openPrivacyContract fail', res)
  87. }
  88. })
  89. }
  90. }
  91. })