import Vue from 'vue' function setBar() { uni.getSystemInfo({ success: function (e) { // #ifndef MP Vue.prototype.usePort = 'h5'; Vue.prototype.StatusBar = e.statusBarHeight; if (e.platform == 'android') { Vue.prototype.CustomBar = e.statusBarHeight + 50; } else { Vue.prototype.CustomBar = e.statusBarHeight + 45; }; // #endif // #ifdef MP-WEIXIN Vue.prototype.usePort = 'wechat'; Vue.prototype.StatusBar = e.statusBarHeight; let custom = wx.getMenuButtonBoundingClientRect(); Vue.prototype.Custom = custom; Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight; // #endif // #ifdef MP-ALIPAY Vue.prototype.StatusBar = e.statusBarHeight; Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight; // #endif } }) } function mount() { Vue.prototype.getLocation = (isReverseGeocoder = false) => { const { tianditu } = require("./tianditu"); const api = new tianditu(); 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) { api.getPlace(res.longitude, res.latitude).then(s => { console.log("天地图逆解析", s) resolve(Object.assign(res, s)) }) } 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.tovw = (num) => (num * 100 / 375).toFixed(3) + "vw"; 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])) } }) }; Vue.prototype.getControlItem = (nameList, detail, specialType = {}) => { console.log(nameList, detail) let list = nameList.map(v => detail.function[v]).filter((v, i) => { if (!v) console.log("未查找到项:", nameList[i]) return v }) for (const key in list) { try { let original = list[key].params, name = Object.entries(original)[0][0]; list[key].paramName = name; list[key].params = detail.params[name]; list[key].paramValue = detail.paramcmdvalues[name] list[key].isfeedback = detail.isfeedback == 1 && list[key].paramValue; if (specialType[nameList[key]] || false) { list[key].inputType = specialType[nameList[key]]; if (["radio"].includes(specialType[nameList[key]])) { list[key].showValue = ""; if (list[key].params.lastvalue + '') list[key].showValue = list[key].params.options.find(v => v.value == list[key].params.lastvalue).label || "" } else if (["radioNum"].includes(specialType[nameList[key]])) { //MT02 控制模式使用 list[key].params.options = []; for (const oKey in original) { let item = detail.params[oKey]; if (original[oKey] == 1) list[key].showValue = item.paramname; if (original[oKey] != detail.paramcmdvalues[oKey] && detail.paramcmdvalues[oKey] == 1) { list[key].paramValue = item.paramname; } else { list[key].paramValue = ''; } list[key].params.options.push({ label: item.paramname, value: item.lastvalue, key: oKey }) }; } } else if (list[key].params.datatype == "boolean") { list[key].paramName = original; list[key].inputType = 'switch'; list[key].showValue = ""; try { if (list[key].params.lastvalue + '') list[key].showValue = list[key].params.options.find(v => v.value == list[key].params.lastvalue).label || "" } catch (error) {} } else { list[key].inputType = list[key].params.num_step ? 'step' : 'int'; } } catch (error) { console.log("出错项", key, list[key]) console.log("出错项funcname", list[key].funcname) console.error(list[key].funcname, error) } } return list } } module.exports = { mount, setBar }