Commit d345bfe7 by weijiguang
parents 6c4f074f e952ce56
......@@ -89,6 +89,7 @@ export default {
allchecked: true,
// checked:true,
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'
}
},
......@@ -96,6 +97,11 @@ export default {
$EventBus.$off('updateCar');
},
mounted() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
this.goods = uni.getStorageSync('shopCarInfo') || [];
$EventBus.$on('updateCar', () => {
this.goods = uni.getStorageSync('shopCarInfo') || [];
......@@ -138,6 +144,7 @@ export default {
// 付款前未登录发起授权
loginByPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
......@@ -87,6 +87,8 @@ export default {
available: [],
goods: {},
skusDefault: [],
skusSellout: [],
loginInfo:"",
pirce: 0,
size: 0,
}
......@@ -95,6 +97,11 @@ export default {
uni.removeStorageSync('goodsList');
},
onLoad() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
uni.removeStorageSync('goodsList');
const goodsInfo = JSON.parse(uni.getStorageSync('goodsInfo'));
this.goodInfo = goodsInfo;
......@@ -102,6 +109,10 @@ export default {
if (skus) {
const sku = skus.find(v => v.isDefault == 1 && v.state == 1) || skus.find(v => v.isDefault == 0 && v.state == 1);
this.skusDefault = skus.find(v => v.isDefault == 1);
this.skusSellout = skus.find(v => v.isDefault == 1 && v.state == 1)
|| skus.find(v => v.state == 1)
|| skus.find(v => v.isDefault == 1)
|| skus[0]
if (!sku) return;
this.selected.push(...sku.rules)
skus.forEach(item => {
......@@ -217,6 +228,7 @@ export default {
// 付款前未登录发起授权
loginByPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......@@ -233,10 +245,13 @@ export default {
priceTotal() {
let discount = 0;
let price = 0;
const { goods } = this;
const { goods,skusSellout } = this;
if (goods.sku) {
discount = goods.sku.discount * this.size
price = goods.sku.price * this.size
}else if(skusSellout){
discount = Number(skusSellout.discount)
price = Number(skusSellout.price)
}
return { discount: discount.toFixed(2), price: price.toFixed(2) }
}
......
......@@ -149,6 +149,13 @@ export default {
}).then(({ data }) => {
this.duration = data.data
})
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
},
data() {
return {
......@@ -157,7 +164,8 @@ export default {
shopData: {},
option: '',
payType: '1',
duration: ''
duration: '',
loginInfo: ''
}
},
computed: {
......@@ -204,6 +212,7 @@ export default {
// 手机号授权登录
getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
{
"name": "user",
"name": "uniapp",
"lockfileVersion": 2,
"requires": true,
"packages": {
......
......@@ -69,7 +69,8 @@ export default {
classifyData: [],
customerName: '',
show: false,
columns: []
columns: [],
loginInfo:""
};
},
computed: {
......@@ -90,6 +91,11 @@ export default {
this.shopInfo = data;
this.getMenuList(data.id)
})
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
},
onHide() {
this.$refs.shopbar.showShopCar = false;
......@@ -159,6 +165,7 @@ export default {
// 手机号授权登录
getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
......@@ -64,8 +64,16 @@
import User from '@/request/user'
export default {
onLoad() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
},
data() {
return {
loginInfo:""
}
},
computed: {
......@@ -77,9 +85,11 @@ export default {
},
},
methods: {
// 手机号授权登录
getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
......@@ -81,11 +81,19 @@ import User from '@/request/user'
import { $EventBus } from "@/utils/EventBus";
export default {
onLoad() {
if(!this.userms){
User.wxLoginAndGetOpenid(true).then(loginInfo=>{
this.loginInfo = loginInfo
})
}
},
name: 'order',
data() {
return {
empty: false,
list: []
list: [],
loginInfo:""
}
},
onShow() {
......@@ -144,6 +152,7 @@ export default {
// 手机号授权登录
getPhoneNumber(e) {
if (e.detail.errMsg == 'getPhoneNumber:ok') {
e.loginInfo = this.loginInfo
User.getPhoneNumber(e, this.getList);
} else if (e.detail.errMsg == "getPhoneNumber:fail user deny") {
uni.showToast({ title: '已拒绝手机号授权', icon: 'error' })
......
import Store from '@/store';
import { $EventBus } from '@/utils/EventBus';
import loadingIcon from 'uview-ui/libs/config/props/loadingIcon';
import { data } from 'uview-ui/libs/mixin/mixin';
export default {
getLocation(callback) {
let _this = this;
......@@ -78,6 +80,9 @@ export default {
},
});
},
getOpenId(res) {
return uni.$u.http.post('/weixin/login', {code:res })
},
getAuthorization(phoneNumber) {
uni.$u.http.post('/weixin/refreshToken ', { phoneNumber }).then((res) => {
const { data } = res;
......@@ -86,12 +91,71 @@ export default {
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) {
uni.setStorage({ key: 'userPhoneInfo', data: res });
Store.commit('setUserPhoneInfo', 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) {
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