privacyPopup.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // miniprogram/privacyPopup/privacyPopup.js
  2. Component({
  3. data: {
  4. title: "用户隐私保护提示",
  5. desc1: "尊敬的用户: 您好!感谢您使用本产品,您在使用本产品前应当阅读并同意",
  6. urlTitle: "《用户隐私保护指引》",
  7. desc2: "如您同意",
  8. desc3: "请您点击“同意”按钮后使用我们的产品和服务,我们将依法保护您的个人信息",
  9. innerShow: false,
  10. height: 0,
  11. },
  12. lifetimes: {
  13. attached: function () {
  14. if (wx.getPrivacySetting) {
  15. wx.getPrivacySetting({
  16. success: res => {
  17. console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName)
  18. this.setData({
  19. urlTitle: res.privacyContractName
  20. })
  21. if (res.needAuthorization) {
  22. this.popUp()
  23. } else {
  24. this.triggerEvent("agree")
  25. }
  26. },
  27. fail: () => { },
  28. complete: () => { },
  29. })
  30. } else {
  31. // 低版本基础库不支持 wx.getPrivacySetting 接口,隐私接口可以直接调用
  32. this.triggerEvent("agree")
  33. }
  34. },
  35. },
  36. methods: {
  37. handleDisagree(e) {
  38. this.triggerEvent("disagree");
  39. wx.showModal({
  40. content: '很抱歉,如您不同意' + this.data.urlTitle + '可能无法继续正常使用我们的产品和服务,请您先同意哦~',
  41. confirmText: "好的",
  42. cancelText: "不同意",
  43. complete: (res) => {
  44. if (res.cancel) {
  45. wx.exitMiniProgram()
  46. }
  47. if (res.confirm) {
  48. }
  49. }
  50. })
  51. },
  52. handleAgree(e) {
  53. this.triggerEvent("agree");
  54. this.disPopUp()
  55. },
  56. popUp() {
  57. this.setData({
  58. innerShow: true
  59. })
  60. },
  61. disPopUp() {
  62. this.setData({
  63. innerShow: false
  64. })
  65. },
  66. openPrivacyContract() {
  67. wx.openPrivacyContract({
  68. success: res => {
  69. console.log('openPrivacyContract success')
  70. },
  71. fail: res => {
  72. console.error('openPrivacyContract fail', res)
  73. }
  74. })
  75. }
  76. }
  77. })