ztxkui 10.0.95 → 10.0.97
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/components/TranslationButton/DownFile.d.ts +7 -0
- package/dist/components/TranslationButton/DownFile.js +97 -0
- package/dist/components/TranslationButton/PreviewFile.d.ts +5 -0
- package/dist/components/TranslationButton/PreviewFile.js +75 -0
- package/dist/components/TranslationButton/TranslationButton.d.ts +34 -0
- package/dist/components/TranslationButton/TranslationButton.js +247 -0
- package/dist/components/TranslationButton/demoComponents/index.d.ts +3 -0
- package/dist/components/TranslationButton/demoComponents/index.js +9 -0
- package/dist/components/TranslationButton/hooks.d.ts +8 -0
- package/dist/components/TranslationButton/hooks.js +143 -0
- package/dist/components/TranslationButton/index.d.ts +4 -0
- package/dist/components/TranslationButton/index.js +4 -0
- package/dist/components/Upload/utils.d.ts +8 -1
- package/dist/components/Upload/utils.js +56 -4
- package/dist/components/UploadCustom/hooks/useDg.d.ts +6 -0
- package/dist/components/UploadCustom/hooks/useDg.js +57 -0
- package/dist/components/business/Signatures/components/CodeModal.d.ts +3 -0
- package/dist/components/business/Signatures/components/CodeModal.js +159 -0
- package/dist/components/electron-signatures/content.d.ts +9 -0
- package/dist/components/electron-signatures/content.js +1126 -0
- package/dist/components/electron-signatures/demoComponents/data.d.ts +58 -0
- package/dist/components/electron-signatures/demoComponents/data.js +1307 -0
- package/dist/components/electron-signatures/demoComponents/detail.d.ts +6 -0
- package/dist/components/electron-signatures/demoComponents/detail.js +283 -0
- package/dist/components/electron-signatures/demoComponents/index.d.ts +2 -0
- package/dist/components/electron-signatures/demoComponents/index.js +27 -0
- package/dist/components/electron-signatures/demoComponents/index_old.d.ts +3 -0
- package/dist/components/electron-signatures/demoComponents/index_old.js +502 -0
- package/dist/components/electron-signatures/demoComponents/jgqrd.d.ts +6 -0
- package/dist/components/electron-signatures/demoComponents/jgqrd.js +135 -0
- package/dist/components/electron-signatures/demoComponents/making.d.ts +6 -0
- package/dist/components/electron-signatures/demoComponents/making.js +211 -0
- package/dist/components/electron-signatures/demoComponents/makingData.d.ts +663 -0
- package/dist/components/electron-signatures/demoComponents/makingData.js +1164 -0
- package/dist/components/electron-signatures/demoComponents/newDetail.d.ts +6 -0
- package/dist/components/electron-signatures/demoComponents/newDetail.js +283 -0
- package/dist/components/electron-signatures/demoComponents/preview.d.ts +3 -0
- package/dist/components/electron-signatures/demoComponents/preview.js +9 -0
- package/dist/components/electron-signatures/demoComponents/singleQjDetail.d.ts +6 -0
- package/dist/components/electron-signatures/demoComponents/singleQjDetail.js +530 -0
- package/dist/components/electron-signatures/demoComponents/singleQjMaking.d.ts +6 -0
- package/dist/components/electron-signatures/demoComponents/singleQjMaking.js +219 -0
- package/dist/components/electron-signatures/demoComponents/test.d.ts +6 -0
- package/dist/components/electron-signatures/demoComponents/test.js +119 -0
- package/dist/components/electron-signatures/dgComponents/contract-comparison.d.ts +39 -0
- package/dist/components/electron-signatures/dgComponents/contract-comparison.js +53 -0
- package/dist/components/electron-signatures/dgComponents/file-comparison-btn.d.ts +11 -0
- package/dist/components/electron-signatures/dgComponents/file-comparison-btn.js +180 -0
- package/dist/components/electron-signatures/dgComponents/new-contract-comparison.d.ts +45 -0
- package/dist/components/electron-signatures/dgComponents/new-contract-comparison.js +68 -0
- package/dist/components/electron-signatures/dgComponents/useContractColumns.d.ts +21 -0
- package/dist/components/electron-signatures/dgComponents/useContractColumns.js +171 -0
- package/dist/components/electron-signatures/electron-signatures-fragment.d.ts +8 -0
- package/dist/components/electron-signatures/electron-signatures-fragment.js +344 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-batch-download.d.ts +52 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-batch-download.js +513 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-detail.d.ts +8 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-detail.js +59 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-download.d.ts +16 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-download.js +89 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-firstLevelPerson.d.ts +9 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-firstLevelPerson.js +16 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-item-detail.d.ts +15 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-item-detail.js +16 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-item.d.ts +20 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-item.js +47 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-list.d.ts +11 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-list.js +191 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-setting.d.ts +15 -0
- package/dist/components/electron-signatures/electronComponents/electron-seal-setting.js +10 -0
- package/dist/components/electron-signatures/electronComponents/last-qys-modal.d.ts +7 -0
- package/dist/components/electron-signatures/electronComponents/last-qys-modal.js +42 -0
- package/dist/components/electron-signatures/electronComponents/useCheckedSealInfoList.d.ts +3 -0
- package/dist/components/electron-signatures/electronComponents/useCheckedSealInfoList.js +45 -0
- package/dist/components/electron-signatures/electronComponents/useElectronColumns.d.ts +30 -0
- package/dist/components/electron-signatures/electronComponents/useElectronColumns.js +380 -0
- package/dist/components/electron-signatures/electronComponents/useFetchElectronData.d.ts +20 -0
- package/dist/components/electron-signatures/electronComponents/useFetchElectronData.js +169 -0
- package/dist/components/electron-signatures/electronComponents/useGetDeptInfo.d.ts +3 -0
- package/dist/components/electron-signatures/electronComponents/useGetDeptInfo.js +38 -0
- package/dist/components/electron-signatures/fileComponents/file-operation.d.ts +7 -0
- package/dist/components/electron-signatures/fileComponents/file-operation.js +67 -0
- package/dist/components/electron-signatures/fileComponents/file-type-select.d.ts +12 -0
- package/dist/components/electron-signatures/fileComponents/file-type-select.js +10 -0
- package/dist/components/electron-signatures/fileComponents/file-upload.d.ts +11 -0
- package/dist/components/electron-signatures/fileComponents/file-upload.js +146 -0
- package/dist/components/electron-signatures/fileComponents/fileUtils.d.ts +17 -0
- package/dist/components/electron-signatures/fileComponents/fileUtils.js +36 -0
- package/dist/components/electron-signatures/fileComponents/new-file-operation.d.ts +10 -0
- package/dist/components/electron-signatures/fileComponents/new-file-operation.js +73 -0
- package/dist/components/electron-signatures/fileComponents/useFetchFileTypeData.d.ts +13 -0
- package/dist/components/electron-signatures/fileComponents/useFetchFileTypeData.js +45 -0
- package/dist/components/electron-signatures/fileComponents/useFileColumns.d.ts +38 -0
- package/dist/components/electron-signatures/fileComponents/useFileColumns.js +329 -0
- package/dist/components/electron-signatures/fileComponents/useFileTypeColumns.d.ts +19 -0
- package/dist/components/electron-signatures/fileComponents/useFileTypeColumns.js +72 -0
- package/dist/components/electron-signatures/hooks/useGetQjVerifyCode.d.ts +30 -0
- package/dist/components/electron-signatures/hooks/useGetQjVerifyCode.js +134 -0
- package/dist/components/electron-signatures/hooks/useMergeRecords.d.ts +17 -0
- package/dist/components/electron-signatures/hooks/useMergeRecords.js +49 -0
- package/dist/components/electron-signatures/hooks/useParseElectronListData.d.ts +49 -0
- package/dist/components/electron-signatures/hooks/useParseElectronListData.js +111 -0
- package/dist/components/electron-signatures/hooks/useParseElectronSetting.d.ts +102 -0
- package/dist/components/electron-signatures/hooks/useParseElectronSetting.js +365 -0
- package/dist/components/electron-signatures/hooks/useParseIsNeedElectronData.d.ts +40 -0
- package/dist/components/electron-signatures/hooks/useParseIsNeedElectronData.js +139 -0
- package/dist/components/electron-signatures/hooks/useParseIsNeedQunjData.d.ts +36 -0
- package/dist/components/electron-signatures/hooks/useParseIsNeedQunjData.js +48 -0
- package/dist/components/electron-signatures/hooks/useParseQunjListData.d.ts +56 -0
- package/dist/components/electron-signatures/hooks/useParseQunjListData.js +204 -0
- package/dist/components/electron-signatures/hooks/useParseQunjSingleData.d.ts +34 -0
- package/dist/components/electron-signatures/hooks/useParseQunjSingleData.js +110 -0
- package/dist/components/electron-signatures/hooks/useParseRecords.d.ts +65 -0
- package/dist/components/electron-signatures/hooks/useParseRecords.js +165 -0
- package/dist/components/electron-signatures/index.d.ts +13 -0
- package/dist/components/electron-signatures/index.js +54 -0
- package/dist/components/electron-signatures/index_old.d.ts +9 -0
- package/dist/components/electron-signatures/index_old.js +966 -0
- package/dist/components/electron-signatures/interface.d.ts +849 -0
- package/dist/components/electron-signatures/interface.js +57 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-apply.d.ts +6 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-apply.js +8 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-check.d.ts +21 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-check.js +41 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-detail.d.ts +35 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-detail.js +267 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-list.d.ts +24 -0
- package/dist/components/electron-signatures/qunjComponents/qunj-list.js +346 -0
- package/dist/components/electron-signatures/qunjComponents/useFetchQunjData.d.ts +20 -0
- package/dist/components/electron-signatures/qunjComponents/useFetchQunjData.js +63 -0
- package/dist/components/electron-signatures/qunjComponents/useQunjColumns.d.ts +36 -0
- package/dist/components/electron-signatures/qunjComponents/useQunjColumns.js +321 -0
- package/dist/components/electron-signatures/translateComponents/TranslateButton.d.ts +10 -0
- package/dist/components/electron-signatures/translateComponents/TranslateButton.js +44 -0
- package/dist/components/electron-signatures/translateComponents/useTranslateCom.d.ts +22 -0
- package/dist/components/electron-signatures/translateComponents/useTranslateCom.js +50 -0
- package/dist/components/electron-signatures/utils.d.ts +26 -0
- package/dist/components/electron-signatures/utils.js +67 -0
- package/dist/components/utils/ZtxkContext.d.ts +16 -0
- package/dist/components/utils/ZtxkContext.js +4 -0
- package/dist/components/utils/useMemoizedFn.d.ts +6 -0
- package/dist/components/utils/useMemoizedFn.js +22 -0
- package/dist/components/utils/usePrevious.d.ts +3 -0
- package/dist/components/utils/usePrevious.js +13 -0
- package/dist/index.css +686 -0
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +105 -87
- package/dist/request.js +1 -1
- package/package.json +4 -3
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import i18next from 'ztxkutils/dist/i18next';
|
|
2
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
3
|
+
import { DownloadOutlined } from '@ant-design/icons';
|
|
4
|
+
import { Button, Dropdown, Menu, message } from '../../index';
|
|
5
|
+
import useServiceName from '../../hooks/useServiceName';
|
|
6
|
+
var DownFile = function (_a) {
|
|
7
|
+
var request = _a.request, tid = _a.tid, fileName = _a.fileName;
|
|
8
|
+
var _b = (useServiceName() || {}).scmServiceName, scmServiceName = _b === void 0 ? '/zmdms-scm-system' : _b;
|
|
9
|
+
// 下载类型选择
|
|
10
|
+
var _c = useState([]), downloadTypeDict = _c[0], setDownloadTypeDict = _c[1];
|
|
11
|
+
var _d = useState(false), loading = _d[0], setLoading = _d[1];
|
|
12
|
+
// 获取下载类型字典
|
|
13
|
+
var getDownloadTypeDict = useCallback(function () {
|
|
14
|
+
return request === null || request === void 0 ? void 0 : request({
|
|
15
|
+
url: "/api/zmdms-system/dict/dictionary",
|
|
16
|
+
method: 'GET',
|
|
17
|
+
params: {
|
|
18
|
+
code: 'fy_file_type',
|
|
19
|
+
},
|
|
20
|
+
}).then(function (res) {
|
|
21
|
+
var _a;
|
|
22
|
+
if (res.status === 200 && res.data.data) {
|
|
23
|
+
setDownloadTypeDict((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data);
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}, [request]);
|
|
27
|
+
useEffect(function () {
|
|
28
|
+
getDownloadTypeDict();
|
|
29
|
+
}, [getDownloadTypeDict]);
|
|
30
|
+
var download = function (dType) {
|
|
31
|
+
setLoading(true);
|
|
32
|
+
request({
|
|
33
|
+
url: "/api" + scmServiceName + "/fanyi/download-trans-file",
|
|
34
|
+
method: 'GET',
|
|
35
|
+
responseType: 'blob',
|
|
36
|
+
params: {
|
|
37
|
+
dtype: dType,
|
|
38
|
+
tid: tid,
|
|
39
|
+
fileName: fileName,
|
|
40
|
+
},
|
|
41
|
+
})
|
|
42
|
+
.then(function (res) {
|
|
43
|
+
try {
|
|
44
|
+
var blob = new Blob([res.data], {
|
|
45
|
+
type: 'application/vnd.ms-excel',
|
|
46
|
+
});
|
|
47
|
+
if (blob.size < 1) {
|
|
48
|
+
message.warning(i18next.t('下载失败,下载的内容为空!'));
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
var aLink = document.createElement('a');
|
|
52
|
+
aLink.style.display = 'none';
|
|
53
|
+
var href = window.URL.createObjectURL(blob);
|
|
54
|
+
aLink.href = href;
|
|
55
|
+
aLink.download = fileName;
|
|
56
|
+
document.body.appendChild(aLink);
|
|
57
|
+
aLink.click();
|
|
58
|
+
document.body.removeChild(aLink);
|
|
59
|
+
window.URL.revokeObjectURL(href);
|
|
60
|
+
return new File([blob], fileName);
|
|
61
|
+
}
|
|
62
|
+
catch (err) {
|
|
63
|
+
console.error(err);
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
.catch(function (err) {
|
|
67
|
+
var _a, _b, _c;
|
|
68
|
+
console.log(err);
|
|
69
|
+
try {
|
|
70
|
+
var blobData = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data;
|
|
71
|
+
blobData
|
|
72
|
+
.text()
|
|
73
|
+
.then(function (data) {
|
|
74
|
+
var result = JSON.parse(data);
|
|
75
|
+
message.error((result === null || result === void 0 ? void 0 : result.msg) || i18next.t('接口调用失败!'));
|
|
76
|
+
})
|
|
77
|
+
.catch(function () {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
message.error(((_b = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg) || i18next.t('接口调用失败!'));
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
catch (e) {
|
|
83
|
+
message.error(((_c = (_b = err === null || err === void 0 ? void 0 : err.response) === null || _b === void 0 ? void 0 : _b.data) === null || _c === void 0 ? void 0 : _c.msg) || i18next.t('接口调用失败!'));
|
|
84
|
+
}
|
|
85
|
+
})
|
|
86
|
+
.finally(function () {
|
|
87
|
+
setLoading(false);
|
|
88
|
+
});
|
|
89
|
+
};
|
|
90
|
+
return (React.createElement(Dropdown, { overlay: function () { return (React.createElement(Menu, { onClick: function (e) {
|
|
91
|
+
download(e.key);
|
|
92
|
+
} }, downloadTypeDict.map(function (item) {
|
|
93
|
+
return React.createElement(Menu.Item, { key: item.dictKey }, item.dictValue);
|
|
94
|
+
}))); }, placement: "bottomLeft" },
|
|
95
|
+
React.createElement(Button, { type: "primary", shape: "circle", icon: React.createElement(DownloadOutlined, null), size: 'small', loading: loading })));
|
|
96
|
+
};
|
|
97
|
+
export default DownFile;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import i18next from 'ztxkutils/dist/i18next';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { createOriginalUrl } from 'ztxkutils/dist/fileOperation';
|
|
4
|
+
import { dangerouslySetXss } from 'ztxkutils/dist/tools';
|
|
5
|
+
import { ZtxkContext } from '../../index';
|
|
6
|
+
import useServiceName from '../../hooks/useServiceName';
|
|
7
|
+
import DownFile from './DownFile';
|
|
8
|
+
var PreviewFile = function (_a) {
|
|
9
|
+
var request = _a.request;
|
|
10
|
+
var fileBaseUrl = React.useContext(ZtxkContext).fileBaseUrl;
|
|
11
|
+
var _b = (useServiceName() || {}).scmServiceName, scmServiceName = _b === void 0 ? '/zmdms-scm-system' : _b;
|
|
12
|
+
var params = new URLSearchParams(window.location.search);
|
|
13
|
+
var oldId = params.get('oldId');
|
|
14
|
+
var tid = params.get('tid');
|
|
15
|
+
var fileName = params.get('fileName') || '';
|
|
16
|
+
try {
|
|
17
|
+
fileName = decodeURIComponent(fileName);
|
|
18
|
+
}
|
|
19
|
+
catch (error) {
|
|
20
|
+
fileName = dangerouslySetXss(fileName);
|
|
21
|
+
console.error(i18next.t('解码文件名失败:'), error);
|
|
22
|
+
}
|
|
23
|
+
var _c = React.useState(''), translatedUrl = _c[0], setTranslatedUrl = _c[1];
|
|
24
|
+
var oldUrl = React.useMemo(function () {
|
|
25
|
+
if (oldId) {
|
|
26
|
+
return createOriginalUrl(fileBaseUrl, oldId, {
|
|
27
|
+
titleName: dangerouslySetXss(fileName || ''),
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
return '';
|
|
31
|
+
}, [fileBaseUrl, oldId, fileName]);
|
|
32
|
+
React.useEffect(function () {
|
|
33
|
+
if (tid) {
|
|
34
|
+
request({
|
|
35
|
+
url: "/api" + scmServiceName + "/fanyi/download-trans-file-id",
|
|
36
|
+
method: 'get',
|
|
37
|
+
params: {
|
|
38
|
+
tid: tid,
|
|
39
|
+
dtype: 3,
|
|
40
|
+
fileName: fileName,
|
|
41
|
+
},
|
|
42
|
+
})
|
|
43
|
+
.then(function (res) {
|
|
44
|
+
setTranslatedUrl(createOriginalUrl(fileBaseUrl, res.data.data.attachId, {
|
|
45
|
+
titleName: res.data.data.originalName,
|
|
46
|
+
}));
|
|
47
|
+
})
|
|
48
|
+
.catch(function (error) {
|
|
49
|
+
console.error(i18next.t('获取翻译文件失败:'), error);
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, [tid, fileBaseUrl, fileName, request]);
|
|
53
|
+
return (React.createElement("div", { style: {
|
|
54
|
+
display: 'flex',
|
|
55
|
+
width: '100%',
|
|
56
|
+
height: '100vh',
|
|
57
|
+
justifyContent: 'space-between',
|
|
58
|
+
overflow: 'hidden',
|
|
59
|
+
} },
|
|
60
|
+
React.createElement("iframe", { style: { width: '100%', height: '100%', border: '2px solid #333' }, src: oldUrl, title: i18next.t('原文档') }),
|
|
61
|
+
React.createElement("div", { style: { width: '5px', height: '100px' } }),
|
|
62
|
+
React.createElement("div", { style: {
|
|
63
|
+
position: 'relative',
|
|
64
|
+
width: '100%',
|
|
65
|
+
border: '2px solid #333',
|
|
66
|
+
} },
|
|
67
|
+
React.createElement("iframe", { style: { width: '100%', height: '100%' }, src: translatedUrl, title: i18next.t('翻译文档') }),
|
|
68
|
+
React.createElement("div", { style: {
|
|
69
|
+
position: 'absolute',
|
|
70
|
+
right: '20px',
|
|
71
|
+
bottom: '50%',
|
|
72
|
+
} },
|
|
73
|
+
React.createElement(DownFile, { request: request, tid: tid, fileName: fileName })))));
|
|
74
|
+
};
|
|
75
|
+
export default PreviewFile;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ButtonProps } from 'antd/lib/button';
|
|
3
|
+
export interface IProps extends ButtonProps {
|
|
4
|
+
/**
|
|
5
|
+
* 附件id 需要翻译的附件id
|
|
6
|
+
*/
|
|
7
|
+
attachId?: string;
|
|
8
|
+
/**
|
|
9
|
+
* 附件名 需要翻译的附件名
|
|
10
|
+
*/
|
|
11
|
+
attachName?: string;
|
|
12
|
+
/**
|
|
13
|
+
* 翻译后的任务ID 用来检测翻译是否完成 用来获取翻译后的文件
|
|
14
|
+
*/
|
|
15
|
+
tid?: string;
|
|
16
|
+
/**
|
|
17
|
+
* 请求方法
|
|
18
|
+
*/
|
|
19
|
+
request?: any;
|
|
20
|
+
/**
|
|
21
|
+
* 开始翻译的其他参数
|
|
22
|
+
*/
|
|
23
|
+
translationParams?: any;
|
|
24
|
+
/**
|
|
25
|
+
* tid改变
|
|
26
|
+
*/
|
|
27
|
+
tidChange?: (tid: string) => void;
|
|
28
|
+
/**
|
|
29
|
+
* 文件预览路径
|
|
30
|
+
*/
|
|
31
|
+
previewUrl: string;
|
|
32
|
+
}
|
|
33
|
+
declare const TranslationButton: React.FC<IProps>;
|
|
34
|
+
export default TranslationButton;
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import i18next from 'ztxkutils/dist/i18next';
|
|
49
|
+
import React, { useState, useMemo } from 'react';
|
|
50
|
+
import { unstable_batchedUpdates } from 'react-dom';
|
|
51
|
+
import { Button, message, Dropdown, Menu, Progress } from '../../index';
|
|
52
|
+
import useServiceName from '../../hooks/useServiceName';
|
|
53
|
+
import { usePercent } from './hooks';
|
|
54
|
+
import { useQuery } from 'react-query';
|
|
55
|
+
var translationTypeList = [
|
|
56
|
+
{ dictKey: '2', dictValue: i18next.t('英文转中文') },
|
|
57
|
+
{ dictKey: '1', dictValue: i18next.t('中文转英文') },
|
|
58
|
+
];
|
|
59
|
+
var TranslationButton = function (props) {
|
|
60
|
+
var attachId = props.attachId, tid = props.tid, request = props.request, translationParams = props.translationParams, tidChange = props.tidChange;
|
|
61
|
+
var _a = useServiceName() || {}, _b = _a.scmServiceName, scmServiceName = _b === void 0 ? '/zmdms-scm-system' : _b, _c = _a.mdmServiceName, mdmServiceName = _c === void 0 ? '/zmdms-mdm-data' : _c;
|
|
62
|
+
var _d = useState(), translationTid = _d[0], setTranslationTid = _d[1];
|
|
63
|
+
var _e = useState(false), loading = _e[0], setLoading = _e[1];
|
|
64
|
+
var res = useQuery({
|
|
65
|
+
queryKey: ['translationTypeList'],
|
|
66
|
+
queryFn: function () {
|
|
67
|
+
return request({
|
|
68
|
+
url: "/api" + mdmServiceName + "/dict-biz/dictionary",
|
|
69
|
+
method: 'GET',
|
|
70
|
+
params: { code: 'zsk_term_library_id' },
|
|
71
|
+
});
|
|
72
|
+
},
|
|
73
|
+
}).data;
|
|
74
|
+
var libraryMap = useMemo(function () {
|
|
75
|
+
var _a;
|
|
76
|
+
return (((_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) || []).reduce(function (acc, item) {
|
|
77
|
+
acc[item.dictKey] = item.dictValue;
|
|
78
|
+
return acc;
|
|
79
|
+
}, {});
|
|
80
|
+
}, [res]);
|
|
81
|
+
// 翻译状态 当没有tid的时候 是 开始状态 start
|
|
82
|
+
// 有tid的时候 调用接口判断是否 是翻译中 然后下载
|
|
83
|
+
var currentTid = useMemo(function () {
|
|
84
|
+
return translationTid || tid;
|
|
85
|
+
}, [translationTid, tid]);
|
|
86
|
+
var translationStatus = useMemo(function () {
|
|
87
|
+
return currentTid ? 'pending' : 'start';
|
|
88
|
+
}, [currentTid]);
|
|
89
|
+
var _f = usePercent({
|
|
90
|
+
currentTid: currentTid,
|
|
91
|
+
request: request,
|
|
92
|
+
}), percent = _f.percent, isTranslating = _f.isTranslating, startTranslate = _f.startTranslate;
|
|
93
|
+
/**
|
|
94
|
+
* @param translationType 翻译转换规则
|
|
95
|
+
*/
|
|
96
|
+
var handleStartTranslation = function (translationType) {
|
|
97
|
+
var translationResultType = {
|
|
98
|
+
from: 'zh',
|
|
99
|
+
to: 'en',
|
|
100
|
+
};
|
|
101
|
+
switch (translationType) {
|
|
102
|
+
case '1':
|
|
103
|
+
translationResultType = {
|
|
104
|
+
from: 'zh',
|
|
105
|
+
to: 'en',
|
|
106
|
+
};
|
|
107
|
+
break;
|
|
108
|
+
case '2':
|
|
109
|
+
translationResultType = {
|
|
110
|
+
from: 'en',
|
|
111
|
+
to: 'zh',
|
|
112
|
+
};
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
setLoading(true);
|
|
116
|
+
// 翻译文件
|
|
117
|
+
request({
|
|
118
|
+
url: "/api" + scmServiceName + "/fanyi/upload-orgin-files",
|
|
119
|
+
method: 'POST',
|
|
120
|
+
data: __assign(__assign({ attachId: attachId, bilingualControl: 0, termLibraryId: (translationParams === null || translationParams === void 0 ? void 0 : translationParams.termLibraryKey)
|
|
121
|
+
? libraryMap[translationParams === null || translationParams === void 0 ? void 0 : translationParams.termLibraryKey]
|
|
122
|
+
: libraryMap['DEFAULT'] }, translationParams), translationResultType),
|
|
123
|
+
})
|
|
124
|
+
.then(function (res) {
|
|
125
|
+
if (res.status === 200) {
|
|
126
|
+
unstable_batchedUpdates(function () {
|
|
127
|
+
var _a, _b, _c, _d;
|
|
128
|
+
setLoading(false);
|
|
129
|
+
setTranslationTid((_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.tid);
|
|
130
|
+
tidChange === null || tidChange === void 0 ? void 0 : tidChange((_d = (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.data) === null || _d === void 0 ? void 0 : _d.tid);
|
|
131
|
+
startTranslate();
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
setLoading(false);
|
|
136
|
+
}
|
|
137
|
+
})
|
|
138
|
+
.catch(function (err) {
|
|
139
|
+
var _a, _b;
|
|
140
|
+
message.error(((_b = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg) || i18next.t('接口调用失败!'));
|
|
141
|
+
setLoading(false);
|
|
142
|
+
});
|
|
143
|
+
};
|
|
144
|
+
var handleDownloadTranslation = function () {
|
|
145
|
+
// 翻译前 先判断下是否翻译完成
|
|
146
|
+
setLoading(true);
|
|
147
|
+
if (currentTid) {
|
|
148
|
+
loopProgress();
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
message.info(i18next.t('没有 找到任务id!'));
|
|
152
|
+
setLoading(false);
|
|
153
|
+
}
|
|
154
|
+
function loopProgress() {
|
|
155
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
156
|
+
var _a, flag, percent_1, title, docType, fileName, err_1;
|
|
157
|
+
return __generator(this, function (_b) {
|
|
158
|
+
switch (_b.label) {
|
|
159
|
+
case 0:
|
|
160
|
+
_b.trys.push([0, 2, , 3]);
|
|
161
|
+
return [4 /*yield*/, getTranslateProgress()];
|
|
162
|
+
case 1:
|
|
163
|
+
_a = _b.sent(), flag = _a.flag, percent_1 = _a.percent, title = _a.title, docType = _a.docType;
|
|
164
|
+
if (flag) {
|
|
165
|
+
setLoading(false);
|
|
166
|
+
fileName = encodeURIComponent(title + '.' + docType);
|
|
167
|
+
window.open(props.previewUrl + "?hideFrame=true&tid=" + currentTid + "&oldId=" + attachId + "&fileName=" + fileName);
|
|
168
|
+
// download(dType);
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
message.warning(i18next.t('当前翻译进度{{percent}}%', { percent: percent_1 }));
|
|
172
|
+
setLoading(false);
|
|
173
|
+
}
|
|
174
|
+
return [3 /*break*/, 3];
|
|
175
|
+
case 2:
|
|
176
|
+
err_1 = _b.sent();
|
|
177
|
+
setLoading(false);
|
|
178
|
+
return [3 /*break*/, 3];
|
|
179
|
+
case 3: return [2 /*return*/];
|
|
180
|
+
}
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
function getTranslateProgress() {
|
|
185
|
+
return request === null || request === void 0 ? void 0 : request({
|
|
186
|
+
url: "/api" + scmServiceName + "/fanyi/query-trans-progress/" + currentTid,
|
|
187
|
+
method: 'GET',
|
|
188
|
+
}).then(function (res) {
|
|
189
|
+
var _a, _b, _c, _d, _e;
|
|
190
|
+
if (res.status === 200) {
|
|
191
|
+
var status_1 = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.status;
|
|
192
|
+
if (status_1 === 314) {
|
|
193
|
+
return Promise.resolve(__assign({ flag: true }, (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.data));
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
return Promise.resolve({
|
|
197
|
+
flag: false,
|
|
198
|
+
percent: Number((_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.percent),
|
|
199
|
+
});
|
|
200
|
+
}).catch(function (err) {
|
|
201
|
+
var _a, _b;
|
|
202
|
+
message.error(((_b = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg) || i18next.t('接口调用失败!'));
|
|
203
|
+
return Promise.reject(false);
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
var renderTranslationDropdown = function (title) {
|
|
208
|
+
return (React.createElement(Dropdown, { overlay: function () { return (React.createElement(Menu, { onClick: function (e) {
|
|
209
|
+
handleStartTranslation(e.key);
|
|
210
|
+
} }, translationTypeList.map(function (item) { return (React.createElement(Menu.Item, { key: item.dictKey }, item.dictValue)); }))); }, placement: "bottomLeft" },
|
|
211
|
+
React.createElement(Button, { type: "link", loading: loading }, title)));
|
|
212
|
+
};
|
|
213
|
+
switch (translationStatus) {
|
|
214
|
+
case 'start':
|
|
215
|
+
return renderTranslationDropdown(i18next.t('翻译文件'));
|
|
216
|
+
case 'pending':
|
|
217
|
+
return (React.createElement(React.Fragment, null,
|
|
218
|
+
React.createElement(Button, { type: "link", loading: loading, onClick: handleDownloadTranslation, disabled: isTranslating }, i18next.t('查看译文')),
|
|
219
|
+
isTranslating && (React.createElement(Progress, { type: "circle", percent: percent, width: 35 })),
|
|
220
|
+
!isTranslating && renderTranslationDropdown(i18next.t('重译'))));
|
|
221
|
+
// case 'down':
|
|
222
|
+
// return (
|
|
223
|
+
// <Dropdown
|
|
224
|
+
// overlay={() => (
|
|
225
|
+
// <Menu
|
|
226
|
+
// onClick={(e) => {
|
|
227
|
+
// handleDownloadTranslation(e.key);
|
|
228
|
+
// }}
|
|
229
|
+
// >
|
|
230
|
+
// {downloadTypeDict.map((item) => {
|
|
231
|
+
// return (
|
|
232
|
+
// <Menu.Item key={item.dictKey}>{item.dictValue}</Menu.Item>
|
|
233
|
+
// );
|
|
234
|
+
// })}
|
|
235
|
+
// </Menu>
|
|
236
|
+
// )}
|
|
237
|
+
// placement="bottomLeft"
|
|
238
|
+
// >
|
|
239
|
+
// <Button type="link" loading={loading}>
|
|
240
|
+
// 下载
|
|
241
|
+
// </Button>
|
|
242
|
+
// </Dropdown>
|
|
243
|
+
// );
|
|
244
|
+
}
|
|
245
|
+
return React.createElement(React.Fragment, null);
|
|
246
|
+
};
|
|
247
|
+
export default TranslationButton;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import i18next from 'ztxkutils/dist/i18next';
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { TranslationButton } from '../../../index';
|
|
4
|
+
import request from '../../../request';
|
|
5
|
+
var Demo = function () {
|
|
6
|
+
return (React.createElement("div", null,
|
|
7
|
+
React.createElement(TranslationButton, { request: request, attachId: "8121178081808801831", attachName: i18next.t('现货价格政策功能方案初稿9-27.docx'), tid: "88", previewUrl: "/document-translation-preview" })));
|
|
8
|
+
};
|
|
9
|
+
export default Demo;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
var __assign = (this && this.__assign) || function () {
|
|
2
|
+
__assign = Object.assign || function(t) {
|
|
3
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
4
|
+
s = arguments[i];
|
|
5
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
6
|
+
t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
14
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
15
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
16
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
17
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
18
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
22
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
23
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
24
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
25
|
+
function step(op) {
|
|
26
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
27
|
+
while (_) try {
|
|
28
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
29
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
30
|
+
switch (op[0]) {
|
|
31
|
+
case 0: case 1: t = op; break;
|
|
32
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
33
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
34
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
35
|
+
default:
|
|
36
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
37
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
38
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
39
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
40
|
+
if (t[2]) _.ops.pop();
|
|
41
|
+
_.trys.pop(); continue;
|
|
42
|
+
}
|
|
43
|
+
op = body.call(thisArg, _);
|
|
44
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
45
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
import i18next from 'ztxkutils/dist/i18next';
|
|
49
|
+
import { useState, useEffect, useRef } from 'react';
|
|
50
|
+
import { message } from 'ztxkui';
|
|
51
|
+
import useServiceName from '../../hooks/useServiceName';
|
|
52
|
+
function getTranslateProgress(request, currentTid, scmServiceName) {
|
|
53
|
+
return request === null || request === void 0 ? void 0 : request({
|
|
54
|
+
url: "/api" + scmServiceName + "/fanyi/query-trans-progress/" + currentTid,
|
|
55
|
+
method: 'GET',
|
|
56
|
+
}).then(function (res) {
|
|
57
|
+
var _a, _b, _c, _d, _e;
|
|
58
|
+
if (res.status === 200) {
|
|
59
|
+
var status_1 = (_b = (_a = res === null || res === void 0 ? void 0 : res.data) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.status;
|
|
60
|
+
if (status_1 === 314) {
|
|
61
|
+
return Promise.resolve(__assign({ flag: true }, (_c = res === null || res === void 0 ? void 0 : res.data) === null || _c === void 0 ? void 0 : _c.data));
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return Promise.resolve({
|
|
65
|
+
flag: false,
|
|
66
|
+
percent: Number((_e = (_d = res === null || res === void 0 ? void 0 : res.data) === null || _d === void 0 ? void 0 : _d.data) === null || _e === void 0 ? void 0 : _e.percent),
|
|
67
|
+
});
|
|
68
|
+
}).catch(function (err) {
|
|
69
|
+
var _a, _b;
|
|
70
|
+
message.error(((_b = (_a = err === null || err === void 0 ? void 0 : err.response) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.msg) || i18next.t('接口调用失败!'));
|
|
71
|
+
return Promise.reject(false);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
export function usePercent(_a) {
|
|
75
|
+
var _this = this;
|
|
76
|
+
var request = _a.request, currentTid = _a.currentTid;
|
|
77
|
+
var _b = useState(0), percent = _b[0], setPercent = _b[1];
|
|
78
|
+
var _c = useState(false), pending = _c[0], setPending = _c[1];
|
|
79
|
+
var timerRef = useRef();
|
|
80
|
+
var requestRef = useRef(request);
|
|
81
|
+
requestRef.current = request;
|
|
82
|
+
var currentTidRef = useRef(currentTid);
|
|
83
|
+
currentTidRef.current = currentTid;
|
|
84
|
+
var _d = (useServiceName() || {}).scmServiceName, scmServiceName = _d === void 0 ? '/zmdms-scm-system' : _d;
|
|
85
|
+
var scmServiceNameRef = useRef(scmServiceName);
|
|
86
|
+
scmServiceNameRef.current = scmServiceName;
|
|
87
|
+
useEffect(function () {
|
|
88
|
+
return function () {
|
|
89
|
+
return clearTimeout(timerRef.current);
|
|
90
|
+
};
|
|
91
|
+
}, []);
|
|
92
|
+
useEffect(function () {
|
|
93
|
+
if (currentTid) {
|
|
94
|
+
handleTranslateProgress().then(function (isCompleted) {
|
|
95
|
+
if (!isCompleted) {
|
|
96
|
+
queryTranslateProgress();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
101
|
+
}, [currentTid]);
|
|
102
|
+
// 处理翻译进度结果
|
|
103
|
+
var handleTranslateProgress = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
104
|
+
var _a, flag, percent;
|
|
105
|
+
return __generator(this, function (_b) {
|
|
106
|
+
switch (_b.label) {
|
|
107
|
+
case 0: return [4 /*yield*/, getTranslateProgress(requestRef.current, currentTidRef.current, scmServiceNameRef.current)];
|
|
108
|
+
case 1:
|
|
109
|
+
_a = _b.sent(), flag = _a.flag, percent = _a.percent;
|
|
110
|
+
setPending(!flag);
|
|
111
|
+
setPercent(percent);
|
|
112
|
+
return [2 /*return*/, flag];
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
}); };
|
|
116
|
+
// 轮询翻译进度
|
|
117
|
+
var queryTranslateProgress = function () {
|
|
118
|
+
timerRef.current = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
119
|
+
var isCompleted;
|
|
120
|
+
return __generator(this, function (_a) {
|
|
121
|
+
switch (_a.label) {
|
|
122
|
+
case 0: return [4 /*yield*/, handleTranslateProgress()];
|
|
123
|
+
case 1:
|
|
124
|
+
isCompleted = _a.sent();
|
|
125
|
+
if (!isCompleted) {
|
|
126
|
+
queryTranslateProgress();
|
|
127
|
+
}
|
|
128
|
+
return [2 /*return*/];
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
}); }, 2000);
|
|
132
|
+
};
|
|
133
|
+
function startTranslate() {
|
|
134
|
+
setPercent(0);
|
|
135
|
+
setPending(true);
|
|
136
|
+
queryTranslateProgress();
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
startTranslate: startTranslate,
|
|
140
|
+
percent: percent,
|
|
141
|
+
isTranslating: pending,
|
|
142
|
+
};
|
|
143
|
+
}
|