133 lines
2.3 KiB
JavaScript
Raw Normal View History

2025-04-28 15:37:57 +08:00
import config from "./config.js";
import {
2025-05-09 16:36:41 +08:00
showModelMessage,jkcBaseDecode
2025-04-28 15:37:57 +08:00
} from "./tools.js";
import {
callOrdereApi
} from "./api.js";
const imgPath = config.imgPath;
2025-04-30 15:19:20 +08:00
export const sdkKey = '44FBZ-K4ZC3-NDE33-O6JAE-VN3GO-NDFRQ';
export function getMap (mapid, instance) {
return uni.createMapContext(mapid, {
this: instance.proxy
});
}
2025-04-28 15:37:57 +08:00
//获取当前定位
export function getLoalcation(success, fail) {
uni.getLocation({
type: 'gcj02', // 返回可以用于 wx.openLocation 的经纬度
geocode: true,
success(res) {
const {
latitude,
longitude
} = res;
if (success) success({
latitude,
longitude
});
},
fail(res) {
if (fail) fail(res);
}
});
}
//逆解析地址
export function reverseGeocoder(qqmapsdk, longitude, latitude, success, fail) {
qqmapsdk.reverseGeocoder({
location: {
latitude: latitude,
longitude: longitude
},
success: (res) => {
if (success) success(res.result);
},
fail: (res) => {
if (fail) success(fail);
}
})
}
//添加点
export function addMarker(id, longitude, latitude, icon, joinCluster) {
return {
id: id,
latitude,
longitude,
width: 30,
height: 30,
zIndex: "100",
iconPath: imgPath + "static/userui/home/" + icon,
joinCluster: joinCluster ? true : false,
test: "1"
};
}
//添加线
export function addLine(scolor, arrPoints) {
return {
points: arrPoints,
color: scolor,
width: 3
}
}
//创建订单
export function addOrder(bikeCode, callback) {
2025-05-09 16:36:41 +08:00
const oUser =JSON.parse(jkcBaseDecode(uni.getStorageSync("wechat_user")));
2025-04-28 15:37:57 +08:00
if (!oUser) {
uni.navigateTo({
url: "/pages/user/login/wx_login"
})
}
const {
userId
} = oUser;
const params = {
userId,
bikeCode
}
saveRide(params, 1, callback)
}
function saveRide(params, icnt, callback) {
callOrdereApi("userOrders/saveRide", params, "post").then(res => {
const {
code,
message
} = res;
if (code != 200) {
if (icnt <= 3) {
saveRide(params, icnt + 1, callback);
return;
}
showModelMessage(message);
if(callback) callback(false);
return;
}
if(callback)callback(true);
setTimeout(() => {
2025-04-29 10:34:15 +08:00
uni.navigateTo({
2025-04-28 15:37:57 +08:00
url: "/pages/user/home/home"
})
}, 1000)
})
2025-05-22 11:28:43 +08:00
}
//添加面
export function addPolygon (scolor, fcolor, arrPoints) {
return {
points: arrPoints,
fillColor: fcolor,
strokeWidth: 3,
strokeColor: scolor,
zIndex: 11
}
}