|
- const app = getApp()
- import request from '../../utils/request'
- import { timestampToTime } from '../../utils/util'
- import Dialog from '@vant/weapp/dialog/dialog';
-
- Page({
- data: {
- isLogin: true,
- itemList: [1, 1, 1, 1, 1, 1],
- showPrivacy: false
- },
- // 事件处理函数
-
- clickPrivacy(e) {
-
- },
-
- closePrivacy() {
- wx.exitMiniProgram()
- },
-
- getPrivacySetting() {
- const canIUsePrivacy = wx.canIUse('getPrivacySetting')
- console.log(canIUsePrivacy, 'canIUse getPrivacySetting')
- if (canIUsePrivacy) {
- wx.getPrivacySetting({
- success: res => {
- console.log(res, 'getPrivacySetting') // 返回结果为: res = { needAuthorization: true/false, privacyContractName: '《xxx隐私保护指引》' }
- if (res.needAuthorization) {
- // 需要弹出隐私协议
- this.setData({
- showPrivacy: true
- })
- } else {
- // this.setData({
- // showPrivacy: true
- // })
- // 用户已经同意过隐私协议,所以不需要再弹出隐私协议,也能调用已声明过的隐私接口
- // wx.getUserProfile()
- // wx.chooseMedia()
- // wx.getClipboardData()
- // wx.startRecord()
- // this.setData({
- // showPrivacy: true
- // })
- }
- },
- fail: () => { },
- complete: () => { }
- })
- }
- },
-
- handleAgreePrivacyAuthorization() {
- console.log('Privacy Agreed!');
- this.setData({
- showPrivacy: false
- })
- // 用户同意隐私协议事件回调
- // 用户点击了同意,之后所有已声明过的隐私接口和组件都可以调用了
- // wx.getUserProfile()
- // wx.chooseMedia()
- // wx.getClipboardData()
- // wx.startRecord()
- },
-
- handleOpenPrivacyContract() {
- // 打开隐私协议页面
- wx.openPrivacyContract({
- success: () => {
- // this.setData({
- // showPrivacy: false
- // })
- }, // 打开成功
- fail: () => { }, // 打开失败
- complete: () => { }
- })
- },
-
- onLoad(option) {
- this.getPrivacySetting()
- },
-
- onShow() {
-
- },
-
- getUserProfile() {
- // 推荐使用wx.getUserProfile获取用户信息,开发者每次通过该接口获取用户个人信息均需用户确认,开发者妥善保管用户快速填写的头像昵称,避免重复弹窗
- wx.getUserProfile({
- desc: '展示用户信息', // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
- success: (res) => {
- console.log(res, 'getUserProfile')
- }
- })
- },
-
- getUserPhone(e) {
- const sessionKey = wx.getStorageSync('sessionKey')
- this.doGetUserPhone(e.detail.encryptedData, e.detail.iv, sessionKey, request.appId)
- },
-
- /** 获取手机号授权 */
- doGetUserPhone(encryptedData, iv, sessionKey, appId) {
- request.post({
- url: '/api/user/getUserPhone',
- data: {
- encryptedData,
- iv,
- sessionKey,
- appId
- }
- }).then(res => {
- console.log(res, 'getUserPhone');
- wx.showToast({
- title: '申请成功!',
- icon: 'success'
- })
- this.checkUserInfo()
- }).catch(err => {
- console.log(err, 'err');
- })
- },
-
- showMore() {
- Dialog.confirm({
- title: '删除作品',
- message: '确定要删除这个作品吗?',
- })
- .then(() => {
- // on confirm
- })
- .catch(() => {
- // on cancel
- });
- },
-
- onShareAppMessage() {
- const promise = new Promise(resolve => {
- setTimeout(() => {
- resolve({
- title: '智像小相册'
- })
- }, 500)
- })
- return {
- title: '智像小相册',
- promise
- }
- },
- onShareTimeline() {
- const promise = new Promise(resolve => {
- setTimeout(() => {
- resolve({
- title: '智像小相册'
- })
- }, 500)
- })
- return {
- title: '智像小相册',
- promise
- }
- }
- })
|