| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- // 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)
- }
- })
- }
- }
- })
|