From 4466afd8a1b6079309ecb2b5ccc0d6afae7f8ec5 Mon Sep 17 00:00:00 2001 From: davy Date: Thu, 3 Apr 2025 02:20:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=EF=BC=9A=E6=9B=B4=E5=A4=9A?= =?UTF-8?q?=E6=B4=BB=E5=8A=A8=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=EF=BC=8C=E7=AD=9B=E9=80=89=E9=80=BB=E8=BE=91=EF=BC=8C=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E9=A1=B5=E9=9D=A2=E7=9A=84=E6=B8=B8=E5=AE=A2=E6=9D=83?= =?UTF-8?q?=E9=99=90=E5=88=A4=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/request.js | 13 +- components/brandFilter.vue | 244 ++++++++++++++++++++++++++++ pages.json | 10 +- pages/activityList/activityList.vue | 181 ++++++++++++++++----- pages/index/index.vue | 65 +------- pages/index/review.vue | 41 +++-- pagesActivity/winelist.vue | 25 +++ 7 files changed, 465 insertions(+), 114 deletions(-) create mode 100644 components/brandFilter.vue diff --git a/api/request.js b/api/request.js index e44f4cf..c75cebb 100644 --- a/api/request.js +++ b/api/request.js @@ -19,11 +19,22 @@ const publicApis = [ '/bar/brewery/getBeerInfo', // 获取酒款信息 '/bar/brewery/getReviewList', // 获取酒评列表 '/bar/brewery/getReviewScoreList', // 获取酒评评分列表 + '/bar/brewery/getActivities', // 获取活动列表 + '/bar/brewery/getActivityInfo', // 获取活动详情 + '/bar/brewery/getBreweryInfo', // 获取品牌详情 ] // 检查是否是公开API const isPublicApi = (url) => { - return publicApis.some(api => url.includes(api)) + // 使用更精确的匹配方式 + return publicApis.some(api => { + // 如果是完整路径匹配 + if (api.includes('/')) { + return url.includes(api); + } + // 如果是通配符匹配 + return url.split('/').includes(api); + }); } export default (params) => { diff --git a/components/brandFilter.vue b/components/brandFilter.vue new file mode 100644 index 0000000..578ac60 --- /dev/null +++ b/components/brandFilter.vue @@ -0,0 +1,244 @@ + + + + + \ No newline at end of file diff --git a/pages.json b/pages.json index 7bb30c5..1ebbdb8 100644 --- a/pages.json +++ b/pages.json @@ -406,6 +406,12 @@ "network": "all", "packages": ["pagesActivity","pagesCoin","pagesMy"] } - } - + }, + "easycom": { + "autoscan": true, + "custom": { + "^u-(.*)": "uview-ui/components/u-$1/u-$1.vue", + "^brand-filter": "@/components/brandFilter.vue" + } + } } diff --git a/pages/activityList/activityList.vue b/pages/activityList/activityList.vue index 9f89bbd..fb8b45f 100644 --- a/pages/activityList/activityList.vue +++ b/pages/activityList/activityList.vue @@ -6,15 +6,15 @@ 最新发布 人气排名 - + 筛选品牌 @@ -64,6 +64,8 @@ + + @@ -72,36 +74,96 @@ import { getActivities } from '@/api/bar.js' - import loginPopup from '@/components/loginPopup.vue'; + import loginPopup from '@/components/loginPopup.vue' + import brandFilter from '@/components/brandFilter.vue' + export default { components: { - loginPopup + loginPopup, + brandFilter }, data() { return { activeList: [], // 活动列表 loading: false, - isRefreshing: false, // 添加下拉刷新状态 + isRefreshing: false, queryForm: { pageNum: 1, pageSize: 5, - orderBy: 'create_time' // 默认最新发布 + orderType: 'latest', }, total: 0, - isFilterActive: false // 筛选按钮激活状态 + isFilterActive: false, + userLocation: null, + isLocationReady: false, // 位置信息是否已获取 + originalList: [], // 存储未经位置筛选的列表 + selectedBrand: null, // 选中的品牌ID }; }, onLoad() { - // 页面加载时获取活动列表,默认最新发布 - this.getActivitiesFun() + // 先获取活动列表 + 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 + }); + } + }); + }, + + // 根据位置信息筛选列表 + 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; + } + }, + // 切换排序 - changeOrder(key) { - if (this.queryForm.orderBy === key) return; - this.queryForm.orderBy = key; + changeOrder(type) { + // 如果点击当前激活的排序方式,不做处理 + if (this.queryForm.orderType === type) return; + + // 切换排序方式 + this.queryForm.orderType = type; + + // 重置分页 this.queryForm.pageNum = 1; this.activeList = []; + + // 重新获取数据 this.getActivitiesFun(); }, @@ -115,35 +177,75 @@ // 跳转详情 toDetail(item) { - if (!uni.getStorageSync('token')) { - this.$refs.loginRef.open() - return - } uni.navigateTo({ url: "/pagesActivity/activityDetail?id=" + item.id - }) + }); + }, + + // 跳转酒评 + toReview(it) { + uni.navigateTo({ + url: "/pages/index/review?beerId=" + it.id + }); }, // 获取活动列表 getActivitiesFun() { this.loading = true; - getActivities(this.queryForm).then(res => { + + 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; }); }, @@ -159,8 +261,25 @@ // 显示品牌筛选 showBrandFilter() { - this.isFilterActive = !this.isFilterActive; - // 其他筛选逻辑 + // 如果还没有数据,先获取数据 + if (!this.originalList || this.originalList.length === 0) { + this.queryForm.pageNum = 1; + this.getActivitiesFun().then(() => { + this.$refs.brandFilterRef.extractBrandsFromList(this.originalList); + this.$refs.brandFilterRef.open(); + }); + } else { + this.$refs.brandFilterRef.extractBrandsFromList(this.originalList); + this.$refs.brandFilterRef.open(); + } + }, + + // 品牌筛选确认 + onBrandFilterConfirm(result) { + this.selectedBrand = result.id; + this.queryForm.pageNum = 1; + this.activeList = []; + this.getActivitiesFun(); }, // 添加下拉刷新方法 @@ -171,19 +290,7 @@ this.activeList = []; // 重新获取数据 - getActivities(this.queryForm).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; - }); - this.activeList = arr; - } - this.isRefreshing = false; - }).catch(err => { - this.isRefreshing = false; - }); + this.getActivitiesFun(); } } } diff --git a/pages/index/index.vue b/pages/index/index.vue index fa66c64..05abcc8 100644 --- a/pages/index/index.vue +++ b/pages/index/index.vue @@ -110,7 +110,7 @@ - + 更多热门活动招募 @@ -296,10 +296,6 @@ }) }, toGo(key) { - // 检查登录状态 - const token = uni.getStorageSync('token') - const userInfo = uni.getStorageSync('userInfo') - switch (key) { case 1: // 新酒上市 uni.navigateTo({ @@ -307,80 +303,29 @@ }) break; case 2: // 生成酒单 - if (!token || !userInfo) { - this.$refs.loginRef.open() - return - } - if (!userInfo.barId) { - uni.showModal({ - title: '提示', - content: '您还未认证门店,请先完成认证', - showCancel: true, - success: (res) => { - if (res.confirm) { - uni.navigateTo({ - url: '/pages/index/registration' - }) - } - } - }) - return - } uni.navigateTo({ url: "/pagesActivity/winelist" }) break; case 3: //酒币换购 - if (!token || !userInfo) { - this.$refs.loginRef.open() - return - } - if (!userInfo.barId) { - uni.showModal({ - title: '提示', - content: '您还未认证门店,请先完成认证', - showCancel: true, - success: (res) => { - if (res.confirm) { - uni.navigateTo({ - url: '/pages/index/registration' - }) - } - } - }) - return - } uni.navigateTo({ url: "/pagesCoin/beerCoin" }) break; case 4: // 关注酒厂 - if (!token || !userInfo) { + const token = uni.getStorageSync('token') + if (!token) { this.$refs.loginRef.open() return } - if (!userInfo.barId) { - uni.showModal({ - title: '提示', - content: '您还未认证门店,请先完成认证', - showCancel: true, - success: (res) => { - if (res.confirm) { - uni.navigateTo({ - url: '/pages/index/registration' - }) - } - } - }) - return - } uni.navigateTo({ url: '/pagesMy/myAttention' }) break; } }, - moreClick() { + // 更多热门活动 + moreHotActivity() { uni.navigateTo({ url: "/pages/activityList/activityList" }) diff --git a/pages/index/review.vue b/pages/index/review.vue index a8d829b..6d7fee7 100644 --- a/pages/index/review.vue +++ b/pages/index/review.vue @@ -267,13 +267,15 @@ isFavor: false, // 是否收藏 }; }, - onLoad({ - beerId - }) { + onLoad({beerId}) { this.beerId = beerId this.queryForm.beerId = beerId this.getBeerInfoFun() - this.getBeerFavorStatusFun() // 收藏状态 + // 只在登录状态下获取收藏状态 + const token = uni.getStorageSync('token') + if (token) { + this.getBeerFavorStatusFun() + } }, onShow() { console.log('show') @@ -281,7 +283,9 @@ this.queryForm.pageNum = 1 this.getReviewListFun() this.getReviewScoreListFun() - if (uni.getStorageSync('token')) { + // 只在登录状态下获取我的酒评信息 + const token = uni.getStorageSync('token') + if (token) { this.getMyReviewInfoFun() } // 滚动到最顶 @@ -298,6 +302,11 @@ }, // 查询酒款收藏状态 getBeerFavorStatusFun() { + const token = uni.getStorageSync('token') + if (!token) { + this.$refs.loginRef.open() + return + } getBeerFavorStatus(this.beerId).then(res => { if(res.data) { this.isFavor = true @@ -349,13 +358,19 @@ }, // 获取我的酒评信息 getMyReviewInfoFun() { + const token = uni.getStorageSync('token') + if (!token) { + this.$refs.loginRef.open() + return + } getMyReviewInfo(this.beerId).then(res => { this.myReviewInfo = res.data }) }, // 写酒评 toWrite() { - if (!uni.getStorageSync('token')) { + const token = uni.getStorageSync('token') + if (!token) { this.$refs.loginRef.open() return } @@ -378,7 +393,8 @@ }, // 收藏酒款 favorBeerFun(status) { - if (!uni.getStorageSync('token')) { + const token = uni.getStorageSync('token') + if (!token) { this.$refs.loginRef.open() return } @@ -403,7 +419,8 @@ }, // 点赞 handleLike(item) { - if (!uni.getStorageSync('token')) { + const token = uni.getStorageSync('token') + if (!token) { this.$refs.loginRef.open() return } @@ -425,16 +442,12 @@ }) item.reviewLike = false } - - // this.reviewList = [] - // this.queryForm.pageNum = 1 - // this.getReviewListFun() }) - }, // 生成酒单 toWinelist() { - if (!uni.getStorageSync('token')) { + const token = uni.getStorageSync('token') + if (!token) { this.$refs.loginRef.open() return } diff --git a/pagesActivity/winelist.vue b/pagesActivity/winelist.vue index e67ab33..0f2c07d 100644 --- a/pagesActivity/winelist.vue +++ b/pagesActivity/winelist.vue @@ -216,6 +216,31 @@ return } + // 检查登录和认证状态 + const token = uni.getStorageSync('token') + const isAuth = uni.getStorageSync('isAuth') + + if (!token) { + this.$refs.loginRef.open() + return + } + + if (!isAuth) { + uni.showModal({ + title: '提示', + content: '您还未认证门店,请先完成认证', + confirmText: '去认证', + success: (res) => { + if (res.confirm) { + uni.navigateTo({ + url: '/pagesActivity/barAuth' + }) + } + } + }) + return + } + if (this.currentStep < 3) { this.currentStep++ }