const app = getApp() import request from '../../utils/request' import { timestampToTime } from '../../utils/util' import Dialog from '@vant/weapp/dialog/dialog'; Page({ data: { isLogin: false, itemList: [ { id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }, { id: 5 }, { id: 6 }, ], showPrivacy: false, avatarUrl: "../../asset/icon/logo-5.png" }, // 事件处理函数 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) { wx.hideHomeButton() this.getPrivacySetting() }, onShow() { const isLogin = wx.getStorageSync('token') this.setData({ isLogin }) app.tokenCallBack = res => { this.setData({ isLogin: res }) } }, 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 }); }, goLogin() { wx.redirectTo({ url: '/pages/login/login', }) }, goCheckImage(e) { console.log(e, 'e'); const id = e.currentTarget.dataset.id wx.navigateTo({ url: `/pages/checkImg/checkImg?id=${id}`, }) }, 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 } } })