cx-chat 0.0.2 → 0.0.3

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.
Files changed (406) hide show
  1. package/dist/cx-chat.css +1 -0
  2. package/dist/cx-chat.es.js +97326 -0
  3. package/dist/cx-chat.umd.js +734 -0
  4. package/package.json +21 -1
  5. package/.cursor/rules/i18n-cn-gloss-comments.mdc +0 -31
  6. package/.cursor/rules/list-page-view-pageconfig.mdc +0 -32
  7. package/.cursor/rules/no-over-defensive-programming.mdc +0 -90
  8. package/.cursor/rules/requirement-description-for-agent.mdc +0 -33
  9. package/.cursor/rules/use-showToast-not-antd-message.mdc +0 -28
  10. package/.docker/Dockerfile +0 -7
  11. package/.env +0 -9
  12. package/.env.development +0 -7
  13. package/.env.production +0 -7
  14. package/.gitlab-ci/docker-build.yaml +0 -28
  15. package/.gitlab-ci/k8s-deploy-dev-master.yaml +0 -42
  16. package/.gitlab-ci/npm-build.yaml +0 -17
  17. package/.gitlab-ci.yml +0 -8
  18. package/.k8s/0-namespace.yaml +0 -6
  19. package/.k8s/1-configmap-web.yaml +0 -7
  20. package/.k8s/1-nginx-conf-dev.yaml +0 -110
  21. package/.k8s/2-deployment.yaml +0 -27
  22. package/.k8s/3-service.yaml +0 -16
  23. package/.k8s/4-ingress-dev.yaml +0 -30
  24. package/.lingma/rules/use-showToast-not-antd-message.md +0 -34
  25. package/.nginx/nginx.conf +0 -52
  26. package/.prettierrc +0 -9
  27. package/eslint.config.js +0 -32
  28. package/index.html +0 -13
  29. package/postcss.config.js +0 -6
  30. package/src/App.tsx +0 -96
  31. package/src/_doc/0.docs-overview.md +0 -28
  32. package/src/_doc/cx-ui/0.docs-overview.md +0 -30
  33. package/src/_doc/cx-ui/comp.1.cx-ui-overview.md +0 -82
  34. package/src/_doc/cx-ui/comp.2.cx-modal.md +0 -82
  35. package/src/_doc/cx-ui/comp.3.cx-button.md +0 -89
  36. package/src/_doc/cx-ui/comp.4.cx-form.md +0 -72
  37. package/src/_doc/cx-ui/comp.5.cx-fields.md +0 -76
  38. package/src/_doc/cx-ui/comp.6.cx-tag.md +0 -57
  39. package/src/_doc/cx-ui/comp.7.cx-empty-state.md +0 -29
  40. package/src/_doc/meta/0.docs-overview.md +0 -24
  41. package/src/_doc/meta/comp.1.enum-runtime.md +0 -33
  42. package/src/_doc/meta/comp.2.dict-runtime.md +0 -39
  43. package/src/_doc/router/0.docs-overview.md +0 -14
  44. package/src/_doc/router/guide.1.menu-component-config.md +0 -181
  45. package/src/_doc/router/guide.2.router-auto-registration.md +0 -114
  46. package/src/_doc/table-view/0.docs-overview.md +0 -30
  47. package/src/_doc/table-view/comp.1.table-view.md +0 -542
  48. package/src/_doc/table-view/props.1.create-table-view-config.md +0 -193
  49. package/src/_doc/table-view/props.2.table-view-search-fields.md +0 -106
  50. package/src/api/_mock/README.md +0 -340
  51. package/src/api/_mock/api.ts +0 -1642
  52. package/src/api/_mock/bundle-shim.ts +0 -16
  53. package/src/api/_mock/handler-shim.ts +0 -6
  54. package/src/api/_mock/handler.ts +0 -458
  55. package/src/api/_mock/index.ts +0 -711
  56. package/src/api/_mock/interceptor.ts +0 -15
  57. package/src/api/_mock/mod.ts +0 -12
  58. package/src/api/_mock/utils.ts +0 -65
  59. package/src/api/base/memory.js +0 -24
  60. package/src/api/chat.js +0 -210
  61. package/src/api/common/auth.js +0 -70
  62. package/src/api/menus/business-rules.js +0 -76
  63. package/src/api/menus/feedback.js +0 -102
  64. package/src/api/menus/knowledge.js +0 -159
  65. package/src/api/menus/model-metadata/manage.js +0 -70
  66. package/src/api/menus/model-metadata/role.js +0 -50
  67. package/src/api/menus/model-metadata/training-detail-mock-data.js +0 -569
  68. package/src/api/menus/model-metadata/training.js +0 -28
  69. package/src/api/menus/skill.js +0 -40
  70. package/src/api/system/agent-config.js +0 -16
  71. package/src/api/system/department.js +0 -94
  72. package/src/api/system/dict.js +0 -86
  73. package/src/api/system/menu.js +0 -37
  74. package/src/api/system/permission.js +0 -26
  75. package/src/api/system/role.js +0 -34
  76. package/src/api/system/sys-config.js +0 -16
  77. package/src/api/system/sys-log.js +0 -17
  78. package/src/api/system/user.js +0 -75
  79. package/src/api/upload.js +0 -39
  80. package/src/assets/react.svg +0 -1
  81. package/src/components/auth/current-user-avatar.tsx +0 -77
  82. package/src/components/common/code-view.tsx +0 -149
  83. package/src/components/common/detail-link.tsx +0 -67
  84. package/src/components/common/error-boundary.tsx +0 -98
  85. package/src/components/common/language-switcher.tsx +0 -91
  86. package/src/components/common/lite-table/index.tsx +0 -135
  87. package/src/components/common/md-editor.tsx +0 -126
  88. package/src/components/common/modal/confirm-dialog.tsx +0 -113
  89. package/src/components/common/modal/dep-user-select-multi.tsx +0 -324
  90. package/src/components/common/modal/dep-user-select.tsx +0 -249
  91. package/src/components/common/modal/user-select-multi.tsx +0 -266
  92. package/src/components/common/pagination.tsx +0 -472
  93. package/src/components/common/path.tsx +0 -175
  94. package/src/components/common/system-logo-mark.tsx +0 -48
  95. package/src/components/cx-ui/button/index.less +0 -208
  96. package/src/components/cx-ui/button/index.tsx +0 -611
  97. package/src/components/cx-ui/checkbox/index.tsx +0 -78
  98. package/src/components/cx-ui/date-picker/index.less +0 -17
  99. package/src/components/cx-ui/date-picker/index.tsx +0 -193
  100. package/src/components/cx-ui/drawer/index.tsx +0 -47
  101. package/src/components/cx-ui/empty-state/index.tsx +0 -20
  102. package/src/components/cx-ui/floating-shell/CxFloatingShell.tsx +0 -89
  103. package/src/components/cx-ui/floating-shell/cx-floating-shell.less +0 -283
  104. package/src/components/cx-ui/floating-shell/has-floating-value.ts +0 -41
  105. package/src/components/cx-ui/form/CxForm.tsx +0 -15
  106. package/src/components/cx-ui/form/index.tsx +0 -20
  107. package/src/components/cx-ui/form-item/index.less +0 -26
  108. package/src/components/cx-ui/form-item/index.tsx +0 -36
  109. package/src/components/cx-ui/index.ts +0 -70
  110. package/src/components/cx-ui/input/auto-complete.tsx +0 -134
  111. package/src/components/cx-ui/input/index.tsx +0 -259
  112. package/src/components/cx-ui/input-number/index.jsx +0 -66
  113. package/src/components/cx-ui/modal/index.jsx +0 -212
  114. package/src/components/cx-ui/modal/index.less +0 -144
  115. package/src/components/cx-ui/modal/useCxModal.ts +0 -125
  116. package/src/components/cx-ui/multi-select/index.jsx +0 -74
  117. package/src/components/cx-ui/multi-select/index.less +0 -40
  118. package/src/components/cx-ui/multi-select/index2.tsx +0 -361
  119. package/src/components/cx-ui/radio/index.tsx +0 -33
  120. package/src/components/cx-ui/range-picker/index.less +0 -65
  121. package/src/components/cx-ui/range-picker/index.tsx +0 -219
  122. package/src/components/cx-ui/select/index.less +0 -34
  123. package/src/components/cx-ui/select/index.tsx +0 -196
  124. package/src/components/cx-ui/skeleton/index.tsx +0 -12
  125. package/src/components/cx-ui/steps/index.tsx +0 -14
  126. package/src/components/cx-ui/styles/_tokens.less +0 -79
  127. package/src/components/cx-ui/styles/index.less +0 -246
  128. package/src/components/cx-ui/switch/index.less +0 -106
  129. package/src/components/cx-ui/switch/index.tsx +0 -120
  130. package/src/components/cx-ui/table/index.less +0 -160
  131. package/src/components/cx-ui/table/index.tsx +0 -152
  132. package/src/components/cx-ui/tabs/index.less +0 -15
  133. package/src/components/cx-ui/tabs/index.tsx +0 -34
  134. package/src/components/cx-ui/tag/index.less +0 -51
  135. package/src/components/cx-ui/tag/index.tsx +0 -140
  136. package/src/components/cx-ui/timeline/index.tsx +0 -14
  137. package/src/components/cx-ui/tooltip/index.tsx +0 -67
  138. package/src/components/cx-ui/tree/index.tsx +0 -193
  139. package/src/components/cx-ui/tree-select/index.jsx +0 -91
  140. package/src/components/cx-ui/tree-select/index.less +0 -27
  141. package/src/components/cx-ui/upload-file/index.less +0 -223
  142. package/src/components/cx-ui/upload-file/index.tsx +0 -640
  143. package/src/components/cx-ui/upload-img/index.tsx +0 -291
  144. package/src/components/layout/components/Header.tsx +0 -216
  145. package/src/components/layout/components/Sidebar.tsx +0 -717
  146. package/src/components/layout/index.tsx +0 -95
  147. package/src/components/table-view/components/search-area.tsx +0 -411
  148. package/src/components/table-view/components/table-view-config.tsx +0 -528
  149. package/src/components/table-view/components/table-view.types.ts +0 -478
  150. package/src/components/table-view/components/tree-api-normalize.ts +0 -38
  151. package/src/components/table-view/components/tree-data-annotate.ts +0 -31
  152. package/src/components/table-view/components/tree-sidebar.tsx +0 -74
  153. package/src/components/table-view/index.tsx +0 -61
  154. package/src/components/table-view/list-page-view.tsx +0 -1049
  155. package/src/components/table-view/select-table-view.tsx +0 -1094
  156. package/src/components/table-view/styles/select-table-view.less +0 -51
  157. package/src/config/default-system-name.ts +0 -9
  158. package/src/config/system.ts +0 -165
  159. package/src/constants/countryCodes.ts +0 -3
  160. package/src/contexts/AuthContext.tsx +0 -256
  161. package/src/contexts/ChatContext.tsx +0 -839
  162. package/src/contexts/MenuContext.tsx +0 -62
  163. package/src/contexts/ToastContext.tsx +0 -181
  164. package/src/hooks/useCopyToClipboard.ts +0 -47
  165. package/src/hooks/useModalSubmit.ts +0 -104
  166. package/src/hooks/useRouter.ts +0 -240
  167. package/src/hooks/useStepForm.ts +0 -46
  168. package/src/hooks/useStickyHeader.ts +0 -42
  169. package/src/hooks/useThreadActions.ts +0 -105
  170. package/src/hooks/useUserPreferences.ts +0 -101
  171. package/src/http/axios.js +0 -372
  172. package/src/http/mock.interceptor.ts +0 -9
  173. package/src/http/obfuscationKey.ts +0 -41
  174. package/src/i18n.ts +0 -60
  175. package/src/index.js +0 -1
  176. package/src/index.less +0 -169
  177. package/src/locales/en/auth.ts +0 -70
  178. package/src/locales/en/base/memory.ts +0 -28
  179. package/src/locales/en/base/settings.ts +0 -41
  180. package/src/locales/en/chat.ts +0 -40
  181. package/src/locales/en/common.ts +0 -173
  182. package/src/locales/en/enum.ts +0 -27
  183. package/src/locales/en/menus/business-rules.ts +0 -48
  184. package/src/locales/en/menus/feedback.ts +0 -62
  185. package/src/locales/en/menus/knowledge.ts +0 -120
  186. package/src/locales/en/menus/model-metadata/index.ts +0 -10
  187. package/src/locales/en/menus/model-metadata/manage.ts +0 -151
  188. package/src/locales/en/menus/model-metadata/role.ts +0 -48
  189. package/src/locales/en/menus/model-metadata/training.ts +0 -65
  190. package/src/locales/en/menus/skill.ts +0 -34
  191. package/src/locales/en/system/agent-config.ts +0 -34
  192. package/src/locales/en/system/department.ts +0 -68
  193. package/src/locales/en/system/dict.ts +0 -44
  194. package/src/locales/en/system/menu.ts +0 -45
  195. package/src/locales/en/system/permission.ts +0 -89
  196. package/src/locales/en/system/role.ts +0 -25
  197. package/src/locales/en/system/sys-config.ts +0 -33
  198. package/src/locales/en/system/sys-log.ts +0 -38
  199. package/src/locales/en/system/user.ts +0 -113
  200. package/src/locales/en.ts +0 -68
  201. package/src/locales/zh/auth.ts +0 -70
  202. package/src/locales/zh/base/memory.ts +0 -29
  203. package/src/locales/zh/base/settings.ts +0 -41
  204. package/src/locales/zh/chat.ts +0 -47
  205. package/src/locales/zh/common.ts +0 -178
  206. package/src/locales/zh/enum.ts +0 -28
  207. package/src/locales/zh/menus/business-rules.ts +0 -47
  208. package/src/locales/zh/menus/feedback.ts +0 -62
  209. package/src/locales/zh/menus/knowledge.ts +0 -117
  210. package/src/locales/zh/menus/model-metadata/index.ts +0 -10
  211. package/src/locales/zh/menus/model-metadata/manage.ts +0 -151
  212. package/src/locales/zh/menus/model-metadata/role.ts +0 -47
  213. package/src/locales/zh/menus/model-metadata/training.ts +0 -64
  214. package/src/locales/zh/menus/skill.ts +0 -34
  215. package/src/locales/zh/system/agent-config.ts +0 -33
  216. package/src/locales/zh/system/department.ts +0 -69
  217. package/src/locales/zh/system/dict.ts +0 -44
  218. package/src/locales/zh/system/menu.ts +0 -47
  219. package/src/locales/zh/system/permission.ts +0 -94
  220. package/src/locales/zh/system/role.ts +0 -25
  221. package/src/locales/zh/system/sys-config.ts +0 -32
  222. package/src/locales/zh/system/sys-log.ts +0 -38
  223. package/src/locales/zh/system/user.ts +0 -114
  224. package/src/locales/zh.ts +0 -67
  225. package/src/main.tsx +0 -50
  226. package/src/meta/const/index.ts +0 -40
  227. package/src/meta/index-dict.ts +0 -56
  228. package/src/meta/index-enum.ts +0 -95
  229. package/src/meta/index.ts +0 -14
  230. package/src/meta/module/dict-data/runtime.ts +0 -199
  231. package/src/meta/module/dict-data/types.ts +0 -17
  232. package/src/meta/module/enum-data/runtime.ts +0 -75
  233. package/src/meta/module/enum-data/types.ts +0 -18
  234. package/src/router/index.tsx +0 -312
  235. package/src/styles/AntdThemeProvider.tsx +0 -40
  236. package/src/styles/antd-theme.ts +0 -20
  237. package/src/styles/global.less +0 -107
  238. package/src/styles/variable.less +0 -103
  239. package/src/types/feedback.ts +0 -43
  240. package/src/types/index.ts +0 -85
  241. package/src/types/menu.ts +0 -43
  242. package/src/utils/aesUtil.ts +0 -123
  243. package/src/utils/chatUtils.ts +0 -524
  244. package/src/utils/cn.ts +0 -6
  245. package/src/utils/crypto.ts +0 -164
  246. package/src/utils/date.ts +0 -72
  247. package/src/utils/file-icons.tsx +0 -79
  248. package/src/utils/index.ts +0 -168
  249. package/src/utils/markdown-math-plugins.ts +0 -21
  250. package/src/utils/menuI18n.ts +0 -305
  251. package/src/utils/menuRouteRegistry.ts +0 -78
  252. package/src/utils/permission-crud.ts +0 -147
  253. package/src/utils/routeConfig.ts +0 -350
  254. package/src/utils/storage.ts +0 -135
  255. package/src/utils/toastBridge.ts +0 -26
  256. package/src/utils/url.ts +0 -38
  257. package/src/utils/validation.ts +0 -16
  258. package/src/views/auth/auth-code/index.less +0 -169
  259. package/src/views/auth/auth-code/index.module.less +0 -174
  260. package/src/views/auth/auth-code/index.tsx +0 -233
  261. package/src/views/auth/login.tsx +0 -498
  262. package/src/views/auth/register.tsx +0 -388
  263. package/src/views/base/memory/index.tsx +0 -136
  264. package/src/views/base/memory/modal/detail-modal.tsx +0 -89
  265. package/src/views/base/memory/modal/submit-modal.tsx +0 -134
  266. package/src/views/base/settings/index.tsx +0 -657
  267. package/src/views/chat/chat.less +0 -323
  268. package/src/views/chat/components/chat-input.tsx +0 -298
  269. package/src/views/chat/components/header-thread-title.tsx +0 -210
  270. package/src/views/chat/components/message-list/content-answer.tsx +0 -100
  271. package/src/views/chat/components/message-list/content-question.tsx +0 -18
  272. package/src/views/chat/components/message-list/index.tsx +0 -520
  273. package/src/views/chat/components/message-list/message-item.tsx +0 -199
  274. package/src/views/chat/components/message-list/preparation-demo-items.ts +0 -147
  275. package/src/views/chat/components/message-list/preparation-steps.tsx +0 -506
  276. package/src/views/chat/components/message-list/suggestion-list.tsx +0 -36
  277. package/src/views/chat/components/message-list/thinking-process.tsx +0 -49
  278. package/src/views/chat/components/message-list/toolbar.tsx +0 -224
  279. package/src/views/chat/components/message-list/use-message-list-scroll.ts +0 -214
  280. package/src/views/chat/components/references-knowledge/context.tsx +0 -57
  281. package/src/views/chat/components/references-knowledge/index.ts +0 -9
  282. package/src/views/chat/components/references-knowledge/modal/knowledge-detail-drawer.tsx +0 -556
  283. package/src/views/chat/components/references-knowledge/modal/knowledge-doc-detail-drawer.tsx +0 -529
  284. package/src/views/chat/components/references-knowledge/panel.tsx +0 -115
  285. package/src/views/chat/hooks/use-chat-common.ts +0 -19
  286. package/src/views/chat/index-session.tsx +0 -647
  287. package/src/views/chat/index.tsx +0 -127
  288. package/src/views/page-error/401.tsx +0 -56
  289. package/src/views/page-error/404.tsx +0 -56
  290. package/src/views/page-menus/business-rules/index.tsx +0 -376
  291. package/src/views/page-menus/business-rules/modal/detail-modal.tsx +0 -186
  292. package/src/views/page-menus/business-rules/modal/scope-modal.tsx +0 -272
  293. package/src/views/page-menus/business-rules/modal/submit-modal.tsx +0 -142
  294. package/src/views/page-menus/feedback/components/feedback-dataset-list.tsx +0 -471
  295. package/src/views/page-menus/feedback/index.tsx +0 -166
  296. package/src/views/page-menus/feedback/modal/export-feedback-modal.tsx +0 -367
  297. package/src/views/page-menus/knowledge/components/doc-editor-by-type.tsx +0 -32
  298. package/src/views/page-menus/knowledge/components/doc-editor-type-file.tsx +0 -330
  299. package/src/views/page-menus/knowledge/detail.tsx +0 -600
  300. package/src/views/page-menus/knowledge/index.tsx +0 -337
  301. package/src/views/page-menus/knowledge/modal/detail-modal.tsx +0 -618
  302. package/src/views/page-menus/knowledge/modal/doc-detail-modal.tsx +0 -550
  303. package/src/views/page-menus/knowledge/modal/doc-parse.ts +0 -99
  304. package/src/views/page-menus/knowledge/modal/doc-submit-modal.tsx +0 -349
  305. package/src/views/page-menus/knowledge/modal/doc-type-picker-modal.tsx +0 -88
  306. package/src/views/page-menus/knowledge/modal/knowledge-user-select-modal.tsx +0 -283
  307. package/src/views/page-menus/knowledge/modal/submit-modal.tsx +0 -179
  308. package/src/views/page-menus/model-metadata/manage/components/metadata-detail-schema-tab.tsx +0 -114
  309. package/src/views/page-menus/model-metadata/manage/components/step1-basic-info.tsx +0 -232
  310. package/src/views/page-menus/model-metadata/manage/components/step2-schema.tsx +0 -316
  311. package/src/views/page-menus/model-metadata/manage/components/step3-permissions.tsx +0 -134
  312. package/src/views/page-menus/model-metadata/manage/components/step4-documents.tsx +0 -134
  313. package/src/views/page-menus/model-metadata/manage/components/step5-example-sql.tsx +0 -101
  314. package/src/views/page-menus/model-metadata/manage/components/submit-add.tsx +0 -338
  315. package/src/views/page-menus/model-metadata/manage/components/submit-edit.tsx +0 -276
  316. package/src/views/page-menus/model-metadata/manage/detail.tsx +0 -298
  317. package/src/views/page-menus/model-metadata/manage/hooks/model-metadata-submit-shared.ts +0 -113
  318. package/src/views/page-menus/model-metadata/manage/hooks/use-model-metadata-item-state.ts +0 -20
  319. package/src/views/page-menus/model-metadata/manage/index.tsx +0 -304
  320. package/src/views/page-menus/model-metadata/manage/modal/components/table-schema.ts +0 -374
  321. package/src/views/page-menus/model-metadata/manage/modal/components/use-table-detail-tabs.tsx +0 -151
  322. package/src/views/page-menus/model-metadata/manage/modal/components/use-table-submit-tabs.tsx +0 -423
  323. package/src/views/page-menus/model-metadata/manage/modal/detail-modal.tsx +0 -218
  324. package/src/views/page-menus/model-metadata/manage/modal/submit-modal.tsx +0 -261
  325. package/src/views/page-menus/model-metadata/manage/modal/table-detail-modal.tsx +0 -196
  326. package/src/views/page-menus/model-metadata/manage/modal/table-submit-modal.tsx +0 -229
  327. package/src/views/page-menus/model-metadata/manage/submit.tsx +0 -31
  328. package/src/views/page-menus/model-metadata/role/index.tsx +0 -207
  329. package/src/views/page-menus/model-metadata/role/modal/detail-modal.tsx +0 -97
  330. package/src/views/page-menus/model-metadata/role/modal/role-assign-users-modal.tsx +0 -254
  331. package/src/views/page-menus/model-metadata/role/modal/role-assign-users-panel.tsx +0 -393
  332. package/src/views/page-menus/model-metadata/role/modal/role-assign-users-utils.ts +0 -120
  333. package/src/views/page-menus/model-metadata/role/modal/role-permission-assign-panel.tsx +0 -698
  334. package/src/views/page-menus/model-metadata/role/modal/role-permission-modal.tsx +0 -237
  335. package/src/views/page-menus/model-metadata/role/modal/submit-modal.tsx +0 -135
  336. package/src/views/page-menus/model-metadata/training/components/detail-records/index.ts +0 -4
  337. package/src/views/page-menus/model-metadata/training/components/detail-records/node-card.tsx +0 -72
  338. package/src/views/page-menus/model-metadata/training/components/detail-records/summary-lines.ts +0 -196
  339. package/src/views/page-menus/model-metadata/training/components/detail-records/summary-list.tsx +0 -153
  340. package/src/views/page-menus/model-metadata/training/components/detail-records/timeline.tsx +0 -103
  341. package/src/views/page-menus/model-metadata/training/components/detail-records/types.ts +0 -82
  342. package/src/views/page-menus/model-metadata/training/detail.tsx +0 -159
  343. package/src/views/page-menus/model-metadata/training/index.tsx +0 -236
  344. package/src/views/page-menus/model-metadata/training/modal/update-detail-modal.tsx +0 -154
  345. package/src/views/page-menus/skill/index.tsx +0 -201
  346. package/src/views/page-menus/skill/modal/detail-modal.tsx +0 -156
  347. package/src/views/page-menus/skill/modal/submit-modal.tsx +0 -214
  348. package/src/views/page-system/agent-config/index.tsx +0 -370
  349. package/src/views/page-system/department/departmentFormShared.ts +0 -36
  350. package/src/views/page-system/department/index.tsx +0 -541
  351. package/src/views/page-system/department/modal/detail-modal.tsx +0 -94
  352. package/src/views/page-system/department/modal/member-role-modal.tsx +0 -128
  353. package/src/views/page-system/department/modal/submit-modal.tsx +0 -265
  354. package/src/views/page-system/dict/index.tsx +0 -440
  355. package/src/views/page-system/dict/modal/cate-submit-modal.tsx +0 -315
  356. package/src/views/page-system/dict/modal/submit-modal.tsx +0 -184
  357. package/src/views/page-system/logs/components/index.ts +0 -3
  358. package/src/views/page-system/logs/components/log-message-demo.tsx +0 -30
  359. package/src/views/page-system/logs/components/log-message-stream.ts +0 -184
  360. package/src/views/page-system/logs/components/message-list/content-answer.tsx +0 -100
  361. package/src/views/page-system/logs/components/message-list/content-question.tsx +0 -18
  362. package/src/views/page-system/logs/components/message-list/index.tsx +0 -515
  363. package/src/views/page-system/logs/components/message-list/message-item.tsx +0 -193
  364. package/src/views/page-system/logs/components/message-list/preparation-demo-items.ts +0 -147
  365. package/src/views/page-system/logs/components/message-list/preparation-steps.tsx +0 -506
  366. package/src/views/page-system/logs/components/message-list/suggestion-list.tsx +0 -36
  367. package/src/views/page-system/logs/components/message-list/thinking-process.tsx +0 -49
  368. package/src/views/page-system/logs/components/message-list/toolbar.tsx +0 -134
  369. package/src/views/page-system/logs/components/message-list/use-message-list-scroll.ts +0 -214
  370. package/src/views/page-system/logs/components/message-modal.tsx +0 -239
  371. package/src/views/page-system/logs/index.tsx +0 -132
  372. package/src/views/page-system/logs/modal/detail-modal.tsx +0 -157
  373. package/src/views/page-system/menu/components/menuFormShared.ts +0 -283
  374. package/src/views/page-system/menu/index.less +0 -12
  375. package/src/views/page-system/menu/index.tsx +0 -410
  376. package/src/views/page-system/menu/modal/icon-modal.less +0 -51
  377. package/src/views/page-system/menu/modal/icon-modal.tsx +0 -87
  378. package/src/views/page-system/menu/modal/submit-modal.tsx +0 -263
  379. package/src/views/page-system/permission/index.tsx +0 -562
  380. package/src/views/page-system/permission/modal/detail-modal.tsx +0 -179
  381. package/src/views/page-system/permission/modal/submit-modal.less +0 -146
  382. package/src/views/page-system/permission/modal/submit-modal.tsx +0 -650
  383. package/src/views/page-system/role/index.tsx +0 -163
  384. package/src/views/page-system/role/modal/detail-modal.tsx +0 -127
  385. package/src/views/page-system/role/modal/permission-assign-group-rules.ts +0 -86
  386. package/src/views/page-system/role/modal/permission-modal.tsx +0 -111
  387. package/src/views/page-system/role/modal/role-modal-shell-styles.ts +0 -21
  388. package/src/views/page-system/role/modal/role-permission-assign-panel.tsx +0 -916
  389. package/src/views/page-system/role/modal/role-permission-assign-shared.ts +0 -1047
  390. package/src/views/page-system/role/modal/submit-modal.tsx +0 -193
  391. package/src/views/page-system/sys-config/index.tsx +0 -294
  392. package/src/views/page-system/user/components/user-role-column.tsx +0 -87
  393. package/src/views/page-system/user/index.tsx +0 -439
  394. package/src/views/page-system/user/modal/assign-roles-modal.tsx +0 -389
  395. package/src/views/page-system/user/modal/detail-modal.tsx +0 -72
  396. package/src/views/page-system/user/modal/modal-style/submit-modal.less +0 -40
  397. package/src/views/page-system/user/modal/submit-modal.less +0 -40
  398. package/src/views/page-system/user/modal/submit-modal.tsx +0 -287
  399. package/src/views/page-system/user/userFormShared.ts +0 -51
  400. package/tailwind.config.js +0 -17
  401. package/tsconfig.app.json +0 -48
  402. package/tsconfig.json +0 -11
  403. package/tsconfig.node.json +0 -26
  404. package/vite.config.ts +0 -272
  405. /package/{public → dist}/favicon.ico +0 -0
  406. /package/{public → dist}/vite.svg +0 -0
@@ -1,1047 +0,0 @@
1
- import type { MenuTreeItem } from '@/types/menu'
2
- import { getMenuDisplayName } from '@/utils/menuI18n'
3
- import type { DataNode } from 'antd/es/tree'
4
- import type { TFunction } from 'i18next'
5
-
6
- import {
7
- PERMISSION_ASSIGN_CODE_BY_FIRST_SEGMENT,
8
- type PermissionAssignFirstSegmentConfig,
9
- } from './permission-assign-group-rules'
10
-
11
- export type PermissionRow = {
12
- id: string
13
- code: string
14
- description?: string
15
- name?: string
16
- menuId?: string
17
- /** 0=系统内置(界面不展示,提交时强制并入)1=基础(勾选菜单后不可取消)2=扩展 */
18
- apiType?: number
19
- sortOrder?: number
20
- httpMethod?: string
21
- }
22
-
23
- export type ResourceGroup = {
24
- resource: string
25
- resourceTitle?: string
26
- permissions: PermissionRow[]
27
- }
28
-
29
- export type MenuPermissionSection = {
30
- sectionKey: string
31
- sectionTitle: string
32
- anchorMenuId: string
33
- resourceGroups: ResourceGroup[]
34
- }
35
-
36
- export function unwrapMenuTreeResponse(res: unknown): any[] {
37
- const r = res as { data?: unknown } | unknown
38
- const d =
39
- r && typeof r === 'object' && 'data' in r ? (r as { data: unknown }).data : r
40
- return Array.isArray(d) ? d : []
41
- }
42
-
43
- export function flattenPermissionsFromMenuTree(
44
- nodes: any[],
45
- idKey: string,
46
- ): PermissionRow[] {
47
- const out: PermissionRow[] = []
48
- const visit = (list: any[]) => {
49
- for (const n of list) {
50
- const menuId = String(n?.[idKey] ?? '')
51
- const perms =
52
- n?.permissions ?? n?.permissionList ?? n?.permissionDTOList ?? []
53
- if (Array.isArray(perms)) {
54
- for (const p of perms) {
55
- if (p == null || typeof p !== 'object') continue
56
- const code = String((p as { code?: string }).code ?? '').trim()
57
- if (!code) continue
58
- const mid = String(
59
- (p as { menuId?: string }).menuId ?? menuId,
60
- ).trim()
61
- const rec = p as Record<string, unknown>
62
- const apiT = parseRecordApiType(rec)
63
- out.push({
64
- id: String((p as { id?: string | number }).id ?? `${mid}-${code}`),
65
- code,
66
- description: (p as { description?: string }).description,
67
- name: (p as { name?: string }).name,
68
- menuId: mid || menuId,
69
- apiType: apiT,
70
- sortOrder: parseRecordSortOrder(rec),
71
- httpMethod: parseRecordHttpMethod(rec),
72
- })
73
- }
74
- }
75
- const ch = n?.children
76
- if (Array.isArray(ch) && ch.length) visit(ch)
77
- }
78
- }
79
- visit(nodes)
80
- return out
81
- }
82
-
83
- function parseRecordApiType(p: Record<string, unknown>): number | undefined {
84
- const raw = p.apiType ?? p.api_type
85
- if (raw === '' || raw == null) return undefined
86
- const n = Number(raw)
87
- return Number.isFinite(n) ? n : undefined
88
- }
89
-
90
- function parseRecordSortOrder(p: Record<string, unknown>): number | undefined {
91
- const raw = p.sortOrder ?? p.sort_order
92
- if (raw === '' || raw == null) return undefined
93
- const n = Number(raw)
94
- return Number.isFinite(n) ? n : undefined
95
- }
96
-
97
- function parseRecordHttpMethod(p: Record<string, unknown>): string | undefined {
98
- const raw = p.httpMethod ?? p.http_method
99
- if (raw == null) return undefined
100
- const s = String(raw).trim()
101
- return s ? s.toUpperCase() : undefined
102
- }
103
-
104
- /** 组内:apiType 0→1→2→其它;同类型按 sortOrder 升序;再按 code */
105
- export function comparePermissionRowsForAssign(
106
- a: PermissionRow,
107
- b: PermissionRow,
108
- ): number {
109
- const rank = (t: number | undefined) =>
110
- t === 0 || t === 1 || t === 2 ? t : 3
111
- const ra = rank(a.apiType)
112
- const rb = rank(b.apiType)
113
- if (ra !== rb) return ra - rb
114
- const sa = a.sortOrder
115
- const sb = b.sortOrder
116
- const na = sa !== undefined && Number.isFinite(sa) ? sa : 0
117
- const nb = sb !== undefined && Number.isFinite(sb) ? sb : 0
118
- if (na !== nb) return na - nb
119
- return a.code.localeCompare(b.code)
120
- }
121
-
122
- /** Swagger UI 风格 HTTP 方法徽章(浅/深色) */
123
- export function swaggerHttpMethodBadgeClass(method: string | undefined): string {
124
- const m = String(method ?? '')
125
- .trim()
126
- .toUpperCase()
127
- const map: Record<string, string> = {
128
- GET:
129
- 'border border-[#61affe]/55 bg-[#61affe]/18 text-[#0b5ed7] dark:border-[#61affe]/35 dark:bg-[#61affe]/14 dark:text-[#9bd0f7]',
130
- POST:
131
- 'border border-[#49cc90]/55 bg-[#49cc90]/18 text-[#0d6e45] dark:border-[#49cc90]/35 dark:bg-[#49cc90]/12 dark:text-[#7ae3b5]',
132
- PUT:
133
- 'border border-[#fca130]/55 bg-[#fca130]/20 text-[#9a5b08] dark:border-[#fca130]/40 dark:bg-[#fca130]/14 dark:text-[#fcd9a8]',
134
- DELETE:
135
- 'border border-[#f93e3e]/50 bg-[#f93e3e]/16 text-[#b91c1c] dark:border-[#f93e3e]/35 dark:bg-[#f93e3e]/12 dark:text-[#fecaca]',
136
- PATCH:
137
- 'border border-[#50e3c2]/50 bg-[#50e3c2]/16 text-[#047857] dark:border-[#50e3c2]/35 dark:bg-[#50e3c2]/12 dark:text-[#99f6e4]',
138
- OPTIONS:
139
- 'border border-[#0d5aa7]/45 bg-[#0d5aa7]/12 text-[#0d5aa7] dark:border-[#7eb4d8]/35 dark:bg-[#0d5aa7]/22 dark:text-[#b8daf5]',
140
- HEAD:
141
- 'border border-[#9012fe]/45 bg-[#9012fe]/12 text-[#5b16a6] dark:border-[#9012fe]/35 dark:bg-[#9012fe]/12 dark:text-[#d8b4fe]',
142
- }
143
- return (
144
- map[m] ??
145
- 'border border-gray-300 bg-gray-100 text-gray-700 dark:border-gray-600 dark:bg-gray-800 dark:text-gray-300'
146
- )
147
- }
148
-
149
- /** 卡片左侧色条(Swagger 色系),不展示 method 文字时用;内置(apiType=0)不加 */
150
- export function swaggerHttpMethodLeftAccentClass(
151
- method: string | undefined,
152
- apiType: number | undefined,
153
- ): string {
154
- if (apiType === 0) return ''
155
- const m = String(method ?? '')
156
- .trim()
157
- .toUpperCase()
158
- const map: Record<string, string> = {
159
- GET: 'border-l-[3px] border-l-[#61affe]',
160
- POST: 'border-l-[3px] border-l-[#49cc90]',
161
- PUT: 'border-l-[3px] border-l-[#fca130]',
162
- DELETE: 'border-l-[3px] border-l-[#f93e3e]',
163
- PATCH: 'border-l-[3px] border-l-[#50e3c2]',
164
- OPTIONS: 'border-l-[3px] border-l-[#0d5aa7]',
165
- HEAD: 'border-l-[3px] border-l-[#9012fe]',
166
- }
167
- return map[m] ?? ''
168
- }
169
-
170
- export function dedupePermissionRows(rows: PermissionRow[]): PermissionRow[] {
171
- const seen = new Set<string>()
172
- const next: PermissionRow[] = []
173
- for (const r of rows) {
174
- const k = `${r.menuId || ''}::${r.code}`
175
- if (seen.has(k)) continue
176
- seen.add(k)
177
- next.push(r)
178
- }
179
- return next
180
- }
181
-
182
- /**
183
- * 将 `getPermissionListAPI` / 分页列表类响应中的条目转为分配面板用的 `PermissionRow[]`。
184
- */
185
- export function mapPermissionListResponseToRows(res: unknown): PermissionRow[] {
186
- const pickArray = (raw: unknown): unknown[] => {
187
- if (raw == null) return []
188
- if (Array.isArray(raw)) return raw
189
- if (typeof raw !== 'object') return []
190
- const o = raw as Record<string, unknown>
191
- if (Array.isArray(o.content)) return o.content
192
- if (Array.isArray(o.items)) return o.items
193
- if (Array.isArray(o.records)) return o.records
194
- if (o.data != null && typeof o.data === 'object') {
195
- const d = o.data as Record<string, unknown>
196
- if (Array.isArray(d.content)) return d.content
197
- if (Array.isArray(d.data)) return d.data
198
- if (Array.isArray(d.records)) return d.records
199
- }
200
- return []
201
- }
202
-
203
- const top =
204
- res && typeof res === 'object' && 'data' in (res as object)
205
- ? (res as { data: unknown }).data
206
- : res
207
- const items = pickArray(top)
208
- const out: PermissionRow[] = []
209
- for (const item of items) {
210
- if (item == null || typeof item !== 'object') continue
211
- const p = item as Record<string, unknown>
212
- const code = String(p.code ?? '').trim()
213
- if (!code) continue
214
- const menuId = String(p.menuId ?? p.menu_id ?? '').trim()
215
- const title = p.title ?? p.name
216
- const apiType = parseRecordApiType(p)
217
- out.push({
218
- id: String(p.id ?? `${menuId || 'p'}-${code}`),
219
- code,
220
- description: p.description != null ? String(p.description) : undefined,
221
- name: title != null ? String(title) : undefined,
222
- menuId,
223
- apiType,
224
- sortOrder: parseRecordSortOrder(p),
225
- httpMethod: parseRecordHttpMethod(p),
226
- })
227
- }
228
- return out
229
- }
230
-
231
- /** 解析角色已选菜单:支持 `getRoleMenuAPI` 及 `getRoleDetailAPI` 的 `data.menuIdList` 等字段。 */
232
- export function normalizeRoleMenuSnapshot(res: unknown): {
233
- menuIds: string[]
234
- halfCheckedMenuIds: string[]
235
- permissionCodes: string[]
236
- extraPermissionRows: PermissionRow[]
237
- } {
238
- const root =
239
- res && typeof res === 'object' && 'data' in (res as object)
240
- ? (res as { data: unknown }).data
241
- : res
242
- if (!root || typeof root !== 'object') {
243
- return {
244
- menuIds: [],
245
- halfCheckedMenuIds: [],
246
- permissionCodes: [],
247
- extraPermissionRows: [],
248
- }
249
- }
250
- const d = root as Record<string, unknown>
251
-
252
- const menuIdsFromRolePermissionDto = (): string[] => {
253
- const nested = d.rolePermissionCreateDTO
254
- if (!nested || typeof nested !== 'object') return []
255
- const n = nested as Record<string, unknown>
256
- if (Array.isArray(n.menuId)) return (n.menuId as unknown[]).map(String)
257
- if (Array.isArray(n.menuIds)) return (n.menuIds as unknown[]).map(String)
258
- return []
259
- }
260
-
261
- const menuIdsFromScalarMenuId = (): string[] => {
262
- const v = d.menuId
263
- if (typeof v === 'string' && v.trim()) {
264
- return v
265
- .split(/[,,\s]+/)
266
- .map((s) => s.trim())
267
- .filter(Boolean)
268
- }
269
- return []
270
- }
271
-
272
- let menuIds = Array.isArray(d.menuIdList)
273
- ? (d.menuIdList as unknown[]).map(String)
274
- : Array.isArray(d.menuIds)
275
- ? (d.menuIds as unknown[]).map(String)
276
- : Array.isArray(d.menuId)
277
- ? (d.menuId as unknown[]).map(String)
278
- : Array.isArray(d.checkedMenuKeys)
279
- ? (d.checkedMenuKeys as unknown[]).map(String)
280
- : menuIdsFromScalarMenuId()
281
-
282
- const fromDto = menuIdsFromRolePermissionDto()
283
- if (!menuIds.length && fromDto.length) {
284
- menuIds = fromDto
285
- } else if (fromDto.length) {
286
- menuIds = [...new Set([...menuIds.map(String), ...fromDto.map(String)])]
287
- }
288
-
289
- const halfCheckedMenuIds = Array.isArray(d.halfCheckedMenuIds)
290
- ? (d.halfCheckedMenuIds as unknown[]).map(String)
291
- : Array.isArray(d.halfCheckedKeys)
292
- ? (d.halfCheckedKeys as unknown[]).map(String)
293
- : []
294
-
295
- let permissionCodes: string[] = []
296
- let extraPermissionRows: PermissionRow[] = []
297
-
298
- if (Array.isArray(d.permissionCodes)) {
299
- permissionCodes = (d.permissionCodes as unknown[]).map(String)
300
- }
301
-
302
- const permArr = d.permissionRows ?? d.permissions
303
- if (Array.isArray(permArr) && permArr.length) {
304
- const first = permArr[0]
305
- if (typeof first === 'string') {
306
- permissionCodes = (permArr as string[]).map(String)
307
- } else if (first && typeof first === 'object') {
308
- extraPermissionRows = (permArr as Record<string, unknown>[]).map(
309
- (p, idx) => {
310
- const code = String(p.code ?? '').trim()
311
- const menuId = String(p.menuId ?? '').trim()
312
- return {
313
- id: String(p.id ?? `${menuId || 'p'}-${code || idx}`),
314
- code,
315
- description: p.description as string | undefined,
316
- name: p.name as string | undefined,
317
- menuId,
318
- apiType: parseRecordApiType(p),
319
- sortOrder: parseRecordSortOrder(p),
320
- httpMethod: parseRecordHttpMethod(p),
321
- }
322
- },
323
- )
324
- if (!permissionCodes.length && extraPermissionRows.length) {
325
- permissionCodes = extraPermissionRows.map((x) => x.code)
326
- }
327
- }
328
- }
329
-
330
- return {
331
- menuIds,
332
- halfCheckedMenuIds,
333
- permissionCodes,
334
- extraPermissionRows,
335
- }
336
- }
337
-
338
- /**
339
- * 解析接口权限快照:支持 `getRoleApiListAPI` 返回体,以及 `getRoleDetailAPI` 的 `data.apiIdList`。
340
- */
341
- export function normalizeRoleApiListSnapshot(res: unknown): {
342
- permissionCodes: string[]
343
- extraPermissionRows: PermissionRow[]
344
- apiIds: string[]
345
- } {
346
- const empty = (): {
347
- permissionCodes: string[]
348
- extraPermissionRows: PermissionRow[]
349
- apiIds: string[]
350
- } => ({
351
- permissionCodes: [],
352
- extraPermissionRows: [],
353
- apiIds: [],
354
- })
355
-
356
- const root =
357
- res && typeof res === 'object' && 'data' in (res as object)
358
- ? (res as { data: unknown }).data
359
- : res
360
-
361
- if (root == null) return empty()
362
-
363
- const asListRows = mapPermissionListResponseToRows(res)
364
- if (asListRows.length) {
365
- return {
366
- permissionCodes: asListRows.map((r) => r.code).filter(Boolean),
367
- extraPermissionRows: asListRows,
368
- apiIds: [],
369
- }
370
- }
371
-
372
- if (Array.isArray(root)) {
373
- const extra = mapPermissionListResponseToRows({ data: root })
374
- return {
375
- permissionCodes: extra.map((r) => r.code).filter(Boolean),
376
- extraPermissionRows: extra,
377
- apiIds: [],
378
- }
379
- }
380
-
381
- if (typeof root !== 'object') return empty()
382
-
383
- const d = root as Record<string, unknown>
384
- const apiIds: string[] = []
385
-
386
- const pushIdArray = (v: unknown) => {
387
- if (!Array.isArray(v)) return
388
- for (const x of v) {
389
- const s = String(x ?? '').trim()
390
- if (s) apiIds.push(s)
391
- }
392
- }
393
-
394
- pushIdArray(d.apiIdList)
395
- pushIdArray(d.apiId)
396
- if (!apiIds.length) pushIdArray(d.apiIds)
397
-
398
- const nested = d.rolePermissionCreateDTO
399
- if (nested && typeof nested === 'object') {
400
- const n = nested as Record<string, unknown>
401
- if (!apiIds.length) pushIdArray(n.apiId)
402
- if (!apiIds.length) pushIdArray(n.apiIds)
403
- }
404
-
405
- let permissionCodes: string[] = []
406
- if (Array.isArray(d.permissionCodes)) {
407
- permissionCodes = (d.permissionCodes as unknown[]).map(String).filter(Boolean)
408
- }
409
-
410
- const pickList = (o: Record<string, unknown>): unknown[] => {
411
- for (const k of [
412
- 'list',
413
- 'records',
414
- 'content',
415
- 'rows',
416
- 'apis',
417
- 'items',
418
- 'apiList',
419
- 'data',
420
- ]) {
421
- const v = o[k]
422
- if (Array.isArray(v)) return v
423
- }
424
- return []
425
- }
426
-
427
- const arr = pickList(d)
428
- let extraPermissionRows: PermissionRow[] = []
429
- if (arr.length && arr[0] != null && typeof arr[0] === 'object') {
430
- extraPermissionRows = mapPermissionListResponseToRows({ data: arr })
431
- if (!permissionCodes.length && extraPermissionRows.length) {
432
- permissionCodes = extraPermissionRows.map((r) => r.code).filter(Boolean)
433
- }
434
- }
435
-
436
- return {
437
- permissionCodes,
438
- extraPermissionRows,
439
- apiIds: [...new Set(apiIds)],
440
- }
441
- }
442
-
443
- export function mapMenusToTreeData(
444
- nodes: any[],
445
- t: TFunction,
446
- lang: string,
447
- idKey: string,
448
- childrenKey: string,
449
- ): DataNode[] {
450
- return nodes.map((n) => {
451
- const children = n[childrenKey] as any[] | undefined
452
- const hasChildren = Array.isArray(children) && children.length > 0
453
- return {
454
- key: String(n[idKey]),
455
- title: getMenuDisplayName(n as MenuTreeItem, t, lang),
456
- children: hasChildren
457
- ? mapMenusToTreeData(children!, t, lang, idKey, childrenKey)
458
- : undefined,
459
- }
460
- })
461
- }
462
-
463
- type MenuCheckInferState = 'off' | 'full' | 'half'
464
-
465
- /**
466
- * `checkStrictly` 下回显:后端常把「全选 + 半选」合并进 `menuIdList` 且不返回 half 字段,
467
- * 若整表当作 checked 会导致父级误显示为全选。在 `mergedMenuIds` 为合并集合时拆出严格 checked / halfChecked。
468
- */
469
- export function inferStrictMenuCheckFromMergedMenuIds(
470
- treeNodes: DataNode[],
471
- mergedMenuIds: string[],
472
- ): { checkedKeys: string[]; halfCheckedKeys: string[] } {
473
- const S = new Set(mergedMenuIds.map((x) => String(x).trim()).filter(Boolean))
474
- const checkedKeys: string[] = []
475
- const halfCheckedKeys: string[] = []
476
-
477
- const walk = (node: DataNode): MenuCheckInferState => {
478
- const key = String(node.key)
479
- const children = (node.children ?? []) as DataNode[]
480
- const childStates = children.map((c) => walk(c))
481
-
482
- if (!S.has(key)) {
483
- return 'off'
484
- }
485
- if (!children.length) {
486
- checkedKeys.push(key)
487
- return 'full'
488
- }
489
- const anyChildOn = childStates.some((s) => s !== 'off')
490
- if (!anyChildOn) {
491
- checkedKeys.push(key)
492
- return 'full'
493
- }
494
- const allChildrenFull = childStates.every((s) => s === 'full')
495
- if (allChildrenFull) {
496
- checkedKeys.push(key)
497
- return 'full'
498
- }
499
- halfCheckedKeys.push(key)
500
- return 'half'
501
- }
502
-
503
- for (const root of treeNodes) {
504
- walk(root)
505
- }
506
-
507
- return { checkedKeys, halfCheckedKeys }
508
- }
509
-
510
- export function findFirstLeafId(
511
- nodes: any[],
512
- idKey: string,
513
- childrenKey: string,
514
- ): string | number | null {
515
- for (const n of nodes) {
516
- const ch = n?.[childrenKey]
517
- if (!Array.isArray(ch) || !ch.length) {
518
- return n[idKey]
519
- }
520
- const deeper = findFirstLeafId(ch, idKey, childrenKey)
521
- if (deeper != null) return deeper
522
- }
523
- return null
524
- }
525
-
526
- export function getMenuPathFromRoot(
527
- roots: any[],
528
- targetId: string,
529
- idKey: string,
530
- childrenKey: string,
531
- ): any[] | null {
532
- const dfs = (nodes: any[], stack: any[]): any[] | null => {
533
- for (const n of nodes) {
534
- const next = [...stack, n]
535
- if (String(n[idKey]) === targetId) return next
536
- const ch = n[childrenKey]
537
- if (Array.isArray(ch) && ch.length) {
538
- const hit = dfs(ch, next)
539
- if (hit) return hit
540
- }
541
- }
542
- return null
543
- }
544
- return dfs(roots, [])
545
- }
546
-
547
- export function menuPreorderIndexMap(
548
- nodes: any[],
549
- idKey: string,
550
- childrenKey: string,
551
- ): Map<string, number> {
552
- const m = new Map<string, number>()
553
- let i = 0
554
- const walk = (list: any[]) => {
555
- for (const n of list) {
556
- m.set(String(n[idKey]), i++)
557
- const ch = n[childrenKey]
558
- if (Array.isArray(ch) && ch.length) walk(ch)
559
- }
560
- }
561
- walk(nodes)
562
- return m
563
- }
564
-
565
- function permAssignI18n(key: string): string {
566
- return `system.permission.${key}`
567
- }
568
-
569
- /**
570
- * 与分配面板分组一致:**仅按 `:` 分段**(trim、去 BOM);不把 `-` 当成层级,避免 `system-logs:page`
571
- * 被误解析成 `system` + `logs` 从而命中 `system` 配置。
572
- */
573
- export function splitPermissionCodeParts(code: string): string[] {
574
- const raw = String(code ?? '')
575
- .replace(/\ufeff/g, '')
576
- .trim()
577
- return raw
578
- .split(':')
579
- .map((s) => s.trim())
580
- .filter((s) => s !== '')
581
- }
582
-
583
- /**
584
- * 仅由菜单树决定的基础分组标题(不含 code 分支后缀):
585
- * - 顶级挂载(路径单节点,或 level=0):`assign_panel.top_level_group_title`(默认「系统」,替代原「公共」)
586
- * - 二级挂载(level=2):同级仅 1 个 → 只显示二级菜单名;多个 →「一级 > 二级」
587
- * - 其它:从路径第二层起拼接菜单名
588
- */
589
- export function buildMenuBaseTitleForAssign(
590
- path: any[] | null,
591
- t: TFunction,
592
- lang: string,
593
- idKey: string,
594
- childrenKey: string,
595
- ): string {
596
- /** 无菜单路径(如接口清单未挂 menuId):与「仅挂顶级」一致用配置标题,避免整段 `-` */
597
- if (!path?.length) {
598
- return String(t(permAssignI18n('assign_panel.top_level_group_title')))
599
- }
600
- const anchor = path[path.length - 1]
601
- const anchorLv = Number(anchor?.level)
602
- const sep = String(
603
- t(permAssignI18n('menu_level_sep'), { defaultValue: '>' }),
604
- )
605
-
606
- /** 树路径仅挂载节点一个:顶级菜单下的权限,标题用「系统」等配置(替代原「公共」) */
607
- if (path.length === 1) {
608
- return String(t(permAssignI18n('assign_panel.top_level_group_title')))
609
- }
610
-
611
- if (Number.isFinite(anchorLv) && anchorLv === 2 && path.length >= 2) {
612
- const parent = path[path.length - 2]
613
- const siblings = parent?.[childrenKey]
614
- const n = Array.isArray(siblings) ? siblings.length : 0
615
- const anchorName = String(
616
- getMenuDisplayName(anchor as MenuTreeItem, t, lang),
617
- )
618
- if (n <= 1) return anchorName
619
- const parentName = String(
620
- getMenuDisplayName(parent as MenuTreeItem, t, lang),
621
- )
622
- return `${parentName} ${sep} ${anchorName}`
623
- }
624
-
625
- if (
626
- (!Number.isFinite(anchorLv) || anchor?.level === undefined) &&
627
- path.length >= 3
628
- ) {
629
- const parent = path[path.length - 2]
630
- const siblings = parent?.[childrenKey]
631
- const n = Array.isArray(siblings) ? siblings.length : 0
632
- const anchorName = String(
633
- getMenuDisplayName(anchor as MenuTreeItem, t, lang),
634
- )
635
- if (n <= 1) return anchorName
636
- const parentName = String(
637
- getMenuDisplayName(parent as MenuTreeItem, t, lang),
638
- )
639
- return `${parentName} ${sep} ${anchorName}`
640
- }
641
-
642
- const belowRoot = path.slice(1)
643
- const titles = belowRoot.map((n) =>
644
- String(getMenuDisplayName(n as MenuTreeItem, t, lang)),
645
- )
646
- return titles.join(` ${sep} `)
647
- }
648
-
649
- function matchConfiguredCodeBranch(
650
- parts: string[],
651
- cfg: PermissionAssignFirstSegmentConfig,
652
- ): { branchKey: string; suffixI18nKey: string | null } {
653
- const lower = parts.map((p) => p.toLowerCase())
654
- const sorted = [...cfg.branches].sort(
655
- (a, b) => b.prefix.length - a.prefix.length,
656
- )
657
- for (const br of sorted) {
658
- const ok = br.prefix.every((seg, i) => lower[i] === seg.toLowerCase())
659
- if (ok) {
660
- // 使用 sortOrder 作为 branchKey 前缀,控制分组显示顺序
661
- const orderPrefix = br.sortOrder !== undefined ? String(br.sortOrder).padStart(3, '0') : '999'
662
- return { branchKey: `${orderPrefix}_${br.prefix.join('_')}`, suffixI18nKey: br.suffixI18nKey }
663
- }
664
- }
665
- /** dict:第二段为 cate 或以 cate- 开头(如 dict:cate-add)与 dict:cate:x 同属「分类」组 */
666
- if (lower[0] === 'dict' && parts.length >= 2) {
667
- const s2 = lower[1]
668
- const cateBr = cfg.branches.find(
669
- (b) =>
670
- b.prefix.length === 2 &&
671
- b.prefix[0].toLowerCase() === 'dict' &&
672
- b.prefix[1].toLowerCase() === 'cate',
673
- )
674
- if (cateBr && (s2 === 'cate' || s2.startsWith('cate-'))) {
675
- const orderPrefix = cateBr.sortOrder !== undefined ? String(cateBr.sortOrder).padStart(3, '0') : '999'
676
- return {
677
- branchKey: `${orderPrefix}_${cateBr.prefix.join('_')}`,
678
- suffixI18nKey: cateBr.suffixI18nKey,
679
- }
680
- }
681
- }
682
- /** system:第二段不是 file / chat 的均归「公共」(含两段及以上未命中上面分支) */
683
- if (
684
- cfg.defaultSuffixI18nKey &&
685
- lower[0] === 'system' &&
686
- parts.length >= 2
687
- ) {
688
- const seg2 = lower[1]
689
- if (seg2 !== 'file' && seg2 !== 'chat' && seg2 !== 'auth') {
690
- const orderPrefix = String(cfg.defaultSortOrder ?? 500).padStart(3, '0')
691
- return { branchKey: `${orderPrefix}_default`, suffixI18nKey: cfg.defaultSuffixI18nKey }
692
- }
693
- }
694
- if (cfg.defaultSuffixI18nKey && parts.length >= 2) {
695
- const orderPrefix = String(cfg.defaultSortOrder ?? 500).padStart(3, '0')
696
- return { branchKey: `${orderPrefix}_default`, suffixI18nKey: cfg.defaultSuffixI18nKey }
697
- }
698
- return { branchKey: 'none', suffixI18nKey: null }
699
- }
700
-
701
- function resolveMenuPartForCodeBranch(
702
- path: any[],
703
- cfg: PermissionAssignFirstSegmentConfig,
704
- t: TFunction,
705
- lang: string,
706
- idKey: string,
707
- childrenKey: string,
708
- ): string {
709
- if (cfg.menuBaseOverrideI18nKey) {
710
- return String(t(permAssignI18n(cfg.menuBaseOverrideI18nKey)))
711
- }
712
- if (cfg.menuBaseUseParentOfAnchor && path.length >= 2) {
713
- return String(
714
- getMenuDisplayName(
715
- path[path.length - 2] as MenuTreeItem,
716
- t,
717
- lang,
718
- ),
719
- )
720
- }
721
- return buildMenuBaseTitleForAssign(path, t, lang, idKey, childrenKey)
722
- }
723
-
724
- /** 未绑定菜单的权限在右栏锚点、与树联动占位(不对应真实菜单节点) */
725
- export const PERMISSION_ASSIGN_UNBOUND_ANCHOR_ID = '__unbound__'
726
-
727
- /**
728
- * 单条权限在分配面板中的分组:标题 = 菜单规则 ± code 配置分支;未配置首段时仅菜单标题。
729
- * `path` 可为 `null`:接口等未挂 `menuId` 时仍按 code 首段配置归类(如 system → 公共)。
730
- */
731
- export function computePermissionAssignSection(
732
- path: any[] | null,
733
- code: string,
734
- idKey: string,
735
- childrenKey: string,
736
- t: TFunction,
737
- lang: string,
738
- ): { sectionKey: string; sectionTitle: string; anchorMenuId: string } | null {
739
- const hasPath = Boolean(path?.length)
740
- const anchorMenuId = hasPath
741
- ? String(path![path!.length - 1][idKey])
742
- : PERMISSION_ASSIGN_UNBOUND_ANCHOR_ID
743
- const pathKey = hasPath
744
- ? path!.slice(1).map((n) => String(n[idKey])).join('__') || anchorMenuId
745
- : PERMISSION_ASSIGN_UNBOUND_ANCHOR_ID
746
- const parts = splitPermissionCodeParts(code)
747
- const first = (parts[0] || '').toLowerCase()
748
- const sep = String(
749
- t(permAssignI18n('menu_level_sep'), { defaultValue: '>' }),
750
- )
751
-
752
- const cfg = PERMISSION_ASSIGN_CODE_BY_FIRST_SEGMENT[first]
753
- if (!cfg) {
754
- const base = buildMenuBaseTitleForAssign(
755
- path,
756
- t,
757
- lang,
758
- idKey,
759
- childrenKey,
760
- )
761
- return {
762
- sectionKey: `${pathKey}::plain`,
763
- sectionTitle: base,
764
- anchorMenuId,
765
- }
766
- }
767
-
768
- const { branchKey, suffixI18nKey } = matchConfiguredCodeBranch(parts, cfg)
769
- const menuPart = resolveMenuPartForCodeBranch(
770
- path,
771
- cfg,
772
- t,
773
- lang,
774
- idKey,
775
- childrenKey,
776
- )
777
- let sectionTitle = menuPart
778
- if (
779
- first === 'dict' &&
780
- branchKey === 'default' &&
781
- hasPath &&
782
- path!.length >= 2
783
- ) {
784
- /** 数据字典数据类:「一级父级 > 二级挂载菜单名」(不用 i18n 末段,与菜单树一致) */
785
- const parent = path![path!.length - 2] as MenuTreeItem
786
- const anchor = path![path!.length - 1] as MenuTreeItem
787
- sectionTitle = `${String(getMenuDisplayName(parent, t, lang))} ${sep} ${String(getMenuDisplayName(anchor, t, lang))}`
788
- } else if (suffixI18nKey) {
789
- sectionTitle = `${menuPart} ${sep} ${String(t(permAssignI18n(suffixI18nKey)))}`
790
- }
791
- return {
792
- sectionKey: `${pathKey}::${first}::${branchKey}`,
793
- sectionTitle,
794
- anchorMenuId,
795
- }
796
- }
797
-
798
- export function collectSubtreeMenuIds(
799
- roots: any[],
800
- rootMenuId: string,
801
- idKey: string,
802
- childrenKey: string,
803
- ): Set<string> {
804
- const path = getMenuPathFromRoot(roots, rootMenuId, idKey, childrenKey)
805
- const target = path?.length ? path[path.length - 1] : null
806
- const out = new Set<string>()
807
- if (!target) {
808
- out.add(rootMenuId)
809
- return out
810
- }
811
- const walk = (n: any) => {
812
- out.add(String(n[idKey]))
813
- const ch = n[childrenKey]
814
- if (Array.isArray(ch) && ch.length) for (const c of ch) walk(c)
815
- }
816
- walk(target)
817
- return out
818
- }
819
-
820
- export function preorderSubtreeMenuIds(
821
- roots: any[],
822
- rootMenuId: string,
823
- idKey: string,
824
- childrenKey: string,
825
- ): string[] {
826
- const path = getMenuPathFromRoot(roots, rootMenuId, idKey, childrenKey)
827
- const target = path?.length ? path[path.length - 1] : null
828
- const order: string[] = []
829
- if (!target) return order
830
- const walk = (n: any) => {
831
- order.push(String(n[idKey]))
832
- const ch = n[childrenKey]
833
- if (Array.isArray(ch) && ch.length) for (const c of ch) walk(c)
834
- }
835
- walk(target)
836
- return order
837
- }
838
-
839
- export function menuHasBoundPermissions(
840
- menuId: string,
841
- rows: PermissionRow[],
842
- ): boolean {
843
- for (const r of rows) {
844
- if (String(r.menuId || '').trim() === menuId) return true
845
- }
846
- return false
847
- }
848
-
849
- export function resolveScrollAnchorForMenuClick(
850
- roots: any[],
851
- menuId: string,
852
- rows: PermissionRow[],
853
- idKey: string,
854
- childrenKey: string,
855
- ): string | null {
856
- if (!rows.length) return null
857
- if (menuHasBoundPermissions(menuId, rows)) return menuId
858
-
859
- const path = getMenuPathFromRoot(roots, menuId, idKey, childrenKey)
860
- if (!path?.length) return null
861
-
862
- const isFirstLevelUnderRoot = path.length === 2
863
- if (isFirstLevelUnderRoot) {
864
- const l1 = path[path.length - 1]
865
- const children = l1[childrenKey]
866
- if (Array.isArray(children) && children.length) {
867
- for (const ch of children) {
868
- const cid = String(ch[idKey])
869
- if (menuHasBoundPermissions(cid, rows)) return cid
870
- }
871
- }
872
- }
873
-
874
- const ordered = preorderSubtreeMenuIds(roots, menuId, idKey, childrenKey)
875
- return (
876
- ordered.find(
877
- (id) => id !== menuId && menuHasBoundPermissions(id, rows),
878
- ) ?? null
879
- )
880
- }
881
-
882
- export function isPermissionRowBuiltin(row: PermissionRow): boolean {
883
- return row.apiType === 0
884
- }
885
-
886
- /** apiType=1 且所属菜单在勾选/半选集合中:随菜单必选,不可在右栏取消 */
887
- export function isPermissionRowMenuLockedBase(
888
- row: PermissionRow,
889
- menuCheckedOrHalfIds: Set<string>,
890
- ): boolean {
891
- if (row.apiType !== 1) return false
892
- const mid = String(row.menuId || '').trim()
893
- return Boolean(mid && menuCheckedOrHalfIds.has(mid))
894
- }
895
-
896
- export function isAssignPermissionChecked(
897
- codes: string[],
898
- row: PermissionRow,
899
- menuCheckedOrHalfIds: Set<string>,
900
- ): boolean {
901
- if (isPermissionRowBuiltin(row)) return true
902
- if (codes.includes('*')) return true
903
- if (codes.includes(row.code)) return true
904
- if (isPermissionRowMenuLockedBase(row, menuCheckedOrHalfIds)) return true
905
- return false
906
- }
907
-
908
- /**
909
- * 提交用:并入全部系统内置(0);对已勾选菜单下的基础权限(1)保证在码列表中。
910
- */
911
- export function mergeRolePermissionAssignPayloadCodes(
912
- selectedCodes: string[],
913
- allRows: PermissionRow[],
914
- menuIdsMerged: string[],
915
- ): string[] {
916
- if (selectedCodes.includes('*')) return selectedCodes
917
- const menuSet = new Set(
918
- menuIdsMerged.map((x) => String(x).trim()).filter(Boolean),
919
- )
920
- const out = new Set(selectedCodes.filter(Boolean))
921
- for (const r of allRows) {
922
- if (r.apiType === 0) {
923
- out.add(r.code)
924
- continue
925
- }
926
- if (r.apiType === 1) {
927
- const mid = String(r.menuId || '').trim()
928
- if (mid && menuSet.has(mid)) out.add(r.code)
929
- }
930
- }
931
- return Array.from(out)
932
- }
933
-
934
- /** 初始化勾选态:在已有快照码基础上补上「已选菜单」下的基础权限(1),避免详情回显缺勾 */
935
- export function augmentInitialMenuBasePermissionCodes(
936
- codes: string[],
937
- allRows: PermissionRow[],
938
- menuIdsCheckedOrHalf: string[],
939
- ): string[] {
940
- if (codes.includes('*')) return codes
941
- const menuSet = new Set(
942
- menuIdsCheckedOrHalf.map((x) => String(x).trim()).filter(Boolean),
943
- )
944
- const out = new Set(codes.filter(Boolean))
945
- for (const r of allRows) {
946
- if (r.apiType !== 1) continue
947
- const mid = String(r.menuId || '').trim()
948
- if (mid && menuSet.has(mid)) out.add(r.code)
949
- }
950
- return Array.from(out)
951
- }
952
-
953
- export function codesForRowsInMenuSubtree(
954
- rows: PermissionRow[],
955
- subtreeMenuIds: Set<string>,
956
- ): Set<string> {
957
- const codes = new Set<string>()
958
- for (const r of rows) {
959
- if (isPermissionRowBuiltin(r)) continue
960
- const mid = String(r.menuId || '').trim()
961
- if (mid && subtreeMenuIds.has(mid)) codes.add(r.code)
962
- }
963
- return codes
964
- }
965
-
966
- export function nextPermissionCodesForMenuSubtree(
967
- prev: string[],
968
- rows: PermissionRow[],
969
- subtreeCodes: Set<string>,
970
- grant: boolean,
971
- ): string[] {
972
- if (subtreeCodes.size === 0) return prev
973
-
974
- if (grant) {
975
- if (prev.includes('*')) return prev
976
- const s = new Set(prev)
977
- for (const c of subtreeCodes) s.add(c)
978
- return Array.from(s)
979
- }
980
-
981
- if (prev.includes('*')) {
982
- const all = new Set(rows.map((r) => r.code))
983
- for (const c of subtreeCodes) all.delete(c)
984
- return Array.from(all)
985
- }
986
- return prev.filter((c) => !subtreeCodes.has(c))
987
- }
988
-
989
- export function isPermissionChecked(codes: string[], code: string): boolean {
990
- if (codes.includes('*')) return true
991
- return codes.includes(code)
992
- }
993
-
994
- /** 与后端 `/role` POST、PUT 体中 `rolePermissionCreateDTO` 字段对齐 */
995
- export type RolePermissionCreateDTO = {
996
- menuId: string[]
997
- apiId: string[]
998
- }
999
-
1000
- /** 未勾选菜单/接口权限时仍须传该对象,数组为空即可 */
1001
- export const EMPTY_ROLE_PERMISSION_CREATE_DTO: RolePermissionCreateDTO = {
1002
- menuId: [],
1003
- apiId: [],
1004
- }
1005
-
1006
- /** menuIds 为全选 + 半选菜单 id 合并去重(半选仅树展示用,提交不再单独字段) */
1007
- export type RolePermissionAssignPayload = {
1008
- menuIds: string[]
1009
- permissionCodes: string[]
1010
- rolePermissionCreateDTO: RolePermissionCreateDTO
1011
- }
1012
-
1013
- /** 由已合并的菜单 id + 权限码解析为接口所需的 menuId / apiId */
1014
- export function buildRolePermissionCreateDTO(
1015
- menuIds: string[],
1016
- permissionCodes: string[],
1017
- allPermissionRows: PermissionRow[],
1018
- ): RolePermissionCreateDTO {
1019
- const menuId = [
1020
- ...new Set(menuIds.map((x) => String(x).trim()).filter(Boolean)),
1021
- ]
1022
-
1023
- let apiId: string[] = []
1024
- if (permissionCodes.includes('*')) {
1025
- apiId = [
1026
- ...new Set(
1027
- allPermissionRows.map((r) => String(r.id).trim()).filter(Boolean),
1028
- ),
1029
- ]
1030
- } else {
1031
- const seen = new Set<string>()
1032
- for (const code of permissionCodes) {
1033
- for (const r of allPermissionRows) {
1034
- if (r.code === code && !seen.has(r.id)) {
1035
- seen.add(r.id)
1036
- apiId.push(String(r.id))
1037
- }
1038
- }
1039
- }
1040
- }
1041
-
1042
- return { menuId, apiId }
1043
- }
1044
-
1045
- export function isRolePermissionPayloadEmpty(p: RolePermissionAssignPayload): boolean {
1046
- return p.menuIds.length === 0 && p.permissionCodes.length === 0
1047
- }