@gientech/modual 1.3.2 → 1.3.3
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/.editorconfig +38 -0
- package/.prettierignore +16 -0
- package/.prettierrc +17 -0
- package/README.md +129 -129
- package/USAGE.md +191 -0
- package/bash.exe.stackdump +40 -0
- package/components.json +21 -0
- package/dist/README.md +129 -0
- package/{assets → dist/assets}/database.svg +11 -11
- package/{assets → dist/assets}/database_add.svg +53 -53
- package/{assets → dist/assets}/database_connect.svg +66 -66
- package/{assets → dist/assets}/database_upload.svg +29 -29
- package/{assets → dist/assets}/defaultWeLogo.svg +14 -14
- package/{assets/index-ldqIbm0x.js → dist/assets/index-XvC_4jDB.js} +106 -101
- package/{assets/index-D-dGaGjW.js → dist/assets/index-mPgEc8KC.js} +288 -102
- package/{assets/MySQL.svg → dist/assets/mysql.svg} +14 -14
- package/dist/assets/style.css +1 -0
- package/dist/assets/style3.css +1 -0
- package/{chat.js → dist/chat.js} +78 -78
- package/dist/database.js +20 -0
- package/{databaseId.js → dist/databaseId.js} +1 -1
- package/{databaseTable.js → dist/databaseTable.js} +1 -1
- package/{modelManage.js → dist/modelManage.js} +1 -1
- package/dist/package.json +56 -0
- package/{sensitive.js → dist/sensitive.js} +1 -1
- package/{streamFilesReader.js → dist/streamFilesReader.js} +11 -11
- package/{worker → dist/worker}/pdf.worker.min.js +21 -21
- package/doc_assets/2.png +0 -0
- package/doc_assets/demo.md +27 -0
- package/doc_assets/demos/dist-app/assets/index.Dh-ZAS9Z.css +2 -0
- package/doc_assets/demos/dist-app/assets/index.Dv8KVW18.js +23699 -0
- package/doc_assets/demos/dist-app/assets/index.Dv8KVW18.js.map +1 -0
- package/doc_assets/demos/dist-app/index.html +14 -0
- package/doc_assets/demos/dist-app/vite.svg +1 -0
- package/doc_assets/images/1.png +0 -0
- package/doc_assets/images/3.png +0 -0
- package/doc_assets/images/component-screenshot.png +1 -0
- package/doc_assets/install.md +5 -0
- package/eslint.config.js +92 -0
- package/index.html +13 -0
- package/package.json +83 -39
- package/postcss.config.cjs +19 -0
- package/public/vite.svg +1 -0
- package/public/worker/pdf.worker.min.js +22 -0
- package/scripts/README.md +133 -0
- package/scripts/build-demo.js +88 -0
- package/scripts/demo-selector.js +216 -0
- package/scripts/dev-demo.js +76 -0
- package/scripts/preview-demo.js +130 -0
- package/scripts/run-demo.bat +34 -0
- package/src/assets/img/downArrow.png +0 -0
- package/src/assets/img/excel.png +0 -0
- package/src/assets/img/img.png +0 -0
- package/src/assets/img/pdf.png +0 -0
- package/src/assets/img/ppt.png +0 -0
- package/src/assets/img/txt.png +0 -0
- package/src/assets/img/word.png +0 -0
- package/src/assets/login/homeBg.png +0 -0
- package/src/assets/login/left.jpg +0 -0
- package/src/assets/login/logoImg.png +0 -0
- package/src/examples/LoginPage/index.tsx +18 -0
- package/src/examples/aaa/index.tsx +3758 -0
- package/src/examples/chat/components/DrawerGraphPreview.tsx +78 -0
- package/src/examples/chat/index.tsx +190 -0
- package/src/examples/gientechStreamFilesReader/index.tsx +1016 -0
- package/src/examples/ragDatabaseDataPage/index.tsx +36 -0
- package/src/examples/ragDatabaseIdPage/index.tsx +44 -0
- package/src/examples/ragDatabasePage/index.tsx +36 -0
- package/src/examples/ragModelManagePage/index.tsx +37 -0
- package/src/examples/ragSearchPage/index.tsx +0 -0
- package/src/examples/ragSensitiveWordsPage/index.tsx +32 -0
- package/src/examples/streamFiles/index.tsx +384 -0
- package/src/lib_enter.ts +38 -0
- package/src/main.tsx +5 -0
- package/src/main.tsx.backup +5 -0
- package/src/modules/chat/Conversations/Item.tsx +167 -0
- package/src/modules/chat/Conversations/List.tsx +143 -0
- package/src/modules/chat/Conversations/groupByTime.ts +39 -0
- package/src/modules/chat/Conversations/index.tsx +212 -0
- package/src/modules/chat/constants.tsx +33 -0
- package/src/modules/chat/data.txt +82 -0
- package/src/modules/chat/index.tsx +1908 -0
- package/src/modules/chat/types.ts +17 -0
- package/src/modules/database/CreateModal.tsx +398 -0
- package/src/modules/database/assets/Doris.png +0 -0
- package/src/modules/database/assets/PostgreSQL.png +0 -0
- package/src/modules/database/assets/SQLServer.png +0 -0
- package/src/modules/database/assets/database.svg +11 -0
- package/src/modules/database/assets/database_add.svg +53 -0
- package/src/modules/database/assets/database_connect.svg +66 -0
- package/src/modules/database/assets/database_upload.svg +29 -0
- package/src/modules/database/assets/empty.png +0 -0
- package/src/modules/database/assets/mysql.svg +14 -0
- package/src/modules/database/index.tsx +466 -0
- package/src/modules/database/server.ts +196 -0
- package/src/modules/databaseId/CustomCom.tsx +156 -0
- package/src/modules/databaseId/EditConfig.tsx +268 -0
- package/src/modules/databaseId/UploadDrawer.tsx +520 -0
- package/src/modules/databaseId/assets/aiOptimize.svg +10 -0
- package/src/modules/databaseId/assets/empty.png +0 -0
- package/src/modules/databaseId/assets/template.svg +6 -0
- package/src/modules/databaseId/assets/upload.svg +9 -0
- package/src/modules/databaseId/assets/useTemp.svg +6 -0
- package/src/modules/databaseId/index.tsx +734 -0
- package/src/modules/databaseId/server.ts +286 -0
- package/src/modules/databaseId/style.css +5 -0
- package/src/modules/databaseTable/EditRowDrawer.tsx +119 -0
- package/src/modules/databaseTable/index.tsx +357 -0
- package/src/modules/databaseTable/server.ts +180 -0
- package/src/modules/headlessChat/constants.tsx +32 -0
- package/src/modules/headlessChat/index.tsx +1065 -0
- package/src/modules/headlessChat/types.ts +23 -0
- package/src/modules/login/components/Login/LoginBox/index.tsx +102 -0
- package/src/modules/login/components/Login/RegisterBox/index.tsx +180 -0
- package/src/modules/login/components/Login/index.tsx +100 -0
- package/src/modules/login/index.tsx +106 -0
- package/src/modules/login/style.css +3 -0
- package/src/modules/login/useServices.ts +53 -0
- package/src/modules/login/utils.ts +42 -0
- package/src/modules/modelManage/ConfigDrawer.tsx +249 -0
- package/src/modules/modelManage/assets/empty.png +0 -0
- package/src/modules/modelManage/const.ts +50 -0
- package/src/modules/modelManage/index.tsx +439 -0
- package/src/modules/modelManage/server.ts +185 -0
- package/src/modules/nodegraph/index.tsx +1 -0
- package/src/modules/search/assets/Icon-history.svg +8 -0
- package/src/modules/search/assets/answerAwartar.png +0 -0
- package/src/modules/search/assets/doc.png +0 -0
- package/src/modules/search/assets/genera.gif +0 -0
- package/src/modules/search/assets/icon-robot.svg +9 -0
- package/src/modules/search/assets/icon-search-bar.svg +14 -0
- package/src/modules/search/assets/icon-sub-title.svg +3 -0
- package/src/modules/search/assets/icon-title.svg +9 -0
- package/src/modules/search/assets/icon-zoomOut.svg +9 -0
- package/src/modules/search/assets/iconAi.svg +9 -0
- package/src/modules/search/assets/pdf.png +0 -0
- package/src/modules/search/assets/ppt.png +0 -0
- package/src/modules/search/assets/search.svg +3 -0
- package/src/modules/search/assets/selected.svg +4 -0
- package/src/modules/search/assets/txt.png +0 -0
- package/src/modules/search/assets/xls.png +0 -0
- package/src/modules/search/components/AssisSelect.tsx +137 -0
- package/src/modules/search/components/Editor/ChatViewEditor.tsx +261 -0
- package/src/modules/search/components/Editor/aichat.css +1 -0
- package/src/modules/search/components/Editor/constant.ts +13 -0
- package/src/modules/search/components/Editor/index.tsx +113 -0
- package/src/modules/search/components/Editor/plugins/autofomatRules.ts +332 -0
- package/src/modules/search/components/Editor/plugins/convertImgPlugins.tsx +20 -0
- package/src/modules/search/components/Editor/plugins/createIndexes.tsx +38 -0
- package/src/modules/search/components/Editor/plugins/displayer.ts +298 -0
- package/src/modules/search/components/Editor/plugins/imageClick.tsx +32 -0
- package/src/modules/search/components/Editor/plugins/myplugin.tsx +98 -0
- package/src/modules/search/components/Editor/ui/avatar.tsx +19 -0
- package/src/modules/search/components/Editor/ui/blockquote-element.tsx +21 -0
- package/src/modules/search/components/Editor/ui/button.tsx +58 -0
- package/src/modules/search/components/Editor/ui/calendar.tsx +68 -0
- package/src/modules/search/components/Editor/ui/caption.tsx +46 -0
- package/src/modules/search/components/Editor/ui/checkbox.tsx +27 -0
- package/src/modules/search/components/Editor/ui/code-block-combobox.tsx +188 -0
- package/src/modules/search/components/Editor/ui/code-block-element.css +434 -0
- package/src/modules/search/components/Editor/ui/code-block-element.tsx +39 -0
- package/src/modules/search/components/Editor/ui/code-leaf.tsx +24 -0
- package/src/modules/search/components/Editor/ui/code-line-element.tsx +10 -0
- package/src/modules/search/components/Editor/ui/code-syntax-leaf.tsx +21 -0
- package/src/modules/search/components/Editor/ui/column-element.tsx +30 -0
- package/src/modules/search/components/Editor/ui/column-group-element.tsx +94 -0
- package/src/modules/search/components/Editor/ui/command.tsx +75 -0
- package/src/modules/search/components/Editor/ui/comment-avatar.tsx +22 -0
- package/src/modules/search/components/Editor/ui/comment-create-form.tsx +37 -0
- package/src/modules/search/components/Editor/ui/comment-item.tsx +74 -0
- package/src/modules/search/components/Editor/ui/comment-leaf.tsx +49 -0
- package/src/modules/search/components/Editor/ui/comment-more-dropdown.tsx +42 -0
- package/src/modules/search/components/Editor/ui/comment-reply-items.tsx +22 -0
- package/src/modules/search/components/Editor/ui/comment-resolve-button.tsx +32 -0
- package/src/modules/search/components/Editor/ui/comment-value.tsx +34 -0
- package/src/modules/search/components/Editor/ui/comments-popover.tsx +63 -0
- package/src/modules/search/components/Editor/ui/date-element.tsx +83 -0
- package/src/modules/search/components/Editor/ui/dialog.tsx +63 -0
- package/src/modules/search/components/Editor/ui/draggable.tsx +177 -0
- package/src/modules/search/components/Editor/ui/dropdown-menu.tsx +180 -0
- package/src/modules/search/components/Editor/ui/emoji-input-element.tsx +85 -0
- package/src/modules/search/components/Editor/ui/excalidraw-element.tsx +28 -0
- package/src/modules/search/components/Editor/ui/fixed-toolbar-buttons.tsx +76 -0
- package/src/modules/search/components/Editor/ui/fixed-toolbar.tsx +8 -0
- package/src/modules/search/components/Editor/ui/floating-toolbar-buttons.tsx +51 -0
- package/src/modules/search/components/Editor/ui/floating-toolbar.tsx +77 -0
- package/src/modules/search/components/Editor/ui/heading-element.tsx +48 -0
- package/src/modules/search/components/Editor/ui/highlight-leaf.tsx +17 -0
- package/src/modules/search/components/Editor/ui/hr-element.tsx +30 -0
- package/src/modules/search/components/Editor/ui/icons.tsx +267 -0
- package/src/modules/search/components/Editor/ui/image-element.tsx +74 -0
- package/src/modules/search/components/Editor/ui/inline-combobox.tsx +368 -0
- package/src/modules/search/components/Editor/ui/input.tsx +25 -0
- package/src/modules/search/components/Editor/ui/insert-dropdown-menu.tsx +218 -0
- package/src/modules/search/components/Editor/ui/kbd-leaf.tsx +20 -0
- package/src/modules/search/components/Editor/ui/link-element.tsx +29 -0
- package/src/modules/search/components/Editor/ui/link-floating-toolbar.tsx +161 -0
- package/src/modules/search/components/Editor/ui/list-element.tsx +30 -0
- package/src/modules/search/components/Editor/ui/mark-toolbar-button.tsx +24 -0
- package/src/modules/search/components/Editor/ui/media-embed-element.tsx +133 -0
- package/src/modules/search/components/Editor/ui/media-popover.tsx +97 -0
- package/src/modules/search/components/Editor/ui/mention-element.tsx +43 -0
- package/src/modules/search/components/Editor/ui/mention-input-element.tsx +141 -0
- package/src/modules/search/components/Editor/ui/mode-dropdown-menu.tsx +93 -0
- package/src/modules/search/components/Editor/ui/more-dropdown-menu.tsx +67 -0
- package/src/modules/search/components/Editor/ui/paragraph-element.tsx +4 -0
- package/src/modules/search/components/Editor/ui/placeholder.tsx +52 -0
- package/src/modules/search/components/Editor/ui/popover.tsx +32 -0
- package/src/modules/search/components/Editor/ui/resizable.tsx +66 -0
- package/src/modules/search/components/Editor/ui/separator.tsx +25 -0
- package/src/modules/search/components/Editor/ui/style.less +12 -0
- package/src/modules/search/components/Editor/ui/table-cell-element.tsx +143 -0
- package/src/modules/search/components/Editor/ui/table-element.tsx +243 -0
- package/src/modules/search/components/Editor/ui/table-row-element.tsx +22 -0
- package/src/modules/search/components/Editor/ui/tableValue.tsx +135 -0
- package/src/modules/search/components/Editor/ui/todo-list-element.tsx +43 -0
- package/src/modules/search/components/Editor/ui/toggle-element.tsx +31 -0
- package/src/modules/search/components/Editor/ui/toolbar.tsx +157 -0
- package/src/modules/search/components/Editor/ui/tooltip.tsx +65 -0
- package/src/modules/search/components/Editor/ui/turn-into-dropdown-menu.tsx +160 -0
- package/src/modules/search/components/Editor/ui/with-draggables.tsx +175 -0
- package/src/modules/search/components/FileList.tsx +287 -0
- package/src/modules/search/components/ImageGroupView/index.tsx +85 -0
- package/src/modules/search/components/ResultContent.tsx +232 -0
- package/src/modules/search/components/SearchInput.tsx +232 -0
- package/src/modules/search/components/SearchLanding.tsx +74 -0
- package/src/modules/search/components/SearchView.tsx +563 -0
- package/src/modules/search/components/SimpleEditor.tsx +158 -0
- package/src/modules/search/components/SimpleFileList.tsx +215 -0
- package/src/modules/search/index.tsx +10 -0
- package/src/modules/search/reademe.md +1 -0
- package/src/modules/search/servers/apis.tsx +19 -0
- package/src/modules/search/servers/index.ts +184 -0
- package/src/modules/search/style.less +503 -0
- package/src/modules/search/type.ts +22 -0
- package/src/modules/search/utils.ts +34 -0
- package/src/modules/sensitive/index.tsx +313 -0
- package/src/modules/sensitive/server.ts +122 -0
- package/src/modules/streamFilesReader/GientechStreamReader.tsx +1555 -0
- package/src/modules/streamFilesReader/components/Header/Toolbar.tsx +0 -0
- package/src/modules/streamFilesReader/components/Header/index.tsx +297 -0
- package/src/modules/streamFilesReader/index.tsx +3 -0
- package/src/style.css +6 -0
- package/src/type.d.ts +0 -0
- package/src/utils/commonFn.tsx +111 -0
- package/src/utils/gientechCommon/components/AppError.tsx +32 -0
- package/src/utils/gientechCommon/components/AppLoading.tsx +75 -0
- package/src/utils/gientechCommon/components/DeleteModal.tsx +75 -0
- package/src/utils/gientechCommon/components/DisplayError.tsx +33 -0
- package/src/utils/gientechCommon/components/DisplayLoading.tsx +38 -0
- package/src/utils/gientechCommon/components/FeedBackModal.tsx +310 -0
- package/src/utils/gientechCommon/components/FileCardCommon.tsx +82 -0
- package/src/utils/gientechCommon/components/FileManager/index.tsx +390 -0
- package/src/utils/gientechCommon/components/FileManager/style.css +5 -0
- package/src/utils/gientechCommon/components/Messages/GientechNewChatWelcome.tsx +296 -0
- package/src/utils/gientechCommon/components/Messages/ReferenceCard.tsx +339 -0
- package/src/utils/gientechCommon/components/Messages/RetriveItem.tsx +245 -0
- package/src/utils/gientechCommon/components/Messages/WebRetriveItem.tsx +209 -0
- package/src/utils/gientechCommon/components/Messages/defaultBot.png +0 -0
- package/src/utils/gientechCommon/components/Messages/defaultStyleSet.tsx +148 -0
- package/src/utils/gientechCommon/components/Messages/defaultWeLogo.svg +14 -0
- package/src/utils/gientechCommon/components/RenameModal.tsx +86 -0
- package/src/utils/gientechCommon/components/style.less +11 -0
- package/src/utils/gientechCommon/configs/commonConfig.ts +2 -0
- package/src/utils/gientechCommon/configs/senderConfig.ts +0 -0
- package/src/utils/gientechCommon/configs/stylesConfig.ts +142 -0
- package/src/utils/gientechCommon/hooks/AichatUseController.tsx +345 -0
- package/src/utils/gientechCommon/slate/converters/deserializers.ts +763 -0
- package/src/utils/gientechCommon/slate/converters/mockData.ts +232 -0
- package/src/utils/gientechCommon/slate/converters/slateConverters.ts +258 -0
- package/src/utils/gientechCommon/slate/richElements/index.tsx +499 -0
- package/src/utils/gientechCommon/utils/request.ts +37 -0
- package/src/utils/gientechCommon/utils/serverFn.ts +172 -0
- package/src/utils/index.tsx +126 -0
- package/src/utils/testconfigs/demologin/index.tsx +32 -0
- package/src/utils/testconfigs/index.ts +53 -0
- package/src/vite-env.d.ts +11 -0
- package/stats.html +4949 -0
- package/tailwind.config.js +170 -0
- package/tsconfig.app.json +30 -0
- package/tsconfig.app.tsbuildinfo +11 -0
- package/tsconfig.json +13 -0
- package/tsconfig.node.json +22 -0
- package/tsconfig.node.tsbuildinfo +1 -0
- package/vite.config.ts +177 -0
- package/workflows/release.yml +60 -0
- package/assets/style.css +0 -1
- package/assets/style3.css +0 -1
- package/database.js +0 -20
- /package/{assets → dist/assets}/Doris.png +0 -0
- /package/{assets → dist/assets}/PostgreSQL.png +0 -0
- /package/{assets → dist/assets}/SQLServer.png +0 -0
- /package/{assets → dist/assets}/_commonjsHelpers-gnU0ypJ3.js +0 -0
- /package/{assets → dist/assets}/circle-alert-g2Y6zAjt.js +0 -0
- /package/{assets → dist/assets}/empty.png +0 -0
- /package/{assets → dist/assets}/index-CEK88UzR.js +0 -0
- /package/{assets → dist/assets}/index-CpW6Dhpp.js +0 -0
- /package/{assets → dist/assets}/plus-omCUN0e3.js +0 -0
- /package/{assets → dist/assets}/style2.css +0 -0
- /package/{assets → dist/assets}/styled-components.browser.esm-DPkS13KC.js +0 -0
- /package/{assets → dist/assets}/x-vPcWt3fC.js +0 -0
- /package/{chat.d.ts → dist/chat.d.ts} +0 -0
- /package/{database.d.ts → dist/database.d.ts} +0 -0
- /package/{databaseId.d.ts → dist/databaseId.d.ts} +0 -0
- /package/{databaseTable.d.ts → dist/databaseTable.d.ts} +0 -0
- /package/{modelManage.d.ts → dist/modelManage.d.ts} +0 -0
- /package/{sensitive.d.ts → dist/sensitive.d.ts} +0 -0
- /package/{streamFilesReader.d.ts → dist/streamFilesReader.d.ts} +0 -0
- /package/{vite.svg → dist/vite.svg} +0 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface UploadedFile {
|
|
2
|
+
name: string;
|
|
3
|
+
size: number;
|
|
4
|
+
type: string;
|
|
5
|
+
filePath: string;
|
|
6
|
+
convertedFilePath?: string;
|
|
7
|
+
uid: string;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface EmptyMessageData {
|
|
11
|
+
content: string;
|
|
12
|
+
filePaths?: string;
|
|
13
|
+
queryId: string;
|
|
14
|
+
currentFiles?: UploadedFile[];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface GientechChatAdopterProps {
|
|
18
|
+
token: string;
|
|
19
|
+
url?: string;
|
|
20
|
+
styles?: any;
|
|
21
|
+
eventsEmit?: (eventName: string, data: any) => void;
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { Loader2, ShoppingCart, User } from 'lucide-react';
|
|
2
|
+
import { Button, Flex, Form, FormInstance, Input, Typography } from 'antd';
|
|
3
|
+
import React, { useState } from 'react';
|
|
4
|
+
export enum LoginFormActionEnum {
|
|
5
|
+
CANCEL = 'cancel',
|
|
6
|
+
SUBMIT = 'submit',
|
|
7
|
+
REFRESH = 'refresh',
|
|
8
|
+
REGISTER = 'register',
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface Iprops {
|
|
12
|
+
setIsRegister: React.Dispatch<React.SetStateAction<boolean>>;
|
|
13
|
+
logoImg?: string;
|
|
14
|
+
eventEmit?: (n: string, d: any) => void;
|
|
15
|
+
form: FormInstance<any>;
|
|
16
|
+
codeImgSrc?: string;
|
|
17
|
+
loginLoading?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const LoginBox: React.FC<Iprops> = props => {
|
|
21
|
+
const { logoImg, setIsRegister, eventEmit, form, codeImgSrc, loginLoading = false } = props;
|
|
22
|
+
const [codeLoading, setCodeLoading] = useState<boolean>(false);
|
|
23
|
+
const handleLogin = () => {
|
|
24
|
+
form.validateFields().then(async res => {
|
|
25
|
+
eventEmit && (await eventEmit('login:login', res));
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const handleClickCode = async () => {
|
|
30
|
+
setCodeLoading(true);
|
|
31
|
+
eventEmit && (await eventEmit('login:codeClick', ''));
|
|
32
|
+
setCodeLoading(false);
|
|
33
|
+
};
|
|
34
|
+
return (
|
|
35
|
+
<Flex vertical justify="center">
|
|
36
|
+
<img
|
|
37
|
+
style={{
|
|
38
|
+
display: 'inline-block',
|
|
39
|
+
width: '100%',
|
|
40
|
+
objectFit: 'cover',
|
|
41
|
+
marginTop: '12px',
|
|
42
|
+
marginBottom: '20px',
|
|
43
|
+
textAlign: 'center',
|
|
44
|
+
}}
|
|
45
|
+
src={logoImg}
|
|
46
|
+
/>
|
|
47
|
+
<Form.Item name={'userName'} rules={[{ required: true, message: '请输入用户名字' }]}>
|
|
48
|
+
<Input placeholder="输入用户名字" prefix={<User size={16} />} />
|
|
49
|
+
</Form.Item>
|
|
50
|
+
<Form.Item name={'password'} rules={[{ required: true, message: '请输入密码' }]}>
|
|
51
|
+
<Input placeholder="输入密码" prefix={<ShoppingCart size={16} />} type="password" />
|
|
52
|
+
</Form.Item>
|
|
53
|
+
{codeImgSrc && (
|
|
54
|
+
<Form.Item name={'verifyCode'} rules={[{ required: true, message: '请输入验证码' }]}>
|
|
55
|
+
<Flex>
|
|
56
|
+
<Input placeholder="输入验证码" />
|
|
57
|
+
|
|
58
|
+
{codeLoading ? (
|
|
59
|
+
<Flex style={{ width: '96px', height: '40px' }} justify="center">
|
|
60
|
+
<Loader2 className="animate-spin" size={20} />
|
|
61
|
+
</Flex>
|
|
62
|
+
) : (
|
|
63
|
+
<img
|
|
64
|
+
onClick={handleClickCode}
|
|
65
|
+
src={codeImgSrc}
|
|
66
|
+
style={{
|
|
67
|
+
width: '96px',
|
|
68
|
+
height: '40px',
|
|
69
|
+
background: 'white',
|
|
70
|
+
border: 'solid 1px #d9d9d9',
|
|
71
|
+
cursor: 'pointer',
|
|
72
|
+
borderRadius: '6px',
|
|
73
|
+
}}
|
|
74
|
+
/>
|
|
75
|
+
)}
|
|
76
|
+
</Flex>
|
|
77
|
+
</Form.Item>
|
|
78
|
+
)}
|
|
79
|
+
<Form.Item>
|
|
80
|
+
<Button
|
|
81
|
+
style={{ width: '100%' }}
|
|
82
|
+
type="primary"
|
|
83
|
+
loading={loginLoading}
|
|
84
|
+
onClick={handleLogin}
|
|
85
|
+
>
|
|
86
|
+
登录
|
|
87
|
+
</Button>
|
|
88
|
+
</Form.Item>
|
|
89
|
+
{/* <Text
|
|
90
|
+
style={{
|
|
91
|
+
textAlign: "right",
|
|
92
|
+
cursor: "pointer"
|
|
93
|
+
}}
|
|
94
|
+
onClick={() => setIsRegister(true)}
|
|
95
|
+
>
|
|
96
|
+
点击注册
|
|
97
|
+
</Text> */}
|
|
98
|
+
</Flex>
|
|
99
|
+
);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
export default LoginBox;
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import { Button, Flex, Form, FormInstance, Input, Typography } from "antd";
|
|
2
|
+
import { LoadingOutlined } from "@ant-design/icons";
|
|
3
|
+
import React, { useState } from "react";
|
|
4
|
+
|
|
5
|
+
export enum RegisterFormActionEnum {
|
|
6
|
+
CANCEL = "cancel",
|
|
7
|
+
SUBMIT = "submit"
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
//不能用数字开头,长度不超过25,无特殊符号,无空格
|
|
11
|
+
const REG_NAME = /^[\u4e00-\u9fa5A-Za-z_][\u4e00-\u9fa5A-Za-z0-9_]{0,24}$/;
|
|
12
|
+
const REG_NAME_MSG = "不能用数字开头,长度不超过25,无特殊符号,无空格";
|
|
13
|
+
|
|
14
|
+
const REG_PHONE =
|
|
15
|
+
/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(16[0-9]{1})|(17[0-9]{1})|(19[0-9]{1}))+\d{8})$/;
|
|
16
|
+
const REF_PHONE_MSG = "手机号格式不正确";
|
|
17
|
+
|
|
18
|
+
const REG_EMAIL = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
|
|
19
|
+
const REF_EMAIL_MSG = "邮箱格式不正确";
|
|
20
|
+
|
|
21
|
+
const REG_PASSWORD = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)[A-Za-z\d]{8,}$/;
|
|
22
|
+
const REF_PASSWORD_MSG =
|
|
23
|
+
"密码必须包含大小写字母和数字,不包含特殊字符,长度至少是8";
|
|
24
|
+
|
|
25
|
+
interface Iprops {
|
|
26
|
+
eventEmit?: (name: string, data: any) => void;
|
|
27
|
+
setIsRegister: React.Dispatch<React.SetStateAction<boolean>>;
|
|
28
|
+
form: FormInstance<any>;
|
|
29
|
+
registerLoading?: boolean;
|
|
30
|
+
registreKaptchaUrl?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const RegisterBox: React.FC<Iprops> = (props) => {
|
|
34
|
+
const {
|
|
35
|
+
eventEmit,
|
|
36
|
+
setIsRegister,
|
|
37
|
+
form,
|
|
38
|
+
registreKaptchaUrl,
|
|
39
|
+
registerLoading = false
|
|
40
|
+
} = props;
|
|
41
|
+
|
|
42
|
+
const [codeLoading, setCodeLoading] = useState<boolean>(false);
|
|
43
|
+
|
|
44
|
+
const handleRegister = async () => {
|
|
45
|
+
form.validateFields().then(async (res) => {
|
|
46
|
+
eventEmit && (await eventEmit("login:register", res));
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const handleClickCode = async () => {
|
|
51
|
+
setCodeLoading(true);
|
|
52
|
+
eventEmit && (await eventEmit("login:registerCodeClick", ""));
|
|
53
|
+
setCodeLoading(false);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Flex style={{ paddingTop: "35px" }} vertical>
|
|
58
|
+
<Form.Item
|
|
59
|
+
label="用户名"
|
|
60
|
+
name={"userName"}
|
|
61
|
+
rules={[
|
|
62
|
+
{ required: true, message: "请输入名称" },
|
|
63
|
+
{
|
|
64
|
+
pattern: new RegExp(REG_NAME),
|
|
65
|
+
message: `名称${REG_NAME_MSG}`
|
|
66
|
+
}
|
|
67
|
+
]}
|
|
68
|
+
>
|
|
69
|
+
<Input placeholder="输入用户名字" />
|
|
70
|
+
</Form.Item>
|
|
71
|
+
<Form.Item
|
|
72
|
+
label="手机号"
|
|
73
|
+
name={"userIphone"}
|
|
74
|
+
rules={[
|
|
75
|
+
{ required: true, message: "请输入手机号" },
|
|
76
|
+
{
|
|
77
|
+
pattern: new RegExp(REG_PHONE),
|
|
78
|
+
message: `${REF_PHONE_MSG}`
|
|
79
|
+
}
|
|
80
|
+
]}
|
|
81
|
+
>
|
|
82
|
+
<Input placeholder="请输入手机号" />
|
|
83
|
+
</Form.Item>
|
|
84
|
+
<Form.Item
|
|
85
|
+
label="邮箱"
|
|
86
|
+
name={"userEmail"}
|
|
87
|
+
rules={[
|
|
88
|
+
{ required: true, message: "请输入邮箱" },
|
|
89
|
+
{
|
|
90
|
+
pattern: new RegExp(REG_EMAIL),
|
|
91
|
+
message: `${REF_EMAIL_MSG}`
|
|
92
|
+
}
|
|
93
|
+
]}
|
|
94
|
+
>
|
|
95
|
+
<Input placeholder="输入邮箱" />
|
|
96
|
+
</Form.Item>
|
|
97
|
+
<Form.Item
|
|
98
|
+
label="密码"
|
|
99
|
+
name={"password"}
|
|
100
|
+
rules={[
|
|
101
|
+
{ required: true, message: "请输入密码" },
|
|
102
|
+
{
|
|
103
|
+
pattern: new RegExp(REG_PASSWORD),
|
|
104
|
+
message: `${REF_PASSWORD_MSG}`
|
|
105
|
+
}
|
|
106
|
+
]}
|
|
107
|
+
>
|
|
108
|
+
<Input placeholder="请输入密码" type="password" />
|
|
109
|
+
</Form.Item>
|
|
110
|
+
<Form.Item
|
|
111
|
+
label="确认密码"
|
|
112
|
+
name={"passwordAffirm"}
|
|
113
|
+
dependencies={["password"]}
|
|
114
|
+
rules={[
|
|
115
|
+
{
|
|
116
|
+
required: true,
|
|
117
|
+
message: "请确认新密码"
|
|
118
|
+
},
|
|
119
|
+
({ getFieldValue }) => ({
|
|
120
|
+
validator(_, value) {
|
|
121
|
+
if (!value || getFieldValue("password") === value) {
|
|
122
|
+
return Promise.resolve();
|
|
123
|
+
}
|
|
124
|
+
return Promise.reject(new Error("两次密码不一致!"));
|
|
125
|
+
}
|
|
126
|
+
})
|
|
127
|
+
]}
|
|
128
|
+
>
|
|
129
|
+
<Input placeholder="请确认新密码" type="password" />
|
|
130
|
+
</Form.Item>
|
|
131
|
+
{registreKaptchaUrl && (
|
|
132
|
+
<Form.Item
|
|
133
|
+
label="验证码"
|
|
134
|
+
name={"verifyCode"}
|
|
135
|
+
rules={[{ required: true, message: "请输入验证码" }]}
|
|
136
|
+
>
|
|
137
|
+
<Flex>
|
|
138
|
+
<Input placeholder="输入验证码" />
|
|
139
|
+
|
|
140
|
+
{codeLoading ? (
|
|
141
|
+
<Flex style={{ width: "96px", height: "40px" }} justify="center">
|
|
142
|
+
<LoadingOutlined />
|
|
143
|
+
</Flex>
|
|
144
|
+
) : (
|
|
145
|
+
<img
|
|
146
|
+
onClick={handleClickCode}
|
|
147
|
+
src={registreKaptchaUrl}
|
|
148
|
+
style={{
|
|
149
|
+
width: "96px",
|
|
150
|
+
height: "40px",
|
|
151
|
+
background: "white",
|
|
152
|
+
border: "solid 1px #d9d9d9",
|
|
153
|
+
cursor: "pointer",
|
|
154
|
+
borderRadius: "6px"
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
)}
|
|
158
|
+
</Flex>
|
|
159
|
+
</Form.Item>
|
|
160
|
+
)}
|
|
161
|
+
<Form.Item>
|
|
162
|
+
<Flex justify="space-between">
|
|
163
|
+
<Button style={{ width: "48%" }} onClick={() => setIsRegister(false)}>
|
|
164
|
+
取消
|
|
165
|
+
</Button>
|
|
166
|
+
<Button
|
|
167
|
+
style={{ width: "48%" }}
|
|
168
|
+
onClick={handleRegister}
|
|
169
|
+
type="primary"
|
|
170
|
+
loading={registerLoading}
|
|
171
|
+
>
|
|
172
|
+
注册
|
|
173
|
+
</Button>
|
|
174
|
+
</Flex>
|
|
175
|
+
</Form.Item>
|
|
176
|
+
</Flex>
|
|
177
|
+
);
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export default RegisterBox;
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { ConfigProvider, Flex, Form } from 'antd';
|
|
2
|
+
import { useState } from 'react';
|
|
3
|
+
import LoginBox from './LoginBox';
|
|
4
|
+
|
|
5
|
+
const defaultStyle = {
|
|
6
|
+
colorPrimary: '#1677ff',
|
|
7
|
+
defaultBg: '#ffffff',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
interface LoginStyle {
|
|
11
|
+
defaultBg?: string;
|
|
12
|
+
colorPrimary?: string;
|
|
13
|
+
}
|
|
14
|
+
interface LoginProps {
|
|
15
|
+
homeBg?: string;
|
|
16
|
+
leftImg?: string;
|
|
17
|
+
logoImg?: string;
|
|
18
|
+
eventEmit?: (n: string, d: any) => void;
|
|
19
|
+
loginLoading?: boolean;
|
|
20
|
+
registerLoading?: boolean;
|
|
21
|
+
codeImgSrc?: string;
|
|
22
|
+
loginStyle?: LoginStyle;
|
|
23
|
+
registreKaptchaUrl?: string;
|
|
24
|
+
}
|
|
25
|
+
const Login = (props: LoginProps) => {
|
|
26
|
+
const {
|
|
27
|
+
homeBg,
|
|
28
|
+
leftImg,
|
|
29
|
+
logoImg,
|
|
30
|
+
eventEmit,
|
|
31
|
+
codeImgSrc = '',
|
|
32
|
+
loginStyle,
|
|
33
|
+
loginLoading,
|
|
34
|
+
registerLoading,
|
|
35
|
+
registreKaptchaUrl,
|
|
36
|
+
} = props;
|
|
37
|
+
const [isRegister, setIsRegister] = useState<boolean>(false);
|
|
38
|
+
const [form] = Form.useForm();
|
|
39
|
+
|
|
40
|
+
return (
|
|
41
|
+
<ConfigProvider
|
|
42
|
+
theme={{
|
|
43
|
+
token: {
|
|
44
|
+
colorPrimary: loginStyle?.colorPrimary || defaultStyle.colorPrimary,
|
|
45
|
+
},
|
|
46
|
+
components: {
|
|
47
|
+
Button: {
|
|
48
|
+
defaultBg: loginStyle?.defaultBg || defaultStyle.defaultBg,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
<Flex
|
|
54
|
+
style={{
|
|
55
|
+
width: '100%',
|
|
56
|
+
height: '100%',
|
|
57
|
+
background: `url('${homeBg}') no-repeat center/cover`,
|
|
58
|
+
}}
|
|
59
|
+
justify="center"
|
|
60
|
+
align="center"
|
|
61
|
+
>
|
|
62
|
+
<Flex
|
|
63
|
+
style={{
|
|
64
|
+
background: 'white',
|
|
65
|
+
height: '55vh',
|
|
66
|
+
minHeight: '393px',
|
|
67
|
+
width: 'calc(55vh * 2)',
|
|
68
|
+
minWidth: '840px',
|
|
69
|
+
borderRadius: '10px',
|
|
70
|
+
overflow: 'hidden',
|
|
71
|
+
}}
|
|
72
|
+
>
|
|
73
|
+
{leftImg && (
|
|
74
|
+
<img
|
|
75
|
+
style={{
|
|
76
|
+
objectFit: 'cover',
|
|
77
|
+
width: '50%',
|
|
78
|
+
}}
|
|
79
|
+
src={leftImg}
|
|
80
|
+
/>
|
|
81
|
+
)}
|
|
82
|
+
<Flex flex={1} style={{ padding: '0 50px' }} justify="center" align="center">
|
|
83
|
+
<Form form={form} labelCol={{ span: 8 }}>
|
|
84
|
+
<LoginBox
|
|
85
|
+
loginLoading={loginLoading}
|
|
86
|
+
form={form}
|
|
87
|
+
logoImg={logoImg}
|
|
88
|
+
setIsRegister={setIsRegister}
|
|
89
|
+
codeImgSrc={codeImgSrc}
|
|
90
|
+
eventEmit={eventEmit}
|
|
91
|
+
/>
|
|
92
|
+
</Form>
|
|
93
|
+
</Flex>
|
|
94
|
+
</Flex>
|
|
95
|
+
</Flex>
|
|
96
|
+
</ConfigProvider>
|
|
97
|
+
);
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export default Login;
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import homeBg from '@/assets/login/homeBg.png';
|
|
2
|
+
import leftImg from '@/assets/login/left.jpg';
|
|
3
|
+
import logoImg from '@/assets/login/logoImg.png';
|
|
4
|
+
import { Layout, message } from 'antd';
|
|
5
|
+
import { Encrypt } from './utils';
|
|
6
|
+
import { useEffect, useState } from 'react';
|
|
7
|
+
import Login from './components/Login';
|
|
8
|
+
import { api_getKaptchaImage, login } from './useServices';
|
|
9
|
+
import './style.css'
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const baseUrl = '/proxy';
|
|
13
|
+
interface LoginMainProps {
|
|
14
|
+
eventsEmit: (eventName: string, data: any) => void;
|
|
15
|
+
}
|
|
16
|
+
function LoginMain({ eventsEmit }: LoginMainProps) {
|
|
17
|
+
const [loginLoading, setLoginLoading] = useState(false);
|
|
18
|
+
const [registerLoading, setRegisterLoading] = useState(false);
|
|
19
|
+
const handleLogin = async (data: any) => {
|
|
20
|
+
try {
|
|
21
|
+
setLoginLoading(true);
|
|
22
|
+
login(
|
|
23
|
+
{ url: baseUrl },
|
|
24
|
+
{
|
|
25
|
+
...data,
|
|
26
|
+
password: Encrypt(data.password),
|
|
27
|
+
},
|
|
28
|
+
res => {
|
|
29
|
+
if (res?.success) {
|
|
30
|
+
eventsEmit('afterLogin',res?.data?.token || '');
|
|
31
|
+
}
|
|
32
|
+
setLoginLoading(false);
|
|
33
|
+
},
|
|
34
|
+
msg => {
|
|
35
|
+
setLoginLoading(false);
|
|
36
|
+
if (msg) {
|
|
37
|
+
message.error(msg);
|
|
38
|
+
} else {
|
|
39
|
+
message.error('登录失败,请稍后再试');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
} catch (e) {
|
|
44
|
+
setLoginLoading(false);
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const [kaptchaUrl, setKaptchaUrl] = useState('');
|
|
49
|
+
const [registreKaptchaUrl, setRegistreKaptchaUrl] = useState('');
|
|
50
|
+
|
|
51
|
+
const handleGetImage = () => {
|
|
52
|
+
try {
|
|
53
|
+
setRegisterLoading(true);
|
|
54
|
+
api_getKaptchaImage({ url: baseUrl }, data => {
|
|
55
|
+
setRegisterLoading(false);
|
|
56
|
+
if (data) {
|
|
57
|
+
const imgBlob = new Blob([data], { type: 'image/jpeg' });
|
|
58
|
+
const imageUrl = window.URL.createObjectURL(imgBlob);
|
|
59
|
+
setKaptchaUrl(imageUrl);
|
|
60
|
+
setRegistreKaptchaUrl(imageUrl);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
} catch (error) {
|
|
64
|
+
setRegisterLoading(false);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
handleGetImage();
|
|
70
|
+
return () => {
|
|
71
|
+
window.URL.revokeObjectURL(kaptchaUrl);
|
|
72
|
+
};
|
|
73
|
+
}, []);
|
|
74
|
+
|
|
75
|
+
const eventEmit = async (name: string, data: any) => {
|
|
76
|
+
switch (name) {
|
|
77
|
+
case 'login:login':
|
|
78
|
+
await handleLogin(data);
|
|
79
|
+
break;
|
|
80
|
+
case 'login:codeClick':
|
|
81
|
+
handleGetImage();
|
|
82
|
+
break;
|
|
83
|
+
case 'login:registerCodeClick':
|
|
84
|
+
handleGetImage();
|
|
85
|
+
break;
|
|
86
|
+
default:
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
return (
|
|
91
|
+
<Layout style={{ height: '100vh', overflow: 'hidden' }}>
|
|
92
|
+
<Login
|
|
93
|
+
loginLoading={loginLoading}
|
|
94
|
+
registerLoading={registerLoading}
|
|
95
|
+
homeBg={homeBg}
|
|
96
|
+
leftImg={leftImg}
|
|
97
|
+
logoImg={logoImg}
|
|
98
|
+
codeImgSrc={kaptchaUrl}
|
|
99
|
+
registreKaptchaUrl={registreKaptchaUrl}
|
|
100
|
+
eventEmit={eventEmit}
|
|
101
|
+
/>
|
|
102
|
+
</Layout>
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export default LoginMain;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import axios from 'axios';
|
|
2
|
+
|
|
3
|
+
export const login = async (
|
|
4
|
+
config: { url: string },
|
|
5
|
+
data: { restult: number; queryId: string },
|
|
6
|
+
sucCb: (arg: any) => void,
|
|
7
|
+
failCb: (arg: any) => void = () => {}
|
|
8
|
+
) => {
|
|
9
|
+
try {
|
|
10
|
+
axios
|
|
11
|
+
.post(`${config.url}/auth/user/login`, data)
|
|
12
|
+
.then(res => {
|
|
13
|
+
if (res.data.success) {
|
|
14
|
+
sucCb && sucCb(res.data);
|
|
15
|
+
} else {
|
|
16
|
+
failCb && failCb(false);
|
|
17
|
+
}
|
|
18
|
+
})
|
|
19
|
+
.catch(error => {
|
|
20
|
+
failCb && failCb(error?.response?.data?.errorMsg);
|
|
21
|
+
console.error('Login error:', error);
|
|
22
|
+
});
|
|
23
|
+
} catch (error) {
|
|
24
|
+
failCb && failCb(false);
|
|
25
|
+
console.log('error', error);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export const api_getKaptchaImage = (config: { url: string }, cb: (arg: any) => void) => {
|
|
30
|
+
try {
|
|
31
|
+
axios
|
|
32
|
+
.get(`/user/kaptcha`, {
|
|
33
|
+
baseURL: '/proxy/auth',
|
|
34
|
+
responseType: 'arraybuffer', // 关键:必须添加
|
|
35
|
+
//params: { t: Date.now() },
|
|
36
|
+
headers: { Accept: '*/*', 'Content-Type': 'application/json' },
|
|
37
|
+
})
|
|
38
|
+
.then(res => {
|
|
39
|
+
if (res.data) {
|
|
40
|
+
cb && cb(res.data);
|
|
41
|
+
} else {
|
|
42
|
+
cb && cb(false);
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
.catch(error => {
|
|
46
|
+
cb && cb(false);
|
|
47
|
+
console.error('Login error:', error);
|
|
48
|
+
});
|
|
49
|
+
} catch (error) {
|
|
50
|
+
cb && cb(false);
|
|
51
|
+
console.log('error', error);
|
|
52
|
+
}
|
|
53
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import CryptoJS from "crypto-js";
|
|
2
|
+
// 默认的 KEY 与 iv
|
|
3
|
+
const KEY = CryptoJS.enc.Utf8.parse("1234567890123456");
|
|
4
|
+
const IV = CryptoJS.enc.Utf8.parse("1234567890123456");
|
|
5
|
+
|
|
6
|
+
export const Encrypt = (word: any, keyStr?: any, ivStr?: any) => {
|
|
7
|
+
let key = KEY;
|
|
8
|
+
let iv = IV;
|
|
9
|
+
if (keyStr) {
|
|
10
|
+
key = CryptoJS.enc.Utf8.parse(keyStr);
|
|
11
|
+
iv = CryptoJS.enc.Utf8.parse(ivStr);
|
|
12
|
+
}
|
|
13
|
+
const srcs = CryptoJS.enc.Utf8.parse(word);
|
|
14
|
+
const encrypted = CryptoJS.AES.encrypt(srcs, key, {
|
|
15
|
+
iv: iv,
|
|
16
|
+
mode: CryptoJS.mode.CBC,
|
|
17
|
+
padding: CryptoJS.pad.ZeroPadding,
|
|
18
|
+
});
|
|
19
|
+
return CryptoJS.enc.Base64.stringify(encrypted.ciphertext);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const Decrypt = (word: string, keyStr: string, ivStr: string) => {
|
|
23
|
+
let key = KEY;
|
|
24
|
+
let iv = IV;
|
|
25
|
+
|
|
26
|
+
if (keyStr) {
|
|
27
|
+
key = CryptoJS.enc.Utf8.parse(keyStr);
|
|
28
|
+
iv = CryptoJS.enc.Utf8.parse(ivStr);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const base64 = CryptoJS.enc.Base64.parse(word);
|
|
32
|
+
const src = CryptoJS.enc.Base64.stringify(base64);
|
|
33
|
+
|
|
34
|
+
const decrypt = CryptoJS.AES.decrypt(src, key, {
|
|
35
|
+
iv: iv,
|
|
36
|
+
mode: CryptoJS.mode.CBC,
|
|
37
|
+
padding: CryptoJS.pad.ZeroPadding,
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
|
|
41
|
+
return decryptedStr.toString();
|
|
42
|
+
};
|