首页不再做登录校验。点击立即选购以及点击首页发布和我的选项的时候进行登录校验。
This commit is contained in:
parent
022bb0b8e4
commit
71e9d9ad18
|
|
@ -77,10 +77,8 @@ export default {
|
||||||
let userInfo = await wx.getUserProfile({
|
let userInfo = await wx.getUserProfile({
|
||||||
desc: '用于小程序登录'
|
desc: '用于小程序登录'
|
||||||
});
|
});
|
||||||
console.log("从微信获取基本用户信息:" + userInfo);
|
|
||||||
// 获取微信登录凭证
|
// 获取微信登录凭证
|
||||||
const wxLoginRes = await wx.login();
|
const wxLoginRes = await wx.login();
|
||||||
console.log(wxLoginRes)
|
|
||||||
// 获取openid
|
// 获取openid
|
||||||
const wxAuthRes = await uni.request({
|
const wxAuthRes = await uni.request({
|
||||||
url: '/wx/auth',
|
url: '/wx/auth',
|
||||||
|
|
@ -88,7 +86,6 @@ export default {
|
||||||
code: wxLoginRes.code
|
code: wxLoginRes.code
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log(wxAuthRes)
|
|
||||||
const openId = wxAuthRes[1].data.data.openid;
|
const openId = wxAuthRes[1].data.data.openid;
|
||||||
// 第一次从服务端获取用户信息
|
// 第一次从服务端获取用户信息
|
||||||
let wxGetUserRes = await this.qryUserInfo(openId);
|
let wxGetUserRes = await this.qryUserInfo(openId);
|
||||||
|
|
@ -113,7 +110,6 @@ export default {
|
||||||
wxLoginCode: wxLoginRes.code
|
wxLoginCode: wxLoginRes.code
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
console.log("通过后台服务获取用户信息:" + userInfo);
|
|
||||||
if (!userInfo || userInfo.customerId == null || userInfo.customerId == undefined) {
|
if (!userInfo || userInfo.customerId == null || userInfo.customerId == undefined) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
icon: 'none',
|
icon: 'none',
|
||||||
|
|
@ -202,7 +198,7 @@ export default {
|
||||||
}
|
}
|
||||||
if (phoneRes && phoneRes.data) {
|
if (phoneRes && phoneRes.data) {
|
||||||
let userInfo = this.getCurUserInfo();
|
let userInfo = this.getCurUserInfo();
|
||||||
this.updateUserPhone({
|
await this.updateUserPhone({
|
||||||
customerId: userInfo.customerId,
|
customerId: userInfo.customerId,
|
||||||
account: phoneRes.data,
|
account: phoneRes.data,
|
||||||
phone: phoneRes.data
|
phone: phoneRes.data
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@
|
||||||
<script>
|
<script>
|
||||||
export default {
|
export default {
|
||||||
name: "module-bar",
|
name: "module-bar",
|
||||||
|
emits: ['getCurPageInfo'],
|
||||||
props: {
|
props: {
|
||||||
moduleBarInfos: {
|
moduleBarInfos: {
|
||||||
type: Array,
|
type: Array,
|
||||||
|
|
@ -48,7 +49,7 @@
|
||||||
navChange(e, isChangeFocus) {
|
navChange(e, isChangeFocus) {
|
||||||
let cur = e.currentTarget.dataset.cur;
|
let cur = e.currentTarget.dataset.cur;
|
||||||
this.curPageCode = isChangeFocus ? cur : this.curPageCode;
|
this.curPageCode = isChangeFocus ? cur : this.curPageCode;
|
||||||
uni.$emit('getCurPageInfo', {
|
this.$emit('getCurPageInfo', {
|
||||||
curPageCode: cur
|
curPageCode: cur
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -80,9 +80,6 @@
|
||||||
<vertical-goods-card :goodsInfos="hotGoods" :multiPicMode="true" title="大家都在买">
|
<vertical-goods-card :goodsInfos="hotGoods" :multiPicMode="true" title="大家都在买">
|
||||||
</vertical-goods-card>
|
</vertical-goods-card>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<vertify-login ref="vertifyLogin" @reload="loadData"></vertify-login>
|
|
||||||
<vertify-phone ref="vertifyPhone" @reload="loadData"></vertify-phone>
|
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -121,16 +118,6 @@
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async loadData() {
|
async loadData() {
|
||||||
uni.showLoading({
|
|
||||||
mask: true,
|
|
||||||
title: '加载中'
|
|
||||||
})
|
|
||||||
let loginRes = this.authLogin();
|
|
||||||
if (!loginRes) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uni.hideLoading();
|
|
||||||
|
|
||||||
// 加载区域信息
|
// 加载区域信息
|
||||||
this.loadRegionList();
|
this.loadRegionList();
|
||||||
// 加载热门商品
|
// 加载热门商品
|
||||||
|
|
@ -150,27 +137,6 @@
|
||||||
// this.hotGoods = await this.$api.data('hotGoods');
|
// this.hotGoods = await this.$api.data('hotGoods');
|
||||||
// this.discountGoods = await this.$api.data('discountGoods');
|
// this.discountGoods = await this.$api.data('discountGoods');
|
||||||
},
|
},
|
||||||
async authLogin() {
|
|
||||||
// 更新缓存中的userInfo
|
|
||||||
let res = await this.$request.storageExistUser();
|
|
||||||
// 获取缓存中的userInfo
|
|
||||||
let curUserInfo = this.$request.getCurUserInfo();
|
|
||||||
// 校验提示登录
|
|
||||||
if (!curUserInfo || !curUserInfo.openId) {
|
|
||||||
this.$refs.vertifyLogin.showModal();
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
this.$refs.vertifyLogin.hideModal();
|
|
||||||
}
|
|
||||||
// 校验提示获取手机号码
|
|
||||||
if (!curUserInfo.phone) {
|
|
||||||
this.$refs.vertifyPhone.showModal();
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
this.$refs.vertifyPhone.hideModal();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
bindEvent() {
|
bindEvent() {
|
||||||
uni.$on('index_showProductDetail', this.showDetails);
|
uni.$on('index_showProductDetail', this.showDetails);
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,13 @@
|
||||||
<personal-center v-if="curPageCode === 'myPage'"></personal-center>
|
<personal-center v-if="curPageCode === 'myPage'"></personal-center>
|
||||||
<!-- <publish-home v-if="curPageCode === 'publishPage'"></publish-home> -->
|
<!-- <publish-home v-if="curPageCode === 'publishPage'"></publish-home> -->
|
||||||
<msg-page v-if="curPageCode === 'msgPage'"></msg-page>
|
<msg-page v-if="curPageCode === 'msgPage'"></msg-page>
|
||||||
<module-bar ref="moduleBar" :moduleBarInfos="moduleBarInfos"></module-bar>
|
<module-bar ref="moduleBar" :moduleBarInfos="moduleBarInfos" @getCurPageInfo="getCurPageInfo"></module-bar>
|
||||||
|
|
||||||
|
<!-- 登录校验弹窗 -->
|
||||||
|
<vertify-login ref="vertifyLogin" @reload="reloadForwardPage"></vertify-login>
|
||||||
|
<vertify-phone ref="vertifyPhone" @reload="reloadForwardPage"></vertify-phone>
|
||||||
|
|
||||||
|
<!-- 发布 -->
|
||||||
<view class="cu-modal content-mask" :class="isShowPublish?'show':''">
|
<view class="cu-modal content-mask" :class="isShowPublish?'show':''">
|
||||||
<view class="cu-dialog bottom-dialog margin-bottom-with-bar">
|
<view class="cu-dialog bottom-dialog margin-bottom-with-bar">
|
||||||
<view class="padding-xl">
|
<view class="padding-xl">
|
||||||
|
|
@ -79,41 +85,69 @@
|
||||||
return {
|
return {
|
||||||
moduleBarInfos: [],
|
moduleBarInfos: [],
|
||||||
curPageCode: 'indexPage',
|
curPageCode: 'indexPage',
|
||||||
isShowPublish: false
|
isShowPublish: false,
|
||||||
|
forwardingPageCode: null
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onLoad() {
|
onLoad() {
|
||||||
this.loadData();
|
this.loadData();
|
||||||
this.bindEvent();
|
|
||||||
},
|
|
||||||
onUnload() {
|
|
||||||
this.offEvent();
|
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async loadData() {
|
async loadData() {
|
||||||
this.moduleBarInfos = await this.$api.data('moduleBarInfos');
|
this.moduleBarInfos = await this.$api.data('moduleBarInfos');
|
||||||
},
|
},
|
||||||
bindEvent() {
|
reloadForwardPage() {
|
||||||
uni.$on('getCurPageInfo', function(data) {
|
this.getCurPageInfo({
|
||||||
if (data.curPageCode === 'publishPage') {
|
curPageCode: this.forwardingPageCode
|
||||||
|
})
|
||||||
|
},
|
||||||
|
async getCurPageInfo(data) {
|
||||||
|
let pageCode = data.curPageCode;
|
||||||
|
this.forwardingPageCode = pageCode;
|
||||||
|
// 登录校验
|
||||||
|
if (['publishPage', 'myPage'].indexOf(pageCode) >= 0) {
|
||||||
|
let loginRes = await this.authLogin();
|
||||||
|
if (!loginRes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.forwardingPageCode = null;
|
||||||
|
|
||||||
|
if (pageCode === 'publishPage') {
|
||||||
this.isShowPublish = true;
|
this.isShowPublish = true;
|
||||||
} else {
|
} else {
|
||||||
this.isShowPublish = false;
|
this.isShowPublish = false;
|
||||||
this.curPageCode = data.curPageCode;
|
this.curPageCode = pageCode;
|
||||||
}
|
}
|
||||||
}.bind(this));
|
|
||||||
},
|
|
||||||
offEvent() {
|
|
||||||
uni.$off('getCurPageInfo')
|
|
||||||
},
|
},
|
||||||
hidePublish() {
|
hidePublish() {
|
||||||
this.isShowPublish = false;
|
this.isShowPublish = false;
|
||||||
},
|
},
|
||||||
showPage(url) {
|
showPage(url) {
|
||||||
console.log(url)
|
|
||||||
uni.navigateTo({
|
uni.navigateTo({
|
||||||
url: url
|
url: url
|
||||||
})
|
})
|
||||||
|
},
|
||||||
|
async authLogin() {
|
||||||
|
// 更新缓存中的userInfo
|
||||||
|
let res = await this.$request.storageExistUser();
|
||||||
|
// 获取缓存中的userInfo
|
||||||
|
let curUserInfo = this.$request.getCurUserInfo();
|
||||||
|
// 校验提示登录
|
||||||
|
if (!curUserInfo || !curUserInfo.openId) {
|
||||||
|
this.$refs.vertifyLogin.showModal();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
this.$refs.vertifyLogin.hideModal();
|
||||||
|
}
|
||||||
|
// 校验提示获取手机号码
|
||||||
|
if (!curUserInfo.phone) {
|
||||||
|
this.$refs.vertifyPhone.showModal();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
this.$refs.vertifyPhone.hideModal();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@
|
||||||
购物车
|
购物车
|
||||||
</view>
|
</view>
|
||||||
<view class="bg-main-color light submit" @click="toggleProductPickModal">加入购物车</view>
|
<view class="bg-main-color light submit" @click="toggleProductPickModal">加入购物车</view>
|
||||||
<view class="bg-main-color submit" @click="toggleProductPickModal($event, true)">立即订购</view>
|
<view class="bg-main-color submit" @tap="checkLogin" @click="toggleProductPickModal($event, true)">立即订购</view>
|
||||||
</view>
|
</view>
|
||||||
<!-- 底部弹窗 -->
|
<!-- 底部弹窗 -->
|
||||||
<uni-popup ref="productPickPopup" type="bottom" @change="changePopupState">
|
<uni-popup ref="productPickPopup" type="bottom" @change="changePopupState">
|
||||||
|
|
@ -179,6 +179,9 @@
|
||||||
class="cuIcon-close"></text></view>
|
class="cuIcon-close"></text></view>
|
||||||
<product-pick :shopInfo="shopInfo" :productInfo="productDetail" :specsList="productDetail.goodsStandardList" :orderNow="orderNow"></product-pick>
|
<product-pick :shopInfo="shopInfo" :productInfo="productDetail" :specsList="productDetail.goodsStandardList" :orderNow="orderNow"></product-pick>
|
||||||
</uni-popup>
|
</uni-popup>
|
||||||
|
<!-- 登录校验弹窗 -->
|
||||||
|
<vertify-login ref="vertifyLogin" @reload="checkLogin"></vertify-login>
|
||||||
|
<vertify-phone ref="vertifyPhone" @reload="checkLogin"></vertify-phone>
|
||||||
</view>
|
</view>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
@ -193,6 +196,7 @@
|
||||||
},
|
},
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
|
inParam: {},
|
||||||
productDetail: {},
|
productDetail: {},
|
||||||
detailPicList: [],
|
detailPicList: [],
|
||||||
swiperList: [],
|
swiperList: [],
|
||||||
|
|
@ -215,7 +219,8 @@
|
||||||
},
|
},
|
||||||
onLoad(options) {
|
onLoad(options) {
|
||||||
let params = JSON.parse(decodeURIComponent(options.params));
|
let params = JSON.parse(decodeURIComponent(options.params));
|
||||||
this.loadData(params);
|
this.inParam = params;
|
||||||
|
this.loadData();
|
||||||
this.bindEvent();
|
this.bindEvent();
|
||||||
},
|
},
|
||||||
onUnload() {
|
onUnload() {
|
||||||
|
|
@ -229,10 +234,10 @@
|
||||||
this.changeSwiperHeight = e.scrollTop > 50 ? true: false;
|
this.changeSwiperHeight = e.scrollTop > 50 ? true: false;
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
async loadData(params) {
|
async loadData() {
|
||||||
let productDetailMock = await this.$api.data('productDetail');
|
let productDetailMock = await this.$api.data('productDetail');
|
||||||
this.productDetail = await this.$request.getGoodsDetail({
|
this.productDetail = await this.$request.getGoodsDetail({
|
||||||
goodsId: params.goodsId
|
goodsId: this.inParam.goodsId
|
||||||
});
|
});
|
||||||
// 默认规格
|
// 默认规格
|
||||||
this.curProductSpecs = this.productDetail.goodsStandardList[0];
|
this.curProductSpecs = this.productDetail.goodsStandardList[0];
|
||||||
|
|
@ -257,6 +262,34 @@
|
||||||
this.reviewers = productDetailMock.reviewers;
|
this.reviewers = productDetailMock.reviewers;
|
||||||
// this.shopInfo = productDetailMock.shopInfo;
|
// this.shopInfo = productDetailMock.shopInfo;
|
||||||
},
|
},
|
||||||
|
async checkLogin() {
|
||||||
|
let loginRes = await this.authLogin();
|
||||||
|
if (!loginRes) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.loadData();
|
||||||
|
},
|
||||||
|
async authLogin() {
|
||||||
|
// 更新缓存中的userInfo
|
||||||
|
let res = await this.$request.storageExistUser();
|
||||||
|
// 获取缓存中的userInfo
|
||||||
|
let curUserInfo = this.$request.getCurUserInfo();
|
||||||
|
// 校验提示登录
|
||||||
|
if (!curUserInfo || !curUserInfo.openId) {
|
||||||
|
this.$refs.vertifyLogin.showModal();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
this.$refs.vertifyLogin.hideModal();
|
||||||
|
}
|
||||||
|
// 校验提示获取手机号码
|
||||||
|
if (!curUserInfo.phone) {
|
||||||
|
this.$refs.vertifyPhone.showModal();
|
||||||
|
return false;
|
||||||
|
} else {
|
||||||
|
this.$refs.vertifyPhone.hideModal();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
bindEvent() {
|
bindEvent() {
|
||||||
uni.$on('product-detail_add2Cart', this.add2Cart);
|
uni.$on('product-detail_add2Cart', this.add2Cart);
|
||||||
},
|
},
|
||||||
|
|
@ -305,7 +338,7 @@
|
||||||
selector: '#pageAnchor' + index
|
selector: '#pageAnchor' + index
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
toggleProductPickModal(e, orderNow) {
|
async toggleProductPickModal(e, orderNow) {
|
||||||
this.orderNow = orderNow ? true : false;
|
this.orderNow = orderNow ? true : false;
|
||||||
if (this.ifShowPageMeta) {
|
if (this.ifShowPageMeta) {
|
||||||
this.$refs.productPickPopup.close();
|
this.$refs.productPickPopup.close();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue