zmdms-utils 0.0.61 → 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.
- package/dist/es/baseUrl.d.ts +15 -1
- package/dist/es/baseUrl.js +23 -22
- package/dist/es/htmlToPdf.d.ts +4 -0
- package/dist/es/htmlToPdf.js +3 -1
- package/dist/es/pdf.js +5 -5
- package/dist/es/request.d.ts +4 -0
- package/dist/es/request.js +8 -0
- package/package.json +49 -49
- package/src/baseUrl.ts +46 -23
- package/src/htmlToPdf.ts +7 -0
- package/src/pdf.ts +4 -9
- package/src/request.ts +9 -0
package/dist/es/baseUrl.d.ts
CHANGED
|
@@ -1,4 +1,18 @@
|
|
|
1
|
-
|
|
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;
|
package/dist/es/baseUrl.js
CHANGED
|
@@ -1,40 +1,41 @@
|
|
|
1
1
|
// 根据当前环境变量获取基础的URL
|
|
2
|
-
function getBaseUrl(processObj) {
|
|
3
|
-
var
|
|
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.
|
|
7
|
-
test: processObj.
|
|
8
|
-
stage: processObj.
|
|
9
|
-
prod: processObj.
|
|
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.
|
|
14
|
-
test: processObj.
|
|
15
|
-
stage: processObj.
|
|
16
|
-
prod: processObj.
|
|
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.
|
|
21
|
-
test: processObj.
|
|
22
|
-
stage: processObj.
|
|
23
|
-
prod: processObj.
|
|
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.
|
|
28
|
-
test: processObj.
|
|
29
|
-
stage: processObj.
|
|
30
|
-
prod: processObj.
|
|
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.
|
|
35
|
-
test: processObj.
|
|
36
|
-
stage: processObj.
|
|
37
|
-
prod: processObj.
|
|
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 {
|
package/dist/es/htmlToPdf.d.ts
CHANGED
package/dist/es/htmlToPdf.js
CHANGED
|
@@ -5,7 +5,7 @@ import { domToCanvas } from './canvas.js';
|
|
|
5
5
|
|
|
6
6
|
function htmlToPdf(config) {
|
|
7
7
|
var _this = this;
|
|
8
|
-
var container = config.container, pageDom = config.pageDom, _a = config.useCanvas, useCanvas = _a === void 0 ? true : _a, isMultiple = config.isMultiple, pdfConfig = config.pdfConfig, pdfName = config.pdfName, isDownload = config.isDownload, waterConfig = config.waterConfig;
|
|
8
|
+
var container = config.container, pageDom = config.pageDom, _a = config.useCanvas, useCanvas = _a === void 0 ? true : _a, isMultiple = config.isMultiple, pdfConfig = config.pdfConfig, pdfName = config.pdfName, isDownload = config.isDownload, waterConfig = config.waterConfig, leftPadding = config.leftPadding;
|
|
9
9
|
// 找到需要转换的dom
|
|
10
10
|
var domList;
|
|
11
11
|
if (typeof pageDom === "string") {
|
|
@@ -44,6 +44,7 @@ function htmlToPdf(config) {
|
|
|
44
44
|
height: canvasHeight,
|
|
45
45
|
},
|
|
46
46
|
pdfConfig: pdfConfig,
|
|
47
|
+
leftPadding: leftPadding,
|
|
47
48
|
pdfDownloadConfig: {
|
|
48
49
|
isDownload: isDownload,
|
|
49
50
|
pdfName: pdfName ? pdfName : dataTitle,
|
|
@@ -75,6 +76,7 @@ function htmlToPdf(config) {
|
|
|
75
76
|
pdfName: pdfName ? pdfName : dataTitle,
|
|
76
77
|
},
|
|
77
78
|
waterConfig: waterConfig,
|
|
79
|
+
leftPadding: leftPadding,
|
|
78
80
|
});
|
|
79
81
|
}
|
|
80
82
|
}
|
package/dist/es/pdf.js
CHANGED
|
@@ -3,13 +3,13 @@ import { jsPDF } from 'jspdf';
|
|
|
3
3
|
import dayjs from 'dayjs';
|
|
4
4
|
|
|
5
5
|
function imgToPdf(config) {
|
|
6
|
-
var images = config.images,
|
|
7
|
-
var
|
|
6
|
+
var images = config.images, leftPadding = config.leftPadding, pdfConfig = config.pdfConfig, pdfDownloadConfig = config.pdfDownloadConfig, waterConfig = config.waterConfig;
|
|
7
|
+
var _a = pdfDownloadConfig || {}, isDownload = _a.isDownload, pdfName = _a.pdfName;
|
|
8
8
|
if (Array.isArray(images)) {
|
|
9
9
|
// 合并成一个pdf导出
|
|
10
10
|
// 解析pdf参数
|
|
11
11
|
var resultPdfConfig = parsePdfConfig(pdfConfig);
|
|
12
|
-
var
|
|
12
|
+
var _b = resultPdfConfig.format, pdfWidth_1 = _b[0], pdfHeight_1 = _b[1];
|
|
13
13
|
// 创建一个新的jsPDF实例
|
|
14
14
|
var pdf_1 = new jsPDF(resultPdfConfig);
|
|
15
15
|
return (function () {
|
|
@@ -116,7 +116,7 @@ function parsePdfConfig(pdfConfig) {
|
|
|
116
116
|
}
|
|
117
117
|
// 将图片插入pdf中
|
|
118
118
|
function insertImgToPdf(pdf, pdfWidth, pdfHeight, config) {
|
|
119
|
-
var imageConfig = config.imageConfig, _a = config.leftPadding, leftPadding = _a === void 0 ?
|
|
119
|
+
var imageConfig = config.imageConfig, _a = config.leftPadding, leftPadding = _a === void 0 ? 15 : _a, waterConfig = config.waterConfig;
|
|
120
120
|
var image = imageConfig.image, width = imageConfig.width, height = imageConfig.height;
|
|
121
121
|
// 缩放图片 以适应PDF页面宽度
|
|
122
122
|
var canvasWidth = width; // 图片原始宽度
|
|
@@ -124,7 +124,7 @@ function insertImgToPdf(pdf, pdfWidth, pdfHeight, config) {
|
|
|
124
124
|
// 一页pdf能显示的canvas高度
|
|
125
125
|
var pageHeight = (canvasWidth / pdfWidth) * pdfHeight;
|
|
126
126
|
// 将绘制图片的宽度 设置 成pdf的宽度 (减去偏移)
|
|
127
|
-
var imgWidth = pdfWidth - leftPadding;
|
|
127
|
+
var imgWidth = pdfWidth - leftPadding * 2;
|
|
128
128
|
// 等比例换算绘制图片高度
|
|
129
129
|
var imgHeight = (imgWidth / canvasWidth) * canvasHeight;
|
|
130
130
|
// 需要打印的图片总高度,初始状态和图片高度相等
|
package/dist/es/request.d.ts
CHANGED
package/dist/es/request.js
CHANGED
|
@@ -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.
|
|
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
|
|
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
|
|
8
|
-
test: processObj
|
|
9
|
-
stage: processObj
|
|
10
|
-
prod: processObj
|
|
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
|
|
16
|
-
test: processObj
|
|
17
|
-
stage: processObj
|
|
18
|
-
prod: processObj
|
|
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
|
|
24
|
-
test: processObj
|
|
25
|
-
stage: processObj
|
|
26
|
-
prod: processObj
|
|
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
|
|
32
|
-
test:
|
|
33
|
-
|
|
34
|
-
|
|
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
|
|
41
|
-
test: processObj
|
|
63
|
+
dev: processObj[`${logoutKey}_DEV`] || "/login",
|
|
64
|
+
test: processObj[`${logoutKey}_DEV`] || "/login",
|
|
42
65
|
stage:
|
|
43
|
-
processObj
|
|
44
|
-
prod: processObj
|
|
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/htmlToPdf.ts
CHANGED
|
@@ -28,6 +28,10 @@ interface IConfig {
|
|
|
28
28
|
* pdf相关配置
|
|
29
29
|
*/
|
|
30
30
|
pdfConfig?: IImgToPdfConfig["pdfConfig"];
|
|
31
|
+
/**
|
|
32
|
+
* 生成PDF的左边距
|
|
33
|
+
*/
|
|
34
|
+
leftPadding?: number;
|
|
31
35
|
/**
|
|
32
36
|
* 是否下载pdf
|
|
33
37
|
*/
|
|
@@ -48,6 +52,7 @@ export function htmlToPdf(config: IConfig) {
|
|
|
48
52
|
pdfName,
|
|
49
53
|
isDownload,
|
|
50
54
|
waterConfig,
|
|
55
|
+
leftPadding,
|
|
51
56
|
} = config;
|
|
52
57
|
// 找到需要转换的dom
|
|
53
58
|
let domList: any;
|
|
@@ -88,6 +93,7 @@ export function htmlToPdf(config: IConfig) {
|
|
|
88
93
|
height: canvasHeight,
|
|
89
94
|
},
|
|
90
95
|
pdfConfig,
|
|
96
|
+
leftPadding,
|
|
91
97
|
pdfDownloadConfig: {
|
|
92
98
|
isDownload,
|
|
93
99
|
pdfName: pdfName ? pdfName : dataTitle,
|
|
@@ -115,6 +121,7 @@ export function htmlToPdf(config: IConfig) {
|
|
|
115
121
|
pdfName: pdfName ? pdfName : dataTitle,
|
|
116
122
|
},
|
|
117
123
|
waterConfig,
|
|
124
|
+
leftPadding,
|
|
118
125
|
});
|
|
119
126
|
}
|
|
120
127
|
}
|
package/src/pdf.ts
CHANGED
|
@@ -3,13 +3,8 @@ import dayjs from "dayjs";
|
|
|
3
3
|
import { IWaterResult } from "./water";
|
|
4
4
|
|
|
5
5
|
export function imgToPdf(config: IImgToPdfConfig) {
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
leftPadding = 20,
|
|
9
|
-
pdfConfig,
|
|
10
|
-
pdfDownloadConfig,
|
|
11
|
-
waterConfig,
|
|
12
|
-
} = config;
|
|
6
|
+
const { images, leftPadding, pdfConfig, pdfDownloadConfig, waterConfig } =
|
|
7
|
+
config;
|
|
13
8
|
const { isDownload, pdfName } = pdfDownloadConfig || {};
|
|
14
9
|
if (Array.isArray(images)) {
|
|
15
10
|
// 合并成一个pdf导出
|
|
@@ -118,7 +113,7 @@ export function insertImgToPdf(
|
|
|
118
113
|
waterConfig?: IWaterResult;
|
|
119
114
|
}
|
|
120
115
|
) {
|
|
121
|
-
const { imageConfig, leftPadding =
|
|
116
|
+
const { imageConfig, leftPadding = 15, waterConfig } = config;
|
|
122
117
|
const { image, width, height } = imageConfig;
|
|
123
118
|
// 缩放图片 以适应PDF页面宽度
|
|
124
119
|
const canvasWidth = width; // 图片原始宽度
|
|
@@ -127,7 +122,7 @@ export function insertImgToPdf(
|
|
|
127
122
|
// 一页pdf能显示的canvas高度
|
|
128
123
|
let pageHeight = (canvasWidth / pdfWidth) * pdfHeight;
|
|
129
124
|
// 将绘制图片的宽度 设置 成pdf的宽度 (减去偏移)
|
|
130
|
-
let imgWidth = pdfWidth - leftPadding;
|
|
125
|
+
let imgWidth = pdfWidth - leftPadding * 2;
|
|
131
126
|
// 等比例换算绘制图片高度
|
|
132
127
|
let imgHeight = (imgWidth / canvasWidth) * canvasHeight;
|
|
133
128
|
// 需要打印的图片总高度,初始状态和图片高度相等
|
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 */
|