cx-chat 0.0.2 → 0.0.4
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/dist/cx-chat.css +1 -0
- package/dist/cx-chat.es.js +68257 -0
- package/dist/cx-chat.umd.js +492 -0
- package/package.json +27 -3
- package/.cursor/rules/i18n-cn-gloss-comments.mdc +0 -31
- package/.cursor/rules/list-page-view-pageconfig.mdc +0 -32
- package/.cursor/rules/no-over-defensive-programming.mdc +0 -90
- package/.cursor/rules/requirement-description-for-agent.mdc +0 -33
- package/.cursor/rules/use-showToast-not-antd-message.mdc +0 -28
- package/.docker/Dockerfile +0 -7
- package/.env +0 -9
- package/.env.development +0 -7
- package/.env.production +0 -7
- package/.gitlab-ci/docker-build.yaml +0 -28
- package/.gitlab-ci/k8s-deploy-dev-master.yaml +0 -42
- package/.gitlab-ci/npm-build.yaml +0 -17
- package/.gitlab-ci.yml +0 -8
- package/.k8s/0-namespace.yaml +0 -6
- package/.k8s/1-configmap-web.yaml +0 -7
- package/.k8s/1-nginx-conf-dev.yaml +0 -110
- package/.k8s/2-deployment.yaml +0 -27
- package/.k8s/3-service.yaml +0 -16
- package/.k8s/4-ingress-dev.yaml +0 -30
- package/.lingma/rules/use-showToast-not-antd-message.md +0 -34
- package/.nginx/nginx.conf +0 -52
- package/.prettierrc +0 -9
- package/eslint.config.js +0 -32
- package/index.html +0 -13
- package/postcss.config.js +0 -6
- package/src/App.tsx +0 -96
- package/src/_doc/0.docs-overview.md +0 -28
- package/src/_doc/cx-ui/0.docs-overview.md +0 -30
- package/src/_doc/cx-ui/comp.1.cx-ui-overview.md +0 -82
- package/src/_doc/cx-ui/comp.2.cx-modal.md +0 -82
- package/src/_doc/cx-ui/comp.3.cx-button.md +0 -89
- package/src/_doc/cx-ui/comp.4.cx-form.md +0 -72
- package/src/_doc/cx-ui/comp.5.cx-fields.md +0 -76
- package/src/_doc/cx-ui/comp.6.cx-tag.md +0 -57
- package/src/_doc/cx-ui/comp.7.cx-empty-state.md +0 -29
- package/src/_doc/meta/0.docs-overview.md +0 -24
- package/src/_doc/meta/comp.1.enum-runtime.md +0 -33
- package/src/_doc/meta/comp.2.dict-runtime.md +0 -39
- package/src/_doc/router/0.docs-overview.md +0 -14
- package/src/_doc/router/guide.1.menu-component-config.md +0 -181
- package/src/_doc/router/guide.2.router-auto-registration.md +0 -114
- package/src/_doc/table-view/0.docs-overview.md +0 -30
- package/src/_doc/table-view/comp.1.table-view.md +0 -542
- package/src/_doc/table-view/props.1.create-table-view-config.md +0 -193
- package/src/_doc/table-view/props.2.table-view-search-fields.md +0 -106
- package/src/api/_mock/README.md +0 -340
- package/src/api/_mock/api.ts +0 -1642
- package/src/api/_mock/bundle-shim.ts +0 -16
- package/src/api/_mock/handler-shim.ts +0 -6
- package/src/api/_mock/handler.ts +0 -458
- package/src/api/_mock/index.ts +0 -711
- package/src/api/_mock/interceptor.ts +0 -15
- package/src/api/_mock/mod.ts +0 -12
- package/src/api/_mock/utils.ts +0 -65
- package/src/api/base/memory.js +0 -24
- package/src/api/chat.js +0 -210
- package/src/api/common/auth.js +0 -70
- package/src/api/menus/business-rules.js +0 -76
- package/src/api/menus/feedback.js +0 -102
- package/src/api/menus/knowledge.js +0 -159
- package/src/api/menus/model-metadata/manage.js +0 -70
- package/src/api/menus/model-metadata/role.js +0 -50
- package/src/api/menus/model-metadata/training-detail-mock-data.js +0 -569
- package/src/api/menus/model-metadata/training.js +0 -28
- package/src/api/menus/skill.js +0 -40
- package/src/api/system/agent-config.js +0 -16
- package/src/api/system/department.js +0 -94
- package/src/api/system/dict.js +0 -86
- package/src/api/system/menu.js +0 -37
- package/src/api/system/permission.js +0 -26
- package/src/api/system/role.js +0 -34
- package/src/api/system/sys-config.js +0 -16
- package/src/api/system/sys-log.js +0 -17
- package/src/api/system/user.js +0 -75
- package/src/api/upload.js +0 -39
- package/src/assets/react.svg +0 -1
- package/src/components/auth/current-user-avatar.tsx +0 -77
- package/src/components/common/code-view.tsx +0 -149
- package/src/components/common/detail-link.tsx +0 -67
- package/src/components/common/error-boundary.tsx +0 -98
- package/src/components/common/language-switcher.tsx +0 -91
- package/src/components/common/lite-table/index.tsx +0 -135
- package/src/components/common/md-editor.tsx +0 -126
- package/src/components/common/modal/confirm-dialog.tsx +0 -113
- package/src/components/common/modal/dep-user-select-multi.tsx +0 -324
- package/src/components/common/modal/dep-user-select.tsx +0 -249
- package/src/components/common/modal/user-select-multi.tsx +0 -266
- package/src/components/common/pagination.tsx +0 -472
- package/src/components/common/path.tsx +0 -175
- package/src/components/common/system-logo-mark.tsx +0 -48
- package/src/components/cx-ui/button/index.less +0 -208
- package/src/components/cx-ui/button/index.tsx +0 -611
- package/src/components/cx-ui/checkbox/index.tsx +0 -78
- package/src/components/cx-ui/date-picker/index.less +0 -17
- package/src/components/cx-ui/date-picker/index.tsx +0 -193
- package/src/components/cx-ui/drawer/index.tsx +0 -47
- package/src/components/cx-ui/empty-state/index.tsx +0 -20
- package/src/components/cx-ui/floating-shell/CxFloatingShell.tsx +0 -89
- package/src/components/cx-ui/floating-shell/cx-floating-shell.less +0 -283
- package/src/components/cx-ui/floating-shell/has-floating-value.ts +0 -41
- package/src/components/cx-ui/form/CxForm.tsx +0 -15
- package/src/components/cx-ui/form/index.tsx +0 -20
- package/src/components/cx-ui/form-item/index.less +0 -26
- package/src/components/cx-ui/form-item/index.tsx +0 -36
- package/src/components/cx-ui/index.ts +0 -70
- package/src/components/cx-ui/input/auto-complete.tsx +0 -134
- package/src/components/cx-ui/input/index.tsx +0 -259
- package/src/components/cx-ui/input-number/index.jsx +0 -66
- package/src/components/cx-ui/modal/index.jsx +0 -212
- package/src/components/cx-ui/modal/index.less +0 -144
- package/src/components/cx-ui/modal/useCxModal.ts +0 -125
- package/src/components/cx-ui/multi-select/index.jsx +0 -74
- package/src/components/cx-ui/multi-select/index.less +0 -40
- package/src/components/cx-ui/multi-select/index2.tsx +0 -361
- package/src/components/cx-ui/radio/index.tsx +0 -33
- package/src/components/cx-ui/range-picker/index.less +0 -65
- package/src/components/cx-ui/range-picker/index.tsx +0 -219
- package/src/components/cx-ui/select/index.less +0 -34
- package/src/components/cx-ui/select/index.tsx +0 -196
- package/src/components/cx-ui/skeleton/index.tsx +0 -12
- package/src/components/cx-ui/steps/index.tsx +0 -14
- package/src/components/cx-ui/styles/_tokens.less +0 -79
- package/src/components/cx-ui/styles/index.less +0 -246
- package/src/components/cx-ui/switch/index.less +0 -106
- package/src/components/cx-ui/switch/index.tsx +0 -120
- package/src/components/cx-ui/table/index.less +0 -160
- package/src/components/cx-ui/table/index.tsx +0 -152
- package/src/components/cx-ui/tabs/index.less +0 -15
- package/src/components/cx-ui/tabs/index.tsx +0 -34
- package/src/components/cx-ui/tag/index.less +0 -51
- package/src/components/cx-ui/tag/index.tsx +0 -140
- package/src/components/cx-ui/timeline/index.tsx +0 -14
- package/src/components/cx-ui/tooltip/index.tsx +0 -67
- package/src/components/cx-ui/tree/index.tsx +0 -193
- package/src/components/cx-ui/tree-select/index.jsx +0 -91
- package/src/components/cx-ui/tree-select/index.less +0 -27
- package/src/components/cx-ui/upload-file/index.less +0 -223
- package/src/components/cx-ui/upload-file/index.tsx +0 -640
- package/src/components/cx-ui/upload-img/index.tsx +0 -291
- package/src/components/layout/components/Header.tsx +0 -216
- package/src/components/layout/components/Sidebar.tsx +0 -717
- package/src/components/layout/index.tsx +0 -95
- package/src/components/table-view/components/search-area.tsx +0 -411
- package/src/components/table-view/components/table-view-config.tsx +0 -528
- package/src/components/table-view/components/table-view.types.ts +0 -478
- package/src/components/table-view/components/tree-api-normalize.ts +0 -38
- package/src/components/table-view/components/tree-data-annotate.ts +0 -31
- package/src/components/table-view/components/tree-sidebar.tsx +0 -74
- package/src/components/table-view/index.tsx +0 -61
- package/src/components/table-view/list-page-view.tsx +0 -1049
- package/src/components/table-view/select-table-view.tsx +0 -1094
- package/src/components/table-view/styles/select-table-view.less +0 -51
- package/src/config/default-system-name.ts +0 -9
- package/src/config/system.ts +0 -165
- package/src/constants/countryCodes.ts +0 -3
- package/src/contexts/AuthContext.tsx +0 -256
- package/src/contexts/ChatContext.tsx +0 -839
- package/src/contexts/MenuContext.tsx +0 -62
- package/src/contexts/ToastContext.tsx +0 -181
- package/src/hooks/useCopyToClipboard.ts +0 -47
- package/src/hooks/useModalSubmit.ts +0 -104
- package/src/hooks/useRouter.ts +0 -240
- package/src/hooks/useStepForm.ts +0 -46
- package/src/hooks/useStickyHeader.ts +0 -42
- package/src/hooks/useThreadActions.ts +0 -105
- package/src/hooks/useUserPreferences.ts +0 -101
- package/src/http/axios.js +0 -372
- package/src/http/mock.interceptor.ts +0 -9
- package/src/http/obfuscationKey.ts +0 -41
- package/src/i18n.ts +0 -60
- package/src/index.js +0 -1
- package/src/index.less +0 -169
- package/src/locales/en/auth.ts +0 -70
- package/src/locales/en/base/memory.ts +0 -28
- package/src/locales/en/base/settings.ts +0 -41
- package/src/locales/en/chat.ts +0 -40
- package/src/locales/en/common.ts +0 -173
- package/src/locales/en/enum.ts +0 -27
- package/src/locales/en/menus/business-rules.ts +0 -48
- package/src/locales/en/menus/feedback.ts +0 -62
- package/src/locales/en/menus/knowledge.ts +0 -120
- package/src/locales/en/menus/model-metadata/index.ts +0 -10
- package/src/locales/en/menus/model-metadata/manage.ts +0 -151
- package/src/locales/en/menus/model-metadata/role.ts +0 -48
- package/src/locales/en/menus/model-metadata/training.ts +0 -65
- package/src/locales/en/menus/skill.ts +0 -34
- package/src/locales/en/system/agent-config.ts +0 -34
- package/src/locales/en/system/department.ts +0 -68
- package/src/locales/en/system/dict.ts +0 -44
- package/src/locales/en/system/menu.ts +0 -45
- package/src/locales/en/system/permission.ts +0 -89
- package/src/locales/en/system/role.ts +0 -25
- package/src/locales/en/system/sys-config.ts +0 -33
- package/src/locales/en/system/sys-log.ts +0 -38
- package/src/locales/en/system/user.ts +0 -113
- package/src/locales/en.ts +0 -68
- package/src/locales/zh/auth.ts +0 -70
- package/src/locales/zh/base/memory.ts +0 -29
- package/src/locales/zh/base/settings.ts +0 -41
- package/src/locales/zh/chat.ts +0 -47
- package/src/locales/zh/common.ts +0 -178
- package/src/locales/zh/enum.ts +0 -28
- package/src/locales/zh/menus/business-rules.ts +0 -47
- package/src/locales/zh/menus/feedback.ts +0 -62
- package/src/locales/zh/menus/knowledge.ts +0 -117
- package/src/locales/zh/menus/model-metadata/index.ts +0 -10
- package/src/locales/zh/menus/model-metadata/manage.ts +0 -151
- package/src/locales/zh/menus/model-metadata/role.ts +0 -47
- package/src/locales/zh/menus/model-metadata/training.ts +0 -64
- package/src/locales/zh/menus/skill.ts +0 -34
- package/src/locales/zh/system/agent-config.ts +0 -33
- package/src/locales/zh/system/department.ts +0 -69
- package/src/locales/zh/system/dict.ts +0 -44
- package/src/locales/zh/system/menu.ts +0 -47
- package/src/locales/zh/system/permission.ts +0 -94
- package/src/locales/zh/system/role.ts +0 -25
- package/src/locales/zh/system/sys-config.ts +0 -32
- package/src/locales/zh/system/sys-log.ts +0 -38
- package/src/locales/zh/system/user.ts +0 -114
- package/src/locales/zh.ts +0 -67
- package/src/main.tsx +0 -50
- package/src/meta/const/index.ts +0 -40
- package/src/meta/index-dict.ts +0 -56
- package/src/meta/index-enum.ts +0 -95
- package/src/meta/index.ts +0 -14
- package/src/meta/module/dict-data/runtime.ts +0 -199
- package/src/meta/module/dict-data/types.ts +0 -17
- package/src/meta/module/enum-data/runtime.ts +0 -75
- package/src/meta/module/enum-data/types.ts +0 -18
- package/src/router/index.tsx +0 -312
- package/src/styles/AntdThemeProvider.tsx +0 -40
- package/src/styles/antd-theme.ts +0 -20
- package/src/styles/global.less +0 -107
- package/src/styles/variable.less +0 -103
- package/src/types/feedback.ts +0 -43
- package/src/types/index.ts +0 -85
- package/src/types/menu.ts +0 -43
- package/src/utils/aesUtil.ts +0 -123
- package/src/utils/chatUtils.ts +0 -524
- package/src/utils/cn.ts +0 -6
- package/src/utils/crypto.ts +0 -164
- package/src/utils/date.ts +0 -72
- package/src/utils/file-icons.tsx +0 -79
- package/src/utils/index.ts +0 -168
- package/src/utils/markdown-math-plugins.ts +0 -21
- package/src/utils/menuI18n.ts +0 -305
- package/src/utils/menuRouteRegistry.ts +0 -78
- package/src/utils/permission-crud.ts +0 -147
- package/src/utils/routeConfig.ts +0 -350
- package/src/utils/storage.ts +0 -135
- package/src/utils/toastBridge.ts +0 -26
- package/src/utils/url.ts +0 -38
- package/src/utils/validation.ts +0 -16
- package/src/views/auth/auth-code/index.less +0 -169
- package/src/views/auth/auth-code/index.module.less +0 -174
- package/src/views/auth/auth-code/index.tsx +0 -233
- package/src/views/auth/login.tsx +0 -498
- package/src/views/auth/register.tsx +0 -388
- package/src/views/base/memory/index.tsx +0 -136
- package/src/views/base/memory/modal/detail-modal.tsx +0 -89
- package/src/views/base/memory/modal/submit-modal.tsx +0 -134
- package/src/views/base/settings/index.tsx +0 -657
- package/src/views/chat/chat.less +0 -323
- package/src/views/chat/components/chat-input.tsx +0 -298
- package/src/views/chat/components/header-thread-title.tsx +0 -210
- package/src/views/chat/components/message-list/content-answer.tsx +0 -100
- package/src/views/chat/components/message-list/content-question.tsx +0 -18
- package/src/views/chat/components/message-list/index.tsx +0 -520
- package/src/views/chat/components/message-list/message-item.tsx +0 -199
- package/src/views/chat/components/message-list/preparation-demo-items.ts +0 -147
- package/src/views/chat/components/message-list/preparation-steps.tsx +0 -506
- package/src/views/chat/components/message-list/suggestion-list.tsx +0 -36
- package/src/views/chat/components/message-list/thinking-process.tsx +0 -49
- package/src/views/chat/components/message-list/toolbar.tsx +0 -224
- package/src/views/chat/components/message-list/use-message-list-scroll.ts +0 -214
- package/src/views/chat/components/references-knowledge/context.tsx +0 -57
- package/src/views/chat/components/references-knowledge/index.ts +0 -9
- package/src/views/chat/components/references-knowledge/modal/knowledge-detail-drawer.tsx +0 -556
- package/src/views/chat/components/references-knowledge/modal/knowledge-doc-detail-drawer.tsx +0 -529
- package/src/views/chat/components/references-knowledge/panel.tsx +0 -115
- package/src/views/chat/hooks/use-chat-common.ts +0 -19
- package/src/views/chat/index-session.tsx +0 -647
- package/src/views/chat/index.tsx +0 -127
- package/src/views/page-error/401.tsx +0 -56
- package/src/views/page-error/404.tsx +0 -56
- package/src/views/page-menus/business-rules/index.tsx +0 -376
- package/src/views/page-menus/business-rules/modal/detail-modal.tsx +0 -186
- package/src/views/page-menus/business-rules/modal/scope-modal.tsx +0 -272
- package/src/views/page-menus/business-rules/modal/submit-modal.tsx +0 -142
- package/src/views/page-menus/feedback/components/feedback-dataset-list.tsx +0 -471
- package/src/views/page-menus/feedback/index.tsx +0 -166
- package/src/views/page-menus/feedback/modal/export-feedback-modal.tsx +0 -367
- package/src/views/page-menus/knowledge/components/doc-editor-by-type.tsx +0 -32
- package/src/views/page-menus/knowledge/components/doc-editor-type-file.tsx +0 -330
- package/src/views/page-menus/knowledge/detail.tsx +0 -600
- package/src/views/page-menus/knowledge/index.tsx +0 -337
- package/src/views/page-menus/knowledge/modal/detail-modal.tsx +0 -618
- package/src/views/page-menus/knowledge/modal/doc-detail-modal.tsx +0 -550
- package/src/views/page-menus/knowledge/modal/doc-parse.ts +0 -99
- package/src/views/page-menus/knowledge/modal/doc-submit-modal.tsx +0 -349
- package/src/views/page-menus/knowledge/modal/doc-type-picker-modal.tsx +0 -88
- package/src/views/page-menus/knowledge/modal/knowledge-user-select-modal.tsx +0 -283
- package/src/views/page-menus/knowledge/modal/submit-modal.tsx +0 -179
- package/src/views/page-menus/model-metadata/manage/components/metadata-detail-schema-tab.tsx +0 -114
- package/src/views/page-menus/model-metadata/manage/components/step1-basic-info.tsx +0 -232
- package/src/views/page-menus/model-metadata/manage/components/step2-schema.tsx +0 -316
- package/src/views/page-menus/model-metadata/manage/components/step3-permissions.tsx +0 -134
- package/src/views/page-menus/model-metadata/manage/components/step4-documents.tsx +0 -134
- package/src/views/page-menus/model-metadata/manage/components/step5-example-sql.tsx +0 -101
- package/src/views/page-menus/model-metadata/manage/components/submit-add.tsx +0 -338
- package/src/views/page-menus/model-metadata/manage/components/submit-edit.tsx +0 -276
- package/src/views/page-menus/model-metadata/manage/detail.tsx +0 -298
- package/src/views/page-menus/model-metadata/manage/hooks/model-metadata-submit-shared.ts +0 -113
- package/src/views/page-menus/model-metadata/manage/hooks/use-model-metadata-item-state.ts +0 -20
- package/src/views/page-menus/model-metadata/manage/index.tsx +0 -304
- package/src/views/page-menus/model-metadata/manage/modal/components/table-schema.ts +0 -374
- package/src/views/page-menus/model-metadata/manage/modal/components/use-table-detail-tabs.tsx +0 -151
- package/src/views/page-menus/model-metadata/manage/modal/components/use-table-submit-tabs.tsx +0 -423
- package/src/views/page-menus/model-metadata/manage/modal/detail-modal.tsx +0 -218
- package/src/views/page-menus/model-metadata/manage/modal/submit-modal.tsx +0 -261
- package/src/views/page-menus/model-metadata/manage/modal/table-detail-modal.tsx +0 -196
- package/src/views/page-menus/model-metadata/manage/modal/table-submit-modal.tsx +0 -229
- package/src/views/page-menus/model-metadata/manage/submit.tsx +0 -31
- package/src/views/page-menus/model-metadata/role/index.tsx +0 -207
- package/src/views/page-menus/model-metadata/role/modal/detail-modal.tsx +0 -97
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-modal.tsx +0 -254
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-panel.tsx +0 -393
- package/src/views/page-menus/model-metadata/role/modal/role-assign-users-utils.ts +0 -120
- package/src/views/page-menus/model-metadata/role/modal/role-permission-assign-panel.tsx +0 -698
- package/src/views/page-menus/model-metadata/role/modal/role-permission-modal.tsx +0 -237
- package/src/views/page-menus/model-metadata/role/modal/submit-modal.tsx +0 -135
- package/src/views/page-menus/model-metadata/training/components/detail-records/index.ts +0 -4
- package/src/views/page-menus/model-metadata/training/components/detail-records/node-card.tsx +0 -72
- package/src/views/page-menus/model-metadata/training/components/detail-records/summary-lines.ts +0 -196
- package/src/views/page-menus/model-metadata/training/components/detail-records/summary-list.tsx +0 -153
- package/src/views/page-menus/model-metadata/training/components/detail-records/timeline.tsx +0 -103
- package/src/views/page-menus/model-metadata/training/components/detail-records/types.ts +0 -82
- package/src/views/page-menus/model-metadata/training/detail.tsx +0 -159
- package/src/views/page-menus/model-metadata/training/index.tsx +0 -236
- package/src/views/page-menus/model-metadata/training/modal/update-detail-modal.tsx +0 -154
- package/src/views/page-menus/skill/index.tsx +0 -201
- package/src/views/page-menus/skill/modal/detail-modal.tsx +0 -156
- package/src/views/page-menus/skill/modal/submit-modal.tsx +0 -214
- package/src/views/page-system/agent-config/index.tsx +0 -370
- package/src/views/page-system/department/departmentFormShared.ts +0 -36
- package/src/views/page-system/department/index.tsx +0 -541
- package/src/views/page-system/department/modal/detail-modal.tsx +0 -94
- package/src/views/page-system/department/modal/member-role-modal.tsx +0 -128
- package/src/views/page-system/department/modal/submit-modal.tsx +0 -265
- package/src/views/page-system/dict/index.tsx +0 -440
- package/src/views/page-system/dict/modal/cate-submit-modal.tsx +0 -315
- package/src/views/page-system/dict/modal/submit-modal.tsx +0 -184
- package/src/views/page-system/logs/components/index.ts +0 -3
- package/src/views/page-system/logs/components/log-message-demo.tsx +0 -30
- package/src/views/page-system/logs/components/log-message-stream.ts +0 -184
- package/src/views/page-system/logs/components/message-list/content-answer.tsx +0 -100
- package/src/views/page-system/logs/components/message-list/content-question.tsx +0 -18
- package/src/views/page-system/logs/components/message-list/index.tsx +0 -515
- package/src/views/page-system/logs/components/message-list/message-item.tsx +0 -193
- package/src/views/page-system/logs/components/message-list/preparation-demo-items.ts +0 -147
- package/src/views/page-system/logs/components/message-list/preparation-steps.tsx +0 -506
- package/src/views/page-system/logs/components/message-list/suggestion-list.tsx +0 -36
- package/src/views/page-system/logs/components/message-list/thinking-process.tsx +0 -49
- package/src/views/page-system/logs/components/message-list/toolbar.tsx +0 -134
- package/src/views/page-system/logs/components/message-list/use-message-list-scroll.ts +0 -214
- package/src/views/page-system/logs/components/message-modal.tsx +0 -239
- package/src/views/page-system/logs/index.tsx +0 -132
- package/src/views/page-system/logs/modal/detail-modal.tsx +0 -157
- package/src/views/page-system/menu/components/menuFormShared.ts +0 -283
- package/src/views/page-system/menu/index.less +0 -12
- package/src/views/page-system/menu/index.tsx +0 -410
- package/src/views/page-system/menu/modal/icon-modal.less +0 -51
- package/src/views/page-system/menu/modal/icon-modal.tsx +0 -87
- package/src/views/page-system/menu/modal/submit-modal.tsx +0 -263
- package/src/views/page-system/permission/index.tsx +0 -562
- package/src/views/page-system/permission/modal/detail-modal.tsx +0 -179
- package/src/views/page-system/permission/modal/submit-modal.less +0 -146
- package/src/views/page-system/permission/modal/submit-modal.tsx +0 -650
- package/src/views/page-system/role/index.tsx +0 -163
- package/src/views/page-system/role/modal/detail-modal.tsx +0 -127
- package/src/views/page-system/role/modal/permission-assign-group-rules.ts +0 -86
- package/src/views/page-system/role/modal/permission-modal.tsx +0 -111
- package/src/views/page-system/role/modal/role-modal-shell-styles.ts +0 -21
- package/src/views/page-system/role/modal/role-permission-assign-panel.tsx +0 -916
- package/src/views/page-system/role/modal/role-permission-assign-shared.ts +0 -1047
- package/src/views/page-system/role/modal/submit-modal.tsx +0 -193
- package/src/views/page-system/sys-config/index.tsx +0 -294
- package/src/views/page-system/user/components/user-role-column.tsx +0 -87
- package/src/views/page-system/user/index.tsx +0 -439
- package/src/views/page-system/user/modal/assign-roles-modal.tsx +0 -389
- package/src/views/page-system/user/modal/detail-modal.tsx +0 -72
- package/src/views/page-system/user/modal/modal-style/submit-modal.less +0 -40
- package/src/views/page-system/user/modal/submit-modal.less +0 -40
- package/src/views/page-system/user/modal/submit-modal.tsx +0 -287
- package/src/views/page-system/user/userFormShared.ts +0 -51
- package/tailwind.config.js +0 -17
- package/tsconfig.app.json +0 -48
- package/tsconfig.json +0 -11
- package/tsconfig.node.json +0 -26
- package/vite.config.ts +0 -272
- /package/{public → dist}/favicon.ico +0 -0
- /package/{public → dist}/vite.svg +0 -0
package/src/utils/date.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 日期格式化(挂到 `Date.prototype.format`)。
|
|
3
|
-
* 占位符:`yyyy` `MM` `dd` `hh` `mm` `ss` `q`(季度)`S`(毫秒)等,与常见 legacy 写法一致。
|
|
4
|
-
*
|
|
5
|
-
* 解析后端字符串请用 {@link parseBackendDate},再调用 `.format(...)`。
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
declare global {
|
|
9
|
-
interface Date {
|
|
10
|
-
format(format?: string): string
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
function legacyFormat(this: Date, format?: string): string {
|
|
15
|
-
let fmt = 'yyyy-MM-dd'
|
|
16
|
-
if (format) fmt = format
|
|
17
|
-
const o: Record<string, number> = {
|
|
18
|
-
'M+': this.getMonth() + 1,
|
|
19
|
-
'd+': this.getDate(),
|
|
20
|
-
'h+': this.getHours(),
|
|
21
|
-
'm+': this.getMinutes(),
|
|
22
|
-
's+': this.getSeconds(),
|
|
23
|
-
'q+': Math.floor((this.getMonth() + 3) / 3),
|
|
24
|
-
S: this.getMilliseconds(),
|
|
25
|
-
}
|
|
26
|
-
const yMatch = fmt.match(/(y+)/)
|
|
27
|
-
if (yMatch) {
|
|
28
|
-
const yToken = yMatch[1]
|
|
29
|
-
fmt = fmt.replace(
|
|
30
|
-
yToken,
|
|
31
|
-
String(this.getFullYear()).substring(4 - yToken.length),
|
|
32
|
-
)
|
|
33
|
-
}
|
|
34
|
-
const keys = ['M+', 'd+', 'h+', 'm+', 's+', 'q+', 'S'] as const
|
|
35
|
-
for (const k of keys) {
|
|
36
|
-
const re = new RegExp(`(${k})`)
|
|
37
|
-
const m = fmt.match(re)
|
|
38
|
-
if (!m) continue
|
|
39
|
-
const token = m[1]
|
|
40
|
-
const v = o[k]
|
|
41
|
-
fmt = fmt.replace(
|
|
42
|
-
token,
|
|
43
|
-
token.length === 1
|
|
44
|
-
? String(v)
|
|
45
|
-
: (`00${v}`).substring(String(v).length),
|
|
46
|
-
)
|
|
47
|
-
}
|
|
48
|
-
return fmt
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line no-extend-native -- 项目约定:链式 `date.format('yyyy-MM-dd')`
|
|
52
|
-
Date.prototype.format = function format(this: Date, f?: string) {
|
|
53
|
-
return legacyFormat.call(this, f)
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 解析后端常见 ISO 时间串:含 `T` 且无 `Z`/offset 时追加 `Z`,按 UTC 解析。
|
|
58
|
-
* @returns 无效或空串时返回 `null`
|
|
59
|
-
*/
|
|
60
|
-
export function parseBackendDate(dateString?: string | null): Date | null {
|
|
61
|
-
if (!dateString) return null
|
|
62
|
-
let adjusted = dateString
|
|
63
|
-
if (
|
|
64
|
-
dateString.includes('T') &&
|
|
65
|
-
!dateString.includes('Z') &&
|
|
66
|
-
!/[+-]\d{2}:?\d{2}$/.test(dateString)
|
|
67
|
-
) {
|
|
68
|
-
adjusted = `${dateString}Z`
|
|
69
|
-
}
|
|
70
|
-
const d = new Date(adjusted)
|
|
71
|
-
return Number.isNaN(d.getTime()) ? null : d
|
|
72
|
-
}
|
package/src/utils/file-icons.tsx
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import React from 'react'
|
|
2
|
-
import {
|
|
3
|
-
FileExcelOutlined,
|
|
4
|
-
FileImageOutlined,
|
|
5
|
-
FileOutlined,
|
|
6
|
-
FilePdfOutlined,
|
|
7
|
-
FilePptOutlined,
|
|
8
|
-
FileTextOutlined,
|
|
9
|
-
FileWordOutlined,
|
|
10
|
-
} from '@ant-design/icons'
|
|
11
|
-
|
|
12
|
-
export type FileIconAsset = {
|
|
13
|
-
/** 图标节点(优先使用);适合直接复用 antd icon */
|
|
14
|
-
icon?: React.ReactNode
|
|
15
|
-
/** 静态资源地址(可选);如果你想后续换成图片图标,用 url 即可 */
|
|
16
|
-
url?: string
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
/** 文件后缀 → 图标资源配置(集中维护,方便后续复用/替换)。 */
|
|
20
|
-
export const FILE_EXT_ICON_ASSET_MAP: Record<string, FileIconAsset> = {
|
|
21
|
-
// 图片
|
|
22
|
-
png: { icon: <FileImageOutlined /> },
|
|
23
|
-
jpg: { icon: <FileImageOutlined /> },
|
|
24
|
-
jpeg: { icon: <FileImageOutlined /> },
|
|
25
|
-
gif: { icon: <FileImageOutlined /> },
|
|
26
|
-
webp: { icon: <FileImageOutlined /> },
|
|
27
|
-
bmp: { icon: <FileImageOutlined /> },
|
|
28
|
-
svg: { icon: <FileImageOutlined /> },
|
|
29
|
-
|
|
30
|
-
// 文档/表格/演示
|
|
31
|
-
pdf: { icon: <FilePdfOutlined /> },
|
|
32
|
-
doc: { icon: <FileWordOutlined /> },
|
|
33
|
-
docx: { icon: <FileWordOutlined /> },
|
|
34
|
-
xls: { icon: <FileExcelOutlined /> },
|
|
35
|
-
xlsx: { icon: <FileExcelOutlined /> },
|
|
36
|
-
csv: { icon: <FileExcelOutlined /> },
|
|
37
|
-
ppt: { icon: <FilePptOutlined /> },
|
|
38
|
-
pptx: { icon: <FilePptOutlined /> },
|
|
39
|
-
|
|
40
|
-
// 文本
|
|
41
|
-
txt: { icon: <FileTextOutlined /> },
|
|
42
|
-
md: { icon: <FileTextOutlined /> },
|
|
43
|
-
log: { icon: <FileTextOutlined /> },
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** 默认图标资源(未命中后缀映射时使用)。 */
|
|
47
|
-
export const DEFAULT_FILE_ICON_ASSET: FileIconAsset = {
|
|
48
|
-
icon: <FileOutlined />,
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/** 获取文件后缀(小写,不带点),支持带 query 的 url。 */
|
|
52
|
-
export function getLowerFileExt(nameOrUrl?: string) {
|
|
53
|
-
if (!nameOrUrl) return ''
|
|
54
|
-
const cleaned = nameOrUrl.split('?')[0]
|
|
55
|
-
const idx = cleaned.lastIndexOf('.')
|
|
56
|
-
if (idx < 0) return ''
|
|
57
|
-
return cleaned.slice(idx + 1).toLowerCase()
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/** 根据后缀获取图标资源(没命中返回默认图标)。 */
|
|
61
|
-
export function getFileIconAssetByExt(ext?: string) {
|
|
62
|
-
const key = (ext || '').toLowerCase()
|
|
63
|
-
return FILE_EXT_ICON_ASSET_MAP[key] ?? DEFAULT_FILE_ICON_ASSET
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** 根据文件名/URL 获取图标资源(内部会取后缀)。 */
|
|
67
|
-
export function getFileIconAssetByName(nameOrUrl?: string) {
|
|
68
|
-
return getFileIconAssetByExt(getLowerFileExt(nameOrUrl))
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/** 将图标资源转换成可渲染节点(支持 url 或 icon)。 */
|
|
72
|
-
export function renderFileIconAsset(asset: FileIconAsset) {
|
|
73
|
-
if (asset.url) {
|
|
74
|
-
// eslint-disable-next-line @next/next/no-img-element
|
|
75
|
-
return <img src={asset.url} alt="" style={{ width: '1em', height: '1em', display: 'block' }} />
|
|
76
|
-
}
|
|
77
|
-
return asset.icon ?? DEFAULT_FILE_ICON_ASSET.icon
|
|
78
|
-
}
|
|
79
|
-
|
package/src/utils/index.ts
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
import type { MenuTreeItem } from '@/types/menu'
|
|
2
|
-
import aesUtil from '@/utils/aesUtil'
|
|
3
|
-
import { getIconComponent } from '@/utils/routeConfig'
|
|
4
|
-
import { showGlobalToast } from '@/utils/toastBridge'
|
|
5
|
-
import { Folder, FolderOpen } from 'lucide-react'
|
|
6
|
-
import React from 'react'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 获取菜单节点图标组件(优先使用配置的 icon,否则返回默认文件夹图标)
|
|
10
|
-
*/
|
|
11
|
-
export function getMenuNodeIcon(node: MenuTreeItem, isExpanded?: boolean, isSelected?: boolean) {
|
|
12
|
-
// 优先使用配置的 icon
|
|
13
|
-
if (node.icon) {
|
|
14
|
-
const Icon = getIconComponent(node.icon)
|
|
15
|
-
if (Icon) return React.createElement(Icon, { size: 16, className: 'text-gray-500 dark:text-gray-400' })
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
// 默认文件夹图标
|
|
19
|
-
return isExpanded || isSelected
|
|
20
|
-
? React.createElement(FolderOpen, { size: 16, className: 'text-gray-400 dark:text-gray-500' })
|
|
21
|
-
: React.createElement(Folder, { size: 16, className: 'text-gray-400 dark:text-gray-500' })
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** 将 { value, label }[] 转为 value → label 的映射(label 常为 i18n key) */
|
|
25
|
-
export function listToValueMap<T extends string | number>(
|
|
26
|
-
options: Array<{ value: T; label: string; [key: string]: any }>,
|
|
27
|
-
labelField: string = 'label', // 增加第二个参数,默认值为 'label'
|
|
28
|
-
): Record<T, string> {
|
|
29
|
-
return Object.fromEntries(
|
|
30
|
-
options.map((item) => [item.value, item[labelField]])
|
|
31
|
-
) as Record<T, string>;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* 通用复制文本到剪贴板
|
|
36
|
-
* @param text 要复制的文本
|
|
37
|
-
* @returns 是否复制成功
|
|
38
|
-
*/
|
|
39
|
-
export async function copyToClipboard(text: string): Promise<boolean> {
|
|
40
|
-
if (!text) return false
|
|
41
|
-
|
|
42
|
-
// 优先使用现代 API
|
|
43
|
-
try {
|
|
44
|
-
if (navigator.clipboard?.writeText) {
|
|
45
|
-
await navigator.clipboard.writeText(text)
|
|
46
|
-
return true
|
|
47
|
-
}
|
|
48
|
-
} catch (err) {
|
|
49
|
-
console.warn('Navigator clipboard failed, using fallback', err)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// 降级方案
|
|
53
|
-
try {
|
|
54
|
-
const textArea = document.createElement('textarea')
|
|
55
|
-
textArea.value = text
|
|
56
|
-
textArea.style.position = 'fixed'
|
|
57
|
-
textArea.style.left = '-999999px'
|
|
58
|
-
textArea.style.top = '-999999px'
|
|
59
|
-
document.body.appendChild(textArea)
|
|
60
|
-
textArea.focus()
|
|
61
|
-
textArea.select()
|
|
62
|
-
const success = document.execCommand('copy')
|
|
63
|
-
document.body.removeChild(textArea)
|
|
64
|
-
return success
|
|
65
|
-
} catch (err) {
|
|
66
|
-
console.error('Copy fallback failed', err)
|
|
67
|
-
return false
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* 从响应头 `content-disposition` 解析下载文件名(兼容 filename / filename*)。
|
|
73
|
-
*/
|
|
74
|
-
function getDownloadFileNameFromHeaders(
|
|
75
|
-
headers: Record<string, any> | undefined,
|
|
76
|
-
splitStr?: string,
|
|
77
|
-
) {
|
|
78
|
-
const contentDisposition = headers?.['content-disposition'] || headers?.['Content-Disposition']
|
|
79
|
-
if (!contentDisposition) return ''
|
|
80
|
-
|
|
81
|
-
// 默认优先解析 RFC 5987: filename*=utf-8''xxx
|
|
82
|
-
const preferSplit = splitStr || "filename*=utf-8''"
|
|
83
|
-
|
|
84
|
-
const raw =
|
|
85
|
-
contentDisposition.indexOf('filename*=') !== -1
|
|
86
|
-
? contentDisposition.split(preferSplit)[1] || contentDisposition.split('filename*=')[1]
|
|
87
|
-
: contentDisposition.split('filename=')[1]
|
|
88
|
-
|
|
89
|
-
if (!raw) return ''
|
|
90
|
-
|
|
91
|
-
const cleaned = raw.trim().replace(/^"+|"+$/g, '').replace(/;.*$/, '')
|
|
92
|
-
if (!cleaned) return ''
|
|
93
|
-
|
|
94
|
-
// 旧后端常把 UTF-8 文件名 encode 成 %xx
|
|
95
|
-
if (cleaned.indexOf('%') !== -1) {
|
|
96
|
-
try {
|
|
97
|
-
return decodeURIComponent(cleaned)
|
|
98
|
-
} catch {
|
|
99
|
-
return cleaned
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return cleaned
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* 处理导出/下载接口返回的 Blob,触发浏览器下载;若返回的是 JSON 错误,则给出当前项目的提示。
|
|
108
|
-
*/
|
|
109
|
-
export function handlerDownload(
|
|
110
|
-
res: any,
|
|
111
|
-
splitStr?: string,
|
|
112
|
-
customerFileName?: string,
|
|
113
|
-
) {
|
|
114
|
-
const blob: Blob = res
|
|
115
|
-
|
|
116
|
-
// 后端有时会以 blob 形式返回 JSON 错误(如未登录/无权限/导出失败)
|
|
117
|
-
if (blob?.type && blob.type.indexOf('application/json') !== -1) {
|
|
118
|
-
const reader = new FileReader()
|
|
119
|
-
reader.readAsText(blob, 'utf-8')
|
|
120
|
-
reader.onload = () => {
|
|
121
|
-
try {
|
|
122
|
-
const resultText = reader.result
|
|
123
|
-
let data: any = typeof resultText === 'string' ? JSON.parse(resultText) : {}
|
|
124
|
-
|
|
125
|
-
// 与 axios 响应拦截器一致:{ data: 'xxxx'(string), code: undefined } 视为加密体
|
|
126
|
-
if (typeof data?.data === 'string' && data?.code === undefined) {
|
|
127
|
-
const decrypted = aesUtil.decrypt(data.data)
|
|
128
|
-
if (typeof decrypted === 'object' && decrypted) {
|
|
129
|
-
data = decrypted
|
|
130
|
-
} else if (typeof decrypted === 'string' && decrypted) {
|
|
131
|
-
try {
|
|
132
|
-
data = JSON.parse(decrypted)
|
|
133
|
-
} catch {
|
|
134
|
-
// 解密结果不是 JSON,按字符串 message 处理
|
|
135
|
-
data = { message: decrypted }
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (data?.code === 1803 || data?.code === 401) {
|
|
141
|
-
window.dispatchEvent(new CustomEvent('common:unauthorized'))
|
|
142
|
-
return
|
|
143
|
-
}
|
|
144
|
-
showGlobalToast(data?.message || '下载失败', 'error')
|
|
145
|
-
} catch {
|
|
146
|
-
showGlobalToast('下载失败', 'error')
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const a = document.createElement('a')
|
|
153
|
-
const href = window.URL.createObjectURL(blob)
|
|
154
|
-
a.href = href
|
|
155
|
-
|
|
156
|
-
const headers = res?.responseHeaders
|
|
157
|
-
const headerFileName = getDownloadFileNameFromHeaders(headers, splitStr)
|
|
158
|
-
a.download = customerFileName || headerFileName || 'download'
|
|
159
|
-
|
|
160
|
-
document.body.appendChild(a)
|
|
161
|
-
a.click()
|
|
162
|
-
document.body.removeChild(a)
|
|
163
|
-
window.URL.revokeObjectURL(href)
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
export * from './file-icons'
|
|
167
|
-
|
|
168
|
-
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import remarkGfm from 'remark-gfm'
|
|
2
|
-
import remarkMath from 'remark-math'
|
|
3
|
-
import rehypeKatex from 'rehype-katex'
|
|
4
|
-
import type { PluggableList } from 'unified'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* react-markdown 共用:GFM + 数学公式。
|
|
8
|
-
* - 模型常见写法为行内 `$...$`、块级 `$$...$$`,以及 `\\(` `\\)`、`\\[` `\\]`。
|
|
9
|
-
* - 须开启 `singleDollarTextMath`,否则 `$ \\frac{23}{24} $` 等不会被识别为公式。
|
|
10
|
-
* - `remark-math` 放在 `remark-gfm` 前,减少 GFM 规则与数学语法的边界冲突。
|
|
11
|
-
*
|
|
12
|
-
* 注:各 remark 插件推断的 Plugin 泛型不完全一致,此处对 PluggableList 做断言以通过类型检查。
|
|
13
|
-
*/
|
|
14
|
-
export const markdownRemarkPlugins: PluggableList = [
|
|
15
|
-
[remarkMath, { singleDollarTextMath: true }],
|
|
16
|
-
remarkGfm,
|
|
17
|
-
] as unknown as PluggableList
|
|
18
|
-
|
|
19
|
-
export const markdownRehypePlugins: PluggableList = [
|
|
20
|
-
rehypeKatex,
|
|
21
|
-
] as unknown as PluggableList
|
package/src/utils/menuI18n.ts
DELETED
|
@@ -1,305 +0,0 @@
|
|
|
1
|
-
import i18n from '@/i18n'
|
|
2
|
-
import type { MenuTreeItem } from '@/types/menu'
|
|
3
|
-
|
|
4
|
-
/** 动态菜单标题前缀,完整键为 p_system.menu.db_code.[code] */
|
|
5
|
-
export const MENU_ITEM_I18N_PREFIX = 'p_system.menu.db_code.'
|
|
6
|
-
|
|
7
|
-
/** 用动态 idKey / childrenKey 读节点字段(MenuTreeItem 无索引签名,需经 unknown 断言) */
|
|
8
|
-
function asMenuRecord(n: MenuTreeItem): Record<string, unknown> {
|
|
9
|
-
return n as unknown as Record<string, unknown>
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export type MenuNameLocales = { zh?: string; en?: string }
|
|
13
|
-
|
|
14
|
-
/** 将后台返回的 name 字段解析为多语言对象(支持标准 JSON) */
|
|
15
|
-
export function parseMenuNameJson(raw: string | undefined | null): MenuNameLocales | null {
|
|
16
|
-
if (raw == null || typeof raw !== 'string') return null
|
|
17
|
-
const s = raw.trim()
|
|
18
|
-
if (!s.startsWith('{')) return null
|
|
19
|
-
try {
|
|
20
|
-
const obj = JSON.parse(s) as Record<string, unknown>
|
|
21
|
-
if (!obj || typeof obj !== 'object') return null
|
|
22
|
-
const zh =
|
|
23
|
-
(typeof obj.zh === 'string' && obj.zh) ||
|
|
24
|
-
(typeof obj['zh-CN'] === 'string' && (obj['zh-CN'] as string)) ||
|
|
25
|
-
undefined
|
|
26
|
-
const en =
|
|
27
|
-
(typeof obj.en === 'string' && obj.en) ||
|
|
28
|
-
(typeof obj['en-US'] === 'string' && (obj['en-US'] as string)) ||
|
|
29
|
-
undefined
|
|
30
|
-
return { zh, en }
|
|
31
|
-
} catch {
|
|
32
|
-
return null
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export function stringifyMenuNameJson(locales: MenuNameLocales): string {
|
|
37
|
-
return JSON.stringify({
|
|
38
|
-
zh: locales.zh ?? '',
|
|
39
|
-
en: locales.en ?? '',
|
|
40
|
-
})
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export function flattenMenuNodes(menus: MenuTreeItem[] | undefined): MenuTreeItem[] {
|
|
44
|
-
const out: MenuTreeItem[] = []
|
|
45
|
-
const walk = (nodes?: MenuTreeItem[]) => {
|
|
46
|
-
if (!nodes?.length) return
|
|
47
|
-
for (const n of nodes) {
|
|
48
|
-
out.push(n)
|
|
49
|
-
walk(n.children)
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
walk(menus)
|
|
53
|
-
return out
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 在菜单树中按 id 查找节点,返回其 `code`(无或空则 undefined)
|
|
58
|
-
*/
|
|
59
|
-
export function findMenuCodeInTree(
|
|
60
|
-
nodes: MenuTreeItem[] | undefined,
|
|
61
|
-
menuId: string | number | null | undefined,
|
|
62
|
-
options?: { idKey?: string; childrenKey?: string },
|
|
63
|
-
): string | undefined {
|
|
64
|
-
if (menuId == null || String(menuId).trim() === '') return undefined
|
|
65
|
-
const idKey = options?.idKey ?? 'id'
|
|
66
|
-
const childrenKey = options?.childrenKey ?? 'children'
|
|
67
|
-
const target = String(menuId)
|
|
68
|
-
|
|
69
|
-
const walk = (list: MenuTreeItem[] | undefined): string | undefined => {
|
|
70
|
-
if (!list?.length) return undefined
|
|
71
|
-
for (const node of list) {
|
|
72
|
-
if (String(asMenuRecord(node)[idKey]) === target) {
|
|
73
|
-
const c = node.code
|
|
74
|
-
return typeof c === 'string' && c.trim() !== '' ? c.trim() : undefined
|
|
75
|
-
}
|
|
76
|
-
const childList = asMenuRecord(node)[childrenKey] as
|
|
77
|
-
| MenuTreeItem[]
|
|
78
|
-
| undefined
|
|
79
|
-
const found = walk(childList)
|
|
80
|
-
if (found != null) return found
|
|
81
|
-
}
|
|
82
|
-
return undefined
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
return walk(nodes)
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* 与权限页菜单树 / CxTreeSelect 节点文案一致:title 多语言 JSON → 单字符串 title/name/code/id
|
|
90
|
-
*/
|
|
91
|
-
export function getMenuTreeNodeFlatLabel(node: MenuTreeItem): string {
|
|
92
|
-
const titleRaw = (node as { title?: unknown }).title
|
|
93
|
-
const titleStr = typeof titleRaw === 'string' ? titleRaw : ''
|
|
94
|
-
const parsed = parseMenuNameJson(titleStr)
|
|
95
|
-
return (
|
|
96
|
-
parsed?.zh ||
|
|
97
|
-
parsed?.en ||
|
|
98
|
-
titleStr ||
|
|
99
|
-
(typeof node.name === 'string' ? node.name : '') ||
|
|
100
|
-
node.code ||
|
|
101
|
-
String(node.id)
|
|
102
|
-
)
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
/** 将菜单树扁平为 id → 展示名(用于权限详情等反查) */
|
|
106
|
-
export function buildMenuIdToLabelMap(
|
|
107
|
-
roots: MenuTreeItem[] | undefined,
|
|
108
|
-
options?: { childrenKey?: string; idKey?: string },
|
|
109
|
-
): Record<string, string> {
|
|
110
|
-
const childrenKey = options?.childrenKey ?? 'children'
|
|
111
|
-
const idKey = options?.idKey ?? 'id'
|
|
112
|
-
const map: Record<string, string> = {}
|
|
113
|
-
const walk = (nodes?: MenuTreeItem[]) => {
|
|
114
|
-
if (!nodes?.length) return
|
|
115
|
-
for (const n of nodes) {
|
|
116
|
-
const idVal = asMenuRecord(n)[idKey]
|
|
117
|
-
if (idVal != null && String(idVal) !== '') {
|
|
118
|
-
map[String(idVal)] = getMenuTreeNodeFlatLabel(n)
|
|
119
|
-
}
|
|
120
|
-
const children = asMenuRecord(n)[childrenKey] as
|
|
121
|
-
| MenuTreeItem[]
|
|
122
|
-
| undefined
|
|
123
|
-
walk(children)
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
walk(roots)
|
|
127
|
-
return map
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
/** 将菜单树扁平为 id → 从根到该节点的层级路径(如「系统管理 > 用户管理 > 用户列表」) */
|
|
131
|
-
export function buildMenuIdToPathLabelMap(
|
|
132
|
-
roots: MenuTreeItem[] | undefined,
|
|
133
|
-
options?: {
|
|
134
|
-
childrenKey?: string
|
|
135
|
-
idKey?: string
|
|
136
|
-
/** 层级分隔符,默认「 > 」 */
|
|
137
|
-
separator?: string
|
|
138
|
-
},
|
|
139
|
-
): Record<string, string> {
|
|
140
|
-
const childrenKey = options?.childrenKey ?? 'children'
|
|
141
|
-
const idKey = options?.idKey ?? 'id'
|
|
142
|
-
const separator = options?.separator ?? ' > '
|
|
143
|
-
const map: Record<string, string> = {}
|
|
144
|
-
const walk = (nodes: MenuTreeItem[] | undefined, ancestorLabels: string[]) => {
|
|
145
|
-
if (!nodes?.length) return
|
|
146
|
-
for (const n of nodes) {
|
|
147
|
-
const label = getMenuTreeNodeFlatLabel(n)
|
|
148
|
-
const segments = [...ancestorLabels, label]
|
|
149
|
-
const pathStr = segments.join(separator)
|
|
150
|
-
const idVal = asMenuRecord(n)[idKey]
|
|
151
|
-
if (idVal != null && String(idVal) !== '') {
|
|
152
|
-
map[String(idVal)] = pathStr
|
|
153
|
-
}
|
|
154
|
-
const children = asMenuRecord(n)[childrenKey] as
|
|
155
|
-
| MenuTreeItem[]
|
|
156
|
-
| undefined
|
|
157
|
-
walk(children, segments)
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
walk(roots, [])
|
|
161
|
-
return map
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* 解析节点在业务中的菜单 level(与 `menuFormShared`、接口 `MenuTreeItem.level` 一致):
|
|
166
|
-
* **0=顶级,1=一级,2=二级**…
|
|
167
|
-
* 无 `level` 时按树深度回退:`depth` 从 1 表示根行 → `level = depth - 1`。
|
|
168
|
-
*/
|
|
169
|
-
export function resolveMenuTreeNodeLevel(
|
|
170
|
-
node: MenuTreeItem,
|
|
171
|
-
depthFromRoot: number,
|
|
172
|
-
): number {
|
|
173
|
-
const n = Number((node as MenuTreeItem).level)
|
|
174
|
-
if (Number.isFinite(n) && n >= 0) return n
|
|
175
|
-
return depthFromRoot - 1
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/** 菜单 id → 业务 level(见 {@link resolveMenuTreeNodeLevel}) */
|
|
179
|
-
export function buildMenuIdToLevelMap(
|
|
180
|
-
roots: MenuTreeItem[] | undefined,
|
|
181
|
-
options?: { childrenKey?: string; idKey?: string },
|
|
182
|
-
): Record<string, number> {
|
|
183
|
-
const childrenKey = options?.childrenKey ?? 'children'
|
|
184
|
-
const idKey = options?.idKey ?? 'id'
|
|
185
|
-
const map: Record<string, number> = {}
|
|
186
|
-
const walk = (nodes: MenuTreeItem[] | undefined, depthFromRoot: number) => {
|
|
187
|
-
if (!nodes?.length) return
|
|
188
|
-
for (const n of nodes) {
|
|
189
|
-
const idVal = asMenuRecord(n)[idKey]
|
|
190
|
-
if (idVal != null && String(idVal) !== '') {
|
|
191
|
-
map[String(idVal)] = resolveMenuTreeNodeLevel(n, depthFromRoot)
|
|
192
|
-
}
|
|
193
|
-
const children = asMenuRecord(n)[childrenKey] as
|
|
194
|
-
| MenuTreeItem[]
|
|
195
|
-
| undefined
|
|
196
|
-
walk(children, depthFromRoot + 1)
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
walk(roots, 1)
|
|
200
|
-
return map
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* 权限绑定菜单 TreeSelect:**仅 `level===0`(顶级)与 `level===2`(二级)可选**;
|
|
205
|
-
* `level===1`(一级)及 `level>=3` 为 `disabled`(仍展示)。
|
|
206
|
-
*/
|
|
207
|
-
export function mapMenuTreeForPermissionBindSelect(
|
|
208
|
-
nodes: MenuTreeItem[] | undefined,
|
|
209
|
-
options?: { childrenKey?: string; idKey?: string },
|
|
210
|
-
): any[] {
|
|
211
|
-
const childrenKey = options?.childrenKey ?? 'children'
|
|
212
|
-
const idKey = options?.idKey ?? 'id'
|
|
213
|
-
|
|
214
|
-
const walk = (list: MenuTreeItem[] | undefined, depthFromRoot: number): any[] => {
|
|
215
|
-
if (!list?.length) return []
|
|
216
|
-
return list.map((node) => {
|
|
217
|
-
const idVal = asMenuRecord(node)[idKey]
|
|
218
|
-
const childrenRaw = asMenuRecord(node)[childrenKey] as
|
|
219
|
-
| MenuTreeItem[]
|
|
220
|
-
| undefined
|
|
221
|
-
const children = walk(childrenRaw, depthFromRoot + 1)
|
|
222
|
-
const lvl = resolveMenuTreeNodeLevel(node as MenuTreeItem, depthFromRoot)
|
|
223
|
-
const disabled = lvl !== 0 && lvl !== 2
|
|
224
|
-
return {
|
|
225
|
-
title: getMenuTreeNodeFlatLabel(node),
|
|
226
|
-
value: String(idVal),
|
|
227
|
-
key: String(idVal),
|
|
228
|
-
disabled,
|
|
229
|
-
children: children.length ? children : undefined,
|
|
230
|
-
}
|
|
231
|
-
})
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
return walk(nodes, 1)
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* 根据菜单树把多语言文案写入 i18n,键为 p_system.menu.db_code.[code]
|
|
239
|
-
*/
|
|
240
|
-
export function syncMenuTreeToI18n(menuRoots: MenuTreeItem[] | undefined) {
|
|
241
|
-
if (!menuRoots?.length) return
|
|
242
|
-
const nodes = flattenMenuNodes(menuRoots)
|
|
243
|
-
for (const node of nodes) {
|
|
244
|
-
if (!node.code) continue
|
|
245
|
-
const key = `${MENU_ITEM_I18N_PREFIX}${node.code}`
|
|
246
|
-
// 新结构:title 可能是 JSON 字符串,也可能是单语言字符串
|
|
247
|
-
if (typeof (node as any).title === 'string' && (node as any).title.trim()) {
|
|
248
|
-
const title = String((node as any).title)
|
|
249
|
-
const parsedTitle = parseMenuNameJson(title)
|
|
250
|
-
if (parsedTitle) {
|
|
251
|
-
if (parsedTitle.zh) i18n.addResource('zh', 'translation', key, parsedTitle.zh)
|
|
252
|
-
if (parsedTitle.en) i18n.addResource('en', 'translation', key, parsedTitle.en)
|
|
253
|
-
} else {
|
|
254
|
-
i18n.addResource('zh', 'translation', key, title)
|
|
255
|
-
i18n.addResource('en', 'translation', key, title)
|
|
256
|
-
}
|
|
257
|
-
continue
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// 旧结构:name 为 JSON 字符串
|
|
261
|
-
const parsed = parseMenuNameJson(node.name)
|
|
262
|
-
if (!parsed) continue
|
|
263
|
-
if (parsed.zh) i18n.addResource('zh', 'translation', key, parsed.zh)
|
|
264
|
-
if (parsed.en) i18n.addResource('en', 'translation', key, parsed.en)
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
/** 侧边栏 / 树上展示用:优先 p_system.menu.db_code.[code],其次 JSON 按当前语言,再退回旧版 i18n key */
|
|
269
|
-
export function getMenuDisplayName(
|
|
270
|
-
menu: MenuTreeItem,
|
|
271
|
-
t: (key: string) => string,
|
|
272
|
-
language?: string,
|
|
273
|
-
): string {
|
|
274
|
-
const lng = language ?? i18n.language ?? 'zh'
|
|
275
|
-
const isEn = lng === 'en' || lng.startsWith('en-')
|
|
276
|
-
|
|
277
|
-
// 新结构:优先使用 title(支持 JSON 字符串按语言显示)
|
|
278
|
-
if (typeof (menu as any).title === 'string' && (menu as any).title.trim()) {
|
|
279
|
-
const title = String((menu as any).title)
|
|
280
|
-
const parsedTitle = parseMenuNameJson(title)
|
|
281
|
-
if (parsedTitle) {
|
|
282
|
-
const fallback = isEn ? parsedTitle.en || parsedTitle.zh : parsedTitle.zh || parsedTitle.en
|
|
283
|
-
if (fallback) return fallback
|
|
284
|
-
}
|
|
285
|
-
return title
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
if (menu.code) {
|
|
289
|
-
const key = `${MENU_ITEM_I18N_PREFIX}${menu.code}`
|
|
290
|
-
const translated = t(key)
|
|
291
|
-
if (translated && translated !== key) return translated
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
const parsed = parseMenuNameJson(menu.name)
|
|
295
|
-
if (parsed) {
|
|
296
|
-
const fallback = isEn ? parsed.en || parsed.zh : parsed.zh || parsed.en
|
|
297
|
-
if (fallback) return fallback
|
|
298
|
-
}
|
|
299
|
-
|
|
300
|
-
const raw = menu.name ?? ''
|
|
301
|
-
if (typeof raw === 'string' && raw.includes('.') && !raw.trim().startsWith('{')) {
|
|
302
|
-
return t(raw)
|
|
303
|
-
}
|
|
304
|
-
return raw || ''
|
|
305
|
-
}
|