|
@@ -1,119 +1,123 @@
|
|
-import Vue from "vue";
|
|
|
|
-import axios from "axios";
|
|
|
|
-
|
|
|
|
-import App from "./App.vue";
|
|
|
|
-import router from "./router";
|
|
|
|
-import store from "./store";
|
|
|
|
-import globalVuePlugins from "./plugins/globalVuePlugins";
|
|
|
|
-// 系统初始采集配置
|
|
|
|
-import CONFIG from "./config";
|
|
|
|
-
|
|
|
|
-// https://github.com/RobinCK/vue-ls
|
|
|
|
-import VueLocalStorage from "vue-ls";
|
|
|
|
-import ViewUI from "view-design";
|
|
|
|
-// import "view-design/dist/styles/iview.css";
|
|
|
|
-import "cropperjs/dist/cropper.min.css";
|
|
|
|
-import "./assets/styles/index.less";
|
|
|
|
-
|
|
|
|
-import { initConfigData } from "@/plugins/env";
|
|
|
|
-import log4js from "./plugins/logger";
|
|
|
|
-const logger = log4js.getLogger("request");
|
|
|
|
-
|
|
|
|
-Vue.use(ViewUI);
|
|
|
|
-ViewUI.Message.config({
|
|
|
|
- top: 10
|
|
|
|
-});
|
|
|
|
-Vue.use(VueLocalStorage);
|
|
|
|
-Vue.use(globalVuePlugins);
|
|
|
|
-
|
|
|
|
-// 加载采集配置
|
|
|
|
-const GLOBAL = initConfigData(CONFIG);
|
|
|
|
-Vue.prototype.GLOBAL = GLOBAL;
|
|
|
|
-
|
|
|
|
-Vue.config.productionTip = false;
|
|
|
|
-
|
|
|
|
-// logger
|
|
|
|
-const addLog = (datas, type) => {
|
|
|
|
- if (type === "start") {
|
|
|
|
- const msg = `${datas.url},开始请求`;
|
|
|
|
- logger.info(msg);
|
|
|
|
- } else if (type === "success") {
|
|
|
|
- const msg = `${datas.config.url},请求成功`;
|
|
|
|
- logger.info(msg);
|
|
|
|
- } else {
|
|
|
|
- const msg = `${datas.config.url},请求错误,错误信息:${datas.response.data.status} - ${datas.response.data.message}`;
|
|
|
|
- logger.error(msg);
|
|
|
|
- }
|
|
|
|
-};
|
|
|
|
-
|
|
|
|
-// axios interceptors
|
|
|
|
-var load = "";
|
|
|
|
-// 同一时间有多个请求时,会形成队列。在第一个请求创建loading,在最后一个响应关闭loading
|
|
|
|
-var queue = [];
|
|
|
|
-axios.interceptors.request.use(
|
|
|
|
- config => {
|
|
|
|
- // 显示loading提示
|
|
|
|
- if (!queue.length && !config["showTinyTips"] && !config["silentRequest"]) {
|
|
|
|
- load = ViewUI.Message.loading({
|
|
|
|
- content: "Loading...",
|
|
|
|
- duration: 0
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- queue.push(1);
|
|
|
|
-
|
|
|
|
- // 为请求地址添加全局domain
|
|
|
|
- if (config.url.indexOf("http://") < 0) {
|
|
|
|
- config.url = GLOBAL.domain + config.url;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 为请求头添加信息
|
|
|
|
- let organizationId = Vue.ls.get("organizationId");
|
|
|
|
- if (organizationId) {
|
|
|
|
- config.headers["organizationId"] = organizationId;
|
|
|
|
- }
|
|
|
|
- // 设置延迟时效
|
|
|
|
- config.timeout = 10 * 60 * 1000;
|
|
|
|
-
|
|
|
|
- addLog(config, "start");
|
|
|
|
- return config;
|
|
|
|
- },
|
|
|
|
- error => {
|
|
|
|
- // console.log(error);
|
|
|
|
- // logger.error("");
|
|
|
|
- // 关闭loading提示
|
|
|
|
- // 串联并发请求,延时处理是为防止多个loading实例闪屏。
|
|
|
|
- setTimeout(() => {
|
|
|
|
- queue.shift();
|
|
|
|
- if (!queue.length) load && load();
|
|
|
|
- }, 100);
|
|
|
|
- return Promise.reject(error);
|
|
|
|
- }
|
|
|
|
-);
|
|
|
|
-axios.interceptors.response.use(
|
|
|
|
- response => {
|
|
|
|
- addLog(response, "success");
|
|
|
|
- // 关闭loading提示
|
|
|
|
- setTimeout(() => {
|
|
|
|
- queue.shift();
|
|
|
|
- if (!queue.length) load && load();
|
|
|
|
- }, 100);
|
|
|
|
- return response;
|
|
|
|
- },
|
|
|
|
- error => {
|
|
|
|
- addLog(error, "error");
|
|
|
|
-
|
|
|
|
- // 关闭loading提示
|
|
|
|
- setTimeout(() => {
|
|
|
|
- queue.shift();
|
|
|
|
- if (!queue.length) load && load();
|
|
|
|
- }, 100);
|
|
|
|
- return Promise.reject(error);
|
|
|
|
- }
|
|
|
|
-);
|
|
|
|
-
|
|
|
|
-new Vue({
|
|
|
|
- router,
|
|
|
|
- store,
|
|
|
|
- render: h => h(App)
|
|
|
|
-}).$mount("#app");
|
|
|
|
|
|
+import Vue from "vue";
|
|
|
|
+import axios from "axios";
|
|
|
|
+
|
|
|
|
+import App from "./App.vue";
|
|
|
|
+import router from "./router";
|
|
|
|
+import store from "./store";
|
|
|
|
+import globalVuePlugins from "./plugins/globalVuePlugins";
|
|
|
|
+// 系统初始采集配置
|
|
|
|
+import CONFIG from "./config";
|
|
|
|
+
|
|
|
|
+// https://github.com/RobinCK/vue-ls
|
|
|
|
+import VueLocalStorage from "vue-ls";
|
|
|
|
+import ViewUI from "view-design";
|
|
|
|
+// import "view-design/dist/styles/iview.css";
|
|
|
|
+import "cropperjs/dist/cropper.min.css";
|
|
|
|
+import "./assets/styles/index.less";
|
|
|
|
+
|
|
|
|
+import { initConfigData } from "@/plugins/env";
|
|
|
|
+import log4js from "./plugins/logger";
|
|
|
|
+const logger = log4js.getLogger("request");
|
|
|
|
+
|
|
|
|
+Vue.use(ViewUI);
|
|
|
|
+ViewUI.Message.config({
|
|
|
|
+ top: 10
|
|
|
|
+});
|
|
|
|
+Vue.use(VueLocalStorage);
|
|
|
|
+Vue.use(globalVuePlugins);
|
|
|
|
+
|
|
|
|
+// 加载采集配置
|
|
|
|
+const GLOBAL = initConfigData(CONFIG);
|
|
|
|
+Vue.prototype.GLOBAL = GLOBAL;
|
|
|
|
+
|
|
|
|
+Vue.config.productionTip = false;
|
|
|
|
+
|
|
|
|
+// logger
|
|
|
|
+const addLog = (datas, type) => {
|
|
|
|
+ if (type === "start") {
|
|
|
|
+ const msg = `${datas.url},开始请求`;
|
|
|
|
+ logger.info(msg);
|
|
|
|
+ } else if (type === "success") {
|
|
|
|
+ const msg = `${datas.config.url},请求成功`;
|
|
|
|
+ logger.info(msg);
|
|
|
|
+ } else {
|
|
|
|
+ const msg = `${datas.config.url},请求错误,错误信息:${datas.response.data.status} - ${datas.response.data.message}`;
|
|
|
|
+ logger.error(msg);
|
|
|
|
+ }
|
|
|
|
+};
|
|
|
|
+
|
|
|
|
+// axios interceptors
|
|
|
|
+var load = "";
|
|
|
|
+// 同一时间有多个请求时,会形成队列。在第一个请求创建loading,在最后一个响应关闭loading
|
|
|
|
+var queue = [];
|
|
|
|
+axios.interceptors.request.use(
|
|
|
|
+ config => {
|
|
|
|
+ // 显示loading提示
|
|
|
|
+ if (!queue.length && !config["showTinyTips"] && !config["silentRequest"]) {
|
|
|
|
+ load = ViewUI.Message.loading({
|
|
|
|
+ content: "Loading...",
|
|
|
|
+ duration: 0
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ queue.push(1);
|
|
|
|
+
|
|
|
|
+ // 为请求地址添加全局domain
|
|
|
|
+ if (config.url.indexOf("http://") < 0) {
|
|
|
|
+ config.url = GLOBAL.domain + config.url;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 为请求头添加信息
|
|
|
|
+ let organizationId = Vue.ls.get("organizationId");
|
|
|
|
+ if (organizationId) {
|
|
|
|
+ config.headers["organizationId"] = organizationId;
|
|
|
|
+ }
|
|
|
|
+ let user = Vue.ls.get("user", { userId: "", examId: "" });
|
|
|
|
+ config.headers["userId"] = user.userId;
|
|
|
|
+ config.headers["examId"] = user.examId;
|
|
|
|
+
|
|
|
|
+ // 设置延迟时效
|
|
|
|
+ config.timeout = 10 * 60 * 1000;
|
|
|
|
+
|
|
|
|
+ addLog(config, "start");
|
|
|
|
+ return config;
|
|
|
|
+ },
|
|
|
|
+ error => {
|
|
|
|
+ // console.log(error);
|
|
|
|
+ // logger.error("");
|
|
|
|
+ // 关闭loading提示
|
|
|
|
+ // 串联并发请求,延时处理是为防止多个loading实例闪屏。
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ queue.shift();
|
|
|
|
+ if (!queue.length) load && load();
|
|
|
|
+ }, 100);
|
|
|
|
+ return Promise.reject(error);
|
|
|
|
+ }
|
|
|
|
+);
|
|
|
|
+axios.interceptors.response.use(
|
|
|
|
+ response => {
|
|
|
|
+ addLog(response, "success");
|
|
|
|
+ // 关闭loading提示
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ queue.shift();
|
|
|
|
+ if (!queue.length) load && load();
|
|
|
|
+ }, 100);
|
|
|
|
+ return response;
|
|
|
|
+ },
|
|
|
|
+ error => {
|
|
|
|
+ addLog(error, "error");
|
|
|
|
+
|
|
|
|
+ // 关闭loading提示
|
|
|
|
+ setTimeout(() => {
|
|
|
|
+ queue.shift();
|
|
|
|
+ if (!queue.length) load && load();
|
|
|
|
+ }, 100);
|
|
|
|
+ return Promise.reject(error);
|
|
|
|
+ }
|
|
|
|
+);
|
|
|
|
+
|
|
|
|
+new Vue({
|
|
|
|
+ router,
|
|
|
|
+ store,
|
|
|
|
+ render: h => h(App)
|
|
|
|
+}).$mount("#app");
|