|
|
@@ -401,7 +401,78 @@ tools.delCosToken=function (data){
|
|
|
uni.removeStorageSync('cosToken')
|
|
|
}
|
|
|
|
|
|
+/**
|
|
|
+ * 定位经纬度
|
|
|
+ * @returns {Promise<unknown>}
|
|
|
+ */
|
|
|
+tools.getLocation=async function (){
|
|
|
+ return new Promise((resolve, reject)=>{
|
|
|
+ //#ifdef APP-PLUS
|
|
|
+ let locationData= uni.getStorageSync('locationData')
|
|
|
+ console.log('locationData:',locationData)
|
|
|
+ if(locationData){
|
|
|
+ resolve(locationData);
|
|
|
+ }else {
|
|
|
+ console.log('执行获取')
|
|
|
+ uni.getLocation({
|
|
|
+ type: 'gcj02',
|
|
|
+ success:async function (res) {
|
|
|
+ console.log('当前位置的经度:' + res.longitude);
|
|
|
+ console.log('当前位置的纬度:' + res.latitude);
|
|
|
+ resolve({'longitude':res.longitude,'latitude':res.latitude});
|
|
|
+ },
|
|
|
+ fail:async function (e) {
|
|
|
+ console.log(e)
|
|
|
+ resolve( {'longitude':"121.631691",'latitude':'38.922691'});
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ //#endif
|
|
|
+ //#ifdef H5
|
|
|
+ resolve( {'longitude':"121.631691",'latitude':'38.922691'});
|
|
|
+ //#endif
|
|
|
+ })
|
|
|
+
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
+/**
|
|
|
+ * 计算距离
|
|
|
+ * @returns {Promise<void>}
|
|
|
+ */
|
|
|
+tools.getDistance=async function (lat1, lng1){
|
|
|
+ let locationData=await tools.getLocation()
|
|
|
+ let lat2=locationData.latitude
|
|
|
+ let lng2=locationData.longitude
|
|
|
+ let radLat1 = lat1*Math.PI / 180.0;
|
|
|
+ let radLat2 = lat2*Math.PI / 180.0;
|
|
|
+ let a = radLat1 - radLat2;
|
|
|
+ let b = lng1*Math.PI / 180.0 - lng2*Math.PI / 180.0;
|
|
|
+ let s = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(a/2),2) + Math.cos(radLat1)*Math.cos(radLat2)*Math.pow(Math.sin(b/2),2)));
|
|
|
+ s = s *6378.137 ;// EARTH_RADIUS;
|
|
|
+ s = Math.round(s * 10000) / 10000;
|
|
|
+ return s;
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 查看大图
|
|
|
+ * @param list
|
|
|
+ * @param index
|
|
|
+ */
|
|
|
+tools.lookBigImg = function (list, index) {
|
|
|
+ uni.previewImage({
|
|
|
+ current: index,//当前所点击预览的图片地址
|
|
|
+ urls: list,//这就是当前行图片数据,注意一定要是数组格式
|
|
|
+ indicator: 'number',
|
|
|
+ loop: true
|
|
|
+ });
|
|
|
+}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 计算年龄
|
|
|
+ * @param birthYearMonthDay
|
|
|
+ * @returns {number}
|
|
|
+ */
|
|
|
tools.getAge=function (birthYearMonthDay) {
|
|
|
birthYearMonthDay=birthYearMonthDay.replace('-','/')
|
|
|
//birthYearMonthDay必须为"1995/6/15"这种字符串格式,不可为"2020-6-15",这种格式在Safari中会报错
|
|
|
@@ -427,9 +498,10 @@ tools.getAge=function (birthYearMonthDay) {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+/**
|
|
|
+ * 获取costoken
|
|
|
+ * @returns {{expiredTime}|any|undefined}
|
|
|
+ */
|
|
|
tools.getCosToken=function (){
|
|
|
let cosToken= uni.getStorageSync('cosToken')
|
|
|
if(!cosToken){
|
|
|
@@ -442,6 +514,13 @@ tools.getCosToken=function (){
|
|
|
return undefined
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+/**
|
|
|
+ * 封装文件结构
|
|
|
+ * @param url
|
|
|
+ * @param type
|
|
|
+ * @returns {{serverSideEncryption: string, location, type: (string), version: string, hash: string}}
|
|
|
+ */
|
|
|
tools.setFileObj=function (url,type){
|
|
|
url= url.replace('https://','')
|
|
|
url= url.replace('http://','')
|