diff --git a/components/loginPopup.vue b/components/loginPopup.vue index 687d255..1ac49c7 100644 --- a/components/loginPopup.vue +++ b/components/loginPopup.vue @@ -9,7 +9,13 @@ - 我已阅读并同意《商家入驻协议》 + + + + 我已阅读并同意 + 《商家入驻协议》 + + @@ -53,6 +59,7 @@ password: '' }, showPassword: false, + isAgree: false }; }, methods: { @@ -76,6 +83,13 @@ // 微信登录 toLogin() { + if (!this.isAgree) { + uni.showToast({ + title: '请先同意商家入驻协议', + icon: 'none' + }) + return + } uni.login({ provider: 'weixin', //使用微信登录 success: (loginRes) => { @@ -99,7 +113,22 @@ }) }, decryptPhoneNumber(e) { - console.log(e.detail.code) + if (!this.isAgree) { + uni.showToast({ + title: '请先同意商家入驻协议', + icon: 'none' + }) + return + } + + if (!e.detail.code) { + uni.showToast({ + title: '获取手机号失败,请重试', + icon: 'none' + }) + return + } + const data = { code: e.detail.code } @@ -194,6 +223,16 @@ uni.setStorageSync('barInfo', res.data) }) }, + // 协议勾选 + checkboxChange(e) { + this.isAgree = e.detail.value.length > 0 + }, + // 跳转到协议页面 + toAgreement() { + uni.navigateTo({ + url: '/pages/index/userAgreement' + }) + }, } } @@ -209,6 +248,7 @@ justify-content: center; align-items: center; padding: 80rpx 32rpx; + border-radius: 24rpx 24rpx 0rpx 0rpx; .title { font-family: Roboto; @@ -253,6 +293,34 @@ font-weight: 500; color: #979797; } + + .agreement-box { + display: flex; + justify-content: center; + align-items: center; + margin-top: 20rpx; + + .checkbox-group { + display: flex; + align-items: center; + + .checkbox { + transform: scale(0.8); + margin-right: 8rpx; + } + + .agreement-text { + font-size: 24rpx; + color: #666666; + margin-right: 4rpx; + } + + .link { + font-size: 24rpx; + color: #19367A; + } + } + } } .page-content { padding: 48rpx 32rpx; diff --git a/pages.json b/pages.json index 9e3613d..0e814ea 100644 --- a/pages.json +++ b/pages.json @@ -167,6 +167,14 @@ { "navigationBarTitleText" : "" } + }, + { + "path": "pages/index/userAgreement", + "style": { + "navigationBarTitleText": "商家入驻协议", + "navigationBarBackgroundColor": "#19367A", + "navigationBarTextStyle": "white" + } } diff --git a/pages/index/chooseLogin.vue b/pages/index/chooseLogin.vue index 9621241..5e39909 100644 --- a/pages/index/chooseLogin.vue +++ b/pages/index/chooseLogin.vue @@ -1,7 +1,7 @@ @@ -27,7 +33,7 @@ export default { data() { return { - + isAgree: false }; }, onLoad() { @@ -36,20 +42,24 @@ methods: { // 微信登录 toLogin() { + if (!this.isAgree) { + uni.showToast({ + title: '请先同意商家入驻协议', + icon: 'none' + }) + return + } uni.login({ - provider: 'weixin', //使用微信登录 + provider: 'weixin', success: (loginRes) => { - console.log(loginRes.code); if (loginRes.code) { uni.showLoading({ mask: true }) getOpenId(loginRes.code).then(res => { - console.log(res.token) this.openId = res.openId if (res.token) { uni.setStorageSync('token', res.token) - // 获取用户信息 this.getUserInfoFun() this.getBarInfoFun() } @@ -59,20 +69,23 @@ }) }, decryptPhoneNumber(e) { - console.log(e.detail.code) + if (!this.isAgree) { + uni.showToast({ + title: '请先同意商家入驻协议', + icon: 'none' + }) + return + } const data = { code: e.detail.code } uni.showLoading() phoneCodeLoginApi(data).then(res=>{ - console.log(res,'22222') if (res.token) { uni.setStorageSync('token', res.token) - // 获取用户信息 this.getUserInfoFun() this.getBarInfoFun() } - }) }, // 获取用户信息 @@ -81,7 +94,6 @@ if (res.user && res.user.barId) { this.userInfo = res.user uni.setStorageSync('userInfo', res.user) - // 进入首页 uni.reLaunch({ url: '/pages/index/index' }) @@ -92,7 +104,6 @@ showCancel: true, success: (res) => { if (res.confirm) { - console.log('确定') uni.navigateTo({ url: '/pages/index/registration?openId=' + this.openId }) @@ -100,7 +111,6 @@ } }) } - uni.hideLoading() }) }, @@ -143,6 +153,16 @@ // uni.navigateTo({ // url: "/pages/index/phoneLogin" // }) + }, + // 跳转到协议页面 + toAgreement() { + uni.navigateTo({ + url: '/pages/index/userAgreement' + }) + }, + // 协议勾选 + checkboxChange(e) { + this.isAgree = e.detail.value.length > 0 } } } @@ -169,10 +189,41 @@ .btn { width: 686rpx; - height: 104rpx; + height: 80rpx; border-radius: 12rpx; // box-shadow: 0px 10px 24px 0px rgba(43, 45, 51, 0.2); } + .agreement-box { + position: fixed; + bottom: 100rpx; + left: 0; + right: 0; + display: flex; + justify-content: center; + align-items: center; + + .checkbox-group { + display: flex; + align-items: center; + justify-content: center; + + .checkbox { + transform: scale(0.8); + margin-right: 8rpx; + } + + .agreement-text { + font-size: 24rpx; + color: #666666; + margin-right: 4rpx; + } + + .link { + font-size: 24rpx; + color: #19367A; + } + } + } } \ No newline at end of file diff --git a/pages/index/my.vue b/pages/index/my.vue index 4379475..5c4e535 100644 --- a/pages/index/my.vue +++ b/pages/index/my.vue @@ -109,25 +109,33 @@ }, data() { return { - loading: true, - statusBaeHeight: 40, userInfo: null, + loading: true, barInfo: null, - myScanData: {} + myScanData: null, + isLoggedIn: false, + statusBaeHeight: 40 }; }, onLoad() { this.statusBaeHeight = uni.getWindowInfo.statusBarHeight }, onShow() { - this.userInfo = uni.getStorageSync('userInfo') - if (this.userInfo) { - this.loading = false + this.checkLoginStatus() + if (this.isLoggedIn) { this.getBarInfoFun() this.getMyScanDataFun() } }, methods: { + // 检查登录状态 + checkLoginStatus() { + const token = uni.getStorageSync('token') + const userInfo = uni.getStorageSync('userInfo') + this.isLoggedIn = !!(token && userInfo) + this.userInfo = userInfo + this.loading = false + }, loginSuccess() { this.userInfo = uni.getStorageSync('userInfo') this.getBarInfoFun() @@ -135,21 +143,51 @@ }, // 获取酒吧信息 getBarInfoFun() { + if (!this.isLoggedIn) return getBarInfo().then(res => { - this.barInfo = res.data + if (res.code === 200) { + this.barInfo = res.data + } + }).catch(err => { + console.error('获取酒吧信息失败:', err) + uni.showToast({ + title: '获取酒吧信息失败', + icon: 'none' + }) }) }, // 获取我的扫码数据 getMyScanDataFun() { + if (!this.isLoggedIn) return getMyScanData().then(res => { - this.myScanData = res.data + if (res.code === 200) { + this.myScanData = res.data + } + }).catch(err => { + console.error('获取扫码数据失败:', err) + uni.showToast({ + title: '获取扫码数据失败', + icon: 'none' + }) }) }, + // 页面跳转 toPage(index) { - if (!uni.getStorageSync('token') && index != 5) { + // 添加枝点小助手不需要登录 + if (index === 5) { + uni.navigateTo({ + url: '/pagesMy/addAiad' + }) + return + } + + // 检查登录状态 + if (!this.isLoggedIn) { this.$refs.loginRef.open() return } + + // 已登录状态,执行对应操作 switch (index) { case 1: // 我参与的 uni.switchTab({ @@ -171,11 +209,6 @@ url: '/pagesMy/myAddress' }) break; - case 5: // 添加枝点小助手 - uni.navigateTo({ - url: '/pagesMy/addAiad' - }) - break; case 6: // 意见反馈 uni.navigateTo({ url: '/pagesMy/feedback' @@ -185,24 +218,45 @@ uni.navigateTo({ url: '/pagesMy/setting' }) + break; default: break; } - }, // 退出登录 logout() { + if (!this.isLoggedIn) return + uni.showModal({ title: '提示', content: '确定要退出登录吗?', success: (res) => { if (res.confirm) { - uni.clearStorageSync() + // 清除登录状态 + uni.removeStorageSync('token') + uni.removeStorageSync('userInfo') + this.isLoggedIn = false this.userInfo = null this.barInfo = null + this.myScanData = null + + // 跳转到登录页 + uni.reLaunch({ + url: '/pages/index/chooseLogin' + }) } } }) + }, + // 关闭登录弹窗 + closeLoginPopup() { + this.$refs.loginRef.close() + }, + // 去登录 + toLogin() { + uni.navigateTo({ + url: '/pages/index/registration' + }) } } }