123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104 |
- 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 = () => {
- return new Promise((resolve, reject) => {
- uni.getLocation({
- altitude: true,
- highAccuracyExpireTime: 5000,
- isHighAccuracy: true,
- success: res => resolve(res)
- })
- })
- };
- 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, funs, values, paramsList) => {
- let list = nameList.map(v => funs[v])
- for (const key in list) {
- const name = Object.entries(list[key].params)[0][0]
- list[key].paramName = name;
- list[key].params = paramsList[name];
- list[key].paramValue = values[name]
- list[key].isfeedback = list[key].isfeedback && (list[key].paramValue != list[key].params.lastvalue)
- if (list[key].params.datatype == "boolean") {
- list[key].inputType = 'switch';
- list[key].showValue = list[key].params.options.find(v => v.value == list[key].params.lastvalue).label
- } else {
- list[key].inputType = list[key].params.num_step ? 'step' : 'int';
- }
- }
- return list
- }
- }
- function getCity() {
- return new Promise((resolve, reject) => {
- // #ifdef H5
- wx.request({
- url: 'http://www.nmc.cn/rest/position',
- method: "GET",
- timeout: 30000,
- success: res => resolve(res.data)
- })
- // #endif
- // #ifndef H5
- this.$Http.getLocationCode().then(res => resolve(res))
- // #endif
- })
- }
- module.exports = {
- mount,
- setBar,
- getCity
- }
|