"use strict"; const common_vendor = require("../common/vendor.js"); require("./qqmap-wx-jssdk.min.js"); const config_host = require("../config/host.js"); const QQMapWX = require("./qqmap-wx-jssdk.min.js"); var qqmapsdk; const api = { loginModalState: true, mapLocation: () => { return new Promise((relove, reject) => { common_vendor.wx$1.authorize({ scope: "scope.userFuzzyLocation", success(res) { if (res.errMsg == "authorize:ok") { common_vendor.wx$1.getFuzzyLocation({ type: "wgs84", success(re) { console.log(re); common_vendor.index.chooseLocation({ latitude: re.latitude, longitude: re.longitude, success: function(data) { console.log(data); let obj = { latitude: data.latitude, longitude: data.longitude, address: data.address }; if (data.errMsg == "chooseLocation:ok") { qqmapsdk = new QQMapWX({ key: "K65BZ-LULE4-744UV-X4EIA-27RA5-A4FWT" }); qqmapsdk.reverseGeocoder({ location: { latitude: data.latitude, longitude: data.longitude }, success: function(mapres) { console.log(mapres); if (mapres.message == "query ok") { obj.name = mapres.result.formatted_addresses.recommend; obj.city = mapres.result.address_component.city; relove(obj); } } }); } } }); } }); } }, fail(err) { console.log(err); } }); }); }, getloction(details) { return new Promise((relove, reject) => { qqmapsdk = new QQMapWX({ key: "K65BZ-LULE4-744UV-X4EIA-27RA5-A4FWT" }); qqmapsdk.geocoder({ //获取表单传入地址 address: details.activedeta.city + details.activedeta.address, //地址参数,例:固定地址,address: '北京市海淀区彩和坊路海淀西大街74号' success: function(res) { console.log(res); relove(res.result.location); }, fail: function(error) { console.error(error); }, complete: function(res) { console.log(res); } }); }); }, urlToObj: (url) => { let obj = {}; let str = url.slice(url.indexOf("?") + 1); let arr = str.split("&"); for (let j = arr.length, i = 0; i < j; i++) { let arr_temp = arr[i].split("="); obj[arr_temp[0]] = arr_temp[1]; } return obj; }, upfile: (file) => { return new Promise((relove, reject) => { common_vendor.index.showLoading({ title: "上传中" }); common_vendor.index.uploadFile({ url: `${config_host.host}/other/upload`, //仅为示例,非真实的接口地址 filePath: file, name: "file", success: (uploadFileRes) => { common_vendor.index.hideLoading(); relove(JSON.parse(uploadFileRes.data).data); } }); }); }, imgurl: (url) => { if (url) { if (url.indexOf("http") == -1) { return config_host.imghost + url; } else { return url; } } else { return ""; } }, imgurl2: (url) => { if (url) { if (url.indexOf("https") == -1) { console.log(url.replace("http", "https")); return url.replace("http", "https"); } else { return url; } } else { return ""; } }, /** * 失败 */ error: (msg) => { return new Promise((relove, reject) => { common_vendor.index.showToast({ title: msg, icon: "none" }); setTimeout(() => { relove(); }, 1500); }); }, /** * 成功提示 */ success: (msg) => { return new Promise((relove, reject) => { common_vendor.index.showToast({ title: msg, icon: "success" }); setTimeout(() => { relove(); }, 1500); }); }, /** * 确认对话框 * @param {Object} contents * @param {Object} callback */ confirm: (contents) => { return new Promise((relove, reject) => { common_vendor.index.showModal({ title: "提示", content: contents, success: function(res) { if (res.confirm) { relove(); } } }); }); }, payment: (param) => { return new Promise((relove, reject) => { common_vendor.index.requestPayment({ provider: "wxpay", timeStamp: param.timeStamp, nonceStr: param.nonceStr, package: param.package, signType: param.signType, paySign: param.paySign, success: function(res) { relove(res); }, fail: function(err) { console.log(err); api.error("支付失败"); } }); }); }, navHeight: () => { try { common_vendor.wx$1.getSystemInfo({ success: (res) => { globalThis.system = res; } }); console.log("res", globalThis.system); globalThis.menu = common_vendor.wx$1.getMenuButtonBoundingClientRect(); globalThis.systemBar = globalThis.system.statusBarHeight; globalThis.navigationBar = (globalThis.menu.top - globalThis.system.statusBarHeight) * 2 + globalThis.menu.height; globalThis.navPaddingTop = globalThis.systemBar; globalThis.navHeight = globalThis.menu.height; globalThis.headerPadding = globalThis.menu.top - globalThis.systemBar; globalThis.systemBarHeight = globalThis.navPaddingTop + globalThis.navHeight + globalThis.headerPadding * 2; } catch (e) { globalThis.navPaddingTop = 43; globalThis.navHeight = 32; globalThis.headerPadding = 4; } return { navPaddingTop: globalThis.navPaddingTop, navHeight: globalThis.navHeight, headerPadding: globalThis.headerPadding, systemBarHeight: globalThis.systemBarHeight, windowHeihgt: globalThis.system.windowHeight - globalThis.systemBarHeight }; }, wxSystemInfo: () => { try { common_vendor.wx$1.getSystemInfo({ success: (res) => { globalThis.system = res; } }); } catch (e) { } return { system: globalThis.system }; } }; exports.api = api;