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,62 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, useEffect } from 'react'
|
|
2
|
+
import { getUserMenuListAPI } from '@api/common/auth'
|
|
3
|
+
import type { MenuTreeItem } from '@/types/menu'
|
|
4
|
+
import { syncMenuTreeToI18n } from '@utils/menuI18n'
|
|
5
|
+
import { useAuth } from './AuthContext'
|
|
6
|
+
|
|
7
|
+
interface MenuContextType {
|
|
8
|
+
menus: MenuTreeItem[]
|
|
9
|
+
isLoading: boolean
|
|
10
|
+
error: Error | null
|
|
11
|
+
refreshMenus: () => Promise<void>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const MenuContext = createContext<MenuContextType | undefined>(undefined)
|
|
15
|
+
|
|
16
|
+
export const MenuProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
17
|
+
const [menus, setMenus] = useState<MenuTreeItem[]>([])
|
|
18
|
+
const [isLoading, setIsLoading] = useState(true)
|
|
19
|
+
const [error, setError] = useState<Error | null>(null)
|
|
20
|
+
const { isAuthenticated } = useAuth()
|
|
21
|
+
|
|
22
|
+
const fetchMenus = async () => {
|
|
23
|
+
try {
|
|
24
|
+
setIsLoading(true)
|
|
25
|
+
setError(null)
|
|
26
|
+
const result = await getUserMenuListAPI({})
|
|
27
|
+
const menuData = result.success && result.data ? result.data : []
|
|
28
|
+
const roots = Array.isArray(menuData) ? menuData : []
|
|
29
|
+
syncMenuTreeToI18n(roots)
|
|
30
|
+
setMenus(roots)
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error('获取菜单失败:', err)
|
|
33
|
+
setError(err instanceof Error ? err : new Error('未知错误'))
|
|
34
|
+
} finally {
|
|
35
|
+
setIsLoading(false)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (!isAuthenticated) {
|
|
41
|
+
setMenus([])
|
|
42
|
+
setIsLoading(false)
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
fetchMenus()
|
|
46
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- 登录态变化时重新拉取菜单
|
|
47
|
+
}, [isAuthenticated])
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<MenuContext.Provider value={{ menus, isLoading, error, refreshMenus: fetchMenus }}>
|
|
51
|
+
{children}
|
|
52
|
+
</MenuContext.Provider>
|
|
53
|
+
)
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export const useMenu = () => {
|
|
57
|
+
const context = useContext(MenuContext)
|
|
58
|
+
if (!context) {
|
|
59
|
+
throw new Error('useMenu 必须在 MenuProvider 内使用')
|
|
60
|
+
}
|
|
61
|
+
return context
|
|
62
|
+
}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
createContext,
|
|
3
|
+
useContext,
|
|
4
|
+
useState,
|
|
5
|
+
useCallback,
|
|
6
|
+
useEffect,
|
|
7
|
+
useRef,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { bindGlobalToast } from '@/utils/toastBridge';
|
|
10
|
+
import { X, CheckCircle, AlertCircle, Info, AlertTriangle } from 'lucide-react';
|
|
11
|
+
import clsx from 'clsx';
|
|
12
|
+
|
|
13
|
+
export type ToastType = 'success' | 'error' | 'info' | 'warning';
|
|
14
|
+
|
|
15
|
+
export interface Toast {
|
|
16
|
+
id: string;
|
|
17
|
+
type: ToastType;
|
|
18
|
+
message: string;
|
|
19
|
+
duration?: number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
interface ToastContextType {
|
|
23
|
+
showToast: (message: string, type: ToastType, duration?: number) => void;
|
|
24
|
+
removeToast: (id: string) => void;
|
|
25
|
+
/** 清空当前所有 Toast(如登录/注册跳转前关闭提示) */
|
|
26
|
+
clearToasts: () => void;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const ToastContext = createContext<ToastContextType | undefined>(undefined);
|
|
30
|
+
|
|
31
|
+
export const useToast = () => {
|
|
32
|
+
const context = useContext(ToastContext);
|
|
33
|
+
if (!context) {
|
|
34
|
+
throw new Error('useToast 必须在 ToastProvider 内使用');
|
|
35
|
+
}
|
|
36
|
+
return context;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
interface ToastProviderProps {
|
|
40
|
+
children: React.ReactNode;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export const ToastProvider: React.FC<ToastProviderProps> = ({ children }) => {
|
|
44
|
+
const [toasts, setToasts] = useState<Toast[]>([]);
|
|
45
|
+
|
|
46
|
+
const removeToast = useCallback((id: string) => {
|
|
47
|
+
setToasts((prev) => prev.filter((toast) => toast.id !== id));
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
const clearToasts = useCallback(() => {
|
|
51
|
+
setToasts([]);
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
const showToast = useCallback((message: string, type: ToastType, duration?: number) => {
|
|
55
|
+
const id = Math.random().toString(36).substring(2, 9);
|
|
56
|
+
const autoCloseDuration = duration || (type === 'error' ? 10000 : 3000); // 错误 10 秒,其他 3 秒
|
|
57
|
+
|
|
58
|
+
// 每次只保留最新一条,避免堆叠多个 Toast
|
|
59
|
+
setToasts([{ id, type, message, duration: autoCloseDuration }]);
|
|
60
|
+
}, []);
|
|
61
|
+
|
|
62
|
+
useEffect(() => {
|
|
63
|
+
bindGlobalToast(showToast);
|
|
64
|
+
return () => {
|
|
65
|
+
bindGlobalToast(null);
|
|
66
|
+
};
|
|
67
|
+
}, [showToast]);
|
|
68
|
+
|
|
69
|
+
return (
|
|
70
|
+
<ToastContext.Provider value={{ showToast, removeToast, clearToasts }}>
|
|
71
|
+
{children}
|
|
72
|
+
<div className="fixed top-4 right-4 z-[9999] flex flex-col gap-2 max-w-md w-full pointer-events-none">
|
|
73
|
+
{toasts.map((toast) => (
|
|
74
|
+
<ToastItem key={toast.id} toast={toast} onDismiss={removeToast} />
|
|
75
|
+
))}
|
|
76
|
+
</div>
|
|
77
|
+
</ToastContext.Provider>
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const ToastItem: React.FC<{ toast: Toast; onDismiss: (id: string) => void }> = ({ toast, onDismiss }) => {
|
|
82
|
+
const iconMap = {
|
|
83
|
+
success: <CheckCircle size={20} className="text-green-500" />,
|
|
84
|
+
error: <AlertCircle size={20} className="text-red-500" />,
|
|
85
|
+
info: <Info size={20} className="text-blue-500" />,
|
|
86
|
+
warning: <AlertTriangle size={20} className="text-yellow-500" />,
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
const bgMap = {
|
|
90
|
+
success: 'bg-white border-green-100 dark:bg-gray-800 dark:border-green-900',
|
|
91
|
+
error: 'bg-white border-red-100 dark:bg-gray-800 dark:border-red-900',
|
|
92
|
+
info: 'bg-white border-blue-100 dark:bg-gray-800 dark:border-blue-900',
|
|
93
|
+
warning: 'bg-white border-yellow-100 dark:bg-gray-800 dark:border-yellow-900',
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const progressColorMap = {
|
|
97
|
+
success: 'bg-green-500',
|
|
98
|
+
error: 'bg-red-500',
|
|
99
|
+
info: 'bg-blue-500',
|
|
100
|
+
warning: 'bg-yellow-500',
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
const durationMs =
|
|
104
|
+
toast.duration != null && toast.duration > 0 ? toast.duration : 0;
|
|
105
|
+
|
|
106
|
+
const [progressPct, setProgressPct] = useState(0);
|
|
107
|
+
const startTimeRef = useRef(Date.now());
|
|
108
|
+
const pausedRef = useRef(false);
|
|
109
|
+
const frozenElapsedRef = useRef(0);
|
|
110
|
+
const rafRef = useRef<number>(0);
|
|
111
|
+
const tickRef = useRef<() => void>(() => {});
|
|
112
|
+
|
|
113
|
+
useEffect(() => {
|
|
114
|
+
if (!durationMs) return;
|
|
115
|
+
|
|
116
|
+
const tick = () => {
|
|
117
|
+
if (pausedRef.current) {
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
const elapsed = Date.now() - startTimeRef.current;
|
|
121
|
+
const pct = Math.min(100, (elapsed / durationMs) * 100);
|
|
122
|
+
setProgressPct(pct);
|
|
123
|
+
if (elapsed >= durationMs) {
|
|
124
|
+
onDismiss(toast.id);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
rafRef.current = requestAnimationFrame(tick);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
tickRef.current = tick;
|
|
131
|
+
rafRef.current = requestAnimationFrame(tick);
|
|
132
|
+
return () => cancelAnimationFrame(rafRef.current);
|
|
133
|
+
}, [durationMs, toast.id, onDismiss]);
|
|
134
|
+
|
|
135
|
+
const handlePointerEnter = () => {
|
|
136
|
+
if (!durationMs) return;
|
|
137
|
+
pausedRef.current = true;
|
|
138
|
+
frozenElapsedRef.current = Date.now() - startTimeRef.current;
|
|
139
|
+
cancelAnimationFrame(rafRef.current);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const handlePointerLeave = () => {
|
|
143
|
+
if (!durationMs) return;
|
|
144
|
+
startTimeRef.current = Date.now() - frozenElapsedRef.current;
|
|
145
|
+
pausedRef.current = false;
|
|
146
|
+
rafRef.current = requestAnimationFrame(tickRef.current);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
return (
|
|
150
|
+
<div
|
|
151
|
+
className={clsx(
|
|
152
|
+
"pointer-events-auto relative overflow-hidden flex items-start gap-3 p-4 rounded-lg shadow-lg border transition-all duration-300 animate-in slide-in-from-right-full",
|
|
153
|
+
bgMap[toast.type]
|
|
154
|
+
)}
|
|
155
|
+
role="alert"
|
|
156
|
+
onPointerEnter={handlePointerEnter}
|
|
157
|
+
onPointerLeave={handlePointerLeave}
|
|
158
|
+
>
|
|
159
|
+
<div className="shrink-0 mt-0.5">{iconMap[toast.type]}</div>
|
|
160
|
+
<div className="flex-1 text-sm font-medium text-gray-900 dark:text-gray-100 break-words z-10">
|
|
161
|
+
{toast.message}
|
|
162
|
+
</div>
|
|
163
|
+
<button
|
|
164
|
+
onClick={() => onDismiss(toast.id)}
|
|
165
|
+
className="shrink-0 text-gray-400 hover:text-gray-600 dark:hover:text-gray-200 transition-colors z-10"
|
|
166
|
+
>
|
|
167
|
+
<X size={18} />
|
|
168
|
+
</button>
|
|
169
|
+
|
|
170
|
+
{/* 进度条(与自动关闭同源计时;悬停时暂停) */}
|
|
171
|
+
{durationMs > 0 && (
|
|
172
|
+
<div
|
|
173
|
+
className={clsx("absolute bottom-0 left-0 h-0.5 opacity-50", progressColorMap[toast.type])}
|
|
174
|
+
style={{ width: `${progressPct}%` }}
|
|
175
|
+
/>
|
|
176
|
+
)}
|
|
177
|
+
</div>
|
|
178
|
+
);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
export default ToastProvider;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
import { useToast } from '@/contexts/ToastContext'
|
|
3
|
+
import { copyToClipboard } from '@/utils'
|
|
4
|
+
import i18n from '@/i18n'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 复制文本到剪贴板并显示 Toast 提示
|
|
8
|
+
* @param successMessage 成功提示文案(i18n key)
|
|
9
|
+
* @param errorMessage 失败提示文案(i18n key)
|
|
10
|
+
*/
|
|
11
|
+
export function useCopyToClipboard(
|
|
12
|
+
successMessage = 'common.copy_success',
|
|
13
|
+
errorMessage = 'common.copy_failed',
|
|
14
|
+
) {
|
|
15
|
+
const { showToast } = useToast()
|
|
16
|
+
const [isCopying, setIsCopying] = useState(false)
|
|
17
|
+
|
|
18
|
+
const handleCopy = useCallback(
|
|
19
|
+
async (text: string) => {
|
|
20
|
+
if (!text) return false
|
|
21
|
+
|
|
22
|
+
setIsCopying(true)
|
|
23
|
+
try {
|
|
24
|
+
const success = await copyToClipboard(text)
|
|
25
|
+
if (success) {
|
|
26
|
+
showToast(i18n.t(successMessage), 'success')
|
|
27
|
+
return true
|
|
28
|
+
} else {
|
|
29
|
+
showToast(i18n.t(errorMessage), 'error')
|
|
30
|
+
return false
|
|
31
|
+
}
|
|
32
|
+
} catch (err) {
|
|
33
|
+
console.error('Copy failed:', err)
|
|
34
|
+
showToast(i18n.t(errorMessage), 'error')
|
|
35
|
+
return false
|
|
36
|
+
} finally {
|
|
37
|
+
setIsCopying(false)
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
[showToast, successMessage, errorMessage],
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
return {
|
|
44
|
+
copy: handleCopy,
|
|
45
|
+
isCopying,
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { useToast } from '@/contexts/ToastContext'
|
|
2
|
+
import { useState } from 'react'
|
|
3
|
+
|
|
4
|
+
type SubmitMode = string
|
|
5
|
+
|
|
6
|
+
type SubmitApiMap<TPayload, TResult = unknown> = {
|
|
7
|
+
add: (payload: TPayload) => Promise<TResult>
|
|
8
|
+
edit: (payload: TPayload) => Promise<TResult>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** 未传 successMessage 时按 opeType 提示;其余为「操作成功」 */
|
|
12
|
+
function defaultSuccessToastByOpeType(opeType: SubmitMode): string {
|
|
13
|
+
const key = String(opeType ?? '')
|
|
14
|
+
.trim()
|
|
15
|
+
.toLowerCase()
|
|
16
|
+
if (key === 'enable') return '操作成功,已启用'
|
|
17
|
+
if (key === 'disable') return '操作成功,已禁用'
|
|
18
|
+
if (key === 'approve' || key === 'pass' || key === 'approved') return '操作成功,已通过'
|
|
19
|
+
if (key === 'reject' || key === 'rejected' || key === 'refuse') return '操作成功,已拒绝'
|
|
20
|
+
if (key === 'delete') return '操作成功,已删除'
|
|
21
|
+
return '操作成功'
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function resolveSuccessToastText(
|
|
25
|
+
mode: SubmitMode,
|
|
26
|
+
successMessage: { add?: string; edit?: string } | undefined,
|
|
27
|
+
): string {
|
|
28
|
+
const fromOption = mode === 'edit' ? successMessage?.edit : successMessage?.add
|
|
29
|
+
if (typeof fromOption === 'string' && fromOption.trim()) return fromOption.trim()
|
|
30
|
+
return defaultSuccessToastByOpeType(mode)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
type UseModalSubmitOptions<TFormValues, TPayload, TResult = unknown> = {
|
|
34
|
+
opeType: SubmitMode
|
|
35
|
+
validate: () => Promise<TFormValues>
|
|
36
|
+
addAPI?: SubmitApiMap<TPayload, TResult>['add']
|
|
37
|
+
editAPI?: SubmitApiMap<TPayload, TResult>['edit']
|
|
38
|
+
transform?: (values: TFormValues) => TPayload
|
|
39
|
+
successMessage?: {
|
|
40
|
+
add?: string
|
|
41
|
+
edit?: string
|
|
42
|
+
}
|
|
43
|
+
onSuccess?: (ctx: {
|
|
44
|
+
values: TFormValues
|
|
45
|
+
payload: TPayload
|
|
46
|
+
result: TResult
|
|
47
|
+
opeType: SubmitMode
|
|
48
|
+
}) => void | Promise<void>
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function useModalSubmit<TFormValues = any, TPayload = any, TResult = unknown>() {
|
|
52
|
+
const [submitting, setSubmitting] = useState(false)
|
|
53
|
+
const { showToast } = useToast()
|
|
54
|
+
|
|
55
|
+
const handleSubmit = async (options: UseModalSubmitOptions<TFormValues, TPayload, TResult>) => {
|
|
56
|
+
const {
|
|
57
|
+
opeType,
|
|
58
|
+
validate,
|
|
59
|
+
addAPI,
|
|
60
|
+
editAPI,
|
|
61
|
+
transform,
|
|
62
|
+
successMessage,
|
|
63
|
+
onSuccess,
|
|
64
|
+
} = options
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const values = await validate()
|
|
68
|
+
setSubmitting(true)
|
|
69
|
+
|
|
70
|
+
const payload = transform ? transform(values) : (values as unknown as TPayload)
|
|
71
|
+
let result: TResult
|
|
72
|
+
|
|
73
|
+
if (opeType === 'edit') {
|
|
74
|
+
if (!editAPI) {
|
|
75
|
+
throw new Error('未配置编辑接口')
|
|
76
|
+
}
|
|
77
|
+
result = await editAPI(payload)
|
|
78
|
+
} else {
|
|
79
|
+
if (!addAPI) {
|
|
80
|
+
throw new Error('未配置新增接口')
|
|
81
|
+
}
|
|
82
|
+
result = await addAPI(payload)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
const toastText = resolveSuccessToastText(opeType, successMessage)
|
|
86
|
+
showToast(toastText, 'success')
|
|
87
|
+
|
|
88
|
+
await onSuccess?.({ values, payload, result, opeType })
|
|
89
|
+
return { values, payload, result }
|
|
90
|
+
} catch (error: any) {
|
|
91
|
+
if (error?.errorFields) return null
|
|
92
|
+
showToast(error?.message || '操作失败', 'error')
|
|
93
|
+
return null
|
|
94
|
+
} finally {
|
|
95
|
+
setSubmitting(false)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
return {
|
|
100
|
+
submitting,
|
|
101
|
+
handleSubmit,
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 路由跳转 Hook
|
|
3
|
+
* 基于 menuRouteRegistry 实现智能路由跳转
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
getListPathByMenuCode,
|
|
8
|
+
getRegisteredMenuRouteEntries,
|
|
9
|
+
} from '@/utils/menuRouteRegistry'
|
|
10
|
+
import { useLocation, useNavigate } from 'react-router-dom'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* 根据当前路径提取基础路径(去掉 /index、/detail/*、/submit/*)
|
|
14
|
+
*/
|
|
15
|
+
function extractBasePath(pathname: string): string {
|
|
16
|
+
return pathname.replace(/\/(index|detail|submit)(\/.*)?$/, '')
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 路由跳转 Hook
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```tsx
|
|
24
|
+
* const router = useRouter()
|
|
25
|
+
*
|
|
26
|
+
* // 跳转到列表页
|
|
27
|
+
* router.toIndex()
|
|
28
|
+
* router.toIndex({ menuCode: 'permission' })
|
|
29
|
+
*
|
|
30
|
+
* // 跳转到新增页
|
|
31
|
+
* router.toAdd()
|
|
32
|
+
* router.toAdd({ state: { defaultType: 1 } })
|
|
33
|
+
*
|
|
34
|
+
* // 跳转到编辑页
|
|
35
|
+
* router.toEdit({ state: { editId: 123 } })
|
|
36
|
+
*
|
|
37
|
+
* // 跳转到详情页
|
|
38
|
+
* router.toDetail(123)
|
|
39
|
+
* router.toDetail(123, { state: { name: 'test' } })
|
|
40
|
+
*
|
|
41
|
+
* // 按菜单 code 跳转
|
|
42
|
+
* router.toMenu('permission', { type: 'index' })
|
|
43
|
+
* router.toMenu('knowledge', { type: 'detail', id: 123 })
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
export function useRouter() {
|
|
47
|
+
const navigate = useNavigate()
|
|
48
|
+
const location = useLocation()
|
|
49
|
+
|
|
50
|
+
const resolveSubmitBasePath = (options?: {
|
|
51
|
+
menuCode?: string
|
|
52
|
+
currentPath?: string
|
|
53
|
+
}): string | undefined => {
|
|
54
|
+
let basePath: string | undefined
|
|
55
|
+
const currentPath = options?.currentPath || location.pathname
|
|
56
|
+
|
|
57
|
+
if (options?.menuCode) {
|
|
58
|
+
const listPath = getListPathByMenuCode(options.menuCode)
|
|
59
|
+
if (listPath) {
|
|
60
|
+
basePath = extractBasePath(listPath)
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (!basePath) {
|
|
65
|
+
basePath = extractBasePath(currentPath)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return basePath
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 跳转到列表页
|
|
73
|
+
*/
|
|
74
|
+
const toIndex = (options?: {
|
|
75
|
+
/** 菜单 code,优先使用。不传则根据当前路径自动推断 */
|
|
76
|
+
menuCode?: string
|
|
77
|
+
/** 当前路径,用于自动推断。默认为当前页面路径 */
|
|
78
|
+
currentPath?: string
|
|
79
|
+
/** 额外的 state 参数 */
|
|
80
|
+
state?: any
|
|
81
|
+
}): void => {
|
|
82
|
+
let targetPath: string | undefined
|
|
83
|
+
const currentPath = options?.currentPath || location.pathname
|
|
84
|
+
|
|
85
|
+
// 优先使用 menuCode
|
|
86
|
+
if (options?.menuCode) {
|
|
87
|
+
targetPath = getListPathByMenuCode(options.menuCode)
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// 其次根据当前路径推断
|
|
91
|
+
if (!targetPath) {
|
|
92
|
+
const basePath = extractBasePath(currentPath)
|
|
93
|
+
const entries = getRegisteredMenuRouteEntries()
|
|
94
|
+
const matched = entries.find((entry) => {
|
|
95
|
+
const entryBasePath = `/${entry.basePath.replace(/^\/+|\/+$/g, '')}`
|
|
96
|
+
return entryBasePath === basePath
|
|
97
|
+
})
|
|
98
|
+
if (matched) {
|
|
99
|
+
targetPath = matched.listPath
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
if (targetPath) {
|
|
104
|
+
navigate(targetPath, { state: options?.state })
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* 跳转到新增页
|
|
110
|
+
*/
|
|
111
|
+
const toAdd = (options?: {
|
|
112
|
+
/** 菜单 code,优先使用。不传则根据当前路径自动推断 */
|
|
113
|
+
menuCode?: string
|
|
114
|
+
/** 当前路径,用于自动推断。默认为当前页面路径 */
|
|
115
|
+
currentPath?: string
|
|
116
|
+
/** 额外的 state 参数 */
|
|
117
|
+
state?: any
|
|
118
|
+
}): void => {
|
|
119
|
+
const basePath = resolveSubmitBasePath(options)
|
|
120
|
+
|
|
121
|
+
if (basePath) {
|
|
122
|
+
navigate(`${basePath}/submit`, { state: options?.state })
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* 跳转到编辑页(submit 路由,路径带 id,与 generateAdminRoutes 注册的 `submit/:id` 一致)
|
|
128
|
+
*/
|
|
129
|
+
const toEdit = (options?: {
|
|
130
|
+
/** 菜单 code,优先使用。不传则根据当前路径自动推断 */
|
|
131
|
+
menuCode?: string
|
|
132
|
+
/** 当前路径,用于自动推断。默认为当前页面路径 */
|
|
133
|
+
currentPath?: string
|
|
134
|
+
/** 须含 `editId`,将写入 URL:`.../submit/:id` */
|
|
135
|
+
state?: any
|
|
136
|
+
}): void => {
|
|
137
|
+
const basePath = resolveSubmitBasePath(options)
|
|
138
|
+
if (!basePath) return
|
|
139
|
+
|
|
140
|
+
const editId = options?.state?.editId
|
|
141
|
+
const idStr = editId != null && String(editId).trim() !== '' ? String(editId) : ''
|
|
142
|
+
|
|
143
|
+
if (idStr) {
|
|
144
|
+
navigate(`${basePath}/submit/${encodeURIComponent(idStr)}`, {
|
|
145
|
+
state: options?.state,
|
|
146
|
+
})
|
|
147
|
+
} else {
|
|
148
|
+
navigate(`${basePath}/submit`, { state: options?.state })
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 跳转到详情页
|
|
154
|
+
*/
|
|
155
|
+
const toDetail = (
|
|
156
|
+
id: string | number,
|
|
157
|
+
options?: {
|
|
158
|
+
/** 菜单 code,优先使用。不传则根据当前路径自动推断 */
|
|
159
|
+
menuCode?: string
|
|
160
|
+
/** 当前路径,用于自动推断。默认为当前页面路径 */
|
|
161
|
+
currentPath?: string
|
|
162
|
+
/** 额外的 state 参数 */
|
|
163
|
+
state?: any
|
|
164
|
+
},
|
|
165
|
+
): void => {
|
|
166
|
+
let basePath: string | undefined
|
|
167
|
+
const currentPath = options?.currentPath || location.pathname
|
|
168
|
+
|
|
169
|
+
// 优先使用 menuCode
|
|
170
|
+
if (options?.menuCode) {
|
|
171
|
+
const listPath = getListPathByMenuCode(options.menuCode)
|
|
172
|
+
if (listPath) {
|
|
173
|
+
basePath = extractBasePath(listPath)
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// 其次根据当前路径推断
|
|
178
|
+
if (!basePath) {
|
|
179
|
+
basePath = extractBasePath(currentPath)
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
if (basePath) {
|
|
183
|
+
navigate(`${basePath}/detail/${encodeURIComponent(String(id))}`, {
|
|
184
|
+
state: options?.state,
|
|
185
|
+
})
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* 跳转到指定菜单 code 对应的页面
|
|
191
|
+
*/
|
|
192
|
+
const toMenu = (
|
|
193
|
+
menuCode: string,
|
|
194
|
+
options?: {
|
|
195
|
+
/** 目标类型:index | add | detail */
|
|
196
|
+
type?: 'index' | 'add' | 'detail'
|
|
197
|
+
/** 详情 ID(type 为 detail 时需要) */
|
|
198
|
+
id?: string | number
|
|
199
|
+
/** 额外的 state 参数 */
|
|
200
|
+
state?: any
|
|
201
|
+
},
|
|
202
|
+
): void => {
|
|
203
|
+
const listPath = getListPathByMenuCode(menuCode)
|
|
204
|
+
if (!listPath) {
|
|
205
|
+
console.warn(`未找到菜单 code "${menuCode}" 对应的路由`)
|
|
206
|
+
return
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const basePath = extractBasePath(listPath)
|
|
210
|
+
const type = options?.type || 'index'
|
|
211
|
+
|
|
212
|
+
let targetPath: string
|
|
213
|
+
switch (type) {
|
|
214
|
+
case 'add':
|
|
215
|
+
targetPath = `${basePath}/submit`
|
|
216
|
+
break
|
|
217
|
+
case 'detail':
|
|
218
|
+
if (!options?.id) {
|
|
219
|
+
console.warn('跳转到详情页需要提供 id 参数')
|
|
220
|
+
return
|
|
221
|
+
}
|
|
222
|
+
targetPath = `${basePath}/detail/${encodeURIComponent(String(options.id))}`
|
|
223
|
+
break
|
|
224
|
+
case 'index':
|
|
225
|
+
default:
|
|
226
|
+
targetPath = listPath
|
|
227
|
+
break
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
navigate(targetPath, { state: options?.state })
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
return {
|
|
234
|
+
toIndex,
|
|
235
|
+
toAdd,
|
|
236
|
+
toEdit,
|
|
237
|
+
toDetail,
|
|
238
|
+
toMenu,
|
|
239
|
+
}
|
|
240
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 分步表单通用Hook
|
|
5
|
+
* 管理步骤状态、连接测试状态等通用逻辑
|
|
6
|
+
*/
|
|
7
|
+
export function useStepForm() {
|
|
8
|
+
const [current, setCurrent] = useState(0)
|
|
9
|
+
const [connectionTested, setConnectionTested] = useState(false)
|
|
10
|
+
const [testingConnection, setTestingConnection] = useState(false)
|
|
11
|
+
|
|
12
|
+
/** 下一步 */
|
|
13
|
+
const next = useCallback(() => {
|
|
14
|
+
setCurrent((prev) => prev + 1)
|
|
15
|
+
}, [])
|
|
16
|
+
|
|
17
|
+
/** 上一步 */
|
|
18
|
+
const prev = useCallback(() => {
|
|
19
|
+
setCurrent((prev) => prev - 1)
|
|
20
|
+
}, [])
|
|
21
|
+
|
|
22
|
+
/** 重置到指定步骤 */
|
|
23
|
+
const resetTo = useCallback((step: number) => {
|
|
24
|
+
setCurrent(step)
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
/** 重置所有状态 */
|
|
28
|
+
const reset = useCallback(() => {
|
|
29
|
+
setCurrent(0)
|
|
30
|
+
setConnectionTested(false)
|
|
31
|
+
setTestingConnection(false)
|
|
32
|
+
}, [])
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
current,
|
|
36
|
+
setCurrent,
|
|
37
|
+
connectionTested,
|
|
38
|
+
setConnectionTested,
|
|
39
|
+
testingConnection,
|
|
40
|
+
setTestingConnection,
|
|
41
|
+
next,
|
|
42
|
+
prev,
|
|
43
|
+
resetTo,
|
|
44
|
+
reset,
|
|
45
|
+
}
|
|
46
|
+
}
|