1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/liuyonghu-WXYHNetworking

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
YHCNetWoking.js 1.7 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
刘勇虎 Отправлено 12.08.2021 12:55 fc11494
/*
* @Author: liuyonghu
* @Date: 2021-08-10 15:24:17
* @LastEditTime: 2021-08-10 16:24:14
* @LastEditors: liuyonghu
* @Description:
* @FilePath: /miniprogram/submodule/YHCNetWoking.js
*/
class YHCNetWoking {
constructor(options) {
if (!options || !options.env) {
return console.error(
EvalError("- YHCNetWoking : Must has a env to config !")
);
}
this.env = options.env;
this.traceUser = options.traceUser;
this.url = true;
this.requestInterceptor = null;
(!!options && !!options.requestInterceptor) && (this.requestInterceptor = options.requestInterceptor);
this.resInterceptor = null;
(!!options && !!options.resInterceptor) && (this.resInterceptor = options.resInterceptor);
this.init();
}
//
init() {
wx.cloud.init({
env: this.env,
traceUser: this.traceUser,
});
}
request(options) {
if (this.requestInterceptor) {
options = this.requestInterceptor(options);
}
const { env, name, data } = options;
const config = !env ? { env } : null;
if (!!!data || !!!data.type) {
return console.error(
EvalError("- YHCNetWoking : Must has a type to request !")
);
}
if (!!!name) {
return console.error(
EvalError("- YHCNetWoking : Must has a name to request !")
);
}
return new Promise((resolve, reject) => {
wx.cloud
.callFunction({
name,
config,
data,
})
.then((resp) => {
if (this.resInterceptor) {
return resolve(this.resInterceptor(resp));
}
resolve(resp);
})
.catch((e) => {
reject(e);
});
});
}
}
module.exports = YHCNetWoking;

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/liuyonghu-WXYHNetworking.git
git@api.gitlife.ru:oschina-mirror/liuyonghu-WXYHNetworking.git
oschina-mirror
liuyonghu-WXYHNetworking
liuyonghu-WXYHNetworking
master