zmdms-utils 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,3 @@
1
+ function getBaseUrl() { }
2
+
3
+ export { getBaseUrl };
@@ -17,9 +17,7 @@ var AxiosRequest = /** @class */ (function () {
17
17
  }
18
18
  // 设置axios方法默认值
19
19
  AxiosRequest.prototype.defaultSetting = function () {
20
- var token = getToken();
21
20
  // 设置默认请求头
22
- axios.defaults.headers.common["Zmdms-Auth"] = "bearer ".concat(token);
23
21
  axios.defaults.headers.common["Tenant-Id"] = this.otherOptions.TenantId;
24
22
  axios.defaults.headers.common["Authorization"] =
25
23
  this.otherOptions.Authorization;
@@ -38,6 +36,14 @@ var AxiosRequest = /** @class */ (function () {
38
36
  // 拦截响应
39
37
  AxiosRequest.prototype.interceptorsReponse = function () {
40
38
  axios.interceptors.response.use(function (response) {
39
+ if (response.status === 200) {
40
+ if (response.data.code === 200) {
41
+ return Promise.resolve(response.data);
42
+ }
43
+ }
44
+ else if (response.status === 201) {
45
+ return Promise.resolve(response);
46
+ }
41
47
  return response;
42
48
  }, function (error) {
43
49
  return Promise.reject(error);
@@ -46,12 +52,16 @@ var AxiosRequest = /** @class */ (function () {
46
52
  // 实例方法
47
53
  AxiosRequest.prototype.request = function (options) {
48
54
  var _a, _b, _c, _d, _e;
49
- var isFormData = options.isFormData; options.isAuth; var resetOptions = __rest(options, ["isFormData", "isAuth"]);
55
+ var token = getToken();
56
+ var isFormData = options.isFormData, _f = options.isAuth, isAuth = _f === void 0 ? true : _f, resetOptions = __rest(options, ["isFormData", "isAuth"]);
50
57
  var newOptions = resetOptions;
51
58
  // 自定义请求头
52
59
  if (!newOptions.headers) {
53
60
  newOptions.headers = {};
54
61
  }
62
+ if (isAuth) {
63
+ newOptions.headers["Zmdms-Auth"] = "bearer ".concat(token);
64
+ }
55
65
  // 处理url
56
66
  if ((_a = newOptions.baseURL) === null || _a === void 0 ? void 0 : _a.endsWith("/")) {
57
67
  newOptions.url = ((_b = newOptions.url) === null || _b === void 0 ? void 0 : _b.startsWith("/"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "zmdms-utils",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.js",
package/src/baseUrl.ts ADDED
@@ -0,0 +1 @@
1
+ export function getBaseUrl() {}
package/src/request.ts CHANGED
@@ -20,9 +20,7 @@ export class AxiosRequest {
20
20
 
21
21
  // 设置axios方法默认值
22
22
  private defaultSetting() {
23
- const token = getToken();
24
23
  // 设置默认请求头
25
- axios.defaults.headers.common["Zmdms-Auth"] = `bearer ${token}`;
26
24
  axios.defaults.headers.common["Tenant-Id"] = this.otherOptions.TenantId;
27
25
  axios.defaults.headers.common["Authorization"] =
28
26
  this.otherOptions.Authorization;
@@ -48,6 +46,13 @@ export class AxiosRequest {
48
46
  private interceptorsReponse() {
49
47
  axios.interceptors.response.use(
50
48
  (response) => {
49
+ if (response.status === 200) {
50
+ if (response.data.code === 200) {
51
+ return Promise.resolve(response.data);
52
+ }
53
+ } else if (response.status === 201) {
54
+ return Promise.resolve(response);
55
+ }
51
56
  return response;
52
57
  },
53
58
  (error) => {
@@ -58,6 +63,7 @@ export class AxiosRequest {
58
63
 
59
64
  // 实例方法
60
65
  public request(options: IOptions) {
66
+ const token = getToken();
61
67
  const { isFormData, isAuth = true, ...resetOptions } = options;
62
68
 
63
69
  const newOptions = resetOptions;
@@ -66,6 +72,9 @@ export class AxiosRequest {
66
72
  if (!newOptions.headers) {
67
73
  newOptions.headers = {};
68
74
  }
75
+ if (isAuth) {
76
+ newOptions.headers["Zmdms-Auth"] = `bearer ${token}`;
77
+ }
69
78
 
70
79
  // 处理url
71
80
  if (newOptions.baseURL?.endsWith("/")) {
File without changes