From ec92a8b7ce351bfb069199c84d9397de1ce971bd Mon Sep 17 00:00:00 2001 From: davy Date: Thu, 3 Apr 2025 20:14:11 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=98=E5=8C=96=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E9=A1=B5=E9=9D=A2=EF=BC=8C=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E4=BD=8D=E7=BD=AE=E8=BF=87=E6=BB=A4=E5=92=8C=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E8=BF=87=E6=BB=A4=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=99=BB=E5=BD=95?= =?UTF-8?q?=E5=BC=B9=E7=AA=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/loginPopup.vue | 33 ++- pages/activityList/activityList.vue | 204 ++++++---------- pages/index/my.vue | 100 +++++++- pages/index/registration.vue | 2 +- pages/index/registrationOld.vue | 359 ---------------------------- 5 files changed, 204 insertions(+), 494 deletions(-) delete mode 100644 pages/index/registrationOld.vue diff --git a/components/loginPopup.vue b/components/loginPopup.vue index 15b1044..b88520e 100644 --- a/components/loginPopup.vue +++ b/components/loginPopup.vue @@ -3,6 +3,7 @@ 登录并认证后体验完整功能 @@ -235,6 +236,27 @@ url: '/pages/index/userAgreement' }) }, + async handleLogin() { + try { + const result = await this.$http.post('/api/login', { + code: this.code, + userInfo: this.userInfo + }) + + // 保存登录信息,替换临时token + uni.setStorageSync('token', result.data.token) + uni.setStorageSync('userInfo', result.data.userInfo) + + this.$emit('login-success', result.data) + this.close() + } catch (error) { + console.error('登录失败:', error) + uni.showToast({ + title: '登录失败,请重试', + icon: 'none' + }) + } + } } } @@ -251,7 +273,7 @@ align-items: center; padding: 80rpx 32rpx; border-radius: 24rpx 24rpx 0rpx 0rpx; - + .title { font-family: Roboto; font-size: 28rpx; @@ -259,7 +281,7 @@ color: #030303; margin-bottom: 92rpx; } - + .wx-btn { width: 100%; height: 88rpx; @@ -268,11 +290,16 @@ display: flex; justify-content: center; align-items: center; - // color: #0B0E26; color: #fff; font-size: 28rpx; font-weight: 500; margin-bottom: 46rpx; + + .wx-icon { + width: 40rpx; + height: 40rpx; + margin-right: 16rpx; + } } .phone-btn { diff --git a/pages/activityList/activityList.vue b/pages/activityList/activityList.vue index fb8b45f..85b9843 100644 --- a/pages/activityList/activityList.vue +++ b/pages/activityList/activityList.vue @@ -35,13 +35,18 @@ 活动状态 - 未开始 - 已结束 - 已结束 - 活动停止 - 招募即将结束 - - {{it.remainingDays}}天 + 待审核 + 未通过 + + + 招募进行中 + + {{it.remainingDays}}天 + + + + 活动已结束 + @@ -49,8 +54,8 @@ 时间:首次扫码开始累计 {{it.duration}}天内 目标:全系列酒款累积扫码 ≥ {{ it.activityTarget}}桶 - - + + @@ -94,61 +99,75 @@ }, total: 0, isFilterActive: false, - userLocation: null, - isLocationReady: false, // 位置信息是否已获取 - originalList: [], // 存储未经位置筛选的列表 selectedBrand: null, // 选中的品牌ID }; }, onLoad() { - // 先获取活动列表 + // 获取活动列表 this.getActivitiesFun(); - // 同时异步获取位置信息 - this.getUserLocation(); }, methods: { - // 获取用户位置 - getUserLocation() { - uni.getLocation({ - type: 'gcj02', - success: (res) => { - this.userLocation = { - latitude: res.latitude, - longitude: res.longitude - }; - this.isLocationReady = true; - // 位置信息获取成功后,重新筛选列表 - this.filterListByLocation(); - }, - fail: (err) => { - console.error('获取位置失败:', err); - this.isLocationReady = true; - uni.showToast({ - title: '未获取到位置信息,将显示所有活动', - icon: 'none', - duration: 2000 + // 获取活动列表 + getActivitiesFun() { + this.loading = true; + + const params = { + pageNum: this.queryForm.pageNum, + pageSize: this.queryForm.pageSize + }; + + // 添加品牌筛选 + if (this.selectedBrand) { + params.breweryId = this.selectedBrand; + } else { + // 只有在没有品牌筛选时,才应用排序 + params.orderBy = this.queryForm.orderType === 'latest' ? 'start_date' : 'popularity'; + params.order = 'desc'; + } + + getActivities(params).then(res => { + console.log('获取到的原始数据:', res); + this.total = res.total; + if(res.rows && res.rows.length > 0) { + let arr = res.rows.map(it => { + it.remainingDays = this.getRemainingDays(it.endDate); + return it; }); + + console.log('处理后的数据:', arr); + + // 如果有品牌筛选,确保只显示选中品牌的活动 + if (this.selectedBrand) { + arr = arr.filter(item => item.breweryId === this.selectedBrand); + } + + console.log('最终显示的数据:', arr); + + // 更新显示列表 + if (this.queryForm.pageNum === 1) { + this.activeList = arr; + } else { + this.activeList = [...this.activeList, ...arr]; + } + } else { + if (this.queryForm.pageNum === 1) { + this.activeList = []; + } } + this.loading = false; + }).catch(err => { + console.error('获取活动列表失败:', err); + this.loading = false; }); }, - // 根据位置信息筛选列表 - filterListByLocation() { - if (this.originalList.length > 0) { - this.activeList = this.originalList.filter(item => this.isActivityInUserCity(item.city)); - } - }, - - // 检查活动是否在用户所在城市 - isActivityInUserCity(activityCity) { - if (!this.userLocation) return false; - try { - const cityList = JSON.parse(activityCity); - // 这里需要和获取到的用户城市信息进行比对 - return true; // 临时返回true,需要实际实现 - } catch (e) { - return false; - } + // 计算剩余天数 + getRemainingDays(date) { + const targetDate = new Date(date); + const currentDate = new Date(); + const timeDiff = targetDate.getTime() - currentDate.getTime(); + const remainingDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); + return remainingDays; }, // 切换排序 @@ -184,92 +203,27 @@ // 跳转酒评 toReview(it) { + const token = uni.getStorageSync('token') + if (!token) { + this.$refs.loginRef.show() + return + } uni.navigateTo({ url: "/pages/index/review?beerId=" + it.id }); }, - // 获取活动列表 - getActivitiesFun() { - this.loading = true; - - const params = { - pageNum: this.queryForm.pageNum, - pageSize: this.queryForm.pageSize - }; - - // 添加品牌筛选 - if (this.selectedBrand) { - params.breweryId = this.selectedBrand; - } else { - // 只有在没有品牌筛选时,才应用排序 - params.orderBy = this.queryForm.orderType === 'latest' ? 'start_date' : 'popularity'; - params.order = 'desc'; - } - - getActivities(params).then(res => { - this.total = res.total; - if(res.rows && res.rows.length > 0) { - let arr = res.rows.map(it => { - it.remainingDays = this.getRemainingDays(it.endDate); - return it; - }); - - // 过滤活动状态:不显示已结束(2,3)、活动停止(4)、未开始(0)的活动 - arr = arr.filter(item => item.stage === 1); - - // 如果有品牌筛选,确保只显示选中品牌的活动 - if (this.selectedBrand) { - arr = arr.filter(item => item.breweryId === this.selectedBrand); - } - - // 保存未经位置筛选的列表 - this.originalList = arr; - - // 如果位置信息已准备好,进行位置筛选 - if (this.isLocationReady && this.userLocation) { - arr = arr.filter(item => this.isActivityInUserCity(item.city)); - } - - // 更新显示列表 - if (this.queryForm.pageNum === 1) { - this.activeList = arr; - } else { - this.activeList = [...this.activeList, ...arr]; - } - } else { - if (this.queryForm.pageNum === 1) { - this.activeList = []; - this.originalList = []; - } - } - this.loading = false; - }).catch(err => { - console.error('获取活动列表失败:', err); - this.loading = false; - }); - }, - - // 计算剩余天数 - getRemainingDays(date) { - const targetDate = new Date(date); - const currentDate = new Date(); - const timeDiff = targetDate.getTime() - currentDate.getTime(); - const remainingDays = Math.ceil(timeDiff / (1000 * 3600 * 24)); - return remainingDays; - }, - // 显示品牌筛选 showBrandFilter() { // 如果还没有数据,先获取数据 - if (!this.originalList || this.originalList.length === 0) { + if (!this.activeList || this.activeList.length === 0) { this.queryForm.pageNum = 1; this.getActivitiesFun().then(() => { - this.$refs.brandFilterRef.extractBrandsFromList(this.originalList); + this.$refs.brandFilterRef.extractBrandsFromList(this.activeList); this.$refs.brandFilterRef.open(); }); } else { - this.$refs.brandFilterRef.extractBrandsFromList(this.originalList); + this.$refs.brandFilterRef.extractBrandsFromList(this.activeList); this.$refs.brandFilterRef.open(); } }, diff --git a/pages/index/my.vue b/pages/index/my.vue index 028986f..c6e2907 100644 --- a/pages/index/my.vue +++ b/pages/index/my.vue @@ -12,17 +12,18 @@ 店铺ID:{{ barInfo.barNumber || '-' }} - + - 未认证 + 未认证 + 认证中 {{ barInfo.authEndTime }}认证到期 本月累计扫码酒款数量 @@ -117,6 +118,28 @@ statusBaeHeight: 40 }; }, + computed: { + // 用户状态 + userStatus() { + if (!this.isLoggedIn) return 'guest' // 游客 + if (!this.barInfo || this.barInfo.authState === 0) return 'unverified' // 未认证 + if (this.barInfo.authState === 1) return 'verifying' // 认证中 + return 'verified' // 认证通过 + }, + // 登录/认证文字 + loginText() { + switch (this.userStatus) { + case 'guest': + return '登录/认证' + case 'unverified': + return '您的门店还未认证,请点击认证门店信息' + case 'verifying': + return '您的门店正在认证中,请耐心等待' + default: + return '登录/认证' + } + } + }, onLoad() { this.statusBaeHeight = uni.getWindowInfo.statusBarHeight }, @@ -128,12 +151,33 @@ } }, methods: { + // 生成临时token + generateTempToken() { + const tempToken = 'temp_' + Math.random().toString(36).substr(2, 9) + '_' + Date.now() + return tempToken + }, + // 检查登录状态 checkLoginStatus() { const token = uni.getStorageSync('token') const userInfo = uni.getStorageSync('userInfo') - this.isLoggedIn = !!(token && userInfo) - this.userInfo = userInfo + + if (!token) { + // 如果没有token,生成临时token + const tempToken = this.generateTempToken() + uni.setStorageSync('token', tempToken) + this.isLoggedIn = false + this.userInfo = null + } else if (token.startsWith('temp_')) { + // 如果是临时token,说明是游客 + this.isLoggedIn = false + this.userInfo = null + } else { + // 正式token,说明已登录 + this.isLoggedIn = true + this.userInfo = userInfo + } + this.loading = false }, loginSuccess() { @@ -171,6 +215,27 @@ }) }) }, + // 处理用户信息区域点击 + handleUserBoxClick() { + switch (this.userStatus) { + case 'guest': + this.$refs.loginRef.open() + break + case 'unverified': + uni.navigateTo({ + url: '/pages/index/registration' + }) + break + case 'verifying': + uni.showToast({ + title: '您的门店正在认证中,请耐心等待', + icon: 'none' + }) + break + default: + break + } + }, // 页面跳转 toPage(index) { // 添加枝点小助手不需要登录 @@ -187,7 +252,30 @@ return } - // 已登录状态,执行对应操作 + // 检查认证状态 + if (this.userStatus === 'unverified') { + uni.navigateTo({ + url: '/pages/index/registration' + }) + return + } + + // 认证中状态只能查看部分功能 + if (this.userStatus === 'verifying') { + if (index === 6) { // 意见反馈 + uni.navigateTo({ + url: '/pagesMy/feedback' + }) + return + } + uni.showToast({ + title: '您的门店正在认证中,请耐心等待', + icon: 'none' + }) + return + } + + // 已认证状态可以访问所有功能 switch (index) { case 1: // 我参与的 uni.switchTab({ diff --git a/pages/index/registration.vue b/pages/index/registration.vue index 33a3119..0c99eb9 100644 --- a/pages/index/registration.vue +++ b/pages/index/registration.vue @@ -168,7 +168,7 @@ :disabled="!isFormValid" @click="submitForm" > - 提交入驻 + 提交认证 diff --git a/pages/index/registrationOld.vue b/pages/index/registrationOld.vue deleted file mode 100644 index 975baab..0000000 --- a/pages/index/registrationOld.vue +++ /dev/null @@ -1,359 +0,0 @@ - - - - - \ No newline at end of file