From c08385b13cce6cccad4444379abd0c77af171a74 Mon Sep 17 00:00:00 2001 From: jiannibang <271381693@qq.com> Date: Tue, 7 May 2024 15:54:57 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=BC=93=E5=AD=98openid,=E6=B2=A1?= =?UTF-8?q?=E6=9C=89openid=E6=97=B6=E8=B7=B3=E8=BF=87=E9=9A=90=E7=A7=81?= =?UTF-8?q?=E5=8D=8F=E8=AE=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 12 +++++++++++- pages/h5map/index.js | 3 ++- project.config.json | 1 - 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app.js b/app.js index b61b222..cf0a1a4 100644 --- a/app.js +++ b/app.js @@ -52,6 +52,14 @@ App({ async onLaunch() { // 展示本地存储能力 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 { const { code } = await new Promise((resolve, reject) => { wx.login({ @@ -63,10 +71,12 @@ App({ code, }); this.globalData.openid = data ? data.openid : null; + wx.setStorageSync("openid", this.globalData.openid); + this.openidCbs.forEach((cb) => cb(this.globalData.openid)); } catch (error) { console.warn(error); + this.openidCbs.forEach((cb) => cb(null)); } - this.openidCbs.forEach((cb) => cb(this.globalData.openid)); }, onOpenid(cb) { this.openidCbs.push(cb); diff --git a/pages/h5map/index.js b/pages/h5map/index.js index afd8755..75915bf 100644 --- a/pages/h5map/index.js +++ b/pages/h5map/index.js @@ -25,7 +25,8 @@ Page({ const app = getApp(); if (!app.globalData.openid) { 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) return wx.redirectTo({ url: `/pages/agreement/index?q=${q}&e=${e}&s=${s}&plate=${plate}`, diff --git a/project.config.json b/project.config.json index 71a72bc..dd628da 100644 --- a/project.config.json +++ b/project.config.json @@ -45,7 +45,6 @@ "tabIndent": "insertSpaces", "tabSize": 4 }, - "libVersion": "2.24.3", "packOptions": { "ignore": [], "include": []