import Vue from 'vue' function mount() { Vue.prototype.getLocation = (isReverseGeocoder = false) => { return new Promise((resolve, reject) => { let that = this; handle() function handle() { uni.getLocation({ altitude: true, highAccuracyExpireTime: 8000, isHighAccuracy: true, success: res => { console.log("获取定位", res) if (isReverseGeocoder) { Vue.prototype.$Http.basic({ "id": "10027201", "content": { "lon": res.longitude, "lat": res.latitude } }).then(s => { console.log("定位", s) res.result = s.data.result; resolve(res) }) } else { resolve(res) } }, fail: err => { uni.hideLoading(); query() } }) } function query() { uni.getSetting({ success({ authSetting }) { if (authSetting['scope.userLocation']) { handle() } else { uni.showModal({ title: '提示', content: '您未开启地理位置授权', cancelText: '下次再说', confirmText: '前去授权', success: ({ confirm }) => { if (confirm) { uni.openSetting({ success(res) { if (res.authSetting['scope.userLocation']) handle(); } }) } else { uni.showToast({ title: "已拒绝地理位置授权", icon: "none", }) } } }) } } }) } }) }; Vue.prototype.cutoff = (msg, title = "", mask = false, exitTime = 0, icon = 'none', duration = 2000, ) => { if (msg != '成功' || title) uni.showToast({ title: msg == '成功' ? title : msg, duration, icon, mask: mask || exitTime != 0 }) if (exitTime && msg == '成功') setTimeout(uni.navigateBack, exitTime) return msg != '成功'; }; Vue.prototype.paging = (content, init) => { if (content.pageTotal == undefined || !content.pageTotal) content.pageTotal = 1; if (content.pageNumber == undefined || !content.pageNumber) content.pageNumber = 1; if (content.pageSize == undefined || !content.pageSize) content.pageSize = 20; if (init) content.pageNumber = 1; return content.pageNumber > content.pageTotal; } Vue.prototype.tovw = (num) => (num * 100 / 375).toFixed(3) + "vw"; Vue.prototype.getApps = appRemark => Object.values(uni.getStorageSync('authList')[appRemark]); Vue.prototype.getHeight = (even, that, calculate = true) => { return new Promise((resolve, reject) => { if (calculate) { uni.getSystemInfo({ success(s) { uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(s.windowHeight - res[0].bottom)) } }); } else { uni.createSelectorQuery().in(that).select(even).boundingClientRect().exec(res => (!res[0]) ? reject('没有查询到元素') : resolve(res[0])) } }) }; } module.exports = { mount }