mirror of
https://gitee.com/java110/WechatOwnerService.git
synced 2026-02-23 13:26:40 +08:00
优化业主手机端自登陆问题
This commit is contained in:
parent
14825927ec
commit
b20f54e72c
@ -17,48 +17,43 @@ mapping
|
||||
from '../../constant/MappingConstant.js'
|
||||
|
||||
import {
|
||||
getCurOwner
|
||||
} from '../owner/ownerApi.js'
|
||||
getOwnerTel
|
||||
} from '../owner/ownerApi.js';
|
||||
|
||||
import {getCommunityId} from '../community/communityApi.js'
|
||||
|
||||
/**
|
||||
* 查询订场记录
|
||||
*/
|
||||
export function getBooks(_objData) {
|
||||
return new Promise((resolve, reject) => {
|
||||
getCurOwner()
|
||||
.then(function(_owner) {
|
||||
let d = {
|
||||
page: "1",
|
||||
row: "1000",
|
||||
communityId: _owner.communityId,
|
||||
|
||||
}
|
||||
|
||||
if (_objData ==0){
|
||||
// debugger
|
||||
d['personTel']=_owner.link;
|
||||
}
|
||||
let d = {
|
||||
page: "1",
|
||||
row: "1000",
|
||||
communityId: getCommunityId(),
|
||||
}
|
||||
if (_objData == 0) {
|
||||
d['personTel'] = getOwnerTel();
|
||||
}
|
||||
request({
|
||||
url: url.querySpacePerson,
|
||||
method: "GET",
|
||||
data: d,
|
||||
success: function(res) {
|
||||
// debugger
|
||||
request({
|
||||
url: url.querySpacePerson,
|
||||
method: "GET",
|
||||
data: d,
|
||||
success: function(res) {
|
||||
// debugger
|
||||
if (res.statusCode == 200) {
|
||||
//将业主信息和房屋信息一起返回
|
||||
res.data['owner'] = _owner;
|
||||
resolve(res.data);
|
||||
return;
|
||||
} else {
|
||||
reject("查询订场信息失败");
|
||||
}
|
||||
},
|
||||
fail: function(res) {
|
||||
reject(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
if (res.statusCode == 200) {
|
||||
//将业主信息和房屋信息一起返回
|
||||
//res.data['owner'] = _owner;
|
||||
resolve(res.data);
|
||||
return;
|
||||
} else {
|
||||
reject("查询订场信息失败");
|
||||
}
|
||||
},
|
||||
fail: function(res) {
|
||||
reject(res);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -98,40 +98,14 @@ export function getCommunityName(){
|
||||
*/
|
||||
export function getCurCommunity() {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (hasLogin()) { // 判断是否已经登录
|
||||
//已经登录 去后台查询
|
||||
getCurOwner()
|
||||
.then(function(_ownerInfo) {
|
||||
let _currentCommunityInfo = {
|
||||
communityId: _ownerInfo.communityId,
|
||||
communityName: _ownerInfo.communityName,
|
||||
tel:_ownerInfo.sCommunityTel
|
||||
};
|
||||
resolve(_currentCommunityInfo);
|
||||
},function() {
|
||||
let _currentCommunityInfo = {
|
||||
communityId: mapping.HC_TEST_COMMUNITY_ID,
|
||||
communityName: mapping.HC_TEST_COMMUNITY_NAME,
|
||||
tel:''
|
||||
};
|
||||
resolve(_currentCommunityInfo);
|
||||
})
|
||||
} else {
|
||||
//没有登录直接写演示小区信息
|
||||
getCommunitys({
|
||||
communityId:mapping.HC_TEST_COMMUNITY_ID,
|
||||
page:1,
|
||||
row:1
|
||||
}).then(function(_communitys){
|
||||
let _currentCommunityInfo = {
|
||||
communityId: _communitys[0].communityId,
|
||||
communityName: _communitys[0].name,
|
||||
tel:_communitys[0].tel
|
||||
};
|
||||
resolve(_currentCommunityInfo);
|
||||
})
|
||||
|
||||
let _currentCommunityInfo = uni.getStorageSync("currentCommunityInfo");
|
||||
if(!_currentCommunityInfo){
|
||||
_currentCommunityInfo = {
|
||||
communityId:conf.DEFAULT_COMMUNITY_ID,
|
||||
communityName: conf.DEFAULT_COMMUNITY_NAME
|
||||
}
|
||||
}
|
||||
resolve(_currentCommunityInfo);
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/**
|
||||
* 首页相关 数据封装API
|
||||
* 业主相关 数据封装API
|
||||
* add by 吴学文 2020-09-07
|
||||
* QQ 92825595
|
||||
*
|
||||
@ -22,55 +22,45 @@ export function getOwnerId() {
|
||||
return "-1"
|
||||
}
|
||||
|
||||
export function getOwnerName() {
|
||||
let _ownerInfo = wx.getStorageSync(mapping.OWNER_INFO);
|
||||
if (_ownerInfo) {
|
||||
return _ownerInfo.ownerName;
|
||||
}
|
||||
return "-1"
|
||||
}
|
||||
|
||||
export function getOwnerTel() {
|
||||
let _ownerInfo = wx.getStorageSync(mapping.OWNER_INFO);
|
||||
if (_ownerInfo) {
|
||||
return _ownerInfo.ownerTel;
|
||||
}
|
||||
return "-1"
|
||||
}
|
||||
|
||||
export function getMemberId() {
|
||||
let _ownerInfo = wx.getStorageSync(mapping.OWNER_INFO);
|
||||
if (_ownerInfo) {
|
||||
return _ownerInfo.memberId;
|
||||
}
|
||||
return "-1"
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询当前业主信息
|
||||
*
|
||||
* return {
|
||||
memberId:'',
|
||||
ownerName:'',
|
||||
ownerId:'',
|
||||
ownerTel:''
|
||||
}
|
||||
*/
|
||||
export function getCurOwner() {
|
||||
return new Promise(
|
||||
(resolve, reject) => {
|
||||
let _ownerInfo = wx.getStorageSync(mapping.OWNER_INFO);
|
||||
if (_ownerInfo) {
|
||||
resolve(_ownerInfo);
|
||||
} else {
|
||||
//查询用户信息
|
||||
let _userInfo = wx.getStorageSync(mapping.USER_INFO);
|
||||
if (!_userInfo) {
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
request({
|
||||
url: url.queryAppUserBindingOwner,
|
||||
data: {
|
||||
openId: JSON.parse(_userInfo).openId
|
||||
},
|
||||
success: function(res) {
|
||||
let _json = res.data;
|
||||
if (_json.code == 0) {
|
||||
_ownerInfo = _json.data[0];
|
||||
if (_ownerInfo == null || _ownerInfo == undefined) {
|
||||
//没有业主信息
|
||||
reject();
|
||||
return;
|
||||
}
|
||||
if (_ownerInfo.state == '12000') {
|
||||
wx.setStorageSync(mapping.OWNER_INFO, _ownerInfo);
|
||||
let _currentCommunityInfo = {
|
||||
communityId: _ownerInfo.communityId,
|
||||
communityName: _ownerInfo.communityName
|
||||
};
|
||||
wx.setStorageSync(mapping.CURRENT_COMMUNITY_INFO,
|
||||
_currentCommunityInfo);
|
||||
}
|
||||
resolve(_json.data[0]);
|
||||
}
|
||||
},
|
||||
fail: function(error) {
|
||||
// 查询失败
|
||||
reject();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
return new Promise((resolve, reject) => {
|
||||
let _ownerInfo = uni.getStorageSync(mapping.OWNER_INFO);
|
||||
resolve(_ownerInfo);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
181
api/user/sessionApi.js
Normal file
181
api/user/sessionApi.js
Normal file
@ -0,0 +1,181 @@
|
||||
/**
|
||||
* 自登陆处理js
|
||||
*
|
||||
*/
|
||||
import {
|
||||
refreshUserOpenId,
|
||||
getWechatMiniOpenId,
|
||||
getCommunityWechatAppId,
|
||||
} from '../../api/user/userApi.js';
|
||||
|
||||
import {
|
||||
getCommunityId
|
||||
} from '../../api/community/communityApi.js';
|
||||
|
||||
import {
|
||||
saveOwnerStorage,
|
||||
saveUserLoginInfo,
|
||||
removeUserLoginInfo,
|
||||
getWAppId,
|
||||
saveWAppId,
|
||||
getLoginFlag
|
||||
} from '@/lib/java110/utils/StorageUtil.js';
|
||||
|
||||
import {
|
||||
isWxOrAli
|
||||
} from '../../lib/java110/utils/EnvUtil.js';
|
||||
|
||||
const LOGIN_FLAG = 'loginFlag'; //登录标识
|
||||
|
||||
/**
|
||||
* 是否 登录
|
||||
*/
|
||||
export function hasLogin() {
|
||||
let loginFlag = wx.getStorageSync(LOGIN_FLAG);
|
||||
let nowDate = new Date();
|
||||
if (loginFlag && loginFlag.expireTime > nowDate.getTime()) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* 自登陆
|
||||
* @param {Object} _objData
|
||||
*/
|
||||
export function autoLogin(options) {
|
||||
//todo 检查登录信息是否过期
|
||||
if (hasLogin()) {
|
||||
return;
|
||||
}
|
||||
//todo 如果是 h5 或者 微信小程序 ,检查是否做了配置,如果没有做配置不做自登陆
|
||||
// #ifdef H5 || MP-MP-WEIXIN
|
||||
autoLoginWechat(options);
|
||||
// #endif
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 主要完成 appId 查询
|
||||
* @param {Object} options
|
||||
*/
|
||||
export function autoLoginWechat(options) {
|
||||
let _openId = options.openId;
|
||||
if(_openId){ //h5 自登陆的情况
|
||||
loginByOpenId(_openId);
|
||||
return;
|
||||
}
|
||||
|
||||
let _objType = "1100"; // todo public
|
||||
// #ifdef MP-WEIXIN
|
||||
_objType = "1000";
|
||||
// #endif
|
||||
getCommunityWechatAppId({
|
||||
communityId: getCommunityId(),
|
||||
objType: _objType
|
||||
}).then(_data => {
|
||||
if (!_data.data || _data.data.indexOf('wx') < 0) {
|
||||
return;
|
||||
}
|
||||
_generatorOpenId(options, _data.data);
|
||||
})
|
||||
}
|
||||
|
||||
export function _generatorOpenId(options, appId) {
|
||||
// #ifdef H5
|
||||
//todo h5 情况
|
||||
_refreshWechatOpenId(options, appId);
|
||||
return;
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
_refreshWechatMiniOpenId(options, appId);
|
||||
// #endif
|
||||
}
|
||||
|
||||
export function _refreshWechatOpenId(options, appId) {
|
||||
//todo 不是微信环境 直接进入
|
||||
if (isWxOrAli() != 'WECHAT') {
|
||||
return;
|
||||
}
|
||||
let _redirectUrl = window.location.href;
|
||||
refreshUserOpenId({
|
||||
redirectUrl: _redirectUrl,
|
||||
wAppId: appId,
|
||||
}).then(_data => {
|
||||
if (_data.code == 0) {
|
||||
window.location.href = _data.data.openUrl;
|
||||
return;
|
||||
}
|
||||
});
|
||||
}
|
||||
export function _refreshWechatMiniOpenId() {
|
||||
let _that = this;
|
||||
wx.login({
|
||||
success: function(loginRes) {
|
||||
if (!loginRes.code) {
|
||||
return;
|
||||
}
|
||||
let accountInfo = uni.getAccountInfoSync();
|
||||
let appId = accountInfo.miniProgram.appId;
|
||||
getWechatMiniOpenId({
|
||||
code: loginRes.code,
|
||||
appId: appId,
|
||||
}).then(_data => {
|
||||
if (_data.code != 0) {
|
||||
uni.showToast({
|
||||
icon: 'none',
|
||||
title: _data.msg
|
||||
})
|
||||
return;
|
||||
}
|
||||
let openId = _data.data;
|
||||
loginByOpenId(openId);
|
||||
})
|
||||
},
|
||||
fail: function(error) {
|
||||
// 调用 wx.login 接口失败
|
||||
console.log('调用wx.login获取code失败');
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export function loginByOpenId(openId){
|
||||
requestNoAuth({
|
||||
url: url.ownerUserLoginByOpenId,
|
||||
method: "POST",
|
||||
data: {
|
||||
openId:openId
|
||||
},
|
||||
//动态数据
|
||||
success: function(res) {
|
||||
let _json = res.data;
|
||||
if (_json.code != 0) {
|
||||
return;
|
||||
}
|
||||
//todo 保存业主信息
|
||||
uni.setStorageSync("userInfo",_json.data);
|
||||
uni.setStorageSync("currentCommunityInfo",{
|
||||
communityId:_json.data.communityId,
|
||||
communityName:_json.data.communityName,
|
||||
});
|
||||
uni.setStorageSync("ownerInfo",{
|
||||
memberId:_json.data.memberId,
|
||||
ownerName:_json.data.ownerName,
|
||||
ownerId:_json.data.ownerId,
|
||||
ownerTel:_json.data.ownerTel,
|
||||
communityId:_json.data.communityId,
|
||||
link:_json.data.ownerTel
|
||||
});
|
||||
saveUserLoginInfo(_json.data.userId, _json.data.token, _json.data.key);
|
||||
},
|
||||
fail: function(e) {
|
||||
uni.hideLoading();
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
@ -284,13 +284,83 @@ export function getCommunityWechatAppId(_objData){
|
||||
})
|
||||
}
|
||||
|
||||
export function ownerLogin(_that, _data) {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
});
|
||||
return new Promise(
|
||||
(resolve, reject) => {
|
||||
requestNoAuth({
|
||||
url: url.ownerUserLogin,
|
||||
method: "POST",
|
||||
data: _data,
|
||||
//动态数据
|
||||
success: function(res) {
|
||||
uni.hideLoading();
|
||||
let _json = res.data;
|
||||
if (_json.code != 0) {
|
||||
reject(_json.msg);
|
||||
return;
|
||||
}
|
||||
//todo 保存业主信息
|
||||
uni.setStorageSync("userInfo",_json.data);
|
||||
uni.setStorageSync("currentCommunityInfo",{
|
||||
communityId:_json.data.communityId,
|
||||
communityName:_json.data.communityName,
|
||||
});
|
||||
uni.setStorageSync("ownerInfo",{
|
||||
memberId:_json.data.memberId,
|
||||
ownerName:_json.data.ownerName,
|
||||
ownerId:_json.data.ownerId,
|
||||
ownerTel:_json.data.ownerTel,
|
||||
communityId:_json.data.communityId,
|
||||
link:_json.data.ownerTel
|
||||
})
|
||||
resolve(_json.data);
|
||||
},
|
||||
fail: function(e) {
|
||||
uni.hideLoading();
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export function refreshAppUserBindingOwnerOpenId(_that, _data) {
|
||||
uni.showLoading({
|
||||
title: '加载中',
|
||||
mask: true
|
||||
});
|
||||
return new Promise(
|
||||
(resolve, reject) => {
|
||||
requestNoAuth({
|
||||
url: url.refreshAppUserBindingOwnerOpenId,
|
||||
method: "POST",
|
||||
data: _data,
|
||||
//动态数据
|
||||
success: function(res) {
|
||||
uni.hideLoading();
|
||||
let _json = res.data;
|
||||
if (_json.code != 0) {
|
||||
reject(_json.msg);
|
||||
return;
|
||||
}
|
||||
resolve(_json);
|
||||
},
|
||||
fail: function(e) {
|
||||
uni.hideLoading();
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
})
|
||||
}
|
||||
|
||||
export function getUserId(){
|
||||
let _userInfo = uni.getStorageSync("userInfo");
|
||||
console.log('_userInfo',_userInfo)
|
||||
|
||||
if(!_userInfo){
|
||||
return null;
|
||||
}
|
||||
|
||||
return JSON.parse(_userInfo).userId;
|
||||
return _userInfo.userId;
|
||||
}
|
||||
|
||||
@ -58,6 +58,10 @@
|
||||
import {
|
||||
getCouponUsers
|
||||
} from '../../api/fee/feeApi.js';
|
||||
|
||||
import {getCommunityId,getCommunityName} from '../../api/community/communityApi.js';
|
||||
|
||||
import {loadLoginOwner,getMemberId} from '../../api/owner/ownerApi.js';
|
||||
export default {
|
||||
name: "my-person",
|
||||
data() {
|
||||
@ -91,6 +95,7 @@
|
||||
_that.login = false;
|
||||
return;
|
||||
}
|
||||
_that.communityName = getCommunityName();
|
||||
_that.login = true;
|
||||
_that.loadOwenrInfo();
|
||||
_that.userInfo = context.getUserInfo();
|
||||
@ -104,7 +109,6 @@
|
||||
loadOwenrInfo: function() {
|
||||
let _that = this;
|
||||
context.getOwner(function(_ownerInfo) {
|
||||
console.log('_ownerInfo', _ownerInfo);
|
||||
if (_ownerInfo) {
|
||||
_that.ownerFlag = true;
|
||||
} else {
|
||||
@ -117,17 +121,20 @@
|
||||
*/
|
||||
loadOwnerHeaderImg: function() {
|
||||
let _that = this;
|
||||
context.getOwner(function(_owner) {
|
||||
if(_owner.headImgUrl){
|
||||
_that.headerImg = _owner.headImgUrl;
|
||||
|
||||
loadLoginOwner({
|
||||
memberId:getMemberId(),
|
||||
communityId:getCommunityId()
|
||||
}).then(_data=>{
|
||||
//console.log(_data);
|
||||
if(_data.url){
|
||||
_that.headerImg = _data.url;
|
||||
}else{
|
||||
_that.headerImg =conf.imgUrl+'/h5/images/serve/head.png';
|
||||
}
|
||||
_that.userName = _owner.appUserName;
|
||||
_that.userPhone = _owner.link;
|
||||
_that.communityName = _owner.communityName;
|
||||
|
||||
});
|
||||
_that.userName = _data.name;
|
||||
_that.userPhone = _data.link;
|
||||
})
|
||||
},
|
||||
// 余额
|
||||
loadOwnerAccount: function() {
|
||||
|
||||
@ -20,8 +20,6 @@ class MappingConstant {
|
||||
|
||||
|
||||
static OWNER_INFO = "ownerInfo"; // 当前业主信息
|
||||
|
||||
static CURRENT_COMMUNITY_INFO = "currentCommunityInfo"; //业主当前小区信息
|
||||
|
||||
static CURRENT_OPEN_ID = "openId";
|
||||
|
||||
|
||||
@ -217,6 +217,10 @@ export default {
|
||||
getWechatMiniOpenId: baseUrl + "app/wechat.getWechatMiniOpenId",
|
||||
getCommunityWechatAppId: baseUrl + "app/wechat.getCommunityWechatAppId",
|
||||
cashier: baseUrl + "app/payment.cashier",
|
||||
ownerUserLogin: baseUrl+"app/user.ownerUserLogin",
|
||||
refreshAppUserBindingOwnerOpenId: baseUrl+"app/owner.refreshAppUserBindingOwnerOpenId",
|
||||
ownerUserLoginByOpenId: baseUrl+"app/user.ownerUserLoginByOpenId",
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -37,7 +37,6 @@ import {
|
||||
|
||||
|
||||
export function navigateH5(_url) {
|
||||
|
||||
if (_url.indexOf("http") < 0 && _url.indexOf("https") < 0) {
|
||||
_url = conf.mallUrl + '#' + _url;
|
||||
}
|
||||
@ -111,11 +110,12 @@ export function navigateTo(_param, callback = () => {}) {
|
||||
return;
|
||||
}
|
||||
debug('vcRoute', 'navigateTo', _param);
|
||||
uni.navigateTo(_param);
|
||||
//校验是否登录,如果没有登录跳转至温馨提示页面
|
||||
checkSession(_param.url, function() {
|
||||
//有回话 跳转至相应页面
|
||||
uni.navigateTo(_param);
|
||||
})
|
||||
// checkSession(_param.url, function() {
|
||||
// //有回话 跳转至相应页面
|
||||
// uni.navigateTo(_param);
|
||||
// })
|
||||
};
|
||||
|
||||
/*
|
||||
|
||||
@ -10,7 +10,9 @@ import mapping from '../../constant/MappingConstant.js'
|
||||
|
||||
import {checkSession} from './page/Page.js'
|
||||
|
||||
import {getToken} from './utils/StorageUtil.js'
|
||||
import {getToken} from './utils/StorageUtil.js';
|
||||
|
||||
import {hasLogin} from '../../api/user/sessionApi.js';
|
||||
|
||||
|
||||
import {debug,warn,info,error} from './utils/LogUtil.js'
|
||||
@ -20,15 +22,20 @@ import {debug,warn,info,error} from './utils/LogUtil.js'
|
||||
**/
|
||||
export function getHeaders() {
|
||||
let _wAppId = uni.getStorageSync(mapping.W_APP_ID);
|
||||
let _token = getToken();
|
||||
if(!_token){
|
||||
_token = "no login";
|
||||
}
|
||||
return {
|
||||
"app-id": app.appId,
|
||||
"transaction-id": coreUtil.wxuuid(),
|
||||
"req-time": getDateYYYYMMDDHHMISS(),
|
||||
"sign": '1234567',
|
||||
"user-id": '-1',
|
||||
"cookie": '_java110_token_=' + getToken(),
|
||||
//"cookie": '_java110_token_=' + getToken(),
|
||||
"Accept": '*/*',
|
||||
"w-app-id": _wAppId
|
||||
"w-app-id": _wAppId,
|
||||
"Authorization":"Bearer "+_token
|
||||
};
|
||||
}
|
||||
/**
|
||||
@ -66,13 +73,17 @@ export function request(_reqObj) {
|
||||
uni.request(_reqObj);
|
||||
return;
|
||||
}
|
||||
//校验是否登录
|
||||
checkSession(null,function() {
|
||||
//有回话 跳转至相应页面
|
||||
//重写token
|
||||
_reqObj.header.cookie = '_java110_token_=' + wx.getStorageSync('token');
|
||||
uni.request(_reqObj);
|
||||
})
|
||||
|
||||
if(!hasLogin()){
|
||||
//todo 这里延迟跳转,等待如果界面又自登陆的话 自登陆完成
|
||||
setTimeout(function(){
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/showlogin'
|
||||
})
|
||||
},1500);
|
||||
return;
|
||||
}
|
||||
uni.request(_reqObj);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -101,6 +112,6 @@ export function requestNoAuth(_reqObj) {
|
||||
} else {
|
||||
_reqObj.header = _headers;
|
||||
}
|
||||
_reqObj.header.cookie = '_java110_token_=' + wx.getStorageSync('token');
|
||||
|
||||
uni.request(_reqObj);
|
||||
}
|
||||
|
||||
@ -41,28 +41,29 @@ import url from '../../../constant/url.js'
|
||||
* @param {Object} options 页面参数
|
||||
*/
|
||||
export function onLoad(options) {
|
||||
pageOnLoad(options);
|
||||
let pages = getCurrentPages() // 获取栈实例
|
||||
let currentRoute = pages[pages.length - 1].route;
|
||||
let _key = options.key;
|
||||
if (isNotNull(_key)) {
|
||||
//根据key 去做登录
|
||||
return ;
|
||||
}
|
||||
//pageOnLoad(options);
|
||||
// let pages = getCurrentPages() // 获取栈实例
|
||||
// let currentRoute = pages[pages.length - 1].route;
|
||||
// let _key = options.key;
|
||||
// if (isNotNull(_key)) {
|
||||
// //根据key 去做登录
|
||||
// return;
|
||||
// }
|
||||
//白名单直接跳过检查登录
|
||||
// if (!url.NEED_NOT_LOGIN_PAGE.includes(currentRoute)) {
|
||||
// console.log('NEED_NOT_LOGIN_PAGE')
|
||||
// checkSession(null,function() {
|
||||
// })
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查会话是否 存在
|
||||
* add by 吴学文 QQ:928255095
|
||||
*/
|
||||
export function checkSession(_pageUrl,_call) {
|
||||
pageCheckSession(_pageUrl,_call)
|
||||
export function checkSession(_pageUrl, _call) {
|
||||
pageCheckSession(_pageUrl, _call)
|
||||
}
|
||||
/**
|
||||
* 是否登录 不跳转 只是判断是否登录
|
||||
@ -90,6 +91,6 @@ export function userLogin(_obj) {
|
||||
* 登录页面 查询code
|
||||
* @param {Object} options 页面数据
|
||||
*/
|
||||
export function getLoginCode(options){
|
||||
export function getLoginCode(options) {
|
||||
return getPageLoginCode(options)
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ export function pageOnLoad(options) {
|
||||
});
|
||||
}
|
||||
|
||||
getPageWAppId(options);
|
||||
//getPageWAppId(options);
|
||||
|
||||
if (isNull(_key)) {
|
||||
onLoadHasAuth();
|
||||
@ -199,7 +199,7 @@ export function pageUserLogin(_obj) {
|
||||
let _ownerInfo = _data.owner;
|
||||
saveOwnerStorage(_ownerInfo);
|
||||
saveUserLoginInfo(_ownerInfo.userId, _data.token, _data.key)
|
||||
resolve();
|
||||
resolve(_ownerInfo);
|
||||
},
|
||||
fail: function(e) {
|
||||
uni.hideLoading();
|
||||
|
||||
@ -73,6 +73,12 @@ export function saveUserLoginInfo(_userId,_token,_key){
|
||||
}
|
||||
}
|
||||
|
||||
export function removeUserLoginInfo(){
|
||||
wx.removeStorageSync(LOGIN_FLAG);
|
||||
wx.removeStorageSync(TOKEN);
|
||||
wx.removeStorageSync(OWNER_KEY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取用户信息
|
||||
*
|
||||
@ -80,7 +86,7 @@ export function saveUserLoginInfo(_userId,_token,_key){
|
||||
*/
|
||||
export function getUserInfo() {
|
||||
let _userInfo = wx.getStorageSync(USER_INFO);
|
||||
return JSON.parse(_userInfo);
|
||||
return _userInfo;
|
||||
};
|
||||
|
||||
export function getToken(){
|
||||
|
||||
@ -943,6 +943,15 @@
|
||||
}
|
||||
|
||||
}
|
||||
,{
|
||||
"path" : "pages/login/loginInitWechat",
|
||||
"style" :
|
||||
{
|
||||
"navigationBarTitleText": "微信登录中",
|
||||
"enablePullDownRefresh": false
|
||||
}
|
||||
|
||||
}
|
||||
],
|
||||
"tabBar": {
|
||||
"color": "#272636",
|
||||
|
||||
@ -92,7 +92,8 @@
|
||||
|
||||
import {
|
||||
getRoomFees
|
||||
} from '../../api/fee/feeApi.js'
|
||||
} from '../../api/fee/feeApi.js';
|
||||
import {autoLogin} from '../../api/user/sessionApi.js';
|
||||
|
||||
|
||||
export default {
|
||||
@ -118,6 +119,7 @@
|
||||
onLoad: function(options) {
|
||||
|
||||
context.onLoad(options);
|
||||
autoLogin(options);
|
||||
},
|
||||
onShow() {
|
||||
let _that = this;
|
||||
|
||||
@ -56,7 +56,8 @@
|
||||
//const util = context.util;
|
||||
|
||||
import {formatDate} from '../../lib/java110/utils/DateUtil.js'
|
||||
import noDataPage from '@/components/no-data-page/no-data-page.vue'
|
||||
import noDataPage from '@/components/no-data-page/no-data-page.vue';
|
||||
import {autoLogin} from '../../api/user/sessionApi.js';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@ -78,6 +79,7 @@
|
||||
*/
|
||||
onLoad: function(options) {
|
||||
context.onLoad(options);
|
||||
autoLogin(options);
|
||||
this.appId = options.wAppId;
|
||||
},
|
||||
/**
|
||||
|
||||
@ -47,8 +47,8 @@
|
||||
|
||||
import {
|
||||
getRoomFees
|
||||
} from '../../api/fee/feeApi.js'
|
||||
|
||||
} from '../../api/fee/feeApi.js';
|
||||
import {autoLogin} from '../../api/user/sessionApi.js';
|
||||
|
||||
export default {
|
||||
data() {
|
||||
@ -70,6 +70,7 @@
|
||||
*/
|
||||
onLoad: function(options) {
|
||||
context.onLoad(options);
|
||||
autoLogin(options);
|
||||
},
|
||||
/**
|
||||
* 生命周期函数--监听页面显示
|
||||
|
||||
@ -41,7 +41,8 @@
|
||||
hasOwner
|
||||
} from '../../api/owner/ownerApi.js';
|
||||
|
||||
import conf from '@/conf/config.js'
|
||||
import conf from '@/conf/config.js';
|
||||
import {autoLogin} from '../../api/user/sessionApi.js';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
@ -74,13 +75,10 @@
|
||||
title:conf.systemName
|
||||
})
|
||||
this.vc.onLoad(options);
|
||||
autoLogin(options);
|
||||
//查询目录
|
||||
},
|
||||
|
||||
/**
|
||||
* 生命周期函数--监听页面初次渲染完成
|
||||
*/
|
||||
onReady: function() {},
|
||||
onShareAppMessage: function() {
|
||||
return {
|
||||
title: '首页',
|
||||
|
||||
@ -43,14 +43,24 @@
|
||||
import wInput from '../../components/watch-input.vue' //input
|
||||
import wButton from '../../components/watch-button.vue' //button
|
||||
import {
|
||||
sendSmsCode
|
||||
sendSmsCode,
|
||||
ownerLogin,
|
||||
} from '../../api/user/userApi.js'
|
||||
import context from '../../lib/java110/Java110Context.js';
|
||||
|
||||
import {
|
||||
userLogin,
|
||||
|
||||
getLoginCode
|
||||
} from '../../lib/java110/page/Page.js'
|
||||
} from '../../lib/java110/page/Page.js';
|
||||
|
||||
import {
|
||||
saveOwnerStorage,
|
||||
saveUserLoginInfo,
|
||||
removeUserLoginInfo,
|
||||
getWAppId,
|
||||
saveWAppId,
|
||||
getLoginFlag
|
||||
} from '@/lib/java110/utils/StorageUtil.js'
|
||||
|
||||
const constant = context.constant;
|
||||
const factory = context.factory;
|
||||
@ -60,9 +70,8 @@
|
||||
data() {
|
||||
return {
|
||||
logoUrl: '',
|
||||
username: '',
|
||||
password: '',
|
||||
appId: "",
|
||||
username: '18909752222',
|
||||
password: '381309',
|
||||
code: "",
|
||||
loginByPhone: false,
|
||||
msgCode: '',
|
||||
@ -74,11 +83,12 @@
|
||||
},
|
||||
onLoad(option) {
|
||||
let that = this;
|
||||
getLoginCode(option)
|
||||
.then((_code) => {
|
||||
that.code = _code
|
||||
});
|
||||
this.logoUrl = constant.url.baseUrl + 'logo.png';
|
||||
//todo 清除缓存内容,以防 业主后退,然后还显示他的东西
|
||||
uni.removeStorageSync("JAVA110_USER_INFO");
|
||||
uni.removeStorageSync("currentCommunityInfo");
|
||||
uni.removeStorageSync("ownerInfo");
|
||||
removeUserLoginInfo();
|
||||
},
|
||||
methods: {
|
||||
_doLogin: function() {
|
||||
@ -104,19 +114,23 @@
|
||||
appId: this.vc.getWAppId(),
|
||||
loginByPhone: this.loginByPhone
|
||||
};
|
||||
userLogin(_obj)
|
||||
.then(() => {
|
||||
wx.switchTab({
|
||||
url: "/pages/index/index?wAppId=" + _that.vc.getWAppId()
|
||||
});
|
||||
ownerLogin(this,_obj)
|
||||
.then((_user) => {
|
||||
//todo 保存登录信息
|
||||
saveUserLoginInfo(_user.userId, _user.token, _user.key);
|
||||
uni.navigateTo({
|
||||
url:'/pages/login/loginInitWechat?communityId='+_user.communityId+"&appUserId="+_user.appUserId
|
||||
})
|
||||
},err=>{
|
||||
uni.showToast({
|
||||
icon:'none',
|
||||
title:err
|
||||
})
|
||||
});
|
||||
},
|
||||
_doRegister: function() {
|
||||
//let _url = '/pages/login/registerByWechat';
|
||||
let _url = '/pages/login/register';
|
||||
// #ifdef H5
|
||||
_url += ('?code=' + this.code);
|
||||
// #endif
|
||||
this.vc.navigateTo({
|
||||
url: _url
|
||||
})
|
||||
|
||||
151
pages/login/loginInitWechat.vue
Normal file
151
pages/login/loginInitWechat.vue
Normal file
@ -0,0 +1,151 @@
|
||||
<template>
|
||||
<view>
|
||||
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import {
|
||||
isNotNull
|
||||
} from '../../lib/java110/utils/StringUtil.js';
|
||||
import {
|
||||
refreshUserOpenId,
|
||||
getOpenIdFromAliPay,
|
||||
getWechatMiniOpenId,
|
||||
getCommunityWechatAppId,
|
||||
refreshAppUserBindingOwnerOpenId
|
||||
} from '../../api/user/userApi.js';
|
||||
import {
|
||||
isWxOrAli
|
||||
} from '../../lib/java110/utils/EnvUtil.js';
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
communityId:'',
|
||||
appId:'',
|
||||
appUserId:'',
|
||||
openId:'',
|
||||
appUserId:'',
|
||||
}
|
||||
},
|
||||
onLoad(options) {
|
||||
this.communityId = options.communityId;
|
||||
this.openId = options.openId;
|
||||
this.appUserId = options.appUserId;
|
||||
let _that = this;
|
||||
if(this.openId){
|
||||
this.saveOpenIdToOwner();
|
||||
return;
|
||||
}
|
||||
this._loadAppId(function(){
|
||||
if(!_that.appId || _that.appId.indexOf('wx') < 0){
|
||||
wx.switchTab({
|
||||
url: "/pages/index/index"
|
||||
});
|
||||
}
|
||||
//todo 查询openId
|
||||
_that._generatorOpenId();
|
||||
});
|
||||
|
||||
},
|
||||
methods: {
|
||||
_loadAppId:function(_call){
|
||||
let _objType = "1100"; // todo public
|
||||
// #ifdef MP-WEIXIN
|
||||
_objType = "1000";
|
||||
// #endif
|
||||
let _that = this;
|
||||
getCommunityWechatAppId({
|
||||
communityId:this.communityId,
|
||||
objType:_objType
|
||||
}).then(_data =>{
|
||||
_that.appId = _data.data;
|
||||
_call();
|
||||
})
|
||||
},
|
||||
_generatorOpenId:function(){
|
||||
// #ifdef H5
|
||||
//todo h5 情况
|
||||
this._refreshWechatOpenId();
|
||||
return;
|
||||
// #endif
|
||||
|
||||
// #ifdef MP-WEIXIN
|
||||
this._refreshWechatMiniOpenId();
|
||||
// #endif
|
||||
},
|
||||
_refreshWechatOpenId: function() {
|
||||
//todo 不是微信环境 直接进入
|
||||
if(isWxOrAli() != 'WECHAT'){
|
||||
wx.switchTab({
|
||||
url: "/pages/index/index"
|
||||
});
|
||||
return ;
|
||||
}
|
||||
let _redirectUrl = window.location.href;
|
||||
refreshUserOpenId({
|
||||
redirectUrl: _redirectUrl,
|
||||
wAppId: this.appId,
|
||||
}).then(_data => {
|
||||
console.log(_data, 123)
|
||||
if (_data.code == 0) {
|
||||
window.location.href = _data.data.openUrl;
|
||||
return;
|
||||
}
|
||||
});
|
||||
},
|
||||
_refreshWechatMiniOpenId:function(){
|
||||
let _that =this;
|
||||
wx.login({
|
||||
success: function(loginRes) {
|
||||
if (!loginRes.code) {
|
||||
return;
|
||||
}
|
||||
let accountInfo = uni.getAccountInfoSync();
|
||||
let appId = accountInfo.miniProgram.appId;
|
||||
getWechatMiniOpenId({
|
||||
code:loginRes.code,
|
||||
appId:appId,
|
||||
}).then(_data =>{
|
||||
if(_data.code != 0){
|
||||
uni.showToast({
|
||||
icon:'none',
|
||||
title:_data.msg
|
||||
})
|
||||
return;
|
||||
}
|
||||
_that.openId = _data.data;
|
||||
_that.saveOpenIdToOwner();
|
||||
})
|
||||
|
||||
},
|
||||
fail: function(error) {
|
||||
// 调用 wx.login 接口失败
|
||||
console.log('调用wx.login获取code失败');
|
||||
console.log(error);
|
||||
}
|
||||
});
|
||||
},
|
||||
saveOpenIdToOwner:function(){
|
||||
refreshAppUserBindingOwnerOpenId(this,{
|
||||
appUserId:this.appUserId,
|
||||
openId:this.openId,
|
||||
communityId:this.communityId
|
||||
}).then(_data=>{
|
||||
wx.switchTab({
|
||||
url: "/pages/index/index"
|
||||
});
|
||||
},err=>{
|
||||
uni.showToast({
|
||||
icon:'none',
|
||||
title:err
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<style>
|
||||
|
||||
</style>
|
||||
@ -61,7 +61,14 @@
|
||||
},
|
||||
_doChangeCommunity: function(_community) {
|
||||
uni.setStorageSync(mapping.CURRENT_COMMUNITY_INFO, _community);
|
||||
wx.setStorageSync(mapping.OWNER_INFO, _community);
|
||||
uni.setStorageSync("ownerInfo",{
|
||||
memberId:_community.memberId,
|
||||
ownerName:_community.name,
|
||||
ownerId:_community.ownerId,
|
||||
ownerTel:_community.link,
|
||||
communityId:_community.communityId,
|
||||
link:_community.link
|
||||
})
|
||||
uni.navigateBack({
|
||||
delta: 1
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user