123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169 |
- 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, update) => {
- if (update) {
- let content1 = JSON.parse(JSON.stringify(content));
- content1.pageSize = (content1.pageNumber - 1) * content1.pageSize;
- content1.pageNumber = 1;
- return content1
- } else {
- 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, route) => {
- const list = Object.values(uni.getStorageSync('authList')[appRemark])
- return route ? list.find(v => v.path == route || v.pathDetail == route) : list
- };
- 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]))
- }
- })
- };
- //compressed压缩图;thumbnail缩略图,hls转码视频,cover封面
- Vue.prototype.getSpecifiedImage = (item, type = 'thumbnail') => {
- if (!item) return "";
- let v = item.subfiles.find(v => v.type == type);
- return v ? v.url : item.url;
- }
- Vue.prototype.formatTime = (date = new Date(), j1 = '-', j2 = ':') => {
- const year = date.getFullYear()
- const month = date.getMonth() + 1
- const day = date.getDate()
- const hour = date.getHours()
- const minute = date.getMinutes()
- const second = date.getSeconds()
- const formatNumber = n => {
- n = n.toString()
- return n[1] ? n : `0${n}`
- }
- return `${[year, month, day].map(formatNumber).join(j1)} ${[hour, minute, second].map(formatNumber).join(j2)}`
- }
- Vue.prototype.getCustomClass = (typename) => {
- return new Promise((resolve, reject) => {
- Vue.prototype.$Http.basic({
- "classname": "sysmanage.develop.optiontype.optiontype",
- "method": "optiontypeselect",
- "content": {
- typename
- }
- }).then(res => {
- console.log("获取自定义分类" + typename, res)
- if (res.msg != '成功') return resolve([]);
- resolve(res.data);
- })
- })
- }
- Vue.prototype.CNY = (sum, precision = 2) => {
- const currency = require("./currency.js");
- return currency(sum, {
- symbol: "¥",
- precision
- }).format();
- }
- }
- module.exports = {
- mount
- }
|