Browse Source

feat: 缓存openid,没有openid时跳过隐私协议

master
jiannibang 2 years ago
parent
commit
c08385b13c
  1. 12
      app.js
  2. 3
      pages/h5map/index.js
  3. 1
      project.config.json

12
app.js

@ -52,6 +52,14 @@ App({
async onLaunch() { async onLaunch() {
// 展示本地存储能力 // 展示本地存储能力
getMapData(); getMapData();
try {
this.globalData.openid = wx.getStorageSync("openid");
} catch (e) {
console.log(e);
}
if (this.globalData.openid)
return this.openidCbs.forEach((cb) => cb(this.globalData.openid));
try { try {
const { code } = await new Promise((resolve, reject) => { const { code } = await new Promise((resolve, reject) => {
wx.login({ wx.login({
@ -63,10 +71,12 @@ App({
code, code,
}); });
this.globalData.openid = data ? data.openid : null; this.globalData.openid = data ? data.openid : null;
wx.setStorageSync("openid", this.globalData.openid);
this.openidCbs.forEach((cb) => cb(this.globalData.openid));
} catch (error) { } catch (error) {
console.warn(error); console.warn(error);
this.openidCbs.forEach((cb) => cb(null));
} }
this.openidCbs.forEach((cb) => cb(this.globalData.openid));
}, },
onOpenid(cb) { onOpenid(cb) {
this.openidCbs.push(cb); this.openidCbs.push(cb);

3
pages/h5map/index.js

@ -25,7 +25,8 @@ Page({
const app = getApp(); const app = getApp();
if (!app.globalData.openid) { if (!app.globalData.openid) {
const openid = await new Promise((resolve) => app.onOpenid(resolve)); const openid = await new Promise((resolve) => app.onOpenid(resolve));
const agreed = await this.getAgreement();
let agreed = true;
if (openid) agreed = await this.getAgreement();
if (!agreed) if (!agreed)
return wx.redirectTo({ return wx.redirectTo({
url: `/pages/agreement/index?q=${q}&e=${e}&s=${s}&plate=${plate}`, url: `/pages/agreement/index?q=${q}&e=${e}&s=${s}&plate=${plate}`,

1
project.config.json

@ -45,7 +45,6 @@
"tabIndent": "insertSpaces", "tabIndent": "insertSpaces",
"tabSize": 4 "tabSize": 4
}, },
"libVersion": "2.24.3",
"packOptions": { "packOptions": {
"ignore": [], "ignore": [],
"include": [] "include": []

Loading…
Cancel
Save