import Vue from 'vue';
import $http from "../api/api";
import store from "../store";
import Confirm from '../views/components/confirm/index';
import ShowImage from '../views/components/showImage/index';
import {Message} from 'iview';
Vue.prototype.$Confirm = Confirm;
Vue.prototype.$ShowImage = ShowImage;
Vue.prototype.$post = (url, data, config) => {
//是否转换为formData
if (config && config.formData) {
let ret = '';
for (let it in data) {
ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
}
data = ret
}
return new Promise((resolve) => {
store.commit('showLoading');
$http.post(url, data, config).then(res => {
store.commit('hideLoading');
if (typeof res === 'string') {
resolve(JSON.parse(res));
} else {
if (res.status == 500) {
resolve({...res, data: [], records: []});
} else {
resolve(res);
}
}
}).catch(err => {
store.commit('hideLoading');
Message.error('网络繁忙,请稍后再试')
})
});
};
Vue.prototype.$get = (url, config) => {
return new Promise((resolve => {
store.commit('showLoading');
$http.get(url, config).then(res => {
store.commit('hideLoading');
if (res.status == 500) {
resolve({...res, data: [], records: []});
Message.error(res.msg)
} else {
resolve(res);
}
}).catch(err => {
store.commit('hideLoading');
Message.error('网络繁忙,请稍后再试')
})
}))
};
Vue.prototype.$compile = function (template) {
let result = Vue.compile(template);
if (result.staticRenderFns.length) {
return result.staticRenderFns[0].call(this);
} else {
return result.render.call(this)
}
};
//数字格式化
Vue.filter('NumFormat', function (value) {
if (!value) return '0.00';
if (typeof value == 'number') {
return value
}
let intPart = Number(value).toFixed(0); //获取整数部分
let intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //将整数部分逢三一断
let floatPart = ".00"; //预定义小数部分
let value2Array = value.split(".");
//=2表示数据有小数位
if (value2Array.length == 2) {
floatPart = value2Array[1].toString(); //拿到小数部分
if (floatPart.length == 1) { //补0,实际上用不着
return intPartFormat + "." + floatPart + '0';
} else {
return intPartFormat + "." + floatPart;
}
} else {
return intPartFormat + floatPart;
}
});
自用plugin
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
推荐阅读更多精彩内容
- Maven Assembly Plugin 和 Shade Plugin 都可以用来在构建单一 Jar 包时,将所...
- 原文链接:https://www.dubby.cn/detail.html?id=9091 介绍maven-jar...
- 相同点: Maven Assembly Plugin 和 Shade Plugin 都可以用来在构建单一 Jar ...
- 之前分享了玫瑰系列洁面膏,今天再分享一下同系列的玫瑰纯露,自用测评如下: 1、质地:清透,不油腻。 2、...