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、...