✨ 登录:清理 auto_login 逻辑,标记 App 等未来在搞
parent
789cbe8461
commit
f968397ad8
|
@ -9,27 +9,27 @@
|
||||||
@onConfirm="onConfirm"
|
@onConfirm="onConfirm"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- 2.短信登录 smsLogin -->
|
<!-- 2. 短信登录 smsLogin -->
|
||||||
<sms-login v-if="authType === 'smsLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
|
<sms-login v-if="authType === 'smsLogin'" :agreeStatus="state.protocol" @onConfirm="onConfirm" />
|
||||||
|
|
||||||
<!-- 4.忘记密码 resetPassword-->
|
<!-- 3. 忘记密码 resetPassword-->
|
||||||
<reset-password v-if="authType === 'resetPassword'" />
|
<reset-password v-if="authType === 'resetPassword'" />
|
||||||
|
|
||||||
<!-- 5.绑定手机号 changeMobile -->
|
<!-- 4. 绑定手机号 changeMobile -->
|
||||||
<change-mobile v-if="authType === 'changeMobile'" />
|
<change-mobile v-if="authType === 'changeMobile'" />
|
||||||
|
|
||||||
<!-- 6.修改密码 changePassword-->
|
<!-- 5. 修改密码 changePassword-->
|
||||||
<changePassword v-if="authType === 'changePassword'" />
|
<changePassword v-if="authType === 'changePassword'" />
|
||||||
|
|
||||||
<!-- 8.微信小程序授权 changeUsername-->
|
<!-- 6. 微信小程序授权 -->
|
||||||
<mp-authorization v-if="authType === 'mpAuthorization'" />
|
<mp-authorization v-if="authType === 'mpAuthorization'" />
|
||||||
|
|
||||||
<!-- 第三方登录+注册 -->
|
<!-- 7. 第三方登录 -->
|
||||||
<view
|
<view
|
||||||
v-if="['accountLogin', 'smsLogin'].includes(authType)"
|
v-if="['accountLogin', 'smsLogin'].includes(authType)"
|
||||||
class="auto-login-box ss-flex ss-flex-col ss-row-center ss-col-center"
|
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 v-if="sheep.$platform.name === 'WechatMiniProgram'" class="ss-flex register-box">
|
||||||
<view class="register-title">还没有账号?</view>
|
<view class="register-title">还没有账号?</view>
|
||||||
<button class="ss-reset-button login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
|
<button class="ss-reset-button login-btn" open-type="getPhoneNumber" @getphonenumber="getPhoneNumber">
|
||||||
|
@ -38,7 +38,7 @@
|
||||||
<view class="circle" />
|
<view class="circle" />
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 微信的公众号、App、小程序的登录,基于 openid + code -->
|
<!-- 7.2 微信的公众号、App、小程序的登录,基于 openid + code -->
|
||||||
<button
|
<button
|
||||||
v-if="
|
v-if="
|
||||||
['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) &&
|
['WechatOfficialAccount', 'WechatMiniProgram', 'App'].includes(sheep.$platform.name) &&
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
/>
|
/>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<!-- iOS 登录 -->
|
<!-- 7.3 iOS 登录 TODO 芋艿:等后面搞 App 再弄 -->
|
||||||
<button
|
<button
|
||||||
v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'"
|
v-if="sheep.$platform.os === 'ios' && sheep.$platform.name === 'App'"
|
||||||
@tap="thirdLogin('apple')"
|
@tap="thirdLogin('apple')"
|
||||||
|
@ -66,6 +66,7 @@
|
||||||
</button>
|
</button>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
|
<!-- 用户协议的勾选 -->
|
||||||
<view
|
<view
|
||||||
v-if="['accountLogin', 'smsLogin'].includes(authType)"
|
v-if="['accountLogin', 'smsLogin'].includes(authType)"
|
||||||
class="agreement-box ss-flex ss-row-center"
|
class="agreement-box ss-flex ss-row-center"
|
||||||
|
@ -124,7 +125,7 @@
|
||||||
|
|
||||||
const currentProtocol = ref(false);
|
const currentProtocol = ref(false);
|
||||||
|
|
||||||
// 勾选协议 TODO 芋艿:协议
|
// 勾选协议
|
||||||
function onChange() {
|
function onChange() {
|
||||||
state.protocol = !state.protocol;
|
state.protocol = !state.protocol;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import third from '@/sheep/api/third';
|
import third from '@/sheep/api/third';
|
||||||
|
// TODO 芋艿:等后面搞 App 再弄
|
||||||
|
|
||||||
const login = () => {
|
const login = () => {
|
||||||
return new Promise(async (resolve, reject) => {
|
return new Promise(async (resolve, reject) => {
|
||||||
|
|
|
@ -4,18 +4,11 @@ import AuthUtil from '@/sheep/api/member/auth';
|
||||||
|
|
||||||
const socialType = 34; // 社交类型 - 微信小程序
|
const socialType = 34; // 社交类型 - 微信小程序
|
||||||
|
|
||||||
let sessionId = uni.getStorageSync('sessionId');
|
|
||||||
let subscribeEventList = [];
|
let subscribeEventList = [];
|
||||||
|
|
||||||
// 加载微信小程序
|
// 加载微信小程序
|
||||||
function load() {
|
function load() {
|
||||||
checkUpdate();
|
checkUpdate();
|
||||||
// const sessionStatus = await checkSession();
|
|
||||||
// 小程序的接口改动太频繁了 强制每次进入都重新获取
|
|
||||||
const sessionStatus = false;
|
|
||||||
if (!sessionStatus) {
|
|
||||||
getSessionId();
|
|
||||||
}
|
|
||||||
getSubscribeTemplate();
|
getSubscribeTemplate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,55 +90,6 @@ const unbind = async () => {
|
||||||
return !error;
|
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) => {
|
const checkUpdate = async (silence = true) => {
|
||||||
if (uni.canIUse('getUpdateManager')) {
|
if (uni.canIUse('getUpdateManager')) {
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
// 登录
|
// 登录
|
||||||
import third from '@/sheep/api/third';
|
import third from '@/sheep/api/third';
|
||||||
|
|
||||||
|
// TODO 芋艿:等后面搞 App 再弄
|
||||||
|
|
||||||
const load = async () => {};
|
const load = async () => {};
|
||||||
|
|
||||||
// 微信开放平台移动应用授权登陆
|
// 微信开放平台移动应用授权登陆
|
||||||
|
|
Loading…
Reference in New Issue