cx-chat 0.0.1
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/.cursor/rules/i18n-cn-gloss-comments.mdc +31 -0
- package/.cursor/rules/list-page-view-pageconfig.mdc +32 -0
- package/.cursor/rules/no-over-defensive-programming.mdc +90 -0
- package/.cursor/rules/requirement-description-for-agent.mdc +33 -0
- package/.cursor/rules/use-showToast-not-antd-message.mdc +28 -0
- package/.docker/Dockerfile +7 -0
- package/.env +9 -0
- package/.env.development +7 -0
- package/.env.production +7 -0
- package/.gitlab-ci/docker-build.yaml +28 -0
- package/.gitlab-ci/k8s-deploy-dev-master.yaml +42 -0
- package/.gitlab-ci/npm-build.yaml +17 -0
- package/.gitlab-ci.yml +8 -0
- package/.k8s/0-namespace.yaml +6 -0
- package/.k8s/1-configmap-web.yaml +7 -0
- package/.k8s/1-nginx-conf-dev.yaml +110 -0
- package/.k8s/2-deployment.yaml +27 -0
- package/.k8s/3-service.yaml +16 -0
- package/.k8s/4-ingress-dev.yaml +30 -0
- package/.lingma/rules/use-showToast-not-antd-message.md +34 -0
- package/.nginx/nginx.conf +52 -0
- package/.prettierrc +9 -0
- package/README.md +1 -0
- package/eslint.config.js +32 -0
- package/index.html +13 -0
- package/package.json +67 -0
- package/postcss.config.js +6 -0
- package/public/favicon.ico +0 -0
- package/public/vite.svg +1 -0
- package/src/App.tsx +96 -0
- package/src/_doc/0.docs-overview.md +28 -0
- package/src/_doc/cx-ui/0.docs-overview.md +30 -0
- package/src/_doc/cx-ui/comp.1.cx-ui-overview.md +82 -0
- package/src/_doc/cx-ui/comp.2.cx-modal.md +82 -0
- package/src/_doc/cx-ui/comp.3.cx-button.md +89 -0
- package/src/_doc/cx-ui/comp.4.cx-form.md +72 -0
- package/src/_doc/cx-ui/comp.5.cx-fields.md +76 -0
- package/src/_doc/cx-ui/comp.6.cx-tag.md +57 -0
- package/src/_doc/cx-ui/comp.7.cx-empty-state.md +29 -0
- package/src/_doc/meta/0.docs-overview.md +24 -0
- package/src/_doc/meta/comp.1.enum-runtime.md +33 -0
- package/src/_doc/meta/comp.2.dict-runtime.md +39 -0
- package/src/_doc/router/0.docs-overview.md +14 -0
- package/src/_doc/router/guide.1.menu-component-config.md +181 -0
- package/src/_doc/router/guide.2.router-auto-registration.md +114 -0
- package/src/_doc/table-view/0.docs-overview.md +30 -0
- package/src/_doc/table-view/comp.1.table-view.md +542 -0
- package/src/_doc/table-view/props.1.create-table-view-config.md +193 -0
- package/src/_doc/table-view/props.2.table-view-search-fields.md +106 -0
- package/src/api/_mock/README.md +340 -0
- package/src/api/_mock/api.ts +1642 -0
- package/src/api/_mock/bundle-shim.ts +16 -0
- package/src/api/_mock/handler-shim.ts +6 -0
- package/src/api/_mock/handler.ts +458 -0
- package/src/api/_mock/index.ts +711 -0
- package/src/api/_mock/interceptor.ts +15 -0
- package/src/api/_mock/mod.ts +12 -0
- package/src/api/_mock/utils.ts +65 -0
- package/src/api/base/memory.js +24 -0
- package/src/api/chat.js +210 -0
- package/src/api/common/auth.js +70 -0
- package/src/api/menus/business-rules.js +76 -0
- package/src/api/menus/feedback.js +102 -0
- package/src/api/menus/knowledge.js +159 -0
- package/src/api/menus/model-metadata/manage.js +70 -0
- package/src/api/menus/model-metadata/role.js +50 -0
- package/src/api/menus/model-metadata/training-detail-mock-data.js +569 -0
- package/src/api/menus/model-metadata/training.js +28 -0
- package/src/api/menus/skill.js +40 -0
- package/src/api/system/agent-config.js +16 -0
- package/src/api/system/department.js +94 -0
- package/src/api/system/dict.js +86 -0
- package/src/api/system/menu.js +37 -0
- package/src/api/system/permission.js +26 -0
- package/src/api/system/role.js +34 -0
- package/src/api/system/sys-config.js +16 -0
- package/src/api/system/sys-log.js +17 -0
- package/src/api/system/user.js +75 -0
- package/src/api/upload.js +39 -0
- package/src/assets/react.svg +1 -0
- package/src/components/auth/current-user-avatar.tsx +77 -0
- package/src/components/common/code-view.tsx +149 -0
- package/src/components/common/detail-link.tsx +67 -0
- package/src/components/common/error-boundary.tsx +98 -0
- package/src/components/common/language-switcher.tsx +91 -0
- package/src/components/common/lite-table/index.tsx +135 -0
- package/src/components/common/md-editor.tsx +126 -0
- package/src/components/common/modal/confirm-dialog.tsx +113 -0
- package/src/components/common/modal/dep-user-select-multi.tsx +324 -0
- package/src/components/common/modal/dep-user-select.tsx +249 -0
- package/src/components/common/modal/user-select-multi.tsx +266 -0
- package/src/components/common/pagination.tsx +472 -0
- package/src/components/common/path.tsx +175 -0
- package/src/components/common/system-logo-mark.tsx +48 -0
- package/src/components/cx-ui/button/index.less +208 -0
- package/src/components/cx-ui/button/index.tsx +611 -0
- package/src/components/cx-ui/checkbox/index.tsx +78 -0
- package/src/components/cx-ui/date-picker/index.less +17 -0
- package/src/components/cx-ui/date-picker/index.tsx +193 -0
- package/src/components/cx-ui/drawer/index.tsx +47 -0
- package/src/components/cx-ui/empty-state/index.tsx +20 -0
- package/src/components/cx-ui/floating-shell/CxFloatingShell.tsx +89 -0
- package/src/components/cx-ui/floating-shell/cx-floating-shell.less +283 -0
- package/src/components/cx-ui/floating-shell/has-floating-value.ts +41 -0
- package/src/components/cx-ui/form/CxForm.tsx +15 -0
- package/src/components/cx-ui/form/index.tsx +20 -0
- package/src/components/cx-ui/form-item/index.less +26 -0
- package/src/components/cx-ui/form-item/index.tsx +36 -0
- package/src/components/cx-ui/index.ts +70 -0
- package/src/components/cx-ui/input/auto-complete.tsx +134 -0
- package/src/components/cx-ui/input/index.tsx +259 -0
- package/src/components/cx-ui/input-number/index.jsx +66 -0
- package/src/components/cx-ui/modal/index.jsx +212 -0
- package/src/components/cx-ui/modal/index.less +144 -0
- package/src/components/cx-ui/modal/useCxModal.ts +125 -0
- package/src/components/cx-ui/multi-select/index.jsx +74 -0
- package/src/components/cx-ui/multi-select/index.less +40 -0
- package/src/components/cx-ui/multi-select/index2.tsx +361 -0
- package/src/components/cx-ui/radio/index.tsx +33 -0
- package/src/components/cx-ui/range-picker/index.less +65 -0
- package/src/components/cx-ui/range-picker/index.tsx +219 -0
- package/src/components/cx-ui/select/index.less +34 -0
- package/src/components/cx-ui/select/index.tsx +196 -0
- package/src/components/cx-ui/skeleton/index.tsx +12 -0
- package/src/components/cx-ui/steps/index.tsx +14 -0
- package/src/components/cx-ui/styles/_tokens.less +79 -0
- package/src/components/cx-ui/styles/index.less +246 -0
- package/src/components/cx-ui/switch/index.less +106 -0
- package/src/components/cx-ui/switch/index.tsx +120 -0
- package/src/components/cx-ui/table/index.less +160 -0
- package/src/components/cx-ui/table/index.tsx +152 -0
- package/src/components/cx-ui/tabs/index.less +15 -0
- package/src/components/cx-ui/tabs/index.tsx +34 -0
- package/src/components/cx-ui/tag/index.less +51 -0
- package/src/components/cx-ui/tag/index.tsx +140 -0
- package/src/components/cx-ui/timeline/index.tsx +14 -0
- package/src/components/cx-ui/tooltip/index.tsx +67 -0
- package/src/components/cx-ui/tree/index.tsx +193 -0
- package/src/components/cx-ui/tree-select/index.jsx +91 -0
- package/src/components/cx-ui/tree-select/index.less +27 -0
- package/src/components/cx-ui/upload-file/index.less +223 -0
- package/src/components/cx-ui/upload-file/index.tsx +640 -0
- package/src/components/cx-ui/upload-img/index.tsx +291 -0
- package/src/components/layout/components/Header.tsx +216 -0
- package/src/components/layout/components/Sidebar.tsx +717 -0
- package/src/components/layout/index.tsx +95 -0
- package/src/components/table-view/components/search-area.tsx +411 -0
- package/src/components/table-view/components/table-view-config.tsx +528 -0
- package/src/components/table-view/components/table-view.types.ts +478 -0
- package/src/components/table-view/components/tree-api-normalize.ts +38 -0
- package/src/components/table-view/components/tree-data-annotate.ts +31 -0
- package/src/components/table-view/components/tree-sidebar.tsx +74 -0
- package/src/components/table-view/index.tsx +61 -0
- package/src/components/table-view/list-page-view.tsx +1049 -0
- package/src/components/table-view/select-table-view.tsx +1094 -0
- package/src/components/table-view/styles/select-table-view.less +51 -0
- package/src/config/default-system-name.ts +9 -0
- package/src/config/system.ts +165 -0
- package/src/constants/countryCodes.ts +3 -0
- package/src/contexts/AuthContext.tsx +256 -0
- package/src/contexts/ChatContext.tsx +839 -0
- package/src/contexts/MenuContext.tsx +62 -0
- package/src/contexts/ToastContext.tsx +181 -0
- package/src/hooks/useCopyToClipboard.ts +47 -0
- package/src/hooks/useModalSubmit.ts +104 -0
- package/src/hooks/useRouter.ts +240 -0
- package/src/hooks/useStepForm.ts +46 -0
- package/src/hooks/useStickyHeader.ts +42 -0
- package/src/hooks/useThreadActions.ts +105 -0
- package/src/hooks/useUserPreferences.ts +101 -0
- package/src/http/axios.js +372 -0
- package/src/http/mock.interceptor.ts +9 -0
- package/src/http/obfuscationKey.ts +41 -0
- package/src/i18n.ts +60 -0
- package/src/index.js +1 -0
- package/src/index.less +169 -0
- package/src/locales/en/auth.ts +70 -0
- package/src/locales/en/base/memory.ts +28 -0
- package/src/locales/en/base/settings.ts +41 -0
- package/src/locales/en/chat.ts +40 -0
- package/src/locales/en/common.ts +173 -0
- package/src/locales/en/enum.ts +27 -0
- package/src/locales/en/menus/business-rules.ts +48 -0
- package/src/locales/en/menus/feedback.ts +62 -0
- package/src/locales/en/menus/knowledge.ts +120 -0
- package/src/locales/en/menus/model-metadata/index.ts +10 -0
- package/src/locales/en/menus/model-metadata/manage.ts +151 -0
- package/src/locales/en/menus/model-metadata/role.ts +48 -0
- package/src/locales/en/menus/model-metadata/training.ts +65 -0
- package/src/locales/en/menus/skill.ts +34 -0
- package/src/locales/en/system/agent-config.ts +34 -0
- package/src/locales/en/system/department.ts +68 -0
- package/src/locales/en/system/dict.ts +44 -0
- package/src/locales/en/system/menu.ts +45 -0
- package/src/locales/en/system/permission.ts +89 -0
- package/src/locales/en/system/role.ts +25 -0
- package/src/locales/en/system/sys-config.ts +33 -0
- package/src/locales/en/system/sys-log.ts +38 -0
- package/src/locales/en/system/user.ts +113 -0
- package/src/locales/en.ts +68 -0
- package/src/locales/zh/auth.ts +70 -0
- package/src/locales/zh/base/memory.ts +29 -0
- package/src/locales/zh/base/settings.ts +41 -0
- package/src/locales/zh/chat.ts +47 -0
- package/src/locales/zh/common.ts +178 -0
- package/src/locales/zh/enum.ts +28 -0
- package/src/locales/zh/menus/business-rules.ts +47 -0
- package/src/locales/zh/menus/feedback.ts +62 -0
- package/src/locales/zh/menus/knowledge.ts +117 -0
- package/src/locales/zh/menus/model-metadata/index.ts +10 -0
- package/src/locales/zh/menus/model-metadata/manage.ts +151 -0
- package/src/locales/zh/menus/model-metadata/role.ts +47 -0
- package/src/locales/zh/menus/model-metadata/training.ts +64 -0
- package/src/locales/zh/menus/skill.ts +34 -0
- package/src/locales/zh/system/agent-config.ts +33 -0
- package/src/locales/zh/system/department.ts +69 -0
- package/src/locales/zh/system/dict.ts +44 -0
- package/src/locales/zh/system/menu.ts +47 -0
- package/src/locales/zh/system/permission.ts +94 -0
- package/src/locales/zh/system/role.ts +25 -0
- package/src/locales/zh/system/sys-config.ts +32 -0
- package/src/locales/zh/system/sys-log.ts +38 -0
- package/src/locales/zh/system/user.ts +114 -0
- package/src/locales/zh.ts +67 -0
- package/src/main.tsx +50 -0
- package/src/meta/const/index.ts +40 -0
- package/src/meta/index-dict.ts +56 -0
- package/src/meta/index-enum.ts +95 -0
- package/src/meta/index.ts +14 -0
- package/src/meta/module/dict-data/runtime.ts +199 -0
- package/src/meta/module/dict-data/types.ts +17 -0
- package/src/meta/module/enum-data/runtime.ts +75 -0
- package/src/meta/module/enum-data/types.ts +18 -0
- package/src/router/index.tsx +312 -0
- package/src/styles/AntdThemeProvider.tsx +40 -0
- package/src/styles/antd-theme.ts +20 -0
- package/src/styles/global.less +107 -0
- package/src/styles/variable.less +103 -0
- package/src/types/feedback.ts +43 -0
- package/src/types/index.ts +85 -0
- package/src/types/menu.ts +43 -0
- package/src/utils/aesUtil.ts +123 -0
- package/src/utils/chatUtils.ts +524 -0
- package/src/utils/cn.ts +6 -0
- package/src/utils/crypto.ts +164 -0
- package/src/utils/date.ts +72 -0
- package/src/utils/file-icons.tsx +79 -0
- package/src/utils/index.ts +168 -0
- package/src/utils/markdown-math-plugins.ts +21 -0
- package/src/utils/menuI18n.ts +305 -0
- package/src/utils/menuRouteRegistry.ts +78 -0
- package/src/utils/permission-crud.ts +147 -0
- package/src/utils/routeConfig.ts +350 -0
- package/src/utils/storage.ts +135 -0
- package/src/utils/toastBridge.ts +26 -0
- package/src/utils/url.ts +38 -0
- package/src/utils/validation.ts +16 -0
- package/src/views/auth/auth-code/index.less +169 -0
- package/src/views/auth/auth-code/index.module.less +174 -0
- package/src/views/auth/auth-code/index.tsx +233 -0
- package/src/views/auth/login.tsx +498 -0
- package/src/views/auth/register.tsx +388 -0
- package/src/views/base/memory/index.tsx +136 -0
- package/src/views/base/memory/modal/detail-modal.tsx +89 -0
- package/src/views/base/memory/modal/submit-modal.tsx +134 -0
- package/src/views/base/settings/index.tsx +657 -0
- package/src/views/chat/chat.less +323 -0
- package/src/views/chat/components/chat-input.tsx +298 -0
- package/src/views/chat/components/header-thread-title.tsx +210 -0
- package/src/views/chat/components/message-list/content-answer.tsx +100 -0
- package/src/views/chat/components/message-list/content-question.tsx +18 -0
- package/src/views/chat/components/message-list/index.tsx +520 -0
- package/src/views/chat/components/message-list/message-item.tsx +199 -0
- package/src/views/chat/components/message-list/preparation-demo-items.ts +147 -0
- package/src/views/chat/components/message-list/preparation-steps.tsx +506 -0
- package/src/views/chat/components/message-list/suggestion-list.tsx +36 -0
- package/src/views/chat/components/message-list/thinking-process.tsx +49 -0
- package/src/views/chat/components/message-list/toolbar.tsx +224 -0
- package/src/views/chat/components/message-list/use-message-list-scroll.ts +214 -0
- package/src/views/chat/components/references-knowledge/context.tsx +57 -0
- package/src/views/chat/components/references-knowledge/index.ts +9 -0
- package/src/views/chat/components/references-knowledge/modal/knowledge-detail-drawer.tsx +556 -0
- package/src/views/chat/components/references-knowledge/modal/knowledge-doc-detail-drawer.tsx +529 -0
- package/src/views/chat/components/references-knowledge/panel.tsx +115 -0
- package/src/views/chat/hooks/use-chat-common.ts +19 -0
- package/src/views/chat/index-session.tsx +647 -0
- package/src/views/chat/index.tsx +127 -0
- package/src/views/page-error/401.tsx +56 -0
- package/src/views/page-error/404.tsx +56 -0
- package/src/views/page-menus/business-rules/index.tsx +376 -0
- package/src/views/page-menus/business-rules/modal/detail-modal.tsx +186 -0
- package/src/views/page-menus/business-rules/modal/scope-modal.tsx +272 -0
- package/src/views/page-menus/business-rules/modal/submit-modal.tsx +142 -0
- package/src/views/page-menus/feedback/components/feedback-dataset-list.tsx +471 -0
- package/src/views/page-menus/feedback/index.tsx +166 -0
- package/src/views/page-menus/feedback/modal/export-feedback-modal.tsx +367 -0
- package/src/views/page-menus/knowledge/components/doc-editor-by-type.tsx +32 -0
- package/src/views/page-menus/knowledge/components/doc-editor-type-file.tsx +330 -0
- package/src/views/page-menus/knowledge/detail.tsx +600 -0
- package/src/views/page-menus/knowledge/index.tsx +337 -0
- package/src/views/page-menus/knowledge/modal/detail-modal.tsx +618 -0
- package/src/views/page-menus/knowledge/modal/doc-detail-modal.tsx +550 -0
- package/src/views/page-menus/knowledge/modal/doc-parse.ts +99 -0
- package/src/views/page-menus/knowledge/modal/doc-submit-modal.tsx +349 -0
- package/src/views/page-menus/knowledge/modal/doc-type-picker-modal.tsx +88 -0
- package/src/views/page-menus/knowledge/modal/knowledge-user-select-modal.tsx +283 -0
- package/src/views/page-menus/knowledge/modal/submit-modal.tsx +179 -0
- package/src/views/page-menus/model-metadata/manage/components/metadata-detail-schema-tab.tsx +114 -0
- package/src/views/page-menus/model-metadata/manage/components/step1-basic-info.tsx +232 -0
- package/src/views/page-menus/model-metadata/manage/components/step2-schema.tsx +316 -0
- package/src/views/page-menus/model-metadata/manage/components/step3-permissions.tsx +134 -0
- package/src/views/page-menus/model-metadata/manage/components/step4-documents.tsx +134 -0
- package/src/views/page-menus/model-metadata/manage/components/step5-example-sql.tsx +101 -0
- package/src/views/page-menus/model-metadata/manage/components/submit-add.tsx +338 -0
- package/src/views/page-menus/model-metadata/manage/components/submit-edit.tsx +276 -0
- package/src/views/page-menus/model-metadata/manage/detail.tsx +298 -0
- package/src/views/page-menus/model-metadata/manage/hooks/model-metadata-submit-shared.ts +113 -0
- package/src/views/page-menus/model-metadata/manage/hooks/use-model-metadata-item-state.ts +20 -0
- package/src/views/page-menus/model-metadata/manage/index.tsx +304 -0
- package/src/views/page-menus/model-metadata/manage/modal/components/table-schema.ts +374 -0
- package/src/views/page-menus/model-metadata/manage/modal/components/use-table-detail-tabs.tsx +151 -0
- package/src/views/page-menus/model-metadata/manage/modal/components/use-table-submit-tabs.tsx +423 -0
- package/src/views/page-menus/model-metadata/manage/modal/detail-modal.tsx +218 -0
- package/src/views/page-menus/model-metadata/manage/modal/submit-modal.tsx +261 -0
- package/src/views/page-menus/model-metadata/manage/modal/table-detail-modal.tsx +196 -0
- package/src/views/page-menus/model-metadata/manage/modal/table-submit-modal.tsx +229 -0
- package/src/views/page-menus/model-metadata/manage/submit.tsx +31 -0
- package/src/views/page-menus/model-metadata/role/index.tsx +207 -0
- package/src/views/page-menus/model-metadata/role/modal/detail-modal.tsx +97 -0
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-modal.tsx +254 -0
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-panel.tsx +393 -0
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-utils.ts +120 -0
- package/src/views/page-menus/model-metadata/role/modal/role-permission-assign-panel.tsx +698 -0
- package/src/views/page-menus/model-metadata/role/modal/role-permission-modal.tsx +237 -0
- package/src/views/page-menus/model-metadata/role/modal/submit-modal.tsx +135 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/index.ts +4 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/node-card.tsx +72 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/summary-lines.ts +196 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/summary-list.tsx +153 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/timeline.tsx +103 -0
- package/src/views/page-menus/model-metadata/training/components/detail-records/types.ts +82 -0
- package/src/views/page-menus/model-metadata/training/detail.tsx +159 -0
- package/src/views/page-menus/model-metadata/training/index.tsx +236 -0
- package/src/views/page-menus/model-metadata/training/modal/update-detail-modal.tsx +154 -0
- package/src/views/page-menus/skill/index.tsx +201 -0
- package/src/views/page-menus/skill/modal/detail-modal.tsx +156 -0
- package/src/views/page-menus/skill/modal/submit-modal.tsx +214 -0
- package/src/views/page-system/agent-config/index.tsx +370 -0
- package/src/views/page-system/department/departmentFormShared.ts +36 -0
- package/src/views/page-system/department/index.tsx +541 -0
- package/src/views/page-system/department/modal/detail-modal.tsx +94 -0
- package/src/views/page-system/department/modal/member-role-modal.tsx +128 -0
- package/src/views/page-system/department/modal/submit-modal.tsx +265 -0
- package/src/views/page-system/dict/index.tsx +440 -0
- package/src/views/page-system/dict/modal/cate-submit-modal.tsx +315 -0
- package/src/views/page-system/dict/modal/submit-modal.tsx +184 -0
- package/src/views/page-system/logs/components/index.ts +3 -0
- package/src/views/page-system/logs/components/log-message-demo.tsx +30 -0
- package/src/views/page-system/logs/components/log-message-stream.ts +184 -0
- package/src/views/page-system/logs/components/message-list/content-answer.tsx +100 -0
- package/src/views/page-system/logs/components/message-list/content-question.tsx +18 -0
- package/src/views/page-system/logs/components/message-list/index.tsx +515 -0
- package/src/views/page-system/logs/components/message-list/message-item.tsx +193 -0
- package/src/views/page-system/logs/components/message-list/preparation-demo-items.ts +147 -0
- package/src/views/page-system/logs/components/message-list/preparation-steps.tsx +506 -0
- package/src/views/page-system/logs/components/message-list/suggestion-list.tsx +36 -0
- package/src/views/page-system/logs/components/message-list/thinking-process.tsx +49 -0
- package/src/views/page-system/logs/components/message-list/toolbar.tsx +134 -0
- package/src/views/page-system/logs/components/message-list/use-message-list-scroll.ts +214 -0
- package/src/views/page-system/logs/components/message-modal.tsx +239 -0
- package/src/views/page-system/logs/index.tsx +132 -0
- package/src/views/page-system/logs/modal/detail-modal.tsx +157 -0
- package/src/views/page-system/menu/components/menuFormShared.ts +283 -0
- package/src/views/page-system/menu/index.less +12 -0
- package/src/views/page-system/menu/index.tsx +410 -0
- package/src/views/page-system/menu/modal/icon-modal.less +51 -0
- package/src/views/page-system/menu/modal/icon-modal.tsx +87 -0
- package/src/views/page-system/menu/modal/submit-modal.tsx +263 -0
- package/src/views/page-system/permission/index.tsx +562 -0
- package/src/views/page-system/permission/modal/detail-modal.tsx +179 -0
- package/src/views/page-system/permission/modal/submit-modal.less +146 -0
- package/src/views/page-system/permission/modal/submit-modal.tsx +650 -0
- package/src/views/page-system/role/index.tsx +163 -0
- package/src/views/page-system/role/modal/detail-modal.tsx +127 -0
- package/src/views/page-system/role/modal/permission-assign-group-rules.ts +86 -0
- package/src/views/page-system/role/modal/permission-modal.tsx +111 -0
- package/src/views/page-system/role/modal/role-modal-shell-styles.ts +21 -0
- package/src/views/page-system/role/modal/role-permission-assign-panel.tsx +916 -0
- package/src/views/page-system/role/modal/role-permission-assign-shared.ts +1047 -0
- package/src/views/page-system/role/modal/submit-modal.tsx +193 -0
- package/src/views/page-system/sys-config/index.tsx +294 -0
- package/src/views/page-system/user/components/user-role-column.tsx +87 -0
- package/src/views/page-system/user/index.tsx +439 -0
- package/src/views/page-system/user/modal/assign-roles-modal.tsx +389 -0
- package/src/views/page-system/user/modal/detail-modal.tsx +72 -0
- package/src/views/page-system/user/modal/modal-style/submit-modal.less +40 -0
- package/src/views/page-system/user/modal/submit-modal.less +40 -0
- package/src/views/page-system/user/modal/submit-modal.tsx +287 -0
- package/src/views/page-system/user/userFormShared.ts +51 -0
- package/tailwind.config.js +17 -0
- package/tsconfig.app.json +48 -0
- package/tsconfig.json +11 -0
- package/tsconfig.node.json +26 -0
- package/vite.config.ts +264 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type React from 'react'
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
import { useOutletContext } from 'react-router-dom';
|
|
4
|
+
|
|
5
|
+
export interface MainLayoutContext {
|
|
6
|
+
setHeaderTitle: (title: React.ReactNode | null) => void;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export const useStickyHeader = (title: string) => {
|
|
10
|
+
const context = useOutletContext<MainLayoutContext>();
|
|
11
|
+
// Safeguard: if hook is used outside of MainLayout context
|
|
12
|
+
const setHeaderTitle = context?.setHeaderTitle || (() => { });
|
|
13
|
+
|
|
14
|
+
const ref = useRef<HTMLDivElement>(null);
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
const element = ref.current;
|
|
18
|
+
if (!element) return;
|
|
19
|
+
|
|
20
|
+
const observer = new IntersectionObserver(
|
|
21
|
+
([entry]) => {
|
|
22
|
+
// If element is NOT interacting (scrolled out of view), show title in header
|
|
23
|
+
if (!entry.isIntersecting && entry.boundingClientRect.top < 0) {
|
|
24
|
+
// Only trigger if it went off the TOP, not bottom
|
|
25
|
+
setHeaderTitle(title);
|
|
26
|
+
} else {
|
|
27
|
+
setHeaderTitle(null);
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{ threshold: 0 }
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
observer.observe(element);
|
|
34
|
+
|
|
35
|
+
return () => {
|
|
36
|
+
observer.disconnect();
|
|
37
|
+
setHeaderTitle(null);
|
|
38
|
+
};
|
|
39
|
+
}, [title, setHeaderTitle]);
|
|
40
|
+
|
|
41
|
+
return ref;
|
|
42
|
+
};
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
cancelTopChatAPI,
|
|
5
|
+
deleteChatSessionAPI,
|
|
6
|
+
topChatAPI,
|
|
7
|
+
updateChatTitleAPI,
|
|
8
|
+
} from '@/api/chat'
|
|
9
|
+
|
|
10
|
+
/** 全局订阅:正在执行删除 API 的会话 id(无则 null) */
|
|
11
|
+
export const CHAT_DELETING_SESSION_QUERY_KEY = ['chat', 'deletingSessionId'] as const
|
|
12
|
+
|
|
13
|
+
export function useDeletingChatSessionId(): string | null {
|
|
14
|
+
const { data } = useQuery({
|
|
15
|
+
queryKey: CHAT_DELETING_SESSION_QUERY_KEY,
|
|
16
|
+
queryFn: () => null as string | null,
|
|
17
|
+
staleTime: Infinity,
|
|
18
|
+
gcTime: Infinity,
|
|
19
|
+
initialData: null,
|
|
20
|
+
})
|
|
21
|
+
return typeof data === 'string' && data.length > 0 ? data : null
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
type UseThreadActionsOptions = {
|
|
25
|
+
onDeleteSuccess?: (threadId: string) => void
|
|
26
|
+
onUpdateSuccess?: () => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export const useThreadActions = (options?: UseThreadActionsOptions) => {
|
|
30
|
+
const queryClient = useQueryClient()
|
|
31
|
+
|
|
32
|
+
const updateTitleMutation = useMutation({
|
|
33
|
+
mutationFn: async (payload: { sessionId: string; title: string }) => {
|
|
34
|
+
await updateChatTitleAPI({
|
|
35
|
+
sessionId: payload.sessionId,
|
|
36
|
+
title: payload.title,
|
|
37
|
+
})
|
|
38
|
+
},
|
|
39
|
+
onSuccess: () => {
|
|
40
|
+
queryClient.invalidateQueries({ queryKey: ['threads'] })
|
|
41
|
+
options?.onUpdateSuccess?.()
|
|
42
|
+
},
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const pinMutation = useMutation({
|
|
46
|
+
mutationFn: async (payload: {
|
|
47
|
+
sessionId: string
|
|
48
|
+
/** 当前是否已置顶:已置顶则取消置顶,否则置顶 */
|
|
49
|
+
isPinned: boolean
|
|
50
|
+
}) => {
|
|
51
|
+
const { sessionId } = payload
|
|
52
|
+
if (payload.isPinned) {
|
|
53
|
+
await cancelTopChatAPI({ sessionId })
|
|
54
|
+
} else {
|
|
55
|
+
await topChatAPI({ sessionId })
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
onSuccess: () => {
|
|
59
|
+
queryClient.invalidateQueries({ queryKey: ['threads'] })
|
|
60
|
+
options?.onUpdateSuccess?.()
|
|
61
|
+
},
|
|
62
|
+
})
|
|
63
|
+
|
|
64
|
+
const deleteThreadMutation = useMutation({
|
|
65
|
+
mutationFn: async (threadId: string) => {
|
|
66
|
+
await deleteChatSessionAPI({ sessionId: threadId })
|
|
67
|
+
return threadId
|
|
68
|
+
},
|
|
69
|
+
onMutate: (threadId) => {
|
|
70
|
+
queryClient.setQueryData(CHAT_DELETING_SESSION_QUERY_KEY, threadId)
|
|
71
|
+
},
|
|
72
|
+
onSettled: () => {
|
|
73
|
+
queryClient.setQueryData(CHAT_DELETING_SESSION_QUERY_KEY, null)
|
|
74
|
+
},
|
|
75
|
+
onSuccess: (threadId) => {
|
|
76
|
+
queryClient.invalidateQueries({ queryKey: ['threads'] })
|
|
77
|
+
options?.onDeleteSuccess?.(threadId)
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
const renameThread = (threadId: string, title: string) => {
|
|
82
|
+
return updateTitleMutation.mutate({
|
|
83
|
+
sessionId: threadId,
|
|
84
|
+
title: title.trim(),
|
|
85
|
+
})
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
/** @param isPinned 当前会话是否已置顶(与列表 top_status===1 一致) */
|
|
89
|
+
const togglePinThread = (threadId: string, isPinned: boolean) => {
|
|
90
|
+
return pinMutation.mutate({ sessionId: threadId, isPinned })
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const deleteThread = (threadId: string) => {
|
|
94
|
+
return deleteThreadMutation.mutate(threadId)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
return {
|
|
98
|
+
renameThread,
|
|
99
|
+
togglePinThread,
|
|
100
|
+
deleteThread,
|
|
101
|
+
isUpdatingThread:
|
|
102
|
+
updateTitleMutation.isPending || pinMutation.isPending,
|
|
103
|
+
isDeletingThread: deleteThreadMutation.isPending,
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useTranslation } from 'react-i18next';
|
|
3
|
+
import { setUserCurrentThemeAPI, setUserCurrentLanguageAPI } from '@api/system/user';
|
|
4
|
+
import { getStore, removeStore, setStore } from '@/utils/storage'
|
|
5
|
+
type UserPreferenceSource = {
|
|
6
|
+
theme?: string;
|
|
7
|
+
language?: string;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export const useUserPreferences = () => {
|
|
11
|
+
const { i18n } = useTranslation();
|
|
12
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
13
|
+
|
|
14
|
+
// Load preferences from provided user info (no extra API needed)
|
|
15
|
+
const loadPreferences = useCallback(async (userInfo?: UserPreferenceSource) => {
|
|
16
|
+
try {
|
|
17
|
+
// Apply theme: storage 优先,其次用户信息(当前主题保存仅本地)
|
|
18
|
+
// const localTheme = localStorage.getItem('theme');
|
|
19
|
+
const localTheme = getStore('theme');
|
|
20
|
+
const preferredTheme =
|
|
21
|
+
localTheme === 'dark' || localTheme === 'light'
|
|
22
|
+
? localTheme
|
|
23
|
+
: userInfo?.theme;
|
|
24
|
+
|
|
25
|
+
if (preferredTheme === 'dark') {
|
|
26
|
+
document.documentElement.classList.add('dark');
|
|
27
|
+
// localStorage.setItem('theme', 'dark');
|
|
28
|
+
setStore('theme', 'dark');
|
|
29
|
+
} else {
|
|
30
|
+
document.documentElement.classList.remove('dark');
|
|
31
|
+
if (preferredTheme === 'light') {
|
|
32
|
+
// localStorage.setItem('theme', 'light');
|
|
33
|
+
setStore('theme', 'light');
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Apply language
|
|
38
|
+
const langCode = userInfo?.language;
|
|
39
|
+
if (langCode) {
|
|
40
|
+
i18n.changeLanguage(langCode);
|
|
41
|
+
// localStorage.setItem('i18nextLng', langCode);
|
|
42
|
+
setStore('i18nextLng', langCode);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
setIsLoading(false);
|
|
46
|
+
} catch (error) {
|
|
47
|
+
console.error('Failed to load user preferences:', error);
|
|
48
|
+
// Fallback to storage
|
|
49
|
+
// const localTheme = localStorage.getItem('theme');
|
|
50
|
+
const localTheme = getStore('theme');
|
|
51
|
+
if (localTheme === 'dark') {
|
|
52
|
+
document.documentElement.classList.add('dark');
|
|
53
|
+
} else {
|
|
54
|
+
document.documentElement.classList.remove('dark');
|
|
55
|
+
}
|
|
56
|
+
setIsLoading(false);
|
|
57
|
+
}
|
|
58
|
+
}, [i18n]);
|
|
59
|
+
|
|
60
|
+
// 保存主题到服务端(同时落 localStorage,保证刷新后主题一致)
|
|
61
|
+
const saveTheme = useCallback(async (theme: 'light' | 'dark') => {
|
|
62
|
+
try {
|
|
63
|
+
await setUserCurrentThemeAPI({
|
|
64
|
+
theme,
|
|
65
|
+
mode: theme,
|
|
66
|
+
} as any);
|
|
67
|
+
setStore('theme', theme);
|
|
68
|
+
// localStorage.setItem('theme', theme);
|
|
69
|
+
} catch (error) {
|
|
70
|
+
console.error('Failed to save theme:', error);
|
|
71
|
+
// Still save to localStorage as fallback
|
|
72
|
+
setStore('theme', theme);
|
|
73
|
+
// localStorage.setItem('theme', theme);
|
|
74
|
+
}
|
|
75
|
+
}, []);
|
|
76
|
+
|
|
77
|
+
// 保存语言到服务端(同时落 localStorage,保证刷新后语言一致)
|
|
78
|
+
const saveLanguage = useCallback(async (langCode: string) => {
|
|
79
|
+
try {
|
|
80
|
+
await setUserCurrentLanguageAPI({
|
|
81
|
+
language: langCode,
|
|
82
|
+
lang: langCode,
|
|
83
|
+
code: langCode,
|
|
84
|
+
} as any);
|
|
85
|
+
setStore('i18nextLng', langCode);
|
|
86
|
+
// localStorage.setItem('i18nextLng', langCode);
|
|
87
|
+
} catch (error) {
|
|
88
|
+
console.error('Failed to save language:', error);
|
|
89
|
+
// Still save to localStorage as fallback
|
|
90
|
+
setStore('i18nextLng', langCode);
|
|
91
|
+
// localStorage.setItem('i18nextLng', langCode);
|
|
92
|
+
}
|
|
93
|
+
}, []);
|
|
94
|
+
|
|
95
|
+
return {
|
|
96
|
+
isLoading,
|
|
97
|
+
loadPreferences,
|
|
98
|
+
saveTheme,
|
|
99
|
+
saveLanguage,
|
|
100
|
+
};
|
|
101
|
+
};
|
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { showGlobalToast } from '@/utils/toastBridge';
|
|
2
|
+
import { mockManager } from '@api/_mock';
|
|
3
|
+
import { handleMockRequest } from '@api/_mock/handler';
|
|
4
|
+
import aesUtil from '@utils/aesUtil';
|
|
5
|
+
import { getStore, removeStore } from '@utils/storage';
|
|
6
|
+
import axios from 'axios';
|
|
7
|
+
import i18n from '../i18n';
|
|
8
|
+
import { clearObfuscationKey, getObfuscationKey } from './obfuscationKey';
|
|
9
|
+
|
|
10
|
+
export const API_BASE_URL = `${import.meta.env.VITE_PUBLIC_PATH}${import.meta.env.VITE_API_BASE_URL}`;
|
|
11
|
+
|
|
12
|
+
export const globeEncryption = Boolean(import.meta.env.VITE_APP_ENCRYPTION) || true;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 获取系统语言请求头值:根据当前国际化语言映射到后端约定的枚举。
|
|
16
|
+
* - 中文:zh_CN
|
|
17
|
+
* - 英文:en_US
|
|
18
|
+
*/
|
|
19
|
+
export function getSystemLanguageHeaderValue() {
|
|
20
|
+
const lng = i18n.language || 'zh';
|
|
21
|
+
// i18next 常见语言形态:en / en-US / zh / zh-CN
|
|
22
|
+
if (lng.startsWith('en')) return 'en_US';
|
|
23
|
+
return 'zh_CN';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const request = axios.create({
|
|
27
|
+
baseURL: API_BASE_URL,
|
|
28
|
+
headers: {
|
|
29
|
+
'Content-Type': 'application/json',
|
|
30
|
+
},
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
let isRedirectingToLogin = false;
|
|
34
|
+
|
|
35
|
+
/** 已是登录页则不再 location 跳转,避免无意义刷新(兼容 BrowserRouter / HashRouter) */
|
|
36
|
+
function isCurrentLoginPage() {
|
|
37
|
+
const path = window.location.pathname || '';
|
|
38
|
+
if (/^\/login\/?$/i.test(path)) return true;
|
|
39
|
+
|
|
40
|
+
const hash = window.location.hash || '';
|
|
41
|
+
return /^#\/login(\/|$|\?)/i.test(hash);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getLoginHref() {
|
|
45
|
+
return `${window.location.origin}${window.location.pathname}#/login`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let requestI = aesUtil.genKey(48);
|
|
49
|
+
|
|
50
|
+
export const ifNeedEncrypt = (config) => {
|
|
51
|
+
requestI = aesUtil.genKey(48);
|
|
52
|
+
if (config.noEncryption) {
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
return globeEncryption;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
request.interceptors.request.use(
|
|
59
|
+
async (config) => {
|
|
60
|
+
if (mockManager.isEnabled()) {
|
|
61
|
+
console.log('[Mock] Axios request intercepted:', config.url);
|
|
62
|
+
|
|
63
|
+
const mockResponse = await handleMockRequest(config);
|
|
64
|
+
if (mockResponse) {
|
|
65
|
+
return Promise.reject({
|
|
66
|
+
isMock: true,
|
|
67
|
+
response: mockResponse,
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
return config;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (ifNeedEncrypt(config)) {
|
|
74
|
+
let data = config.data;
|
|
75
|
+
if (config.method != 'get' && config.method != 'delete') {
|
|
76
|
+
try {
|
|
77
|
+
const encryptSuffix = aesUtil.genKey(16);
|
|
78
|
+
data = {
|
|
79
|
+
data: aesUtil.encrypt(data, encryptSuffix),
|
|
80
|
+
i: requestI,
|
|
81
|
+
};
|
|
82
|
+
} catch (e) {
|
|
83
|
+
console.log(e);
|
|
84
|
+
}
|
|
85
|
+
config.data = data;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
config.headers['System-Language'] = getSystemLanguageHeaderValue();
|
|
90
|
+
|
|
91
|
+
const token = getStore('token');
|
|
92
|
+
if (token) {
|
|
93
|
+
config.headers['token-agent'] = `${token}`;
|
|
94
|
+
}
|
|
95
|
+
return config;
|
|
96
|
+
},
|
|
97
|
+
(error) => {
|
|
98
|
+
return Promise.reject(error);
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
request.interceptors.response.use(
|
|
103
|
+
(response) => {
|
|
104
|
+
if (response.config.isMock) {
|
|
105
|
+
return response.data;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const config = response.config;
|
|
109
|
+
|
|
110
|
+
let data = response.data;
|
|
111
|
+
// 统一尝试解密:若响应数据为加密字符串则解密,失败则继续使用原数据
|
|
112
|
+
try {
|
|
113
|
+
if (typeof response.data === 'string') {
|
|
114
|
+
const decryptSuffix = getObfuscationKey();
|
|
115
|
+
data = aesUtil.decrypt(response.data, decryptSuffix);
|
|
116
|
+
response.data = data;
|
|
117
|
+
} else if (typeof response.data.data === 'string' && !response.data.code) {
|
|
118
|
+
const decryptSuffix = getObfuscationKey();
|
|
119
|
+
data = aesUtil.decrypt(response.data.data, decryptSuffix);
|
|
120
|
+
response.data = data;
|
|
121
|
+
}
|
|
122
|
+
} catch (e) {
|
|
123
|
+
console.log(e);
|
|
124
|
+
}
|
|
125
|
+
if (data.code === undefined) {
|
|
126
|
+
data.responseHeaders = response.headers;
|
|
127
|
+
return data;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
switch (data.code) {
|
|
131
|
+
case 401:
|
|
132
|
+
if (!isRedirectingToLogin) {
|
|
133
|
+
isRedirectingToLogin = true;
|
|
134
|
+
removeStore('token');
|
|
135
|
+
clearObfuscationKey();
|
|
136
|
+
window.dispatchEvent(new CustomEvent('common:unauthorized'));
|
|
137
|
+
setTimeout(() => {}, 100);
|
|
138
|
+
}
|
|
139
|
+
break;
|
|
140
|
+
case 1803:
|
|
141
|
+
if (!isRedirectingToLogin) {
|
|
142
|
+
isRedirectingToLogin = true;
|
|
143
|
+
removeStore('token');
|
|
144
|
+
clearObfuscationKey();
|
|
145
|
+
window.dispatchEvent(new CustomEvent('common:unauthorized'));
|
|
146
|
+
setTimeout(() => {
|
|
147
|
+
if (!isCurrentLoginPage()) {
|
|
148
|
+
window.location.href = getLoginHref();
|
|
149
|
+
} else {
|
|
150
|
+
isRedirectingToLogin = false;
|
|
151
|
+
}
|
|
152
|
+
}, 100);
|
|
153
|
+
}
|
|
154
|
+
break;
|
|
155
|
+
case 403:
|
|
156
|
+
if (data.message !== null) {
|
|
157
|
+
showGlobalToast(data.message, 'error');
|
|
158
|
+
} else {
|
|
159
|
+
showGlobalToast('未知错误', 'error');
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case 500:
|
|
163
|
+
if (data.message !== null) {
|
|
164
|
+
showGlobalToast(data.message, 'error');
|
|
165
|
+
} else {
|
|
166
|
+
showGlobalToast('未知错误', 'error');
|
|
167
|
+
}
|
|
168
|
+
break;
|
|
169
|
+
// code 200:业务成功由调用方用 i18n/固定文案提示;此处不弹 message,避免与前端成功文案重复
|
|
170
|
+
case 200:
|
|
171
|
+
return data;
|
|
172
|
+
default:
|
|
173
|
+
if (data.message && data.message != '文件不存在') {
|
|
174
|
+
showGlobalToast(String(data.message), 'error');
|
|
175
|
+
}
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
return Promise.reject(data);
|
|
179
|
+
},
|
|
180
|
+
async (err) => {
|
|
181
|
+
if (err?.isMock && err.response) {
|
|
182
|
+
return Promise.resolve(err.response.data);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const response = err.response;
|
|
186
|
+
if (!response) {
|
|
187
|
+
if (err.message) {
|
|
188
|
+
const tempMessage = err.message.replaceAll(' ', '').toLowerCase();
|
|
189
|
+
if (tempMessage.indexOf('timeout') !== -1) {
|
|
190
|
+
showGlobalToast(i18n.t('common.request_timeout'), 'error');
|
|
191
|
+
}
|
|
192
|
+
if (tempMessage.indexOf('networkerror') !== -1) {
|
|
193
|
+
showGlobalToast(i18n.t('common.service_error'), 'error');
|
|
194
|
+
}
|
|
195
|
+
return Promise.reject(err);
|
|
196
|
+
}
|
|
197
|
+
if (err.__CANCEL__) {
|
|
198
|
+
return Promise.reject(err);
|
|
199
|
+
}
|
|
200
|
+
showGlobalToast(String(err), 'error');
|
|
201
|
+
return Promise.reject(err);
|
|
202
|
+
}
|
|
203
|
+
const url = response.config.url;
|
|
204
|
+
if (url.split('/').length > 2) {
|
|
205
|
+
showGlobalToast(i18n.t('common.service_error'), 'error');
|
|
206
|
+
return Promise.reject(err);
|
|
207
|
+
}
|
|
208
|
+
showGlobalToast(String(err), 'error');
|
|
209
|
+
return Promise.reject(err);
|
|
210
|
+
}
|
|
211
|
+
);
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* 成功时响应拦截器返回业务体,非 AxiosResponse
|
|
215
|
+
* @param {string} url
|
|
216
|
+
* @param {*} params
|
|
217
|
+
* @param {string} [baseURL]
|
|
218
|
+
* @returns {Promise<any>}
|
|
219
|
+
*/
|
|
220
|
+
export const axiosGetRequest = (url, params = {}, baseURL) => {
|
|
221
|
+
return request({
|
|
222
|
+
method: 'get',
|
|
223
|
+
url: url,
|
|
224
|
+
params: params,
|
|
225
|
+
...(baseURL && { baseURL: baseURL }),
|
|
226
|
+
headers: {
|
|
227
|
+
'Content-Type': 'application/json',
|
|
228
|
+
},
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
export const axiosPostRequest = (url, params = {}, config = {}) => {
|
|
233
|
+
const { signal, headers: extraHeaders } = config
|
|
234
|
+
return request({
|
|
235
|
+
method: 'post',
|
|
236
|
+
url: url,
|
|
237
|
+
data: params,
|
|
238
|
+
...(signal != null ? { signal } : {}),
|
|
239
|
+
headers: {
|
|
240
|
+
'Content-Type': 'application/json',
|
|
241
|
+
...(extraHeaders || {}),
|
|
242
|
+
},
|
|
243
|
+
});
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* @param {string} url
|
|
248
|
+
* @param {*} params
|
|
249
|
+
* @returns {Promise<any>}
|
|
250
|
+
*/
|
|
251
|
+
export const axiosPutRequest = (url, params) => {
|
|
252
|
+
return request({
|
|
253
|
+
method: 'put',
|
|
254
|
+
url: url,
|
|
255
|
+
data: params,
|
|
256
|
+
headers: {
|
|
257
|
+
'Content-Type': 'application/json',
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* @param {string} url
|
|
264
|
+
* @param {*} params
|
|
265
|
+
* @returns {Promise<any>}
|
|
266
|
+
*/
|
|
267
|
+
export const axiosPatchRequest = (url, params) => {
|
|
268
|
+
return request({
|
|
269
|
+
method: 'patch',
|
|
270
|
+
url: url,
|
|
271
|
+
data: params,
|
|
272
|
+
headers: {
|
|
273
|
+
'Content-Type': 'application/json',
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export const axiosDeleteRequest = (url, params = {}) => {
|
|
279
|
+
return request({
|
|
280
|
+
method: 'delete',
|
|
281
|
+
url: url,
|
|
282
|
+
params: params,
|
|
283
|
+
headers: {
|
|
284
|
+
'Content-Type': 'application/json',
|
|
285
|
+
},
|
|
286
|
+
});
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
/**
|
|
290
|
+
* @param {string} url
|
|
291
|
+
* @param {*} params
|
|
292
|
+
* @returns {Promise<any>}
|
|
293
|
+
*/
|
|
294
|
+
export const axiosPostUploadRequest = (url, params) => {
|
|
295
|
+
return request({
|
|
296
|
+
method: 'post',
|
|
297
|
+
url: url,
|
|
298
|
+
data: params,
|
|
299
|
+
headers: {
|
|
300
|
+
'Content-Type': 'multipart/form-data',
|
|
301
|
+
},
|
|
302
|
+
noEncryption: true
|
|
303
|
+
});
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* 无需token验证的请求 避免旧token过期导致请求失败
|
|
308
|
+
* @param {string} url
|
|
309
|
+
* @param {*} params
|
|
310
|
+
* @returns {Promise<any>}
|
|
311
|
+
*/
|
|
312
|
+
export const getRequestWithNoToken = (url, params) => {
|
|
313
|
+
return request({
|
|
314
|
+
method: 'get',
|
|
315
|
+
url: url,
|
|
316
|
+
params: params,
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
/** 原样导出 axios 实例,供需自定义 config(如 blob、额外 headers)的场景 */
|
|
321
|
+
export { request };
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* POST JSON 并接收二进制(如导出文件);成功时拦截器返回 Blob 等业务体
|
|
325
|
+
*/
|
|
326
|
+
export function axiosPostBlob(url, data) {
|
|
327
|
+
return request({
|
|
328
|
+
method: 'post',
|
|
329
|
+
url,
|
|
330
|
+
data,
|
|
331
|
+
responseType: 'blob',
|
|
332
|
+
headers: {
|
|
333
|
+
'Content-Type': 'application/json',
|
|
334
|
+
},
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* GET 请求并接收二进制(如导出文件);成功时拦截器返回 Blob 等业务体
|
|
340
|
+
* @param {string} url
|
|
341
|
+
* @param {Record<string, any>} [params]
|
|
342
|
+
*/
|
|
343
|
+
export function axiosGetBlob(url, params = {}) {
|
|
344
|
+
return request({
|
|
345
|
+
method: 'get',
|
|
346
|
+
url,
|
|
347
|
+
params,
|
|
348
|
+
responseType: 'blob',
|
|
349
|
+
headers: {
|
|
350
|
+
'Content-Type': 'application/json',
|
|
351
|
+
},
|
|
352
|
+
noEncryption: true,
|
|
353
|
+
});
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
export const getDownload = (url, params) => {
|
|
357
|
+
return request({
|
|
358
|
+
method: 'get',
|
|
359
|
+
url: url,
|
|
360
|
+
params: params,
|
|
361
|
+
responseType: 'blob'
|
|
362
|
+
});
|
|
363
|
+
};
|
|
364
|
+
|
|
365
|
+
export const postDownload = (url, params) => {
|
|
366
|
+
return request({
|
|
367
|
+
method: 'post',
|
|
368
|
+
url: url,
|
|
369
|
+
data: params,
|
|
370
|
+
responseType: 'blob'
|
|
371
|
+
});
|
|
372
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Axios Mock 拦截器 - 用于 http/axios.js
|
|
3
|
+
* 使用通用处理器 handleMockRequest
|
|
4
|
+
*/
|
|
5
|
+
import type { InternalAxiosRequestConfig, AxiosResponse } from 'axios'
|
|
6
|
+
import { handleMockRequest } from '../api/_mock/handler'
|
|
7
|
+
|
|
8
|
+
export { handleMockRequest }
|
|
9
|
+
export default handleMockRequest
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import aesUtil from '@utils/aesUtil'
|
|
2
|
+
|
|
3
|
+
/** 与普通 localStorage 键隔离,且不经过 setStore 的二次加密,避免无意义嵌套 */
|
|
4
|
+
const SESSION_KEY = 'apps-agent-req-obfuscation-i'
|
|
5
|
+
|
|
6
|
+
let memoryKey: string | null = null
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 请求体迷惑字段(如 body.i):每标签页生成一次后复用,避免拦截器里直接 genKey()。
|
|
10
|
+
*/
|
|
11
|
+
export function getObfuscationKey(): string {
|
|
12
|
+
if (memoryKey) {
|
|
13
|
+
return memoryKey
|
|
14
|
+
}
|
|
15
|
+
try {
|
|
16
|
+
const saved = sessionStorage.getItem(SESSION_KEY)
|
|
17
|
+
if (saved) {
|
|
18
|
+
memoryKey = saved
|
|
19
|
+
return memoryKey
|
|
20
|
+
}
|
|
21
|
+
} catch {
|
|
22
|
+
// 隐私模式等
|
|
23
|
+
}
|
|
24
|
+
memoryKey = aesUtil.genKey()
|
|
25
|
+
try {
|
|
26
|
+
sessionStorage.setItem(SESSION_KEY, memoryKey)
|
|
27
|
+
} catch {
|
|
28
|
+
// 仅内存持有
|
|
29
|
+
}
|
|
30
|
+
return memoryKey
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 登出或清会话时调用,下次请求会重新生成 */
|
|
34
|
+
export function clearObfuscationKey(): void {
|
|
35
|
+
memoryKey = null
|
|
36
|
+
try {
|
|
37
|
+
sessionStorage.removeItem(SESSION_KEY)
|
|
38
|
+
} catch {
|
|
39
|
+
/* empty */
|
|
40
|
+
}
|
|
41
|
+
}
|