zmdms-utils 0.0.38 → 0.0.40
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/auth.d.ts +2 -1
- package/dist/es/auth.js +20 -1
- package/dist/es/node_modules/jwt-decode/build/jwt-decode.esm.js +3 -0
- package/dist/es/water.d.ts +2 -0
- package/dist/es/water.js +22 -7
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/package.json +4 -3
- package/src/auth.ts +20 -0
- package/src/index.ts +1 -1
- package/src/water.ts +26 -7
package/dist/es/auth.d.ts
CHANGED
|
@@ -4,5 +4,6 @@
|
|
|
4
4
|
declare function getToken(): string | null;
|
|
5
5
|
declare function setToken(token: string): void;
|
|
6
6
|
declare function removeToken(): void;
|
|
7
|
+
declare function parseToken(token?: string): unknown;
|
|
7
8
|
|
|
8
|
-
export { getToken, removeToken, setToken };
|
|
9
|
+
export { getToken, parseToken, removeToken, setToken };
|
package/dist/es/auth.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import o from './node_modules/jwt-decode/build/jwt-decode.esm.js';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 权限相关
|
|
3
5
|
*/
|
|
@@ -26,5 +28,22 @@ function removeToken() {
|
|
|
26
28
|
console.error("设置token失败", err);
|
|
27
29
|
}
|
|
28
30
|
}
|
|
31
|
+
function parseToken(token) {
|
|
32
|
+
var t = token;
|
|
33
|
+
if (!t) {
|
|
34
|
+
t = getToken();
|
|
35
|
+
}
|
|
36
|
+
if (t) {
|
|
37
|
+
try {
|
|
38
|
+
return o(t);
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
console.log("解析失败", err);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// 没有token
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
29
48
|
|
|
30
|
-
export { getToken, removeToken, setToken };
|
|
49
|
+
export { getToken, parseToken, removeToken, setToken };
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
function e(e){this.message=e;}e.prototype=new Error,e.prototype.name="InvalidCharacterError";var r="undefined"!=typeof window&&window.atob&&window.atob.bind(window)||function(r){var t=String(r).replace(/=+$/,"");if(t.length%4==1)throw new e("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,o,a=0,i=0,c="";o=t.charAt(i++);~o&&(n=a%4?64*n+o:o,a++%4)?c+=String.fromCharCode(255&n>>(-2*a&6)):0)o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=".indexOf(o);return c};function t(e){var t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw "Illegal base64url string!"}try{return function(e){return decodeURIComponent(r(e).replace(/(.)/g,(function(e,r){var t=r.charCodeAt(0).toString(16).toUpperCase();return t.length<2&&(t="0"+t),"%"+t})))}(t)}catch(e){return r(t)}}function n(e){this.message=e;}function o(e,r){if("string"!=typeof e)throw new n("Invalid token specified");var o=!0===(r=r||{}).header?0:1;try{return JSON.parse(t(e.split(".")[o]))}catch(e){throw new n("Invalid token specified: "+e.message)}}n.prototype=new Error,n.prototype.name="InvalidTokenError";
|
|
2
|
+
|
|
3
|
+
export { n as InvalidTokenError, o as default };
|
package/dist/es/water.d.ts
CHANGED
|
@@ -15,6 +15,7 @@ declare function mergeWaterConfig(waterConfig?: IWaterConfig): {
|
|
|
15
15
|
rotate: number;
|
|
16
16
|
zIndex: number;
|
|
17
17
|
content: string | string[];
|
|
18
|
+
lineSpacing: number;
|
|
18
19
|
font: {
|
|
19
20
|
color: string | CanvasGradient | CanvasPattern;
|
|
20
21
|
fontSize: number;
|
|
@@ -32,6 +33,7 @@ interface IWaterConfig {
|
|
|
32
33
|
zIndex?: number;
|
|
33
34
|
image?: string;
|
|
34
35
|
content?: string | string[];
|
|
36
|
+
lineSpacing?: number;
|
|
35
37
|
font?: {
|
|
36
38
|
color?: CanvasFillStrokeStyles["fillStyle"];
|
|
37
39
|
fontSize?: number;
|
package/dist/es/water.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import dayjs from 'dayjs';
|
|
2
|
+
import { parseToken } from './auth.js';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* 创建水印
|
|
3
6
|
*/
|
|
4
7
|
function createWater(config) {
|
|
5
|
-
var _a = mergeWaterConfig(config), width = _a.width, height = _a.height, rotate = _a.rotate, content = _a.content, font = _a.font;
|
|
8
|
+
var _a = mergeWaterConfig(config), width = _a.width, height = _a.height, rotate = _a.rotate, content = _a.content, font = _a.font, lineSpacing = _a.lineSpacing;
|
|
6
9
|
// 创建canvas元素
|
|
7
10
|
var canvas = document.createElement("canvas");
|
|
8
11
|
canvas.width = width * 2;
|
|
@@ -21,7 +24,7 @@ function createWater(config) {
|
|
|
21
24
|
if (Array.isArray(textLines)) {
|
|
22
25
|
// 多行文本
|
|
23
26
|
textLines.forEach(function (line, index) {
|
|
24
|
-
ctx.fillText(line, 0, index * font.fontSize);
|
|
27
|
+
ctx.fillText(line, 0, index * (font.fontSize + lineSpacing));
|
|
25
28
|
});
|
|
26
29
|
}
|
|
27
30
|
else {
|
|
@@ -45,15 +48,17 @@ function createWater(config) {
|
|
|
45
48
|
*/
|
|
46
49
|
function mergeWaterConfig(waterConfig) {
|
|
47
50
|
var _a, _b, _c, _d, _e, _f;
|
|
51
|
+
var defaultContent = getDefaultContent();
|
|
48
52
|
return {
|
|
49
53
|
width: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.width) || 200,
|
|
50
|
-
height: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.height) ||
|
|
51
|
-
rotate: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.rotate) || -
|
|
54
|
+
height: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.height) || 200,
|
|
55
|
+
rotate: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.rotate) || -20,
|
|
52
56
|
zIndex: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.zIndex) || 10,
|
|
53
|
-
content: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.content) ||
|
|
57
|
+
content: (waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.content) || defaultContent,
|
|
58
|
+
lineSpacing: 4,
|
|
54
59
|
font: {
|
|
55
|
-
color: ((_a = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _a === void 0 ? void 0 : _a.color) || "rgba(0, 0, 0, 0.
|
|
56
|
-
fontSize: ((_b = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _b === void 0 ? void 0 : _b.fontSize) ||
|
|
60
|
+
color: ((_a = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _a === void 0 ? void 0 : _a.color) || "rgba(0, 0, 0, 0.2)",
|
|
61
|
+
fontSize: ((_b = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _b === void 0 ? void 0 : _b.fontSize) || 14,
|
|
57
62
|
fontWeight: ((_c = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _c === void 0 ? void 0 : _c.fontWeight) || "normal",
|
|
58
63
|
fontStyle: ((_d = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _d === void 0 ? void 0 : _d.fontStyle) || "normal",
|
|
59
64
|
fontFamily: ((_e = waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.font) === null || _e === void 0 ? void 0 : _e.fontFamily) || "微软雅黑",
|
|
@@ -62,5 +67,15 @@ function mergeWaterConfig(waterConfig) {
|
|
|
62
67
|
image: waterConfig === null || waterConfig === void 0 ? void 0 : waterConfig.image,
|
|
63
68
|
};
|
|
64
69
|
}
|
|
70
|
+
function getDefaultContent() {
|
|
71
|
+
var jwtInfo = parseToken();
|
|
72
|
+
if (typeof jwtInfo === "object") {
|
|
73
|
+
var username = jwtInfo.real_name || jwtInfo.realName || "";
|
|
74
|
+
var phone = jwtInfo.phone || "";
|
|
75
|
+
var time = dayjs().format("YYMMDD");
|
|
76
|
+
return ["".concat(username, " ").concat(phone), time];
|
|
77
|
+
}
|
|
78
|
+
return "交投集团";
|
|
79
|
+
}
|
|
65
80
|
|
|
66
81
|
export { createWater, mergeWaterConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { initMicroApp } from './es/microAppCreator.js';
|
|
2
2
|
export { isQiankun } from './es/qiankunUtils.js';
|
|
3
3
|
export { initGlobalError, initMainApp } from './es/mainApp.js';
|
|
4
|
-
export { getToken, removeToken, setToken } from './es/auth.js';
|
|
4
|
+
export { getToken, parseToken, removeToken, setToken } from './es/auth.js';
|
|
5
5
|
export { AxiosRequest, IOptions, IOtherOptions } from './es/request.js';
|
|
6
6
|
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
7
|
export { Crypto, md5 } from './es/crypto.js';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { initMicroApp } from './es/microAppCreator.js';
|
|
2
2
|
export { isQiankun } from './es/qiankunUtils.js';
|
|
3
3
|
export { initGlobalError, initMainApp } from './es/mainApp.js';
|
|
4
|
-
export { getToken, removeToken, setToken } from './es/auth.js';
|
|
4
|
+
export { getToken, parseToken, removeToken, setToken } from './es/auth.js';
|
|
5
5
|
export { AxiosRequest } from './es/request.js';
|
|
6
6
|
export { getBaseUrl } from './es/baseUrl.js';
|
|
7
7
|
export { Crypto, md5 } from './es/crypto.js';
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zmdms-utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.40",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -16,13 +16,14 @@
|
|
|
16
16
|
"axios": "^1.4.0",
|
|
17
17
|
"crypto-js": "^4.1.1",
|
|
18
18
|
"dayjs": "^1.11.7",
|
|
19
|
-
"qiankun": "^2.10.8",
|
|
20
19
|
"html2canvas": "^1.4.1",
|
|
21
20
|
"jspdf": "^2.5.1",
|
|
22
|
-
"print-js": "^1.6.0"
|
|
21
|
+
"print-js": "^1.6.0",
|
|
22
|
+
"qiankun": "^2.10.8"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"decimal.js": "^10.4.3",
|
|
26
|
+
"jwt-decode": "3.1.2",
|
|
26
27
|
"mitt": "^3.0.0",
|
|
27
28
|
"pinyin-pro": "^3.18.2"
|
|
28
29
|
},
|
package/src/auth.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import jwtDecode from "jwt-decode";
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 权限相关
|
|
3
5
|
*/
|
|
@@ -25,3 +27,21 @@ export function removeToken() {
|
|
|
25
27
|
console.error("设置token失败", err);
|
|
26
28
|
}
|
|
27
29
|
}
|
|
30
|
+
|
|
31
|
+
export function parseToken(token?: string) {
|
|
32
|
+
let t: string | undefined | null = token;
|
|
33
|
+
if (!t) {
|
|
34
|
+
t = getToken();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
if (t) {
|
|
38
|
+
try {
|
|
39
|
+
return jwtDecode(t);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
console.log("解析失败", err);
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
// 没有token
|
|
46
|
+
return null;
|
|
47
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { initMicroApp } from "./microAppCreator";
|
|
2
2
|
export { isQiankun } from "./qiankunUtils";
|
|
3
3
|
export { initMainApp, initGlobalError } from "./mainApp";
|
|
4
|
-
export { getToken, setToken, removeToken } from "./auth";
|
|
4
|
+
export { getToken, setToken, removeToken, parseToken } from "./auth";
|
|
5
5
|
export { AxiosRequest, type IOtherOptions, type IOptions } from "./request";
|
|
6
6
|
export { getBaseUrl } from "./baseUrl";
|
|
7
7
|
export { Crypto, md5 } from "./crypto";
|
package/src/water.ts
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import dayjs from "dayjs";
|
|
2
|
+
import { parseToken } from "./auth";
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* 创建水印
|
|
3
6
|
*/
|
|
4
7
|
export function createWater(config: IWaterConfig) {
|
|
5
|
-
const { width, height, rotate, content, font } =
|
|
8
|
+
const { width, height, rotate, content, font, lineSpacing } =
|
|
9
|
+
mergeWaterConfig(config);
|
|
6
10
|
|
|
7
11
|
// 创建canvas元素
|
|
8
12
|
const canvas = document.createElement("canvas");
|
|
@@ -24,7 +28,7 @@ export function createWater(config: IWaterConfig) {
|
|
|
24
28
|
if (Array.isArray(textLines)) {
|
|
25
29
|
// 多行文本
|
|
26
30
|
textLines.forEach((line, index) => {
|
|
27
|
-
ctx.fillText(line, 0, index * font.fontSize);
|
|
31
|
+
ctx.fillText(line, 0, index * (font.fontSize + lineSpacing));
|
|
28
32
|
});
|
|
29
33
|
} else {
|
|
30
34
|
// 单行文本
|
|
@@ -50,15 +54,17 @@ export function createWater(config: IWaterConfig) {
|
|
|
50
54
|
* 默认配置
|
|
51
55
|
*/
|
|
52
56
|
export function mergeWaterConfig(waterConfig?: IWaterConfig) {
|
|
57
|
+
const defaultContent = getDefaultContent();
|
|
53
58
|
return {
|
|
54
59
|
width: waterConfig?.width || 200,
|
|
55
|
-
height: waterConfig?.height ||
|
|
56
|
-
rotate: waterConfig?.rotate || -
|
|
60
|
+
height: waterConfig?.height || 200,
|
|
61
|
+
rotate: waterConfig?.rotate || -20,
|
|
57
62
|
zIndex: waterConfig?.zIndex || 10,
|
|
58
|
-
content: waterConfig?.content ||
|
|
63
|
+
content: waterConfig?.content || defaultContent,
|
|
64
|
+
lineSpacing: 4,
|
|
59
65
|
font: {
|
|
60
|
-
color: waterConfig?.font?.color || "rgba(0, 0, 0, 0.
|
|
61
|
-
fontSize: waterConfig?.font?.fontSize ||
|
|
66
|
+
color: waterConfig?.font?.color || "rgba(0, 0, 0, 0.2)",
|
|
67
|
+
fontSize: waterConfig?.font?.fontSize || 14,
|
|
62
68
|
fontWeight: waterConfig?.font?.fontWeight || "normal",
|
|
63
69
|
fontStyle: waterConfig?.font?.fontStyle || "normal",
|
|
64
70
|
fontFamily: waterConfig?.font?.fontFamily || "微软雅黑",
|
|
@@ -68,6 +74,17 @@ export function mergeWaterConfig(waterConfig?: IWaterConfig) {
|
|
|
68
74
|
};
|
|
69
75
|
}
|
|
70
76
|
|
|
77
|
+
function getDefaultContent() {
|
|
78
|
+
const jwtInfo: any = parseToken();
|
|
79
|
+
if (typeof jwtInfo === "object") {
|
|
80
|
+
const username = jwtInfo.real_name || jwtInfo.realName || "";
|
|
81
|
+
const phone = jwtInfo.phone || "";
|
|
82
|
+
const time = dayjs().format("YYMMDD");
|
|
83
|
+
return [`${username} ${phone}`, time];
|
|
84
|
+
}
|
|
85
|
+
return "交投集团";
|
|
86
|
+
}
|
|
87
|
+
|
|
71
88
|
// 生成水印相关配置
|
|
72
89
|
export interface IWaterConfig {
|
|
73
90
|
// 水印宽度 120
|
|
@@ -82,6 +99,8 @@ export interface IWaterConfig {
|
|
|
82
99
|
image?: string;
|
|
83
100
|
// 文本水印内容
|
|
84
101
|
content?: string | string[];
|
|
102
|
+
// 多行文本时,每行文本的间距
|
|
103
|
+
lineSpacing?: number;
|
|
85
104
|
// 水印字体大小
|
|
86
105
|
font?: {
|
|
87
106
|
color?: CanvasFillStrokeStyles["fillStyle"];
|