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) => {
//是否轉(zhuǎn)換為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('網(wǎng)絡(luò)繁忙,請稍后再試')
})
});
};
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('網(wǎng)絡(luò)繁忙,請稍后再試')
})
}))
};
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)
}
};
//數(shù)字格式化
Vue.filter('NumFormat', function (value) {
if (!value) return '0.00';
if (typeof value == 'number') {
return value
}
let intPart = Number(value).toFixed(0); //獲取整數(shù)部分
let intPartFormat = intPart.toString().replace(/(\d)(?=(?:\d{3})+$)/g, '$1,'); //將整數(shù)部分逢三一斷
let floatPart = ".00"; //預(yù)定義小數(shù)部分
let value2Array = value.split(".");
//=2表示數(shù)據(jù)有小數(shù)位
if (value2Array.length == 2) {
floatPart = value2Array[1].toString(); //拿到小數(shù)部分
if (floatPart.length == 1) { //補(bǔ)0,實際上用不著
return intPartFormat + "." + floatPart + '0';
} else {
return intPartFormat + "." + floatPart;
}
} else {
return intPartFormat + floatPart;
}
});
自用plugin
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門啼止,熙熙樓的掌柜王于貴愁眉苦臉地迎上來道逗,“玉大人,你說我怎么就攤上這事族壳°颈瑁” “怎么了?”我有些...
- 文/不壞的土叔 我叫張陵仿荆,是天一觀的道長贰您。 經(jīng)常有香客問我,道長拢操,這世上最難降的妖魔是什么锦亦? 我笑而不...
- 正文 為了忘掉前任,我火速辦了婚禮令境,結(jié)果婚禮上杠园,老公的妹妹穿的比我還像新娘。我一直安慰自己舔庶,他們只是感情好抛蚁,可當(dāng)我...
- 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著惕橙,像睡著了一般瞧甩。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上弥鹦,一...
- 文/蒼蘭香墨 我猛地睜開眼血当,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了洒疚?” 一聲冷哼從身側(cè)響起歹颓,我...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡乏德,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年,在試婚紗的時候發(fā)現(xiàn)自己被綠了吠昭。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片喊括。...
- 正文 年R本政府宣布蘑拯,位于F島的核電站,受9級特大地震影響兜粘,放射性物質(zhì)發(fā)生泄漏申窘。R本人自食惡果不足惜,卻給世界環(huán)境...
- 文/蒙蒙 一孔轴、第九天 我趴在偏房一處隱蔽的房頂上張望剃法。 院中可真熱鬧,春花似錦路鹰、人聲如沸贷洲。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽优构。三九已至,卻和暖如春趣斤,著一層夾襖步出監(jiān)牢的瞬間俩块,已是汗流浹背。 一陣腳步聲響...
- 正文 我出身青樓,卻偏偏與公主長得像漫仆,于是被迫代替她去往敵國和親捎拯。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- Maven Assembly Plugin 和 Shade Plugin 都可以用來在構(gòu)建單一 Jar 包時,將所...
- 原文鏈接:https://www.dubby.cn/detail.html?id=9091 介紹maven-jar...
- 相同點(diǎn): Maven Assembly Plugin 和 Shade Plugin 都可以用來在構(gòu)建單一 Jar ...
- 之前分享了玫瑰系列潔面膏,今天再分享一下同系列的玫瑰純露懂扼,自用測評如下: 1禁荸、質(zhì)地:清透,不油膩阀湿。 2赶熟、...