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,51 @@
|
|
|
1
|
+
.select-table {
|
|
2
|
+
.select-table-sidebar {
|
|
3
|
+
position: absolute;
|
|
4
|
+
height: 100%;
|
|
5
|
+
}
|
|
6
|
+
.select-table-view-right {
|
|
7
|
+
// 右侧面板
|
|
8
|
+
height: 100%;
|
|
9
|
+
}
|
|
10
|
+
&.select-table-tree {
|
|
11
|
+
.select-table-view-right {
|
|
12
|
+
margin-left: 340px;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
&.select-table-multiple {
|
|
16
|
+
.select-table-sidebar {
|
|
17
|
+
height: calc(100% - 225px);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/* 搜索区控件聚焦态边框/光圈防裁切(尤其在 modal + overflow hidden 场景) */
|
|
22
|
+
.ant-form,
|
|
23
|
+
.ant-form-item,
|
|
24
|
+
.ant-form-item-control,
|
|
25
|
+
.ant-form-item-control-input,
|
|
26
|
+
.ant-form-item-control-input-content {
|
|
27
|
+
overflow: visible;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
.ant-form {
|
|
31
|
+
padding-left: 3px;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
.ant-form-item {
|
|
35
|
+
margin-bottom: 0;
|
|
36
|
+
padding: 2px 0;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* SelectTable 在 modal 内保持自身搜索区 form 布局,不受全局 modal form 纵向规则影响 */
|
|
41
|
+
.ant-modal-body .select-table form.ant-form {
|
|
42
|
+
display: flex !important;
|
|
43
|
+
flex-direction: row !important;
|
|
44
|
+
flex-wrap: nowrap !important;
|
|
45
|
+
align-items: center !important;
|
|
46
|
+
flex: 0 0 auto !important;
|
|
47
|
+
min-height: auto !important;
|
|
48
|
+
align-self: auto !important;
|
|
49
|
+
width: auto !important;
|
|
50
|
+
overflow: visible !important;
|
|
51
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** 与 `config/system` 首批 `systemName` 一致;接口返回后由 `setSystemConfig` 覆盖应用内展示。 */
|
|
2
|
+
export const DEFAULT_SYSTEM_NAME_FALLBACK = 'Agent Forge'
|
|
3
|
+
|
|
4
|
+
export function resolveInitialSystemName(
|
|
5
|
+
viteAppName: string | undefined,
|
|
6
|
+
): string {
|
|
7
|
+
const t = viteAppName?.trim()
|
|
8
|
+
return t || DEFAULT_SYSTEM_NAME_FALLBACK
|
|
9
|
+
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { getSysConfigAPI } from '@/api/system/sys-config'
|
|
2
|
+
import { resolveInitialSystemName } from '@/config/default-system-name'
|
|
3
|
+
import { resolveAvatarUrl } from '@/utils/url'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
|
|
6
|
+
export type SystemConfig = {
|
|
7
|
+
agentAvatar: string
|
|
8
|
+
browserIcon: string
|
|
9
|
+
copyright: string
|
|
10
|
+
loginPageName: string
|
|
11
|
+
showCopyright: boolean
|
|
12
|
+
systemLogo: string
|
|
13
|
+
systemName: string
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const SYS_KEYS = {
|
|
17
|
+
agentAvatar: 'AGENT_AVATAR',
|
|
18
|
+
browserIcon: 'BROWSER_ICON',
|
|
19
|
+
copyright: 'SYSTEM_COPYRIGHT',
|
|
20
|
+
loginPageName: 'LOGIN_PAGE_NAME',
|
|
21
|
+
showCopyright: 'SHOW_COPYRIGHT',
|
|
22
|
+
systemLogo: 'SYSTEM_LOGO',
|
|
23
|
+
systemName: 'SYSTEM_NAME',
|
|
24
|
+
} as const
|
|
25
|
+
|
|
26
|
+
const ENV_DEFAULTS: SystemConfig = {
|
|
27
|
+
systemName: resolveInitialSystemName(import.meta.env.VITE_APP_NAME),
|
|
28
|
+
loginPageName:
|
|
29
|
+
import.meta.env.VITE_APP_TITLE ||
|
|
30
|
+
import.meta.env.VITE_APP_NAME ||
|
|
31
|
+
'Agent Forge',
|
|
32
|
+
systemLogo: import.meta.env.VITE_APP_LOGO_URL || '',
|
|
33
|
+
browserIcon: '',
|
|
34
|
+
copyright: '',
|
|
35
|
+
showCopyright: true,
|
|
36
|
+
agentAvatar: '',
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
let systemConfig: SystemConfig = { ...ENV_DEFAULTS }
|
|
40
|
+
|
|
41
|
+
const systemConfigListeners = new Set<() => void>()
|
|
42
|
+
|
|
43
|
+
/** 订阅系统配置变更:保存系统配置后用于触发页面同步更新。 */
|
|
44
|
+
export function subscribeSystemConfig(listener: () => void): () => void {
|
|
45
|
+
systemConfigListeners.add(listener)
|
|
46
|
+
return () => {
|
|
47
|
+
systemConfigListeners.delete(listener)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
function notifySystemConfigChanged() {
|
|
52
|
+
for (const fn of systemConfigListeners) {
|
|
53
|
+
try {
|
|
54
|
+
fn()
|
|
55
|
+
} catch (e) {
|
|
56
|
+
// ignore
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** React Hook:获取系统配置并在变更时触发组件刷新。 */
|
|
62
|
+
export function useSystemConfig(): SystemConfig {
|
|
63
|
+
const [snap, setSnap] = React.useState(() => systemConfig)
|
|
64
|
+
React.useEffect(() => {
|
|
65
|
+
return subscribeSystemConfig(() => {
|
|
66
|
+
setSnap(systemConfig)
|
|
67
|
+
})
|
|
68
|
+
}, [])
|
|
69
|
+
return snap
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** 读取当前系统配置(入口加载后即为最新)。 */
|
|
73
|
+
export function getSystemConfig(): SystemConfig {
|
|
74
|
+
return systemConfig
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** 获取系统名称(用于 Header / 登录页等)。 */
|
|
78
|
+
export function getSystemName(): string {
|
|
79
|
+
return systemConfig.systemName
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/** 获取系统 Logo(用于 Header)。 */
|
|
83
|
+
export function getSystemLogoUrl(): string {
|
|
84
|
+
return systemConfig.systemLogo
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** 获取浏览器标题(用于 document.title)。 */
|
|
88
|
+
export function getBrowserTitle(): string {
|
|
89
|
+
return systemConfig.loginPageName || systemConfig.systemName
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** 获取浏览器图标(favicon)。 */
|
|
93
|
+
export function getBrowserIconUrl(): string {
|
|
94
|
+
return systemConfig.browserIcon
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/** 获取会话 Agent 头像(没有配置则返回空字符串)。 */
|
|
98
|
+
export function getChatAgentAvatarUrl(): string {
|
|
99
|
+
const raw = systemConfig.agentAvatar
|
|
100
|
+
if (!raw) return ''
|
|
101
|
+
return resolveAvatarUrl(raw) ?? raw
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function parseShowCopyright(raw: any): boolean {
|
|
105
|
+
if (raw === undefined || raw === null || raw === '') return true
|
|
106
|
+
if (raw === 1 || raw === true || raw === '1' || raw === 'true') return true
|
|
107
|
+
if (raw === 0 || raw === false || raw === '0' || raw === 'false') return false
|
|
108
|
+
return Boolean(raw)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function applyBrowserBranding(cfg: SystemConfig) {
|
|
112
|
+
document.title = cfg.loginPageName || cfg.systemName
|
|
113
|
+
|
|
114
|
+
const iconUrl = cfg.browserIcon
|
|
115
|
+
if (!iconUrl) return
|
|
116
|
+
|
|
117
|
+
const links = Array.from(document.querySelectorAll<HTMLLinkElement>("link[rel*='icon']"))
|
|
118
|
+
if (links.length > 0) {
|
|
119
|
+
for (const link of links) {
|
|
120
|
+
link.href = iconUrl
|
|
121
|
+
}
|
|
122
|
+
return
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const link = document.createElement('link')
|
|
126
|
+
link.rel = 'icon'
|
|
127
|
+
link.href = iconUrl
|
|
128
|
+
document.head.appendChild(link)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function resolveConfigsTextFromResponse(res: any): string {
|
|
132
|
+
const direct = res?.data
|
|
133
|
+
if (typeof direct === 'string') return direct
|
|
134
|
+
const nested = res?.data?.data
|
|
135
|
+
if (typeof nested === 'string') return nested
|
|
136
|
+
return ''
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** 加载系统配置:应用启动时调用(与免登录字典加载同批次)。 */
|
|
140
|
+
export async function loadSystemConfigOnBoot(): Promise<SystemConfig> {
|
|
141
|
+
const res: any = await getSysConfigAPI({ type: 'pageConfig' })
|
|
142
|
+
const configsText = resolveConfigsTextFromResponse(res)
|
|
143
|
+
if (!configsText) {
|
|
144
|
+
applyBrowserBranding(systemConfig)
|
|
145
|
+
notifySystemConfigChanged()
|
|
146
|
+
return systemConfig
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const obj = JSON.parse(configsText)
|
|
150
|
+
const next: SystemConfig = {
|
|
151
|
+
systemName: obj?.[SYS_KEYS.systemName] ?? ENV_DEFAULTS.systemName,
|
|
152
|
+
copyright: obj?.[SYS_KEYS.copyright] ?? '',
|
|
153
|
+
systemLogo: obj?.[SYS_KEYS.systemLogo] ?? '',
|
|
154
|
+
loginPageName: obj?.[SYS_KEYS.loginPageName] ?? '',
|
|
155
|
+
browserIcon: obj?.[SYS_KEYS.browserIcon] ?? '',
|
|
156
|
+
showCopyright: parseShowCopyright(obj?.[SYS_KEYS.showCopyright]),
|
|
157
|
+
agentAvatar: obj?.[SYS_KEYS.agentAvatar] ?? '',
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
systemConfig = { ...ENV_DEFAULTS, ...next }
|
|
161
|
+
applyBrowserBranding(systemConfig)
|
|
162
|
+
notifySystemConfigChanged()
|
|
163
|
+
return systemConfig
|
|
164
|
+
}
|
|
165
|
+
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
import React, { createContext, useContext, useState, useEffect, useLayoutEffect, useMemo } from 'react';
|
|
2
|
+
import { clearObfuscationKey } from '@/http/obfuscationKey';
|
|
3
|
+
import { axiosPostRequest, request } from '@/http/axios';
|
|
4
|
+
import type { User } from '../types';
|
|
5
|
+
import { useUserPreferences } from '../hooks/useUserPreferences';
|
|
6
|
+
import { getUserApiListAPI } from '@api/common/auth'
|
|
7
|
+
import { getUserInfoAPI } from '@api/system/user'
|
|
8
|
+
import { getStore, removeStore, setStore } from '@/utils/storage'
|
|
9
|
+
import { loadCommonDictData, registerDictDataLoadedNotifier } from '@/meta/index-dict'
|
|
10
|
+
|
|
11
|
+
interface AuthContextType {
|
|
12
|
+
user: User | null;
|
|
13
|
+
isAuthenticated: boolean;
|
|
14
|
+
isLoading: boolean;
|
|
15
|
+
/** 免登录 / 登录后字典任一侧完成一次写入 DICT_DATA(成功或失败)+1,供依赖字典的界面重渲染 */
|
|
16
|
+
commonDictRevision: number;
|
|
17
|
+
login: (token: string) => Promise<void>;
|
|
18
|
+
logout: () => Promise<void>;
|
|
19
|
+
refreshUser: () => Promise<void>;
|
|
20
|
+
hasPermission: (permission: string) => boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const AuthContext = createContext<AuthContextType | undefined>(undefined);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 将 getCurrentUserInfo 等返回的 { code, data: { id, name, ... } } 解包为扁平用户对象。
|
|
27
|
+
* axios 拦截器在 code===200 时返回整段业务体,用户信息在 `data` 内。
|
|
28
|
+
*/
|
|
29
|
+
function unwrapUserInfoBody(raw: any): any {
|
|
30
|
+
if (raw == null || typeof raw !== 'object') return raw;
|
|
31
|
+
const inner = raw.data;
|
|
32
|
+
if (
|
|
33
|
+
inner != null &&
|
|
34
|
+
typeof inner === 'object' &&
|
|
35
|
+
!Array.isArray(inner) &&
|
|
36
|
+
(inner.id != null ||
|
|
37
|
+
inner.name != null ||
|
|
38
|
+
inner.phone != null ||
|
|
39
|
+
inner.email != null)
|
|
40
|
+
) {
|
|
41
|
+
return { ...inner };
|
|
42
|
+
}
|
|
43
|
+
return raw;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function normalizePermissionCodes(raw: any): string[] {
|
|
47
|
+
const source =
|
|
48
|
+
raw?.permissions ??
|
|
49
|
+
raw?.permissionCodes ??
|
|
50
|
+
raw?.authorities ??
|
|
51
|
+
[];
|
|
52
|
+
|
|
53
|
+
if (!Array.isArray(source)) return [];
|
|
54
|
+
|
|
55
|
+
const list = source
|
|
56
|
+
.map((item: any) => {
|
|
57
|
+
if (typeof item === 'string') return item.trim();
|
|
58
|
+
if (item && typeof item === 'object') {
|
|
59
|
+
return String(
|
|
60
|
+
item.code ??
|
|
61
|
+
item.permission ??
|
|
62
|
+
item.permissionCode ??
|
|
63
|
+
item.authority ??
|
|
64
|
+
''
|
|
65
|
+
).trim();
|
|
66
|
+
}
|
|
67
|
+
return '';
|
|
68
|
+
})
|
|
69
|
+
.filter(Boolean);
|
|
70
|
+
|
|
71
|
+
return Array.from(new Set(list));
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export const AuthProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => {
|
|
75
|
+
const [user, setUser] = useState<User | null>(null);
|
|
76
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
77
|
+
const [commonDictRevision, setCommonDictRevision] = useState(0);
|
|
78
|
+
const { loadPreferences } = useUserPreferences();
|
|
79
|
+
|
|
80
|
+
useLayoutEffect(() => {
|
|
81
|
+
return registerDictDataLoadedNotifier(() => {
|
|
82
|
+
setCommonDictRevision((n) => n + 1);
|
|
83
|
+
});
|
|
84
|
+
}, []);
|
|
85
|
+
|
|
86
|
+
const fetchUser = async () => {
|
|
87
|
+
try {
|
|
88
|
+
// 基础资料:/user/getCurrentUserInfo(勿整对象合并 v1 me,避免覆盖姓名/手机)
|
|
89
|
+
let userInfo: any = unwrapUserInfoBody(await getUserInfoAPI());
|
|
90
|
+
|
|
91
|
+
let normalizedPermissions = normalizePermissionCodes(userInfo);
|
|
92
|
+
// 权限码:若用户信息里未带,则用 getUserApiListAPI 补齐(暂模拟,对齐旧 v1 users/me/get 的 permissions)
|
|
93
|
+
if (normalizedPermissions.length === 0) {
|
|
94
|
+
try {
|
|
95
|
+
const permRes: any = await getUserApiListAPI({});
|
|
96
|
+
const permList = Array.isArray(permRes?.data)
|
|
97
|
+
? permRes.data
|
|
98
|
+
: [];
|
|
99
|
+
const fromApi = normalizePermissionCodes({ permissions: permList });
|
|
100
|
+
if (fromApi.length) {
|
|
101
|
+
normalizedPermissions = fromApi;
|
|
102
|
+
userInfo = { ...userInfo, permissions: fromApi };
|
|
103
|
+
}
|
|
104
|
+
} catch (e) {
|
|
105
|
+
console.warn('[AuthContext] getUserApiListAPI failed', e);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const mergedUser: any = {
|
|
110
|
+
...userInfo,
|
|
111
|
+
permissions: normalizedPermissions,
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
setUser(mergedUser);
|
|
115
|
+
setStore('user', mergedUser);
|
|
116
|
+
// 登录成功后加载用户偏好设置
|
|
117
|
+
await loadPreferences(mergedUser);
|
|
118
|
+
// 通用字典不阻塞首屏;结束后由 index-dict / module 内通知 bump revision
|
|
119
|
+
void loadCommonDictData();
|
|
120
|
+
} catch (error: any) {
|
|
121
|
+
console.error('获取用户信息失败', error);
|
|
122
|
+
console.log('[AuthContext] 错误详情:', {
|
|
123
|
+
status: error.response?.status,
|
|
124
|
+
data: error.response?.data,
|
|
125
|
+
message: error.message
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
// 检查是否为网络错误(离线)
|
|
129
|
+
// Axios 'Network Error' 通常没有 response 或 code 为 ERR_NETWORK
|
|
130
|
+
const isNetworkError = !error.response && error.code !== 'ECONNABORTED';
|
|
131
|
+
// 注意:401 由拦截器处理(登出/重定向)
|
|
132
|
+
|
|
133
|
+
if (isNetworkError) {
|
|
134
|
+
console.log('检测到网络错误,临时保持会话状态');
|
|
135
|
+
// 瞬时网络错误不执行登出
|
|
136
|
+
} else if (error.response?.status >= 500) {
|
|
137
|
+
console.log('服务器错误(5xx),保持会话状态');
|
|
138
|
+
// 服务器错误也不执行登出
|
|
139
|
+
} else {
|
|
140
|
+
// 其他错误...
|
|
141
|
+
// 如果是 400(错误请求),可能是验证或解密问题
|
|
142
|
+
// 401 由拦截器处理
|
|
143
|
+
// 最安全的做法是不立即登出,除非确定 token 无效
|
|
144
|
+
// 让拦截器处理 401
|
|
145
|
+
console.error('未处理的 fetchUser 错误,不立即登出:', error);
|
|
146
|
+
|
|
147
|
+
// logout(); // <-- 已禁用激进登出
|
|
148
|
+
}
|
|
149
|
+
} finally {
|
|
150
|
+
setIsLoading(false);
|
|
151
|
+
}
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
useEffect(() => {
|
|
155
|
+
const initAuth = () => {
|
|
156
|
+
const legacy = localStorage.getItem('token');
|
|
157
|
+
if (legacy && !getStore('token')) {
|
|
158
|
+
setStore('token', legacy);
|
|
159
|
+
localStorage.removeItem('token');
|
|
160
|
+
}
|
|
161
|
+
const token = getStore('token');
|
|
162
|
+
if (token) {
|
|
163
|
+
fetchUser();
|
|
164
|
+
} else {
|
|
165
|
+
setIsLoading(false);
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
|
|
169
|
+
initAuth();
|
|
170
|
+
|
|
171
|
+
const handleVisibilityChange = () => {
|
|
172
|
+
if (document.visibilityState === 'visible') {
|
|
173
|
+
const token = getStore('token');
|
|
174
|
+
if (token && !user) {
|
|
175
|
+
console.log('应用恢复且用户信息缺失,尝试恢复会话...');
|
|
176
|
+
fetchUser();
|
|
177
|
+
} else if (token) {
|
|
178
|
+
// 可选:根据需要静默刷新用户数据
|
|
179
|
+
// fetchUser();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
|
|
184
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
|
185
|
+
return () => {
|
|
186
|
+
document.removeEventListener('visibilitychange', handleVisibilityChange);
|
|
187
|
+
};
|
|
188
|
+
}, []);
|
|
189
|
+
|
|
190
|
+
const login = async (token: string) => {
|
|
191
|
+
setStore('token', token);
|
|
192
|
+
await fetchUser();
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
const logout = async () => {
|
|
196
|
+
/** 退出登录:带 token 调用后端作废,同时前端立刻清本地登录态 */
|
|
197
|
+
const token = getStore('token');
|
|
198
|
+
const req = request({
|
|
199
|
+
method: 'post',
|
|
200
|
+
url: '/auth/logout',
|
|
201
|
+
data: {},
|
|
202
|
+
headers: {
|
|
203
|
+
'Content-Type': 'application/json',
|
|
204
|
+
...(token ? { 'token-agent': `${token}` } : {}),
|
|
205
|
+
},
|
|
206
|
+
}).catch((error) => {
|
|
207
|
+
console.error('Logout failed:', error);
|
|
208
|
+
});
|
|
209
|
+
|
|
210
|
+
removeStore('token');
|
|
211
|
+
removeStore('user');
|
|
212
|
+
clearObfuscationKey();
|
|
213
|
+
setUser(null);
|
|
214
|
+
|
|
215
|
+
await req;
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
const permissionSet = useMemo(() => {
|
|
219
|
+
const normalized = normalizePermissionCodes(user);
|
|
220
|
+
return new Set(normalized);
|
|
221
|
+
}, [user]);
|
|
222
|
+
|
|
223
|
+
const hasPermission = (permission: string): boolean => {
|
|
224
|
+
if (!user) return false;
|
|
225
|
+
if (!permission) return true;
|
|
226
|
+
if (permissionSet.has('*')) return true;
|
|
227
|
+
if (Array.isArray((user as any).roles) && (user as any).roles.some((r: any) => String(r).toLowerCase() === 'admin')) {
|
|
228
|
+
return true;
|
|
229
|
+
}
|
|
230
|
+
return permissionSet.has(permission);
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
return (
|
|
234
|
+
<AuthContext.Provider
|
|
235
|
+
value={{
|
|
236
|
+
user,
|
|
237
|
+
isAuthenticated: !!user,
|
|
238
|
+
isLoading,
|
|
239
|
+
commonDictRevision,
|
|
240
|
+
login,
|
|
241
|
+
logout,
|
|
242
|
+
refreshUser: fetchUser,
|
|
243
|
+
hasPermission,
|
|
244
|
+
}}>
|
|
245
|
+
{children}
|
|
246
|
+
</AuthContext.Provider>
|
|
247
|
+
);
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
export const useAuth = () => {
|
|
251
|
+
const context = useContext(AuthContext);
|
|
252
|
+
if (context === undefined) {
|
|
253
|
+
throw new Error('useAuth 必须在 AuthProvider 内使用');
|
|
254
|
+
}
|
|
255
|
+
return context;
|
|
256
|
+
};
|