1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162 |
- "use strict";
- const common_vendor = require("./vendor.js");
- class Request {
- http(router, data = {}, method, contentType) {
- let path = "https://live.test.ylrztop.com/prod-api";
- common_vendor.index.setStorageSync("requestPath", path);
- common_vendor.index.showLoading({
- title: "加载中"
- });
- return new Promise((resolve, reject) => {
- let token = common_vendor.index.getStorageSync("AppToken");
- var httpContentType = "application/x-www-form-urlencoded";
- if (contentType != void 0) {
- httpContentType = contentType;
- }
- common_vendor.index.request({
- header: {
- // 'Content-Type': 'application/x-www-form-urlencoded',
- "Content-Type": httpContentType,
- "AppToken": token
- },
- url: `${path}${router}`,
- data,
- method,
- success: (res) => {
- if (res.code == 401) {
- let pages = getCurrentPages();
- let url = pages[pages.length - 1];
- 如果登录界面已打开, 自动关闭;
- if (url != void 0 && url.route == "/pages/home/index") {
- resolve(res.data);
- return;
- }
- common_vendor.index.reLaunch({
- url: "/pages/home/index",
- success: () => {
- common_vendor.index.hideLoading();
- },
- fail: () => {
- common_vendor.index.hideLoading();
- }
- });
- return;
- }
- if (res.token) {
- common_vendor.index.setStorageSync("AppToken", res.token);
- }
- resolve(res.data);
- },
- fail: (res) => {
- },
- complete: (res) => {
- if (res.data.code == 401) {
- return false;
- }
- common_vendor.index.hideLoading();
- }
- });
- });
- }
- }
- exports.Request = Request;
|