小程序常用函数封装

function e(e, n) {
if (!(e instanceof n)) throw new TypeError(“Cannot call a class as a function”);
}

Object.defineProperty(exports, “__esModule”, {
value: !0
});

var n = function() {
function e(e, n) {
for (var t = 0; t < n.length; t++) { var o = n[t]; o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, o.key, o); } } return function(n, t, o) { return t && e(n.prototype, t), o && e(n, o), n; }; }(), t = getApp(), o = function() {
function o() {
e(this, o);
}
return n(o, [ {
key: “request”,
value: function(e) {
var n = arguments.length > 1 && void 0 !== arguments[1] ? arguments[1] : {};
return new Promise(function(o, a) {
wx.showLoading({
title: “请稍候”
}), wx.request({
url: t.globalData.apiBase + e,
data: n,
header: {
“content-type”: “application/json”
},
method: “POST”,
dataType: “json”,
success: function(e) {
wx.hideLoading(), o(e);
},
fail: function(e) {
wx.hideLoading(), a(e);
}
});
});
}
}, {
key: “getUserInfo”,
value: function(e, n, t, o) {
var a = wx.getStorageSync(e);
o || t(a), a && !o || this.request(e, {
uid: n.uid,
id: n.id
}).then(function(e) {
var n = e.data.data, o = e.data.code;
e && e.data && parseFloat(e.data.code) > 0 ? (console.log(n), t(n)) : t(o);
});
}
}, {
key: “downloadFile”,
value: function(e) {
return new Promise(function(n, t) {
wx.showLoading({
title: “请稍候”
}), wx.downloadFile({
url: e,
success: function(e) {
wx.hideLoading(), 200 === e.statusCode && n(e.tempFilePath);
}
});
});
}
}, {
key: “chooseImage”,
value: function(e) {
return new Promise(function(n, t) {
wx.chooseImage({
count: e,
sizeType: [ “compressed” ],
sourceType: [ “album”, “camera” ],
success: function(e) {
n(e);
},
fail: function(e) {
t(e);
}
});
});
}
}, {
key: “getImageInfo”,
value: function(e) {
return new Promise(function(n, t) {
wx.getImageInfo({
src: e,
success: function(e) {
n(e);
},
fail: function(e) {
t(e);
}
});
});
}
}, {
key: “chooseVideo”,
value: function() {
return new Promise(function(e, n) {
wx.chooseVideo({
sourceType: [ “album”, “camera” ],
compressed: !0,
maxDuration: 60,
success: function(n) {
e(n);
},
fail: function(e) {
n(e);
}
});
});
}
}, {
key: “uploadFile”,
value: function(e, n, o) {
return new Promise(function(a, u) {
wx.uploadFile({
url: t.globalData.apiBase + e,
filePath: n,
name: o,
success: function(e) {
a(e);
},
fail: function(e) {
u(e);
}
});
});
}
}, {
key: “previewImage”,
value: function(e, n) {
wx.previewImage({
current: e,
urls: n
});
}
}, {
key: “showToast”,
value: function(e) {
wx.showToast({
title: e,
icon: “none”
});
}
}, {
key: “showModal”,
value: function(e) {
return new Promise(function(n, t) {
wx.showModal({
title: “温馨提示”,
content: e,
success: function(e) {
n(e);
},
fail: function(e) {
t(e);
}
});
});
}
}, {
key: “transformYearMonth”,
value: function(e, n) {
var t = arguments.length > 2 && void 0 !== arguments[2] ? arguments[2] : “.”, o = new Date(1e3 * e), a = o.getFullYear(), u = o.getMonth() + 1 < 10 ? "0" + (o.getMonth() + 1) : o.getMonth() + 1, i = o.getDate() < 10 ? "0" + o.getDate() : o.getDate(); return 1 == n ? "" + a + t + u + t + i : 2 == n ? "" + a + t + u : void 0; } }, { key: "numberSub", value: function(e, n) { return e > n ? e – n : n > e ? n – e : 0;
}
} ]), o;
}();

exports.default = o;

This entry was posted in 编程 by .

发表评论

电子邮件地址不会被公开。 必填项已用*标注