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,132 @@
|
|
|
1
|
+
import ListPageView, { createListPageConfig } from '@components/table-view'
|
|
2
|
+
import type { ColumnsType } from 'antd/es/table'
|
|
3
|
+
import dayjs from 'dayjs'
|
|
4
|
+
import { useMemo } from 'react'
|
|
5
|
+
import { useTranslation } from 'react-i18next'
|
|
6
|
+
|
|
7
|
+
import { getSysLogPageAPI } from '@/api/system/sys-log'
|
|
8
|
+
import { DetailLink } from '@/components/common/detail-link'
|
|
9
|
+
import { ALIGN } from '@/meta'
|
|
10
|
+
// import { LogMessageDemo } from './components'
|
|
11
|
+
import { CxDamo } from 'cx-my-react-lib'
|
|
12
|
+
import DetailModal from './modal/detail-modal'
|
|
13
|
+
|
|
14
|
+
const useListPageConfig = createListPageConfig({
|
|
15
|
+
tableAPI: getSysLogPageAPI,
|
|
16
|
+
pageInfo: {
|
|
17
|
+
title: 'system.sys_log.title',
|
|
18
|
+
subTitle: 'system.sys_log.subtitle',
|
|
19
|
+
},
|
|
20
|
+
initialSearchFormData: {
|
|
21
|
+
startTimeRange: [dayjs().subtract(1, 'hour'), dayjs()],
|
|
22
|
+
},
|
|
23
|
+
searchFields: [
|
|
24
|
+
{
|
|
25
|
+
prop: 'param',
|
|
26
|
+
label: 'system.sys_log.search.keyword_label',
|
|
27
|
+
placeholder: 'system.sys_log.search.keyword_placeholder',
|
|
28
|
+
width: '300px',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
prop: 'startTimeRange',
|
|
32
|
+
label: 'system.sys_log.fields.startTime',
|
|
33
|
+
placeholder: [
|
|
34
|
+
'system.sys_log.search.startTime_placeholder_start',
|
|
35
|
+
'system.sys_log.search.startTime_placeholder_end',
|
|
36
|
+
],
|
|
37
|
+
type: 'dateRange',
|
|
38
|
+
showTime: true,
|
|
39
|
+
clearable: false,
|
|
40
|
+
rangeStartProp: 'startTime',
|
|
41
|
+
rangeEndProp: 'endTime',
|
|
42
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
43
|
+
width: '50px',
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
detailAction: {
|
|
47
|
+
detailType: 'modal',
|
|
48
|
+
labelKey: 'system.sys_log.actions.detail',
|
|
49
|
+
},
|
|
50
|
+
table: {
|
|
51
|
+
showSelection: false,
|
|
52
|
+
operationWidth: 90,
|
|
53
|
+
paginationMode: 'slice',
|
|
54
|
+
},
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
function IndexView() {
|
|
58
|
+
const { t } = useTranslation()
|
|
59
|
+
const pageConfig = useListPageConfig()
|
|
60
|
+
|
|
61
|
+
const columns = useMemo<ColumnsType<any>>(
|
|
62
|
+
() => [
|
|
63
|
+
{
|
|
64
|
+
title: 'system.sys_log.fields.url',
|
|
65
|
+
key: 'url',
|
|
66
|
+
align: ALIGN.LEFT,
|
|
67
|
+
render: (url: any, record: any) => (
|
|
68
|
+
<DetailLink
|
|
69
|
+
text={url ?? '-'}
|
|
70
|
+
title={t('system.sys_log.actions.detail')}
|
|
71
|
+
onClick={() =>
|
|
72
|
+
pageConfig.onDetail?.({
|
|
73
|
+
type: 'detail',
|
|
74
|
+
data: record,
|
|
75
|
+
config: pageConfig.detailAction,
|
|
76
|
+
})
|
|
77
|
+
}
|
|
78
|
+
/>
|
|
79
|
+
),
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
title: 'system.sys_log.fields.interfaceName',
|
|
83
|
+
key: 'interfaceName',
|
|
84
|
+
align: ALIGN.CENTER,
|
|
85
|
+
render: (v: any) => v ?? '-',
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
{
|
|
89
|
+
title: 'system.sys_log.fields.startTime',
|
|
90
|
+
key: 'startTime',
|
|
91
|
+
align: ALIGN.CENTER,
|
|
92
|
+
render: (v: any) => v ?? '-',
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
title: 'system.sys_log.fields.clientIp',
|
|
96
|
+
key: 'clientIp',
|
|
97
|
+
align: ALIGN.CENTER,
|
|
98
|
+
render: (v: any) => v ?? '-',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
title: 'system.sys_log.fields.cost',
|
|
102
|
+
key: 'cost',
|
|
103
|
+
align: ALIGN.CENTER,
|
|
104
|
+
render: (v: any) => v ?? '-',
|
|
105
|
+
},
|
|
106
|
+
|
|
107
|
+
{
|
|
108
|
+
title: 'system.sys_log.fields.userName',
|
|
109
|
+
key: 'userName',
|
|
110
|
+
align: ALIGN.CENTER,
|
|
111
|
+
render: (v: any) => v ?? '-',
|
|
112
|
+
},
|
|
113
|
+
|
|
114
|
+
],
|
|
115
|
+
[pageConfig, t],
|
|
116
|
+
)
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<>
|
|
120
|
+
<ListPageView
|
|
121
|
+
columns={columns}
|
|
122
|
+
pageConfig={pageConfig}
|
|
123
|
+
detailModalComponent={DetailModal as any}
|
|
124
|
+
/>
|
|
125
|
+
{/* <LogMessageDemo /> */}
|
|
126
|
+
<CxDamo />
|
|
127
|
+
</>
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export default IndexView
|
|
132
|
+
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
import { getSysLogDetailAPI } from '@/api/system/sys-log'
|
|
2
|
+
import { CxModal } from '@cx-ui'
|
|
3
|
+
import { Descriptions, Spin } from 'antd'
|
|
4
|
+
import { forwardRef, useImperativeHandle, useState } from 'react'
|
|
5
|
+
import { useTranslation } from 'react-i18next'
|
|
6
|
+
|
|
7
|
+
function normalizeSysLogDetail(raw: any): Record<string, unknown> {
|
|
8
|
+
if (raw?.data?.data) return raw.data.data as Record<string, unknown>
|
|
9
|
+
if (raw?.data) return raw.data as Record<string, unknown>
|
|
10
|
+
return (raw && typeof raw === 'object' ? raw : {}) as Record<string, unknown>
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
const DetailModal = forwardRef(function DetailModal(_props: unknown, ref) {
|
|
14
|
+
const { t } = useTranslation()
|
|
15
|
+
const [open, setOpen] = useState(false)
|
|
16
|
+
const [loading, setLoading] = useState(false)
|
|
17
|
+
const [detail, setDetail] = useState<Record<string, unknown>>({})
|
|
18
|
+
|
|
19
|
+
/** 将字段值格式化为可展示的字符串(空值统一显示 '-')。 */
|
|
20
|
+
const formatValue = (v: unknown) => {
|
|
21
|
+
if (v === undefined || v === null || String(v) === '') return '-'
|
|
22
|
+
return String(v)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** 长文本字段展示:支持换行、自动换行与滚动。 */
|
|
26
|
+
const renderLongText = (v: unknown, maxHeightClassName = 'max-h-64') => {
|
|
27
|
+
const text = formatValue(v)
|
|
28
|
+
if (text === '-') return '-'
|
|
29
|
+
return (
|
|
30
|
+
<div
|
|
31
|
+
className={`${maxHeightClassName} overflow-auto whitespace-pre-wrap break-words font-mono text-xs leading-5`}
|
|
32
|
+
>
|
|
33
|
+
{text}
|
|
34
|
+
</div>
|
|
35
|
+
)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** 渲染响应内容:通常很长,放在底部独立区域避免挤压其它字段。 */
|
|
39
|
+
const renderResponseSection = () => {
|
|
40
|
+
const text = formatValue(detail.response)
|
|
41
|
+
return (
|
|
42
|
+
<div className="mt-4">
|
|
43
|
+
<div className="text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
|
|
44
|
+
{t('system.sys_log.fields.response')}
|
|
45
|
+
</div>
|
|
46
|
+
{text === '-' ? (
|
|
47
|
+
<div className="text-sm text-gray-500 dark:text-gray-400">-</div>
|
|
48
|
+
) : (
|
|
49
|
+
<div className="rounded-lg border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/40 p-3">
|
|
50
|
+
{renderLongText(detail.response, 'max-h-[420px]')}
|
|
51
|
+
</div>
|
|
52
|
+
)}
|
|
53
|
+
</div>
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** 渲染参数区域:bodyParam 通常较长,单独展示。 */
|
|
58
|
+
const renderParamSections = () => {
|
|
59
|
+
const bodyParamText = formatValue(detail.bodyParam)
|
|
60
|
+
return (
|
|
61
|
+
<div className="mt-4 space-y-4">
|
|
62
|
+
<div>
|
|
63
|
+
<div className="text-sm font-medium text-gray-700 dark:text-gray-200 mb-2">
|
|
64
|
+
{t('system.sys_log.fields.bodyParam')}
|
|
65
|
+
</div>
|
|
66
|
+
{bodyParamText === '-' ? (
|
|
67
|
+
<div className="text-sm text-gray-500 dark:text-gray-400">-</div>
|
|
68
|
+
) : (
|
|
69
|
+
<div className="rounded-lg border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/40 p-3">
|
|
70
|
+
{renderLongText(detail.bodyParam, 'max-h-[240px]')}
|
|
71
|
+
</div>
|
|
72
|
+
)}
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const close = () => {
|
|
79
|
+
setOpen(false)
|
|
80
|
+
setDetail({})
|
|
81
|
+
setLoading(false)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
useImperativeHandle(ref, () => ({
|
|
85
|
+
/** 打开系统日志详情弹窗:根据 id 拉取详情并展示。 */
|
|
86
|
+
open: async (payload: { opeId?: string | number; record?: any } = {}) => {
|
|
87
|
+
const opeId = payload.opeId ?? payload.record?.id ?? payload.record?._id
|
|
88
|
+
const fallback = payload.record ?? {}
|
|
89
|
+
setOpen(true)
|
|
90
|
+
setLoading(true)
|
|
91
|
+
setDetail(fallback)
|
|
92
|
+
if (opeId == null || opeId === '') {
|
|
93
|
+
setLoading(false)
|
|
94
|
+
return
|
|
95
|
+
}
|
|
96
|
+
try {
|
|
97
|
+
const res = await getSysLogDetailAPI(opeId)
|
|
98
|
+
setDetail(normalizeSysLogDetail(res))
|
|
99
|
+
} catch {
|
|
100
|
+
setDetail(fallback)
|
|
101
|
+
} finally {
|
|
102
|
+
setLoading(false)
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
close,
|
|
106
|
+
}))
|
|
107
|
+
|
|
108
|
+
return (
|
|
109
|
+
<CxModal title={t('system.sys_log.detail_title')} isOpen={open} onClose={close} opeType="detail" modalConfig={{ width: '800px' }}>
|
|
110
|
+
{loading ? (
|
|
111
|
+
<div className="flex justify-center py-10">
|
|
112
|
+
<Spin />
|
|
113
|
+
</div>
|
|
114
|
+
) : (
|
|
115
|
+
<div>
|
|
116
|
+
<Descriptions column={1} size="small" bordered>
|
|
117
|
+
<Descriptions.Item label={t('system.sys_log.fields.url')}>
|
|
118
|
+
{formatValue(detail.url)}
|
|
119
|
+
</Descriptions.Item>
|
|
120
|
+
<Descriptions.Item label={t('system.sys_log.fields.method')}>
|
|
121
|
+
{formatValue(detail.method)}
|
|
122
|
+
</Descriptions.Item>
|
|
123
|
+
<Descriptions.Item label={t('system.sys_log.fields.interfaceName')}>
|
|
124
|
+
{formatValue(detail.interfaceName)}
|
|
125
|
+
</Descriptions.Item>
|
|
126
|
+
<Descriptions.Item label={t('system.sys_log.fields.urlParam')}>
|
|
127
|
+
{renderLongText(detail.urlParam)}
|
|
128
|
+
</Descriptions.Item>
|
|
129
|
+
<Descriptions.Item label={t('system.sys_log.fields.userId')}>
|
|
130
|
+
{formatValue(detail.userId)}
|
|
131
|
+
</Descriptions.Item>
|
|
132
|
+
<Descriptions.Item label={t('system.sys_log.fields.userName')}>
|
|
133
|
+
{formatValue(detail.userName)}
|
|
134
|
+
</Descriptions.Item>
|
|
135
|
+
<Descriptions.Item label={t('system.sys_log.fields.startTime')}>
|
|
136
|
+
{formatValue(detail.startTime)}
|
|
137
|
+
</Descriptions.Item>
|
|
138
|
+
<Descriptions.Item label={t('system.sys_log.fields.endTime')}>
|
|
139
|
+
{formatValue(detail.endTime)}
|
|
140
|
+
</Descriptions.Item>
|
|
141
|
+
<Descriptions.Item label={t('system.sys_log.fields.cost')}>
|
|
142
|
+
{formatValue(detail.cost)}
|
|
143
|
+
</Descriptions.Item>
|
|
144
|
+
<Descriptions.Item label={t('system.sys_log.fields.clientIp')}>
|
|
145
|
+
{formatValue(detail.clientIp)}
|
|
146
|
+
</Descriptions.Item>
|
|
147
|
+
</Descriptions>
|
|
148
|
+
{renderParamSections()}
|
|
149
|
+
{renderResponseSection()}
|
|
150
|
+
</div>
|
|
151
|
+
)}
|
|
152
|
+
</CxModal>
|
|
153
|
+
)
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
export default DetailModal
|
|
157
|
+
|
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import type { FormInstance, Rule } from 'antd/es/form'
|
|
2
|
+
import { useCallback } from 'react'
|
|
3
|
+
|
|
4
|
+
import { addMenuAPI, editMenuAPI } from '@/api/system/menu'
|
|
5
|
+
import { useToast } from '@/contexts/ToastContext'
|
|
6
|
+
import { useModalSubmit } from '@/hooks/useModalSubmit'
|
|
7
|
+
import i18n from '@/i18n'
|
|
8
|
+
import type { MenuTreeItem } from '@/types/menu'
|
|
9
|
+
import { stringifyMenuNameJson } from '@/utils/menuI18n'
|
|
10
|
+
|
|
11
|
+
/** 本文件内统一 `t('key')`,与 react-i18next 的 `t` 用法一致 */
|
|
12
|
+
const t = i18n.t.bind(i18n)
|
|
13
|
+
|
|
14
|
+
export type MenuFormValues = {
|
|
15
|
+
parentId?: string
|
|
16
|
+
code: string
|
|
17
|
+
titleZh: string
|
|
18
|
+
titleEn: string
|
|
19
|
+
description: string
|
|
20
|
+
path: string
|
|
21
|
+
component: string
|
|
22
|
+
icon: string
|
|
23
|
+
sortOrder: number
|
|
24
|
+
status: number
|
|
25
|
+
fullDisplay: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function emptyMenuFormValues(): MenuFormValues {
|
|
29
|
+
return {
|
|
30
|
+
parentId: undefined,
|
|
31
|
+
code: '',
|
|
32
|
+
titleZh: '',
|
|
33
|
+
titleEn: '',
|
|
34
|
+
description: '',
|
|
35
|
+
path: '',
|
|
36
|
+
component: '',
|
|
37
|
+
icon: '',
|
|
38
|
+
sortOrder: 0,
|
|
39
|
+
status: 1,
|
|
40
|
+
fullDisplay: 0,
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 与弹窗、侧栏共用的校验提示(中文):
|
|
46
|
+
* 请输入菜单编码、编码须字母开头且仅含字母数字下划线、请输入菜单名称
|
|
47
|
+
*/
|
|
48
|
+
export function buildMenuFormRules(): {
|
|
49
|
+
code: Rule[]
|
|
50
|
+
titleZh: Rule[]
|
|
51
|
+
titleEn: Rule[]
|
|
52
|
+
path: Rule[]
|
|
53
|
+
sortOrder: Rule[]
|
|
54
|
+
} {
|
|
55
|
+
return {
|
|
56
|
+
code: [
|
|
57
|
+
{ required: true, message: t('system.menu.code_required') },
|
|
58
|
+
{
|
|
59
|
+
pattern: /^[a-zA-Z][a-zA-Z0-9_-]*$/,
|
|
60
|
+
message: t('system.menu.code_pattern_hint'),
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
titleZh: [{ required: true, message: t('system.menu.title_required') }],
|
|
64
|
+
titleEn: [{ required: true, message: t('system.menu.title_required') }],
|
|
65
|
+
path: [{ required: true, message: t('system.menu.path_required') }],
|
|
66
|
+
sortOrder: [
|
|
67
|
+
{ required: true, message: t('common.sort_order_required') },
|
|
68
|
+
],
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* 菜单层级与路由字段规则:
|
|
74
|
+
* - level=0:顶级菜单,固定 path='/'、component='Root'
|
|
75
|
+
* - level=1:一级菜单,固定 path='/'、component='Main'
|
|
76
|
+
* - level>=2:按表单输入提交
|
|
77
|
+
*/
|
|
78
|
+
export function normalizeMenuRouteByLevel(
|
|
79
|
+
level: number,
|
|
80
|
+
path?: string,
|
|
81
|
+
component?: string,
|
|
82
|
+
) {
|
|
83
|
+
if (level <= 0) {
|
|
84
|
+
return {
|
|
85
|
+
path: '/',
|
|
86
|
+
component: 'Root',
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
if (level === 1) {
|
|
90
|
+
return {
|
|
91
|
+
path: '/',
|
|
92
|
+
component: 'Main',
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
path: String(path ?? ''),
|
|
97
|
+
component: String(component ?? ''),
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** 父级 ID:仅取自表单 `parentId`,空则视为顶级 `0`。 */
|
|
102
|
+
export function resolveMenuPayloadParentId(values: Record<string, unknown>): string {
|
|
103
|
+
const formPid = values.parentId
|
|
104
|
+
if (formPid != null && String(formPid) !== '') {
|
|
105
|
+
const p = String(formPid)
|
|
106
|
+
return p === '0' ? '0' : p
|
|
107
|
+
}
|
|
108
|
+
return '0'
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export function findMenuNodeById(
|
|
112
|
+
nodes: MenuTreeItem[] | undefined,
|
|
113
|
+
id: string,
|
|
114
|
+
): MenuTreeItem | null {
|
|
115
|
+
for (const node of nodes || []) {
|
|
116
|
+
if (String(node.id) === String(id)) return node
|
|
117
|
+
const found = findMenuNodeById(node.children || [], id)
|
|
118
|
+
if (found) return found
|
|
119
|
+
}
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** 根据表单父级与当前树,计算将保存菜单的 level(0=顶级)。 */
|
|
124
|
+
export function resolveMenuSubmitLevel(
|
|
125
|
+
values: Record<string, unknown>,
|
|
126
|
+
treeData: MenuTreeItem[],
|
|
127
|
+
): number {
|
|
128
|
+
const payloadParentId = resolveMenuPayloadParentId(values)
|
|
129
|
+
if (payloadParentId === '0') return 0
|
|
130
|
+
const parentNode = findMenuNodeById(treeData, payloadParentId)
|
|
131
|
+
if (!parentNode) return 0
|
|
132
|
+
return Number(parentNode.level ?? 0) + 1
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export type SubmitMenuFormParams = {
|
|
136
|
+
opeType: string
|
|
137
|
+
form: FormInstance
|
|
138
|
+
/** 当前菜单层级(0=顶级),由页面 state/ref 维护,不注册到 Form */
|
|
139
|
+
getLevel: () => number
|
|
140
|
+
/** 编辑:当前节点;有 id 则走合并更新 */
|
|
141
|
+
existingMenu?: MenuTreeItem | null
|
|
142
|
+
onSuccess?: (ctx: {
|
|
143
|
+
opeType: string
|
|
144
|
+
payload: Record<string, unknown>
|
|
145
|
+
result: unknown
|
|
146
|
+
values: Record<string, unknown>
|
|
147
|
+
}) => void | Promise<void>
|
|
148
|
+
/** 允许的最大 level,默认 2(即 0/1/2 三级) */
|
|
149
|
+
maxLevel?: number
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 菜单页专用:内部固定 `addMenuAPI` / `editMenuAPI` 与 `useModalSubmit`。
|
|
154
|
+
* 侧栏编辑、新增弹窗各 `useMenuFormSubmit()` 一份即可(状态互不干扰)。
|
|
155
|
+
*/
|
|
156
|
+
export function useMenuFormSubmit() {
|
|
157
|
+
const { handleSubmit, submitting } = useModalSubmit<
|
|
158
|
+
Record<string, unknown>,
|
|
159
|
+
Record<string, unknown>
|
|
160
|
+
>()
|
|
161
|
+
const { showToast } = useToast()
|
|
162
|
+
|
|
163
|
+
const submitMenuForm = useCallback(
|
|
164
|
+
(params: SubmitMenuFormParams) => {
|
|
165
|
+
const {
|
|
166
|
+
opeType,
|
|
167
|
+
form,
|
|
168
|
+
getLevel,
|
|
169
|
+
existingMenu,
|
|
170
|
+
onSuccess,
|
|
171
|
+
maxLevel = 2,
|
|
172
|
+
} = params
|
|
173
|
+
|
|
174
|
+
return handleSubmit({
|
|
175
|
+
opeType,
|
|
176
|
+
validate: async () => {
|
|
177
|
+
try {
|
|
178
|
+
const values = (await form.validateFields()) as Record<string, unknown>
|
|
179
|
+
const level = getLevel()
|
|
180
|
+
if (level > maxLevel) {
|
|
181
|
+
throw new Error(String(t('system.menu.max_three_level_hint')))
|
|
182
|
+
}
|
|
183
|
+
return { ...values, level }
|
|
184
|
+
} catch (e: any) {
|
|
185
|
+
const err = e as { errorFields?: unknown[] }
|
|
186
|
+
if (Array.isArray(err?.errorFields) && err.errorFields.length > 0) {
|
|
187
|
+
showToast(String(t('common.form_validation_warning')), 'warning')
|
|
188
|
+
}
|
|
189
|
+
throw e
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
addAPI: addMenuAPI as (p: Record<string, unknown>) => Promise<unknown>,
|
|
193
|
+
editAPI: editMenuAPI as (p: Record<string, unknown>) => Promise<unknown>,
|
|
194
|
+
transform: (values) => buildMenuSubmitPayload(values, { existingMenu }),
|
|
195
|
+
onSuccess,
|
|
196
|
+
})
|
|
197
|
+
},
|
|
198
|
+
[handleSubmit, showToast],
|
|
199
|
+
)
|
|
200
|
+
|
|
201
|
+
return { submitMenuForm, submitting }
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/** 提交用:取自合并后的 `values.level`(由 validate 注入),非法则 0 */
|
|
205
|
+
export function menuLevelFromFormValues(values: Record<string, unknown>): number {
|
|
206
|
+
const n = Number(values.level)
|
|
207
|
+
return Number.isFinite(n) ? n : 0
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export type BuildMenuSubmitPayloadOptions = {
|
|
211
|
+
/** 编辑:传入当前节点;有 `id` 时合并原记录并剔除 children / parentName 等 */
|
|
212
|
+
existingMenu?: MenuTreeItem | null
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* 新增 / 编辑共用的请求体组装。
|
|
217
|
+
* - 无 `existingMenu?.id`:仅提交业务字段(新增)。
|
|
218
|
+
* - 有 `existingMenu?.id`:展开原菜单(去掉树/展示字段)后与表单合并(编辑)。
|
|
219
|
+
*/
|
|
220
|
+
export function buildMenuSubmitPayload(
|
|
221
|
+
values: Record<string, unknown>,
|
|
222
|
+
options: BuildMenuSubmitPayloadOptions = {},
|
|
223
|
+
): Record<string, unknown> {
|
|
224
|
+
const { existingMenu } = options
|
|
225
|
+
const level = menuLevelFromFormValues(values)
|
|
226
|
+
const payloadParentId = resolveMenuPayloadParentId(values)
|
|
227
|
+
const routeFields = normalizeMenuRouteByLevel(
|
|
228
|
+
level,
|
|
229
|
+
values.path as string | undefined,
|
|
230
|
+
values.component as string | undefined,
|
|
231
|
+
)
|
|
232
|
+
const title = stringifyMenuNameJson({
|
|
233
|
+
zh: String(values.titleZh ?? ''),
|
|
234
|
+
en: String(values.titleEn ?? ''),
|
|
235
|
+
})
|
|
236
|
+
const sortOrder = Number(values.sortOrder ?? 0)
|
|
237
|
+
const status = Number(values.status ?? 1)
|
|
238
|
+
const fullDisplay =
|
|
239
|
+
level === 1 ? Number(values.fullDisplay ?? 0) : 0
|
|
240
|
+
|
|
241
|
+
if (existingMenu?.id) {
|
|
242
|
+
const {
|
|
243
|
+
children: _children,
|
|
244
|
+
parentName: _parentName,
|
|
245
|
+
parent_name: _parent_name,
|
|
246
|
+
...menuForEdit
|
|
247
|
+
} = existingMenu as MenuTreeItem & {
|
|
248
|
+
parentName?: unknown
|
|
249
|
+
parent_name?: unknown
|
|
250
|
+
}
|
|
251
|
+
const payload: Record<string, unknown> = {
|
|
252
|
+
...menuForEdit,
|
|
253
|
+
...values,
|
|
254
|
+
title,
|
|
255
|
+
sortOrder,
|
|
256
|
+
status,
|
|
257
|
+
fullDisplay,
|
|
258
|
+
level,
|
|
259
|
+
parentId: payloadParentId,
|
|
260
|
+
path: routeFields.path,
|
|
261
|
+
component: routeFields.component,
|
|
262
|
+
}
|
|
263
|
+
delete payload.titleZh
|
|
264
|
+
delete payload.titleEn
|
|
265
|
+
delete payload.parentName
|
|
266
|
+
delete payload.parent_name
|
|
267
|
+
return payload
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
return {
|
|
271
|
+
parentId: payloadParentId,
|
|
272
|
+
code: values.code,
|
|
273
|
+
title,
|
|
274
|
+
description: values.description,
|
|
275
|
+
path: routeFields.path,
|
|
276
|
+
component: routeFields.component,
|
|
277
|
+
icon: values.icon,
|
|
278
|
+
sortOrder,
|
|
279
|
+
status,
|
|
280
|
+
fullDisplay,
|
|
281
|
+
level,
|
|
282
|
+
}
|
|
283
|
+
}
|