Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2024-12-20 17:11:14 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
8776338ff2cc3ab0a5f493a3f5b8c2df7bff9005
8776338f
1 parent
ad7ac83d
✨ feat: 判断定位填表功能
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
13 deletions
src/App.vue
src/utils/tools.js
src/views/stop.vue
src/App.vue
View file @
8776338
...
...
@@ -2,7 +2,7 @@
* @Author: hookehuyr hookehuyr@gmail.com
* @Date: 2022-05-26 23:52:36
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-
09-19 10:49:04
* @LastEditTime: 2024-
12-20 17:08:45
* @FilePath: /data-table/src/App.vue
* @Description:
-->
...
...
@@ -22,7 +22,7 @@ import vConsole from "@/utils/vconsole";
import wx from 'weixin-js-sdk'
import { wxJsAPI } from '@/api/wx/config'
import { apiList } from '@/api/wx/jsApiList.js'
import { wxInfo, getUrlParams, stringifyQuery } from "@/utils/tools";
import { wxInfo, getUrlParams, stringifyQuery
, isWithinRadius
} from "@/utils/tools";
import { styleColor } from "@/constant.js";
import { getFormSettingAPI } from "@/api/form.js";
import { showDialog, showConfirmDialog } from 'vant';
...
...
@@ -162,6 +162,28 @@ onMounted(async () => {
wx.config(wxJs.data);
wx.ready(() => {
wx.showAllNonBaseMenuItem();
// TEST:判断定位填表功能
let open_location = false;
const targetLat = 31.278001;
const targetLng = 121.542778;
const radius = 1000; // 半径 1000 米
if (force_back !== '1' && open_location) { // 非后台用户模式
wx.getLocation({
type: 'wgs84', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
success: function (res) {
let currentLat = res.latitude; // 纬度,浮点数,范围为90 ~ -90
let currentLng = res.longitude; // 经度,浮点数,范围为180 ~ -180。
let is_in = isWithinRadius(currentLat, currentLng, targetLat, targetLng, radius);
if (!is_in) {
// 表单定位错误
$router.push("/stop?status=location_error");
}
},
fail: function (res) {
$router.push("/stop?status=get_location_fail");
},
});
}
});
wx.error((err) => {
console.warn(err);
...
...
src/utils/tools.js
View file @
8776338
/*
* @Date: 2024-07-31 17:19:25
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2024-09-05 17:08:08
* @FilePath: /data-table/src/utils/tools.js
* @Description: 文件描述
*/
/*
* @Date: 2022-04-18 15:59:42
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-02-24 16:13:06
* @LastEditTime: 2024-12-20 16:09:42
* @FilePath: /data-table/src/utils/tools.js
* @Description: 文件描述
*/
...
...
@@ -195,6 +188,43 @@ const isInViewport = (el) => { // 判断元素是否在可视区域
);
};
/**
* 判断当前经纬度是否在目标经纬度的范围内
* @param {number} currentLat - 当前纬度
* @param {number} currentLng - 当前经度
* @param {number} targetLat - 目标纬度
* @param {number} targetLng - 目标经度
* @param {number} radius - 半径(单位:米)
* @returns {boolean} 是否在范围内
*/
const
isWithinRadius
=
(
currentLat
,
currentLng
,
targetLat
,
targetLng
,
radius
)
=>
{
const
EARTH_RADIUS
=
6371000
;
// 地球半径(单位:米)
// 将角度转换为弧度
const
toRadians
=
(
degrees
)
=>
(
degrees
*
Math
.
PI
)
/
180
;
// 当前点和目标点的纬度差和经度差
const
deltaLat
=
toRadians
(
targetLat
-
currentLat
);
const
deltaLng
=
toRadians
(
targetLng
-
currentLng
);
// 转换为弧度
const
radCurrentLat
=
toRadians
(
currentLat
);
const
radTargetLat
=
toRadians
(
targetLat
);
// Haversine 公式计算两点间的距离
const
a
=
Math
.
sin
(
deltaLat
/
2
)
*
Math
.
sin
(
deltaLat
/
2
)
+
Math
.
cos
(
radCurrentLat
)
*
Math
.
cos
(
radTargetLat
)
*
Math
.
sin
(
deltaLng
/
2
)
*
Math
.
sin
(
deltaLng
/
2
);
const
c
=
2
*
Math
.
atan2
(
Math
.
sqrt
(
a
),
Math
.
sqrt
(
1
-
a
));
const
distance
=
EARTH_RADIUS
*
c
;
// 判断距离是否在范围内
return
distance
<=
radius
;
}
export
{
formatDate
,
wxInfo
,
...
...
@@ -206,4 +236,5 @@ export {
stringifyQuery
,
prettyLog
,
isInViewport
,
isWithinRadius
,
};
...
...
src/views/stop.vue
View file @
8776338
<!--
* @Date: 2022-06-29 18:18:02
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 202
2-06-29 18:18:09
* @FilePath: /
tswj/src/views/test/404
.vue
* @LastEditTime: 202
4-12-20 17:07:15
* @FilePath: /
data-table/src/views/stop
.vue
* @Description: 文件描述
-->
<template>
...
...
@@ -19,6 +19,8 @@
<span v-if="status === 'apply'">表单未开始</span>
<span v-if="status === 'finish'">表单已结束</span>
<span v-if="status === 'disable'">表单已关闭</span>
<span v-if="status === 'get_location_fail'">表单获取定位授权失败</span>
<span v-if="status === 'location_error'">未在指定位置提交,请确认后重试</span>
</p>
<!-- <p style="font-size: 0.9rem; margin-bottom: 0.5rem">您的作品正在审核中</p> -->
<!-- <p style="font-size: 0.9rem">请耐心等待~~</p> -->
...
...
@@ -34,7 +36,7 @@ import { ref } from "vue";
import { useRoute, useRouter } from "vue-router";
import { styleColor } from "@/constant.js";
import icon_success from "@images/que-sucess@2x.png";
import wx from 'weixin-js-sdk'
import {
Cookies,
$,
...
...
Please
register
or
login
to post a comment