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,361 @@
|
|
|
1
|
+
import React, {
|
|
2
|
+
useCallback,
|
|
3
|
+
useEffect,
|
|
4
|
+
useLayoutEffect,
|
|
5
|
+
useMemo,
|
|
6
|
+
useRef,
|
|
7
|
+
useState,
|
|
8
|
+
} from 'react';
|
|
9
|
+
import { createPortal } from 'react-dom';
|
|
10
|
+
import { ChevronDown, Check, Search } from 'lucide-react';
|
|
11
|
+
import clsx from 'clsx';
|
|
12
|
+
import { useTranslation } from 'react-i18next';
|
|
13
|
+
|
|
14
|
+
export interface MultiSelectOption {
|
|
15
|
+
label: string;
|
|
16
|
+
value: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface MultiSelectProps {
|
|
20
|
+
options: MultiSelectOption[];
|
|
21
|
+
value: string[];
|
|
22
|
+
onChange: (value: string[]) => void;
|
|
23
|
+
placeholder?: string;
|
|
24
|
+
label?: string;
|
|
25
|
+
className?: string;
|
|
26
|
+
/**
|
|
27
|
+
* 在 antd Modal / Drawer 等容器里,为避免下拉被 overflow 裁剪,建议保持默认 true
|
|
28
|
+
*/
|
|
29
|
+
portal?: boolean;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const CxMultiSelect: React.FC<MultiSelectProps> = ({
|
|
33
|
+
options,
|
|
34
|
+
value,
|
|
35
|
+
onChange,
|
|
36
|
+
placeholder = 'Select options',
|
|
37
|
+
label,
|
|
38
|
+
className,
|
|
39
|
+
portal = true,
|
|
40
|
+
}) => {
|
|
41
|
+
const { t } = useTranslation();
|
|
42
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
43
|
+
const [searchTerm, setSearchTerm] = useState('');
|
|
44
|
+
const containerRef = useRef<HTMLDivElement>(null);
|
|
45
|
+
const triggerRef = useRef<HTMLDivElement>(null);
|
|
46
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
47
|
+
const [dropdownStyle, setDropdownStyle] = useState<React.CSSProperties>({});
|
|
48
|
+
const raf1Ref = useRef<number | null>(null);
|
|
49
|
+
const raf2Ref = useRef<number | null>(null);
|
|
50
|
+
|
|
51
|
+
// Close on click outside
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
54
|
+
const targetNode = event.target as Node;
|
|
55
|
+
const clickedInContainer =
|
|
56
|
+
containerRef.current && containerRef.current.contains(targetNode);
|
|
57
|
+
const clickedInDropdown =
|
|
58
|
+
dropdownRef.current && dropdownRef.current.contains(targetNode);
|
|
59
|
+
|
|
60
|
+
if (!clickedInContainer && !clickedInDropdown) {
|
|
61
|
+
setIsOpen(false);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
66
|
+
return () => document.removeEventListener('mousedown', handleClickOutside);
|
|
67
|
+
}, []);
|
|
68
|
+
|
|
69
|
+
const filteredOptions = useMemo(
|
|
70
|
+
() =>
|
|
71
|
+
options.filter(option =>
|
|
72
|
+
option.label.toLowerCase().includes(searchTerm.toLowerCase()),
|
|
73
|
+
),
|
|
74
|
+
[options, searchTerm],
|
|
75
|
+
);
|
|
76
|
+
|
|
77
|
+
const updateDropdownPosition = useCallback(() => {
|
|
78
|
+
if (!portal) return;
|
|
79
|
+
const el = triggerRef.current;
|
|
80
|
+
if (!el) return;
|
|
81
|
+
const rect = el.getBoundingClientRect();
|
|
82
|
+
setDropdownStyle({
|
|
83
|
+
position: 'fixed',
|
|
84
|
+
left: rect.left,
|
|
85
|
+
top: rect.bottom + 4,
|
|
86
|
+
width: rect.width,
|
|
87
|
+
zIndex: 2000, // 高于 antd Modal 内容层,避免被遮挡
|
|
88
|
+
});
|
|
89
|
+
}, [portal]);
|
|
90
|
+
|
|
91
|
+
const scheduleUpdatePosition = useCallback(() => {
|
|
92
|
+
if (!portal) return;
|
|
93
|
+
if (raf1Ref.current != null) cancelAnimationFrame(raf1Ref.current);
|
|
94
|
+
if (raf2Ref.current != null) cancelAnimationFrame(raf2Ref.current);
|
|
95
|
+
|
|
96
|
+
// 双帧:第一帧拿到本次 commit 后的位置,第二帧等布局/滚动条/动画更稳定
|
|
97
|
+
raf1Ref.current = requestAnimationFrame(() => {
|
|
98
|
+
updateDropdownPosition();
|
|
99
|
+
raf2Ref.current = requestAnimationFrame(() => {
|
|
100
|
+
updateDropdownPosition();
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}, [portal, updateDropdownPosition]);
|
|
104
|
+
|
|
105
|
+
// 组件卸载时清理 raf,避免 setState 警告
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
return () => {
|
|
108
|
+
if (raf1Ref.current != null) cancelAnimationFrame(raf1Ref.current);
|
|
109
|
+
if (raf2Ref.current != null) cancelAnimationFrame(raf2Ref.current);
|
|
110
|
+
};
|
|
111
|
+
}, []);
|
|
112
|
+
|
|
113
|
+
const toggleOption = (optionValue: string) => {
|
|
114
|
+
const newValue = value.includes(optionValue)
|
|
115
|
+
? value.filter(v => v !== optionValue)
|
|
116
|
+
: [...value, optionValue];
|
|
117
|
+
onChange(newValue);
|
|
118
|
+
scheduleUpdatePosition();
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const handleSelectAll = () => {
|
|
122
|
+
if (value.length === filteredOptions.length) {
|
|
123
|
+
// Deselect all visible
|
|
124
|
+
const visibleValues = filteredOptions.map(o => o.value);
|
|
125
|
+
onChange(value.filter(v => !visibleValues.includes(v)));
|
|
126
|
+
} else {
|
|
127
|
+
// Select all visible
|
|
128
|
+
const visibleValues = filteredOptions.map(o => o.value);
|
|
129
|
+
const newValue = [...new Set([...value, ...visibleValues])];
|
|
130
|
+
onChange(newValue);
|
|
131
|
+
}
|
|
132
|
+
scheduleUpdatePosition();
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
useEffect(() => {
|
|
136
|
+
if (!isOpen) return;
|
|
137
|
+
updateDropdownPosition();
|
|
138
|
+
|
|
139
|
+
const handleScrollOrResize = () => updateDropdownPosition();
|
|
140
|
+
window.addEventListener('resize', handleScrollOrResize);
|
|
141
|
+
// 捕获阶段监听滚动,兼容 modal body 内部滚动容器
|
|
142
|
+
window.addEventListener('scroll', handleScrollOrResize, true);
|
|
143
|
+
return () => {
|
|
144
|
+
window.removeEventListener('resize', handleScrollOrResize);
|
|
145
|
+
window.removeEventListener('scroll', handleScrollOrResize, true);
|
|
146
|
+
};
|
|
147
|
+
}, [isOpen, updateDropdownPosition]);
|
|
148
|
+
|
|
149
|
+
// 当选择/搜索导致表单布局变化时(比如 antd 校验提示出现/消失),需要同步更新位置
|
|
150
|
+
useLayoutEffect(() => {
|
|
151
|
+
if (!isOpen) return;
|
|
152
|
+
if (!portal) return;
|
|
153
|
+
scheduleUpdatePosition();
|
|
154
|
+
}, [isOpen, portal, updateDropdownPosition, searchTerm, value, filteredOptions]);
|
|
155
|
+
|
|
156
|
+
// 监听触发器尺寸变化(antd Form 的 help/extra 出现可能导致触发器位置变化)
|
|
157
|
+
useEffect(() => {
|
|
158
|
+
if (!isOpen) return;
|
|
159
|
+
if (!portal) return;
|
|
160
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
161
|
+
const el = triggerRef.current;
|
|
162
|
+
if (!el) return;
|
|
163
|
+
|
|
164
|
+
const ro = new ResizeObserver(() => {
|
|
165
|
+
scheduleUpdatePosition();
|
|
166
|
+
});
|
|
167
|
+
ro.observe(el);
|
|
168
|
+
return () => ro.disconnect();
|
|
169
|
+
}, [isOpen, portal, updateDropdownPosition]);
|
|
170
|
+
|
|
171
|
+
// 监听 body 尺寸变化(Modal 打开/关闭、滚动条出现/消失会影响 left/top)
|
|
172
|
+
useEffect(() => {
|
|
173
|
+
if (!isOpen) return;
|
|
174
|
+
if (!portal) return;
|
|
175
|
+
if (typeof ResizeObserver === 'undefined') return;
|
|
176
|
+
if (typeof document === 'undefined') return;
|
|
177
|
+
const ro = new ResizeObserver(() => {
|
|
178
|
+
scheduleUpdatePosition();
|
|
179
|
+
});
|
|
180
|
+
ro.observe(document.body);
|
|
181
|
+
return () => ro.disconnect();
|
|
182
|
+
}, [isOpen, portal, scheduleUpdatePosition]);
|
|
183
|
+
|
|
184
|
+
const renderTrigger = () => {
|
|
185
|
+
if (value.length === 0) {
|
|
186
|
+
return <span className="text-gray-500 dark:text-gray-400">{placeholder}</span>;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// Show summary: "Role (Selected 2)" or "角色 (已选2项)"
|
|
190
|
+
return (
|
|
191
|
+
<span className="text-gray-900 dark:text-white truncate">
|
|
192
|
+
{placeholder} <span className="text-blue-600 dark:text-blue-400">({t('common.selected_count', { count: value.length, defaultValue: `${value.length} selected` })})</span>
|
|
193
|
+
</span>
|
|
194
|
+
);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
return (
|
|
198
|
+
<div className={clsx("relative", className)} ref={containerRef}>
|
|
199
|
+
{label && (
|
|
200
|
+
<label className="block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">
|
|
201
|
+
{label}
|
|
202
|
+
</label>
|
|
203
|
+
)}
|
|
204
|
+
|
|
205
|
+
{/* Trigger Button */}
|
|
206
|
+
<div
|
|
207
|
+
ref={triggerRef}
|
|
208
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
209
|
+
className={clsx(
|
|
210
|
+
"w-full h-10 px-3 bg-gray-50 dark:bg-gray-900 border rounded-lg cursor-pointer flex items-center justify-between transition-colors text-sm",
|
|
211
|
+
isOpen ? "border-blue-500 ring-2 ring-blue-500/20" : "border-gray-200 dark:border-gray-700 hover:border-gray-300 dark:hover:border-gray-600"
|
|
212
|
+
)}
|
|
213
|
+
>
|
|
214
|
+
<div className="flex-1 overflow-hidden">
|
|
215
|
+
{renderTrigger()}
|
|
216
|
+
</div>
|
|
217
|
+
<ChevronDown size={16} className={clsx("text-gray-400 transition-transform ml-2", isOpen && "transform rotate-180")} />
|
|
218
|
+
</div>
|
|
219
|
+
|
|
220
|
+
{/* Dropdown Menu */}
|
|
221
|
+
{isOpen && !portal && (
|
|
222
|
+
<div
|
|
223
|
+
ref={dropdownRef}
|
|
224
|
+
className="absolute z-50 w-full mt-1 bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg max-h-80 flex flex-col"
|
|
225
|
+
>
|
|
226
|
+
{/* Search */}
|
|
227
|
+
<div className="p-2 border-b border-gray-200 dark:border-gray-700">
|
|
228
|
+
<div className="relative">
|
|
229
|
+
<Search size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" />
|
|
230
|
+
<input
|
|
231
|
+
type="text"
|
|
232
|
+
value={searchTerm}
|
|
233
|
+
onChange={e => setSearchTerm(e.target.value)}
|
|
234
|
+
placeholder={t('common.search', { defaultValue: 'Search...' })}
|
|
235
|
+
className="w-full pl-9 pr-3 py-1.5 text-sm bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 dark:text-white"
|
|
236
|
+
onClick={e => e.stopPropagation()}
|
|
237
|
+
/>
|
|
238
|
+
</div>
|
|
239
|
+
</div>
|
|
240
|
+
|
|
241
|
+
{/* Options List */}
|
|
242
|
+
<div className="overflow-y-auto flex-1 p-1">
|
|
243
|
+
{filteredOptions.length > 0 && (
|
|
244
|
+
<div
|
|
245
|
+
onClick={handleSelectAll}
|
|
246
|
+
className="px-3 py-2 text-sm text-blue-600 dark:text-blue-400 hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md cursor-pointer font-medium mb-1"
|
|
247
|
+
>
|
|
248
|
+
{value.length === filteredOptions.length ? t('common.unselect_all') : t('common.select_all')}
|
|
249
|
+
</div>
|
|
250
|
+
)}
|
|
251
|
+
|
|
252
|
+
{filteredOptions.length === 0 ? (
|
|
253
|
+
<div className="px-3 py-4 text-center text-sm text-gray-500 dark:text-gray-400">
|
|
254
|
+
{t('common.no_results', { defaultValue: 'No results found' })}
|
|
255
|
+
</div>
|
|
256
|
+
) : (
|
|
257
|
+
filteredOptions.map(option => {
|
|
258
|
+
const isSelected = value.includes(option.value);
|
|
259
|
+
return (
|
|
260
|
+
<div
|
|
261
|
+
key={option.value}
|
|
262
|
+
onClick={() => toggleOption(option.value)}
|
|
263
|
+
className={clsx(
|
|
264
|
+
"flex items-center px-3 py-2 text-sm rounded-md cursor-pointer transition-colors",
|
|
265
|
+
isSelected
|
|
266
|
+
? "bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-300"
|
|
267
|
+
: "text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800"
|
|
268
|
+
)}
|
|
269
|
+
>
|
|
270
|
+
<div className={clsx(
|
|
271
|
+
"w-4 h-4 rounded border flex items-center justify-center mr-3 transition-colors",
|
|
272
|
+
isSelected
|
|
273
|
+
? "bg-blue-600 border-blue-600"
|
|
274
|
+
: "border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800"
|
|
275
|
+
)}>
|
|
276
|
+
{isSelected && <Check size={10} className="text-white" />}
|
|
277
|
+
</div>
|
|
278
|
+
{option.label}
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
})
|
|
282
|
+
)}
|
|
283
|
+
</div>
|
|
284
|
+
</div>
|
|
285
|
+
)}
|
|
286
|
+
|
|
287
|
+
{isOpen && portal && typeof document !== 'undefined' &&
|
|
288
|
+
createPortal(
|
|
289
|
+
<div
|
|
290
|
+
ref={dropdownRef}
|
|
291
|
+
style={dropdownStyle}
|
|
292
|
+
className="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg max-h-80 flex flex-col"
|
|
293
|
+
onMouseDown={e => e.stopPropagation()}
|
|
294
|
+
onClick={e => e.stopPropagation()}
|
|
295
|
+
>
|
|
296
|
+
{/* Search */}
|
|
297
|
+
<div className="p-2 border-b border-gray-200 dark:border-gray-700">
|
|
298
|
+
<div className="relative">
|
|
299
|
+
<Search size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" />
|
|
300
|
+
<input
|
|
301
|
+
type="text"
|
|
302
|
+
value={searchTerm}
|
|
303
|
+
onChange={e => setSearchTerm(e.target.value)}
|
|
304
|
+
placeholder={t('common.search', { defaultValue: 'Search...' })}
|
|
305
|
+
className="w-full pl-9 pr-3 py-1.5 text-sm bg-gray-50 dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-md focus:outline-none focus:ring-1 focus:ring-blue-500 dark:text-white"
|
|
306
|
+
onClick={e => e.stopPropagation()}
|
|
307
|
+
/>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
|
|
311
|
+
{/* Options List */}
|
|
312
|
+
<div className="overflow-y-auto flex-1 p-1">
|
|
313
|
+
{filteredOptions.length > 0 && (
|
|
314
|
+
<div
|
|
315
|
+
onClick={handleSelectAll}
|
|
316
|
+
className="px-3 py-2 text-sm text-blue-600 dark:text-blue-400 hover:bg-gray-50 dark:hover:bg-gray-800 rounded-md cursor-pointer font-medium mb-1"
|
|
317
|
+
>
|
|
318
|
+
{value.length === filteredOptions.length ? t('common.unselect_all') : t('common.select_all')}
|
|
319
|
+
</div>
|
|
320
|
+
)}
|
|
321
|
+
|
|
322
|
+
{filteredOptions.length === 0 ? (
|
|
323
|
+
<div className="px-3 py-4 text-center text-sm text-gray-500 dark:text-gray-400">
|
|
324
|
+
{t('common.no_results', { defaultValue: 'No results found' })}
|
|
325
|
+
</div>
|
|
326
|
+
) : (
|
|
327
|
+
filteredOptions.map(option => {
|
|
328
|
+
const isSelected = value.includes(option.value);
|
|
329
|
+
return (
|
|
330
|
+
<div
|
|
331
|
+
key={option.value}
|
|
332
|
+
onClick={() => toggleOption(option.value)}
|
|
333
|
+
className={clsx(
|
|
334
|
+
"flex items-center px-3 py-2 text-sm rounded-md cursor-pointer transition-colors",
|
|
335
|
+
isSelected
|
|
336
|
+
? "bg-blue-50 text-blue-700 dark:bg-blue-900/20 dark:text-blue-300"
|
|
337
|
+
: "text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800"
|
|
338
|
+
)}
|
|
339
|
+
>
|
|
340
|
+
<div className={clsx(
|
|
341
|
+
"w-4 h-4 rounded border flex items-center justify-center mr-3 transition-colors",
|
|
342
|
+
isSelected
|
|
343
|
+
? "bg-blue-600 border-blue-600"
|
|
344
|
+
: "border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800"
|
|
345
|
+
)}>
|
|
346
|
+
{isSelected && <Check size={10} className="text-white" />}
|
|
347
|
+
</div>
|
|
348
|
+
{option.label}
|
|
349
|
+
</div>
|
|
350
|
+
);
|
|
351
|
+
})
|
|
352
|
+
)}
|
|
353
|
+
</div>
|
|
354
|
+
</div>,
|
|
355
|
+
document.body,
|
|
356
|
+
)}
|
|
357
|
+
</div>
|
|
358
|
+
);
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
export default CxMultiSelect;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { GetProps } from 'antd'
|
|
2
|
+
import { Radio } from 'antd'
|
|
3
|
+
import React from 'react'
|
|
4
|
+
|
|
5
|
+
type AntRadioGroupProps = GetProps<typeof Radio.Group>
|
|
6
|
+
type AntRadioProps = GetProps<typeof Radio>
|
|
7
|
+
|
|
8
|
+
export type CxRadioOption = {
|
|
9
|
+
label: React.ReactNode
|
|
10
|
+
value: any
|
|
11
|
+
disabled?: boolean
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type CxRadioProps = Omit<AntRadioGroupProps, 'options'> & {
|
|
15
|
+
options: CxRadioOption[]
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** 单选按钮组:基于 antd Radio.Group,统一 options 的写法。 */
|
|
19
|
+
const CxRadioGroup: React.FC<CxRadioProps> = ({ options, ...rest }) => {
|
|
20
|
+
return <Radio.Group {...rest} options={options as any} />
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/** 单个单选按钮:基于 antd Radio。 */
|
|
24
|
+
const CxRadioPrimitive: React.FC<AntRadioProps> = (props) => {
|
|
25
|
+
return <Radio {...props} />
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const CxRadio = Object.assign(CxRadioPrimitive, {
|
|
29
|
+
Group: CxRadioGroup,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
export default CxRadio
|
|
33
|
+
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
.cx-range-picker {
|
|
2
|
+
border-radius: 8px;
|
|
3
|
+
position: relative;
|
|
4
|
+
display: inline-flex;
|
|
5
|
+
align-items: center;
|
|
6
|
+
|
|
7
|
+
&.cx-range-picker--cxForm {
|
|
8
|
+
min-height: 42px;
|
|
9
|
+
height: 42px;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
&.cx-range-picker--cxSearch {
|
|
13
|
+
min-height: 40px;
|
|
14
|
+
height: 40px;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.ant-picker-input > input {
|
|
18
|
+
font-size: inherit;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Range 分隔符:保持在正常布局流里,并固定占位宽度。
|
|
22
|
+
* 这样「空值隐藏」与「focus/有值显示」之间不会发生宽度回跳,也不会与 placeholder 叠加。
|
|
23
|
+
*/
|
|
24
|
+
.ant-picker-range-separator {
|
|
25
|
+
width: 24px;
|
|
26
|
+
min-width: 24px;
|
|
27
|
+
display: inline-flex;
|
|
28
|
+
align-items: center;
|
|
29
|
+
justify-content: center;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* 固定两侧输入框占比,避免 placeholder 文案切换导致宽度跳动:
|
|
34
|
+
* - 空值态 RangePicker placeholder 可能是 ['', ''](浮动标签)
|
|
35
|
+
* - focus 态会显示真实 placeholder(文案更长)
|
|
36
|
+
*/
|
|
37
|
+
.ant-picker-input {
|
|
38
|
+
flex: 1 1 0;
|
|
39
|
+
min-width: 0;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* 日期时间范围:无值且未聚焦/未展开面板时,默认不展示分隔符;
|
|
45
|
+
* 有值或聚焦/展开时恢复展示,避免空态下出现突兀的“~ / -”。
|
|
46
|
+
*/
|
|
47
|
+
.cx-range-picker.cx-range-picker--noValue:not(.ant-picker-focused):not(.cx-range-picker--panelOpen) {
|
|
48
|
+
.ant-picker-range-separator {
|
|
49
|
+
opacity: 0;
|
|
50
|
+
visibility: hidden;
|
|
51
|
+
width: 24px;
|
|
52
|
+
min-width: 24px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/* 空值失焦态:仅修正右侧日历图标垂直居中(不影响分隔符/输入宽度) */
|
|
56
|
+
.ant-picker-suffix {
|
|
57
|
+
display: inline-flex;
|
|
58
|
+
align-items: center;
|
|
59
|
+
margin-top: 0;
|
|
60
|
+
margin-bottom: 0;
|
|
61
|
+
/* 只做视觉位移,不脱离文档流,避免 focus 前后宽度跳动 */
|
|
62
|
+
transform: translateY(-6px);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import type { GetProps } from 'antd'
|
|
2
|
+
import { ConfigProvider, DatePicker } from 'antd'
|
|
3
|
+
import zhCN from 'antd/locale/zh_CN'
|
|
4
|
+
import enUS from 'antd/locale/en_US'
|
|
5
|
+
import clsx from 'clsx'
|
|
6
|
+
import dayjs from 'dayjs'
|
|
7
|
+
import 'dayjs/locale/zh-cn'
|
|
8
|
+
import 'dayjs/locale/en'
|
|
9
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react'
|
|
10
|
+
|
|
11
|
+
import { CxFloatingShell } from '../floating-shell/CxFloatingShell'
|
|
12
|
+
import { hasCxFloatingValue } from '../floating-shell/has-floating-value'
|
|
13
|
+
import './index.less'
|
|
14
|
+
|
|
15
|
+
const { RangePicker } = DatePicker
|
|
16
|
+
|
|
17
|
+
type AntRangePickerProps = GetProps<typeof RangePicker>
|
|
18
|
+
|
|
19
|
+
const LOCALE_ENUM: Record<
|
|
20
|
+
string,
|
|
21
|
+
{ antd: typeof zhCN; dayjs: string }
|
|
22
|
+
> = {
|
|
23
|
+
'zh-CN': { antd: zhCN, dayjs: 'zh-cn' },
|
|
24
|
+
'en-US': { antd: enUS, dayjs: 'en' },
|
|
25
|
+
zh: { antd: zhCN, dayjs: 'zh-cn' },
|
|
26
|
+
en: { antd: enUS, dayjs: 'en' },
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
type CxRangePickerOwn = {
|
|
30
|
+
cxFloatingLabel?: React.ReactNode
|
|
31
|
+
cxFocusPlaceholder?: [string, string]
|
|
32
|
+
/** 在控件容器上监听 Enter(antd RangePicker 无此 prop) */
|
|
33
|
+
onPressEnter?: () => void
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export type CxRangePickerProps = Omit<AntRangePickerProps, 'variant'> & CxRangePickerOwn
|
|
37
|
+
|
|
38
|
+
type CxRangePickerBaseProps = Omit<AntRangePickerProps, 'variant'> & CxRangePickerOwn
|
|
39
|
+
|
|
40
|
+
/** 判断浮动标签是否有效(避免 String() / Number() 这类强转)。 */
|
|
41
|
+
const hasNonEmptyFloatingLabel = (label: React.ReactNode): boolean => {
|
|
42
|
+
if (label == null || label === false) return false
|
|
43
|
+
if (typeof label === 'string') return label.trim().length > 0
|
|
44
|
+
return true
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** 获取浮动壳聚焦占位:优先 cxFocusPlaceholder,其次仅接受 [string,string] placeholder。 */
|
|
48
|
+
const resolveFocusPlaceholder = (
|
|
49
|
+
cxFocusPlaceholder: [string, string] | undefined,
|
|
50
|
+
placeholder: AntRangePickerProps['placeholder'] | undefined,
|
|
51
|
+
): [string, string] | undefined => {
|
|
52
|
+
if (cxFocusPlaceholder) return cxFocusPlaceholder
|
|
53
|
+
if (Array.isArray(placeholder) && placeholder.length >= 2) {
|
|
54
|
+
const p0 = placeholder[0]
|
|
55
|
+
const p1 = placeholder[1]
|
|
56
|
+
if (typeof p0 === 'string' && typeof p1 === 'string') return [p0, p1]
|
|
57
|
+
}
|
|
58
|
+
return undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** 解析页面语言:优先 html lang,其次回退 zh-CN。 */
|
|
62
|
+
const resolveDocumentLang = (): string => {
|
|
63
|
+
if (typeof document === 'undefined') return 'zh-CN'
|
|
64
|
+
const lang = document.documentElement.lang
|
|
65
|
+
return lang ? lang : 'zh-CN'
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** CxRangePicker 基础组件:统一 RangePicker 与浮动标签能力。 */
|
|
69
|
+
const CxRangePickerPrimitive: React.FC<CxRangePickerProps> = (props) => {
|
|
70
|
+
const {
|
|
71
|
+
className,
|
|
72
|
+
style = undefined,
|
|
73
|
+
cxFloatingLabel,
|
|
74
|
+
cxFocusPlaceholder,
|
|
75
|
+
placeholder,
|
|
76
|
+
value,
|
|
77
|
+
onOpenChange,
|
|
78
|
+
disabled,
|
|
79
|
+
onPressEnter,
|
|
80
|
+
...rest
|
|
81
|
+
} = props
|
|
82
|
+
|
|
83
|
+
/** 解析高度:默认 42,可通过 style.height 覆盖(数值)。 */
|
|
84
|
+
const resolveHeight = () => {
|
|
85
|
+
const h = style && typeof style === 'object' ? (style as { height?: unknown }).height : undefined
|
|
86
|
+
return typeof h === 'number' ? h : 42
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** 根据高度推导浮动壳的布局类型:40 及以下按搜索区,其他按表单区。 */
|
|
90
|
+
const shellVariant: 'cxForm' | 'cxSearch' = resolveHeight() <= 40 ? 'cxSearch' : 'cxForm'
|
|
91
|
+
|
|
92
|
+
const localeLang = resolveDocumentLang()
|
|
93
|
+
const localeConfig = LOCALE_ENUM[localeLang] || LOCALE_ENUM['zh-CN']
|
|
94
|
+
|
|
95
|
+
useEffect(() => {
|
|
96
|
+
dayjs.locale(localeConfig.dayjs)
|
|
97
|
+
}, [localeConfig.dayjs])
|
|
98
|
+
|
|
99
|
+
const useFloat = hasNonEmptyFloatingLabel(cxFloatingLabel)
|
|
100
|
+
const [panelOpen, setPanelOpen] = useState(false)
|
|
101
|
+
|
|
102
|
+
const hasValue = useMemo(() => hasCxFloatingValue(value, 'range'), [value])
|
|
103
|
+
const pickerRef = useRef<any>(null)
|
|
104
|
+
|
|
105
|
+
/** 控制日期范围分隔符显示:无值且未聚焦/未打开面板时默认隐藏。 */
|
|
106
|
+
const pickerClass = clsx(
|
|
107
|
+
'cx-range-picker',
|
|
108
|
+
shellVariant === 'cxSearch' ? 'cx-range-picker--cxSearch' : 'cx-range-picker--cxForm',
|
|
109
|
+
hasValue ? 'cx-range-picker--hasValue' : 'cx-range-picker--noValue',
|
|
110
|
+
panelOpen ? 'cx-range-picker--panelOpen' : null,
|
|
111
|
+
className,
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
const pickerStyle: React.CSSProperties = {
|
|
115
|
+
boxSizing: 'border-box',
|
|
116
|
+
...(style && typeof style === 'object' ? style : {}),
|
|
117
|
+
width: '100%',
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
const pickerEl = (
|
|
121
|
+
<RangePicker
|
|
122
|
+
{...(rest as AntRangePickerProps)}
|
|
123
|
+
disabled={disabled}
|
|
124
|
+
value={value}
|
|
125
|
+
ref={pickerRef}
|
|
126
|
+
className={pickerClass}
|
|
127
|
+
style={pickerStyle}
|
|
128
|
+
placeholder={useFloat ? ['', ''] : placeholder}
|
|
129
|
+
onOpenChange={(open) => {
|
|
130
|
+
const panel = Array.isArray(open) ? Boolean(open[0] || open[1]) : Boolean(open)
|
|
131
|
+
setPanelOpen(panel)
|
|
132
|
+
onOpenChange?.(open)
|
|
133
|
+
}}
|
|
134
|
+
/>
|
|
135
|
+
)
|
|
136
|
+
|
|
137
|
+
const inner = useFloat ? (
|
|
138
|
+
<CxFloatingShell
|
|
139
|
+
disabled={disabled}
|
|
140
|
+
focusPlaceholder={resolveFocusPlaceholder(cxFocusPlaceholder, placeholder)}
|
|
141
|
+
hasValue={hasValue}
|
|
142
|
+
label={cxFloatingLabel}
|
|
143
|
+
overlayOpen={panelOpen}
|
|
144
|
+
variant={shellVariant}
|
|
145
|
+
>
|
|
146
|
+
{pickerEl}
|
|
147
|
+
</CxFloatingShell>
|
|
148
|
+
) : (
|
|
149
|
+
pickerEl
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
<ConfigProvider locale={localeConfig.antd}>
|
|
154
|
+
<div
|
|
155
|
+
className="cx-range-picker-wrap"
|
|
156
|
+
onKeyDown={(e) => {
|
|
157
|
+
if (e.key !== 'Enter') return
|
|
158
|
+
onPressEnter?.()
|
|
159
|
+
}}
|
|
160
|
+
role="presentation">
|
|
161
|
+
{inner}
|
|
162
|
+
</div>
|
|
163
|
+
</ConfigProvider>
|
|
164
|
+
)
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/** Large:42px,高度偏表单主输入。 */
|
|
168
|
+
export function CxRangePickerLarge(props: CxRangePickerBaseProps): React.ReactElement
|
|
169
|
+
export function CxRangePickerLarge(props: CxRangePickerProps) {
|
|
170
|
+
return (
|
|
171
|
+
<CxRangePickerPrimitive
|
|
172
|
+
{...(props as any)}
|
|
173
|
+
style={{ ...(props as any)?.style, height: 42, minHeight: 42 }}
|
|
174
|
+
/>
|
|
175
|
+
)
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/** Medium:40px,高度偏搜索区输入。 */
|
|
179
|
+
export function CxRangePickerMedium(props: CxRangePickerBaseProps): React.ReactElement
|
|
180
|
+
export function CxRangePickerMedium(props: CxRangePickerProps) {
|
|
181
|
+
return (
|
|
182
|
+
<CxRangePickerPrimitive
|
|
183
|
+
{...(props as any)}
|
|
184
|
+
style={{ ...(props as any)?.style, height: 40, minHeight: 40 }}
|
|
185
|
+
/>
|
|
186
|
+
)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/** Small:32px,更紧凑。 */
|
|
190
|
+
export function CxRangePickerSmall(props: CxRangePickerBaseProps): React.ReactElement
|
|
191
|
+
export function CxRangePickerSmall(props: CxRangePickerProps) {
|
|
192
|
+
return (
|
|
193
|
+
<CxRangePickerPrimitive
|
|
194
|
+
{...(props as any)}
|
|
195
|
+
style={{ ...(props as any)?.style, height: 32, minHeight: 32 }}
|
|
196
|
+
/>
|
|
197
|
+
)
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
/** Float:第 4 种类型,浮动标签区间选择(使用 CxFloatingShell)。 */
|
|
201
|
+
export function CxRangePickerFloat(props: CxRangePickerBaseProps): React.ReactElement
|
|
202
|
+
export function CxRangePickerFloat(props: CxRangePickerBaseProps) {
|
|
203
|
+
const hasLabel = hasNonEmptyFloatingLabel((props as any)?.cxFloatingLabel)
|
|
204
|
+
return (
|
|
205
|
+
<CxRangePickerPrimitive
|
|
206
|
+
{...(props as any)}
|
|
207
|
+
cxFloatingLabel={hasLabel ? (props as any)?.cxFloatingLabel : (props as any)?.placeholder}
|
|
208
|
+
/>
|
|
209
|
+
)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const ExportedCxRangePicker = Object.assign(CxRangePickerPrimitive, {
|
|
213
|
+
Large: CxRangePickerLarge,
|
|
214
|
+
Medium: CxRangePickerMedium,
|
|
215
|
+
Small: CxRangePickerSmall,
|
|
216
|
+
Float: CxRangePickerFloat,
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
export default ExportedCxRangePicker
|