@hzab/form-render 1.6.6 → 1.6.8

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/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
- # @hzab/form-render@1.6.6
1
+
2
+ # @hzab/form-render@1.6.8
3
+
4
+ feat:富文本组件添加私有化部署文件上传与oss上传的区分
5
+
6
+ # @hzab/form-render@1.6.7
2
7
 
3
8
  fix: 修复 LocationListPicker 组件在编辑时第一次无法正确渲染的 bug。
4
9
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hzab/form-render",
3
- "version": "1.6.6",
3
+ "version": "1.6.8",
4
4
  "description": "",
5
5
  "main": "src",
6
6
  "scripts": {
@@ -60,8 +60,7 @@ export const LocationListPicker = observer((props) => {
60
60
  }, []);
61
61
 
62
62
  useEffect(() => {
63
- listRef.current = value || [];
64
- if (!Array.isArray(value) || value?.length == 0 || !mapUtilsRef.current) {
63
+ if (!Array.isArray(value) || value?.length == 0) {
65
64
  return;
66
65
  }
67
66
  // 处理 id
@@ -70,6 +69,10 @@ export const LocationListPicker = observer((props) => {
70
69
  it.id = nanoid();
71
70
  }
72
71
  });
72
+ listRef.current = value || [];
73
+ if (!mapUtilsRef.current) {
74
+ return;
75
+ }
73
76
  renderMarker();
74
77
  }, [value]);
75
78
 
@@ -89,6 +92,7 @@ export const LocationListPicker = observer((props) => {
89
92
  mapUtilsRef.current.setCircle(item.longitude, item.latitude, item.range, { ...item });
90
93
  }
91
94
  });
95
+ mapUtilsRef.current.setFitView();
92
96
  clearActive();
93
97
  }
94
98
 
@@ -106,7 +110,6 @@ export const LocationListPicker = observer((props) => {
106
110
  });
107
111
 
108
112
  renderMarker();
109
- mapUtilsRef.current.setFitView();
110
113
  }
111
114
 
112
115
  function onAddClick() {
@@ -2,7 +2,8 @@ import "@wangeditor/editor/dist/css/style.css"; // 引入 css
2
2
  import React, { useState, useEffect, useImperativeHandle, forwardRef } from "react";
3
3
  import { Editor as WangEditor, Toolbar } from "@wangeditor/editor-for-react";
4
4
  import { IDomEditor, IEditorConfig, IToolbarConfig } from "@wangeditor/editor";
5
- import UploadOss from "./common/ossUpload";
5
+ import { getOssUploadRequest, getOfflineUploadRequest } from "../Upload/common/customRequest";
6
+ import { handlePreviewUrls } from "../Upload/common/OfflineUpload";
6
7
  import "./index.less";
7
8
  import { Spin, message } from 'antd';
8
9
  import { connect, mapProps, observer } from "@formily/react";
@@ -15,11 +16,16 @@ interface PropsType {
15
16
  toolbarConfig?: Partial<IToolbarConfig>;
16
17
  editorConfig?: Partial<IEditorConfig>;
17
18
  ossOpt: AnyObject,
18
- params: AnyObject,
19
+ uploadParams: AnyObject,
19
20
  height: string,
21
+ ossServerUrl: string,
20
22
  ossUrl: string,
23
+ offlinePreviewUrl: string,
24
+ offlineServerUrl: string,
21
25
  value: string,
22
26
  onChange: any,
27
+ customRequest: any,
28
+ uploadMode: string,
23
29
  zIndex: number
24
30
  }
25
31
 
@@ -31,10 +37,18 @@ export const RichEditor = observer(function (props: PropsType, parentRef) {
31
37
  onChange,
32
38
  value,
33
39
  ossOpt,
40
+ uploadMode = "oss",
41
+ offlinePreviewUrl = "",
42
+ offlineServerUrl = "",
43
+ uploadParams = {},
34
44
  // ossUrl = "https://test-abt.hzabjt.com:18091/api/v1/user/oss/getWebOssConfig",
45
+ ossServerUrl = "/api/v1/user/oss/getWebOssConfig",
35
46
  ossUrl = "/api/v1/user/oss/getWebOssConfig",
36
47
  zIndex = 9999
37
48
  } = props;
49
+ const isPrivateStore =
50
+ props.uploadParams?.fileAcl === "private" || props.ossOpt?.signatureParams?.fileAcl === "private";
51
+
38
52
  useImperativeHandle(parentRef, () => ({
39
53
  setEditorContent,
40
54
  getEditorContent,
@@ -57,6 +71,40 @@ export const RichEditor = observer(function (props: PropsType, parentRef) {
57
71
  return html;
58
72
  };
59
73
 
74
+
75
+ const customUpload = async (file: File, insertFn) => {
76
+ let customRequest = props.customRequest;
77
+ if (uploadMode === "oss") {
78
+ customRequest = getOssUploadRequest({
79
+ ...props,
80
+ isPrivateStore,
81
+ params: uploadParams,
82
+ ossServerUrl: ossServerUrl || ossUrl,
83
+ });
84
+ } else if (uploadMode === "offline") {
85
+ customRequest = getOfflineUploadRequest({
86
+ ...props,
87
+ isPrivateStore,
88
+ params: uploadParams,
89
+ offlineServerUrl: offlineServerUrl || ossUrl,
90
+ offlinePreviewUrl: offlinePreviewUrl,
91
+ });
92
+ }
93
+ setIsLoading(true);
94
+ customRequest({
95
+ file,
96
+ onSuccess: (res) => {
97
+ setIsLoading(false);
98
+ console.log(res)
99
+ insertFn(res.url, '', '');
100
+ },
101
+ onError: () => {
102
+ setIsLoading(false);
103
+ message.error(`${file.name} 上传失败`);
104
+ }
105
+ })
106
+ }
107
+
60
108
  const config: Partial<IEditorConfig> = {
61
109
  // TS 语法
62
110
  placeholder: "请输入内容...",
@@ -74,19 +122,7 @@ export const RichEditor = observer(function (props: PropsType, parentRef) {
74
122
  withCredentials: false,
75
123
  // 超时时间,默认为 10 秒
76
124
  timeout: 5 * 1000, // 5 秒
77
- async customUpload(file: File, insertFn) {
78
- const ossUpload = new UploadOss({
79
- serverUrl: ossUrl,
80
- ...ossOpt,
81
- });
82
- const res = await ossUpload.upload(file, {
83
- params: {
84
- isPublic: 1,
85
- ...(props.params || {}),
86
- },
87
- })
88
- insertFn(res?.data?.data?.fileUrl, '', '')
89
- },
125
+ customUpload,
90
126
  },
91
127
  uploadVideo: {
92
128
  // form-data fieldName ,默认值 'wangeditor-uploaded-image'
@@ -97,30 +133,13 @@ export const RichEditor = observer(function (props: PropsType, parentRef) {
97
133
  allowedFileTypes: ['video/*'],
98
134
  // 跨域是否传递 cookie ,默认为 false
99
135
  withCredentials: false,
100
- customUpload(file: File, insertFn) {
101
- setIsLoading(true)
102
- const ossUpload = new UploadOss({
103
- serverUrl: ossUrl,
104
- ...ossOpt,
105
- });
106
- ossUpload.upload(file, {
107
- params: {
108
- isPublic: 1,
109
- ...(props.params || {}),
110
- },
111
- }).then((res) => {
112
- setIsLoading(false)
113
- insertFn(res?.data?.data?.fileUrl, '', '')
114
- }).catch(() => {
115
- setIsLoading(false)
116
- message.error(`${file.name} 上传失败`);
117
- })
118
- },
136
+ customUpload,
119
137
  },
120
138
  },
121
139
  ...editorConfig,
122
140
  };
123
141
 
142
+
124
143
  const onEditorChange = (e) => {
125
144
  const content = e.getHtml();
126
145
  setHtml(content);
@@ -1,155 +0,0 @@
1
- import { axios } from "@hzab/data-model";
2
- import { nanoid } from "nanoid";
3
-
4
- export function getSignature(opt = {}) {
5
- const { serverUrl = "/api/v1/user/oss/getWebOssConfig" } = opt;
6
- // 减 10 秒,避免发起请求时 刚好过期的情况
7
- if (
8
- window.__ossSignatureRes &&
9
- serverUrl === window.__ossSignatureRes.serverUrl &&
10
- Date.now() - window.__ossSignatureRes.__saveTime < window.__ossSignatureRes.expireTimeMillis - 10000
11
- ) {
12
- return Promise.resolve(window.__ossSignatureRes);
13
- }
14
- const { axios: _ax = axios, params = {}, axiosConf } = opt;
15
- return _ax
16
- .get(serverUrl, {
17
- ...axiosConf,
18
- params: {
19
- isPublic: 1,
20
- ...params,
21
- },
22
- })
23
- .then((res) => {
24
- window.__ossSignatureRes = res?.data?.data;
25
- if (window.__ossSignatureRes) {
26
- window.__ossSignatureRes.__saveTime = Date.now();
27
- window.__ossSignatureRes.serverUrl = serverUrl;
28
- }
29
- return window.__ossSignatureRes;
30
- });
31
- }
32
-
33
- class OssUpload {
34
- constructor(props = {}) {
35
- this.axios = props.axios || axios;
36
- this.axiosConf = props.axiosConf || {};
37
- this.serverUrl = props.serverUrl || "/api/v1/user/oss/getWebOssConfig";
38
- this.signatureParams = props.signatureParams || {};
39
- }
40
-
41
- getSignature(serverUrl = this.serverUrl, opt) {
42
- return getSignature({
43
- ...opt,
44
- serverUrl,
45
- axios: opt?.axios || this.axios,
46
- axiosConf: { ...this.axiosConf, ...opt?.axiosConf },
47
- });
48
- }
49
-
50
- upload(file, opt = {}) {
51
- return new Promise(async (resolve, reject) => {
52
- const ossParams = await this.getSignature(opt.serverUrl || this.serverUrl, {
53
- ...opt,
54
- params: { ...this.signatureParams, ...opt.signatureParams },
55
- });
56
-
57
- const { ossParams: propOssParams } = opt || {};
58
- const formData = new FormData();
59
- // key 表示上传到 Bucket 内的 Object 的完整路径,例如 exampledir/exampleobject.txtObject,完整路径中不能包含 Bucket 名称。
60
- // filename 表示待上传的本地文件名称。
61
- let filename = file?.name;
62
- if (file?.name) {
63
- const nameArr = file?.name.match(/^(.+)\.(.+)$/);
64
- if (nameArr && nameArr.length > 2) {
65
- filename = `${nameArr[1]}_${Date.now()}_${nanoid()}.${nameArr[2]}`;
66
- }
67
- }
68
- if (!filename) {
69
- filename = `${Date.now()}_${nanoid()}.${file.type?.replace(/\w+\/, ''/)}`;
70
- }
71
- const key = `${ossParams?.dir}${filename}`;
72
- formData.set("key", key);
73
- formData.set("OSSAccessKeyId", ossParams.accessid);
74
- formData.set("policy", ossParams.policy);
75
- formData.set("Signature", ossParams.signature);
76
- if (ossParams.callback) {
77
- formData.set("callback", ossParams.callback);
78
- }
79
- formData.set("success_action_status", 200);
80
- formData.set("file", file);
81
-
82
- if (propOssParams) {
83
- for (const key in propOssParams) {
84
- if (Object.hasOwnProperty.call(propOssParams, key)) {
85
- formData.set(key, propOssParams[key]);
86
- }
87
- }
88
- }
89
-
90
- const _axios = opt?.axios || this.axios;
91
-
92
- return _axios
93
- .post(ossParams.host, formData, { ...this.axiosConf, ...opt?.axiosConf })
94
- .then((res) => {
95
- resolve(res);
96
- return res;
97
- })
98
- .catch((err) => {
99
- console.error("oss upload err", err);
100
- reject(err);
101
- return Promise.reject(err);
102
- });
103
- });
104
- }
105
- }
106
-
107
- /**
108
- * 处理文件上传逻辑
109
- * @param {Array} files
110
- * @param {Object} opt
111
- * @returns
112
- */
113
- export async function handleOssUpload(files, opt) {
114
- const _files = files;
115
- const { ossUrl, signatureParams, ossParams, axiosConf } = opt || {};
116
- const ossUpload = new OssUpload({
117
- axios: opt.axios,
118
- axiosConf: axiosConf,
119
- serverUrl: ossUrl || "/api/v1/user/oss/getWebOssConfig",
120
- });
121
-
122
- const promise = [];
123
- _files?.forEach((file) => {
124
- // 数据已经是 url 的情况
125
- if (typeof file === "string" || file.ossUrl) {
126
- promise.push(Promise.resolve(file));
127
- } else {
128
- promise.push(
129
- ossUpload
130
- .upload(file, {
131
- signatureParams: {
132
- isPublic: 1,
133
- ...(signatureParams || {}),
134
- },
135
- ossParams,
136
- axiosConf,
137
- })
138
- .then((res) => {
139
- return Promise.resolve(res?.data?.data?.fileUrl);
140
- }),
141
- );
142
- }
143
- });
144
-
145
- return Promise.all(promise).then((filePromises) => {
146
- filePromises?.forEach((fileUrl, idx) => {
147
- _files[idx].ossUrl = fileUrl;
148
- });
149
- return Promise.resolve(_files);
150
- });
151
- }
152
-
153
- export { axios };
154
-
155
- export default OssUpload;