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

pull/32/MERGE
YunaiV 2023-12-23 19:52:56 +08:00
parent 789cbe8461
commit f968397ad8
4 changed files with 14 additions and 66 deletions

View File

@ -9,27 +9,27 @@
@onConfirm="onConfirm"
/>
<!-- 2.短信登录 smsLogin -->
<!-- 2. 短信登录 smsLogin -->
<sms-login v-if="authType === 'smsLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
<!-- 4.忘记密码 resetPassword-->
<!-- 3. 忘记密码 resetPassword-->
<reset-password v-if="authType === 'resetPassword'" />
<!-- 5.绑定手机号 changeMobile -->
<!-- 4. 绑定手机号 changeMobile -->
<change-mobile v-if="authType === 'changeMobile'" />
<!-- 6.修改密码 changePassword-->
<!-- 5. 修改密码 changePassword-->
<changePassword v-if="authType === 'changePassword'" />
<!-- 8.微信小程序授权 changeUsername-->
<!-- 6. 微信小程序授权 -->
<mp-authorization v-if="authType === 'mpAuthorization'" />
<!-- 第三方登录+注册 -->
<!-- 7. 第三方登录 -->
<view
v-if="['accountLogin', 'smsLogin'].includes(authType)"
class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center"
>
<!-- 立即注册&快捷登录 TextButton -->
<!-- 7.1 微信小程序的快捷登录 -->
<view v-if="sheep.$platform.name === 'WechatMiniProgram'" class="ss-flex register-box">
<view class="register-title">还没有账号?</view>
<button class="ss-reset-button login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
@ -38,7 +38,7 @@
<view class="circle" />
</view>
<!-- 微信的公众号App小程序的登录基于 openid + code -->
<!-- 7.2 微信的公众号App小程序的登录基于 openid + code -->
<button
v-if="
['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) &&
@ -53,7 +53,7 @@
/>
</button>
<!-- iOS 登录 -->
<!-- 7.3 iOS 登录 TODO 芋艿等后面搞 App 再弄 -->
<button
v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'"
@tap="thirdLogin('apple')"
@ -66,6 +66,7 @@
</button>
</view>
<!-- 用户协议的勾选 -->
<view
v-if="['accountLogin', 'smsLogin'].includes(authType)"
class="agreement-box ss-flex ss-row-center"
@ -124,7 +125,7 @@
const currentProtocol = ref(false);
// TODO
//
function onChange() {
state.protocol = !state.protocol;
}

View File

@ -1,4 +1,5 @@
import third from '@/sheep/api/third';
// TODO 芋艿:等后面搞 App 再弄
const login = () => {
return new Promise(async (resolve, reject) => {

View File

@ -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')) {

View File

@ -1,6 +1,8 @@
// 登录
import third from '@/sheep/api/third';
// TODO 芋艿:等后面搞 App 再弄
const load = async () => {};
// 微信开放平台移动应用授权登陆