首页不再做登录校验。点击立即选购以及点击首页发布和我的选项的时候进行登录校验。

This commit is contained in:
donqi 2022-07-01 22:31:45 +08:00
parent 022bb0b8e4
commit 71e9d9ad18
5 changed files with 98 additions and 68 deletions

View File

@ -77,10 +77,8 @@ export default {
let userInfo = await wx.getUserProfile({
desc: '用于小程序登录'
});
console.log("从微信获取基本用户信息:" + userInfo);
// 获取微信登录凭证
const wxLoginRes = await wx.login();
console.log(wxLoginRes)
// 获取openid
const wxAuthRes = await uni.request({
url: '/wx/auth',
@ -88,7 +86,6 @@ export default {
code: wxLoginRes.code
}
})
console.log(wxAuthRes)
const openId = wxAuthRes[1].data.data.openid;
// 第一次从服务端获取用户信息
let wxGetUserRes = await this.qryUserInfo(openId);
@ -113,7 +110,6 @@ export default {
wxLoginCode: wxLoginRes.code
}
}
console.log("通过后台服务获取用户信息:" + userInfo);
if (!userInfo || userInfo.customerId == null || userInfo.customerId == undefined) {
uni.showToast({
icon: 'none',
@ -202,7 +198,7 @@ export default {
}
if (phoneRes && phoneRes.data) {
let userInfo = this.getCurUserInfo();
this.updateUserPhone({
await this.updateUserPhone({
customerId: userInfo.customerId,
account: phoneRes.data,
phone: phoneRes.data

View File

@ -27,6 +27,7 @@
<script>
export default {
name: "module-bar",
emits: ['getCurPageInfo'],
props: {
moduleBarInfos: {
type: Array,
@ -48,7 +49,7 @@
navChange(e, isChangeFocus) {
let cur = e.currentTarget.dataset.cur;
this.curPageCode = isChangeFocus ? cur : this.curPageCode;
uni.$emit('getCurPageInfo', {
this.$emit('getCurPageInfo', {
curPageCode: cur
});
}

View File

@ -80,9 +80,6 @@
<vertical-goods-card :goodsInfos="hotGoods" :multiPicMode="true" title="大家都在买">
</vertical-goods-card>
</view>
<vertify-login ref="vertifyLogin" @reload="loadData"></vertify-login>
<vertify-phone ref="vertifyPhone" @reload="loadData"></vertify-phone>
</view>
</template>
@ -121,16 +118,6 @@
},
methods: {
async loadData() {
uni.showLoading({
mask: true,
title: '加载中'
})
let loginRes = this.authLogin();
if (!loginRes) {
return;
}
uni.hideLoading();
//
this.loadRegionList();
//
@ -150,27 +137,6 @@
// this.hotGoods = await this.$api.data('hotGoods');
// 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() {
uni.$on('index_showProductDetail', this.showDetails);
},

View File

@ -5,7 +5,13 @@
<personal-center v-if="curPageCode === 'myPage'"></personal-center>
<!-- <publish-home v-if="curPageCode === 'publishPage'"></publish-home> -->
<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-dialog bottom-dialog margin-bottom-with-bar">
<view class="padding-xl">
@ -79,41 +85,69 @@
return {
moduleBarInfos: [],
curPageCode: 'indexPage',
isShowPublish: false
isShowPublish: false,
forwardingPageCode: null
}
},
onLoad() {
this.loadData();
this.bindEvent();
},
onUnload() {
this.offEvent();
},
methods: {
async loadData() {
this.moduleBarInfos = await this.$api.data('moduleBarInfos');
},
bindEvent() {
uni.$on('getCurPageInfo', function(data) {
if (data.curPageCode === 'publishPage') {
reloadForwardPage() {
this.getCurPageInfo({
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;
} else {
this.isShowPublish = false;
this.curPageCode = data.curPageCode;
this.curPageCode = pageCode;
}
}.bind(this));
},
offEvent() {
uni.$off('getCurPageInfo')
},
hidePublish() {
this.isShowPublish = false;
},
showPage(url) {
console.log(url)
uni.navigateTo({
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;
}
}
}

View File

@ -171,7 +171,7 @@
购物车
</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>
<!-- 底部弹窗 -->
<uni-popup ref="productPickPopup" type="bottom" @change="changePopupState">
@ -179,6 +179,9 @@
class="cuIcon-close"></text></view>
<product-pick :shopInfo="shopInfo" :productInfo="productDetail" :specsList="productDetail.goodsStandardList" :orderNow="orderNow"></product-pick>
</uni-popup>
<!-- 登录校验弹窗 -->
<vertify-login ref="vertifyLogin" @reload="checkLogin"></vertify-login>
<vertify-phone ref="vertifyPhone" @reload="checkLogin"></vertify-phone>
</view>
</template>
@ -193,6 +196,7 @@
},
data() {
return {
inParam: {},
productDetail: {},
detailPicList: [],
swiperList: [],
@ -215,7 +219,8 @@
},
onLoad(options) {
let params = JSON.parse(decodeURIComponent(options.params));
this.loadData(params);
this.inParam = params;
this.loadData();
this.bindEvent();
},
onUnload() {
@ -229,10 +234,10 @@
this.changeSwiperHeight = e.scrollTop > 50 ? true: false;
},
methods: {
async loadData(params) {
async loadData() {
let productDetailMock = await this.$api.data('productDetail');
this.productDetail = await this.$request.getGoodsDetail({
goodsId: params.goodsId
goodsId: this.inParam.goodsId
});
//
this.curProductSpecs = this.productDetail.goodsStandardList[0];
@ -257,6 +262,34 @@
this.reviewers = productDetailMock.reviewers;
// 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() {
uni.$on('product-detail_add2Cart', this.add2Cart);
},
@ -305,7 +338,7 @@
selector: '#pageAnchor' + index
})
},
toggleProductPickModal(e, orderNow) {
async toggleProductPickModal(e, orderNow) {
this.orderNow = orderNow ? true : false;
if (this.ifShowPageMeta) {
this.$refs.productPickPopup.close();