登录:清理 auto_login 逻辑,标记 App 等未来在搞

This commit is contained in:
YunaiV
2023-12-23 19:52:56 +08:00
parent 789cbe8461
commit f968397ad8
4 changed files with 14 additions and 66 deletions
+1
View File
@@ -1,4 +1,5 @@
import third from '@/sheep/api/third';
// TODO 芋艿:等后面搞 App 再弄
const login = () => {
return new Promise(async (resolve, reject) => {
@@ -4,18 +4,11 @@ import AuthUtil from '@/sheep/api/member/auth';
const socialType = 34; // 社交类型 - 微信小程序
let sessionId = uni.getStorageSync('sessionId');
let subscribeEventList = [];
// 加载微信小程序
function load() {
checkUpdate();
// const sessionStatus = await checkSession();
// 小程序的接口改动太频繁了 强制每次进入都重新获取
const sessionStatus = false;
if (!sessionStatus) {
getSessionId();
}
getSubscribeTemplate();
}
@@ -97,55 +90,6 @@ const unbind = async () => {
return !error;
};
// 获取最新sessionId
const getSessionId = async (auto_login = null) => {
// 获取code
let codeStr = '';
const loginResult = await uni.login();
if (loginResult.errMsg === 'login:ok') {
codeStr = loginResult.code;
} else {
getSessionId(auto_login);
return false;
}
if(auto_login === null) {
auto_login = !!($store('app').platform.auto_login && !$store('user').isLogin);
}
const { error, data } = await third.wechat.getSessionId({
platform: 'miniProgram',
payload: encodeURIComponent(
JSON.stringify({
code: codeStr,
auto_login,
}),
),
});
if (error === 0) {
uni.setStorageSync('sessionId', data.session_id);
return true;
}
return false;
};
// 检查sessionId是否可用
const checkSession = () => {
return new Promise((resolve, reject) => {
if (!sessionId) {
return resolve(false);
}
uni.checkSession({
success() {
return resolve(true);
},
fail() {
uni.removeStorageSync('sessionId');
return resolve(false);
},
});
});
};
// 小程序更新
const checkUpdate = async (silence = true) => {
if (uni.canIUse('getUpdateManager')) {
@@ -1,6 +1,8 @@
// 登录
import third from '@/sheep/api/third';
// TODO 芋艿:等后面搞 App 再弄
const load = async () => {};
// 微信开放平台移动应用授权登陆