From f449c7c7f2f0c88024f4db956660717d27adc850 Mon Sep 17 00:00:00 2001 From: wuxw <928255095@qq.com> Date: Thu, 18 Jul 2024 23:33:06 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=9B=91=E6=8E=A7=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/user/sessionApi.js | 58 +++++++++++++++++++++++------------------- conf/config.js | 2 +- pages/notice/index.vue | 3 ++- 3 files changed, 35 insertions(+), 28 deletions(-) diff --git a/api/user/sessionApi.js b/api/user/sessionApi.js index 5cc1a8c..4c8859a 100644 --- a/api/user/sessionApi.js +++ b/api/user/sessionApi.js @@ -20,17 +20,17 @@ import { } from '../../api/community/communityApi.js'; import { - saveOwnerStorage, - saveUserLoginInfo, - removeUserLoginInfo, - getWAppId, - saveWAppId, - getLoginFlag - } from '@/lib/java110/utils/StorageUtil.js'; + saveOwnerStorage, + saveUserLoginInfo, + removeUserLoginInfo, + getWAppId, + saveWAppId, + getLoginFlag +} from '@/lib/java110/utils/StorageUtil.js'; import { - isWxOrAli - } from '../../lib/java110/utils/EnvUtil.js'; + isWxOrAli +} from '../../lib/java110/utils/EnvUtil.js'; const LOGIN_FLAG = 'loginFlag'; //登录标识 @@ -57,7 +57,7 @@ export function autoLogin(options) { if (hasLogin()) { return; } - + //todo 如果是 h5 或者 微信小程序 ,检查是否做了配置,如果没有做配置不做自登陆 // #ifdef H5 || MP-WEIXIN autoLoginWechat(options); @@ -71,20 +71,23 @@ export function autoLogin(options) { */ export function autoLoginWechat(options) { let _openId = options.openId; - - if(_openId){ //h5 自登陆的情况 - loginByOpenId(_openId); - return; + if (_openId) { //h5 自登陆的情况 + let _time = uni.getStorageSync('refreshUserOpenId'); + if(_time){ + loginByOpenId(_openId); + uni.removeStorageSync('refreshUserOpenId'); + return; + } } //todo 如果参数中带了wAppId let _wAppId = options.wAppId; - - if(_wAppId){ + + if (_wAppId) { _generatorOpenId(options, _wAppId); return; } - - + + let _objType = "1100"; // todo public // #ifdef MP-WEIXIN _objType = "1000"; @@ -123,6 +126,8 @@ export function _refreshWechatOpenId(options, appId) { wAppId: appId, }).then(_data => { if (_data.code == 0) { + let _date = new Date(); + uni.setStorageSync("refreshUserOpenId", _data.getTime()); window.location.href = _data.data.openUrl; return; } @@ -160,12 +165,12 @@ export function _refreshWechatMiniOpenId() { }); } -export function loginByOpenId(openId){ +export function loginByOpenId(openId) { requestNoAuth({ url: url.ownerUserLoginByOpenId, method: "POST", data: { - openId:openId + openId: openId }, //动态数据 success: function(res) { @@ -174,18 +179,19 @@ export function loginByOpenId(openId){ return; } //todo 保存业主信息 - uni.setStorageSync("userInfo",_json.data); - uni.setStorageSync("currentCommunityInfo",{ - communityId:_json.data.communityId, - communityName:_json.data.communityName, + uni.setStorageSync("userInfo", _json.data); + uni.setStorageSync("currentCommunityInfo", { + communityId: _json.data.communityId, + communityName: _json.data.communityName, }); uni.removeStorageSync("ownerInfo"); saveUserLoginInfo(_json.data.userId, _json.data.token, _json.data.key); + }, fail: function(e) { uni.hideLoading(); reject(e); } }); - -} + +} \ No newline at end of file diff --git a/conf/config.js b/conf/config.js index 30d306e..3043454 100644 --- a/conf/config.js +++ b/conf/config.js @@ -14,7 +14,7 @@ const baseUrl = '/'; // #endif // #ifndef H5 -//服务器域名 小程序 或者 app 时 后端地址 +//服务器域名 小程序 或者 app 时 后端地址 const baseUrl = 'http://127.0.0.1:8008/'; // #endif diff --git a/pages/notice/index.vue b/pages/notice/index.vue index 47a08c6..df7f188 100644 --- a/pages/notice/index.vue +++ b/pages/notice/index.vue @@ -35,6 +35,7 @@ import uniLoadMore from '@/components/uni-load-more/uni-load-more.vue'; /** index.js **/ import context from '../../lib/java110/Java110Context.js'; + import { getCommunityId } from '../../api/community/communityApi.js'; const constant = context.constant; //获取app实例 //获取app实例 const app = getApp().globalData; @@ -61,7 +62,7 @@ onLoad: function(options) { let that = this; context.onLoad(options); - that.communityId = context.getUserInfo().communityId; + that.communityId = getCommunityId(); that._loadNotices(); }, onShow: function() {