aldehyde 0.2.527 → 0.2.528
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/lib/controls/entity-select/entity-select.d.ts.map +1 -1
- package/lib/controls/entity-select/entity-select.js +3 -3
- package/lib/controls/entity-select/entity-select.js.map +1 -1
- package/lib/controls/entity-select/index.css +6 -0
- package/lib/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +99 -99
- package/lib/draw-canvas-edit/components/asset-bar/index.less +35 -35
- package/lib/draw-canvas-edit/components/main-header/index.less +23 -23
- package/lib/icon/local-aliIcon/iconfont.js +1 -1
- package/lib/icon/local-aliIcon/iconfont.js.map +1 -1
- package/lib/lowcode-components/base-table/index.less +61 -61
- package/lib/lowcode-components/data-number/index.less +10 -10
- package/lib/lowcode-components/date-time/index.less +4 -4
- package/lib/lowcode-components/four-angle-glow-border/index.less +49 -49
- package/lib/lowcode-components/heatmap-chart/index.d.ts +42 -0
- package/lib/lowcode-components/heatmap-chart/index.d.ts.map +1 -0
- package/lib/lowcode-components/heatmap-chart/index.js +326 -0
- package/lib/lowcode-components/heatmap-chart/index.js.map +1 -0
- package/lib/lowcode-components/index.d.ts +2 -0
- package/lib/lowcode-components/index.d.ts.map +1 -1
- package/lib/lowcode-components/index.js +2 -1
- package/lib/lowcode-components/index.js.map +1 -1
- package/lib/lowcode-components/lowcode-view/component/assets.d.ts.map +1 -1
- package/lib/lowcode-components/lowcode-view/component/assets.js +8 -0
- package/lib/lowcode-components/lowcode-view/component/assets.js.map +1 -1
- package/lib/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
- package/lib/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
- package/lib/lowcode-components/text-scroller/index.less +28 -28
- package/lib/module/dtmpl-edit-card.d.ts.map +1 -1
- package/lib/module/dtmpl-edit-card.js +2 -6
- package/lib/module/dtmpl-edit-card.js.map +1 -1
- package/lib/module/dtmpl-edit-page.d.ts.map +1 -1
- package/lib/module/dtmpl-edit-page.js +2 -6
- package/lib/module/dtmpl-edit-page.js.map +1 -1
- package/lib/module/ttmpl-table.d.ts +3 -0
- package/lib/module/ttmpl-table.d.ts.map +1 -1
- package/lib/module/ttmpl-table.js +15 -8
- package/lib/module/ttmpl-table.js.map +1 -1
- package/lib/routable/ttmpl-table-route.d.ts.map +1 -1
- package/lib/routable/ttmpl-table-route.js +32 -7
- package/lib/routable/ttmpl-table-route.js.map +1 -1
- package/lib/table/act-table.d.ts +1 -0
- package/lib/table/act-table.d.ts.map +1 -1
- package/lib/table/act-table.js +2 -2
- package/lib/table/act-table.js.map +1 -1
- package/lib/table/column/column-builder.d.ts.map +1 -1
- package/lib/table/column/column-builder.js +20 -4
- package/lib/table/column/column-builder.js.map +1 -1
- package/lib/table/relation-table.js +1 -1
- package/lib/table/relation-table.js.map +1 -1
- package/lib/tmpl/hc-data-source.d.ts +1 -0
- package/lib/tmpl/hc-data-source.d.ts.map +1 -1
- package/lib/tmpl/hc-data-source.js +11 -0
- package/lib/tmpl/hc-data-source.js.map +1 -1
- package/lib/tmpl/hcservice-v3.d.ts +1 -0
- package/lib/tmpl/hcservice-v3.d.ts.map +1 -1
- package/lib/tmpl/hcservice-v3.js +12 -0
- package/lib/tmpl/hcservice-v3.js.map +1 -1
- package/lib/tmpl/interface.d.ts +7 -0
- package/lib/tmpl/interface.d.ts.map +1 -1
- package/lib/tmpl/interface.js.map +1 -1
- package/package.json +1 -1
- package/src/aldehyde/controls/entity-select/entity-select.tsx +4 -5
- package/src/aldehyde/controls/entity-select/index.css +6 -0
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.css +99 -99
- package/src/aldehyde/controls/icon-selector/icon/phonenode-menu-icon/iconfont.json +156 -156
- package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.less +35 -35
- package/src/aldehyde/draw-canvas-edit/components/asset-bar/index.tsx +110 -110
- package/src/aldehyde/draw-canvas-edit/components/main-header/index.less +23 -23
- package/src/aldehyde/draw-canvas-edit/components/main-header/index.tsx +263 -263
- package/src/aldehyde/draw-canvas-edit/components/render/draws/index.ts +7 -7
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/base-graph.ts +241 -241
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/circle.ts +699 -699
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/curve.ts +500 -500
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/index.ts +5 -5
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/line.ts +493 -493
- package/src/aldehyde/draw-canvas-edit/components/render/graphs/rect.ts +680 -680
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/drag-handlers.ts +68 -68
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/graph-handlers.ts +113 -113
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/index.ts +9 -9
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/key-move-handlers.ts +49 -49
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/link-handlers.ts +45 -45
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/shutcut-handlers.ts +45 -45
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/text-handlers.ts +81 -81
- package/src/aldehyde/draw-canvas-edit/components/render/handlers/zoom-handlers.ts +59 -59
- package/src/aldehyde/draw-canvas-edit/components/render/tools/align-tool.ts +89 -89
- package/src/aldehyde/draw-canvas-edit/components/render/tools/asset-tool.ts +154 -154
- package/src/aldehyde/draw-canvas-edit/components/render/tools/link-tool.ts +222 -222
- package/src/aldehyde/draw-canvas-edit/components/render/tools/z-index-tool.ts +224 -224
- package/src/aldehyde/draw-canvas-edit/components/render/utils/a-star.ts +116 -116
- package/src/aldehyde/draw-canvas-edit/components/render/utils/bezier-scene-func.ts +72 -72
- package/src/aldehyde/draw-canvas-edit/components/setting-form/imag-upload.tsx +119 -119
- package/src/aldehyde/icon/local-aliIcon/iconfont.js +1 -1
- package/src/aldehyde/layout4/imgs/user.svg +26 -26
- package/src/aldehyde/lowcode-components/base-color-block/index.tsx +31 -31
- package/src/aldehyde/lowcode-components/base-table/index.less +61 -61
- package/src/aldehyde/lowcode-components/data-number/index.less +10 -10
- package/src/aldehyde/lowcode-components/date-time/index.less +4 -4
- package/src/aldehyde/lowcode-components/date-time/index.tsx +64 -64
- package/src/aldehyde/lowcode-components/four-angle-glow-border/index.less +49 -49
- package/src/aldehyde/lowcode-components/four-angle-glow-border/index.tsx +53 -53
- package/src/aldehyde/lowcode-components/heatmap-chart/index.tsx +362 -0
- package/src/aldehyde/lowcode-components/index.ts +4 -2
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-controller.ts +64 -64
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-definition.ts +77 -77
- package/src/aldehyde/lowcode-components/lowcode-view/component/abstract-designer-loader.ts +36 -36
- package/src/aldehyde/lowcode-components/lowcode-view/component/assets.ts +8 -0
- package/src/aldehyde/lowcode-components/lowcode-view/component/component-container.tsx +144 -144
- package/src/aldehyde/lowcode-components/lowcode-view/component/font/FontGlobal.css +26 -26
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/controller.ts +36 -36
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/definition.ts +53 -53
- package/src/aldehyde/lowcode-components/lowcode-view/component/group-layer/index.tsx +15 -15
- package/src/aldehyde/lowcode-components/lowcode-view/component/layer-builder.tsx +98 -98
- package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.less +13 -13
- package/src/aldehyde/lowcode-components/lowcode-view/component/screen-fit/index.tsx +121 -121
- package/src/aldehyde/lowcode-components/placeholder-component/index.tsx +81 -81
- package/src/aldehyde/lowcode-components/text-scroller/index.less +28 -28
- package/src/aldehyde/lowcode-components/text-scroller/index.tsx +173 -173
- package/src/aldehyde/module/dtmpl-edit-card.tsx +2 -6
- package/src/aldehyde/module/dtmpl-edit-page.tsx +2 -6
- package/src/aldehyde/module/ttmpl-table.tsx +25 -7
- package/src/aldehyde/routable/ttmpl-table-route.tsx +37 -7
- package/src/aldehyde/table/act-table.tsx +4 -2
- package/src/aldehyde/table/column/column-builder.tsx +30 -5
- package/src/aldehyde/table/relation-table.tsx +1 -1
- package/src/aldehyde/tmpl/hc-data-source.tsx +11 -0
- package/src/aldehyde/tmpl/hcservice-v3.tsx +11 -0
- package/src/aldehyde/tmpl/interface.tsx +3 -1
|
@@ -1,73 +1,73 @@
|
|
|
1
|
-
import Konva from 'konva';
|
|
2
|
-
|
|
3
|
-
function rotatePoint(x1: number, y1: number, x2: number, y2: number, angleInDegrees: number) {
|
|
4
|
-
const radians = angleInDegrees * (Math.PI / 180);
|
|
5
|
-
const cosTheta = Math.cos(radians);
|
|
6
|
-
const sinTheta = Math.sin(radians);
|
|
7
|
-
|
|
8
|
-
// Translate point (x2, y2) to be relative to (x1, y1)
|
|
9
|
-
const x = x2 - x1;
|
|
10
|
-
const y = y2 - y1;
|
|
11
|
-
|
|
12
|
-
// Rotate point
|
|
13
|
-
const xPrime = cosTheta * x - sinTheta * y;
|
|
14
|
-
const yPrime = sinTheta * x + cosTheta * y;
|
|
15
|
-
|
|
16
|
-
// Translate back
|
|
17
|
-
const xNew = xPrime + x1;
|
|
18
|
-
const yNew = yPrime + y1;
|
|
19
|
-
|
|
20
|
-
return { x: xNew, y: yNew };
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function drawPointer(ctx: Konva.Context, shape: Konva.Shape, startX: number, startY: number, ctrlX: number, ctrlY: number) {
|
|
24
|
-
const x2 = startX + 12;
|
|
25
|
-
const y2 = startY - 6;
|
|
26
|
-
const x3 = startX + 12;
|
|
27
|
-
const y3 = startY + 6;
|
|
28
|
-
const angle = (Math.atan2(ctrlY - startY, ctrlX - startX) * 180) / Math.PI;
|
|
29
|
-
const p2 = rotatePoint(startX, startY, x2, y2, angle);
|
|
30
|
-
const p3 = rotatePoint(startX, startY, x3, y3, angle);
|
|
31
|
-
ctx.beginPath();
|
|
32
|
-
ctx.moveTo(startX, startY);
|
|
33
|
-
ctx.lineTo(p2.x, p2.y);
|
|
34
|
-
ctx.lineTo(p3.x, p3.y);
|
|
35
|
-
ctx.lineTo(startX, startY);
|
|
36
|
-
ctx.lineTo(p2.x, p2.y);
|
|
37
|
-
ctx.strokeShape(shape);
|
|
38
|
-
ctx.fillShape(shape);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
export function BezierSceneFunc(ctx: Konva.Context, shape: Konva.Shape) {
|
|
42
|
-
if (shape instanceof Konva.Arrow) {
|
|
43
|
-
const ps = shape.points();
|
|
44
|
-
if (ps.length / 2 === 4) {
|
|
45
|
-
// 三次
|
|
46
|
-
ctx.beginPath();
|
|
47
|
-
ctx.moveTo(ps[0], ps[1]);
|
|
48
|
-
ctx.bezierCurveTo(ps[2], ps[3], ps[4], ps[5], ps[6], ps[7]);
|
|
49
|
-
ctx.strokeShape(shape);
|
|
50
|
-
ctx.closePath();
|
|
51
|
-
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
52
|
-
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[6], ps[7], ps[4], ps[5]);
|
|
53
|
-
} else if (ps.length / 2 === 3) {
|
|
54
|
-
// 二次
|
|
55
|
-
ctx.beginPath();
|
|
56
|
-
ctx.moveTo(ps[0], ps[1]);
|
|
57
|
-
ctx.quadraticCurveTo(ps[2], ps[3], ps[4], ps[5]);
|
|
58
|
-
ctx.strokeShape(shape);
|
|
59
|
-
ctx.closePath();
|
|
60
|
-
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
61
|
-
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[4], ps[5], ps[2], ps[3]);
|
|
62
|
-
} else {
|
|
63
|
-
// 直线
|
|
64
|
-
ctx.beginPath();
|
|
65
|
-
ctx.moveTo(ps[0], ps[1]);
|
|
66
|
-
ctx.lineTo(ps[2], ps[3]);
|
|
67
|
-
ctx.strokeShape(shape);
|
|
68
|
-
ctx.closePath();
|
|
69
|
-
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
70
|
-
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[2], ps[3], ps[0], ps[1]);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
1
|
+
import Konva from 'konva';
|
|
2
|
+
|
|
3
|
+
function rotatePoint(x1: number, y1: number, x2: number, y2: number, angleInDegrees: number) {
|
|
4
|
+
const radians = angleInDegrees * (Math.PI / 180);
|
|
5
|
+
const cosTheta = Math.cos(radians);
|
|
6
|
+
const sinTheta = Math.sin(radians);
|
|
7
|
+
|
|
8
|
+
// Translate point (x2, y2) to be relative to (x1, y1)
|
|
9
|
+
const x = x2 - x1;
|
|
10
|
+
const y = y2 - y1;
|
|
11
|
+
|
|
12
|
+
// Rotate point
|
|
13
|
+
const xPrime = cosTheta * x - sinTheta * y;
|
|
14
|
+
const yPrime = sinTheta * x + cosTheta * y;
|
|
15
|
+
|
|
16
|
+
// Translate back
|
|
17
|
+
const xNew = xPrime + x1;
|
|
18
|
+
const yNew = yPrime + y1;
|
|
19
|
+
|
|
20
|
+
return { x: xNew, y: yNew };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function drawPointer(ctx: Konva.Context, shape: Konva.Shape, startX: number, startY: number, ctrlX: number, ctrlY: number) {
|
|
24
|
+
const x2 = startX + 12;
|
|
25
|
+
const y2 = startY - 6;
|
|
26
|
+
const x3 = startX + 12;
|
|
27
|
+
const y3 = startY + 6;
|
|
28
|
+
const angle = (Math.atan2(ctrlY - startY, ctrlX - startX) * 180) / Math.PI;
|
|
29
|
+
const p2 = rotatePoint(startX, startY, x2, y2, angle);
|
|
30
|
+
const p3 = rotatePoint(startX, startY, x3, y3, angle);
|
|
31
|
+
ctx.beginPath();
|
|
32
|
+
ctx.moveTo(startX, startY);
|
|
33
|
+
ctx.lineTo(p2.x, p2.y);
|
|
34
|
+
ctx.lineTo(p3.x, p3.y);
|
|
35
|
+
ctx.lineTo(startX, startY);
|
|
36
|
+
ctx.lineTo(p2.x, p2.y);
|
|
37
|
+
ctx.strokeShape(shape);
|
|
38
|
+
ctx.fillShape(shape);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function BezierSceneFunc(ctx: Konva.Context, shape: Konva.Shape) {
|
|
42
|
+
if (shape instanceof Konva.Arrow) {
|
|
43
|
+
const ps = shape.points();
|
|
44
|
+
if (ps.length / 2 === 4) {
|
|
45
|
+
// 三次
|
|
46
|
+
ctx.beginPath();
|
|
47
|
+
ctx.moveTo(ps[0], ps[1]);
|
|
48
|
+
ctx.bezierCurveTo(ps[2], ps[3], ps[4], ps[5], ps[6], ps[7]);
|
|
49
|
+
ctx.strokeShape(shape);
|
|
50
|
+
ctx.closePath();
|
|
51
|
+
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
52
|
+
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[6], ps[7], ps[4], ps[5]);
|
|
53
|
+
} else if (ps.length / 2 === 3) {
|
|
54
|
+
// 二次
|
|
55
|
+
ctx.beginPath();
|
|
56
|
+
ctx.moveTo(ps[0], ps[1]);
|
|
57
|
+
ctx.quadraticCurveTo(ps[2], ps[3], ps[4], ps[5]);
|
|
58
|
+
ctx.strokeShape(shape);
|
|
59
|
+
ctx.closePath();
|
|
60
|
+
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
61
|
+
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[4], ps[5], ps[2], ps[3]);
|
|
62
|
+
} else {
|
|
63
|
+
// 直线
|
|
64
|
+
ctx.beginPath();
|
|
65
|
+
ctx.moveTo(ps[0], ps[1]);
|
|
66
|
+
ctx.lineTo(ps[2], ps[3]);
|
|
67
|
+
ctx.strokeShape(shape);
|
|
68
|
+
ctx.closePath();
|
|
69
|
+
shape.pointerAtBeginning() && drawPointer(ctx, shape, ps[0], ps[1], ps[2], ps[3]);
|
|
70
|
+
shape.pointerAtEnding() && drawPointer(ctx, shape, ps[2], ps[3], ps[0], ps[1]);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
73
|
}
|
|
@@ -1,119 +1,119 @@
|
|
|
1
|
-
import React, { useEffect, useState } from "react";
|
|
2
|
-
import { Upload as AntdUpLoad, UploadFile, message } from "antd";
|
|
3
|
-
import { RcFile } from "antd/es/upload";
|
|
4
|
-
import { PlusOutlined } from "@ant-design/icons";
|
|
5
|
-
import { HydrocarbonService, Superagent, ProgramConfig } from "../../../index";
|
|
6
|
-
import { fileUpload } from "../../constant";
|
|
7
|
-
import { useLocale } from "../../../locale/useLocale";
|
|
8
|
-
|
|
9
|
-
const { sourceId, serverKey } = fileUpload;
|
|
10
|
-
|
|
11
|
-
// 本地文件上传,处理url
|
|
12
|
-
const handleImgUrl = (basePath: string) => {
|
|
13
|
-
if (basePath.startsWith("http")) {
|
|
14
|
-
return basePath;
|
|
15
|
-
}
|
|
16
|
-
const url = encodeURI(ProgramConfig.joinPath(
|
|
17
|
-
ProgramConfig.joinPath(ProgramConfig.api(), "/v3/files"),
|
|
18
|
-
basePath
|
|
19
|
-
)) +
|
|
20
|
-
`?@token=${ProgramConfig.hydrocarbonToken()}&@programToken=${ProgramConfig.programCode(serverKey)}&@applicationToken=${ProgramConfig.applicationCode(serverKey)}`;
|
|
21
|
-
return url;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const fileInfo = {
|
|
25
|
-
uid: '-1',
|
|
26
|
-
name: 'image.png',
|
|
27
|
-
status: 'done',
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export interface CommonFilePath {
|
|
31
|
-
fileName?: string;
|
|
32
|
-
contentType?: string;//文件类型
|
|
33
|
-
path?: string;
|
|
34
|
-
iconPath?: string;
|
|
35
|
-
valid?: string;
|
|
36
|
-
baseType?: string;
|
|
37
|
-
basePath?: string;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
export interface UploadProps {
|
|
42
|
-
accept?: string;
|
|
43
|
-
size?: number;
|
|
44
|
-
onChange?: (data: { src: string, code: string }) => void;
|
|
45
|
-
value?: { src: string, code: string };
|
|
46
|
-
recordCode?: string; // 当前画面关联数据code,用于图片命名区分
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const ImageUpload: React.FC<UploadProps> = (props) => {
|
|
50
|
-
const { onChange, accept, size, recordCode, value } = props;
|
|
51
|
-
const [fileList, setFileList] = useState([]);
|
|
52
|
-
const [imgCode, setImgCode] = useState<string>(); // 本地图片code
|
|
53
|
-
const { translate } = useLocale();
|
|
54
|
-
|
|
55
|
-
useEffect(() => {
|
|
56
|
-
setFileList(value?.src ? [{ ...fileInfo, url: handleImgUrl(value?.src) }] : []);
|
|
57
|
-
setImgCode(value?.code);
|
|
58
|
-
}, [value]);
|
|
59
|
-
|
|
60
|
-
const beforeUpload = async (file: RcFile) => {
|
|
61
|
-
if (size && file.size > size * 1024 * 1024) {
|
|
62
|
-
message.warning(translate("${文件大小不能超过}") + `${size}M`);
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
const handleChange = async (info) => {
|
|
69
|
-
if (info.file.status == "done") {
|
|
70
|
-
const fileKey = info.file.response.fileKey;
|
|
71
|
-
const fileName = info.file.name;
|
|
72
|
-
const data = { valid: "new", fileKey, fileName };
|
|
73
|
-
const result = { 描述: `${recordCode || ""}-${fileName}`, 文件: JSON.stringify(data) };
|
|
74
|
-
const { code } = await HydrocarbonService.postMstrucDtmplData(serverKey, sourceId, result, message);
|
|
75
|
-
setImgCode(code);
|
|
76
|
-
const imgData = await HydrocarbonService.requestMstrucDtmplData(serverKey, sourceId, code, null);
|
|
77
|
-
const basePath = JSON.parse(imgData.fieldMap["文件"] || "{}").base?.path;
|
|
78
|
-
if (basePath) {
|
|
79
|
-
const url = handleImgUrl(basePath);
|
|
80
|
-
setFileList([{ ...info.file, url }]);
|
|
81
|
-
// onChange?.(url);
|
|
82
|
-
onChange?.({ src: basePath, code });
|
|
83
|
-
} else {
|
|
84
|
-
setFileList([...info.fileList]);
|
|
85
|
-
}
|
|
86
|
-
} else {
|
|
87
|
-
setFileList([...info.fileList]);
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
const handleDelete = async () => {
|
|
92
|
-
await HydrocarbonService.deleteByCode(serverKey, sourceId, [imgCode]);
|
|
93
|
-
setFileList([]);
|
|
94
|
-
onChange?.(null);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<AntdUpLoad
|
|
99
|
-
action={(file) => HydrocarbonService.postFileAction(serverKey, file)}
|
|
100
|
-
headers={Superagent.getHeaderObj(serverKey)}
|
|
101
|
-
name={'file'}
|
|
102
|
-
beforeUpload={beforeUpload}
|
|
103
|
-
listType={'picture-card'}
|
|
104
|
-
fileList={fileList?.length ? fileList as Array<UploadFile> : undefined}
|
|
105
|
-
accept={accept}
|
|
106
|
-
onChange={handleChange}
|
|
107
|
-
onRemove={handleDelete}
|
|
108
|
-
onPreview={() => window.open(fileList[0].url)}
|
|
109
|
-
styles={{ root: { overflow: "hidden" } }}
|
|
110
|
-
>
|
|
111
|
-
{fileList.length > 0 ? null : <div className={'upload-btn'}>
|
|
112
|
-
<PlusOutlined />
|
|
113
|
-
<div style={{ marginTop: 8 }}>{translate("${上传图片}")}</div>
|
|
114
|
-
</div>}
|
|
115
|
-
</AntdUpLoad>
|
|
116
|
-
)
|
|
117
|
-
};
|
|
118
|
-
|
|
119
|
-
export default ImageUpload;
|
|
1
|
+
import React, { useEffect, useState } from "react";
|
|
2
|
+
import { Upload as AntdUpLoad, UploadFile, message } from "antd";
|
|
3
|
+
import { RcFile } from "antd/es/upload";
|
|
4
|
+
import { PlusOutlined } from "@ant-design/icons";
|
|
5
|
+
import { HydrocarbonService, Superagent, ProgramConfig } from "../../../index";
|
|
6
|
+
import { fileUpload } from "../../constant";
|
|
7
|
+
import { useLocale } from "../../../locale/useLocale";
|
|
8
|
+
|
|
9
|
+
const { sourceId, serverKey } = fileUpload;
|
|
10
|
+
|
|
11
|
+
// 本地文件上传,处理url
|
|
12
|
+
const handleImgUrl = (basePath: string) => {
|
|
13
|
+
if (basePath.startsWith("http")) {
|
|
14
|
+
return basePath;
|
|
15
|
+
}
|
|
16
|
+
const url = encodeURI(ProgramConfig.joinPath(
|
|
17
|
+
ProgramConfig.joinPath(ProgramConfig.api(), "/v3/files"),
|
|
18
|
+
basePath
|
|
19
|
+
)) +
|
|
20
|
+
`?@token=${ProgramConfig.hydrocarbonToken()}&@programToken=${ProgramConfig.programCode(serverKey)}&@applicationToken=${ProgramConfig.applicationCode(serverKey)}`;
|
|
21
|
+
return url;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const fileInfo = {
|
|
25
|
+
uid: '-1',
|
|
26
|
+
name: 'image.png',
|
|
27
|
+
status: 'done',
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export interface CommonFilePath {
|
|
31
|
+
fileName?: string;
|
|
32
|
+
contentType?: string;//文件类型
|
|
33
|
+
path?: string;
|
|
34
|
+
iconPath?: string;
|
|
35
|
+
valid?: string;
|
|
36
|
+
baseType?: string;
|
|
37
|
+
basePath?: string;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
export interface UploadProps {
|
|
42
|
+
accept?: string;
|
|
43
|
+
size?: number;
|
|
44
|
+
onChange?: (data: { src: string, code: string }) => void;
|
|
45
|
+
value?: { src: string, code: string };
|
|
46
|
+
recordCode?: string; // 当前画面关联数据code,用于图片命名区分
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const ImageUpload: React.FC<UploadProps> = (props) => {
|
|
50
|
+
const { onChange, accept, size, recordCode, value } = props;
|
|
51
|
+
const [fileList, setFileList] = useState([]);
|
|
52
|
+
const [imgCode, setImgCode] = useState<string>(); // 本地图片code
|
|
53
|
+
const { translate } = useLocale();
|
|
54
|
+
|
|
55
|
+
useEffect(() => {
|
|
56
|
+
setFileList(value?.src ? [{ ...fileInfo, url: handleImgUrl(value?.src) }] : []);
|
|
57
|
+
setImgCode(value?.code);
|
|
58
|
+
}, [value]);
|
|
59
|
+
|
|
60
|
+
const beforeUpload = async (file: RcFile) => {
|
|
61
|
+
if (size && file.size > size * 1024 * 1024) {
|
|
62
|
+
message.warning(translate("${文件大小不能超过}") + `${size}M`);
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const handleChange = async (info) => {
|
|
69
|
+
if (info.file.status == "done") {
|
|
70
|
+
const fileKey = info.file.response.fileKey;
|
|
71
|
+
const fileName = info.file.name;
|
|
72
|
+
const data = { valid: "new", fileKey, fileName };
|
|
73
|
+
const result = { 描述: `${recordCode || ""}-${fileName}`, 文件: JSON.stringify(data) };
|
|
74
|
+
const { code } = await HydrocarbonService.postMstrucDtmplData(serverKey, sourceId, result, message);
|
|
75
|
+
setImgCode(code);
|
|
76
|
+
const imgData = await HydrocarbonService.requestMstrucDtmplData(serverKey, sourceId, code, null);
|
|
77
|
+
const basePath = JSON.parse(imgData.fieldMap["文件"] || "{}").base?.path;
|
|
78
|
+
if (basePath) {
|
|
79
|
+
const url = handleImgUrl(basePath);
|
|
80
|
+
setFileList([{ ...info.file, url }]);
|
|
81
|
+
// onChange?.(url);
|
|
82
|
+
onChange?.({ src: basePath, code });
|
|
83
|
+
} else {
|
|
84
|
+
setFileList([...info.fileList]);
|
|
85
|
+
}
|
|
86
|
+
} else {
|
|
87
|
+
setFileList([...info.fileList]);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const handleDelete = async () => {
|
|
92
|
+
await HydrocarbonService.deleteByCode(serverKey, sourceId, [imgCode]);
|
|
93
|
+
setFileList([]);
|
|
94
|
+
onChange?.(null);
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
return (
|
|
98
|
+
<AntdUpLoad
|
|
99
|
+
action={(file) => HydrocarbonService.postFileAction(serverKey, file)}
|
|
100
|
+
headers={Superagent.getHeaderObj(serverKey)}
|
|
101
|
+
name={'file'}
|
|
102
|
+
beforeUpload={beforeUpload}
|
|
103
|
+
listType={'picture-card'}
|
|
104
|
+
fileList={fileList?.length ? fileList as Array<UploadFile> : undefined}
|
|
105
|
+
accept={accept}
|
|
106
|
+
onChange={handleChange}
|
|
107
|
+
onRemove={handleDelete}
|
|
108
|
+
onPreview={() => window.open(fileList[0].url)}
|
|
109
|
+
styles={{ root: { overflow: "hidden" } }}
|
|
110
|
+
>
|
|
111
|
+
{fileList.length > 0 ? null : <div className={'upload-btn'}>
|
|
112
|
+
<PlusOutlined />
|
|
113
|
+
<div style={{ marginTop: 8 }}>{translate("${上传图片}")}</div>
|
|
114
|
+
</div>}
|
|
115
|
+
</AntdUpLoad>
|
|
116
|
+
)
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export default ImageUpload;
|