// components/popup/index.js const app = getApp(); Component({ observers: { 'globalData.innerShow': function (value) { // 当globalData.someData发生变化时,这个函数会被调用 //console.log(`globalData.innerShow changed to: ${value}`); if (app.globalData.showModal) { return; } this.setData({ userInfo: wx.getStorageSync('userInfo'), innerShow: app.globalData.innerShow }) this.init(); }, 'globalData.showModal': function (value) { // 当globalData.someData发生变化时,这个函数会被调用 //console.log(`globalData.innerShow changed to: ${value}`); if (app.globalData.value) { return; } this.setData({ userInfo: wx.getStorageSync('userInfo'), innerShow: app.globalData.innerShow }) this.init(); } }, /** * 组件的属性列表 */ properties: { }, /** * 组件的初始数据 */ data: { userInfo: wx.getStorageSync('userInfo'), innerShow: false, showModal: app.globalData.showModal, }, lifetimes: { attached: function () { let that = this; this.setData({ userInfo: wx.getStorageSync('userInfo'), }); app.watch("innerShow", (n, v) => { that.setData({ userInfo: wx.getStorageSync('userInfo') }) if (app.globalData.innerShow) { that.init(); } }) }, }, /** * 组件的方法列表 */ methods: { confirm(e) { this.disPopUp() this.triggerEvent("ok") }, async confirmMobile(e) { let that = this; //console.log(e) if (!e.detail.code) { return; } wx.showLoading({ title: '登录中', mask: true }) wx.login({ async success(res3) { //console.log(res3) let { data } = await app.getApiAsync("/wx/getUserInfo", { code: res3.code, pcode: e.detail.code, shareId: app.globalData.shareId || '' }); that.setData({ userInfo: data.data }); app.globalData.userInfo = data.data; wx.setStorageSync('userInfo', data.data); app.globalData.token = data.token; wx.setStorageSync('token', data.token); that.disPopUp() that.triggerEvent("ok") } }) }, init() { let that = this; if (wx.getPrivacySetting) { wx.getPrivacySetting({ success: res => { //console.log("是否需要授权:", res.needAuthorization, "隐私协议的名称为:", res.privacyContractName) if (res.needAuthorization) { this.popUp() } else if (!that.data.userInfo || !that.data.userInfo.userId) { this.popUp() } else { this.triggerEvent("ok") } }, fail: () => {}, complete: () => {}, }) } else { // 低版本基础库不支持 wx.getPrivacySetting 接口,隐私接口可以直接调用 this.triggerEvent("ok") } }, openUserXieyi() { wx.navigateTo({ url: '/pages/autoPage/autoPage?code=USER_SERVICE_AGREEMENT', }) }, handleDisagree(e) { this.triggerEvent("nok") this.disPopUp() }, handleAgree(e) { //console.log("ok") this.triggerEvent("ok") this.disPopUp() }, popUp() { this.setData({ innerShow: true }) }, disPopUp() { this.setData({ innerShow: false }) }, openPrivacyContract() { wx.openPrivacyContract({ success: res => { //console.log('openPrivacyContract success') }, fail: res => { console.error('openPrivacyContract fail', res) } }) } } })