|
@@ -1,185 +1,192 @@
|
|
import axios from "axios";
|
|
import axios from "axios";
|
|
-import { ElMessage, ElNotification } from "element-plus";
|
|
|
|
|
|
+import {ElMessage, ElNotification} from "element-plus";
|
|
import router from "@/router";
|
|
import router from "@/router";
|
|
-import { endLoading, startLoading } from "./loading";
|
|
|
|
-import { CyMessageBox } from "@/components/cy/message-box";
|
|
|
|
-import { useProgressBarStore } from "@/pinia/progress-bar-store";
|
|
|
|
|
|
+import {endLoading, startLoading} from "./loading";
|
|
|
|
+import {CyMessageBox} from "@/components/cy/message-box";
|
|
|
|
+import {useProgressBarStore} from "@/pinia/progress-bar-store";
|
|
import XEUtils from "xe-utils";
|
|
import XEUtils from "xe-utils";
|
|
-import { stringify } from "qs";
|
|
|
|
|
|
+import {stringify} from "qs";
|
|
import env from "@/utils/setting";
|
|
import env from "@/utils/setting";
|
|
|
|
|
|
const service = axios.create({
|
|
const service = axios.create({
|
|
- baseURL: env.VITE_BASE_URL,
|
|
|
|
- withCredentials: true,
|
|
|
|
- timeout: 0,
|
|
|
|
- showLoading: true,
|
|
|
|
- paramsSerializer: {
|
|
|
|
- serialize: stringify,
|
|
|
|
- },
|
|
|
|
|
|
+ baseURL: env.VITE_BASE_URL,
|
|
|
|
+ withCredentials: true,
|
|
|
|
+ timeout: 0,
|
|
|
|
+ showLoading: true,
|
|
|
|
+ paramsSerializer: {
|
|
|
|
+ serialize: stringify,
|
|
|
|
+ },
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+let onceFun = null;
|
|
/*axios请求拦截*/
|
|
/*axios请求拦截*/
|
|
service.interceptors.request.use(
|
|
service.interceptors.request.use(
|
|
- config => {
|
|
|
|
- if (typeof config.jdtTitle !== "undefined") {
|
|
|
|
- useProgressBarStore().initialize({
|
|
|
|
- title: config.jdtTitle,
|
|
|
|
- isOpen: true,
|
|
|
|
- closeButton: false,
|
|
|
|
- });
|
|
|
|
- } else {
|
|
|
|
- if (
|
|
|
|
- config.url !== "/caseFrontSheet/printVerify" &&
|
|
|
|
- !config.url.startsWith("/mixLabelPrint")
|
|
|
|
- ) {
|
|
|
|
- if (config.showLoading) {
|
|
|
|
- startLoading();
|
|
|
|
|
|
+ config => {
|
|
|
|
+ if (typeof config.jdtTitle !== "undefined") {
|
|
|
|
+ useProgressBarStore().initialize({
|
|
|
|
+ title: config.jdtTitle,
|
|
|
|
+ isOpen: true,
|
|
|
|
+ closeButton: false,
|
|
|
|
+ });
|
|
|
|
+ } else {
|
|
|
|
+ if (
|
|
|
|
+ config.url !== "/caseFrontSheet/printVerify" &&
|
|
|
|
+ !config.url.startsWith("/mixLabelPrint")
|
|
|
|
+ ) {
|
|
|
|
+ if (config.showLoading) {
|
|
|
|
+ startLoading();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
+ config.headers["token"] = localStorage.token;
|
|
|
|
+ return config;
|
|
|
|
+ },
|
|
|
|
+ error => {
|
|
|
|
+ endLoading();
|
|
|
|
+ return Promise.reject(error);
|
|
}
|
|
}
|
|
- config.headers["token"] = localStorage.token;
|
|
|
|
- return config;
|
|
|
|
- },
|
|
|
|
- error => {
|
|
|
|
- endLoading();
|
|
|
|
- return Promise.reject(error);
|
|
|
|
- }
|
|
|
|
);
|
|
);
|
|
|
|
|
|
service.interceptors.response.use(
|
|
service.interceptors.response.use(
|
|
- response => {
|
|
|
|
- endLoading();
|
|
|
|
- if (response.data.code === 200 || response.data.code === 0) {
|
|
|
|
- return response.data.data;
|
|
|
|
- }
|
|
|
|
- if (response.data.code === 2002) {
|
|
|
|
- return response.data;
|
|
|
|
- }
|
|
|
|
- if (response.data.code === 201) {
|
|
|
|
- ElMessage({
|
|
|
|
- type: "success",
|
|
|
|
- title: "成功",
|
|
|
|
- duration: 3500,
|
|
|
|
- dangerouslyUseHTMLString: true,
|
|
|
|
- message: response.data.message,
|
|
|
|
- });
|
|
|
|
- return response.data.data;
|
|
|
|
- }
|
|
|
|
- if (response.data.code === 202) {
|
|
|
|
- CyMessageBox.alert({
|
|
|
|
- type: "success",
|
|
|
|
- message: response.data.message,
|
|
|
|
- dangerouslyUseHTMLString: true,
|
|
|
|
- }).then(XEUtils.noop);
|
|
|
|
- return response.data.data;
|
|
|
|
- }
|
|
|
|
- if (response.data.code === 203) {
|
|
|
|
- ElNotification({
|
|
|
|
- type: "success",
|
|
|
|
- message: response.data.message,
|
|
|
|
- duration: 3000,
|
|
|
|
- title: "成功",
|
|
|
|
- });
|
|
|
|
- return response.data.data;
|
|
|
|
- }
|
|
|
|
|
|
+ response => {
|
|
|
|
+ endLoading();
|
|
|
|
+ if (response.data.code === 200 || response.data.code === 0) {
|
|
|
|
+ return response.data.data;
|
|
|
|
+ }
|
|
|
|
+ if (response.data.code === 2002) {
|
|
|
|
+ return response.data;
|
|
|
|
+ }
|
|
|
|
+ if (response.data.code === 201) {
|
|
|
|
+ ElMessage({
|
|
|
|
+ type: "success",
|
|
|
|
+ title: "成功",
|
|
|
|
+ duration: 3500,
|
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ });
|
|
|
|
+ return response.data.data;
|
|
|
|
+ }
|
|
|
|
+ if (response.data.code === 202) {
|
|
|
|
+ CyMessageBox.alert({
|
|
|
|
+ type: "success",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
|
+ }).then(XEUtils.noop);
|
|
|
|
+ return response.data.data;
|
|
|
|
+ }
|
|
|
|
+ if (response.data.code === 203) {
|
|
|
|
+ ElNotification({
|
|
|
|
+ type: "success",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ duration: 3000,
|
|
|
|
+ title: "成功",
|
|
|
|
+ });
|
|
|
|
+ return response.data.data;
|
|
|
|
+ }
|
|
|
|
|
|
- if (response.data.code > 1000 && response.data.code < 2000) {
|
|
|
|
- ElMessage({
|
|
|
|
- type: "error",
|
|
|
|
- message: response.data.message,
|
|
|
|
- duration: 3500,
|
|
|
|
- grouping: true,
|
|
|
|
- });
|
|
|
|
- } else if (response.data.code > 2000 && response.data.code < 3000) {
|
|
|
|
- if (response.data.code === 2003) {
|
|
|
|
- CyMessageBox.alert({
|
|
|
|
- type: "error",
|
|
|
|
- message: response.data.message,
|
|
|
|
- title: "提示",
|
|
|
|
- dangerouslyUseHTMLString: true,
|
|
|
|
- }).then(XEUtils.noop);
|
|
|
|
- } else {
|
|
|
|
- CyMessageBox.alert({
|
|
|
|
- type: "error",
|
|
|
|
- message: response.data.message,
|
|
|
|
- title: "提示",
|
|
|
|
- }).then(XEUtils.noop);
|
|
|
|
- }
|
|
|
|
- } else if (response.data.code > 3000 && response.data.code < 4000) {
|
|
|
|
- CyMessageBox.alert({
|
|
|
|
- type: "error",
|
|
|
|
- message: response.data.message,
|
|
|
|
- title: "提示",
|
|
|
|
- showIcon: false,
|
|
|
|
- }).then(() => {
|
|
|
|
- router.push("/login").then(XEUtils.noop);
|
|
|
|
- });
|
|
|
|
- } else if (response.data.code === 5001) {
|
|
|
|
- CyMessageBox.alert({
|
|
|
|
- type: "error",
|
|
|
|
- message: response.data.message,
|
|
|
|
- title: "提示",
|
|
|
|
- }).then(XEUtils.noop);
|
|
|
|
- }
|
|
|
|
- if (response.data.code === 6001) {
|
|
|
|
- ElMessage({
|
|
|
|
- message: response.data.message,
|
|
|
|
- type: "error",
|
|
|
|
- duration: 2500,
|
|
|
|
- grouping: true,
|
|
|
|
- });
|
|
|
|
- return {
|
|
|
|
- error: true,
|
|
|
|
- data: response.data.data,
|
|
|
|
- };
|
|
|
|
- } else if (response.data.code === 6002) {
|
|
|
|
- CyMessageBox.alert({
|
|
|
|
- type: "error",
|
|
|
|
- message: response.data.message,
|
|
|
|
- title: "提示",
|
|
|
|
- }).then(XEUtils.noop);
|
|
|
|
- return Promise.reject(response.data.data);
|
|
|
|
- }
|
|
|
|
|
|
+ if (response.data.code > 1000 && response.data.code < 2000) {
|
|
|
|
+ ElMessage({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ duration: 3500,
|
|
|
|
+ grouping: true,
|
|
|
|
+ });
|
|
|
|
+ } else if (response.data.code > 2000 && response.data.code < 3000) {
|
|
|
|
+ if (response.data.code === 2003) {
|
|
|
|
+ CyMessageBox.alert({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ title: "提示",
|
|
|
|
+ dangerouslyUseHTMLString: true,
|
|
|
|
+ }).then(XEUtils.noop);
|
|
|
|
+ } else {
|
|
|
|
+ CyMessageBox.alert({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ title: "提示",
|
|
|
|
+ }).then(XEUtils.noop);
|
|
|
|
+ }
|
|
|
|
+ } else if (response.data.code > 3000 && response.data.code < 4000) {
|
|
|
|
+ if (onceFun == null) {
|
|
|
|
+ onceFun = true
|
|
|
|
+ CyMessageBox.alert({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ title: "提示",
|
|
|
|
+ showIcon: false,
|
|
|
|
+ }).then(() => {
|
|
|
|
+ router.push("/login").then(XEUtils.noop);
|
|
|
|
+ }).finally(() => {
|
|
|
|
+ onceFun = null;
|
|
|
|
+ })
|
|
|
|
+ }
|
|
|
|
|
|
- if (response.data.code > 7000 && response.data.code < 8000) {
|
|
|
|
- CyMessageBox.alert({
|
|
|
|
- type: "error",
|
|
|
|
- message: response.data.message,
|
|
|
|
- title: "提示",
|
|
|
|
- }).then(XEUtils.noop);
|
|
|
|
- return Promise.reject(response.data);
|
|
|
|
- }
|
|
|
|
|
|
+ } else if (response.data.code === 5001) {
|
|
|
|
+ CyMessageBox.alert({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ title: "提示",
|
|
|
|
+ }).then(XEUtils.noop);
|
|
|
|
+ }
|
|
|
|
+ if (response.data.code === 6001) {
|
|
|
|
+ ElMessage({
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ type: "error",
|
|
|
|
+ duration: 2500,
|
|
|
|
+ grouping: true,
|
|
|
|
+ });
|
|
|
|
+ return {
|
|
|
|
+ error: true,
|
|
|
|
+ data: response.data.data,
|
|
|
|
+ };
|
|
|
|
+ } else if (response.data.code === 6002) {
|
|
|
|
+ CyMessageBox.alert({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ title: "提示",
|
|
|
|
+ }).then(XEUtils.noop);
|
|
|
|
+ return Promise.reject(response.data.data);
|
|
|
|
+ }
|
|
|
|
|
|
- if (response.data.data) {
|
|
|
|
- return Promise.reject(response.data);
|
|
|
|
- }
|
|
|
|
|
|
+ if (response.data.code > 7000 && response.data.code < 8000) {
|
|
|
|
+ CyMessageBox.alert({
|
|
|
|
+ type: "error",
|
|
|
|
+ message: response.data.message,
|
|
|
|
+ title: "提示",
|
|
|
|
+ }).then(XEUtils.noop);
|
|
|
|
+ return Promise.reject(response.data);
|
|
|
|
+ }
|
|
|
|
|
|
- return Promise.reject(response.data.message || "服务器内部错误");
|
|
|
|
- },
|
|
|
|
- error => {
|
|
|
|
- endLoading();
|
|
|
|
- // 取消请求,不显示 message
|
|
|
|
- if (error.code && error.code === "ERR_CANCELED") {
|
|
|
|
- useProgressBarStore().initialize({
|
|
|
|
- title: "",
|
|
|
|
- isOpen: false,
|
|
|
|
- closeButton: true,
|
|
|
|
- });
|
|
|
|
- return Promise.reject(error);
|
|
|
|
|
|
+ if (response.data.data) {
|
|
|
|
+ return Promise.reject(response.data);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Promise.reject(response.data.message || "服务器内部错误");
|
|
|
|
+ },
|
|
|
|
+ error => {
|
|
|
|
+ endLoading();
|
|
|
|
+ // 取消请求,不显示 message
|
|
|
|
+ if (error.code && error.code === "ERR_CANCELED") {
|
|
|
|
+ useProgressBarStore().initialize({
|
|
|
|
+ title: "",
|
|
|
|
+ isOpen: false,
|
|
|
|
+ closeButton: true,
|
|
|
|
+ });
|
|
|
|
+ return Promise.reject(error);
|
|
|
|
+ }
|
|
|
|
+ ElMessage({
|
|
|
|
+ message: error,
|
|
|
|
+ type: "error",
|
|
|
|
+ duration: 3500,
|
|
|
|
+ grouping: true,
|
|
|
|
+ });
|
|
|
|
+ useProgressBarStore().initialize({
|
|
|
|
+ title: "",
|
|
|
|
+ isOpen: false,
|
|
|
|
+ closeButton: true,
|
|
|
|
+ });
|
|
|
|
+ return Promise.reject(error);
|
|
}
|
|
}
|
|
- ElMessage({
|
|
|
|
- message: error,
|
|
|
|
- type: "error",
|
|
|
|
- duration: 3500,
|
|
|
|
- grouping: true,
|
|
|
|
- });
|
|
|
|
- useProgressBarStore().initialize({
|
|
|
|
- title: "",
|
|
|
|
- isOpen: false,
|
|
|
|
- closeButton: true,
|
|
|
|
- });
|
|
|
|
- return Promise.reject(error);
|
|
|
|
- }
|
|
|
|
);
|
|
);
|
|
|
|
|
|
export default service;
|
|
export default service;
|