1.api:
2.圖片上傳:
module.exports = {
upload: function(o) {
var t = getApp();
function a(e) {
"function" == typeof o.start && o.start(e), wx.uploadFile({
url: o.url || t.api.default.upload_image,
filePath: e.path,
name: o.name || "image",
formData: o.data || {},
success: function(e) {
200 == e.statusCode ? "function" == typeof o.success && (e.data = JSON.parse(e.data),
o.success(e.data)) : "function" == typeof o.error && o.error("上傳錯誤:" + e.statusCode + ";" + e.data),
o.complete();
},
fail: function(e) {
"function" == typeof o.error && o.error(e.errMsg), o.complete();
}
});
}
(o = o || {}).complete = o.complete || function() {}, o.data = o.data || {}, wx.chooseImage({
count: 1,
success: function(e) {
if (e.tempFiles && 0 < e.tempFiles.length) {
var t = e.tempFiles[0];
a(t);
} else "function" == typeof o.error && o.error("請選擇文件"), o.complete();
},
fail: function(e) {
"function" == typeof o.error && (o.error("請選擇文件"), o.complete());
}
});
}
};
3.錢的轉換 和手機號中間4為變****:
module.exports = {
//分轉元
moneyFormat: function(num){
if(!num){
num = 0;
}
num=num*0.01;
num = parseFloat((num + "").replace('/[^\d\.-]/g', "")).toFixed(2) + "";
return num
},
// 分轉元
moneyFormat2: function(arg1){
if(!arg1){
arg1 = 0;
}
var arg2 = 0.01;
var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
s1.split(".").length>1?m += s1.split(".")[1].length:m=m;
s2.split(".").length>1?m += s2.split(".")[1].length:m=m;
var num = (s1.replace(".", "")* s2.replace(".", ""))/Math.pow(10, m);
return num;
},
// 元轉兩位小數
moneyFormat3: function(num){
return Number(num).toFixed(2);
},
// 分轉元 只取整數
moneyFormat4: function(arg1){
if(!arg1){arg1 = 0;}
var arg2 = 0.01;
var num = (arg1*arg2+'').split(".")[0];
return num;
},
dateFormat: function (strDate, format = "yyyy-MM-dd hh:mm:ss") {
var realDate = strDate ? getDate(strDate*1000) : getDate();
var regYear = getRegExp("(y+)", "i");
var date = [
["M+", realDate.getMonth() + 1],
["d+", realDate.getDate()],
["h+", realDate.getHours()],
["m+", realDate.getMinutes()],
["s+", realDate.getSeconds()],
["q+", Math.floor((realDate.getMonth() + 3) / 3)],
["S+", realDate.getMilliseconds()],
];
var reg1 = regYear.exec(format);
if (reg1) {
format = format.replace(reg1[1], (realDate.getFullYear() + '').substring(4 - reg1[1].length));
}
for (var i = 0; i < date.length; i++) {
var reg2 = getRegExp("(" + date[i][0] + ")").exec(format);
if (reg2) {
format = format.replace(reg2[1], reg2[1].length == 1 ? date[i][1] : ("00" + date[i][1]).substring(("" + date[i][1]).length));
}
}
return format
},
//手機號加密
mobileFormat: function(str){
if(str!=''&&str!=undefined&&str!=null){
str = str.substring(0,3)+'****'+str.substring(7);
}
return str;
},
cardNumFormat: function(str){
if (!str) {
return;
}
return str.replace(getRegExp('(\s)','g'),'').replace(getRegExp('(\d{4})','g'),'$1 ').replace(getRegExp('\s*$'),'');
}
};