Showing
3 changed files
with
68 additions
and
13 deletions
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-26 23:52:36 | 3 | * @Date: 2022-05-26 23:52:36 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2024-09-19 10:49:04 | 5 | + * @LastEditTime: 2024-12-20 17:08:45 |
| 6 | * @FilePath: /data-table/src/App.vue | 6 | * @FilePath: /data-table/src/App.vue |
| 7 | * @Description: | 7 | * @Description: |
| 8 | --> | 8 | --> |
| ... | @@ -22,7 +22,7 @@ import vConsole from "@/utils/vconsole"; | ... | @@ -22,7 +22,7 @@ import vConsole from "@/utils/vconsole"; |
| 22 | import wx from 'weixin-js-sdk' | 22 | import wx from 'weixin-js-sdk' |
| 23 | import { wxJsAPI } from '@/api/wx/config' | 23 | import { wxJsAPI } from '@/api/wx/config' |
| 24 | import { apiList } from '@/api/wx/jsApiList.js' | 24 | import { apiList } from '@/api/wx/jsApiList.js' |
| 25 | -import { wxInfo, getUrlParams, stringifyQuery } from "@/utils/tools"; | 25 | +import { wxInfo, getUrlParams, stringifyQuery, isWithinRadius } from "@/utils/tools"; |
| 26 | import { styleColor } from "@/constant.js"; | 26 | import { styleColor } from "@/constant.js"; |
| 27 | import { getFormSettingAPI } from "@/api/form.js"; | 27 | import { getFormSettingAPI } from "@/api/form.js"; |
| 28 | import { showDialog, showConfirmDialog } from 'vant'; | 28 | import { showDialog, showConfirmDialog } from 'vant'; |
| ... | @@ -162,6 +162,28 @@ onMounted(async () => { | ... | @@ -162,6 +162,28 @@ onMounted(async () => { |
| 162 | wx.config(wxJs.data); | 162 | wx.config(wxJs.data); |
| 163 | wx.ready(() => { | 163 | wx.ready(() => { |
| 164 | wx.showAllNonBaseMenuItem(); | 164 | wx.showAllNonBaseMenuItem(); |
| 165 | + // TEST:判断定位填表功能 | ||
| 166 | + let open_location = false; | ||
| 167 | + const targetLat = 31.278001; | ||
| 168 | + const targetLng = 121.542778; | ||
| 169 | + const radius = 1000; // 半径 1000 米 | ||
| 170 | + if (force_back !== '1' && open_location) { // 非后台用户模式 | ||
| 171 | + wx.getLocation({ | ||
| 172 | + type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02' | ||
| 173 | + success: function (res) { | ||
| 174 | + let currentLat = res.latitude; // 纬度,浮点数,范围为90 ~ -90 | ||
| 175 | + let currentLng = res.longitude; // 经度,浮点数,范围为180 ~ -180。 | ||
| 176 | + let is_in = isWithinRadius(currentLat, currentLng, targetLat, targetLng, radius); | ||
| 177 | + if (!is_in) { | ||
| 178 | + // 表单定位错误 | ||
| 179 | + $router.push("/stop?status=location_error"); | ||
| 180 | + } | ||
| 181 | + }, | ||
| 182 | + fail: function (res) { | ||
| 183 | + $router.push("/stop?status=get_location_fail"); | ||
| 184 | + }, | ||
| 185 | + }); | ||
| 186 | + } | ||
| 165 | }); | 187 | }); |
| 166 | wx.error((err) => { | 188 | wx.error((err) => { |
| 167 | console.warn(err); | 189 | console.warn(err); | ... | ... |
| 1 | /* | 1 | /* |
| 2 | * @Date: 2024-07-31 17:19:25 | 2 | * @Date: 2024-07-31 17:19:25 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2024-09-05 17:08:08 | 4 | + * @LastEditTime: 2024-12-20 16:09:42 |
| 5 | - * @FilePath: /data-table/src/utils/tools.js | ||
| 6 | - * @Description: 文件描述 | ||
| 7 | - */ | ||
| 8 | -/* | ||
| 9 | - * @Date: 2022-04-18 15:59:42 | ||
| 10 | - * @LastEditors: hookehuyr hookehuyr@gmail.com | ||
| 11 | - * @LastEditTime: 2023-02-24 16:13:06 | ||
| 12 | * @FilePath: /data-table/src/utils/tools.js | 5 | * @FilePath: /data-table/src/utils/tools.js |
| 13 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 14 | */ | 7 | */ |
| ... | @@ -195,6 +188,43 @@ const isInViewport = (el) => { // 判断元素是否在可视区域 | ... | @@ -195,6 +188,43 @@ const isInViewport = (el) => { // 判断元素是否在可视区域 |
| 195 | ); | 188 | ); |
| 196 | }; | 189 | }; |
| 197 | 190 | ||
| 191 | +/** | ||
| 192 | + * 判断当前经纬度是否在目标经纬度的范围内 | ||
| 193 | + * @param {number} currentLat - 当前纬度 | ||
| 194 | + * @param {number} currentLng - 当前经度 | ||
| 195 | + * @param {number} targetLat - 目标纬度 | ||
| 196 | + * @param {number} targetLng - 目标经度 | ||
| 197 | + * @param {number} radius - 半径(单位:米) | ||
| 198 | + * @returns {boolean} 是否在范围内 | ||
| 199 | + */ | ||
| 200 | +const isWithinRadius = (currentLat, currentLng, targetLat, targetLng, radius) => { | ||
| 201 | + const EARTH_RADIUS = 6371000; // 地球半径(单位:米) | ||
| 202 | + | ||
| 203 | + // 将角度转换为弧度 | ||
| 204 | + const toRadians = (degrees) => (degrees * Math.PI) / 180; | ||
| 205 | + | ||
| 206 | + // 当前点和目标点的纬度差和经度差 | ||
| 207 | + const deltaLat = toRadians(targetLat - currentLat); | ||
| 208 | + const deltaLng = toRadians(targetLng - currentLng); | ||
| 209 | + | ||
| 210 | + // 转换为弧度 | ||
| 211 | + const radCurrentLat = toRadians(currentLat); | ||
| 212 | + const radTargetLat = toRadians(targetLat); | ||
| 213 | + | ||
| 214 | + // Haversine 公式计算两点间的距离 | ||
| 215 | + const a = | ||
| 216 | + Math.sin(deltaLat / 2) * Math.sin(deltaLat / 2) + | ||
| 217 | + Math.cos(radCurrentLat) * | ||
| 218 | + Math.cos(radTargetLat) * | ||
| 219 | + Math.sin(deltaLng / 2) * | ||
| 220 | + Math.sin(deltaLng / 2); | ||
| 221 | + const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | ||
| 222 | + const distance = EARTH_RADIUS * c; | ||
| 223 | + | ||
| 224 | + // 判断距离是否在范围内 | ||
| 225 | + return distance <= radius; | ||
| 226 | +} | ||
| 227 | + | ||
| 198 | export { | 228 | export { |
| 199 | formatDate, | 229 | formatDate, |
| 200 | wxInfo, | 230 | wxInfo, |
| ... | @@ -206,4 +236,5 @@ export { | ... | @@ -206,4 +236,5 @@ export { |
| 206 | stringifyQuery, | 236 | stringifyQuery, |
| 207 | prettyLog, | 237 | prettyLog, |
| 208 | isInViewport, | 238 | isInViewport, |
| 239 | + isWithinRadius, | ||
| 209 | }; | 240 | }; | ... | ... |
| 1 | <!-- | 1 | <!-- |
| 2 | * @Date: 2022-06-29 18:18:02 | 2 | * @Date: 2022-06-29 18:18:02 |
| 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 3 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 4 | - * @LastEditTime: 2022-06-29 18:18:09 | 4 | + * @LastEditTime: 2024-12-20 17:07:15 |
| 5 | - * @FilePath: /tswj/src/views/test/404.vue | 5 | + * @FilePath: /data-table/src/views/stop.vue |
| 6 | * @Description: 文件描述 | 6 | * @Description: 文件描述 |
| 7 | --> | 7 | --> |
| 8 | <template> | 8 | <template> |
| ... | @@ -19,6 +19,8 @@ | ... | @@ -19,6 +19,8 @@ |
| 19 | <span v-if="status === 'apply'">表单未开始</span> | 19 | <span v-if="status === 'apply'">表单未开始</span> |
| 20 | <span v-if="status === 'finish'">表单已结束</span> | 20 | <span v-if="status === 'finish'">表单已结束</span> |
| 21 | <span v-if="status === 'disable'">表单已关闭</span> | 21 | <span v-if="status === 'disable'">表单已关闭</span> |
| 22 | + <span v-if="status === 'get_location_fail'">表单获取定位授权失败</span> | ||
| 23 | + <span v-if="status === 'location_error'">未在指定位置提交,请确认后重试</span> | ||
| 22 | </p> | 24 | </p> |
| 23 | <!-- <p style="font-size: 0.9rem; margin-bottom: 0.5rem">您的作品正在审核中</p> --> | 25 | <!-- <p style="font-size: 0.9rem; margin-bottom: 0.5rem">您的作品正在审核中</p> --> |
| 24 | <!-- <p style="font-size: 0.9rem">请耐心等待~~</p> --> | 26 | <!-- <p style="font-size: 0.9rem">请耐心等待~~</p> --> |
| ... | @@ -34,7 +36,7 @@ import { ref } from "vue"; | ... | @@ -34,7 +36,7 @@ import { ref } from "vue"; |
| 34 | import { useRoute, useRouter } from "vue-router"; | 36 | import { useRoute, useRouter } from "vue-router"; |
| 35 | import { styleColor } from "@/constant.js"; | 37 | import { styleColor } from "@/constant.js"; |
| 36 | import icon_success from "@images/que-sucess@2x.png"; | 38 | import icon_success from "@images/que-sucess@2x.png"; |
| 37 | - | 39 | +import wx from 'weixin-js-sdk' |
| 38 | import { | 40 | import { |
| 39 | Cookies, | 41 | Cookies, |
| 40 | $, | 42 | $, | ... | ... |
-
Please register or login to post a comment