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,232 @@
|
|
|
1
|
+
import { useAuth } from '@/contexts/AuthContext'
|
|
2
|
+
import { DICT_DATA, DICT_KEY, ENUM_DATA } from '@/meta'
|
|
3
|
+
import { CxForm, CxFormItem, CxInput, CxSelect } from '@cx-ui'
|
|
4
|
+
import { Form } from 'antd'
|
|
5
|
+
import { forwardRef, useEffect, useImperativeHandle, useMemo } from 'react'
|
|
6
|
+
import { useTranslation } from 'react-i18next'
|
|
7
|
+
|
|
8
|
+
// 第一步 i18n:menus.model_metadata.manage.fields / placeholders / rules → locales/zh/menus/model-metadata/manage.ts
|
|
9
|
+
|
|
10
|
+
/** 与测连接入参一致,用于判断连接相关字段是否相对上次成功测试有变化 */
|
|
11
|
+
export function modelMetadataConnectionDigest(v: Record<string, any>): string {
|
|
12
|
+
return JSON.stringify({
|
|
13
|
+
databaseName: v.databaseName ?? '',
|
|
14
|
+
dbType: v.dbType ?? '',
|
|
15
|
+
host: v.host ?? '',
|
|
16
|
+
port: v.port ?? '',
|
|
17
|
+
dbSchema: v.dbSchema ?? '',
|
|
18
|
+
username: v.username ?? '',
|
|
19
|
+
password: v.password ?? '',
|
|
20
|
+
charsetName: v.charsetName ?? '',
|
|
21
|
+
})
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export type Step1BasicInfoHandle = {
|
|
25
|
+
validateForNext: () => Promise<Record<string, any>>
|
|
26
|
+
validateForConnectionTest: () => Promise<void>
|
|
27
|
+
getConnectionTestPayload: () => Record<string, any>
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type Step1BasicInfoProps = {
|
|
31
|
+
initialValues?: Record<string, any>
|
|
32
|
+
isEdit?: boolean
|
|
33
|
+
/** 连接相关字段摘要变化时回调(仅当与上次成功测试不一致时由父级清除「已测试」) */
|
|
34
|
+
onConnectionDigestChange?: (digest: string) => void
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const Step1BasicInfo = forwardRef<Step1BasicInfoHandle, Step1BasicInfoProps>(
|
|
38
|
+
function Step1BasicInfo(
|
|
39
|
+
{ initialValues, isEdit, onConnectionDigestChange },
|
|
40
|
+
ref,
|
|
41
|
+
) {
|
|
42
|
+
const { t } = useTranslation()
|
|
43
|
+
const { commonDictRevision } = useAuth()
|
|
44
|
+
const [form] = Form.useForm()
|
|
45
|
+
|
|
46
|
+
const dbTypeOptions = useMemo(
|
|
47
|
+
() => DICT_DATA[DICT_KEY.dbType]?.option ?? [],
|
|
48
|
+
[commonDictRevision],
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
// 校验文案:menus.model_metadata.manage.rules.* → locales/zh/menus/model-metadata/manage.ts
|
|
52
|
+
const formRules = useMemo(
|
|
53
|
+
() => ({
|
|
54
|
+
subject: [
|
|
55
|
+
{ required: true, message: t('menus.model_metadata.manage.rules.subject_required') }, // 主题必填
|
|
56
|
+
{ whitespace: true, message: t('menus.model_metadata.manage.rules.subject_required') },
|
|
57
|
+
],
|
|
58
|
+
databaseName: [
|
|
59
|
+
{ required: true, message: t('menus.model_metadata.manage.rules.databaseName_required') }, // 库名必填
|
|
60
|
+
{ whitespace: true, message: t('menus.model_metadata.manage.rules.databaseName_required') },
|
|
61
|
+
],
|
|
62
|
+
dbType: [{ required: true, message: t('menus.model_metadata.manage.rules.dbType_required') }], // 库类型必填
|
|
63
|
+
host: [
|
|
64
|
+
{ required: true, message: t('menus.model_metadata.manage.rules.host_required') }, // 主机必填
|
|
65
|
+
{ whitespace: true, message: t('menus.model_metadata.manage.rules.host_required') },
|
|
66
|
+
],
|
|
67
|
+
port: [{ required: true, message: t('menus.model_metadata.manage.rules.port_required') }], // 端口必填
|
|
68
|
+
username: [
|
|
69
|
+
{ required: true, message: t('menus.model_metadata.manage.rules.username_required') }, // 用户名必填
|
|
70
|
+
{ whitespace: true, message: t('menus.model_metadata.manage.rules.username_required') },
|
|
71
|
+
],
|
|
72
|
+
password: isEdit
|
|
73
|
+
? []
|
|
74
|
+
: [
|
|
75
|
+
{ required: true, message: t('menus.model_metadata.manage.rules.password_required') }, // 密码必填
|
|
76
|
+
{ whitespace: true, message: t('menus.model_metadata.manage.rules.password_required') },
|
|
77
|
+
],
|
|
78
|
+
}),
|
|
79
|
+
[t, isEdit],
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (initialValues && Object.keys(initialValues).length > 0) {
|
|
84
|
+
form.setFieldsValue(initialValues)
|
|
85
|
+
}
|
|
86
|
+
}, [form, initialValues])
|
|
87
|
+
|
|
88
|
+
// 开发:新增时空表单自动填基础信息,不需要时把下面整段 useEffect 注释掉即可
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (!import.meta.env.DEV) return
|
|
91
|
+
if (initialValues && Object.keys(initialValues).length > 0) return
|
|
92
|
+
form.setFieldsValue({
|
|
93
|
+
subject: 'dev-local-db',
|
|
94
|
+
databaseName: 'agent-forge',
|
|
95
|
+
dbType: 'mysql',
|
|
96
|
+
host: '10.101.1.128',
|
|
97
|
+
port: 13306,
|
|
98
|
+
dbSchema: '',
|
|
99
|
+
username: 'root',
|
|
100
|
+
password: 'Q95pRHWuOJTSAPJo',
|
|
101
|
+
optionsJson: '',
|
|
102
|
+
})
|
|
103
|
+
}, [form, initialValues])
|
|
104
|
+
|
|
105
|
+
const watched = Form.useWatch(
|
|
106
|
+
['databaseName', 'dbType', 'host', 'port', 'username', 'password', 'dbSchema', 'charsetName'],
|
|
107
|
+
form,
|
|
108
|
+
)
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
const v = form.getFieldsValue(true) as Record<string, any>
|
|
112
|
+
onConnectionDigestChange?.(modelMetadataConnectionDigest(v))
|
|
113
|
+
}, [watched, form, onConnectionDigestChange])
|
|
114
|
+
|
|
115
|
+
useImperativeHandle(
|
|
116
|
+
ref,
|
|
117
|
+
() => ({
|
|
118
|
+
validateForNext: async () => {
|
|
119
|
+
await form.validateFields(['subject', 'databaseName', 'dbType', 'host', 'port', 'username'])
|
|
120
|
+
return form.getFieldsValue(true) as Record<string, any>
|
|
121
|
+
},
|
|
122
|
+
validateForConnectionTest: () =>
|
|
123
|
+
form.validateFields([
|
|
124
|
+
'databaseName',
|
|
125
|
+
'dbType',
|
|
126
|
+
'host',
|
|
127
|
+
'port',
|
|
128
|
+
'username',
|
|
129
|
+
'password',
|
|
130
|
+
]),
|
|
131
|
+
getConnectionTestPayload: () => {
|
|
132
|
+
const v = form.getFieldsValue(true) as Record<string, any>
|
|
133
|
+
return {
|
|
134
|
+
databaseName: v.databaseName,
|
|
135
|
+
dbType: v.dbType,
|
|
136
|
+
host: v.host,
|
|
137
|
+
port: v.port,
|
|
138
|
+
dbSchema: v.dbSchema,
|
|
139
|
+
username: v.username,
|
|
140
|
+
password: v.password,
|
|
141
|
+
charsetName: v.charsetName,
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
}),
|
|
145
|
+
[form],
|
|
146
|
+
)
|
|
147
|
+
|
|
148
|
+
const fieldClass = 'w-full min-w-0'
|
|
149
|
+
const inputClass = 'w-full min-w-0 max-w-full'
|
|
150
|
+
|
|
151
|
+
// 标签/占位:menus.model_metadata.manage.fields.* / placeholders.* → zh/menus/model-metadata/manage.ts
|
|
152
|
+
return (
|
|
153
|
+
<CxForm form={form} rules={formRules} layout="vertical" className="w-full min-w-0">
|
|
154
|
+
<div className="grid w-full min-w-0 grid-cols-2 gap-x-6 gap-y-4">
|
|
155
|
+
{/* 主题 */}
|
|
156
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.subject')} name="subject">
|
|
157
|
+
<CxInput className={inputClass} placeholder={t('menus.model_metadata.manage.placeholders.subject')} />
|
|
158
|
+
</CxFormItem>
|
|
159
|
+
{/* 数据库名 */}
|
|
160
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.databaseName')} name="databaseName">
|
|
161
|
+
<CxInput className={inputClass} placeholder={t('menus.model_metadata.manage.placeholders.databaseName')} />
|
|
162
|
+
</CxFormItem>
|
|
163
|
+
</div>
|
|
164
|
+
|
|
165
|
+
<div className="grid w-full min-w-0 grid-cols-2 gap-x-6 gap-y-4">
|
|
166
|
+
{/* 库类型 */}
|
|
167
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.dbType')} name="dbType">
|
|
168
|
+
<CxSelect
|
|
169
|
+
className={inputClass}
|
|
170
|
+
placeholder={t('menus.model_metadata.manage.placeholders.dbType')}
|
|
171
|
+
options={dbTypeOptions}
|
|
172
|
+
fieldNames={{ label: 'name', value: 'value' }}
|
|
173
|
+
/>
|
|
174
|
+
</CxFormItem>
|
|
175
|
+
{/* 字符集 */}
|
|
176
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.charsetName')} name="charsetName">
|
|
177
|
+
<CxSelect
|
|
178
|
+
className={inputClass}
|
|
179
|
+
allowClear
|
|
180
|
+
placeholder={t('menus.model_metadata.manage.placeholders.charsetName')}
|
|
181
|
+
options={ENUM_DATA.dbCharset.option}
|
|
182
|
+
/>
|
|
183
|
+
</CxFormItem>
|
|
184
|
+
</div>
|
|
185
|
+
|
|
186
|
+
<div className="grid w-full min-w-0 grid-cols-4 gap-x-6 gap-y-4">
|
|
187
|
+
{/* 主机 */}
|
|
188
|
+
<CxFormItem className={`${fieldClass} col-span-3`} label={t('menus.model_metadata.manage.fields.host')} name="host">
|
|
189
|
+
<CxInput className={inputClass} placeholder={t('menus.model_metadata.manage.placeholders.host')} />
|
|
190
|
+
</CxFormItem>
|
|
191
|
+
{/* 端口 */}
|
|
192
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.port')} name="port">
|
|
193
|
+
<CxInput className={inputClass} placeholder={t('menus.model_metadata.manage.placeholders.port')} />
|
|
194
|
+
</CxFormItem>
|
|
195
|
+
</div>
|
|
196
|
+
|
|
197
|
+
<div className="grid w-full min-w-0 grid-cols-4 gap-x-6 gap-y-4">
|
|
198
|
+
{/* Schema */}
|
|
199
|
+
<CxFormItem className={`${fieldClass} col-span-2`} label={t('menus.model_metadata.manage.fields.dbSchema')} name="dbSchema">
|
|
200
|
+
<CxInput className={inputClass} placeholder={t('menus.model_metadata.manage.placeholders.dbSchema')} />
|
|
201
|
+
</CxFormItem>
|
|
202
|
+
{/* 用户名 */}
|
|
203
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.username')} name="username">
|
|
204
|
+
<CxInput className={inputClass} placeholder={t('menus.model_metadata.manage.placeholders.username')} />
|
|
205
|
+
</CxFormItem>
|
|
206
|
+
{/* 密码 */}
|
|
207
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.password')} name="password">
|
|
208
|
+
<CxInput
|
|
209
|
+
className={inputClass}
|
|
210
|
+
type="password"
|
|
211
|
+
autoComplete="new-password"
|
|
212
|
+
placeholder={t('menus.model_metadata.manage.placeholders.password')}
|
|
213
|
+
/>
|
|
214
|
+
</CxFormItem>
|
|
215
|
+
</div>
|
|
216
|
+
|
|
217
|
+
<div className="mt-6 w-full min-w-0">
|
|
218
|
+
{/* 配置 JSON */}
|
|
219
|
+
<CxFormItem className={fieldClass} label={t('menus.model_metadata.manage.fields.optionsJson')} name="optionsJson">
|
|
220
|
+
<CxInput.Textarea
|
|
221
|
+
className={inputClass}
|
|
222
|
+
rows={4}
|
|
223
|
+
placeholder={t('menus.model_metadata.manage.placeholders.optionsJson')}
|
|
224
|
+
/>
|
|
225
|
+
</CxFormItem>
|
|
226
|
+
</div>
|
|
227
|
+
</CxForm>
|
|
228
|
+
)
|
|
229
|
+
},
|
|
230
|
+
)
|
|
231
|
+
|
|
232
|
+
export default Step1BasicInfo
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
import { introspectPreviewAPI } from '@api/menus/model-metadata/manage'
|
|
2
|
+
import { useToast } from '@/contexts/ToastContext'
|
|
3
|
+
import { useAuth } from '@/contexts/AuthContext'
|
|
4
|
+
import { CxButton, CxInput, CxTable } from '@cx-ui'
|
|
5
|
+
import type { CxModalRef } from '@cx-ui/modal/useCxModal'
|
|
6
|
+
import { Spin } from 'antd'
|
|
7
|
+
import axios from 'axios'
|
|
8
|
+
import { Plus, RefreshCw } from 'lucide-react'
|
|
9
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
10
|
+
import { useTranslation } from 'react-i18next'
|
|
11
|
+
import TableSubmitModal from '../modal/table-submit-modal'
|
|
12
|
+
|
|
13
|
+
/** 与 introspect/preview 接口一致的连接入参 */
|
|
14
|
+
function buildIntrospectPreviewParams(connection: Record<string, any>) {
|
|
15
|
+
return {
|
|
16
|
+
databaseName: connection.databaseName,
|
|
17
|
+
dbType: connection.dbType,
|
|
18
|
+
host: connection.host,
|
|
19
|
+
port: connection.port,
|
|
20
|
+
username: connection.username,
|
|
21
|
+
password: connection.password,
|
|
22
|
+
dbSchema: connection.dbSchema,
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 反查结构预览(不落库),返回 tables 数组 */
|
|
27
|
+
async function fetchIntrospectPreviewTables(
|
|
28
|
+
connection: Record<string, any>,
|
|
29
|
+
options?: { signal?: AbortSignal },
|
|
30
|
+
) {
|
|
31
|
+
const res = await introspectPreviewAPI(buildIntrospectPreviewParams(connection), options)
|
|
32
|
+
return (res as any)?.data ?? []
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// 本步 i18n:menus.model_metadata.manage.* → locales/zh/menus/model-metadata/manage.ts
|
|
36
|
+
|
|
37
|
+
type SchemaTable = {
|
|
38
|
+
_clientId?: string
|
|
39
|
+
tableSchema?: string
|
|
40
|
+
tableName?: string
|
|
41
|
+
tableComment?: string
|
|
42
|
+
tableType?: string
|
|
43
|
+
columns?: any[]
|
|
44
|
+
indexes?: any[]
|
|
45
|
+
foreignKeys?: any[]
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
type Step2SchemaProps = {
|
|
49
|
+
connectionParams: Record<string, any>
|
|
50
|
+
tables: SchemaTable[]
|
|
51
|
+
onTablesChange: (tables: SchemaTable[]) => void
|
|
52
|
+
isEdit?: boolean
|
|
53
|
+
currentStep?: number
|
|
54
|
+
/** 新增:每次从第一步点「下一步」进入本步时递增,用于强制重新拉取结构预览 */
|
|
55
|
+
previewNonce?: number
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function isAbortError(e: unknown) {
|
|
59
|
+
return axios.isCancel(e) || (e as any)?.code === 'ERR_CANCELED' || (e as any)?.name === 'CanceledError'
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function newClientId() {
|
|
63
|
+
return `c_${Date.now()}_${Math.random().toString(36).slice(2, 11)}`
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function emptySchemaTable(): SchemaTable {
|
|
67
|
+
return {
|
|
68
|
+
_clientId: newClientId(),
|
|
69
|
+
tableSchema: '',
|
|
70
|
+
tableName: '',
|
|
71
|
+
tableComment: '',
|
|
72
|
+
tableType: '',
|
|
73
|
+
columns: [],
|
|
74
|
+
indexes: [],
|
|
75
|
+
foreignKeys: [],
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function tableStableKey(r: SchemaTable) {
|
|
80
|
+
return r._clientId ?? `${r.tableSchema ?? ''}::${r.tableName ?? ''}`
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function removeSchemaTable(tables: SchemaTable[], target: SchemaTable): SchemaTable[] {
|
|
84
|
+
const tid = target._clientId
|
|
85
|
+
if (tid) return tables.filter((t) => t._clientId !== tid)
|
|
86
|
+
const k = tableStableKey(target)
|
|
87
|
+
let removed = false
|
|
88
|
+
return tables.filter((t) => {
|
|
89
|
+
if (t._clientId) return true
|
|
90
|
+
if (!removed && tableStableKey(t) === k) {
|
|
91
|
+
removed = true
|
|
92
|
+
return false
|
|
93
|
+
}
|
|
94
|
+
return true
|
|
95
|
+
})
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default function Step2Schema({
|
|
99
|
+
connectionParams,
|
|
100
|
+
tables,
|
|
101
|
+
onTablesChange,
|
|
102
|
+
isEdit,
|
|
103
|
+
currentStep,
|
|
104
|
+
previewNonce = 0,
|
|
105
|
+
}: Step2SchemaProps) {
|
|
106
|
+
const { showToast } = useToast()
|
|
107
|
+
const { hasPermission } = useAuth()
|
|
108
|
+
const { t } = useTranslation()
|
|
109
|
+
const [previewLoading, setPreviewLoading] = useState(false)
|
|
110
|
+
const [tableNameQuery, setTableNameQuery] = useState('')
|
|
111
|
+
const tableSubmitModalRef = useRef<CxModalRef>(null)
|
|
112
|
+
|
|
113
|
+
const filteredTables = useMemo(() => {
|
|
114
|
+
const q = tableNameQuery.trim().toLowerCase()
|
|
115
|
+
if (!q) return tables
|
|
116
|
+
return tables.filter((row) => String(row.tableName ?? '').toLowerCase().includes(q))
|
|
117
|
+
}, [tables, tableNameQuery])
|
|
118
|
+
|
|
119
|
+
useEffect(() => {
|
|
120
|
+
setTableNameQuery('')
|
|
121
|
+
}, [previewNonce])
|
|
122
|
+
|
|
123
|
+
const runIntrospectFetch = useCallback(
|
|
124
|
+
async (options?: { signal?: AbortSignal }) => {
|
|
125
|
+
return fetchIntrospectPreviewTables(connectionParams, options)
|
|
126
|
+
},
|
|
127
|
+
[connectionParams],
|
|
128
|
+
)
|
|
129
|
+
|
|
130
|
+
/** 仅随进入第二步 / previewNonce / 连接对象引用变化触发;勿把 showToast、t 等放进依赖,否则父级重渲染会反复 onTablesChange([]) 冲掉本地新增行 */
|
|
131
|
+
useEffect(() => {
|
|
132
|
+
if (isEdit) return
|
|
133
|
+
if (currentStep !== 1) return
|
|
134
|
+
if (!previewNonce) return
|
|
135
|
+
|
|
136
|
+
onTablesChange([])
|
|
137
|
+
|
|
138
|
+
const ac = new AbortController()
|
|
139
|
+
setPreviewLoading(true)
|
|
140
|
+
;(async () => {
|
|
141
|
+
try {
|
|
142
|
+
const data = await fetchIntrospectPreviewTables(connectionParams, { signal: ac.signal })
|
|
143
|
+
onTablesChange(Array.isArray(data) ? data : [])
|
|
144
|
+
} catch (error: any) {
|
|
145
|
+
if (isAbortError(error)) return
|
|
146
|
+
showToast(error?.message || t('menus.model_metadata.manage.preview_failed'), 'error') // 结构预览失败
|
|
147
|
+
} finally {
|
|
148
|
+
if (!ac.signal.aborted) {
|
|
149
|
+
setPreviewLoading(false)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
})()
|
|
153
|
+
|
|
154
|
+
return () => {
|
|
155
|
+
ac.abort()
|
|
156
|
+
}
|
|
157
|
+
// onTablesChange 为 setState 引用稳定;showToast/t 勿写入依赖以免每次渲染清空 tables
|
|
158
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps -- 见上
|
|
159
|
+
}, [isEdit, currentStep, previewNonce, connectionParams, onTablesChange])
|
|
160
|
+
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
const handleTableUpdate = (e: CustomEvent<SchemaTable>) => {
|
|
163
|
+
const u = e.detail
|
|
164
|
+
const newTables = tables.map((row) => {
|
|
165
|
+
if (u._clientId && row._clientId && u._clientId === row._clientId) return u
|
|
166
|
+
if (
|
|
167
|
+
row.tableName === u.tableName &&
|
|
168
|
+
(row.tableSchema ?? '') === (u.tableSchema ?? '')
|
|
169
|
+
) {
|
|
170
|
+
return u
|
|
171
|
+
}
|
|
172
|
+
return row
|
|
173
|
+
})
|
|
174
|
+
onTablesChange(newTables)
|
|
175
|
+
showToast(t('menus.model_metadata.manage.table_updated'), 'success') // 表信息已更新
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
window.addEventListener('tableUpdated', handleTableUpdate as any)
|
|
179
|
+
return () => {
|
|
180
|
+
window.removeEventListener('tableUpdated', handleTableUpdate as any)
|
|
181
|
+
}
|
|
182
|
+
}, [tables, onTablesChange, showToast, t])
|
|
183
|
+
|
|
184
|
+
const handleRefetch = useCallback(async () => {
|
|
185
|
+
setPreviewLoading(true)
|
|
186
|
+
try {
|
|
187
|
+
const data = await runIntrospectFetch()
|
|
188
|
+
onTablesChange(Array.isArray(data) ? data : [])
|
|
189
|
+
showToast(t('menus.model_metadata.manage.preview_refreshed'), 'success') // 表结构已重新获取
|
|
190
|
+
} catch (error: any) {
|
|
191
|
+
showToast(error?.message || t('menus.model_metadata.manage.preview_failed'), 'error') // 结构预览失败
|
|
192
|
+
} finally {
|
|
193
|
+
setPreviewLoading(false)
|
|
194
|
+
}
|
|
195
|
+
}, [onTablesChange, runIntrospectFetch, showToast, t])
|
|
196
|
+
|
|
197
|
+
const handleAddTable = useCallback(() => {
|
|
198
|
+
setTableNameQuery('')
|
|
199
|
+
const row = emptySchemaTable()
|
|
200
|
+
const nextTables = [...tables, row]
|
|
201
|
+
onTablesChange(nextTables)
|
|
202
|
+
setTimeout(() => {
|
|
203
|
+
tableSubmitModalRef.current?.open({
|
|
204
|
+
opeType: 'add',
|
|
205
|
+
data: row,
|
|
206
|
+
schemaTables: nextTables,
|
|
207
|
+
})
|
|
208
|
+
}, 0)
|
|
209
|
+
}, [tables, onTablesChange])
|
|
210
|
+
|
|
211
|
+
const handleDeleteTable = useCallback(
|
|
212
|
+
(record: SchemaTable) => {
|
|
213
|
+
onTablesChange(removeSchemaTable(tables, record))
|
|
214
|
+
},
|
|
215
|
+
[tables, onTablesChange],
|
|
216
|
+
)
|
|
217
|
+
|
|
218
|
+
const handleEditTable = (record: SchemaTable) => {
|
|
219
|
+
tableSubmitModalRef.current?.open({
|
|
220
|
+
opeType: 'edit',
|
|
221
|
+
data: record,
|
|
222
|
+
schemaTables: tables,
|
|
223
|
+
})
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 表列表列标题:fields.* → zh/menus/model-metadata.ts
|
|
227
|
+
const columns = [
|
|
228
|
+
{
|
|
229
|
+
title: t('menus.model_metadata.manage.fields.tableName'), // 表名
|
|
230
|
+
dataIndex: 'tableName',
|
|
231
|
+
key: 'tableName',
|
|
232
|
+
width: 200,
|
|
233
|
+
},
|
|
234
|
+
{
|
|
235
|
+
title: t('menus.model_metadata.manage.fields.tableComment'), // 表注释
|
|
236
|
+
dataIndex: 'tableComment',
|
|
237
|
+
key: 'tableComment',
|
|
238
|
+
ellipsis: true,
|
|
239
|
+
minWidth: 200,
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
title: t('menus.model_metadata.manage.fields.columnCount'), // 字段数量
|
|
243
|
+
key: 'columnCount',
|
|
244
|
+
width: 120,
|
|
245
|
+
render: (_: unknown, record: SchemaTable) => record.columns?.length ?? 0,
|
|
246
|
+
},
|
|
247
|
+
{
|
|
248
|
+
title: t('common.actions'), // 操作
|
|
249
|
+
key: 'action',
|
|
250
|
+
width: 112,
|
|
251
|
+
render: (_: unknown, record: SchemaTable) => (
|
|
252
|
+
<div className="flex items-center justify-center gap-1">
|
|
253
|
+
<CxButton.IconEdit onClick={() => handleEditTable(record)} />
|
|
254
|
+
<CxButton.IconDelete onClick={() => handleDeleteTable(record)} />
|
|
255
|
+
</div>
|
|
256
|
+
),
|
|
257
|
+
},
|
|
258
|
+
]
|
|
259
|
+
|
|
260
|
+
return (
|
|
261
|
+
<div className="flex h-full min-h-0 w-full min-w-0 flex-1 flex-col">
|
|
262
|
+
{previewLoading ? (
|
|
263
|
+
<div className="flex min-h-[240px] flex-1 items-center justify-center py-8">
|
|
264
|
+
<Spin size="large" tip={t('common.loading')} />
|
|
265
|
+
</div>
|
|
266
|
+
) : (
|
|
267
|
+
<>
|
|
268
|
+
<div
|
|
269
|
+
className={`mb-3 flex w-full min-w-0 shrink-0 items-center gap-3 px-0.5 pt-px ${
|
|
270
|
+
tables.length > 0 ? 'justify-between' : 'justify-end'
|
|
271
|
+
}`}
|
|
272
|
+
>
|
|
273
|
+
{tables.length > 0 ? (
|
|
274
|
+
<CxInput
|
|
275
|
+
allowClear
|
|
276
|
+
className="max-w-sm min-w-0 flex-1"
|
|
277
|
+
value={tableNameQuery}
|
|
278
|
+
placeholder={t('menus.model_metadata.manage.filter_table_name_placeholder')} // 按表名筛选
|
|
279
|
+
onChange={(e) => setTableNameQuery(e.target.value)}
|
|
280
|
+
/>
|
|
281
|
+
) : null}
|
|
282
|
+
<div className="flex shrink-0 items-center gap-2">
|
|
283
|
+
<CxButton type="primary" htmlType="button" onClick={handleAddTable} icon={<Plus size={16} />}>
|
|
284
|
+
{t('menus.model_metadata.manage.add_schema_table')} {/* 新增表 */}
|
|
285
|
+
</CxButton>
|
|
286
|
+
{hasPermission('model-metadata:preview') ? (
|
|
287
|
+
<CxButton
|
|
288
|
+
type="default"
|
|
289
|
+
htmlType="button"
|
|
290
|
+
onClick={() => void handleRefetch()}
|
|
291
|
+
icon={<RefreshCw size={16} />}
|
|
292
|
+
>
|
|
293
|
+
{t('menus.model_metadata.manage.refetch_schema_preview')} {/* 重新获取 */}
|
|
294
|
+
</CxButton>
|
|
295
|
+
) : null}
|
|
296
|
+
</div>
|
|
297
|
+
</div>
|
|
298
|
+
<div className="min-h-0 w-full min-w-0 flex-1 overflow-hidden">
|
|
299
|
+
<CxTable
|
|
300
|
+
className="min-w-0 w-full"
|
|
301
|
+
autoScrollY
|
|
302
|
+
minScrollY={160}
|
|
303
|
+
columns={columns}
|
|
304
|
+
dataSource={filteredTables}
|
|
305
|
+
rowKey={(record) => tableStableKey(record)}
|
|
306
|
+
pagination={false}
|
|
307
|
+
scroll={{ x: true }}
|
|
308
|
+
/>
|
|
309
|
+
</div>
|
|
310
|
+
</>
|
|
311
|
+
)}
|
|
312
|
+
|
|
313
|
+
<TableSubmitModal ref={tableSubmitModalRef} />
|
|
314
|
+
</div>
|
|
315
|
+
)
|
|
316
|
+
}
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { CxButton, CxInput, CxSelect, CxTable } from '@cx-ui'
|
|
2
|
+
import { Plus } from 'lucide-react'
|
|
3
|
+
import { useMemo } from 'react'
|
|
4
|
+
import { useTranslation } from 'react-i18next'
|
|
5
|
+
import { tableEditSelectPopupMin } from '../modal/components/table-schema'
|
|
6
|
+
|
|
7
|
+
export type MetadataPermissionRow = {
|
|
8
|
+
id?: string
|
|
9
|
+
permissionName: string
|
|
10
|
+
permissionColumns: string[]
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type SchemaTableBriefForPermissions = {
|
|
14
|
+
tableName?: string
|
|
15
|
+
columns?: { columnName?: string }[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 全表字段名去重,不含表名 */
|
|
19
|
+
function columnOptionsFromTables(tables: SchemaTableBriefForPermissions[]) {
|
|
20
|
+
const seen = new Set<string>()
|
|
21
|
+
for (const tb of tables || []) {
|
|
22
|
+
for (const col of tb.columns || []) {
|
|
23
|
+
const cn = String(col.columnName ?? '').trim()
|
|
24
|
+
if (!cn) continue
|
|
25
|
+
seen.add(cn)
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return [...seen].sort((a, b) => a.localeCompare(b)).map((name) => ({ value: name, label: name }))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
type Step3PermissionsProps = {
|
|
32
|
+
permissions: MetadataPermissionRow[]
|
|
33
|
+
onPermissionsChange: (rows: MetadataPermissionRow[]) => void
|
|
34
|
+
tables: SchemaTableBriefForPermissions[]
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export function validPermissionColumnValues(tables: SchemaTableBriefForPermissions[]) {
|
|
38
|
+
return new Set(columnOptionsFromTables(tables).map((o) => o.value))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export default function Step3Permissions({
|
|
42
|
+
permissions,
|
|
43
|
+
onPermissionsChange,
|
|
44
|
+
tables,
|
|
45
|
+
}: Step3PermissionsProps) {
|
|
46
|
+
const { t } = useTranslation()
|
|
47
|
+
const columnOptions = useMemo(() => columnOptionsFromTables(tables), [tables])
|
|
48
|
+
|
|
49
|
+
const handleAdd = () => {
|
|
50
|
+
onPermissionsChange([...permissions, { permissionName: '', permissionColumns: [] }])
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const handleDelete = (index: number) => {
|
|
54
|
+
onPermissionsChange(permissions.filter((_, i) => i !== index))
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const handleChange = (index: number, patch: Partial<MetadataPermissionRow>) => {
|
|
58
|
+
const next = [...permissions]
|
|
59
|
+
next[index] = { ...next[index], ...patch }
|
|
60
|
+
onPermissionsChange(next)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const columns = [
|
|
64
|
+
{
|
|
65
|
+
title: t('menus.model_metadata.manage.fields.permissionName'),
|
|
66
|
+
key: 'permissionName',
|
|
67
|
+
width: 180,
|
|
68
|
+
render: (_: unknown, __: MetadataPermissionRow, index: number) => (
|
|
69
|
+
<div className="min-w-0 max-w-full">
|
|
70
|
+
<CxInput
|
|
71
|
+
className="w-full min-w-0"
|
|
72
|
+
value={permissions[index].permissionName}
|
|
73
|
+
onChange={(e) => handleChange(index, { permissionName: e.target.value })}
|
|
74
|
+
placeholder={t('menus.model_metadata.manage.placeholders.permissionName')}
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
),
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
title: t('menus.model_metadata.manage.fields.permissionColumns'),
|
|
81
|
+
key: 'permissionColumns',
|
|
82
|
+
minWidth: 360,
|
|
83
|
+
render: (_: unknown, __: MetadataPermissionRow, index: number) => (
|
|
84
|
+
<CxSelect
|
|
85
|
+
popupMatchSelectWidth={false}
|
|
86
|
+
styles={{ popup: { root: tableEditSelectPopupMin } }}
|
|
87
|
+
mode="multiple"
|
|
88
|
+
showSearch
|
|
89
|
+
allowClear
|
|
90
|
+
optionFilterProp="label"
|
|
91
|
+
className="w-full min-w-0 max-w-full !items-start [&_.ant-select-selector]:!h-auto [&_.ant-select-selector]:!min-h-8 [&_.ant-select-selector]:items-start [&_.ant-select-selection-overflow]:!flex-wrap [&_.ant-select-selection-overflow]:!gap-y-1 [&_.ant-select-selection-overflow]:!gap-x-1 [&_.ant-select-selection-item]:!m-0"
|
|
92
|
+
options={columnOptions}
|
|
93
|
+
value={permissions[index].permissionColumns || []}
|
|
94
|
+
placeholder={t('menus.model_metadata.manage.placeholders.permissionColumns')}
|
|
95
|
+
onChange={(v) =>
|
|
96
|
+
handleChange(index, {
|
|
97
|
+
permissionColumns: Array.isArray(v) ? (v as string[]) : [],
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
/>
|
|
101
|
+
),
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
title: t('common.actions'),
|
|
105
|
+
key: 'action',
|
|
106
|
+
width: 80,
|
|
107
|
+
render: (_: unknown, __: MetadataPermissionRow, index: number) => (
|
|
108
|
+
<CxButton.IconDelete onClick={() => handleDelete(index)} />
|
|
109
|
+
),
|
|
110
|
+
},
|
|
111
|
+
]
|
|
112
|
+
|
|
113
|
+
return (
|
|
114
|
+
<div className="flex h-full min-h-0 w-full min-w-0 flex-1 flex-col overflow-hidden">
|
|
115
|
+
<div className="mb-4 flex w-full min-w-0 shrink-0 items-center justify-between">
|
|
116
|
+
<h3 className="text-base font-medium">{t('menus.model_metadata.manage.permissions')}</h3>
|
|
117
|
+
<CxButton type="primary" onClick={handleAdd} icon={<Plus size={16} />}>
|
|
118
|
+
{t('menus.model_metadata.manage.add_permission')}
|
|
119
|
+
</CxButton>
|
|
120
|
+
</div>
|
|
121
|
+
<div className="min-h-0 w-full min-w-0 flex-1 overflow-hidden">
|
|
122
|
+
<CxTable
|
|
123
|
+
className="min-w-0 w-full"
|
|
124
|
+
autoScrollY
|
|
125
|
+
minScrollY={160}
|
|
126
|
+
columns={columns}
|
|
127
|
+
dataSource={permissions.map((row, index) => ({ ...row, key: index }))}
|
|
128
|
+
pagination={false}
|
|
129
|
+
scroll={{ x: true }}
|
|
130
|
+
/>
|
|
131
|
+
</div>
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|