Commit e952ce56 by songbingqi

修复两次登陆的问题

parent e8779c14
...@@ -89,6 +89,7 @@ export default { ...@@ -89,6 +89,7 @@ export default {
allchecked: true, allchecked: true,
// checked:true, // checked:true,
goods: [],//购物车商品信息 goods: [],//购物车商品信息
loginInfo:"",
imgPath: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F01%2F82%2F40%2F596fa6dc00bb4_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633499781&t=d37222e32213957ddbdd01d62e071309' imgPath: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic.51yuansu.com%2Fpic3%2Fcover%2F01%2F82%2F40%2F596fa6dc00bb4_610.jpg&refer=http%3A%2F%2Fpic.51yuansu.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633499781&t=d37222e32213957ddbdd01d62e071309'
} }
}, },
...@@ -96,6 +97,11 @@ export default { ...@@ -96,6 +97,11 @@ export default {
$EventBus.$off('updateCar'); $EventBus.$off('updateCar');
}, },
mounted() { mounted() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
this.goods = uni.getStorageSync('shopCarInfo') || []; this.goods = uni.getStorageSync('shopCarInfo') || [];
$EventBus.$on('updateCar', () => { $EventBus.$on('updateCar', () => {
this.goods = uni.getStorageSync('shopCarInfo') || []; this.goods = uni.getStorageSync('shopCarInfo') || [];
...@@ -138,6 +144,7 @@ export default { ...@@ -138,6 +144,7 @@ export default {
// 付款前未登录发起授权 // 付款前未登录发起授权
loginByPhoneNumber(e) { loginByPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e); User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") { } else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' }) uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
...@@ -88,6 +88,7 @@ export default { ...@@ -88,6 +88,7 @@ export default {
goods: {}, goods: {},
skusDefault: [], skusDefault: [],
skusSellout: [], skusSellout: [],
loginInfo:"",
pirce: 0, pirce: 0,
size: 0, size: 0,
} }
...@@ -96,6 +97,11 @@ export default { ...@@ -96,6 +97,11 @@ export default {
uni.removeStorageSync('goodsList'); uni.removeStorageSync('goodsList');
}, },
onLoad() { onLoad() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
uni.removeStorageSync('goodsList'); uni.removeStorageSync('goodsList');
const goodsInfo = JSON.parse(uni.getStorageSync('goodsInfo')); const goodsInfo = JSON.parse(uni.getStorageSync('goodsInfo'));
this.goodInfo = goodsInfo; this.goodInfo = goodsInfo;
...@@ -222,6 +228,7 @@ export default { ...@@ -222,6 +228,7 @@ export default {
// 付款前未登录发起授权 // 付款前未登录发起授权
loginByPhoneNumber(e) { loginByPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e); User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") { } else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' }) uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
...@@ -149,6 +149,13 @@ export default { ...@@ -149,6 +149,13 @@ export default {
}).then(({ data }) => { }).then(({ data }) => {
this.duration = data.data this.duration = data.data
}) })
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
}, },
data() { data() {
return { return {
...@@ -157,7 +164,8 @@ export default { ...@@ -157,7 +164,8 @@ export default {
shopData: {}, shopData: {},
option: '', option: '',
payType: '1', payType: '1',
duration: '' duration: '',
loginInfo: ''
} }
}, },
computed: { computed: {
...@@ -204,6 +212,7 @@ export default { ...@@ -204,6 +212,7 @@ export default {
// 手机号授权登录 // 手机号授权登录
getPhoneNumber(e) { getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e); User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") { } else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' }) uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
{ {
"name": "user", "name": "uniapp",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
......
...@@ -69,7 +69,8 @@ export default { ...@@ -69,7 +69,8 @@ export default {
classifyData: [], classifyData: [],
customerName: '', customerName: '',
show: false, show: false,
columns: [] columns: [],
loginInfo:""
}; };
}, },
computed: { computed: {
...@@ -90,6 +91,11 @@ export default { ...@@ -90,6 +91,11 @@ export default {
this.shopInfo = data; this.shopInfo = data;
this.getMenuList(data.id) this.getMenuList(data.id)
}) })
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
}, },
onHide() { onHide() {
this.$refs.shopbar.showShopCar = false; this.$refs.shopbar.showShopCar = false;
...@@ -152,6 +158,7 @@ export default { ...@@ -152,6 +158,7 @@ export default {
// 手机号授权登录 // 手机号授权登录
getPhoneNumber(e) { getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e); User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") { } else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' }) uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
...@@ -64,8 +64,16 @@ ...@@ -64,8 +64,16 @@
import User from '@/request/user' import User from '@/request/user'
export default { export default {
onLoad() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
},
data() { data() {
return { return {
loginInfo:""
} }
}, },
computed: { computed: {
...@@ -77,9 +85,11 @@ export default { ...@@ -77,9 +85,11 @@ export default {
}, },
}, },
methods: { methods: {
// 手机号授权登录 // 手机号授权登录
getPhoneNumber(e) { getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e); User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") { } else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' }) uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
...@@ -81,11 +81,19 @@ import User from '@/request/user' ...@@ -81,11 +81,19 @@ import User from '@/request/user'
import { $EventBus } from "@/utils/EventBus"; import { $EventBus } from "@/utils/EventBus";
export default { export default {
onLoad() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
},
name: 'order', name: 'order',
data() { data() {
return { return {
empty: false, empty: false,
list: [] list: [],
loginInfo:""
} }
}, },
onShow() { onShow() {
...@@ -144,6 +152,7 @@ export default { ...@@ -144,6 +152,7 @@ export default {
// 手机号授权登录 // 手机号授权登录
getPhoneNumber(e) { getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') { if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e, this.getList); User.getPhoneNumber(e, this.getList);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") { } else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' }) uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
import Store from '@/store'; import Store from '@/store';
import { $EventBus } from '@/utils/EventBus'; import { $EventBus } from '@/utils/EventBus';
import loadingIcon from 'uview-ui/libs/config/props/loadingIcon';
import { data } from 'uview-ui/libs/mixin/mixin';
export default { export default {
getLocation(callback) { getLocation(callback) {
let _this = this; let _this = this;
...@@ -78,6 +80,9 @@ export default { ...@@ -78,6 +80,9 @@ export default {
}, },
}); });
}, },
getOpenId(res) {
return uni.$u.http.post('/weixin/login', {code:res })
},
getAuthorization(phoneNumber) { getAuthorization(phoneNumber) {
uni.$u.http.post('/weixin/refreshToken ', { phoneNumber }).then((res) => { uni.$u.http.post('/weixin/refreshToken ', { phoneNumber }).then((res) => {
const { data } = res; const { data } = res;
...@@ -86,12 +91,71 @@ export default { ...@@ -86,12 +91,71 @@ export default {
uni.showToast({ title: '登录成功!' }); uni.showToast({ title: '登录成功!' });
}); });
}, },
wxLoginAndGetOpenid(loding, updata) {
return new Promise((resolve, reject) => {
uni.login({
provider: 'weixin',
success: (res) => {
const code = res.code
if(code){
this.getOpenId(code).then((res)=>{
const loginInfo = res.data.msg
resolve(loginInfo)
})
}
}
})
})
},
loginDecrypt(res){
return uni.$u.http.post('/weixin/decrypt ', {
session_key:res.loginInfo.session_key,
openId:res.loginInfo.openid,
encryptedData:res.data,
iv:res.iv,
source:3
})
},
// 手机号授权登录 // 手机号授权登录
getPhoneNumber(res, callback) { getPhoneNumber(res, callback) {
uni.setStorage({ key: 'userPhoneInfo', data: res }); uni.setStorage({ key: 'userPhoneInfo', data: res });
Store.commit('setUserPhoneInfo', res); Store.commit('setUserPhoneInfo', res);
uni.setStorage({ key: 'phoneInfo', data: res }); uni.setStorage({ key: 'phoneInfo', data: res });
this.uniLogin(res.detail, callback); const loginInfo = res.loginInfo
const iv = res.detail.iv
const data = res.detail.encryptedData
wx.checkSession({
success: (res) => {
console.log('seeon未过期')
this.onLogin(loginInfo,iv,data,callback)
},
fail: (res) => {
console.log('seeon已过期')
this.wxLoginAndGetOpenid(true).then(loginInfo => {
this.onLogin(loginInfo,iv,data,callback)
})
}
})
// this.uniLogin(res.detail, callback);
},
onLogin(loginInfo,iv,data,callback) {
this.loginDecrypt({loginInfo:JSON.parse(loginInfo),iv,data}).then(res => {
const { statusCode, data } = res;
const { code, token, phoneNumber } = data;
if (statusCode == 200 && data && code == 200) {
uni.setStorage({ key: 'Authorization', data: token });
uni.setStorage({ key: 'phoneNumber', data: phoneNumber });
uni.setStorage({ key: 'userInfo', data: data });
Store.commit('setUserInfo', data);
Store.commit('setAuthorization', token);
if(callback)
callback();
}
}).catch((err) => {
uni.showToast({
title: err.msg,
});
});
}, },
setAllow(allow) { setAllow(allow) {
uni.$u.http uni.$u.http
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment