Authored by QC-L

修改登录相关逻辑 review by 黄敬囿

... ... @@ -62,6 +62,7 @@ class App extends Component {
'pages/orderList/orderlistcell',
'pages/orderDetail/logistics/logistics',
'pages/webview/webview',
'pages/select-country/select-country',
/**零元购*/
// "pages/bindPhoneNumber/bindPhoneNumber",
"pages/zeroSell/index",
... ... @@ -128,7 +129,7 @@ class App extends Component {
setSessionkey();
app_report('start', 'LIFECYCLE', 'START', {}, this);
let userInfo = Taro.getStorageSync('userInfo');
if (userInfo && userInfo.uid && userInfo.session_key) {
if (userInfo && userInfo.uid) {
checkUidAndSessionKey(userInfo.uid, userInfo.session_key).then(result => {
if (result.statusCode === 200) {
console.log('session_key 未过期');
... ...
... ... @@ -61,7 +61,6 @@ export const decodeUnionId = (srd_session, result) => {
// 存储 userInfo
if (res && res.userInfo) {
setStorageWithValueForKey('userInfo', res.userInfo);
setStorageWithValueForKey('myUserInfo', res.userInfo);
} else {
return;
}
... ... @@ -193,7 +192,7 @@ const getStorageWithValueForKey = (key) => {
})
}
const getGlobalData = () => {
export const getGlobalData = () => {
const app = getApp();
let globalData;
if (app && app.globalData) {
... ... @@ -411,4 +410,8 @@ export const getLoginButtonType = () => {
const getStorageUserInfo = () => {
const userInfo = wx.getStorageSync('userInfo');
return userInfo;
}
export const getCountryArea = () => {
return login.getCountryArea();
}
\ No newline at end of file
... ...
... ... @@ -7,7 +7,8 @@ const WECHAT_ADDUNIONUPDUSER = 'app.wechat.addUnionUpdUser';
const WECHAT_PASSPORT_SIGNINBYOPENID = 'app.passport.signinByOpenID';
const WECHAT_PASSPORT_MINIAPPBINDBYAUTO = 'app.passport.miniAppBindByAuto';
const WECHAT_ADDUPDUSER = 'app.wechat.addUpdUser';
const WECHAT_PASSPORT_VERIFY = 'app.passport.verify'
const WECHAT_PASSPORT_VERIFY = 'app.passport.verify';
const PHONE_PASSPORT_GET_AREA = 'app.passport.getArea';
const WechatPath = '/wechat/';
... ... @@ -102,4 +103,10 @@ export class LoginService extends BaseService {
area: areaCode
})
}
async getCountryArea() {
return await this.GET({
method: PHONE_PASSPORT_GET_AREA
});
}
}
\ No newline at end of file
... ...
... ... @@ -8,7 +8,8 @@ import * as globalData from '../../actions/globalData';
import config from '../../config';
import './index.scss';
import event from '../../utils/event.js'
import { getUserInfo, getPhoneNumber, checkUnionIdIsBind } from '../../libs/login/login.js'
import { getUserInfo, getPhoneNumber, checkUnionIdIsBind, getGlobalData } from '../../libs/login/login.js'
import router from '../../router/index.js';
const USER_GET_PHONENUMBER_ERROR = 'user-get-phonenumber-error';
const USER_LOGIN_CALLBACK = 'user-login-callback';
... ... @@ -60,6 +61,21 @@ export default class Login extends Component {
this.eventOnAll();
}
componentDidShow() {
const globalData = getGlobalData();
let country = globalData.country;
if (country) {
this.setState({
countryArea: country.area || '86'
})
}
}
componentWillUnmount() {
const globalData = getGlobalData();
globalData.country = null;
}
addPrefix(prefix, eventName) {
return `${prefix}-${eventName}`;
}
... ... @@ -116,7 +132,7 @@ export default class Login extends Component {
}
chooseCountry() {
router.go('selectCountry');
}
phoneInputChanged(e) {
... ...
// login/select-country/select-country.js
import { getCountryArea, getGlobalData } from '../../libs/login/login.js';
Page({
/**
* 页面的初始数据
*/
data: {
country: []
},
/**
* 生命周期函数--监听页面加载
*/
onLoad: function (options) {
this.getCountryArea();
},
async getCountryArea() {
try {
let country = await getCountryArea();
this.setData({
country
})
} catch (error) {
}
},
selectCountry(e) {
let country = e.currentTarget.dataset.country;
let globalData = getGlobalData();
globalData.country = country;
wx.navigateBack({
delta: 1
});
},
})
\ No newline at end of file
... ...
{}
\ No newline at end of file
... ...
<!--login/select-country/select-country.wxml-->
<view class="select-country-bg">
<block wx:for="{{country}}" wx:key="{{item.id}}">
<view class="country-info" bindtap="selectCountry" data-country="{{item}}">
<text class="country-name">{{item.name}}</text>
<text class="country-area-code">+{{item.area}}</text>
</view>
</block>
</view>
... ...
/* login/select-country/select-country.wxss */
.select-country-bg {
margin: 0 20rpx;
}
.country-info {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
font-size: 34rpx;
color:#444444;
height: 100rpx;
border-bottom: 1rpx solid #b0b0b0;
}
.country-area-code {
color:#b0b0b0;
}
\ No newline at end of file
... ...
... ... @@ -51,6 +51,8 @@ export default {
},
logistics: {
path: '/pages/orderDetail/logistics/logistics'
},
selectCountry: {
path: '/pages/select-country/select-country'
}
}
... ...