From d74f295e5b54d98b6940dc98bf2ac280975642d3 Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Tue, 25 Mar 2025 17:35:38 +0800 Subject: [PATCH] =?UTF-8?q?feat(student):=20=E4=BD=93=E8=82=B2=E9=A6=86?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=8A=9F=E8=83=BD-=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E4=BD=93=E8=82=B2=E9=A6=86=E5=88=97=E8=A1=A8=E6=8E=A5=E5=8F=A3?= =?UTF-8?q?=E5=92=8C=E7=9B=B8=E5=85=B3=E9=A1=B5=E9=9D=A2=20-=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=94=A8=E6=88=B7=E5=AE=9A=E4=BD=8D=E5=92=8C=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E8=B7=9D=E7=A6=BB=E5=8A=9F=E8=83=BD=20-=20=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E5=88=97=E8=A1=A8=E5=B1=95=E7=A4=BA=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=B7=9D=E7=A6=BB=E6=98=BE=E7=A4=BA=20-=20=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E8=B7=B3=E8=BD=AC=E5=88=B0=E8=AF=BE=E7=A8=8B=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=9A=84=E5=8A=9F=E8=83=BD=20-=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=B0=8F=E7=A8=8B=E5=BA=8F=E9=85=8D=E7=BD=AE=EF=BC=8C=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E5=AE=9A=E4=BD=8D=E6=9D=83=E9=99=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/member.js | 8 ++ manifest.json | 7 +- pages/student/timetable/index.vue | 6 +- pages/student/timetable/list.vue | 230 ++++++++++++++---------------- 4 files changed, 123 insertions(+), 128 deletions(-) diff --git a/api/member.js b/api/member.js index a839115..66a6815 100644 --- a/api/member.js +++ b/api/member.js @@ -67,6 +67,14 @@ export default { }) }, + //场地列表 + venuesList(data) { + let url = '/member/venues_list' + return http.get(url, data).then(res => { + return res; + }) + }, + } \ No newline at end of file diff --git a/manifest.json b/manifest.json index f835c56..010b722 100644 --- a/manifest.json +++ b/manifest.json @@ -62,7 +62,7 @@ "quickapp" : {}, /* 小程序特有相关 */ "mp-weixin" : { - "appid" : "wx42762c713f7bfa2e", + "appid" : "wx675f2696abf932c5", "setting" : { "urlCheck" : false, "minified" : true, @@ -74,7 +74,10 @@ "desc" : "你的位置信息将用于小程序位置接口的效果展示" } }, - "requiredPrivateInfos" : [ "getFuzzyLocation" ] + "requiredPrivateInfos": [ + "getLocation", + "chooseLocation" + ] }, "mp-alipay" : { "usingComponents" : true diff --git a/pages/student/timetable/index.vue b/pages/student/timetable/index.vue index 91d83cf..c8cf0bd 100644 --- a/pages/student/timetable/index.vue +++ b/pages/student/timetable/index.vue @@ -110,7 +110,7 @@ export default { //今日日期 today: '', - dateList: []//日期列表 + dateList: [],//日期列表 } }, onLoad(options) { @@ -248,8 +248,10 @@ export default { }, //体育馆列表 more() { + let schedule_date = this.filteredData.schedule_date + let venue_id = this.venuesInfo.id//当前场馆id uni.navigateTo({ - url: '/pages/student/timetable/list' + url: `/pages/student/timetable/list?schedule_date=${schedule_date}&venue_id=${venue_id}` }) } } diff --git a/pages/student/timetable/list.vue b/pages/student/timetable/list.vue index c0b5886..04f1228 100644 --- a/pages/student/timetable/list.vue +++ b/pages/student/timetable/list.vue @@ -4,122 +4,18 @@ - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - + + {{v.name}} + {{v.address}} + 无法获取定位 + 距您{{v.distance}}km + 当前场馆 - - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - - 当前场馆 - - - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - - 当前场馆 - - - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - - 当前场馆 - - - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - - 当前场馆 - - - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - - 当前场馆 - - - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - - 当前场馆 - - - - XXX体育馆 - 南山区科苑路15号科兴科学园 - 距您1km - - 当前场馆 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -140,29 +36,92 @@ //筛选条件 filteredData:{ - page:1,//当前页码 - limit:10,//每页返回数据条数 - total:10,//数据总条数 + // page:1,//当前页码 + // limit:10,//每页返回数据条数 + // total:10,//数据总条数 + schedule_date:'',//日期 }, tableList:[],//表格数据 + longitude:'',//当前用户经度 + latitude:'',//当前用户纬度 + venue_id:'',//当前场馆id } }, - onLoad() {}, + onLoad(options) { + this.filteredData.schedule_date = options.schedule_date//日期 + //场馆id + this.venue_id = options.venue_id || '' + }, onShow() { this.init()//初始化 }, - - methods: { //初始化 async init() { - await this.getList() + await this.getUserLocation(); + await this.getList(); + }, + + + // 获取用户当前位置(支持多端) + async getUserLocation() { + try { + const location = await this.getLocation(); + this.longitude = location.longitude; + this.latitude = location.latitude; + } catch (error) { + console.log(error); + uni.showToast({ + title: '获取位置失败', + icon: 'none' + }); + // throw error; // 重新抛出错误,以便在 init 方法中捕获 + } + }, + + // 封装 uni.getLocation 为一个返回 Promise 的函数 + getLocation() { + return new Promise((resolve, reject) => { + uni.getLocation({ + type: 'wgs84', + success: (res) => { + console.log('当前位置的经度:' + res.longitude); + console.log('当前位置的纬度:' + res.latitude); + resolve(res); + }, + fail: (err) => { + console.log(err); + reject(err); + } + }); + }); + }, + + //计算距离 + getDistance(lat1, lng1, lat2, lng2) { + const R = 6371; // 地球半径,单位为公里 + const dLat = this.deg2rad(lat2 - lat1); + const dLon = this.deg2rad(lng2 - lng1); + const a = + Math.sin(dLat / 2) * Math.sin(dLat / 2) + + Math.cos(this.deg2rad(lat1)) * Math.cos(this.deg2rad(lat2)) * + Math.sin(dLon / 2) * Math.sin(dLon / 2); + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); + const distance = R * c; // 距离,单位为公里 + + return distance.toFixed(2); // 保留两位小数 + }, + // 将角度转换为弧度 + deg2rad(deg) { + return deg * (Math.PI / 180); }, - //加载更过(下一页) + + //加载更多(下一页) loadMoreData() { + return //本页面无需下一页 //判断是否加载 if (!this.isReachedBottom) { this.isReachedBottom = true;//设置为不可请求状态 @@ -176,7 +135,7 @@ }, 1000); }, - //获取列表 + //获取场地列表 async getList(){ this.loading = true @@ -192,7 +151,7 @@ return } - let res = await memberApi.courseList(data) + let res = await memberApi.venuesList(data) this.loading = false this.isReachedBottom = false; if (res.code != 1){ @@ -203,11 +162,34 @@ return } - this.tableList = res.data.data + this.tableList = res.data + + + + this.tableList.forEach((v,k)=>{ + if(this.longitude && this.latitude && v.longitude && v.latitude){ + v.distance = this.getDistance(this.latitude, this.longitude, v.latitude, v.longitude) + }else{ + v.distance = null + } + }) + + console.log('列表',this.tableList) + + + + - this.total = res.data.total - this.page++ }, + + //跳转页面-课程列表 + opebViewTimetable(item) { + let venue_id = item.id + uni.navigateTo({ + url: `/pages/student/timetable/index?venue_id=${venue_id}` + }) + }, + } }