@hzab/form-render-mobile 1.2.0 → 1.2.1-beta1

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,61 +1,69 @@
1
- import { axios } from "@hzab/data-model";
2
- import OssUpload from "@hzab/utils/src/upload/ossUpload";
3
-
4
- /**
5
- * 处理文件上传逻辑
6
- * @param {Array} files
7
- * @param {Object} opt
8
- * @returns
9
- */
10
- export async function handleOssUpload(files, opt) {
11
- const _files = files;
12
- const { ossUrl, signatureParams, ossParams, axiosConf, beforeUpload } = opt || {};
13
- const ossUpload = new OssUpload({
14
- axios: opt.axios,
15
- axiosConf: axiosConf,
16
- serverUrl: ossUrl || "/api/v1/user/oss/getWebOssConfig",
17
- });
18
-
19
- const promise = [];
20
- _files?.forEach((file) => {
21
- // 数据已经是 url 的情况
22
- if (typeof file === "string") {
23
- promise.push(Promise.resolve(file));
24
- } else if (typeof file.ossUrl === "string") {
25
- promise.push(Promise.resolve(file.ossUrl));
26
- } else {
27
- promise.push(
28
- new Promise(async (resolve, reject) => {
29
- const f = (await (beforeUpload && beforeUpload(file, { reject }))) || file;
30
-
31
- ossUpload
32
- .upload(f, {
33
- ...opt,
34
- signatureParams: {
35
- isPublic: 1,
36
- ...(signatureParams || {}),
37
- },
38
- ossParams,
39
- axiosConf,
40
- })
41
- .then((res) => {
42
- resolve(res?.data?.data?.fileUrl);
43
- return Promise.resolve(res?.data?.data?.fileUrl);
44
- })
45
- .catch(reject);
46
- }),
47
- );
48
- }
49
- });
50
-
51
- return Promise.all(promise).then((filePromises) => {
52
- filePromises?.forEach((fileUrl, idx) => {
53
- _files[idx].ossUrl = fileUrl;
54
- });
55
- return Promise.resolve(_files);
56
- });
57
- }
58
-
59
- export { axios };
60
-
61
- export default OssUpload;
1
+ import { axios } from "@hzab/data-model";
2
+ import OssUpload from "@hzab/utils/src/upload/ossUpload";
3
+
4
+ /**
5
+ * 处理文件上传逻辑
6
+ * @param {Array} files
7
+ * @param {Object} opt
8
+ * @returns
9
+ */
10
+ export async function handleOssUpload(files, opt) {
11
+ const _files = files;
12
+ const { ossUrl, signatureParams, ossParams, axiosConf, beforeUpload, thumbnailParams } = opt || {};
13
+ const ossUpload = new OssUpload({
14
+ axios: opt.axios,
15
+ axiosConf: axiosConf,
16
+ serverUrl: ossUrl || "/api/v1/user/oss/getWebOssConfig",
17
+ });
18
+
19
+ const promise = [];
20
+ _files?.forEach((file) => {
21
+ // 数据已经是 url 的情况
22
+ if (typeof file === "string") {
23
+ promise.push(Promise.resolve(file));
24
+ } else if (typeof file.ossUrl === "string") {
25
+ promise.push(Promise.resolve(file.ossUrl));
26
+ } else {
27
+ promise.push(
28
+ new Promise(async (resolve, reject) => {
29
+ const f = (await (beforeUpload && beforeUpload(file, { reject }))) || file;
30
+
31
+ ossUpload
32
+ .upload(f, {
33
+ ...opt,
34
+ signatureParams: {
35
+ isPublic: 1,
36
+ ...(signatureParams || {}),
37
+ },
38
+ ossParams,
39
+ axiosConf,
40
+ thumbnailParams,
41
+ })
42
+ .then((res) => {
43
+ resolve({
44
+ fileUrl: res?.data?.data?.fileUrl,
45
+ thumbnailUrl: res?.data?.data?.thumbnailUrl,
46
+ });
47
+ return Promise.resolve({
48
+ fileUrl: res?.data?.data?.fileUrl,
49
+ thumbnailUrl: res?.data?.data?.thumbnailUrl,
50
+ });
51
+ })
52
+ .catch(reject);
53
+ }),
54
+ );
55
+ }
56
+ });
57
+
58
+ return Promise.all(promise).then((filePromises) => {
59
+ filePromises?.forEach((item, idx) => {
60
+ _files[idx].ossUrl = item?.fileUrl;
61
+ _files[idx].thumbnailUrl = item?.thumbnailUrl;
62
+ });
63
+ return Promise.resolve(_files);
64
+ });
65
+ }
66
+
67
+ export { axios };
68
+
69
+ export default OssUpload;
@@ -1,142 +1,147 @@
1
- import { nanoid } from "nanoid";
2
-
3
- /**
4
- * 建立一个可以存取该 file 的 url
5
- * @param {Object} file 文件
6
- * @returns {string} url
7
- * blob:http://localhost:8000/c9950644-5118-4231-9be7-8183bde1fdc7
8
- */
9
- export function getFileURL(file) {
10
- let url = file.url || null;
11
-
12
- try {
13
- // 下面函数执行的效果是一样的,只是需要针对不同的浏览器执行不同的 js 函数而已
14
- if (window.createObjectURL != undefined) {
15
- // basic
16
- url = window.createObjectURL(file);
17
- } else if (window.URL != undefined) {
18
- // mozilla(firefox)
19
- url = window.URL.createObjectURL(file);
20
- } else if (window.webkitURL != undefined) {
21
- // webkit or chrome
22
- url = window.webkitURL.createObjectURL(file);
23
- }
24
- } catch (error) {
25
- console.warn("getFileURL Error: ", error);
26
- }
27
-
28
- return url;
29
- }
30
-
31
- /**
32
- * 判断 url 是否带有指定图片后缀
33
- * @param {string} url
34
- * @returns
35
- */
36
- export function checkImageUrl(url) {
37
- const imgTypes = [
38
- "apng",
39
- "avif",
40
- "bmp",
41
- "gif",
42
- "ico",
43
- "cur",
44
- "jpg",
45
- "jpeg",
46
- "jfif",
47
- "pjpeg",
48
- "pjp",
49
- "png",
50
- "svg",
51
- "tif",
52
- "tiff",
53
- "webp",
54
- ];
55
- return checkUrlSuffix(url, imgTypes);
56
- }
57
-
58
- /**
59
- * 判断 url 是否带有指定视频后缀
60
- * @param {string} url
61
- * @returns
62
- */
63
- export function checkVideoUrl(url) {
64
- const imgTypes = ["3gp", "mpg", "mpeg", "mp4", "m4v", "m4p", "ogv", "ogg", "mov", "webm"];
65
- return checkUrlSuffix(url, imgTypes);
66
- }
67
-
68
- /**
69
- * 判断 url 是否带有指定音频后缀
70
- * @param {string} url
71
- * @returns
72
- */
73
- export function checkAudioUrl(url) {
74
- const imgTypes = ["3gp", "adts", "mpeg", "mp3", "mp4", "ogg", "mov", "webm", "rtp", "amr", "wav"];
75
- return checkUrlSuffix(url, imgTypes);
76
- }
77
-
78
- /**
79
- * 检查 url 是否带有指定后缀
80
- * @param {string} url url 地址
81
- * @param {Array} types 后缀数组
82
- * @returns
83
- */
84
- export function checkUrlSuffix(url, types = [], caseSensitive) {
85
- if (!url) {
86
- return false;
87
- }
88
- let _url = url?.replace(/\?.+/, "");
89
- const reg = new RegExp(`\.(${types.join("|")})$`, caseSensitive ? undefined : "i");
90
- if (reg.test(_url)) {
91
- return true;
92
- }
93
- }
94
-
95
- function getArr(value) {
96
- return Array.isArray(value) ? value : (value && [value]) || [];
97
- }
98
-
99
- export function handleMaxCount(fileList, maxCount) {
100
- let list = getArr(fileList);
101
- if (maxCount > 0 && list.length > maxCount) {
102
- list = list.slice(maxCount);
103
- }
104
- return list;
105
- }
106
-
107
- /**
108
- * 处理传入的数据,数据格式统一转成 Array<fileObject>
109
- * @param {Array} fileList Array<fileObject|string>
110
- * @param {number} maxCount
111
- * @returns Array<fileObject>
112
- */
113
- export function handleInputFileList(_fileList, maxCount = 1) {
114
- const fileList = handleMaxCount(getArr(_fileList), maxCount);
115
- if (fileList.length === 0) {
116
- return fileList;
117
- }
118
- let resList = fileList;
119
- if (!Array.isArray(resList)) {
120
- resList = [resList];
121
- }
122
- resList = fileList.map((file, i) => {
123
- if (typeof file === "string") {
124
- const uid = nanoid();
125
- return {
126
- name: uid,
127
- uid: uid,
128
- ossUrl: file,
129
- url: file,
130
- // size: Infinity,
131
- };
132
- }
133
- if (file && !file.uid) {
134
- file.uid = nanoid();
135
- }
136
- if (file && !file.name) {
137
- file.name = file.uid;
138
- }
139
- return file;
140
- });
141
- return resList;
142
- }
1
+ import { nanoid } from "nanoid";
2
+
3
+ /**
4
+ * 建立一个可以存取该 file 的 url
5
+ * @param {Object} file 文件
6
+ * @returns {string} url
7
+ * blob:http://localhost:8000/c9950644-5118-4231-9be7-8183bde1fdc7
8
+ */
9
+ export function getFileURL(file) {
10
+ let url = file.url || null;
11
+
12
+ try {
13
+ // 下面函数执行的效果是一样的,只是需要针对不同的浏览器执行不同的 js 函数而已
14
+ if (window.createObjectURL != undefined) {
15
+ // basic
16
+ url = window.createObjectURL(file);
17
+ } else if (window.URL != undefined) {
18
+ // mozilla(firefox)
19
+ url = window.URL.createObjectURL(file);
20
+ } else if (window.webkitURL != undefined) {
21
+ // webkit or chrome
22
+ url = window.webkitURL.createObjectURL(file);
23
+ }
24
+ } catch (error) {
25
+ console.warn("getFileURL Error: ", error);
26
+ }
27
+
28
+ return url;
29
+ }
30
+
31
+ /**
32
+ * 判断 url 是否带有指定图片后缀
33
+ * @param {string} url
34
+ * @returns
35
+ */
36
+ export function checkImageUrl(url) {
37
+ const imgTypes = [
38
+ "apng",
39
+ "avif",
40
+ "bmp",
41
+ "gif",
42
+ "ico",
43
+ "cur",
44
+ "jpg",
45
+ "jpeg",
46
+ "jfif",
47
+ "pjpeg",
48
+ "pjp",
49
+ "png",
50
+ "svg",
51
+ "tif",
52
+ "tiff",
53
+ "webp",
54
+ ];
55
+ return checkUrlSuffix(url, imgTypes);
56
+ }
57
+
58
+ /**
59
+ * 判断 url 是否带有指定视频后缀
60
+ * @param {string} url
61
+ * @returns
62
+ */
63
+ export function checkVideoUrl(url) {
64
+ const imgTypes = ["3gp", "mpg", "mpeg", "mp4", "m4v", "m4p", "ogv", "ogg", "mov", "webm"];
65
+ return checkUrlSuffix(url, imgTypes);
66
+ }
67
+
68
+ /**
69
+ * 判断 url 是否带有指定音频后缀
70
+ * @param {string} url
71
+ * @returns
72
+ */
73
+ export function checkAudioUrl(url) {
74
+ const imgTypes = ["3gp", "adts", "mpeg", "mp3", "mp4", "ogg", "mov", "webm", "rtp", "amr", "wav"];
75
+ return checkUrlSuffix(url, imgTypes);
76
+ }
77
+
78
+ /**
79
+ * 检查 url 是否带有指定后缀
80
+ * @param {string} url url 地址
81
+ * @param {Array} types 后缀数组
82
+ * @returns
83
+ */
84
+ export function checkUrlSuffix(url, types = [], caseSensitive) {
85
+ if (!url) {
86
+ return false;
87
+ }
88
+ let _url = url?.replace(/\?.+/, "");
89
+ const reg = new RegExp(`\.(${types.join("|")})$`, caseSensitive ? undefined : "i");
90
+ if (reg.test(_url)) {
91
+ return true;
92
+ }
93
+ }
94
+
95
+ function getArr(value) {
96
+ return Array.isArray(value) ? value : (value && [value]) || [];
97
+ }
98
+
99
+ export function handleMaxCount(fileList, maxCount) {
100
+ let list = getArr(fileList);
101
+ if (maxCount > 0 && list.length > maxCount) {
102
+ list = list.slice(maxCount);
103
+ }
104
+ return list;
105
+ }
106
+
107
+ /**
108
+ * 处理传入的数据,数据格式统一转成 Array<fileObject>
109
+ * @param {Array} fileList Array<fileObject|string>
110
+ * @param {number} maxCount
111
+ * @returns Array<fileObject>
112
+ */
113
+ export function handleInputFileList(_fileList, maxCount = 1, opt) {
114
+ const fileList = handleMaxCount(getArr(_fileList), maxCount);
115
+ if (fileList.length === 0) {
116
+ return fileList;
117
+ }
118
+ let resList = fileList;
119
+ if (!Array.isArray(resList)) {
120
+ resList = [resList];
121
+ }
122
+ resList = fileList.map((file, i) => {
123
+ if (typeof file === "string") {
124
+ const uid = nanoid();
125
+ let thumbnailUrl = "";
126
+ if (opt?.ossOpt?.signatureParams?.isPublic !== 0) {
127
+ thumbnailUrl = `${file}${opt?.thumbnailParams ? "?" + opt?.thumbnailParams : ""}`;
128
+ }
129
+ return {
130
+ name: uid,
131
+ uid: uid,
132
+ ossUrl: file,
133
+ url: file,
134
+ thumbnailUrl: thumbnailUrl,
135
+ // size: Infinity,
136
+ };
137
+ }
138
+ if (file && !file.uid) {
139
+ file.uid = nanoid();
140
+ }
141
+ if (file && !file.name) {
142
+ file.name = file.uid;
143
+ }
144
+ return file;
145
+ });
146
+ return resList;
147
+ }
@@ -1,45 +1,45 @@
1
- import { useState, useEffect } from "react";
2
- import { ImageViewer } from "antd-mobile";
3
-
4
- import { loadHeaderImage } from "../../common/img";
5
-
6
- import "./index.less";
7
-
8
- function ImagePreviewer(props) {
9
- const { headers, src } = props;
10
- const [maskVisible, setMaskVisible] = useState(false);
11
- const [imgUrl, setImgUrl] = useState("");
12
-
13
- function onPreview() {
14
- setMaskVisible(true);
15
- }
16
-
17
- const init = async () => {
18
- if (headers) {
19
- loadHeaderImage(src, headers).then(setImgUrl);
20
- } else {
21
- setImgUrl(src);
22
- }
23
- };
24
-
25
- useEffect(() => {
26
- init();
27
- }, [src]);
28
-
29
- return (
30
- <div className={`uploader-image-previewer ${props.className || ""}`}>
31
- <div className="uploader-image-previewer-img-wrap" onClick={onPreview}>
32
- <img className="uploader-image-previewer-img" src={imgUrl} alt={props.alt} onClick={onPreview} />
33
- </div>
34
- <ImageViewer
35
- image={imgUrl}
36
- visible={maskVisible}
37
- onClose={() => {
38
- setMaskVisible(false);
39
- }}
40
- />
41
- </div>
42
- );
43
- }
44
-
45
- export default ImagePreviewer;
1
+ import { useState, useEffect } from "react";
2
+ import { ImageViewer } from "antd-mobile";
3
+
4
+ import { loadHeaderImage } from "../../common/img";
5
+
6
+ import "./index.less";
7
+
8
+ function ImagePreviewer(props) {
9
+ const { headers, src, thumbnailUrl } = props;
10
+ const [maskVisible, setMaskVisible] = useState(false);
11
+ const [imgUrl, setImgUrl] = useState("");
12
+
13
+ function onPreview() {
14
+ setMaskVisible(true);
15
+ }
16
+
17
+ const init = async () => {
18
+ if (headers) {
19
+ loadHeaderImage(src, headers).then(setImgUrl);
20
+ } else {
21
+ setImgUrl(src);
22
+ }
23
+ };
24
+
25
+ useEffect(() => {
26
+ init();
27
+ }, [src]);
28
+
29
+ return (
30
+ <div className={`uploader-image-previewer ${props.className || ""}`}>
31
+ <div className="uploader-image-previewer-img-wrap" onClick={onPreview}>
32
+ <img className="uploader-image-previewer-img" src={thumbnailUrl} alt={props.alt} onClick={onPreview} />
33
+ </div>
34
+ <ImageViewer
35
+ image={imgUrl}
36
+ visible={maskVisible}
37
+ onClose={() => {
38
+ setMaskVisible(false);
39
+ }}
40
+ />
41
+ </div>
42
+ );
43
+ }
44
+
45
+ export default ImagePreviewer;
@@ -1,49 +1,53 @@
1
- import { getFileURL } from "../../common/utils";
2
-
3
- import { TYPE_VIDEO, TYPE_IMG, TYPE_AUDIO, checkFileType } from "../../common/checkFileType";
4
-
5
- import Video from "../video";
6
- import Image from "../Image";
7
- import ItemRender from "./ItemRender";
8
-
9
- export const ItemList = (props) => {
10
- const { fileList, baseUrl, disabled, readOnly, onItemDel, headers } = props || {};
11
-
12
- return (
13
- <>
14
- {fileList.map((it, idx) => {
15
- if (!it) {
16
- return null;
17
- }
18
- const { name, url = it?.ossUrl } = it || {};
19
-
20
- let src = url || getFileURL(it);
21
-
22
- if (baseUrl) {
23
- src = baseUrl + src;
24
- }
25
-
26
- let content = it?.name;
27
-
28
- const fileType = checkFileType(it);
29
- if (fileType === TYPE_IMG) {
30
- content = <Image className="file-item-view" headers={headers} src={src} alt={name} />;
31
- }
32
- if (fileType === TYPE_VIDEO) {
33
- content = <Video src={src} href={src} />;
34
- }
35
- if (fileType === TYPE_AUDIO) {
36
- content = <audio src={src} controls></audio>;
37
- }
38
-
39
- return (
40
- <ItemRender index={idx} key={name + "_" + idx} disabled={disabled} readOnly={readOnly} onItemDel={onItemDel}>
41
- <div className="file-item-content-box">{content}</div>
42
- </ItemRender>
43
- );
44
- })}
45
- </>
46
- );
47
- };
48
-
49
- export default ItemList;
1
+ import { getFileURL } from "../../common/utils";
2
+
3
+ import { TYPE_VIDEO, TYPE_IMG, TYPE_AUDIO, checkFileType } from "../../common/checkFileType";
4
+
5
+ import Video from "../video";
6
+ import Image from "../Image";
7
+ import ItemRender from "./ItemRender";
8
+
9
+ export const ItemList = (props) => {
10
+ const { fileList, baseUrl, disabled, readOnly, onItemDel, headers } = props || {};
11
+
12
+ return (
13
+ <>
14
+ {fileList.map((it, idx) => {
15
+ if (!it) {
16
+ return null;
17
+ }
18
+ const { name, url = it?.ossUrl, thumbnailUrl } = it || {};
19
+
20
+ let src = url || getFileURL(it);
21
+ let thumbnailSrc = thumbnailUrl;
22
+
23
+ if (baseUrl) {
24
+ src = baseUrl + src;
25
+ thumbnailSrc = baseUrl + thumbnailUrl;
26
+ }
27
+
28
+ let content = it?.name;
29
+
30
+ const fileType = checkFileType(it);
31
+ if (fileType === TYPE_IMG) {
32
+ content = (
33
+ <Image className="file-item-view" headers={headers} src={src} thumbnailUrl={thumbnailSrc} alt={name} />
34
+ );
35
+ }
36
+ if (fileType === TYPE_VIDEO) {
37
+ content = <Video src={src} href={src} />;
38
+ }
39
+ if (fileType === TYPE_AUDIO) {
40
+ content = <audio src={src} controls></audio>;
41
+ }
42
+
43
+ return (
44
+ <ItemRender index={idx} key={name + "_" + idx} disabled={disabled} readOnly={readOnly} onItemDel={onItemDel}>
45
+ <div className="file-item-content-box">{content}</div>
46
+ </ItemRender>
47
+ );
48
+ })}
49
+ </>
50
+ );
51
+ };
52
+
53
+ export default ItemList;