zmdms-utils 0.0.62 → 0.0.63

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.
@@ -1,4 +1,18 @@
1
- declare function getBaseUrl(processObj: any): {
1
+ interface IOptions {
2
+ /** 环境变量key值 */
3
+ envKey: string;
4
+ /** api地址的前缀key */
5
+ apiKey: string;
6
+ /** 附件服务器前缀key */
7
+ fileKey: string;
8
+ /** 退出登录默认的key */
9
+ logoutKey: string;
10
+ /** 数字中心各个环境key值 */
11
+ cicomsKey?: string;
12
+ /** 外网服务器前缀key值 */
13
+ outKey?: string;
14
+ }
15
+ declare function getBaseUrl(processObj: any, options?: IOptions): {
2
16
  API_URL: any;
3
17
  CICOMS_API_URL: any;
4
18
  FILE_URL: any;
@@ -1,40 +1,41 @@
1
1
  // 根据当前环境变量获取基础的URL
2
- function getBaseUrl(processObj) {
3
- var ENV = processObj.REACT_APP_ENV; // 获取当前环境变量
2
+ function getBaseUrl(processObj, options) {
3
+ var _a = options || {}, _b = _a.envKey, envKey = _b === void 0 ? "REACT_APP_ENV" : _b, _c = _a.apiKey, apiKey = _c === void 0 ? "REACT_APP_API" : _c, _d = _a.fileKey, fileKey = _d === void 0 ? "REACT_APP_FILE" : _d, _e = _a.logoutKey, logoutKey = _e === void 0 ? "REACT_APP_LOGOUT" : _e, _f = _a.cicomsKey, cicomsKey = _f === void 0 ? "REACT_APP_CICOMS_API" : _f, _g = _a.outKey, outKey = _g === void 0 ? "REACT_APP_OUTHR_API" : _g;
4
+ var ENV = processObj[envKey]; // 获取当前环境变量
4
5
  // api各个环境地址
5
6
  var apiBaseUrlObj = {
6
- dev: processObj.REACT_APP_API_DEV || "http://192.168.0.134:8000",
7
- test: processObj.REACT_APP_API_TEST || window.location.origin,
8
- stage: processObj.REACT_APP_API_STAGE || window.location.origin,
9
- prod: processObj.REACT_APP_API_PROD || window.location.origin,
7
+ dev: processObj["".concat(apiKey, "_DEV")] || "http://192.168.0.134:8000",
8
+ test: processObj["".concat(apiKey, "_TEST")] || window.location.origin,
9
+ stage: processObj["".concat(apiKey, "_STAGE")] || window.location.origin,
10
+ prod: processObj["".concat(apiKey, "_PROD")] || window.location.origin,
10
11
  };
11
12
  // 数字中心各个环境地址
12
13
  var cicomsApiBaseUrlObj = {
13
- dev: processObj.REACT_APP_CICOMS_API_DEV || window.location.origin,
14
- test: processObj.REACT_APP_CICOMS_API_TEST || window.location.origin,
15
- stage: processObj.REACT_APP_CICOMS_API_STAGE || window.location.origin,
16
- prod: processObj.REACT_APP_CICOMS_API_PROD || window.location.origin,
14
+ dev: processObj["".concat(cicomsKey, "_DEV")] || window.location.origin,
15
+ test: processObj["".concat(cicomsKey, "_TEST")] || window.location.origin,
16
+ stage: processObj["".concat(cicomsKey, "_STAGE")] || window.location.origin,
17
+ prod: processObj["".concat(cicomsKey, "_PROD")] || window.location.origin,
17
18
  };
18
19
  // file 服务器
19
20
  var fileBaseUrlObj = {
20
- dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.134:8000",
21
- test: processObj.REACT_APP_FILE_TEST || window.location.origin,
22
- stage: processObj.REACT_APP_FILE_STAGE || window.location.origin,
23
- prod: processObj.REACT_APP_FILE_PROD || window.location.origin,
21
+ dev: processObj["".concat(fileKey, "_DEV")] || "http://192.168.0.134:8000",
22
+ test: processObj["".concat(fileKey, "_TEST")] || window.location.origin,
23
+ stage: processObj["".concat(fileKey, "_STAGE")] || window.location.origin,
24
+ prod: processObj["".concat(fileKey, "_PROD")] || window.location.origin,
24
25
  };
25
26
  // 外网项目各个环境地址
26
27
  var outHrDomain = {
27
- dev: processObj.REACT_APP_OUTHR_API_DEV || "http://192.168.0.134:18886",
28
- test: processObj.REACT_APP_OUTHR_API_TEST || "http://hr-out.cico.com.cn:30601",
29
- stage: processObj.REACT_APP_OUTHR_API_STAGE || "http://10.100.234.36:18886",
30
- prod: processObj.REACT_APP_OUTHR_API_PROD || "https://dhr.cncico.com:18443",
28
+ dev: processObj["".concat(outKey, "_DEV")] || "http://192.168.0.134:18886",
29
+ test: processObj["".concat(outKey, "_TEST")] || "http://hr-out.cico.com.cn:30601",
30
+ stage: processObj["".concat(outKey, "_STAGE")] || "http://10.100.234.36:18886",
31
+ prod: processObj["".concat(outKey, "_PROD")] || "https://dhr.cncico.com:18443",
31
32
  };
32
33
  // 退出登录地址
33
34
  var logoutUrl = {
34
- dev: processObj.REACT_APP_LOGOUT_DEV || "/login",
35
- test: processObj.REACT_APP_LOGOUT_TEST || "/login",
36
- stage: processObj.REACT_APP_LOGOUT_STAGE || "http://testportal.cncico.com:8099/",
37
- prod: processObj.REACT_APP_LOGOUT_PROD || "http://newportal.cncico.com/",
35
+ dev: processObj["".concat(logoutKey, "_DEV")] || "/login",
36
+ test: processObj["".concat(logoutKey, "_DEV")] || "/login",
37
+ stage: processObj["".concat(logoutKey, "_DEV")] || "http://testportal.cncico.com:8099/",
38
+ prod: processObj["".concat(logoutKey, "_DEV")] || "http://newportal.cncico.com/",
38
39
  };
39
40
  var currentKey = ENV.toLowerCase() || "prod";
40
41
  return {
@@ -60,6 +60,10 @@ interface IOtherOptions {
60
60
  TenantId?: string;
61
61
  /** auth值 */
62
62
  Authorization?: string;
63
+ /** 公用请求头 */
64
+ commonHeaders?: {
65
+ [prop: string]: any;
66
+ };
63
67
  /** 超时时间 */
64
68
  timeout?: number;
65
69
  /** 基础url */
@@ -34,11 +34,19 @@ var AxiosRequest = /** @class */ (function () {
34
34
  }
35
35
  // 设置axios方法默认值
36
36
  AxiosRequest.prototype.defaultSetting = function () {
37
+ var _this = this;
37
38
  // 设置默认请求头
38
39
  this.instanceAxios.defaults.headers.common["Tenant-Id"] =
39
40
  this.otherOptions.TenantId;
40
41
  this.instanceAxios.defaults.headers.common["Authorization"] =
41
42
  this.otherOptions.Authorization;
43
+ if (this.otherOptions.commonHeaders) {
44
+ Object.keys(this.otherOptions.commonHeaders).forEach(function (key) {
45
+ var _a;
46
+ _this.instanceAxios.defaults.headers.common[key] =
47
+ (_a = _this.otherOptions.commonHeaders) === null || _a === void 0 ? void 0 : _a[key];
48
+ });
49
+ }
42
50
  // 其他默认参数
43
51
  this.instanceAxios.defaults.timeout = this.otherOptions.timeout;
44
52
  this.instanceAxios.defaults.baseURL = this.otherOptions.baseURL;
package/package.json CHANGED
@@ -1,49 +1,49 @@
1
- {
2
- "name": "zmdms-utils",
3
- "version": "0.0.62",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "module": "dist/index.js",
7
- "type": "module",
8
- "scripts": {
9
- "clean": "rimraf ./dist",
10
- "build": "npm run clean && npm run build-es",
11
- "build-es": "npm run clean && rollup --config ./rollup.esm.config.js"
12
- },
13
- "author": "",
14
- "license": "ISC",
15
- "peerDependencies": {
16
- "axios": "^1.4.0",
17
- "crypto-js": "^4.1.1",
18
- "dayjs": "^1.11.7",
19
- "html2canvas": "^1.4.1",
20
- "jspdf": "^2.5.1",
21
- "print-js": "^1.6.0",
22
- "qiankun": "^2.10.8"
23
- },
24
- "dependencies": {
25
- "decimal.js": "^10.4.3",
26
- "jwt-decode": "3.1.2",
27
- "mitt": "^3.0.0",
28
- "pinyin-pro": "^3.18.2"
29
- },
30
- "devDependencies": {
31
- "@rollup/plugin-commonjs": "^24.0.1",
32
- "@rollup/plugin-json": "^6.0.0",
33
- "@rollup/plugin-node-resolve": "^15.0.1",
34
- "@types/crypto-js": "^4.1.1",
35
- "axios": "^1.4.0",
36
- "crypto-js": "^4.1.1",
37
- "dayjs": "^1.11.10",
38
- "html2canvas": "^1.4.1",
39
- "jspdf": "^2.5.1",
40
- "print-js": "^1.6.0",
41
- "qiankun": "^2.10.8",
42
- "rimraf": "^4.4.1",
43
- "rollup": "^3.20.2",
44
- "rollup-plugin-dts": "^5.3.0",
45
- "rollup-plugin-peer-deps-external": "^2.2.4",
46
- "rollup-plugin-typescript2": "^0.34.1",
47
- "typescript": "^5.0.2"
48
- }
49
- }
1
+ {
2
+ "name": "zmdms-utils",
3
+ "version": "0.0.63",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "module": "dist/index.js",
7
+ "type": "module",
8
+ "scripts": {
9
+ "clean": "rimraf ./dist",
10
+ "build": "npm run clean && npm run build-es",
11
+ "build-es": "npm run clean && rollup --config ./rollup.esm.config.js"
12
+ },
13
+ "author": "",
14
+ "license": "ISC",
15
+ "peerDependencies": {
16
+ "axios": "^1.4.0",
17
+ "crypto-js": "^4.1.1",
18
+ "dayjs": "^1.11.7",
19
+ "html2canvas": "^1.4.1",
20
+ "jspdf": "^2.5.1",
21
+ "print-js": "^1.6.0",
22
+ "qiankun": "^2.10.8"
23
+ },
24
+ "dependencies": {
25
+ "decimal.js": "^10.4.3",
26
+ "jwt-decode": "3.1.2",
27
+ "mitt": "^3.0.0",
28
+ "pinyin-pro": "^3.18.2"
29
+ },
30
+ "devDependencies": {
31
+ "@rollup/plugin-commonjs": "^24.0.1",
32
+ "@rollup/plugin-json": "^6.0.0",
33
+ "@rollup/plugin-node-resolve": "^15.0.1",
34
+ "@types/crypto-js": "^4.1.1",
35
+ "axios": "^1.4.0",
36
+ "crypto-js": "^4.1.1",
37
+ "dayjs": "^1.11.10",
38
+ "html2canvas": "^1.4.1",
39
+ "jspdf": "^2.5.1",
40
+ "print-js": "^1.6.0",
41
+ "qiankun": "^2.10.8",
42
+ "rimraf": "^4.4.1",
43
+ "rollup": "^3.20.2",
44
+ "rollup-plugin-dts": "^5.3.0",
45
+ "rollup-plugin-peer-deps-external": "^2.2.4",
46
+ "rollup-plugin-typescript2": "^0.34.1",
47
+ "typescript": "^5.0.2"
48
+ }
49
+ }
package/src/baseUrl.ts CHANGED
@@ -1,47 +1,70 @@
1
+ interface IOptions {
2
+ /** 环境变量key值 */
3
+ envKey: string;
4
+ /** api地址的前缀key */
5
+ apiKey: string;
6
+ /** 附件服务器前缀key */
7
+ fileKey: string;
8
+ /** 退出登录默认的key */
9
+ logoutKey: string;
10
+ /** 数字中心各个环境key值 */
11
+ cicomsKey?: string;
12
+ /** 外网服务器前缀key值 */
13
+ outKey?: string;
14
+ }
15
+
1
16
  // 根据当前环境变量获取基础的URL
2
- export function getBaseUrl(processObj: any) {
3
- const ENV = processObj.REACT_APP_ENV; // 获取当前环境变量
17
+ export function getBaseUrl(processObj: any, options?: IOptions) {
18
+ const {
19
+ envKey = "REACT_APP_ENV",
20
+ apiKey = "REACT_APP_API",
21
+ fileKey = "REACT_APP_FILE",
22
+ logoutKey = "REACT_APP_LOGOUT",
23
+ cicomsKey = "REACT_APP_CICOMS_API",
24
+ outKey = "REACT_APP_OUTHR_API",
25
+ } = options || {};
26
+
27
+ const ENV = processObj[envKey]; // 获取当前环境变量
4
28
 
5
29
  // api各个环境地址
6
30
  const apiBaseUrlObj: any = {
7
- dev: processObj.REACT_APP_API_DEV || "http://192.168.0.134:8000",
8
- test: processObj.REACT_APP_API_TEST || window.location.origin,
9
- stage: processObj.REACT_APP_API_STAGE || window.location.origin,
10
- prod: processObj.REACT_APP_API_PROD || window.location.origin,
31
+ dev: processObj[`${apiKey}_DEV`] || "http://192.168.0.134:8000",
32
+ test: processObj[`${apiKey}_TEST`] || window.location.origin,
33
+ stage: processObj[`${apiKey}_STAGE`] || window.location.origin,
34
+ prod: processObj[`${apiKey}_PROD`] || window.location.origin,
11
35
  };
12
36
 
13
37
  // 数字中心各个环境地址
14
38
  const cicomsApiBaseUrlObj: any = {
15
- dev: processObj.REACT_APP_CICOMS_API_DEV || window.location.origin,
16
- test: processObj.REACT_APP_CICOMS_API_TEST || window.location.origin,
17
- stage: processObj.REACT_APP_CICOMS_API_STAGE || window.location.origin,
18
- prod: processObj.REACT_APP_CICOMS_API_PROD || window.location.origin,
39
+ dev: processObj[`${cicomsKey}_DEV`] || window.location.origin,
40
+ test: processObj[`${cicomsKey}_TEST`] || window.location.origin,
41
+ stage: processObj[`${cicomsKey}_STAGE`] || window.location.origin,
42
+ prod: processObj[`${cicomsKey}_PROD`] || window.location.origin,
19
43
  };
20
44
 
21
45
  // file 服务器
22
46
  const fileBaseUrlObj: any = {
23
- dev: processObj.REACT_APP_FILE_DEV || "http://192.168.0.134:8000",
24
- test: processObj.REACT_APP_FILE_TEST || window.location.origin,
25
- stage: processObj.REACT_APP_FILE_STAGE || window.location.origin,
26
- prod: processObj.REACT_APP_FILE_PROD || window.location.origin,
47
+ dev: processObj[`${fileKey}_DEV`] || "http://192.168.0.134:8000",
48
+ test: processObj[`${fileKey}_TEST`] || window.location.origin,
49
+ stage: processObj[`${fileKey}_STAGE`] || window.location.origin,
50
+ prod: processObj[`${fileKey}_PROD`] || window.location.origin,
27
51
  };
28
52
 
29
53
  // 外网项目各个环境地址
30
54
  const outHrDomain: any = {
31
- dev: processObj.REACT_APP_OUTHR_API_DEV || "http://192.168.0.134:18886",
32
- test:
33
- processObj.REACT_APP_OUTHR_API_TEST || "http://hr-out.cico.com.cn:30601",
34
- stage: processObj.REACT_APP_OUTHR_API_STAGE || "http://10.100.234.36:18886",
35
- prod: processObj.REACT_APP_OUTHR_API_PROD || "https://dhr.cncico.com:18443",
55
+ dev: processObj[`${outKey}_DEV`] || "http://192.168.0.134:18886",
56
+ test: processObj[`${outKey}_TEST`] || "http://hr-out.cico.com.cn:30601",
57
+ stage: processObj[`${outKey}_STAGE`] || "http://10.100.234.36:18886",
58
+ prod: processObj[`${outKey}_PROD`] || "https://dhr.cncico.com:18443",
36
59
  };
37
60
 
38
61
  // 退出登录地址
39
62
  const logoutUrl: any = {
40
- dev: processObj.REACT_APP_LOGOUT_DEV || "/login",
41
- test: processObj.REACT_APP_LOGOUT_TEST || "/login",
63
+ dev: processObj[`${logoutKey}_DEV`] || "/login",
64
+ test: processObj[`${logoutKey}_DEV`] || "/login",
42
65
  stage:
43
- processObj.REACT_APP_LOGOUT_STAGE || "http://testportal.cncico.com:8099/",
44
- prod: processObj.REACT_APP_LOGOUT_PROD || "http://newportal.cncico.com/",
66
+ processObj[`${logoutKey}_DEV`] || "http://testportal.cncico.com:8099/",
67
+ prod: processObj[`${logoutKey}_DEV`] || "http://newportal.cncico.com/",
45
68
  };
46
69
 
47
70
  const currentKey = ENV.toLowerCase() || "prod";
package/src/request.ts CHANGED
@@ -67,6 +67,13 @@ export class AxiosRequest {
67
67
  this.instanceAxios.defaults.headers.common["Authorization"] =
68
68
  this.otherOptions.Authorization;
69
69
 
70
+ if (this.otherOptions.commonHeaders) {
71
+ Object.keys(this.otherOptions.commonHeaders).forEach((key) => {
72
+ this.instanceAxios.defaults.headers.common[key] =
73
+ this.otherOptions.commonHeaders?.[key];
74
+ });
75
+ }
76
+
70
77
  // 其他默认参数
71
78
  this.instanceAxios.defaults.timeout = this.otherOptions.timeout;
72
79
  this.instanceAxios.defaults.baseURL = this.otherOptions.baseURL;
@@ -399,6 +406,8 @@ export interface IOtherOptions {
399
406
  TenantId?: string;
400
407
  /** auth值 */
401
408
  Authorization?: string;
409
+ /** 公用请求头 */
410
+ commonHeaders?: { [prop: string]: any };
402
411
  /** 超时时间 */
403
412
  timeout?: number;
404
413
  /** 基础url */