123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- "use strict";
- var common_vendor = require("../../common/vendor.js");
- var store_index = require("../../store/index.js");
- var utils_request_upload_upload = require("./upload/upload.js");
- var core_config_index = require("../../core/config/index.js");
- const apiUrl = core_config_index.config.get("apiUrl");
- const $http = new utils_request_upload_upload.fileUpload({
- baseUrl: apiUrl,
- fileUrl: apiUrl,
- defaultUploadUrl: "upload/image",
- header: {
- "content-type": "application/json;charset=utf-8"
- },
- timeout: 15e3,
- config: {
- isPrompt: true,
- load: true,
- isFactory: true
- }
- });
- let requestNum = 0;
- $http.requestStart = (options) => {
- if (options.load) {
- if (requestNum <= 0) {
- common_vendor.index.showLoading({
- title: "\u52A0\u8F7D\u4E2D",
- mask: true
- });
- }
- requestNum += 1;
- }
- if (options.method == "FILE" && options.maxSize) {
- const maxSize = options.maxSize;
- for (let item of options.files) {
- if (item.size > maxSize) {
- setTimeout(() => {
- common_vendor.index.showToast({
- title: "\u56FE\u7247\u8FC7\u5927\uFF0C\u8BF7\u91CD\u65B0\u4E0A\u4F20",
- icon: "none"
- });
- });
- return false;
- }
- }
- }
- options.header["api-name"] = store_index.store.getters.platform;
- options.header["token"] = store_index.store.getters.token;
- return options;
- };
- $http.requestEnd = (options) => {
- if (options.load) {
- if (requestNum > 0) {
- common_vendor.index.hideLoading();
- }
- }
- };
- $http.dataFactory = async (res) => {
- requestNum -= 1;
- if (requestNum <= 0) {
- common_vendor.index.hideLoading();
- }
- const httpData = res.response;
- if (httpData.code === 0) {
- common_vendor.index.showToast({
- title: httpData.msg,
- icon: "none",
- duration: 2500
- });
- return false;
- } else if (httpData.code == 401) {
- store_index.store.dispatch("Logout");
- common_vendor.index.showToast({
- title: "\u767B\u5F55\u72B6\u6001\u9519\u8BEF\u6216\u5DF2\u5931\u6548",
- icon: "none",
- duration: 2500
- });
- return false;
- } else if (httpData.code === 200) {
- return Promise.resolve(httpData);
- } else {
- common_vendor.index.showToast({
- title: "\u670D\u52A1\u7AEF\u9519\u8BEF",
- icon: "none",
- duration: 2500
- });
- return false;
- }
- };
- $http.requestError = (e) => {
- if (e.statusCode === 0) {
- throw e;
- } else {
- setTimeout(() => showRequestError(e), 10);
- }
- };
- const showRequestError = (e) => {
- let errMsg = `\u7F51\u7EDC\u8BF7\u6C42\u51FA\u9519\uFF1A${e.errMsg}`;
- if (e.errMsg === "request:fail url not in domain list") {
- errMsg = "\u5F53\u524DAPI\u57DF\u540D\u672A\u6DFB\u52A0\u5230\u5FAE\u4FE1\u5C0F\u7A0B\u5E8F\u6388\u6743\u540D\u5355 " + e.errMsg;
- }
- if (e.errMsg === "request:fail") {
- errMsg = "\u7F51\u7EDC\u8BF7\u6C42\u9519\u8BEF\uFF0C\u8BF7\u68C0\u67E5\u60A8\u7684\u7F51\u7EDC\u662F\u5426\u6B63\u5E38\uFF01";
- }
- common_vendor.index.showToast({
- title: errMsg,
- icon: "none",
- duration: 3500
- });
- };
- exports.$http = $http;
|