186 lines
8.1 KiB
JavaScript
186 lines
8.1 KiB
JavaScript
// 封一些公共方法
|
|
|
|
// 判断小程序端中 是否已经有了位置权限
|
|
export function handleHavePointInMin() {
|
|
return new Promise((resolve, reject) => {
|
|
uni.getSetting({
|
|
success(res) {
|
|
// 判断现在有没有拿到微信信息的权限 没有的话 就去跳转设置
|
|
if (!res.authSetting["scope.userFuzzyLocation"]) {
|
|
uni.showModal({
|
|
title: "注意",
|
|
content: "拒绝授权位置服务会导致小程序功能无法正常使用,建议授权位置信息",
|
|
confirmText: "去设置",
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
uni.openSetting({
|
|
success(settingRes) {
|
|
console.log("settingRes", settingRes);
|
|
// 如果点击了同意就去拿位置 存起来
|
|
if (settingRes.authSetting["scope.userFuzzyLocation"]) {
|
|
uni.getFuzzyLocation({
|
|
type: "gcj02",
|
|
altitude: true,
|
|
success: async (res) => {
|
|
let seatInfo = {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
};
|
|
uni.setStorageSync(
|
|
"seatInfo",
|
|
JSON.stringify(seatInfo)
|
|
);
|
|
uni.setStorageSync(
|
|
"actualLocation",
|
|
JSON.stringify(seatInfo)
|
|
);
|
|
resolve(seatInfo)
|
|
// _this.seatInfo = seatInfo;
|
|
// _this.handleGetOnLoad();
|
|
},
|
|
});
|
|
}
|
|
},
|
|
});
|
|
} else if (res.cancel) {
|
|
console.log("用户点击取消");
|
|
}
|
|
},
|
|
});
|
|
} else {
|
|
let seatInfo = uni.getStorageSync("seatInfo")
|
|
if (seatInfo) {
|
|
return JSON.parse(seatInfo)
|
|
} else {
|
|
uni.getFuzzyLocation({
|
|
type: "gcj02",
|
|
altitude: true,
|
|
success: async (res) => {
|
|
let seatInfo = {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
};
|
|
uni.setStorageSync(
|
|
"seatInfo",
|
|
JSON.stringify(seatInfo)
|
|
);
|
|
uni.setStorageSync(
|
|
"actualLocation",
|
|
JSON.stringify(seatInfo)
|
|
);
|
|
resolve(seatInfo)
|
|
},
|
|
});
|
|
}
|
|
}
|
|
},
|
|
});
|
|
})
|
|
}
|
|
|
|
// 判断在 安卓 app端中 是否有了位置权限
|
|
export function handleHavePointInApp() {
|
|
return new Promise((resolve, reject) => {
|
|
const context = plus.android.runtimeMainActivity();
|
|
const PackageManager = plus.android.importClass("android.content.pm.PackageManager");
|
|
const hasPermission = context.checkCallingOrSelfPermission("android.permission.ACCESS_FINE_LOCATION") === PackageManager.PERMISSION_GRANTED;
|
|
|
|
// true 的时候 就是有了位置权限
|
|
if (hasPermission) {
|
|
let seatInfo = uni.getStorageSync("seatInfo")
|
|
if (seatInfo) {
|
|
return JSON.parse(seatInfo)
|
|
} else {
|
|
plus.geolocation.getCurrentPosition(
|
|
async function (position) {
|
|
console.log("当前位置:", position);
|
|
let res = position.coords;
|
|
let seatInfo = {
|
|
latitude: res.latitude,
|
|
longitude: res.longitude,
|
|
};
|
|
uni.setStorageSync("seatInfo", JSON.stringify(seatInfo));
|
|
uni.setStorageSync("actualLocation", JSON.stringify(seatInfo));
|
|
_this.seat = seatInfo;
|
|
let latitude = res.latitude;
|
|
let longitude = res.longitude;
|
|
return {
|
|
latitude: latitude,
|
|
longitude: longitude
|
|
}
|
|
}
|
|
);
|
|
}
|
|
} else {
|
|
uni.showModal({
|
|
title: "注意",
|
|
content: "拒绝授权位置服务会导致小程序功能无法正常使用,建议授权位置信息",
|
|
confirmText: "去设置",
|
|
success: function (res) {
|
|
if (res.confirm) {
|
|
const main = plus.android.runtimeMainActivity();
|
|
const Intent = plus.android.importClass(
|
|
"android.content.Intent"
|
|
);
|
|
const Settings = plus.android.importClass(
|
|
"android.provider.Settings"
|
|
);
|
|
const intent = new Intent(
|
|
Settings.ACTION_APPLICATION_DETAILS_SETTINGS
|
|
);
|
|
const uri = plus.android.invoke(
|
|
"android.net.Uri",
|
|
"parse",
|
|
"package:" + main.getPackageName()
|
|
);
|
|
intent.setData(uri);
|
|
main.startActivity(intent);
|
|
}
|
|
},
|
|
});
|
|
}
|
|
})
|
|
}
|
|
|
|
// 拿到最近的服务区数据
|
|
export async function handleGetNearService(_this, longitude, latitude) {
|
|
|
|
let seatInfo = JSON.parse(uni.getStorageSync("seatInfo"));
|
|
let req = {
|
|
Province_Code: "340000",
|
|
longitude: longitude ? longitude : seatInfo.longitude ? seatInfo.longitude : '',
|
|
latitude: latitude ? latitude : seatInfo.latitude ? seatInfo.latitude : '',
|
|
};
|
|
uni.showLoading({
|
|
title: "查找最近的服务区...",
|
|
});
|
|
const data = await _this.$api.$get(
|
|
"/CommercialApi/BaseInfo/GetServerpartList",
|
|
req
|
|
);
|
|
|
|
let _data = data.Result_Data.List;
|
|
let obj = handleChangeServiceInfo(_data[0]);
|
|
console.log('publicMethods', obj);
|
|
uni.setStorageSync("currentService", obj); // 当前选中服务区信息
|
|
uni.hideLoading();
|
|
return obj
|
|
}
|
|
|
|
// 兼容一下老接口要的服务区对象的内容
|
|
function handleChangeServiceInfo(obj) {
|
|
let newObj = {
|
|
...obj,
|
|
Distance: obj.SERVERPART_DISTANCE,
|
|
OwnerUnitId: obj.OWNERUNIT_ID,
|
|
OwnerUnitName: obj.OWNERUNIT_NAME,
|
|
ProvinceCode: "340000",
|
|
ServerPart_Id: obj.SERVERPART_ID,
|
|
ServerPart_Name: obj.SERVERPART_NAME,
|
|
ServerPart_Tel: "",
|
|
ServerPart_X: obj.SERVERPART_X,
|
|
ServerPart_Y: obj.SERVERPART_Y,
|
|
showName: `${obj.SERVERPART_NAME}(${obj.SERVERPART_DISTANCE}km)`,
|
|
};
|
|
return newObj;
|
|
} |