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,67 @@
|
|
|
1
|
+
import clsx from 'clsx'
|
|
2
|
+
import { ReactNode } from 'react'
|
|
3
|
+
import { useTranslation } from 'react-i18next'
|
|
4
|
+
import { CxTooltip } from '@cx-ui'
|
|
5
|
+
|
|
6
|
+
export type DetailLinkProps = {
|
|
7
|
+
/** 显示的文本内容 */
|
|
8
|
+
text: string
|
|
9
|
+
/** 点击事件 */
|
|
10
|
+
onClick?: () => void
|
|
11
|
+
/** 额外的渲染内容(如徽章、图标等) */
|
|
12
|
+
extra?: ReactNode
|
|
13
|
+
/** 自定义类名 */
|
|
14
|
+
className?: string
|
|
15
|
+
/** 是否禁用 */
|
|
16
|
+
disabled?: boolean
|
|
17
|
+
/** tooltip 提示文本,默认为"查看" */
|
|
18
|
+
title?: string
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 表格中可点击跳转详情的链接组件
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* // 基础用法
|
|
26
|
+
* <DetailLink text={record.name} onClick={() => handleDetail(record)} />
|
|
27
|
+
*
|
|
28
|
+
* @example
|
|
29
|
+
* // 带额外内容(如徽章)
|
|
30
|
+
* <DetailLink
|
|
31
|
+
* text={record.name}
|
|
32
|
+
* onClick={() => handleDetail(record)}
|
|
33
|
+
* extra={<span className="ml-2 px-2 py-0.5 text-xs bg-blue-100 text-blue-700 rounded-full">系统</span>}
|
|
34
|
+
* />
|
|
35
|
+
*/
|
|
36
|
+
export function DetailLink({
|
|
37
|
+
text,
|
|
38
|
+
onClick,
|
|
39
|
+
extra,
|
|
40
|
+
className,
|
|
41
|
+
disabled = false,
|
|
42
|
+
title,
|
|
43
|
+
}: DetailLinkProps) {
|
|
44
|
+
const { t } = useTranslation()
|
|
45
|
+
const tooltipTitle = title ?? t('common.view')
|
|
46
|
+
|
|
47
|
+
return (
|
|
48
|
+
<CxTooltip title={tooltipTitle}>
|
|
49
|
+
<button
|
|
50
|
+
type="button"
|
|
51
|
+
className={clsx(
|
|
52
|
+
'max-w-full cursor-pointer truncate text-blue-600 hover:underline dark:text-blue-400',
|
|
53
|
+
disabled && 'cursor-not-allowed opacity-50 hover:no-underline',
|
|
54
|
+
className,
|
|
55
|
+
)}
|
|
56
|
+
disabled={disabled}
|
|
57
|
+
onClick={disabled ? undefined : onClick}>
|
|
58
|
+
<span className="inline-flex items-center gap-1">
|
|
59
|
+
<span className="truncate">{text}</span>
|
|
60
|
+
{extra}
|
|
61
|
+
</span>
|
|
62
|
+
</button>
|
|
63
|
+
</CxTooltip>
|
|
64
|
+
)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
DetailLink.displayName = 'DetailLink'
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {Component} from 'react';
|
|
2
|
+
import type {ErrorInfo, ReactNode} from 'react';
|
|
3
|
+
import {AlertTriangle, RefreshCcw} from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
children?: ReactNode;
|
|
7
|
+
fallback?: ReactNode;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface State {
|
|
11
|
+
hasError: boolean;
|
|
12
|
+
error: Error | null;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class ErrorBoundary extends Component<Props, State> {
|
|
16
|
+
public state: State = {
|
|
17
|
+
hasError: false,
|
|
18
|
+
error: null,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
public static getDerivedStateFromError(error: Error): State {
|
|
22
|
+
return {hasError: true, error};
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
public componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
|
26
|
+
console.error('------- 全局错误边界捕获到错误 -------');
|
|
27
|
+
console.error('错误:', error);
|
|
28
|
+
console.error('组件堆栈:', errorInfo.componentStack);
|
|
29
|
+
console.error('----------------------------------------');
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
public handleReload = () => {
|
|
33
|
+
window.location.reload();
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
public render() {
|
|
37
|
+
if (this.state.hasError) {
|
|
38
|
+
if (this.props.fallback) {
|
|
39
|
+
return this.props.fallback;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return (
|
|
43
|
+
<div className="min-h-screen bg-gray-50 dark:bg-gray-900 flex flex-col items-center justify-center p-4">
|
|
44
|
+
<div
|
|
45
|
+
className="max-w-md w-full bg-white dark:bg-gray-800 rounded-xl shadow-lg p-8 text-center border border-gray-200 dark:border-gray-700">
|
|
46
|
+
<div
|
|
47
|
+
className="w-16 h-16 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center mx-auto mb-6">
|
|
48
|
+
<AlertTriangle className="w-8 h-8 text-red-600 dark:text-red-400"/>
|
|
49
|
+
</div>
|
|
50
|
+
<h1 className="text-2xl font-bold text-gray-900 dark:text-white mb-2">
|
|
51
|
+
出错了
|
|
52
|
+
</h1>
|
|
53
|
+
<p className="text-gray-500 dark:text-gray-400 mb-6">
|
|
54
|
+
应用程序遇到意外错误。请尝试重新加载页面。
|
|
55
|
+
</p>
|
|
56
|
+
|
|
57
|
+
{this.state.error && (
|
|
58
|
+
<div
|
|
59
|
+
className="mb-6 p-4 bg-gray-100 dark:bg-gray-900 rounded-lg text-left overflow-auto max-h-32 text-xs font-mono text-red-500">
|
|
60
|
+
{this.state.error.toString()}
|
|
61
|
+
</div>
|
|
62
|
+
)}
|
|
63
|
+
|
|
64
|
+
<button
|
|
65
|
+
onClick={this.handleReload}
|
|
66
|
+
className="inline-flex items-center gap-2 px-6 py-2.5 bg-blue-600 text-white rounded-lg hover:bg-blue-700 transition-colors font-medium shadow-sm focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 dark:focus:ring-offset-gray-800"
|
|
67
|
+
>
|
|
68
|
+
<RefreshCcw size={18}/>
|
|
69
|
+
重新加载应用
|
|
70
|
+
</button>
|
|
71
|
+
|
|
72
|
+
<div className="mt-8 pt-6 border-t border-gray-200 dark:border-gray-700 w-full">
|
|
73
|
+
<p className="text-sm text-gray-500 mb-3">
|
|
74
|
+
如果重新加载无法解决问题,请尝试重置应用程序。
|
|
75
|
+
<br/>
|
|
76
|
+
<span className="text-xs text-orange-500">
|
|
77
|
+
(这将清除您的本地会话和设置)
|
|
78
|
+
</span>
|
|
79
|
+
</p>
|
|
80
|
+
<button
|
|
81
|
+
onClick={() => {
|
|
82
|
+
localStorage.clear();
|
|
83
|
+
window.location.reload();
|
|
84
|
+
}}
|
|
85
|
+
className="text-sm text-red-600 hover:text-red-700 underline underline-offset-4"
|
|
86
|
+
>
|
|
87
|
+
重置应用并清除缓存
|
|
88
|
+
</button>
|
|
89
|
+
</div>
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
return this.props.children;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default ErrorBoundary;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { useUserPreferences } from '@/hooks/useUserPreferences';
|
|
2
|
+
import { setStore } from '@/utils/storage';
|
|
3
|
+
import { Check, Globe } from 'lucide-react';
|
|
4
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
5
|
+
import { useTranslation } from 'react-i18next';
|
|
6
|
+
|
|
7
|
+
const languages = [
|
|
8
|
+
{ code: 'zh', name: '简体中文', nativeName: '简体中文', displayCode: '中' },
|
|
9
|
+
{ code: 'en', name: 'English', nativeName: 'English', displayCode: 'EN' },
|
|
10
|
+
];
|
|
11
|
+
|
|
12
|
+
interface LanguageSwitcherProps {
|
|
13
|
+
direction?: 'up' | 'down';
|
|
14
|
+
/** 是否在按钮上显示当前语言代码(如 EN / ZH) */
|
|
15
|
+
showCode?: boolean;
|
|
16
|
+
/** 仅本地切换语言:不调用保存语言接口(用于登录页等未登录场景) */
|
|
17
|
+
localOnly?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const LanguageSwitcher: React.FC<LanguageSwitcherProps> = ({ direction = 'up', showCode = false, localOnly = false }) => {
|
|
21
|
+
const { i18n } = useTranslation();
|
|
22
|
+
const [isOpen, setIsOpen] = useState(false);
|
|
23
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
24
|
+
const { saveLanguage } = useUserPreferences();
|
|
25
|
+
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
28
|
+
if (dropdownRef.current && !dropdownRef.current.contains(event.target as Node)) {
|
|
29
|
+
setIsOpen(false);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (isOpen) {
|
|
34
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return () => {
|
|
38
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
39
|
+
};
|
|
40
|
+
}, [isOpen]);
|
|
41
|
+
|
|
42
|
+
const currentCode = String(i18n.language || '').toLowerCase().startsWith('zh') ? 'zh' : 'en';
|
|
43
|
+
const currentLanguage = languages.find(lang => lang.code === currentCode) || languages[0];
|
|
44
|
+
|
|
45
|
+
const handleLanguageChange = (langCode: string) => {
|
|
46
|
+
i18n.changeLanguage(langCode);
|
|
47
|
+
if (localOnly) {
|
|
48
|
+
// localStorage.setItem('i18nextLng', langCode);
|
|
49
|
+
setStore('i18nextLng', langCode);
|
|
50
|
+
} else {
|
|
51
|
+
saveLanguage(langCode); // Save to server
|
|
52
|
+
}
|
|
53
|
+
setIsOpen(false);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<div className="relative" ref={dropdownRef}>
|
|
58
|
+
<button
|
|
59
|
+
onClick={() => setIsOpen(!isOpen)}
|
|
60
|
+
className={`p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors text-gray-500 dark:text-gray-400${showCode ? ' flex items-center gap-1' : ''}`}
|
|
61
|
+
title={currentLanguage.nativeName}
|
|
62
|
+
>
|
|
63
|
+
<Globe size={20} />
|
|
64
|
+
{showCode && (
|
|
65
|
+
<span className="text-[11px] font-bold tracking-wide w-4 text-center">{currentLanguage.displayCode}</span>
|
|
66
|
+
)}
|
|
67
|
+
<span className="sr-only">Switch Language</span>
|
|
68
|
+
</button>
|
|
69
|
+
|
|
70
|
+
{isOpen && (
|
|
71
|
+
<div className={`absolute right-0 w-48 bg-white dark:bg-gray-800 border border-gray-200 dark:border-gray-700 rounded-lg shadow-lg py-1 z-50 ${direction === 'up' ? 'bottom-full mb-2' : 'top-full mt-2'
|
|
72
|
+
}`}>
|
|
73
|
+
{languages.map((lang) => (
|
|
74
|
+
<button
|
|
75
|
+
key={lang.code}
|
|
76
|
+
onClick={() => handleLanguageChange(lang.code)}
|
|
77
|
+
className="w-full flex items-center justify-between px-4 py-2 text-sm text-gray-700 dark:text-gray-300 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors"
|
|
78
|
+
>
|
|
79
|
+
<span>{lang.nativeName}</span>
|
|
80
|
+
{currentCode === lang.code && (
|
|
81
|
+
<Check size={16} className="text-blue-600 dark:text-blue-400" />
|
|
82
|
+
)}
|
|
83
|
+
</button>
|
|
84
|
+
))}
|
|
85
|
+
</div>
|
|
86
|
+
)}
|
|
87
|
+
</div>
|
|
88
|
+
);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export default LanguageSwitcher;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import clsx from 'clsx'
|
|
3
|
+
|
|
4
|
+
import type { ListRenderContext } from '@/components/table-view/components/table-view.types'
|
|
5
|
+
|
|
6
|
+
export function getRecordKey(record: any, rowKey: string): string | number {
|
|
7
|
+
const v = record?.[rowKey] ?? record?._id
|
|
8
|
+
if (v === undefined || v === null) {
|
|
9
|
+
return `__idx_${JSON.stringify(record).slice(0, 80)}`
|
|
10
|
+
}
|
|
11
|
+
return v
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function keysEqual(a: string | number, b: string | number) {
|
|
15
|
+
return String(a) === String(b)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export type LiteTableBaseProps = Pick<
|
|
19
|
+
ListRenderContext,
|
|
20
|
+
'columns' | 'renderCell' | 'tableData' | 't'
|
|
21
|
+
>
|
|
22
|
+
|
|
23
|
+
export type LiteTableProps = LiteTableBaseProps & {
|
|
24
|
+
/** 行主键字段,默认 `id` */
|
|
25
|
+
rowKey?: string
|
|
26
|
+
onRowClick?: (record: any, index: number) => void
|
|
27
|
+
rowClassName?: (record: any, index: number) => string
|
|
28
|
+
/** 包裹 table 的横向滚动容器 */
|
|
29
|
+
className?: string
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 从列表渲染上下文中取出 LiteTable 所需字段(忽略 `tree` 等) */
|
|
33
|
+
export function pickLiteTableProps(ctx: ListRenderContext): LiteTableBaseProps {
|
|
34
|
+
return {
|
|
35
|
+
columns: ctx.columns,
|
|
36
|
+
renderCell: ctx.renderCell,
|
|
37
|
+
tableData: ctx.tableData,
|
|
38
|
+
t: ctx.t,
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function columnAlignClass(align: string | undefined): string {
|
|
43
|
+
if (align === 'center') return 'text-center'
|
|
44
|
+
if (align === 'right') return 'text-right'
|
|
45
|
+
if (align === 'left') return 'text-left'
|
|
46
|
+
return ''
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** 与 antd Table 列约定一致:number 视为 px */
|
|
50
|
+
function columnWidthStyle(col: {
|
|
51
|
+
width?: number | string
|
|
52
|
+
}): React.CSSProperties | undefined {
|
|
53
|
+
const w = col.width
|
|
54
|
+
if (w === undefined || w === null || w === '') return undefined
|
|
55
|
+
return { width: typeof w === 'number' ? `${w}px` : w }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 轻量表格(原生 table):
|
|
60
|
+
* - 适合简单展示
|
|
61
|
+
* - 不依赖 antd Table
|
|
62
|
+
*/
|
|
63
|
+
export default function LiteTable(props: LiteTableProps) {
|
|
64
|
+
const {
|
|
65
|
+
className,
|
|
66
|
+
columns,
|
|
67
|
+
onRowClick,
|
|
68
|
+
renderCell,
|
|
69
|
+
rowClassName,
|
|
70
|
+
rowKey = 'id',
|
|
71
|
+
tableData,
|
|
72
|
+
t,
|
|
73
|
+
} = props
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<div className={clsx('overflow-x-auto', className)}>
|
|
77
|
+
<table className="w-full table-fixed text-left text-sm">
|
|
78
|
+
<thead className="bg-gray-50 dark:bg-gray-700/50 text-gray-500 dark:text-gray-400">
|
|
79
|
+
<tr>
|
|
80
|
+
{columns.map((col: any, index: number) => (
|
|
81
|
+
<th
|
|
82
|
+
key={(col.key as string) ?? col.dataIndex ?? index}
|
|
83
|
+
style={columnWidthStyle(col)}
|
|
84
|
+
className={clsx(
|
|
85
|
+
'px-3 py-4 font-medium',
|
|
86
|
+
columnAlignClass(col.headerAlign ?? col.align ?? 'left'),
|
|
87
|
+
)}>
|
|
88
|
+
{typeof col.title === 'string'
|
|
89
|
+
? t(col.title as any)
|
|
90
|
+
: ((col.title as React.ReactNode) ?? '')}
|
|
91
|
+
</th>
|
|
92
|
+
))}
|
|
93
|
+
</tr>
|
|
94
|
+
</thead>
|
|
95
|
+
<tbody className="divide-y divide-gray-200 dark:divide-gray-700">
|
|
96
|
+
{tableData.map((record: any, rowIndex: number) => (
|
|
97
|
+
<tr
|
|
98
|
+
key={String(getRecordKey(record, rowKey))}
|
|
99
|
+
role={onRowClick ? 'button' : undefined}
|
|
100
|
+
tabIndex={onRowClick ? 0 : undefined}
|
|
101
|
+
onClick={onRowClick ? () => onRowClick(record, rowIndex) : undefined}
|
|
102
|
+
onKeyDown={
|
|
103
|
+
onRowClick
|
|
104
|
+
? (e) => {
|
|
105
|
+
if (e.key === 'Enter' || e.key === ' ') {
|
|
106
|
+
e.preventDefault()
|
|
107
|
+
onRowClick(record, rowIndex)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
: undefined
|
|
111
|
+
}
|
|
112
|
+
className={clsx(
|
|
113
|
+
'transition-colors hover:bg-gray-50 dark:hover:bg-gray-700/50',
|
|
114
|
+
onRowClick && 'cursor-pointer',
|
|
115
|
+
rowClassName?.(record, rowIndex),
|
|
116
|
+
)}>
|
|
117
|
+
{columns.map((col: any, colIndex: number) => (
|
|
118
|
+
<td
|
|
119
|
+
key={(col.key as string) ?? col.dataIndex ?? colIndex}
|
|
120
|
+
style={columnWidthStyle(col)}
|
|
121
|
+
className={clsx(
|
|
122
|
+
'px-3 py-4 text-gray-900 dark:text-white',
|
|
123
|
+
columnAlignClass(col.align),
|
|
124
|
+
)}>
|
|
125
|
+
{renderCell(col, record, rowIndex)}
|
|
126
|
+
</td>
|
|
127
|
+
))}
|
|
128
|
+
</tr>
|
|
129
|
+
))}
|
|
130
|
+
</tbody>
|
|
131
|
+
</table>
|
|
132
|
+
</div>
|
|
133
|
+
)
|
|
134
|
+
}
|
|
135
|
+
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
import { useTranslation } from 'react-i18next'
|
|
3
|
+
import { cn } from '@/utils/cn'
|
|
4
|
+
import ReactMarkdown from 'react-markdown'
|
|
5
|
+
import remarkGfm from 'remark-gfm'
|
|
6
|
+
|
|
7
|
+
type Props = {
|
|
8
|
+
value?: string
|
|
9
|
+
onChange?: (next: string) => void
|
|
10
|
+
/** 挂最外层;作为 Form.Item 唯一直接子节点时用这里写高度,勿再外包 div(会接不到 value/onChange) */
|
|
11
|
+
className?: string
|
|
12
|
+
id?: string
|
|
13
|
+
disabled?: boolean
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** 左侧 Markdown 源码、右侧实时预览(与滚动大致同步) */
|
|
17
|
+
export function MdEditor({ value, onChange, className, id, disabled }: Props) {
|
|
18
|
+
const { t } = useTranslation()
|
|
19
|
+
const sourceRef = useRef<HTMLTextAreaElement | null>(null)
|
|
20
|
+
const previewRef = useRef<HTMLDivElement | null>(null)
|
|
21
|
+
const activeRef = useRef<0 | 1 | 2>(0)
|
|
22
|
+
const ignoreNextRef = useRef<{ source: boolean; preview: boolean }>({
|
|
23
|
+
source: false,
|
|
24
|
+
preview: false,
|
|
25
|
+
})
|
|
26
|
+
const rafRef = useRef<number | null>(null)
|
|
27
|
+
const releaseTimerRef = useRef<number | null>(null)
|
|
28
|
+
|
|
29
|
+
const scheduleRelease = () => {
|
|
30
|
+
if (releaseTimerRef.current != null) window.clearTimeout(releaseTimerRef.current)
|
|
31
|
+
releaseTimerRef.current = window.setTimeout(() => {
|
|
32
|
+
activeRef.current = 0
|
|
33
|
+
}, 120)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const syncScroll = (from: 1 | 2) => {
|
|
37
|
+
const sourceEl = sourceRef.current
|
|
38
|
+
const previewEl = previewRef.current
|
|
39
|
+
if (!sourceEl || !previewEl) return
|
|
40
|
+
activeRef.current = from
|
|
41
|
+
scheduleRelease()
|
|
42
|
+
|
|
43
|
+
if (rafRef.current != null) cancelAnimationFrame(rafRef.current)
|
|
44
|
+
rafRef.current = requestAnimationFrame(() => {
|
|
45
|
+
if (from === 1) {
|
|
46
|
+
ignoreNextRef.current.preview = true
|
|
47
|
+
const maxFrom = sourceEl.scrollHeight - sourceEl.clientHeight
|
|
48
|
+
const maxTo = previewEl.scrollHeight - previewEl.clientHeight
|
|
49
|
+
const ratio = maxFrom > 0 ? sourceEl.scrollTop / maxFrom : 0
|
|
50
|
+
previewEl.scrollTop = maxTo > 0 ? ratio * maxTo : 0
|
|
51
|
+
return
|
|
52
|
+
}
|
|
53
|
+
ignoreNextRef.current.source = true
|
|
54
|
+
const maxFrom = previewEl.scrollHeight - previewEl.clientHeight
|
|
55
|
+
const maxTo = sourceEl.scrollHeight - sourceEl.clientHeight
|
|
56
|
+
const ratio = maxFrom > 0 ? previewEl.scrollTop / maxFrom : 0
|
|
57
|
+
sourceEl.scrollTop = maxTo > 0 ? ratio * maxTo : 0
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
useEffect(() => {
|
|
62
|
+
return () => {
|
|
63
|
+
if (rafRef.current != null) cancelAnimationFrame(rafRef.current)
|
|
64
|
+
if (releaseTimerRef.current != null) window.clearTimeout(releaseTimerRef.current)
|
|
65
|
+
}
|
|
66
|
+
}, [])
|
|
67
|
+
|
|
68
|
+
return (
|
|
69
|
+
<div
|
|
70
|
+
id={id}
|
|
71
|
+
className={cn('flex h-full w-full min-h-0 gap-4 overflow-hidden', className)}
|
|
72
|
+
>
|
|
73
|
+
<div className="flex h-full min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800">
|
|
74
|
+
<div className="flex min-h-[44px] shrink-0 items-center border-b border-gray-200 bg-gray-50 px-3 py-2.5 dark:border-gray-700 dark:bg-gray-700/50">
|
|
75
|
+
<h3 className="line-clamp-1 py-0.5 text-xs font-semibold uppercase tracking-wider text-gray-700 dark:text-gray-300">
|
|
76
|
+
{t('common.md_editor.editor_source')}
|
|
77
|
+
</h3>
|
|
78
|
+
</div>
|
|
79
|
+
<div className="min-h-0 flex-1 overflow-hidden">
|
|
80
|
+
<textarea
|
|
81
|
+
ref={sourceRef}
|
|
82
|
+
className="h-full w-full min-h-0 resize-none overflow-auto border-0 bg-transparent p-3 font-mono text-sm text-gray-900 outline-none dark:text-gray-100"
|
|
83
|
+
placeholder={t('common.md_editor.raw_text_placeholder')}
|
|
84
|
+
value={value ?? ''}
|
|
85
|
+
disabled={disabled}
|
|
86
|
+
onChange={(e) => onChange?.(e.target.value)}
|
|
87
|
+
onScroll={() => {
|
|
88
|
+
if (ignoreNextRef.current.source) {
|
|
89
|
+
ignoreNextRef.current.source = false
|
|
90
|
+
return
|
|
91
|
+
}
|
|
92
|
+
if (activeRef.current === 0 || activeRef.current === 1) syncScroll(1)
|
|
93
|
+
}}
|
|
94
|
+
/>
|
|
95
|
+
</div>
|
|
96
|
+
</div>
|
|
97
|
+
|
|
98
|
+
<div className="flex h-full min-h-0 flex-1 flex-col overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm dark:border-gray-700 dark:bg-gray-800">
|
|
99
|
+
<div className="flex min-h-[44px] shrink-0 items-center border-b border-gray-200 bg-gray-50 px-3 py-2.5 dark:border-gray-700 dark:bg-gray-700/50">
|
|
100
|
+
<h3 className="line-clamp-1 py-0.5 text-xs font-semibold uppercase tracking-wider text-gray-700 dark:text-gray-300">
|
|
101
|
+
{t('common.md_editor.editor_preview')}
|
|
102
|
+
</h3>
|
|
103
|
+
</div>
|
|
104
|
+
<div
|
|
105
|
+
ref={previewRef}
|
|
106
|
+
className="prose prose-sm max-w-none min-h-0 flex-1 overflow-auto p-3 text-gray-900 dark:prose-invert dark:text-gray-100"
|
|
107
|
+
onScroll={() => {
|
|
108
|
+
if (ignoreNextRef.current.preview) {
|
|
109
|
+
ignoreNextRef.current.preview = false
|
|
110
|
+
return
|
|
111
|
+
}
|
|
112
|
+
if (activeRef.current === 0 || activeRef.current === 2) syncScroll(2)
|
|
113
|
+
}}
|
|
114
|
+
>
|
|
115
|
+
{(value ?? '').trim() ? (
|
|
116
|
+
<ReactMarkdown remarkPlugins={[remarkGfm]}>{value ?? ''}</ReactMarkdown>
|
|
117
|
+
) : (
|
|
118
|
+
<span className="not-prose text-sm text-gray-400">
|
|
119
|
+
{t('common.md_editor.preview_empty')}
|
|
120
|
+
</span>
|
|
121
|
+
)}
|
|
122
|
+
</div>
|
|
123
|
+
</div>
|
|
124
|
+
</div>
|
|
125
|
+
)
|
|
126
|
+
}
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import { AlertTriangle, X } from 'lucide-react'
|
|
3
|
+
import { useTranslation } from 'react-i18next'
|
|
4
|
+
|
|
5
|
+
import { CxButton, CxButtonCancel, CxButtonIcon } from '@cx-ui'
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 基于 `ui/ConfirmDialog` 的克隆:交互与 props 一致;底部与关闭使用 `CxButton`。
|
|
9
|
+
* `ui/ConfirmDialog.tsx` 保持不动作参考;需要本实现时在页面中改 import 指向本文件即可。
|
|
10
|
+
*/
|
|
11
|
+
interface ConfirmDialogProps {
|
|
12
|
+
isOpen: boolean
|
|
13
|
+
onClose: () => void
|
|
14
|
+
onConfirm: () => void
|
|
15
|
+
title: string
|
|
16
|
+
message: string
|
|
17
|
+
/** 遮罩层额外 class(如嵌套在 antd Modal 内时用 `z-[2000]` 盖住主弹窗) */
|
|
18
|
+
overlayClassName?: string
|
|
19
|
+
confirmText?: string
|
|
20
|
+
cancelText?: string
|
|
21
|
+
/** 为 true 时隐藏取消按钮(结果提示场景只需要一个按钮) */
|
|
22
|
+
hideCancel?: boolean
|
|
23
|
+
/** 为 true 时交换主/次按钮顺序 */
|
|
24
|
+
swapButtons?: boolean
|
|
25
|
+
danger?: boolean
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const ConfirmDialog: React.FC<ConfirmDialogProps> = ({
|
|
29
|
+
isOpen,
|
|
30
|
+
onClose,
|
|
31
|
+
onConfirm,
|
|
32
|
+
title,
|
|
33
|
+
message,
|
|
34
|
+
overlayClassName,
|
|
35
|
+
confirmText,
|
|
36
|
+
cancelText,
|
|
37
|
+
hideCancel = false,
|
|
38
|
+
swapButtons = false,
|
|
39
|
+
danger = false,
|
|
40
|
+
}) => {
|
|
41
|
+
const { t } = useTranslation()
|
|
42
|
+
|
|
43
|
+
if (!isOpen) return null
|
|
44
|
+
|
|
45
|
+
const overlayClass = ['fixed inset-0 bg-black/50 flex items-center justify-center p-4 z-50', overlayClassName]
|
|
46
|
+
.filter(Boolean)
|
|
47
|
+
.join(' ')
|
|
48
|
+
|
|
49
|
+
const confirmButton = danger ? (
|
|
50
|
+
<CxButton color="danger" variant="solid" onClick={onConfirm}>
|
|
51
|
+
{confirmText || t('common.confirm')}
|
|
52
|
+
</CxButton>
|
|
53
|
+
) : (
|
|
54
|
+
<CxButton type="primary" onClick={onConfirm}>
|
|
55
|
+
{confirmText || t('common.confirm')}
|
|
56
|
+
</CxButton>
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const cancelButton = hideCancel ? null : (
|
|
60
|
+
<CxButtonCancel onClick={onClose}>
|
|
61
|
+
{cancelText || t('common.cancel')}
|
|
62
|
+
</CxButtonCancel>
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
return (
|
|
66
|
+
<div className={overlayClass}>
|
|
67
|
+
<div className="bg-white dark:bg-gray-800 rounded-xl shadow-2xl max-w-md w-full">
|
|
68
|
+
<div className="p-6">
|
|
69
|
+
<div className="flex items-start gap-4">
|
|
70
|
+
{danger && (
|
|
71
|
+
<div className="flex-shrink-0 w-10 h-10 bg-red-100 dark:bg-red-900/30 rounded-full flex items-center justify-center">
|
|
72
|
+
<AlertTriangle
|
|
73
|
+
size={20}
|
|
74
|
+
className="text-red-600 dark:text-red-400"
|
|
75
|
+
/>
|
|
76
|
+
</div>
|
|
77
|
+
)}
|
|
78
|
+
<div className="flex-1 min-w-0">
|
|
79
|
+
<h3 className="text-lg font-semibold text-gray-900 dark:text-white mb-2">
|
|
80
|
+
{title}
|
|
81
|
+
</h3>
|
|
82
|
+
<p className="text-sm text-gray-600 dark:text-gray-400 whitespace-pre-line max-h-[45vh] overflow-auto pr-1">
|
|
83
|
+
{message}
|
|
84
|
+
</p>
|
|
85
|
+
</div>
|
|
86
|
+
<CxButtonIcon
|
|
87
|
+
type="default"
|
|
88
|
+
icon={<X size={20} />}
|
|
89
|
+
onClick={onClose}
|
|
90
|
+
title={t('common.close')}
|
|
91
|
+
className="text-gray-400 hover:text-gray-600 dark:hover:text-gray-200"
|
|
92
|
+
/>
|
|
93
|
+
</div>
|
|
94
|
+
</div>
|
|
95
|
+
<div className="px-6 py-4 bg-gray-50 dark:bg-gray-700/50 rounded-b-xl flex justify-end gap-3">
|
|
96
|
+
{swapButtons ? (
|
|
97
|
+
<>
|
|
98
|
+
{confirmButton}
|
|
99
|
+
{cancelButton}
|
|
100
|
+
</>
|
|
101
|
+
) : (
|
|
102
|
+
<>
|
|
103
|
+
{cancelButton}
|
|
104
|
+
{confirmButton}
|
|
105
|
+
</>
|
|
106
|
+
)}
|
|
107
|
+
</div>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export default ConfirmDialog
|