修改登录相关逻辑 review by 黄敬囿
Showing
9 changed files
with
104 additions
and
7 deletions
@@ -62,6 +62,7 @@ class App extends Component { | @@ -62,6 +62,7 @@ class App extends Component { | ||
62 | 'pages/orderList/orderlistcell', | 62 | 'pages/orderList/orderlistcell', |
63 | 'pages/orderDetail/logistics/logistics', | 63 | 'pages/orderDetail/logistics/logistics', |
64 | 'pages/webview/webview', | 64 | 'pages/webview/webview', |
65 | + 'pages/select-country/select-country', | ||
65 | /**零元购*/ | 66 | /**零元购*/ |
66 | // "pages/bindPhoneNumber/bindPhoneNumber", | 67 | // "pages/bindPhoneNumber/bindPhoneNumber", |
67 | "pages/zeroSell/index", | 68 | "pages/zeroSell/index", |
@@ -128,7 +129,7 @@ class App extends Component { | @@ -128,7 +129,7 @@ class App extends Component { | ||
128 | setSessionkey(); | 129 | setSessionkey(); |
129 | app_report('start', 'LIFECYCLE', 'START', {}, this); | 130 | app_report('start', 'LIFECYCLE', 'START', {}, this); |
130 | let userInfo = Taro.getStorageSync('userInfo'); | 131 | let userInfo = Taro.getStorageSync('userInfo'); |
131 | - if (userInfo && userInfo.uid && userInfo.session_key) { | 132 | + if (userInfo && userInfo.uid) { |
132 | checkUidAndSessionKey(userInfo.uid, userInfo.session_key).then(result => { | 133 | checkUidAndSessionKey(userInfo.uid, userInfo.session_key).then(result => { |
133 | if (result.statusCode === 200) { | 134 | if (result.statusCode === 200) { |
134 | console.log('session_key 未过期'); | 135 | console.log('session_key 未过期'); |
@@ -61,7 +61,6 @@ export const decodeUnionId = (srd_session, result) => { | @@ -61,7 +61,6 @@ export const decodeUnionId = (srd_session, result) => { | ||
61 | // 存储 userInfo | 61 | // 存储 userInfo |
62 | if (res && res.userInfo) { | 62 | if (res && res.userInfo) { |
63 | setStorageWithValueForKey('userInfo', res.userInfo); | 63 | setStorageWithValueForKey('userInfo', res.userInfo); |
64 | - setStorageWithValueForKey('myUserInfo', res.userInfo); | ||
65 | } else { | 64 | } else { |
66 | return; | 65 | return; |
67 | } | 66 | } |
@@ -193,7 +192,7 @@ const getStorageWithValueForKey = (key) => { | @@ -193,7 +192,7 @@ const getStorageWithValueForKey = (key) => { | ||
193 | }) | 192 | }) |
194 | } | 193 | } |
195 | 194 | ||
196 | -const getGlobalData = () => { | 195 | +export const getGlobalData = () => { |
197 | const app = getApp(); | 196 | const app = getApp(); |
198 | let globalData; | 197 | let globalData; |
199 | if (app && app.globalData) { | 198 | if (app && app.globalData) { |
@@ -411,4 +410,8 @@ export const getLoginButtonType = () => { | @@ -411,4 +410,8 @@ export const getLoginButtonType = () => { | ||
411 | const getStorageUserInfo = () => { | 410 | const getStorageUserInfo = () => { |
412 | const userInfo = wx.getStorageSync('userInfo'); | 411 | const userInfo = wx.getStorageSync('userInfo'); |
413 | return userInfo; | 412 | return userInfo; |
413 | +} | ||
414 | + | ||
415 | +export const getCountryArea = () => { | ||
416 | + return login.getCountryArea(); | ||
414 | } | 417 | } |
@@ -7,7 +7,8 @@ const WECHAT_ADDUNIONUPDUSER = 'app.wechat.addUnionUpdUser'; | @@ -7,7 +7,8 @@ const WECHAT_ADDUNIONUPDUSER = 'app.wechat.addUnionUpdUser'; | ||
7 | const WECHAT_PASSPORT_SIGNINBYOPENID = 'app.passport.signinByOpenID'; | 7 | const WECHAT_PASSPORT_SIGNINBYOPENID = 'app.passport.signinByOpenID'; |
8 | const WECHAT_PASSPORT_MINIAPPBINDBYAUTO = 'app.passport.miniAppBindByAuto'; | 8 | const WECHAT_PASSPORT_MINIAPPBINDBYAUTO = 'app.passport.miniAppBindByAuto'; |
9 | const WECHAT_ADDUPDUSER = 'app.wechat.addUpdUser'; | 9 | const WECHAT_ADDUPDUSER = 'app.wechat.addUpdUser'; |
10 | -const WECHAT_PASSPORT_VERIFY = 'app.passport.verify' | 10 | +const WECHAT_PASSPORT_VERIFY = 'app.passport.verify'; |
11 | +const PHONE_PASSPORT_GET_AREA = 'app.passport.getArea'; | ||
11 | 12 | ||
12 | const WechatPath = '/wechat/'; | 13 | const WechatPath = '/wechat/'; |
13 | 14 | ||
@@ -102,4 +103,10 @@ export class LoginService extends BaseService { | @@ -102,4 +103,10 @@ export class LoginService extends BaseService { | ||
102 | area: areaCode | 103 | area: areaCode |
103 | }) | 104 | }) |
104 | } | 105 | } |
106 | + | ||
107 | + async getCountryArea() { | ||
108 | + return await this.GET({ | ||
109 | + method: PHONE_PASSPORT_GET_AREA | ||
110 | + }); | ||
111 | + } | ||
105 | } | 112 | } |
@@ -8,7 +8,8 @@ import * as globalData from '../../actions/globalData'; | @@ -8,7 +8,8 @@ import * as globalData from '../../actions/globalData'; | ||
8 | import config from '../../config'; | 8 | import config from '../../config'; |
9 | import './index.scss'; | 9 | import './index.scss'; |
10 | import event from '../../utils/event.js' | 10 | import event from '../../utils/event.js' |
11 | -import { getUserInfo, getPhoneNumber, checkUnionIdIsBind } from '../../libs/login/login.js' | 11 | +import { getUserInfo, getPhoneNumber, checkUnionIdIsBind, getGlobalData } from '../../libs/login/login.js' |
12 | +import router from '../../router/index.js'; | ||
12 | 13 | ||
13 | const USER_GET_PHONENUMBER_ERROR = 'user-get-phonenumber-error'; | 14 | const USER_GET_PHONENUMBER_ERROR = 'user-get-phonenumber-error'; |
14 | const USER_LOGIN_CALLBACK = 'user-login-callback'; | 15 | const USER_LOGIN_CALLBACK = 'user-login-callback'; |
@@ -60,6 +61,21 @@ export default class Login extends Component { | @@ -60,6 +61,21 @@ export default class Login extends Component { | ||
60 | this.eventOnAll(); | 61 | this.eventOnAll(); |
61 | } | 62 | } |
62 | 63 | ||
64 | + componentDidShow() { | ||
65 | + const globalData = getGlobalData(); | ||
66 | + let country = globalData.country; | ||
67 | + if (country) { | ||
68 | + this.setState({ | ||
69 | + countryArea: country.area || '86' | ||
70 | + }) | ||
71 | + } | ||
72 | + } | ||
73 | + | ||
74 | + componentWillUnmount() { | ||
75 | + const globalData = getGlobalData(); | ||
76 | + globalData.country = null; | ||
77 | + } | ||
78 | + | ||
63 | addPrefix(prefix, eventName) { | 79 | addPrefix(prefix, eventName) { |
64 | return `${prefix}-${eventName}`; | 80 | return `${prefix}-${eventName}`; |
65 | } | 81 | } |
@@ -116,7 +132,7 @@ export default class Login extends Component { | @@ -116,7 +132,7 @@ export default class Login extends Component { | ||
116 | } | 132 | } |
117 | 133 | ||
118 | chooseCountry() { | 134 | chooseCountry() { |
119 | - | 135 | + router.go('selectCountry'); |
120 | } | 136 | } |
121 | 137 | ||
122 | phoneInputChanged(e) { | 138 | phoneInputChanged(e) { |
src/pages/select-country/select-country.js
0 → 100644
1 | +// login/select-country/select-country.js | ||
2 | +import { getCountryArea, getGlobalData } from '../../libs/login/login.js'; | ||
3 | +Page({ | ||
4 | + | ||
5 | + /** | ||
6 | + * 页面的初始数据 | ||
7 | + */ | ||
8 | + data: { | ||
9 | + country: [] | ||
10 | + }, | ||
11 | + | ||
12 | + /** | ||
13 | + * 生命周期函数--监听页面加载 | ||
14 | + */ | ||
15 | + onLoad: function (options) { | ||
16 | + this.getCountryArea(); | ||
17 | + }, | ||
18 | + | ||
19 | + async getCountryArea() { | ||
20 | + try { | ||
21 | + let country = await getCountryArea(); | ||
22 | + this.setData({ | ||
23 | + country | ||
24 | + }) | ||
25 | + } catch (error) { | ||
26 | + | ||
27 | + } | ||
28 | + }, | ||
29 | + | ||
30 | + selectCountry(e) { | ||
31 | + let country = e.currentTarget.dataset.country; | ||
32 | + let globalData = getGlobalData(); | ||
33 | + globalData.country = country; | ||
34 | + wx.navigateBack({ | ||
35 | + delta: 1 | ||
36 | + }); | ||
37 | + }, | ||
38 | +}) |
src/pages/select-country/select-country.json
0 → 100644
1 | +{} |
src/pages/select-country/select-country.wxml
0 → 100644
1 | +<!--login/select-country/select-country.wxml--> | ||
2 | +<view class="select-country-bg"> | ||
3 | + <block wx:for="{{country}}" wx:key="{{item.id}}"> | ||
4 | + <view class="country-info" bindtap="selectCountry" data-country="{{item}}"> | ||
5 | + <text class="country-name">{{item.name}}</text> | ||
6 | + <text class="country-area-code">+{{item.area}}</text> | ||
7 | + </view> | ||
8 | + </block> | ||
9 | +</view> |
src/pages/select-country/select-country.wxss
0 → 100644
1 | +/* login/select-country/select-country.wxss */ | ||
2 | + | ||
3 | +.select-country-bg { | ||
4 | + margin: 0 20rpx; | ||
5 | +} | ||
6 | + | ||
7 | +.country-info { | ||
8 | + display: flex; | ||
9 | + flex-direction: row; | ||
10 | + justify-content: space-between; | ||
11 | + align-items: center; | ||
12 | + font-size: 34rpx; | ||
13 | + color:#444444; | ||
14 | + height: 100rpx; | ||
15 | + border-bottom: 1rpx solid #b0b0b0; | ||
16 | +} | ||
17 | + | ||
18 | +.country-area-code { | ||
19 | + color:#b0b0b0; | ||
20 | +} |
@@ -51,6 +51,8 @@ export default { | @@ -51,6 +51,8 @@ export default { | ||
51 | }, | 51 | }, |
52 | logistics: { | 52 | logistics: { |
53 | path: '/pages/orderDetail/logistics/logistics' | 53 | path: '/pages/orderDetail/logistics/logistics' |
54 | + }, | ||
55 | + selectCountry: { | ||
56 | + path: '/pages/select-country/select-country' | ||
54 | } | 57 | } |
55 | - | ||
56 | } | 58 | } |
-
Please register or login to post a comment