邃芒智像相册
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

149 řádky
3.6 KiB

  1. const app = getApp()
  2. import request from '../../utils/request'
  3. import { timestampToTime } from '../../utils/util'
  4. Page({
  5. data: {
  6. showPrivacy: false
  7. },
  8. // 事件处理函数
  9. clickPrivacy(e) {
  10. },
  11. closePrivacy() {
  12. wx.exitMiniProgram()
  13. },
  14. getPrivacySetting() {
  15. const canIUsePrivacy = wx.canIUse('getPrivacySetting')
  16. console.log(canIUsePrivacy, 'canIUse getPrivacySetting')
  17. if (canIUsePrivacy) {
  18. wx.getPrivacySetting({
  19. success: res => {
  20. console.log(res, 'getPrivacySetting') // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
  21. if (res.needAuthorization) {
  22. // 需要弹出隐私协议
  23. this.setData({
  24. showPrivacy: true
  25. })
  26. } else {
  27. // this.setData({
  28. // showPrivacy: true
  29. // })
  30. // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
  31. // wx.getUserProfile()
  32. // wx.chooseMedia()
  33. // wx.getClipboardData()
  34. // wx.startRecord()
  35. // this.setData({
  36. // showPrivacy: true
  37. // })
  38. }
  39. },
  40. fail: () => { },
  41. complete: () => { }
  42. })
  43. }
  44. },
  45. handleAgreePrivacyAuthorization() {
  46. console.log('Privacy Agreed!');
  47. this.setData({
  48. showPrivacy: false
  49. })
  50. // 用户同意隐私协议事件回调
  51. // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
  52. // wx.getUserProfile()
  53. // wx.chooseMedia()
  54. // wx.getClipboardData()
  55. // wx.startRecord()
  56. },
  57. handleOpenPrivacyContract() {
  58. // 打开隐私协议页面
  59. wx.openPrivacyContract({
  60. success: () => {
  61. // this.setData({
  62. // showPrivacy: false
  63. // })
  64. }, // 打开成功
  65. fail: () => { }, // 打开失败
  66. complete: () => { }
  67. })
  68. },
  69. onLoad(option) {
  70. this.getPrivacySetting()
  71. },
  72. onShow() {
  73. },
  74. getUserProfile() {
  75. // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
  76. wx.getUserProfile({
  77. desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  78. success: (res) => {
  79. console.log(res, 'getUserProfile')
  80. }
  81. })
  82. },
  83. getUserPhone(e) {
  84. const sessionKey = wx.getStorageSync('sessionKey')
  85. this.doGetUserPhone(e.detail.encryptedData, e.detail.iv, sessionKey, request.appId)
  86. },
  87. /** 获取手机号授权 */
  88. doGetUserPhone(encryptedData, iv, sessionKey, appId) {
  89. request.post({
  90. url: '/api/user/getUserPhone',
  91. data: {
  92. encryptedData,
  93. iv,
  94. sessionKey,
  95. appId
  96. }
  97. }).then(res => {
  98. console.log(res, 'getUserPhone');
  99. wx.showToast({
  100. title: '申请成功!',
  101. icon: 'success'
  102. })
  103. this.checkUserInfo()
  104. }).catch(err => {
  105. console.log(err, 'err');
  106. })
  107. },
  108. onShareAppMessage() {
  109. const promise = new Promise(resolve => {
  110. setTimeout(() => {
  111. resolve({
  112. title: '小闲聊'
  113. })
  114. }, 500)
  115. })
  116. return {
  117. title: '小闲聊',
  118. promise
  119. }
  120. },
  121. onShareTimeline() {
  122. const promise = new Promise(resolve => {
  123. setTimeout(() => {
  124. resolve({
  125. title: '小闲聊'
  126. })
  127. }, 500)
  128. })
  129. return {
  130. title: '小闲聊',
  131. promise
  132. }
  133. }
  134. })