privacy-popup.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // component/privacy-popup/privacy-popup.ts
  2. Component({
  3. /**
  4. * 组件的属性列表
  5. */
  6. properties: {
  7. initCheck: {
  8. type: Boolean,
  9. value: false
  10. },
  11. changTabBar: {
  12. type: Boolean,
  13. value: true
  14. }
  15. },
  16. observers: {
  17. show: function (value) {
  18. if(this.properties.changTabBar){
  19. if (value) {
  20. wx.hideTabBar()
  21. } else {
  22. wx.showTabBar()
  23. }
  24. }
  25. }
  26. },
  27. pageLifetimes: {
  28. show() {
  29. if (this.properties.initCheck) {
  30. this.check()
  31. }
  32. }
  33. },
  34. /**
  35. * 组件的初始数据
  36. */
  37. data: {
  38. show: false,
  39. needAuthorization: false,
  40. privacyContractName: ''
  41. },
  42. /**
  43. * 组件的方法列表
  44. */
  45. methods: {
  46. check() {
  47. if (wx.canIUse('getPrivacySetting')) {
  48. wx.getPrivacySetting({
  49. success: res => {
  50. console.log(res)
  51. this.setData({
  52. ...res,
  53. show: res.needAuthorization
  54. })
  55. if (!res.needAuthorization) {
  56. this.privacySubmit()
  57. }
  58. }
  59. })
  60. } else {
  61. this.privacySubmit()
  62. }
  63. },
  64. handleAgreePrivacyAuthorization() {
  65. this.privacySubmit(true)
  66. },
  67. privacySubmit(status = false) {
  68. this.triggerEvent('privacySubmit', {
  69. status
  70. })
  71. this.hidden()
  72. },
  73. hidden() {
  74. this.setData({
  75. show: false
  76. })
  77. },
  78. cancel() {
  79. this.triggerEvent('privacyCancel')
  80. this.hidden()
  81. },
  82. openPrivacyContract() {
  83. wx.openPrivacyContract({
  84. success() {
  85. console.log('打开隐私协议')
  86. }
  87. })
  88. }
  89. }
  90. })