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,20 @@
|
|
|
1
|
+
import { useState } from 'react'
|
|
2
|
+
|
|
3
|
+
/** 模型元数据「明细」表单共用状态(表结构 / 权限 / 文档 / 示例 SQL) */
|
|
4
|
+
export function useModelMetadataItemState() {
|
|
5
|
+
const [tables, setTables] = useState<any[]>([])
|
|
6
|
+
const [permissions, setPermissions] = useState<any[]>([])
|
|
7
|
+
const [documents, setDocuments] = useState<any[]>([])
|
|
8
|
+
const [exampleSqlList, setExampleSqlList] = useState<any[]>([])
|
|
9
|
+
|
|
10
|
+
return {
|
|
11
|
+
tables,
|
|
12
|
+
setTables,
|
|
13
|
+
permissions,
|
|
14
|
+
setPermissions,
|
|
15
|
+
documents,
|
|
16
|
+
setDocuments,
|
|
17
|
+
exampleSqlList,
|
|
18
|
+
setExampleSqlList,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,304 @@
|
|
|
1
|
+
import { useAuth } from '@/contexts/AuthContext'
|
|
2
|
+
import { ALIGN, DICT_DATA, DICT_KEY, ENUM_DATA } from '@/meta'
|
|
3
|
+
import {
|
|
4
|
+
deleteModelMetadataAPI,
|
|
5
|
+
disableModelMetadataAPI,
|
|
6
|
+
enableModelMetadataAPI,
|
|
7
|
+
getModelMetadataPageAPI,
|
|
8
|
+
} from '@api/menus/model-metadata/manage'
|
|
9
|
+
import { DetailLink } from '@components/common/detail-link'
|
|
10
|
+
import ListPageView, { createListPageConfig } from '@components/table-view'
|
|
11
|
+
import { CxButton, CxTag } from '@cx-ui'
|
|
12
|
+
import { useMemo, useRef } from 'react'
|
|
13
|
+
|
|
14
|
+
import DetailModal from './modal/detail-modal'
|
|
15
|
+
import SubmitModal from './modal/submit-modal'
|
|
16
|
+
|
|
17
|
+
// 列表页 i18n:menus.model_metadata.manage.* → locales/zh/menus/model-metadata/manage.ts
|
|
18
|
+
const useListPageConfig = createListPageConfig({
|
|
19
|
+
tableAPI: getModelMetadataPageAPI,
|
|
20
|
+
deleteAPI: deleteModelMetadataAPI,
|
|
21
|
+
updateStatusAPI: ({ id, status }) =>
|
|
22
|
+
Number(status) === 1 ? enableModelMetadataAPI(id) : disableModelMetadataAPI(id),
|
|
23
|
+
pageInfo: {
|
|
24
|
+
title: 'menus.model_metadata.manage.page_title', // 模型元数据管理
|
|
25
|
+
subTitle: 'menus.model_metadata.manage.page_subtitle', // 副标题
|
|
26
|
+
},
|
|
27
|
+
searchFields: [
|
|
28
|
+
{
|
|
29
|
+
prop: 'subject',
|
|
30
|
+
label: 'menus.model_metadata.manage.fields.subject', // 主题
|
|
31
|
+
placeholder: 'menus.model_metadata.manage.search_placeholder_subject', // 搜主题
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
prop: 'databaseName',
|
|
35
|
+
label: 'menus.model_metadata.manage.fields.databaseName', // 数据库名
|
|
36
|
+
placeholder: 'menus.model_metadata.manage.search_placeholder_databaseName', // 搜库名
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
prop: 'dbType',
|
|
40
|
+
label: 'menus.model_metadata.manage.fields.dbType', // 库类型
|
|
41
|
+
type: 'select',
|
|
42
|
+
options: [],
|
|
43
|
+
width: '120px',
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
prop: 'status',
|
|
47
|
+
label: 'menus.model_metadata.manage.fields.status',
|
|
48
|
+
type: 'select',
|
|
49
|
+
placeholder: 'common.status',
|
|
50
|
+
options: ENUM_DATA.commonStatus.option.map(({ label, value }) => ({
|
|
51
|
+
label,
|
|
52
|
+
value,
|
|
53
|
+
})),
|
|
54
|
+
width: '120px',
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
prop: 'createBy',
|
|
58
|
+
label: 'common.creator',
|
|
59
|
+
placeholder: 'menus.model_metadata.manage.search_placeholder_createBy', // 搜创建人
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
prop: 'createTime',
|
|
63
|
+
label: 'common.create_time',
|
|
64
|
+
type: 'dateRange',
|
|
65
|
+
rangeStartProp: 'createTimeStart',
|
|
66
|
+
rangeEndProp: 'createTimeEnd',
|
|
67
|
+
showTime: true,
|
|
68
|
+
format: 'YYYY-MM-DD HH:mm:ss',
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
statusToggle: {
|
|
72
|
+
dangerOnDisable: true,
|
|
73
|
+
disableConfirm: {
|
|
74
|
+
cancelText: 'common.cancel',
|
|
75
|
+
content: 'menus.model_metadata.manage.disable_confirm_content',
|
|
76
|
+
contentFields: 'subject',
|
|
77
|
+
okText: 'common.confirm',
|
|
78
|
+
title: 'menus.model_metadata.manage.disable_confirm_title',
|
|
79
|
+
},
|
|
80
|
+
enableConfirm: {
|
|
81
|
+
cancelText: 'common.cancel',
|
|
82
|
+
content: 'menus.model_metadata.manage.enable_confirm_content',
|
|
83
|
+
contentFields: 'subject',
|
|
84
|
+
okText: 'common.confirm',
|
|
85
|
+
title: 'menus.model_metadata.manage.enable_confirm_title',
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
submitAction: {
|
|
89
|
+
permission: 'model-metadata:add',
|
|
90
|
+
submitType: 'page',
|
|
91
|
+
labelKey: 'menus.model_metadata.manage.add', // 新增
|
|
92
|
+
},
|
|
93
|
+
detailAction: {
|
|
94
|
+
detailType: 'page',
|
|
95
|
+
labelKey: 'common.view',
|
|
96
|
+
},
|
|
97
|
+
table: {
|
|
98
|
+
scrollX: 'max-content',
|
|
99
|
+
},
|
|
100
|
+
deleteConfirm: {
|
|
101
|
+
title: 'menus.model_metadata.manage.delete_confirm_title', // 删除确认标题
|
|
102
|
+
content: 'menus.model_metadata.manage.delete_confirm_content', // 删除确认正文
|
|
103
|
+
okText: 'common.delete',
|
|
104
|
+
cancelText: 'common.cancel',
|
|
105
|
+
},
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
function IndexView() {
|
|
109
|
+
const { hasPermission, commonDictRevision } = useAuth()
|
|
110
|
+
const pageConfig = useListPageConfig()
|
|
111
|
+
|
|
112
|
+
const dbTypeSearchOptions = useMemo(
|
|
113
|
+
() =>
|
|
114
|
+
(DICT_DATA[DICT_KEY.dbType]?.option ?? []).map((o) => ({
|
|
115
|
+
label: o.name,
|
|
116
|
+
value: o.value,
|
|
117
|
+
})),
|
|
118
|
+
[commonDictRevision],
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
const listPageConfig = useMemo(
|
|
122
|
+
() => ({
|
|
123
|
+
...pageConfig,
|
|
124
|
+
searchFields: pageConfig.searchFields.map((f: any) =>
|
|
125
|
+
f.prop === 'dbType' ? { ...f, options: dbTypeSearchOptions } : f,
|
|
126
|
+
),
|
|
127
|
+
}),
|
|
128
|
+
[pageConfig, dbTypeSearchOptions],
|
|
129
|
+
)
|
|
130
|
+
/** 与主题列「跳转详情页」分离:操作列查看走弹窗,不经过 listPageConfig.onDetail 的 page 默认逻辑 */
|
|
131
|
+
const detailModalRef = useRef<{
|
|
132
|
+
open: (p?: any) => void
|
|
133
|
+
close: () => void
|
|
134
|
+
} | null>(null)
|
|
135
|
+
const submitModalRef = useRef<{
|
|
136
|
+
open: (p?: any) => void
|
|
137
|
+
close: () => void
|
|
138
|
+
} | null>(null)
|
|
139
|
+
|
|
140
|
+
const columns = useMemo(
|
|
141
|
+
() => [
|
|
142
|
+
{
|
|
143
|
+
title: 'menus.model_metadata.manage.fields.subject', // 主题
|
|
144
|
+
key: 'subject',
|
|
145
|
+
align: ALIGN.LEFT,
|
|
146
|
+
minWidth: 160,
|
|
147
|
+
render: (value: unknown, data: any) => (
|
|
148
|
+
<DetailLink
|
|
149
|
+
text={String(value ?? data?.subject ?? '-')}
|
|
150
|
+
disabled={!hasPermission('model-metadata:detail')}
|
|
151
|
+
onClick={() =>
|
|
152
|
+
listPageConfig.onDetail?.({
|
|
153
|
+
type: 'detail',
|
|
154
|
+
data,
|
|
155
|
+
config: listPageConfig.detailAction,
|
|
156
|
+
})
|
|
157
|
+
}
|
|
158
|
+
/>
|
|
159
|
+
),
|
|
160
|
+
},
|
|
161
|
+
{
|
|
162
|
+
title: 'menus.model_metadata.manage.fields.databaseName', // 数据库名
|
|
163
|
+
key: 'databaseName',
|
|
164
|
+
align: ALIGN.LEFT,
|
|
165
|
+
minWidth: 150,
|
|
166
|
+
ellipsis: true,
|
|
167
|
+
render: (value: unknown) => value ?? '-',
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
title: 'menus.model_metadata.manage.fields.schemaVersion', // 元数据版本
|
|
171
|
+
key: 'schemaVersion',
|
|
172
|
+
align: ALIGN.CENTER,
|
|
173
|
+
width: 120,
|
|
174
|
+
render: (value: unknown) => value ?? '-',
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
title: 'menus.model_metadata.manage.fields.dbType', // 库类型
|
|
178
|
+
key: 'dbType',
|
|
179
|
+
align: ALIGN.CENTER,
|
|
180
|
+
width: 100,
|
|
181
|
+
render: (value: unknown) => value ?? '-',
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
title: 'menus.model_metadata.manage.fields.host',
|
|
185
|
+
key: 'host',
|
|
186
|
+
align: ALIGN.LEFT,
|
|
187
|
+
width: 230,
|
|
188
|
+
ellipsis: true,
|
|
189
|
+
render: (_: unknown, record: any) => `${record.host ?? ''}:${record.port ?? ''}`,
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
title: 'menus.model_metadata.manage.fields.tableCount', // 表数量
|
|
193
|
+
key: 'tableCount',
|
|
194
|
+
align: ALIGN.CENTER,
|
|
195
|
+
width: 100,
|
|
196
|
+
render: (value: unknown) => value ?? 0,
|
|
197
|
+
},
|
|
198
|
+
{
|
|
199
|
+
title: 'common.status',
|
|
200
|
+
key: 'status',
|
|
201
|
+
align: ALIGN.CENTER,
|
|
202
|
+
width: 100,
|
|
203
|
+
render: (value: unknown) => <CxTag.Enabled value={value as number} />,
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
title: 'common.creator',
|
|
207
|
+
key: 'createBy',
|
|
208
|
+
align: ALIGN.LEFT,
|
|
209
|
+
width: 120,
|
|
210
|
+
render: (value: unknown) => value ?? '-',
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
title: 'common.create_time',
|
|
214
|
+
key: 'createTime',
|
|
215
|
+
align: ALIGN.LEFT,
|
|
216
|
+
width: 170,
|
|
217
|
+
render: (value: unknown) => value ?? '-',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
title: 'common.actions',
|
|
221
|
+
key: 'action',
|
|
222
|
+
align: ALIGN.LEFT,
|
|
223
|
+
width: 220,
|
|
224
|
+
render: (_: unknown, data: any) => {
|
|
225
|
+
const isEnabled = Number(data?.status) === 1
|
|
226
|
+
return (
|
|
227
|
+
<div className="flex flex-wrap gap-2">
|
|
228
|
+
{hasPermission('model-metadata:detail') && (
|
|
229
|
+
<CxButton.IconView
|
|
230
|
+
onClick={() =>
|
|
231
|
+
detailModalRef.current?.open({
|
|
232
|
+
opeType: 'detail',
|
|
233
|
+
opeId: data?.id,
|
|
234
|
+
data,
|
|
235
|
+
})
|
|
236
|
+
}
|
|
237
|
+
/>
|
|
238
|
+
)}
|
|
239
|
+
{hasPermission('model-metadata:enable') && !isEnabled && (
|
|
240
|
+
<CxButton.IconEnable
|
|
241
|
+
onClick={() =>
|
|
242
|
+
listPageConfig.onStatusToggle?.({
|
|
243
|
+
nextStatus: 1,
|
|
244
|
+
data,
|
|
245
|
+
})
|
|
246
|
+
}
|
|
247
|
+
/>
|
|
248
|
+
)}
|
|
249
|
+
{hasPermission('model-metadata:disable') && isEnabled && (
|
|
250
|
+
<CxButton.IconDisable
|
|
251
|
+
onClick={() =>
|
|
252
|
+
listPageConfig.onStatusToggle?.({
|
|
253
|
+
nextStatus: 0,
|
|
254
|
+
data,
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
/>
|
|
258
|
+
)}
|
|
259
|
+
{hasPermission('model-metadata:edit') && !isEnabled && (
|
|
260
|
+
<CxButton.IconEdit
|
|
261
|
+
onClick={() =>
|
|
262
|
+
listPageConfig.onEdit?.({
|
|
263
|
+
type: 'edit',
|
|
264
|
+
data,
|
|
265
|
+
config: listPageConfig.submitAction,
|
|
266
|
+
})
|
|
267
|
+
}
|
|
268
|
+
/>
|
|
269
|
+
)}
|
|
270
|
+
{hasPermission('model-metadata:delete') && !isEnabled && (
|
|
271
|
+
<CxButton.IconDelete onClick={() => listPageConfig.onDelete?.(data)} />
|
|
272
|
+
)}
|
|
273
|
+
</div>
|
|
274
|
+
)
|
|
275
|
+
},
|
|
276
|
+
},
|
|
277
|
+
],
|
|
278
|
+
[hasPermission, listPageConfig],
|
|
279
|
+
)
|
|
280
|
+
|
|
281
|
+
return (
|
|
282
|
+
<>
|
|
283
|
+
<ListPageView columns={columns} pageConfig={listPageConfig} />
|
|
284
|
+
<DetailModal
|
|
285
|
+
ref={detailModalRef}
|
|
286
|
+
onEditMain={(opeId) => {
|
|
287
|
+
submitModalRef.current?.open({
|
|
288
|
+
opeType: 'edit',
|
|
289
|
+
opeId,
|
|
290
|
+
data: { id: opeId },
|
|
291
|
+
})
|
|
292
|
+
}}
|
|
293
|
+
/>
|
|
294
|
+
<SubmitModal
|
|
295
|
+
ref={submitModalRef}
|
|
296
|
+
onOk={async () => {
|
|
297
|
+
await listPageConfig.fetchTableData?.()
|
|
298
|
+
}}
|
|
299
|
+
/>
|
|
300
|
+
</>
|
|
301
|
+
)
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export default IndexView
|
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
/** 表结构弹窗:类型、常量、与提交/校验相关的纯函数(供 modal 与 submit 共用) */
|
|
2
|
+
|
|
3
|
+
export const TABLE_SUBMIT_MODAL_WIDTH = 1400
|
|
4
|
+
export const TABLE_SUBMIT_MODAL_HEIGHT = 'min(95dvh, 95vh)'
|
|
5
|
+
|
|
6
|
+
export const COMMON_DATA_TYPES = [
|
|
7
|
+
'bigint',
|
|
8
|
+
'binary',
|
|
9
|
+
'bit',
|
|
10
|
+
'blob',
|
|
11
|
+
'bool',
|
|
12
|
+
'char',
|
|
13
|
+
'date',
|
|
14
|
+
'datetime',
|
|
15
|
+
'decimal',
|
|
16
|
+
'double',
|
|
17
|
+
'float',
|
|
18
|
+
'int',
|
|
19
|
+
'json',
|
|
20
|
+
'longtext',
|
|
21
|
+
'mediumint',
|
|
22
|
+
'mediumtext',
|
|
23
|
+
'smallint',
|
|
24
|
+
'text',
|
|
25
|
+
'time',
|
|
26
|
+
'timestamp',
|
|
27
|
+
'tinyint',
|
|
28
|
+
'varbinary',
|
|
29
|
+
'varchar',
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
export const INDEX_KIND_OPTIONS = [
|
|
33
|
+
{ value: 'NORMAL', label: 'NORMAL' },
|
|
34
|
+
{ value: 'UNIQUE', label: 'UNIQUE' },
|
|
35
|
+
{ value: 'FULLTEXT', label: 'FULLTEXT' },
|
|
36
|
+
{ value: 'SPATIAL', label: 'SPATIAL' },
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
export const INDEX_METHOD_OPTIONS = [
|
|
40
|
+
{ value: 'BTREE', label: 'BTREE' },
|
|
41
|
+
{ value: 'HASH', label: 'HASH' },
|
|
42
|
+
{ value: 'RTREE', label: 'RTREE' },
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
export const FK_RULE_VALUES = ['CASCADE', 'RESTRICT', 'SET NULL', 'NO ACTION'] as const
|
|
46
|
+
export const FK_RULE_OPTIONS = FK_RULE_VALUES.map((v) => ({
|
|
47
|
+
value: v,
|
|
48
|
+
label: v,
|
|
49
|
+
}))
|
|
50
|
+
|
|
51
|
+
export const tableEditSelectPopupMin = { minWidth: 120 } as const
|
|
52
|
+
export const cxSelectInTableProps = {
|
|
53
|
+
className: 'w-full min-w-0 max-w-full overflow-hidden',
|
|
54
|
+
popupMatchSelectWidth: false,
|
|
55
|
+
styles: { popup: { root: tableEditSelectPopupMin } },
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export const cxSelectFkProps = {
|
|
59
|
+
...cxSelectInTableProps,
|
|
60
|
+
showSearch: true,
|
|
61
|
+
allowClear: true,
|
|
62
|
+
optionFilterProp: 'label' as const,
|
|
63
|
+
filterOption: (input: string, option?: { label?: unknown; value?: string }) => {
|
|
64
|
+
const q = input.trim().toLowerCase()
|
|
65
|
+
if (!q) return true
|
|
66
|
+
const lv = String(option?.label ?? '').toLowerCase()
|
|
67
|
+
const vv = String(option?.value ?? '').toLowerCase()
|
|
68
|
+
return lv.includes(q) || vv.includes(q)
|
|
69
|
+
},
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
export const tableSubmitModalShellStyles = {
|
|
73
|
+
container: {
|
|
74
|
+
display: 'flex',
|
|
75
|
+
flexDirection: 'column' as const,
|
|
76
|
+
overflow: 'hidden',
|
|
77
|
+
height: TABLE_SUBMIT_MODAL_HEIGHT,
|
|
78
|
+
maxHeight: TABLE_SUBMIT_MODAL_HEIGHT,
|
|
79
|
+
},
|
|
80
|
+
body: {
|
|
81
|
+
flex: '1 1 0%',
|
|
82
|
+
minHeight: 0,
|
|
83
|
+
display: 'flex',
|
|
84
|
+
flexDirection: 'column' as const,
|
|
85
|
+
overflow: 'hidden',
|
|
86
|
+
},
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
export type SchemaTableBrief = {
|
|
90
|
+
tableName?: string
|
|
91
|
+
tableComment?: string
|
|
92
|
+
columns?: { columnName?: string; COLUMN_NAME?: string }[]
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export type Column = {
|
|
96
|
+
columnName: string
|
|
97
|
+
dataType: string
|
|
98
|
+
/** 是否隐私:0 否,1 是 */
|
|
99
|
+
privacyFlag?: number
|
|
100
|
+
charLength?: number
|
|
101
|
+
numericPrecision?: number
|
|
102
|
+
numericScale?: number
|
|
103
|
+
isNullable?: number
|
|
104
|
+
columnDefault?: string
|
|
105
|
+
commentText?: string
|
|
106
|
+
valueType?: number
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
export type IndexColumn = {
|
|
110
|
+
columnName: string
|
|
111
|
+
seqInIndex: number
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export type Index = {
|
|
115
|
+
indexName: string
|
|
116
|
+
isUnique?: number
|
|
117
|
+
indexType?: string
|
|
118
|
+
indexMethod?: string
|
|
119
|
+
indexColumns: IndexColumn[]
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
export type ForeignKeyColumn = {
|
|
123
|
+
columnName: string
|
|
124
|
+
referencedColumnName: string
|
|
125
|
+
seqInFk: number
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export type ForeignKey = {
|
|
129
|
+
fkName: string
|
|
130
|
+
referencedTableSchema?: string
|
|
131
|
+
referencedTable: string
|
|
132
|
+
updateRule?: string
|
|
133
|
+
deleteRule?: string
|
|
134
|
+
fkColumns: ForeignKeyColumn[]
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
export type TableDetail = {
|
|
138
|
+
tableSchema?: string
|
|
139
|
+
tableName: string
|
|
140
|
+
tableComment?: string
|
|
141
|
+
tableType?: string
|
|
142
|
+
columns: Column[]
|
|
143
|
+
indexes: Index[]
|
|
144
|
+
foreignKeys: ForeignKey[]
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function tableColumnNameList(table: SchemaTableBrief | undefined): string[] {
|
|
148
|
+
if (!table?.columns?.length) return []
|
|
149
|
+
const names = table.columns
|
|
150
|
+
.map((c) => c.columnName ?? c.COLUMN_NAME ?? '')
|
|
151
|
+
.filter(Boolean) as string[]
|
|
152
|
+
return [...new Set(names)]
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export function clonePart<T>(x: T): T {
|
|
156
|
+
return JSON.parse(JSON.stringify(x)) as T
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export function parseIndexColumnNames(s: string): IndexColumn[] {
|
|
160
|
+
const names = s
|
|
161
|
+
.split(',')
|
|
162
|
+
.map((x) => x.trim())
|
|
163
|
+
.filter(Boolean)
|
|
164
|
+
return names.map((columnName, i) => ({ columnName, seqInIndex: i + 1 }))
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** 反查预览 / 详情:indexColumns 为 { columnName, seqInIndex }[],seqInIndex 可能全为 0 */
|
|
168
|
+
export function normalizeIndexColumnsInput(raw: unknown): IndexColumn[] {
|
|
169
|
+
if (raw == null || raw === '') return []
|
|
170
|
+
if (!Array.isArray(raw) || raw.length === 0) return []
|
|
171
|
+
const mapped = (raw as { columnName?: string; seqInIndex?: number }[]).map((c, i) => ({
|
|
172
|
+
columnName: String(c.columnName ?? ''),
|
|
173
|
+
seqInIndex: typeof c.seqInIndex === 'number' ? c.seqInIndex : NaN,
|
|
174
|
+
_i: i,
|
|
175
|
+
}))
|
|
176
|
+
const rows = mapped.filter((x) => x.columnName)
|
|
177
|
+
if (rows.length === 0) return []
|
|
178
|
+
const hasPositiveSeq = rows.some((r) => Number(r.seqInIndex) > 0)
|
|
179
|
+
const ordered = hasPositiveSeq
|
|
180
|
+
? rows.slice().sort((a, b) => {
|
|
181
|
+
const sa = Number(a.seqInIndex) > 0 ? Number(a.seqInIndex) : 1e9 + a._i
|
|
182
|
+
const sb = Number(b.seqInIndex) > 0 ? Number(b.seqInIndex) : 1e9 + b._i
|
|
183
|
+
return sa - sb
|
|
184
|
+
})
|
|
185
|
+
: rows.slice().sort((a, b) => a._i - b._i)
|
|
186
|
+
return ordered.map((c, i) => ({ columnName: c.columnName, seqInIndex: i + 1 }))
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** 提交:indexColumns 为 { columnName, seqInIndex }[],seqInIndex 为下标+1 */
|
|
190
|
+
export function normalizeIndexColumnsForSubmit(raw: unknown) {
|
|
191
|
+
return normalizeIndexColumnsInput(raw).map((c, i) => ({
|
|
192
|
+
columnName: c.columnName,
|
|
193
|
+
seqInIndex: i + 1,
|
|
194
|
+
}))
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
export function indexColumnNamesForMultiSelect(cols: IndexColumn[] | undefined): string[] {
|
|
198
|
+
if (!cols?.length) return []
|
|
199
|
+
return cols
|
|
200
|
+
.slice()
|
|
201
|
+
.map((c, i) => ({ ...c, _i: i }))
|
|
202
|
+
.sort((a, b) => {
|
|
203
|
+
const d = (a.seqInIndex ?? 0) - (b.seqInIndex ?? 0)
|
|
204
|
+
return d !== 0 ? d : a._i - b._i
|
|
205
|
+
})
|
|
206
|
+
.map((c) => c.columnName)
|
|
207
|
+
.filter(Boolean)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export function getIndexKind(idx: Index): string {
|
|
211
|
+
if (idx.isUnique === 1) return 'UNIQUE'
|
|
212
|
+
const t = (idx.indexType || '').toUpperCase()
|
|
213
|
+
if (t.includes('FULLTEXT')) return 'FULLTEXT'
|
|
214
|
+
if (t.includes('SPATIAL')) return 'SPATIAL'
|
|
215
|
+
if (t === 'UNIQUE') return 'UNIQUE'
|
|
216
|
+
return 'NORMAL'
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export function applyIndexKind(idx: Index, kind: string): Index {
|
|
220
|
+
if (kind === 'UNIQUE') {
|
|
221
|
+
return { ...idx, isUnique: 1, indexType: 'UNIQUE' }
|
|
222
|
+
}
|
|
223
|
+
return { ...idx, isUnique: 0, indexType: kind }
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
export function fkColNamesForMultiSelect(
|
|
227
|
+
cols: ForeignKeyColumn[] | undefined,
|
|
228
|
+
key: 'columnName' | 'referencedColumnName',
|
|
229
|
+
): string[] {
|
|
230
|
+
if (!cols?.length) return []
|
|
231
|
+
return cols
|
|
232
|
+
.slice()
|
|
233
|
+
.map((c, i) => ({ ...c, _i: i }))
|
|
234
|
+
.sort((a, b) => {
|
|
235
|
+
const d = (a.seqInFk ?? 0) - (b.seqInFk ?? 0)
|
|
236
|
+
return d !== 0 ? d : a._i - b._i
|
|
237
|
+
})
|
|
238
|
+
.map((c) => String(c[key] ?? '').trim())
|
|
239
|
+
.filter(Boolean)
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function zipFkPairColumns(localArr: string[], refArr: string[]): ForeignKeyColumn[] {
|
|
243
|
+
const n = Math.max(localArr.length, refArr.length)
|
|
244
|
+
if (n === 0) return []
|
|
245
|
+
return Array.from({ length: n }, (_, i) => ({
|
|
246
|
+
columnName: localArr[i] ?? '',
|
|
247
|
+
referencedColumnName: refArr[i] ?? '',
|
|
248
|
+
seqInFk: i + 1,
|
|
249
|
+
}))
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/** 反查预览 / 详情:fkColumns 为 { columnName, referencedColumnName, seqInFk }[],seqInFk 可能全为 0 */
|
|
253
|
+
export function normalizeForeignKeyColumnsInput(raw: unknown): ForeignKeyColumn[] {
|
|
254
|
+
if (raw == null || raw === '') return []
|
|
255
|
+
if (!Array.isArray(raw) || raw.length === 0) return []
|
|
256
|
+
if (typeof raw[0] !== 'object' || raw[0] == null) return []
|
|
257
|
+
const mapped = (raw as { columnName?: string; referencedColumnName?: string; seqInFk?: number }[]).map(
|
|
258
|
+
(c, i) => ({
|
|
259
|
+
columnName: String(c.columnName ?? ''),
|
|
260
|
+
referencedColumnName: String(c.referencedColumnName ?? ''),
|
|
261
|
+
seqInFk: typeof c.seqInFk === 'number' ? c.seqInFk : NaN,
|
|
262
|
+
_i: i,
|
|
263
|
+
}),
|
|
264
|
+
)
|
|
265
|
+
const hasPositiveSeq = mapped.some((r) => Number(r.seqInFk) > 0)
|
|
266
|
+
const ordered = hasPositiveSeq
|
|
267
|
+
? mapped.slice().sort((a, b) => {
|
|
268
|
+
const sa = Number(a.seqInFk) > 0 ? Number(a.seqInFk) : 1e9 + a._i
|
|
269
|
+
const sb = Number(b.seqInFk) > 0 ? Number(b.seqInFk) : 1e9 + b._i
|
|
270
|
+
return sa - sb
|
|
271
|
+
})
|
|
272
|
+
: mapped.slice().sort((a, b) => a._i - b._i)
|
|
273
|
+
return ordered.map((c, i) => ({
|
|
274
|
+
columnName: c.columnName,
|
|
275
|
+
referencedColumnName: c.referencedColumnName,
|
|
276
|
+
seqInFk: i + 1,
|
|
277
|
+
}))
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/** 提交:fkColumns 每项 seqInFk 为下标+1 */
|
|
281
|
+
export function normalizeFkColumnsForSubmit(raw: unknown) {
|
|
282
|
+
return normalizeForeignKeyColumnsInput(raw).map((c, i) => ({
|
|
283
|
+
columnName: c.columnName,
|
|
284
|
+
referencedColumnName: c.referencedColumnName,
|
|
285
|
+
seqInFk: i + 1,
|
|
286
|
+
}))
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
export function validateForeignKeyRows(fks: unknown): string | null {
|
|
290
|
+
const list = Array.isArray(fks) ? fks : []
|
|
291
|
+
for (const fk of list) {
|
|
292
|
+
const cols = normalizeForeignKeyColumnsInput((fk as any)?.fkColumns)
|
|
293
|
+
const locs = cols.map((c) => String(c.columnName ?? '').trim()).filter(Boolean)
|
|
294
|
+
const refs = cols.map((c) => String(c.referencedColumnName ?? '').trim()).filter(Boolean)
|
|
295
|
+
const fkName = String((fk as any)?.fkName ?? '').trim()
|
|
296
|
+
const refTable = String((fk as any)?.referencedTable ?? '').trim()
|
|
297
|
+
const touched = Boolean(fkName || refTable || locs.length || refs.length)
|
|
298
|
+
if (!touched) continue
|
|
299
|
+
if (!fkName) return 'fk_name_required'
|
|
300
|
+
if (!refTable) return 'fk_referenced_table_required'
|
|
301
|
+
if (locs.length !== refs.length) return 'fk_columns_count_mismatch'
|
|
302
|
+
if (locs.length === 0) return 'fk_columns_required'
|
|
303
|
+
}
|
|
304
|
+
return null
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function validateForeignKeysInTables(tables: unknown): string | null {
|
|
308
|
+
const list = Array.isArray(tables) ? tables : []
|
|
309
|
+
for (const tb of list) {
|
|
310
|
+
const err = validateForeignKeyRows((tb as any)?.foreignKeys)
|
|
311
|
+
if (err) return err
|
|
312
|
+
}
|
|
313
|
+
return null
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
export function validateIndexRows(indexes: unknown): string | null {
|
|
317
|
+
const list = Array.isArray(indexes) ? indexes : []
|
|
318
|
+
for (const ix of list) {
|
|
319
|
+
const name = String((ix as any)?.indexName ?? '').trim()
|
|
320
|
+
const cols = normalizeIndexColumnsInput((ix as any)?.indexColumns)
|
|
321
|
+
const colNames = cols.map((c) => String(c.columnName ?? '').trim()).filter(Boolean)
|
|
322
|
+
const touched = Boolean(name || colNames.length)
|
|
323
|
+
if (!touched) continue
|
|
324
|
+
if (!name) return 'index_name_required'
|
|
325
|
+
if (colNames.length === 0) return 'index_columns_required'
|
|
326
|
+
}
|
|
327
|
+
return null
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
export function validateIndexesInTables(tables: unknown): string | null {
|
|
331
|
+
const list = Array.isArray(tables) ? tables : []
|
|
332
|
+
for (const tb of list) {
|
|
333
|
+
const err = validateIndexRows((tb as any)?.indexes)
|
|
334
|
+
if (err) return err
|
|
335
|
+
}
|
|
336
|
+
return null
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
export function isEmptyIndexRow(ix: unknown): boolean {
|
|
340
|
+
const name = String((ix as any)?.indexName ?? '').trim()
|
|
341
|
+
if (name) return false
|
|
342
|
+
return normalizeIndexColumnsInput((ix as any)?.indexColumns).length === 0
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export function isEmptyForeignKeyRow(fk: unknown): boolean {
|
|
346
|
+
const fkName = String((fk as any)?.fkName ?? '').trim()
|
|
347
|
+
const refTable = String((fk as any)?.referencedTable ?? '').trim()
|
|
348
|
+
if (fkName || refTable) return false
|
|
349
|
+
return normalizeForeignKeyColumnsInput((fk as any)?.fkColumns).length === 0
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
export const emptyColumn = (): Column => ({
|
|
353
|
+
columnName: '',
|
|
354
|
+
dataType: 'varchar',
|
|
355
|
+
privacyFlag: 0,
|
|
356
|
+
isNullable: 1,
|
|
357
|
+
commentText: '',
|
|
358
|
+
})
|
|
359
|
+
|
|
360
|
+
export const emptyIndex = (): Index => ({
|
|
361
|
+
indexName: '',
|
|
362
|
+
isUnique: 0,
|
|
363
|
+
indexType: 'NORMAL',
|
|
364
|
+
indexMethod: 'BTREE',
|
|
365
|
+
indexColumns: [],
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
export const emptyForeignKey = (): ForeignKey => ({
|
|
369
|
+
fkName: '',
|
|
370
|
+
referencedTable: '',
|
|
371
|
+
updateRule: 'NO ACTION',
|
|
372
|
+
deleteRule: 'NO ACTION',
|
|
373
|
+
fkColumns: [],
|
|
374
|
+
})
|