cx-chat 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (404) hide show
  1. package/.cursor/rules/i18n-cn-gloss-comments.mdc +31 -0
  2. package/.cursor/rules/list-page-view-pageconfig.mdc +32 -0
  3. package/.cursor/rules/no-over-defensive-programming.mdc +90 -0
  4. package/.cursor/rules/requirement-description-for-agent.mdc +33 -0
  5. package/.cursor/rules/use-showToast-not-antd-message.mdc +28 -0
  6. package/.docker/Dockerfile +7 -0
  7. package/.env +9 -0
  8. package/.env.development +7 -0
  9. package/.env.production +7 -0
  10. package/.gitlab-ci/docker-build.yaml +28 -0
  11. package/.gitlab-ci/k8s-deploy-dev-master.yaml +42 -0
  12. package/.gitlab-ci/npm-build.yaml +17 -0
  13. package/.gitlab-ci.yml +8 -0
  14. package/.k8s/0-namespace.yaml +6 -0
  15. package/.k8s/1-configmap-web.yaml +7 -0
  16. package/.k8s/1-nginx-conf-dev.yaml +110 -0
  17. package/.k8s/2-deployment.yaml +27 -0
  18. package/.k8s/3-service.yaml +16 -0
  19. package/.k8s/4-ingress-dev.yaml +30 -0
  20. package/.lingma/rules/use-showToast-not-antd-message.md +34 -0
  21. package/.nginx/nginx.conf +52 -0
  22. package/.prettierrc +9 -0
  23. package/README.md +1 -0
  24. package/eslint.config.js +32 -0
  25. package/index.html +13 -0
  26. package/package.json +67 -0
  27. package/postcss.config.js +6 -0
  28. package/public/favicon.ico +0 -0
  29. package/public/vite.svg +1 -0
  30. package/src/App.tsx +96 -0
  31. package/src/_doc/0.docs-overview.md +28 -0
  32. package/src/_doc/cx-ui/0.docs-overview.md +30 -0
  33. package/src/_doc/cx-ui/comp.1.cx-ui-overview.md +82 -0
  34. package/src/_doc/cx-ui/comp.2.cx-modal.md +82 -0
  35. package/src/_doc/cx-ui/comp.3.cx-button.md +89 -0
  36. package/src/_doc/cx-ui/comp.4.cx-form.md +72 -0
  37. package/src/_doc/cx-ui/comp.5.cx-fields.md +76 -0
  38. package/src/_doc/cx-ui/comp.6.cx-tag.md +57 -0
  39. package/src/_doc/cx-ui/comp.7.cx-empty-state.md +29 -0
  40. package/src/_doc/meta/0.docs-overview.md +24 -0
  41. package/src/_doc/meta/comp.1.enum-runtime.md +33 -0
  42. package/src/_doc/meta/comp.2.dict-runtime.md +39 -0
  43. package/src/_doc/router/0.docs-overview.md +14 -0
  44. package/src/_doc/router/guide.1.menu-component-config.md +181 -0
  45. package/src/_doc/router/guide.2.router-auto-registration.md +114 -0
  46. package/src/_doc/table-view/0.docs-overview.md +30 -0
  47. package/src/_doc/table-view/comp.1.table-view.md +542 -0
  48. package/src/_doc/table-view/props.1.create-table-view-config.md +193 -0
  49. package/src/_doc/table-view/props.2.table-view-search-fields.md +106 -0
  50. package/src/api/_mock/README.md +340 -0
  51. package/src/api/_mock/api.ts +1642 -0
  52. package/src/api/_mock/bundle-shim.ts +16 -0
  53. package/src/api/_mock/handler-shim.ts +6 -0
  54. package/src/api/_mock/handler.ts +458 -0
  55. package/src/api/_mock/index.ts +711 -0
  56. package/src/api/_mock/interceptor.ts +15 -0
  57. package/src/api/_mock/mod.ts +12 -0
  58. package/src/api/_mock/utils.ts +65 -0
  59. package/src/api/base/memory.js +24 -0
  60. package/src/api/chat.js +210 -0
  61. package/src/api/common/auth.js +70 -0
  62. package/src/api/menus/business-rules.js +76 -0
  63. package/src/api/menus/feedback.js +102 -0
  64. package/src/api/menus/knowledge.js +159 -0
  65. package/src/api/menus/model-metadata/manage.js +70 -0
  66. package/src/api/menus/model-metadata/role.js +50 -0
  67. package/src/api/menus/model-metadata/training-detail-mock-data.js +569 -0
  68. package/src/api/menus/model-metadata/training.js +28 -0
  69. package/src/api/menus/skill.js +40 -0
  70. package/src/api/system/agent-config.js +16 -0
  71. package/src/api/system/department.js +94 -0
  72. package/src/api/system/dict.js +86 -0
  73. package/src/api/system/menu.js +37 -0
  74. package/src/api/system/permission.js +26 -0
  75. package/src/api/system/role.js +34 -0
  76. package/src/api/system/sys-config.js +16 -0
  77. package/src/api/system/sys-log.js +17 -0
  78. package/src/api/system/user.js +75 -0
  79. package/src/api/upload.js +39 -0
  80. package/src/assets/react.svg +1 -0
  81. package/src/components/auth/current-user-avatar.tsx +77 -0
  82. package/src/components/common/code-view.tsx +149 -0
  83. package/src/components/common/detail-link.tsx +67 -0
  84. package/src/components/common/error-boundary.tsx +98 -0
  85. package/src/components/common/language-switcher.tsx +91 -0
  86. package/src/components/common/lite-table/index.tsx +135 -0
  87. package/src/components/common/md-editor.tsx +126 -0
  88. package/src/components/common/modal/confirm-dialog.tsx +113 -0
  89. package/src/components/common/modal/dep-user-select-multi.tsx +324 -0
  90. package/src/components/common/modal/dep-user-select.tsx +249 -0
  91. package/src/components/common/modal/user-select-multi.tsx +266 -0
  92. package/src/components/common/pagination.tsx +472 -0
  93. package/src/components/common/path.tsx +175 -0
  94. package/src/components/common/system-logo-mark.tsx +48 -0
  95. package/src/components/cx-ui/button/index.less +208 -0
  96. package/src/components/cx-ui/button/index.tsx +611 -0
  97. package/src/components/cx-ui/checkbox/index.tsx +78 -0
  98. package/src/components/cx-ui/date-picker/index.less +17 -0
  99. package/src/components/cx-ui/date-picker/index.tsx +193 -0
  100. package/src/components/cx-ui/drawer/index.tsx +47 -0
  101. package/src/components/cx-ui/empty-state/index.tsx +20 -0
  102. package/src/components/cx-ui/floating-shell/CxFloatingShell.tsx +89 -0
  103. package/src/components/cx-ui/floating-shell/cx-floating-shell.less +283 -0
  104. package/src/components/cx-ui/floating-shell/has-floating-value.ts +41 -0
  105. package/src/components/cx-ui/form/CxForm.tsx +15 -0
  106. package/src/components/cx-ui/form/index.tsx +20 -0
  107. package/src/components/cx-ui/form-item/index.less +26 -0
  108. package/src/components/cx-ui/form-item/index.tsx +36 -0
  109. package/src/components/cx-ui/index.ts +70 -0
  110. package/src/components/cx-ui/input/auto-complete.tsx +134 -0
  111. package/src/components/cx-ui/input/index.tsx +259 -0
  112. package/src/components/cx-ui/input-number/index.jsx +66 -0
  113. package/src/components/cx-ui/modal/index.jsx +212 -0
  114. package/src/components/cx-ui/modal/index.less +144 -0
  115. package/src/components/cx-ui/modal/useCxModal.ts +125 -0
  116. package/src/components/cx-ui/multi-select/index.jsx +74 -0
  117. package/src/components/cx-ui/multi-select/index.less +40 -0
  118. package/src/components/cx-ui/multi-select/index2.tsx +361 -0
  119. package/src/components/cx-ui/radio/index.tsx +33 -0
  120. package/src/components/cx-ui/range-picker/index.less +65 -0
  121. package/src/components/cx-ui/range-picker/index.tsx +219 -0
  122. package/src/components/cx-ui/select/index.less +34 -0
  123. package/src/components/cx-ui/select/index.tsx +196 -0
  124. package/src/components/cx-ui/skeleton/index.tsx +12 -0
  125. package/src/components/cx-ui/steps/index.tsx +14 -0
  126. package/src/components/cx-ui/styles/_tokens.less +79 -0
  127. package/src/components/cx-ui/styles/index.less +246 -0
  128. package/src/components/cx-ui/switch/index.less +106 -0
  129. package/src/components/cx-ui/switch/index.tsx +120 -0
  130. package/src/components/cx-ui/table/index.less +160 -0
  131. package/src/components/cx-ui/table/index.tsx +152 -0
  132. package/src/components/cx-ui/tabs/index.less +15 -0
  133. package/src/components/cx-ui/tabs/index.tsx +34 -0
  134. package/src/components/cx-ui/tag/index.less +51 -0
  135. package/src/components/cx-ui/tag/index.tsx +140 -0
  136. package/src/components/cx-ui/timeline/index.tsx +14 -0
  137. package/src/components/cx-ui/tooltip/index.tsx +67 -0
  138. package/src/components/cx-ui/tree/index.tsx +193 -0
  139. package/src/components/cx-ui/tree-select/index.jsx +91 -0
  140. package/src/components/cx-ui/tree-select/index.less +27 -0
  141. package/src/components/cx-ui/upload-file/index.less +223 -0
  142. package/src/components/cx-ui/upload-file/index.tsx +640 -0
  143. package/src/components/cx-ui/upload-img/index.tsx +291 -0
  144. package/src/components/layout/components/Header.tsx +216 -0
  145. package/src/components/layout/components/Sidebar.tsx +717 -0
  146. package/src/components/layout/index.tsx +95 -0
  147. package/src/components/table-view/components/search-area.tsx +411 -0
  148. package/src/components/table-view/components/table-view-config.tsx +528 -0
  149. package/src/components/table-view/components/table-view.types.ts +478 -0
  150. package/src/components/table-view/components/tree-api-normalize.ts +38 -0
  151. package/src/components/table-view/components/tree-data-annotate.ts +31 -0
  152. package/src/components/table-view/components/tree-sidebar.tsx +74 -0
  153. package/src/components/table-view/index.tsx +61 -0
  154. package/src/components/table-view/list-page-view.tsx +1049 -0
  155. package/src/components/table-view/select-table-view.tsx +1094 -0
  156. package/src/components/table-view/styles/select-table-view.less +51 -0
  157. package/src/config/default-system-name.ts +9 -0
  158. package/src/config/system.ts +165 -0
  159. package/src/constants/countryCodes.ts +3 -0
  160. package/src/contexts/AuthContext.tsx +256 -0
  161. package/src/contexts/ChatContext.tsx +839 -0
  162. package/src/contexts/MenuContext.tsx +62 -0
  163. package/src/contexts/ToastContext.tsx +181 -0
  164. package/src/hooks/useCopyToClipboard.ts +47 -0
  165. package/src/hooks/useModalSubmit.ts +104 -0
  166. package/src/hooks/useRouter.ts +240 -0
  167. package/src/hooks/useStepForm.ts +46 -0
  168. package/src/hooks/useStickyHeader.ts +42 -0
  169. package/src/hooks/useThreadActions.ts +105 -0
  170. package/src/hooks/useUserPreferences.ts +101 -0
  171. package/src/http/axios.js +372 -0
  172. package/src/http/mock.interceptor.ts +9 -0
  173. package/src/http/obfuscationKey.ts +41 -0
  174. package/src/i18n.ts +60 -0
  175. package/src/index.js +1 -0
  176. package/src/index.less +169 -0
  177. package/src/locales/en/auth.ts +70 -0
  178. package/src/locales/en/base/memory.ts +28 -0
  179. package/src/locales/en/base/settings.ts +41 -0
  180. package/src/locales/en/chat.ts +40 -0
  181. package/src/locales/en/common.ts +173 -0
  182. package/src/locales/en/enum.ts +27 -0
  183. package/src/locales/en/menus/business-rules.ts +48 -0
  184. package/src/locales/en/menus/feedback.ts +62 -0
  185. package/src/locales/en/menus/knowledge.ts +120 -0
  186. package/src/locales/en/menus/model-metadata/index.ts +10 -0
  187. package/src/locales/en/menus/model-metadata/manage.ts +151 -0
  188. package/src/locales/en/menus/model-metadata/role.ts +48 -0
  189. package/src/locales/en/menus/model-metadata/training.ts +65 -0
  190. package/src/locales/en/menus/skill.ts +34 -0
  191. package/src/locales/en/system/agent-config.ts +34 -0
  192. package/src/locales/en/system/department.ts +68 -0
  193. package/src/locales/en/system/dict.ts +44 -0
  194. package/src/locales/en/system/menu.ts +45 -0
  195. package/src/locales/en/system/permission.ts +89 -0
  196. package/src/locales/en/system/role.ts +25 -0
  197. package/src/locales/en/system/sys-config.ts +33 -0
  198. package/src/locales/en/system/sys-log.ts +38 -0
  199. package/src/locales/en/system/user.ts +113 -0
  200. package/src/locales/en.ts +68 -0
  201. package/src/locales/zh/auth.ts +70 -0
  202. package/src/locales/zh/base/memory.ts +29 -0
  203. package/src/locales/zh/base/settings.ts +41 -0
  204. package/src/locales/zh/chat.ts +47 -0
  205. package/src/locales/zh/common.ts +178 -0
  206. package/src/locales/zh/enum.ts +28 -0
  207. package/src/locales/zh/menus/business-rules.ts +47 -0
  208. package/src/locales/zh/menus/feedback.ts +62 -0
  209. package/src/locales/zh/menus/knowledge.ts +117 -0
  210. package/src/locales/zh/menus/model-metadata/index.ts +10 -0
  211. package/src/locales/zh/menus/model-metadata/manage.ts +151 -0
  212. package/src/locales/zh/menus/model-metadata/role.ts +47 -0
  213. package/src/locales/zh/menus/model-metadata/training.ts +64 -0
  214. package/src/locales/zh/menus/skill.ts +34 -0
  215. package/src/locales/zh/system/agent-config.ts +33 -0
  216. package/src/locales/zh/system/department.ts +69 -0
  217. package/src/locales/zh/system/dict.ts +44 -0
  218. package/src/locales/zh/system/menu.ts +47 -0
  219. package/src/locales/zh/system/permission.ts +94 -0
  220. package/src/locales/zh/system/role.ts +25 -0
  221. package/src/locales/zh/system/sys-config.ts +32 -0
  222. package/src/locales/zh/system/sys-log.ts +38 -0
  223. package/src/locales/zh/system/user.ts +114 -0
  224. package/src/locales/zh.ts +67 -0
  225. package/src/main.tsx +50 -0
  226. package/src/meta/const/index.ts +40 -0
  227. package/src/meta/index-dict.ts +56 -0
  228. package/src/meta/index-enum.ts +95 -0
  229. package/src/meta/index.ts +14 -0
  230. package/src/meta/module/dict-data/runtime.ts +199 -0
  231. package/src/meta/module/dict-data/types.ts +17 -0
  232. package/src/meta/module/enum-data/runtime.ts +75 -0
  233. package/src/meta/module/enum-data/types.ts +18 -0
  234. package/src/router/index.tsx +312 -0
  235. package/src/styles/AntdThemeProvider.tsx +40 -0
  236. package/src/styles/antd-theme.ts +20 -0
  237. package/src/styles/global.less +107 -0
  238. package/src/styles/variable.less +103 -0
  239. package/src/types/feedback.ts +43 -0
  240. package/src/types/index.ts +85 -0
  241. package/src/types/menu.ts +43 -0
  242. package/src/utils/aesUtil.ts +123 -0
  243. package/src/utils/chatUtils.ts +524 -0
  244. package/src/utils/cn.ts +6 -0
  245. package/src/utils/crypto.ts +164 -0
  246. package/src/utils/date.ts +72 -0
  247. package/src/utils/file-icons.tsx +79 -0
  248. package/src/utils/index.ts +168 -0
  249. package/src/utils/markdown-math-plugins.ts +21 -0
  250. package/src/utils/menuI18n.ts +305 -0
  251. package/src/utils/menuRouteRegistry.ts +78 -0
  252. package/src/utils/permission-crud.ts +147 -0
  253. package/src/utils/routeConfig.ts +350 -0
  254. package/src/utils/storage.ts +135 -0
  255. package/src/utils/toastBridge.ts +26 -0
  256. package/src/utils/url.ts +38 -0
  257. package/src/utils/validation.ts +16 -0
  258. package/src/views/auth/auth-code/index.less +169 -0
  259. package/src/views/auth/auth-code/index.module.less +174 -0
  260. package/src/views/auth/auth-code/index.tsx +233 -0
  261. package/src/views/auth/login.tsx +498 -0
  262. package/src/views/auth/register.tsx +388 -0
  263. package/src/views/base/memory/index.tsx +136 -0
  264. package/src/views/base/memory/modal/detail-modal.tsx +89 -0
  265. package/src/views/base/memory/modal/submit-modal.tsx +134 -0
  266. package/src/views/base/settings/index.tsx +657 -0
  267. package/src/views/chat/chat.less +323 -0
  268. package/src/views/chat/components/chat-input.tsx +298 -0
  269. package/src/views/chat/components/header-thread-title.tsx +210 -0
  270. package/src/views/chat/components/message-list/content-answer.tsx +100 -0
  271. package/src/views/chat/components/message-list/content-question.tsx +18 -0
  272. package/src/views/chat/components/message-list/index.tsx +520 -0
  273. package/src/views/chat/components/message-list/message-item.tsx +199 -0
  274. package/src/views/chat/components/message-list/preparation-demo-items.ts +147 -0
  275. package/src/views/chat/components/message-list/preparation-steps.tsx +506 -0
  276. package/src/views/chat/components/message-list/suggestion-list.tsx +36 -0
  277. package/src/views/chat/components/message-list/thinking-process.tsx +49 -0
  278. package/src/views/chat/components/message-list/toolbar.tsx +224 -0
  279. package/src/views/chat/components/message-list/use-message-list-scroll.ts +214 -0
  280. package/src/views/chat/components/references-knowledge/context.tsx +57 -0
  281. package/src/views/chat/components/references-knowledge/index.ts +9 -0
  282. package/src/views/chat/components/references-knowledge/modal/knowledge-detail-drawer.tsx +556 -0
  283. package/src/views/chat/components/references-knowledge/modal/knowledge-doc-detail-drawer.tsx +529 -0
  284. package/src/views/chat/components/references-knowledge/panel.tsx +115 -0
  285. package/src/views/chat/hooks/use-chat-common.ts +19 -0
  286. package/src/views/chat/index-session.tsx +647 -0
  287. package/src/views/chat/index.tsx +127 -0
  288. package/src/views/page-error/401.tsx +56 -0
  289. package/src/views/page-error/404.tsx +56 -0
  290. package/src/views/page-menus/business-rules/index.tsx +376 -0
  291. package/src/views/page-menus/business-rules/modal/detail-modal.tsx +186 -0
  292. package/src/views/page-menus/business-rules/modal/scope-modal.tsx +272 -0
  293. package/src/views/page-menus/business-rules/modal/submit-modal.tsx +142 -0
  294. package/src/views/page-menus/feedback/components/feedback-dataset-list.tsx +471 -0
  295. package/src/views/page-menus/feedback/index.tsx +166 -0
  296. package/src/views/page-menus/feedback/modal/export-feedback-modal.tsx +367 -0
  297. package/src/views/page-menus/knowledge/components/doc-editor-by-type.tsx +32 -0
  298. package/src/views/page-menus/knowledge/components/doc-editor-type-file.tsx +330 -0
  299. package/src/views/page-menus/knowledge/detail.tsx +600 -0
  300. package/src/views/page-menus/knowledge/index.tsx +337 -0
  301. package/src/views/page-menus/knowledge/modal/detail-modal.tsx +618 -0
  302. package/src/views/page-menus/knowledge/modal/doc-detail-modal.tsx +550 -0
  303. package/src/views/page-menus/knowledge/modal/doc-parse.ts +99 -0
  304. package/src/views/page-menus/knowledge/modal/doc-submit-modal.tsx +349 -0
  305. package/src/views/page-menus/knowledge/modal/doc-type-picker-modal.tsx +88 -0
  306. package/src/views/page-menus/knowledge/modal/knowledge-user-select-modal.tsx +283 -0
  307. package/src/views/page-menus/knowledge/modal/submit-modal.tsx +179 -0
  308. package/src/views/page-menus/model-metadata/manage/components/metadata-detail-schema-tab.tsx +114 -0
  309. package/src/views/page-menus/model-metadata/manage/components/step1-basic-info.tsx +232 -0
  310. package/src/views/page-menus/model-metadata/manage/components/step2-schema.tsx +316 -0
  311. package/src/views/page-menus/model-metadata/manage/components/step3-permissions.tsx +134 -0
  312. package/src/views/page-menus/model-metadata/manage/components/step4-documents.tsx +134 -0
  313. package/src/views/page-menus/model-metadata/manage/components/step5-example-sql.tsx +101 -0
  314. package/src/views/page-menus/model-metadata/manage/components/submit-add.tsx +338 -0
  315. package/src/views/page-menus/model-metadata/manage/components/submit-edit.tsx +276 -0
  316. package/src/views/page-menus/model-metadata/manage/detail.tsx +298 -0
  317. package/src/views/page-menus/model-metadata/manage/hooks/model-metadata-submit-shared.ts +113 -0
  318. package/src/views/page-menus/model-metadata/manage/hooks/use-model-metadata-item-state.ts +20 -0
  319. package/src/views/page-menus/model-metadata/manage/index.tsx +304 -0
  320. package/src/views/page-menus/model-metadata/manage/modal/components/table-schema.ts +374 -0
  321. package/src/views/page-menus/model-metadata/manage/modal/components/use-table-detail-tabs.tsx +151 -0
  322. package/src/views/page-menus/model-metadata/manage/modal/components/use-table-submit-tabs.tsx +423 -0
  323. package/src/views/page-menus/model-metadata/manage/modal/detail-modal.tsx +218 -0
  324. package/src/views/page-menus/model-metadata/manage/modal/submit-modal.tsx +261 -0
  325. package/src/views/page-menus/model-metadata/manage/modal/table-detail-modal.tsx +196 -0
  326. package/src/views/page-menus/model-metadata/manage/modal/table-submit-modal.tsx +229 -0
  327. package/src/views/page-menus/model-metadata/manage/submit.tsx +31 -0
  328. package/src/views/page-menus/model-metadata/role/index.tsx +207 -0
  329. package/src/views/page-menus/model-metadata/role/modal/detail-modal.tsx +97 -0
  330. package/src/views/page-menus/model-metadata/role/modal/role-assign-users-modal.tsx +254 -0
  331. package/src/views/page-menus/model-metadata/role/modal/role-assign-users-panel.tsx +393 -0
  332. package/src/views/page-menus/model-metadata/role/modal/role-assign-users-utils.ts +120 -0
  333. package/src/views/page-menus/model-metadata/role/modal/role-permission-assign-panel.tsx +698 -0
  334. package/src/views/page-menus/model-metadata/role/modal/role-permission-modal.tsx +237 -0
  335. package/src/views/page-menus/model-metadata/role/modal/submit-modal.tsx +135 -0
  336. package/src/views/page-menus/model-metadata/training/components/detail-records/index.ts +4 -0
  337. package/src/views/page-menus/model-metadata/training/components/detail-records/node-card.tsx +72 -0
  338. package/src/views/page-menus/model-metadata/training/components/detail-records/summary-lines.ts +196 -0
  339. package/src/views/page-menus/model-metadata/training/components/detail-records/summary-list.tsx +153 -0
  340. package/src/views/page-menus/model-metadata/training/components/detail-records/timeline.tsx +103 -0
  341. package/src/views/page-menus/model-metadata/training/components/detail-records/types.ts +82 -0
  342. package/src/views/page-menus/model-metadata/training/detail.tsx +159 -0
  343. package/src/views/page-menus/model-metadata/training/index.tsx +236 -0
  344. package/src/views/page-menus/model-metadata/training/modal/update-detail-modal.tsx +154 -0
  345. package/src/views/page-menus/skill/index.tsx +201 -0
  346. package/src/views/page-menus/skill/modal/detail-modal.tsx +156 -0
  347. package/src/views/page-menus/skill/modal/submit-modal.tsx +214 -0
  348. package/src/views/page-system/agent-config/index.tsx +370 -0
  349. package/src/views/page-system/department/departmentFormShared.ts +36 -0
  350. package/src/views/page-system/department/index.tsx +541 -0
  351. package/src/views/page-system/department/modal/detail-modal.tsx +94 -0
  352. package/src/views/page-system/department/modal/member-role-modal.tsx +128 -0
  353. package/src/views/page-system/department/modal/submit-modal.tsx +265 -0
  354. package/src/views/page-system/dict/index.tsx +440 -0
  355. package/src/views/page-system/dict/modal/cate-submit-modal.tsx +315 -0
  356. package/src/views/page-system/dict/modal/submit-modal.tsx +184 -0
  357. package/src/views/page-system/logs/components/index.ts +3 -0
  358. package/src/views/page-system/logs/components/log-message-demo.tsx +30 -0
  359. package/src/views/page-system/logs/components/log-message-stream.ts +184 -0
  360. package/src/views/page-system/logs/components/message-list/content-answer.tsx +100 -0
  361. package/src/views/page-system/logs/components/message-list/content-question.tsx +18 -0
  362. package/src/views/page-system/logs/components/message-list/index.tsx +515 -0
  363. package/src/views/page-system/logs/components/message-list/message-item.tsx +193 -0
  364. package/src/views/page-system/logs/components/message-list/preparation-demo-items.ts +147 -0
  365. package/src/views/page-system/logs/components/message-list/preparation-steps.tsx +506 -0
  366. package/src/views/page-system/logs/components/message-list/suggestion-list.tsx +36 -0
  367. package/src/views/page-system/logs/components/message-list/thinking-process.tsx +49 -0
  368. package/src/views/page-system/logs/components/message-list/toolbar.tsx +134 -0
  369. package/src/views/page-system/logs/components/message-list/use-message-list-scroll.ts +214 -0
  370. package/src/views/page-system/logs/components/message-modal.tsx +239 -0
  371. package/src/views/page-system/logs/index.tsx +132 -0
  372. package/src/views/page-system/logs/modal/detail-modal.tsx +157 -0
  373. package/src/views/page-system/menu/components/menuFormShared.ts +283 -0
  374. package/src/views/page-system/menu/index.less +12 -0
  375. package/src/views/page-system/menu/index.tsx +410 -0
  376. package/src/views/page-system/menu/modal/icon-modal.less +51 -0
  377. package/src/views/page-system/menu/modal/icon-modal.tsx +87 -0
  378. package/src/views/page-system/menu/modal/submit-modal.tsx +263 -0
  379. package/src/views/page-system/permission/index.tsx +562 -0
  380. package/src/views/page-system/permission/modal/detail-modal.tsx +179 -0
  381. package/src/views/page-system/permission/modal/submit-modal.less +146 -0
  382. package/src/views/page-system/permission/modal/submit-modal.tsx +650 -0
  383. package/src/views/page-system/role/index.tsx +163 -0
  384. package/src/views/page-system/role/modal/detail-modal.tsx +127 -0
  385. package/src/views/page-system/role/modal/permission-assign-group-rules.ts +86 -0
  386. package/src/views/page-system/role/modal/permission-modal.tsx +111 -0
  387. package/src/views/page-system/role/modal/role-modal-shell-styles.ts +21 -0
  388. package/src/views/page-system/role/modal/role-permission-assign-panel.tsx +916 -0
  389. package/src/views/page-system/role/modal/role-permission-assign-shared.ts +1047 -0
  390. package/src/views/page-system/role/modal/submit-modal.tsx +193 -0
  391. package/src/views/page-system/sys-config/index.tsx +294 -0
  392. package/src/views/page-system/user/components/user-role-column.tsx +87 -0
  393. package/src/views/page-system/user/index.tsx +439 -0
  394. package/src/views/page-system/user/modal/assign-roles-modal.tsx +389 -0
  395. package/src/views/page-system/user/modal/detail-modal.tsx +72 -0
  396. package/src/views/page-system/user/modal/modal-style/submit-modal.less +40 -0
  397. package/src/views/page-system/user/modal/submit-modal.less +40 -0
  398. package/src/views/page-system/user/modal/submit-modal.tsx +287 -0
  399. package/src/views/page-system/user/userFormShared.ts +51 -0
  400. package/tailwind.config.js +17 -0
  401. package/tsconfig.app.json +48 -0
  402. package/tsconfig.json +11 -0
  403. package/tsconfig.node.json +26 -0
  404. package/vite.config.ts +264 -0
@@ -0,0 +1,1642 @@
1
+ /**
2
+ * Mock API 接口 - 模拟后端接口
3
+ */
4
+ import mockManager, {
5
+ mockUsers,
6
+ mockRoles,
7
+ mockDepartments,
8
+ mockDepartmentMembers,
9
+ mockFeedbacks,
10
+ departmentMemberPool, // 导入成员池
11
+ } from './index'
12
+ // ==================== 用户相关 API ====================
13
+ export const usersMockApi = {
14
+ /**
15
+ * 获取用户列表
16
+ */
17
+ list: async (params: any) => {
18
+ if (!mockManager.isEnabled()) {
19
+ throw new Error('Not in mock mode')
20
+ }
21
+
22
+ // 模拟筛选逻辑
23
+ let items = [...mockUsers.items]
24
+
25
+ if (params?.q) {
26
+ const searchQ = params.q.toLowerCase()
27
+ items = items.filter(
28
+ (user) =>
29
+ user.name?.toLowerCase().includes(searchQ) ||
30
+ user.email.toLowerCase().includes(searchQ),
31
+ )
32
+ }
33
+
34
+ if (params?.roles && params.roles.length > 0) {
35
+ items = items.filter((user) =>
36
+ user.roles.some((role) => params.roles.includes(role)),
37
+ )
38
+ }
39
+
40
+ if (params?.is_active !== undefined) {
41
+ items = items.filter(
42
+ (user) => Number(user.status) === Number(params.is_active),
43
+ )
44
+ }
45
+
46
+ // 分页:优先 page + size(ListPageView),兼容 skip/limit
47
+ const size = Math.max(
48
+ 1,
49
+ Number(params?.size ?? params?.pageSize ?? params?.limit ?? 10),
50
+ )
51
+ const page = Math.max(1, Number(params?.page ?? 1))
52
+ const skip =
53
+ params?.skip != null
54
+ ? Math.max(0, Number(params.skip))
55
+ : (page - 1) * size
56
+ const limit =
57
+ params?.limit != null ? Math.max(1, Number(params.limit)) : size
58
+ const total = items.length
59
+ items = items.slice(skip, skip + limit)
60
+
61
+ return mockManager.response({ items, total })
62
+ },
63
+
64
+ /**
65
+ * 创建用户
66
+ */
67
+ create: async (data: any) => {
68
+ if (!mockManager.isEnabled()) {
69
+ throw new Error('Not in mock mode')
70
+ }
71
+
72
+ const newUser = {
73
+ id: mockUsers.items.length + 1,
74
+ ...data,
75
+ created_at: new Date().toISOString(),
76
+ }
77
+
78
+ return mockManager.response({ success: true, user: newUser })
79
+ },
80
+
81
+ /**
82
+ * 更新用户
83
+ */
84
+ update: async (data: any) => {
85
+ if (!mockManager.isEnabled()) {
86
+ throw new Error('Not in mock mode')
87
+ }
88
+
89
+ return mockManager.response({ success: true })
90
+ },
91
+
92
+ /**
93
+ * 删除用户
94
+ */
95
+ delete: async (userId: string) => {
96
+ if (!mockManager.isEnabled()) {
97
+ throw new Error('Not in mock mode')
98
+ }
99
+
100
+ return mockManager.response({ success: true })
101
+ },
102
+
103
+ detail: async (userId: string) => {
104
+ if (!mockManager.isEnabled()) {
105
+ throw new Error('Not in mock mode')
106
+ }
107
+ const u = mockUsers.items.find((x) => String(x.id) === String(userId))
108
+ return mockManager.response({
109
+ data: u ?? { id: Number(userId), name: `用户${userId}` },
110
+ })
111
+ },
112
+ }
113
+
114
+ // ==================== 角色列表 Mock(page-system `role.js` 与 rolesMockApi 共用)====================
115
+ let rolePageMockList: any[] | null = null
116
+
117
+ function ensureRolePageMockList(): any[] {
118
+ if (!rolePageMockList) {
119
+ rolePageMockList = mockRoles.items.map((r: any) => ({
120
+ ...r,
121
+ status: r.name === 'default user' ? 0 : 1,
122
+ }))
123
+ }
124
+ return rolePageMockList
125
+ }
126
+
127
+ /** 供 `role.js` 与 `rolesMockApi.list`:返回含 content/totalElements(ListPageView)及 items/total */
128
+ export function getRoleListMockData(params: any) {
129
+ let items = [...ensureRolePageMockList()]
130
+ const q = String(params?.searchQ ?? params?.q ?? '')
131
+ .trim()
132
+ .toLowerCase()
133
+ const perm = String(
134
+ params?.searchPermission ?? params?.permission_code ?? '',
135
+ )
136
+ .trim()
137
+ .toLowerCase()
138
+ const statusRaw = params?.status
139
+
140
+ if (q) {
141
+ items = items.filter(
142
+ (x) =>
143
+ String(x.name || '')
144
+ .toLowerCase()
145
+ .includes(q) ||
146
+ String(x.description || '')
147
+ .toLowerCase()
148
+ .includes(q),
149
+ )
150
+ }
151
+ if (perm) {
152
+ items = items.filter((x) =>
153
+ (Array.isArray(x.permissions) ? x.permissions : []).some((p: string) =>
154
+ String(p)
155
+ .toLowerCase()
156
+ .includes(perm),
157
+ ),
158
+ )
159
+ }
160
+ if (statusRaw !== undefined && statusRaw !== null && statusRaw !== '') {
161
+ const sn = Number(statusRaw)
162
+ if (!Number.isNaN(sn)) {
163
+ items = items.filter((x) => Number(x.status ?? 1) === sn)
164
+ }
165
+ }
166
+
167
+ const size = Math.max(
168
+ 1,
169
+ Number(params?.size ?? params?.pageSize ?? params?.limit ?? 10),
170
+ )
171
+ const page = Math.max(1, Number(params?.page ?? 1))
172
+ const total = items.length
173
+ const start = (page - 1) * size
174
+ const slice = items.slice(start, start + size)
175
+ return {
176
+ content: slice,
177
+ totalElements: total,
178
+ items: slice,
179
+ total,
180
+ }
181
+ }
182
+
183
+ export function buildRoleMockAddResult(data: any) {
184
+ const list = ensureRolePageMockList()
185
+ const nextId =
186
+ list.length === 0
187
+ ? 1
188
+ : Math.max(...list.map((x) => Number(x.id) || 0)) + 1
189
+ const next = {
190
+ id: nextId,
191
+ name: String(data?.name || '').trim(),
192
+ description: String(data?.description ?? '').trim(),
193
+ email: `${String(data?.name || 'role').replace(/\s+/g, '_')}@mock.local`,
194
+ permissions: [] as string[],
195
+ status: Number(data?.status ?? 1) === 0 ? 0 : 1,
196
+ created_at: new Date().toISOString(),
197
+ }
198
+ list.push(next)
199
+ return {
200
+ success: true,
201
+ code: 200,
202
+ message: '新增成功',
203
+ data: next,
204
+ }
205
+ }
206
+
207
+ export function buildRoleMockEditResult(data: any) {
208
+ const list = ensureRolePageMockList()
209
+ const id = Number(data?.id)
210
+ if (!id) {
211
+ throw new Error('id is required')
212
+ }
213
+ const idx = list.findIndex((x) => Number(x.id) === id)
214
+ if (idx < 0) {
215
+ throw new Error('角色不存在')
216
+ }
217
+ list[idx] = {
218
+ ...list[idx],
219
+ name: String(data?.name ?? list[idx].name).trim(),
220
+ description: String(data?.description ?? list[idx].description ?? '').trim(),
221
+ status: Number(data?.status ?? list[idx].status ?? 1) === 0 ? 0 : 1,
222
+ }
223
+ return {
224
+ success: true,
225
+ code: 200,
226
+ message: '更新成功',
227
+ data: list[idx],
228
+ }
229
+ }
230
+
231
+ export function buildRoleMockDeleteResult(roleId: string | number) {
232
+ const list = ensureRolePageMockList()
233
+ const id = String(roleId)
234
+ const idx = list.findIndex((x) => String(x.id) === id)
235
+ if (idx >= 0) {
236
+ list.splice(idx, 1)
237
+ }
238
+ return {
239
+ success: true,
240
+ code: 200,
241
+ message: '删除成功',
242
+ data: { ok: true },
243
+ }
244
+ }
245
+
246
+ // ==================== 角色相关 API ====================
247
+ export const rolesMockApi = {
248
+ /**
249
+ * 获取角色列表
250
+ */
251
+ list: async (params: any) => {
252
+ if (!mockManager.isEnabled()) {
253
+ throw new Error('Not in mock mode')
254
+ }
255
+
256
+ return mockManager.response(getRoleListMockData(params))
257
+ },
258
+
259
+ /**
260
+ * 获取可分配给用户的角色
261
+ */
262
+ assignableToUser: async (data: any) => {
263
+ if (!mockManager.isEnabled()) {
264
+ throw new Error('Not in mock mode')
265
+ }
266
+
267
+ const assignableRoles = mockRoles.items.map((role) => ({
268
+ role,
269
+ can_manage: role.name !== 'admin',
270
+ }))
271
+
272
+ return mockManager.response(assignableRoles)
273
+ },
274
+
275
+ /**
276
+ * 创建角色
277
+ */
278
+ create: async (data: any) => {
279
+ if (!mockManager.isEnabled()) {
280
+ throw new Error('Not in mock mode')
281
+ }
282
+
283
+ return mockManager.response(buildRoleMockAddResult(data))
284
+ },
285
+
286
+ /**
287
+ * 删除角色
288
+ */
289
+ delete: async (roleId: string) => {
290
+ if (!mockManager.isEnabled()) {
291
+ throw new Error('Not in mock mode')
292
+ }
293
+
294
+ return mockManager.response(buildRoleMockDeleteResult(roleId))
295
+ },
296
+
297
+ detail: async (roleId: string) => {
298
+ if (!mockManager.isEnabled()) {
299
+ throw new Error('Not in mock mode')
300
+ }
301
+ const r = mockRoles.items.find((x: any) => String(x.id) === String(roleId))
302
+ return mockManager.response({
303
+ data: r ?? { id: Number(roleId), name: `角色${roleId}` },
304
+ })
305
+ },
306
+
307
+ update: async (_data: any) => {
308
+ if (!mockManager.isEnabled()) {
309
+ throw new Error('Not in mock mode')
310
+ }
311
+ return mockManager.response({ success: true })
312
+ },
313
+ }
314
+
315
+ // ==================== 部门相关 API ====================
316
+ export const departmentsMockApi = {
317
+ /**
318
+ * 获取部门树
319
+ */
320
+ tree: async () => {
321
+ if (!mockManager.isEnabled()) {
322
+ throw new Error('Not in mock mode')
323
+ }
324
+
325
+ return mockManager.response(mockDepartments.tree)
326
+ },
327
+
328
+ /**
329
+ * 检查部门代码是否可用
330
+ */
331
+ checkCode: async (code: string) => {
332
+ if (!mockManager.isEnabled()) {
333
+ throw new Error('Not in mock mode')
334
+ }
335
+
336
+ // 简单模拟:除了已存在的代码,其他都可用
337
+ const existingCodes = ['HQ', 'TECH', 'FE', 'BE', 'MKT']
338
+ const available = !existingCodes.includes(code)
339
+
340
+ return mockManager.response({ available })
341
+ },
342
+
343
+ /**
344
+ * 获取部门成员(GET);POST 添加成员时返回成功(与真实路由一致)
345
+ */
346
+ members: async (
347
+ deptId: number,
348
+ body: any,
349
+ queryParams: any = {},
350
+ method?: string,
351
+ ) => {
352
+ if (!mockManager.isEnabled()) {
353
+ throw new Error('Not in mock mode')
354
+ }
355
+
356
+ const m = String(method ?? 'get').toUpperCase()
357
+ if (m === 'POST') {
358
+ return mockManager.response({ success: true, data: body })
359
+ }
360
+
361
+ const params = { ...queryParams, ...body }
362
+ const skip = params?.skip || 0
363
+ const limit = params?.limit || 10
364
+
365
+ // 使用部门 ID 作为随机种子,确保同一个部门始终返回相同的成员
366
+ // 但不同部门返回不同的成员
367
+ const randomSeed = deptId % departmentMemberPool.length
368
+ const shuffled = [...departmentMemberPool]
369
+
370
+ // 简单的洗牌算法
371
+ for (let i = shuffled.length - 1; i > 0; i--) {
372
+ const j = (randomSeed + i) % shuffled.length
373
+ ;[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]
374
+ }
375
+
376
+ // 根据分页截取数据
377
+ const items = shuffled.slice(skip, skip + limit)
378
+ const total = departmentMemberPool.length
379
+
380
+ return mockManager.response({
381
+ items,
382
+ total,
383
+ })
384
+ },
385
+
386
+ /**
387
+ * 创建部门
388
+ */
389
+ create: async (data: any) => {
390
+ if (!mockManager.isEnabled()) {
391
+ throw new Error('Not in mock mode')
392
+ }
393
+
394
+ return mockManager.response({ success: true })
395
+ },
396
+
397
+ /**
398
+ * 更新部门
399
+ */
400
+ update: async (data: any) => {
401
+ if (!mockManager.isEnabled()) {
402
+ throw new Error('Not in mock mode')
403
+ }
404
+
405
+ return mockManager.response({ success: true })
406
+ },
407
+
408
+ /**
409
+ * 删除部门
410
+ */
411
+ delete: async (deptId: string) => {
412
+ if (!mockManager.isEnabled()) {
413
+ throw new Error('Not in mock mode')
414
+ }
415
+
416
+ return mockManager.response({ success: true })
417
+ },
418
+
419
+ detail: async (id: string) => {
420
+ if (!mockManager.isEnabled()) {
421
+ throw new Error('Not in mock mode')
422
+ }
423
+ return mockManager.response({ id, name: `部门${id}` })
424
+ },
425
+ }
426
+
427
+ // ==================== 数据字典 Mock ====================
428
+ type DictMockCate = {
429
+ id: string
430
+ name: string
431
+ code: string
432
+ description?: string
433
+ sortOrder: number
434
+ parentId: string
435
+ }
436
+
437
+ type DictMockData = {
438
+ id: string
439
+ name: string
440
+ value: string
441
+ description?: string
442
+ sortOrder: number
443
+ status: number
444
+ dictTypeId: string
445
+ defaultFlag: boolean
446
+ }
447
+
448
+ let dictMockCates: DictMockCate[] = [
449
+ { id: 'dc1', name: '通用', code: 'COMMON', description: '', sortOrder: 1, parentId: '0' },
450
+ { id: 'dc2', name: '用户', code: 'USER', description: '', sortOrder: 2, parentId: '0' },
451
+ {
452
+ id: 'dc2_1',
453
+ name: '用户状态',
454
+ code: 'USER_STATUS',
455
+ description: '登录状态类',
456
+ sortOrder: 1,
457
+ parentId: 'dc2',
458
+ },
459
+ ]
460
+
461
+ let dictMockDataRows: DictMockData[] = [
462
+ {
463
+ id: 'dd1',
464
+ name: '正常',
465
+ value: '1',
466
+ description: '',
467
+ sortOrder: 1,
468
+ status: 1,
469
+ dictTypeId: 'dc2_1',
470
+ defaultFlag: true,
471
+ },
472
+ {
473
+ id: 'dd2',
474
+ name: '冻结',
475
+ value: '2',
476
+ description: '',
477
+ sortOrder: 2,
478
+ status: 1,
479
+ dictTypeId: 'dc2_1',
480
+ defaultFlag: false,
481
+ },
482
+ {
483
+ id: 'dd3',
484
+ name: '示例项',
485
+ value: 'X',
486
+ description: '',
487
+ sortOrder: 1,
488
+ status: 0,
489
+ dictTypeId: 'dc1',
490
+ defaultFlag: false,
491
+ },
492
+ ]
493
+
494
+ let dictMockCateSeq = 300
495
+ let dictMockDataSeq = 3000
496
+
497
+ function dictSortOrderNum(a: { sortOrder?: number }, b: { sortOrder?: number }) {
498
+ return (a.sortOrder ?? 0) - (b.sortOrder ?? 0)
499
+ }
500
+
501
+ function buildDictCateTree(): any[] {
502
+ const byParent = new Map<string, DictMockCate[]>()
503
+ for (const c of dictMockCates) {
504
+ const pid = c.parentId ? String(c.parentId) : '0'
505
+ const arr = byParent.get(pid) ?? []
506
+ arr.push(c)
507
+ byParent.set(pid, arr)
508
+ }
509
+ const walk = (parentId: string): any[] => {
510
+ const list = (byParent.get(parentId) ?? []).slice().sort(dictSortOrderNum)
511
+ return list.map((row) => ({
512
+ id: row.id,
513
+ name: row.name,
514
+ code: row.code,
515
+ description: row.description ?? '',
516
+ sortOrder: row.sortOrder,
517
+ parentId: row.parentId,
518
+ children: walk(row.id),
519
+ }))
520
+ }
521
+ return walk('0')
522
+ }
523
+
524
+ function collectDescendantDictCateIds(id: string): Set<string> {
525
+ const ids = new Set<string>([id])
526
+ let added = true
527
+ while (added) {
528
+ added = false
529
+ for (const c of dictMockCates) {
530
+ if (ids.has(String(c.parentId)) && !ids.has(c.id)) {
531
+ ids.add(c.id)
532
+ added = true
533
+ }
534
+ }
535
+ }
536
+ return ids
537
+ }
538
+
539
+ /**
540
+ * 按分类 code 列表构造「字典项行」(与 dictDataByCodes 逻辑一致,供 single/batch 新接口复用)
541
+ * @param {string[]} codes
542
+ */
543
+ function buildPublicDictRowsMap(codes: string[]) {
544
+ const publicSeed: Record<string, { name: string; value: string; sortOrder?: number }[]> = {
545
+ phone_area_code: [
546
+ { name: '中国大陆 +86', value: '+86', sortOrder: 1 },
547
+ { name: '中国香港 +852', value: '+852', sortOrder: 2 },
548
+ { name: '中国澳门 +853', value: '+853', sortOrder: 3 },
549
+ { name: '中国台湾 +886', value: '+886', sortOrder: 4 },
550
+ { name: '美国 +1', value: '+1', sortOrder: 10 },
551
+ ],
552
+ permission_code: [
553
+ { name: '菜单', value: 'menu', sortOrder: 1 },
554
+ { name: '按钮', value: 'button', sortOrder: 2 },
555
+ { name: '接口', value: 'api', sortOrder: 3 },
556
+ ],
557
+ request_type: [
558
+ { name: 'GET', value: 'GET', sortOrder: 1 },
559
+ { name: 'POST', value: 'POST', sortOrder: 2 },
560
+ { name: 'PUT', value: 'PUT', sortOrder: 3 },
561
+ { name: 'DELETE', value: 'DELETE', sortOrder: 4 },
562
+ ],
563
+ }
564
+ const out: Record<string, any[]> = {}
565
+ for (const code of codes) {
566
+ const rows = dictMockDataRows.filter((d) => d.dictTypeId === code)
567
+ if (rows.length) {
568
+ out[code] = rows.map((d) => ({
569
+ id: d.id,
570
+ name: d.name,
571
+ value: d.value,
572
+ dictValue: d.value,
573
+ dictLabel: d.name,
574
+ sortOrder: d.sortOrder,
575
+ status: d.status,
576
+ defaultFlag: d.defaultFlag,
577
+ }))
578
+ } else if (publicSeed[code]) {
579
+ out[code] = publicSeed[code].map((r, i) => ({
580
+ id: `dd_seed_${code}_${i}`,
581
+ name: r.name,
582
+ value: r.value,
583
+ dictValue: r.value,
584
+ dictLabel: r.name,
585
+ sortOrder: r.sortOrder ?? i + 1,
586
+ status: 1,
587
+ defaultFlag: i === 0,
588
+ }))
589
+ } else {
590
+ out[code] = [
591
+ {
592
+ id: `dd_seed_${code}_0`,
593
+ name: `${code}-选项1`,
594
+ value: '1',
595
+ dictValue: '1',
596
+ dictLabel: `${code}-选项1`,
597
+ sortOrder: 1,
598
+ status: 1,
599
+ defaultFlag: true,
600
+ },
601
+ {
602
+ id: `dd_seed_${code}_1`,
603
+ name: `${code}-选项2`,
604
+ value: '2',
605
+ dictValue: '2',
606
+ dictLabel: `${code}-选项2`,
607
+ sortOrder: 2,
608
+ status: 1,
609
+ defaultFlag: false,
610
+ },
611
+ ]
612
+ }
613
+ }
614
+ return out
615
+ }
616
+
617
+ export const dictMockApi = {
618
+ cateTree: async () => {
619
+ if (!mockManager.isEnabled()) {
620
+ throw new Error('Not in mock mode')
621
+ }
622
+ return mockManager.response(buildDictCateTree())
623
+ },
624
+
625
+ cateDetail: async (id: string) => {
626
+ if (!mockManager.isEnabled()) {
627
+ throw new Error('Not in mock mode')
628
+ }
629
+ const row = dictMockCates.find((c) => c.id === id)
630
+ return mockManager.response(row ?? {})
631
+ },
632
+
633
+ cateCreate: async (data: any) => {
634
+ if (!mockManager.isEnabled()) {
635
+ throw new Error('Not in mock mode')
636
+ }
637
+ dictMockCateSeq += 1
638
+ const id = `dc_${dictMockCateSeq}`
639
+ dictMockCates.push({
640
+ id,
641
+ name: String(data.name ?? ''),
642
+ code: String(data.code ?? ''),
643
+ description: data.description ? String(data.description) : '',
644
+ sortOrder: Number(data.sortOrder ?? 1),
645
+ parentId:
646
+ data.parentId !== undefined &&
647
+ data.parentId !== null &&
648
+ String(data.parentId) !== ''
649
+ ? String(data.parentId)
650
+ : '0',
651
+ })
652
+ return mockManager.response({ success: true, id })
653
+ },
654
+
655
+ cateUpdate: async (id: string, data: any) => {
656
+ if (!mockManager.isEnabled()) {
657
+ throw new Error('Not in mock mode')
658
+ }
659
+ const idx = dictMockCates.findIndex((c) => c.id === id)
660
+ if (idx >= 0) {
661
+ const prev = dictMockCates[idx]
662
+ dictMockCates[idx] = {
663
+ ...prev,
664
+ name: data.name !== undefined ? String(data.name) : prev.name,
665
+ code: data.code !== undefined ? String(data.code) : prev.code,
666
+ description:
667
+ data.description !== undefined ? String(data.description) : prev.description,
668
+ sortOrder:
669
+ data.sortOrder !== undefined ? Number(data.sortOrder) : prev.sortOrder,
670
+ parentId:
671
+ data.parentId !== undefined &&
672
+ data.parentId !== null &&
673
+ String(data.parentId) !== ''
674
+ ? String(data.parentId)
675
+ : prev.parentId,
676
+ id,
677
+ }
678
+ }
679
+ return mockManager.response({ success: true })
680
+ },
681
+
682
+ cateDelete: async (id: string) => {
683
+ if (!mockManager.isEnabled()) {
684
+ throw new Error('Not in mock mode')
685
+ }
686
+ const removeIds = collectDescendantDictCateIds(id)
687
+ dictMockCates = dictMockCates.filter((c) => !removeIds.has(c.id))
688
+ dictMockDataRows = dictMockDataRows.filter((d) => !removeIds.has(d.dictTypeId))
689
+ return mockManager.response({ success: true })
690
+ },
691
+
692
+ dataPage: async (params: any) => {
693
+ if (!mockManager.isEnabled()) {
694
+ throw new Error('Not in mock mode')
695
+ }
696
+ const typeId = String(params?.dictTypeId ?? '').trim()
697
+ let rows = dictMockDataRows.filter((d) => !typeId || d.dictTypeId === typeId)
698
+ const kw = String(params?.keyword ?? '').trim().toLowerCase()
699
+ if (kw) {
700
+ rows = rows.filter(
701
+ (d) =>
702
+ String(d.name).toLowerCase().includes(kw) ||
703
+ String(d.value).toLowerCase().includes(kw),
704
+ )
705
+ }
706
+ if (params?.status !== undefined && params?.status !== null && params?.status !== '') {
707
+ rows = rows.filter((d) => Number(d.status) === Number(params.status))
708
+ }
709
+ const size = Math.max(1, Number(params?.size ?? 10))
710
+ const page = Math.max(1, Number(params?.page ?? 1))
711
+ const total = rows.length
712
+ const start = (page - 1) * size
713
+ const content = rows.slice(start, start + size)
714
+ return mockManager.response({ content, totalElements: total })
715
+ },
716
+
717
+ dataDetail: async (id: string) => {
718
+ if (!mockManager.isEnabled()) {
719
+ throw new Error('Not in mock mode')
720
+ }
721
+ const row = dictMockDataRows.find((d) => d.id === id)
722
+ return mockManager.response(row ?? {})
723
+ },
724
+
725
+ dataCreate: async (data: any) => {
726
+ if (!mockManager.isEnabled()) {
727
+ throw new Error('Not in mock mode')
728
+ }
729
+ dictMockDataSeq += 1
730
+ const id = `dd_${dictMockDataSeq}`
731
+ dictMockDataRows.push({
732
+ id,
733
+ name: String(data.name ?? ''),
734
+ value: String(data.value ?? ''),
735
+ description: data.description ? String(data.description) : '',
736
+ sortOrder: Number(data.sortOrder ?? 1),
737
+ status: data.status !== undefined ? Number(data.status) : 1,
738
+ dictTypeId: String(data.dictTypeId ?? ''),
739
+ defaultFlag: Boolean(data.defaultFlag),
740
+ })
741
+ return mockManager.response({ success: true, id })
742
+ },
743
+
744
+ dataUpdate: async (id: string, data: any) => {
745
+ if (!mockManager.isEnabled()) {
746
+ throw new Error('Not in mock mode')
747
+ }
748
+ const idx = dictMockDataRows.findIndex((d) => d.id === id)
749
+ if (idx >= 0) {
750
+ const prev = dictMockDataRows[idx]
751
+ dictMockDataRows[idx] = {
752
+ ...prev,
753
+ ...data,
754
+ id,
755
+ name: data.name !== undefined ? String(data.name) : prev.name,
756
+ value: data.value !== undefined ? String(data.value) : prev.value,
757
+ description:
758
+ data.description !== undefined ? String(data.description) : prev.description,
759
+ sortOrder:
760
+ data.sortOrder !== undefined ? Number(data.sortOrder) : prev.sortOrder,
761
+ status: data.status !== undefined ? Number(data.status) : prev.status,
762
+ dictTypeId:
763
+ data.dictTypeId !== undefined ? String(data.dictTypeId) : prev.dictTypeId,
764
+ defaultFlag:
765
+ data.defaultFlag !== undefined ? Boolean(data.defaultFlag) : prev.defaultFlag,
766
+ }
767
+ }
768
+ return mockManager.response({ success: true })
769
+ },
770
+
771
+ dataDelete: async (id: string) => {
772
+ if (!mockManager.isEnabled()) {
773
+ throw new Error('Not in mock mode')
774
+ }
775
+ dictMockDataRows = dictMockDataRows.filter((d) => d.id !== id)
776
+ return mockManager.response({ success: true })
777
+ },
778
+
779
+ /**
780
+ * GET /dict/{codes} — 历史:逗号分隔分类编码,返回 Record<code, rows[]>
781
+ */
782
+ dictDataByCodes: async (segment: string) => {
783
+ if (!mockManager.isEnabled()) {
784
+ throw new Error('Not in mock mode')
785
+ }
786
+ const codes = String(segment ?? '')
787
+ .split(',')
788
+ .map((s) => s.trim())
789
+ .filter(Boolean)
790
+ return mockManager.response(buildPublicDictRowsMap(codes))
791
+ },
792
+
793
+ /** GET /dict/batch/{encodedCodes} — 与前端 batchGetDictDataAPI 一致:data 为分类 + children[] */
794
+ dictBatchTypes: async (segment: string) => {
795
+ if (!mockManager.isEnabled()) {
796
+ throw new Error('Not in mock mode')
797
+ }
798
+ const codes = String(segment ?? '')
799
+ .split(',')
800
+ .map((s) => decodeURIComponent(s.trim()))
801
+ .filter(Boolean)
802
+ const map = buildPublicDictRowsMap(codes)
803
+ const typeNames: Record<string, string> = {
804
+ permission_code: '权限编码',
805
+ phone_area_code: '手机区号',
806
+ request_type: '请求方法',
807
+ }
808
+ const data = codes.map((code, idx) => ({
809
+ id: `dtype_${code}`,
810
+ name: typeNames[code] ?? code,
811
+ code,
812
+ description: null,
813
+ sortOrder: idx + 1,
814
+ parentId: '1',
815
+ parentName: '数据字典',
816
+ children: map[code] ?? [],
817
+ }))
818
+ return mockManager.response(data)
819
+ },
820
+
821
+ /** GET /dict/single/{code} — 与真实接口一致:data 为该分类下的字典项数组 */
822
+ dictSingleByType: async (code: string) => {
823
+ if (!mockManager.isEnabled()) {
824
+ throw new Error('Not in mock mode')
825
+ }
826
+ const c = decodeURIComponent(String(code ?? '').trim())
827
+ const map = buildPublicDictRowsMap([c])
828
+ return mockManager.response(map[c] ?? [])
829
+ },
830
+
831
+ /** 同 dictTypeId 下仅一条 defaultFlag=true */
832
+ dataSetDefault: async (id: string) => {
833
+ if (!mockManager.isEnabled()) {
834
+ throw new Error('Not in mock mode')
835
+ }
836
+ const row = dictMockDataRows.find((d) => d.id === id)
837
+ if (!row) {
838
+ return mockManager.response({ success: false })
839
+ }
840
+ const typeId = row.dictTypeId
841
+ for (const d of dictMockDataRows) {
842
+ if (d.dictTypeId === typeId) {
843
+ d.defaultFlag = d.id === id
844
+ }
845
+ }
846
+ return mockManager.response({ success: true })
847
+ },
848
+ }
849
+
850
+ // ==================== 反馈相关 API ====================
851
+ export const feedbacksMockApi = {
852
+ /**
853
+ * 获取反馈列表
854
+ */
855
+ list: async (params: any) => {
856
+ if (!mockManager.isEnabled()) {
857
+ throw new Error('Not in mock mode')
858
+ }
859
+
860
+ // 模拟筛选
861
+ let items = [...mockFeedbacks.items]
862
+
863
+ if (params?.status && params.status !== 'all') {
864
+ items = items.filter((item) => item.status === params.status)
865
+ }
866
+
867
+ if (params?.searchQ) {
868
+ const searchQ = params.searchQ.toLowerCase()
869
+ items = items.filter((item) =>
870
+ item.content.toLowerCase().includes(searchQ),
871
+ )
872
+ }
873
+
874
+ // 分页(page 从 1 开始)
875
+ const page = Math.max(1, Number(params?.page ?? 1))
876
+ const pageSize = Math.max(
877
+ 1,
878
+ Number(params?.size ?? params?.pageSize ?? 10),
879
+ )
880
+ const total = items.length
881
+ const start = (page - 1) * pageSize
882
+ items = items.slice(start, start + pageSize)
883
+
884
+ return mockManager.response({ items, total })
885
+ },
886
+
887
+ /**
888
+ * 删除反馈
889
+ */
890
+ delete: async (feedbackId: string) => {
891
+ if (!mockManager.isEnabled()) {
892
+ throw new Error('Not in mock mode')
893
+ }
894
+
895
+ return mockManager.response({ success: true })
896
+ },
897
+ }
898
+
899
+ // ==================== 权限相关 API(动态数据,与 mockMenus 菜单 id 对齐)====================
900
+ const permissionSeedByMenuId: Record<string, Array<any>> = {
901
+ '1234567890123456789012': [
902
+ {
903
+ anonymous: true,
904
+ apiPath: '/api/common/ping',
905
+ code: 'common:health',
906
+ description: '根级公共探测',
907
+ id: 'perm-seed-root-health',
908
+ menuId: '1234567890123456789012',
909
+ method: 'GET',
910
+ name: '健康检查',
911
+ status: 1,
912
+ },
913
+ {
914
+ anonymous: false,
915
+ apiPath: '/api/config/public',
916
+ code: 'common:config:read',
917
+ description: '读取公开配置',
918
+ id: 'perm-seed-root-config',
919
+ menuId: '1234567890123456789012',
920
+ method: 'GET',
921
+ name: '公开配置',
922
+ status: 1,
923
+ },
924
+ ],
925
+ '1234567890123456789014': [
926
+ {
927
+ anonymous: false,
928
+ apiPath: '/api/users/page',
929
+ code: 'user:page',
930
+ description: '用户分页',
931
+ id: 'perm-seed-legacy-user-page',
932
+ menuId: '1234567890123456789014',
933
+ method: 'POST',
934
+ name: '用户列表',
935
+ status: 1,
936
+ },
937
+ ],
938
+ '1234567890123456789132': [
939
+ {
940
+ anonymous: false,
941
+ apiPath: '/api/user/page',
942
+ code: 'user:list',
943
+ description: '系统用户分页查询',
944
+ id: 'perm-seed-user-1',
945
+ menuId: '1234567890123456789132',
946
+ method: 'POST',
947
+ name: '用户分页',
948
+ status: 1,
949
+ },
950
+ {
951
+ anonymous: false,
952
+ apiPath: '/api/user',
953
+ code: 'user:add',
954
+ description: '创建用户',
955
+ id: 'perm-seed-user-2',
956
+ menuId: '1234567890123456789132',
957
+ method: 'POST',
958
+ name: '新增用户',
959
+ status: 1,
960
+ },
961
+ {
962
+ anonymous: false,
963
+ apiPath: '/api/user/disable',
964
+ code: 'user:disable',
965
+ description: '禁用用户',
966
+ id: 'perm-seed-user-3',
967
+ menuId: '1234567890123456789132',
968
+ method: 'PUT',
969
+ name: '禁用用户',
970
+ status: 1,
971
+ },
972
+ ],
973
+ '1234567890123456789133': [
974
+ {
975
+ anonymous: false,
976
+ apiPath: '/api/menu/tree',
977
+ code: 'menu:tree',
978
+ description: '菜单树',
979
+ id: 'perm-seed-menu-1',
980
+ menuId: '1234567890123456789133',
981
+ method: 'GET',
982
+ name: '菜单树',
983
+ status: 1,
984
+ },
985
+ {
986
+ anonymous: false,
987
+ apiPath: '/api/menu',
988
+ code: 'menu:create',
989
+ description: '新增菜单',
990
+ id: 'perm-seed-menu-2',
991
+ menuId: '1234567890123456789133',
992
+ method: 'POST',
993
+ name: '新增菜单',
994
+ status: 1,
995
+ },
996
+ {
997
+ anonymous: false,
998
+ apiPath: '/api/menu',
999
+ code: 'menu:update',
1000
+ description: '更新菜单',
1001
+ id: 'perm-seed-menu-3',
1002
+ menuId: '1234567890123456789133',
1003
+ method: 'PUT',
1004
+ name: '编辑菜单',
1005
+ status: 1,
1006
+ },
1007
+ ],
1008
+ '1234567890123456789134': [
1009
+ {
1010
+ anonymous: false,
1011
+ apiPath: '/api/permissions/list',
1012
+ code: 'permission:list',
1013
+ description: '按菜单分页查询权限',
1014
+ id: 'perm-seed-pm-1',
1015
+ menuId: '1234567890123456789134',
1016
+ method: 'POST',
1017
+ name: '权限列表',
1018
+ status: 1,
1019
+ },
1020
+ {
1021
+ anonymous: false,
1022
+ apiPath: '/api/permissions/create',
1023
+ code: 'permission:create',
1024
+ description: '新增权限点',
1025
+ id: 'perm-seed-pm-2',
1026
+ menuId: '1234567890123456789134',
1027
+ method: 'POST',
1028
+ name: '新增权限',
1029
+ status: 1,
1030
+ },
1031
+ {
1032
+ anonymous: false,
1033
+ apiPath: '/api/permissions/delete',
1034
+ code: 'permission:delete',
1035
+ description: '删除权限点',
1036
+ id: 'perm-seed-pm-3',
1037
+ menuId: '1234567890123456789134',
1038
+ method: 'POST',
1039
+ name: '删除权限',
1040
+ status: 1,
1041
+ },
1042
+ {
1043
+ anonymous: true,
1044
+ apiPath: '/api/permissions/assignable',
1045
+ code: 'permission:assignable',
1046
+ description: '可分配权限列表(开放)',
1047
+ id: 'perm-seed-pm-4',
1048
+ menuId: '1234567890123456789134',
1049
+ method: 'GET',
1050
+ name: '可分配权限',
1051
+ status: 1,
1052
+ },
1053
+ {
1054
+ anonymous: false,
1055
+ apiPath: '/api/roles/permissions',
1056
+ code: 'role:permission:bind',
1057
+ description: '角色绑定权限',
1058
+ id: 'perm-seed-pm-5',
1059
+ menuId: '1234567890123456789134',
1060
+ method: 'POST',
1061
+ name: '角色授权',
1062
+ status: 0,
1063
+ },
1064
+ {
1065
+ anonymous: false,
1066
+ apiPath: '/api/permissions/export',
1067
+ apiType: 2,
1068
+ code: 'permission:export',
1069
+ description: '导出权限矩阵',
1070
+ id: 'perm-seed-pm-6',
1071
+ menuId: '1234567890123456789134',
1072
+ method: 'GET',
1073
+ name: '导出权限',
1074
+ status: 1,
1075
+ },
1076
+ ],
1077
+ }
1078
+
1079
+ const permissionStore: Record<string, Array<any>> = {
1080
+ ...permissionSeedByMenuId,
1081
+ }
1082
+
1083
+ function genPermissionId() {
1084
+ return `perm-${Date.now()}-${Math.random().toString(16).slice(2, 8)}`
1085
+ }
1086
+
1087
+ function flattenAllPermissions(): any[] {
1088
+ return Object.keys(permissionStore).flatMap((menuId) =>
1089
+ (permissionStore[menuId] || []).map((row: any) => ({ ...row })),
1090
+ )
1091
+ }
1092
+
1093
+ function normalizePermissionRowForFilter(item: any) {
1094
+ const noLogin =
1095
+ item.noLoginStatus != null
1096
+ ? Number(item.noLoginStatus)
1097
+ : item.anonymous === true
1098
+ ? 1
1099
+ : item.anonymous === false
1100
+ ? 0
1101
+ : 0
1102
+ return {
1103
+ ...item,
1104
+ title: item.title ?? item.name,
1105
+ path: item.path ?? item.apiPath,
1106
+ httpMethod: item.httpMethod ?? item.method,
1107
+ noLoginStatus: noLogin,
1108
+ logStatus: item.logStatus != null ? Number(item.logStatus) : 1,
1109
+ apiType: item.apiType != null ? Number(item.apiType) : 1,
1110
+ }
1111
+ }
1112
+
1113
+ function matchesPermissionFilters(item: any, params: Record<string, any>) {
1114
+ const row = normalizePermissionRowForFilter(item)
1115
+ const keyword = String(params?.keyword ?? params?.searchQ ?? '')
1116
+ .trim()
1117
+ .toLowerCase()
1118
+ if (keyword) {
1119
+ const inTitle = String(row.title ?? '').toLowerCase().includes(keyword)
1120
+ const inCode = String(row.code ?? '').toLowerCase().includes(keyword)
1121
+ const inPath = String(row.path ?? '').toLowerCase().includes(keyword)
1122
+ if (!inTitle && !inCode && !inPath) return false
1123
+ }
1124
+ if (
1125
+ params?.status != null &&
1126
+ params?.status !== '' &&
1127
+ !Number.isNaN(Number(params.status))
1128
+ ) {
1129
+ if (Number(row.status) !== Number(params.status)) return false
1130
+ }
1131
+ if (params?.httpMethod != null && params?.httpMethod !== '') {
1132
+ if (String(row.httpMethod) !== String(params.httpMethod)) return false
1133
+ }
1134
+ if (
1135
+ params?.noLoginStatus != null &&
1136
+ params?.noLoginStatus !== '' &&
1137
+ !Number.isNaN(Number(params.noLoginStatus))
1138
+ ) {
1139
+ if (Number(row.noLoginStatus) !== Number(params.noLoginStatus)) return false
1140
+ }
1141
+ if (
1142
+ params?.logStatus != null &&
1143
+ params?.logStatus !== '' &&
1144
+ !Number.isNaN(Number(params.logStatus))
1145
+ ) {
1146
+ if (Number(row.logStatus) !== Number(params.logStatus)) return false
1147
+ }
1148
+ if (
1149
+ params?.apiType != null &&
1150
+ params?.apiType !== '' &&
1151
+ !Number.isNaN(Number(params.apiType))
1152
+ ) {
1153
+ if (Number(row.apiType) !== Number(params.apiType)) return false
1154
+ }
1155
+ return true
1156
+ }
1157
+
1158
+ /** page-system:menuId + keyword/status/httpMethod/... + page + size */
1159
+ function queryPermissionList(params: Record<string, any>) {
1160
+ const menuId = String(params?.menuId || '').trim()
1161
+
1162
+ let items: any[]
1163
+ if (menuId) {
1164
+ items = [...(permissionStore[menuId] || [])]
1165
+ } else {
1166
+ items = flattenAllPermissions()
1167
+ }
1168
+ items = items.filter((item) => matchesPermissionFilters(item, params))
1169
+ items = items.map((item) => normalizePermissionRowForFilter(item))
1170
+
1171
+ const pageSize = Math.max(
1172
+ 1,
1173
+ Number(params?.size ?? params?.pageSize ?? params?.limit ?? 10),
1174
+ )
1175
+ const total = items.length
1176
+
1177
+ if (params?.skip != null) {
1178
+ const skip = Math.max(0, Number(params.skip))
1179
+ return { slice: items.slice(skip, skip + pageSize), total }
1180
+ }
1181
+
1182
+ const page = Math.max(1, Number(params?.page || 1))
1183
+ const start = (page - 1) * pageSize
1184
+ return { slice: items.slice(start, start + pageSize), total }
1185
+ }
1186
+
1187
+ /** 权限列表 Mock 体(与 axios mock 解包后一致);供 `permission.js` 与 handler 共用 */
1188
+ export function getPermissionListMockData(params: any) {
1189
+ const { slice, total } = queryPermissionList(params || {})
1190
+ return {
1191
+ content: slice,
1192
+ totalElements: total,
1193
+ items: slice,
1194
+ total,
1195
+ }
1196
+ }
1197
+
1198
+ /** 新增权限 Mock 业务体;缺 menuId 时抛错,与 axios mock 校验一致 */
1199
+ export function buildPermissionCreateResult(data: any) {
1200
+ const menuId = String(data?.menuId || '').trim()
1201
+ if (!menuId) {
1202
+ throw new Error('menuId is required')
1203
+ }
1204
+ const pathRaw = data?.path ?? data?.apiPath
1205
+ const pathVal = pathRaw == null || pathRaw === '' ? '' : String(pathRaw).trim()
1206
+ const methodRaw = data?.httpMethod ?? data?.method
1207
+ const methodVal = (methodRaw == null || methodRaw === '' ? 'POST' : String(methodRaw)).toUpperCase()
1208
+ const noLogin = Number(data?.noLoginStatus ?? (data?.anonymous ? 1 : 0))
1209
+ const titleRaw = data?.title ?? data?.name
1210
+ const titleVal = titleRaw == null || titleRaw === '' ? '' : String(titleRaw).trim()
1211
+ const next = {
1212
+ id: genPermissionId(),
1213
+ menuId,
1214
+ apiPath: pathVal,
1215
+ path: pathVal,
1216
+ code: String(data?.code || '').trim(),
1217
+ name: titleVal,
1218
+ title: titleVal,
1219
+ description: String(data?.description || '').trim(),
1220
+ method: methodVal,
1221
+ httpMethod: methodVal,
1222
+ anonymous: noLogin === 1,
1223
+ noLoginStatus: noLogin,
1224
+ logStatus: Number(data?.logStatus ?? 1),
1225
+ apiType: Number(data?.apiType ?? 1),
1226
+ sortOrder: Number(data?.sortOrder ?? 0),
1227
+ status: Number(data?.status ?? 1),
1228
+ }
1229
+ if (!permissionStore[menuId]) {
1230
+ permissionStore[menuId] = []
1231
+ }
1232
+ permissionStore[menuId].push(next)
1233
+ return {
1234
+ success: true,
1235
+ code: 200,
1236
+ message: '新增成功',
1237
+ data: next,
1238
+ }
1239
+ }
1240
+
1241
+ /** 删除权限 Mock 业务体 */
1242
+ export function buildPermissionDeleteResult(permissionId: string) {
1243
+ Object.keys(permissionStore).forEach((mid) => {
1244
+ permissionStore[mid] = (permissionStore[mid] || []).filter(
1245
+ (item) => String(item.id) !== String(permissionId),
1246
+ )
1247
+ })
1248
+ return {
1249
+ success: true,
1250
+ code: 200,
1251
+ message: '删除成功',
1252
+ data: { success: true },
1253
+ }
1254
+ }
1255
+
1256
+ export const permissionsMockApi = {
1257
+ assignable: async (params: any) => {
1258
+ if (!mockManager.isEnabled()) {
1259
+ throw new Error('Not in mock mode')
1260
+ }
1261
+ return mockManager.response(getPermissionListMockData(params))
1262
+ },
1263
+
1264
+ create: async (data: any) => {
1265
+ if (!mockManager.isEnabled()) {
1266
+ throw new Error('Not in mock mode')
1267
+ }
1268
+ try {
1269
+ return mockManager.response(buildPermissionCreateResult(data))
1270
+ } catch (e: any) {
1271
+ if (e?.message === 'menuId is required') {
1272
+ return mockManager.error('menuId is required', 400)
1273
+ }
1274
+ throw e
1275
+ }
1276
+ },
1277
+
1278
+ delete: async (permissionId: string) => {
1279
+ if (!mockManager.isEnabled()) {
1280
+ throw new Error('Not in mock mode')
1281
+ }
1282
+ return mockManager.response(buildPermissionDeleteResult(permissionId))
1283
+ },
1284
+
1285
+ list: async (params: any) => {
1286
+ if (!mockManager.isEnabled()) {
1287
+ throw new Error('Not in mock mode')
1288
+ }
1289
+ return mockManager.response(getPermissionListMockData(params))
1290
+ },
1291
+
1292
+ update: async (_data: any) => {
1293
+ if (!mockManager.isEnabled()) {
1294
+ throw new Error('Not in mock mode')
1295
+ }
1296
+ return mockManager.response({ success: true })
1297
+ },
1298
+ }
1299
+
1300
+ // ==================== 角色菜单权限分配(page-system PermissionModal Mock)====================
1301
+ const rolePermissionAssignStore = new Map<
1302
+ string,
1303
+ {
1304
+ menuIds: string[]
1305
+ permissionCodes: string[]
1306
+ }
1307
+ >()
1308
+
1309
+ export function getRolePermissionAssignSnapshot(roleId: string | number) {
1310
+ const key = String(roleId)
1311
+ const cached = rolePermissionAssignStore.get(key)
1312
+ if (cached) {
1313
+ return {
1314
+ menuIds: [...cached.menuIds],
1315
+ permissionCodes: [...cached.permissionCodes],
1316
+ }
1317
+ }
1318
+ const role = mockRoles.items.find((r: any) => String(r.id) === key) as
1319
+ | { permissions?: string[] }
1320
+ | undefined
1321
+ const permissionCodes = Array.isArray(role?.permissions)
1322
+ ? [...role.permissions]
1323
+ : []
1324
+ return {
1325
+ menuIds: [] as string[],
1326
+ permissionCodes,
1327
+ }
1328
+ }
1329
+
1330
+ export function setRolePermissionAssignSnapshot(
1331
+ roleId: string | number,
1332
+ body: {
1333
+ menuIds: string[]
1334
+ permissionCodes: string[]
1335
+ },
1336
+ ) {
1337
+ rolePermissionAssignStore.set(String(roleId), {
1338
+ menuIds: [...body.menuIds],
1339
+ permissionCodes: [...body.permissionCodes],
1340
+ })
1341
+ }
1342
+
1343
+ // ==================== 认证相关 API ====================
1344
+ export const authMockApi = {
1345
+ /**
1346
+ * 登录
1347
+ */
1348
+ login: async (data: any) => {
1349
+ if (!mockManager.isEnabled()) {
1350
+ throw new Error('Not in mock mode')
1351
+ }
1352
+ const inputPhone = String(data?.phone || '').trim()
1353
+ const inputPassword = String(data?.password || '').trim()
1354
+
1355
+ if (!inputPhone || !inputPassword) {
1356
+ return mockManager.error('Incorrect phone or password', 401)
1357
+ }
1358
+
1359
+ // 保留开发后门账号 super(前端已隐藏说明)
1360
+ if (inputPhone === 'super') {
1361
+ return mockManager.response({
1362
+ code: 200,
1363
+ message: 'ok',
1364
+ data: {
1365
+ id: 'super',
1366
+ name: 'super',
1367
+ avatar: '',
1368
+ token: 'mock-token-super',
1369
+ },
1370
+ success: true,
1371
+ timestamp: Date.now(),
1372
+ })
1373
+ }
1374
+
1375
+ return mockManager.response({
1376
+ code: 200,
1377
+ message: 'ok',
1378
+ data: {
1379
+ id: inputPhone.replace(/\s/g, '') || 'user',
1380
+ name: inputPhone,
1381
+ avatar: '',
1382
+ token: `mock-token-${inputPhone.replace(/\D/g, '') || 'user'}`,
1383
+ },
1384
+ success: true,
1385
+ timestamp: Date.now(),
1386
+ })
1387
+ },
1388
+
1389
+ /**
1390
+ * 获取当前用户信息
1391
+ */
1392
+ me: async () => {
1393
+ if (!mockManager.isEnabled()) {
1394
+ throw new Error('Not in mock mode')
1395
+ }
1396
+
1397
+ // 返回 Mock 用户数据 - 参考真实后端返回格式
1398
+ return mockManager.response({
1399
+ id: '5',
1400
+ name: '18888848001',
1401
+ email: '18888848001@189.com',
1402
+ phone: '+86 18888848001',
1403
+ avatar: '',
1404
+ sex: 0,
1405
+ identity: 0,
1406
+ theme: 'dark',
1407
+ language: 'zh-CN',
1408
+ is_active: true,
1409
+ created_at: '2026-04-03T07:13:32.433687Z',
1410
+ updated_at: '2026-04-03T07:13:32.433687Z',
1411
+ // Mock 模式下显式返回权限集合(覆盖 mock 菜单所需权限)
1412
+ permissions: [
1413
+ 'user:view',
1414
+ 'user:add',
1415
+ 'user:edit',
1416
+ 'user:delete',
1417
+ 'user:role',
1418
+
1419
+ 'department:view',
1420
+ 'department:create',
1421
+ 'department:edit',
1422
+ 'department:delete',
1423
+ 'department:member:manage',
1424
+
1425
+ 'role:view',
1426
+ 'role:view:all',
1427
+ 'role:create',
1428
+ 'role:edit',
1429
+ 'role:delete',
1430
+
1431
+ 'permission:view',
1432
+ 'permission:view:all',
1433
+ 'permission:create',
1434
+ 'permission:delete',
1435
+
1436
+ 'system:config:view',
1437
+ 'system:config:edit',
1438
+
1439
+ 'rule:view',
1440
+ 'rule:manage',
1441
+
1442
+ 'feedback:view',
1443
+ 'feedback:review',
1444
+ 'feedback:export',
1445
+ 'feedback:submit',
1446
+ 'feedback:edit',
1447
+ 'feedback:delete',
1448
+
1449
+ 'log:view',
1450
+
1451
+ 'chat:list',
1452
+ 'chat:create',
1453
+ 'chat:view',
1454
+
1455
+ 'memory:view',
1456
+ 'memory:add',
1457
+ 'memory:delete',
1458
+
1459
+ 'skill:view',
1460
+ 'skill:manage',
1461
+
1462
+ 'dict:cate:create',
1463
+ 'dict:cate:edit',
1464
+ 'dict:cate:delete',
1465
+ 'dict:data:create',
1466
+ 'dict:data:edit',
1467
+ 'dict:data:delete',
1468
+ ],
1469
+ roles: ['admin'],
1470
+ departments: [],
1471
+ })
1472
+ },
1473
+
1474
+ /**
1475
+ * 获取用户配置
1476
+ */
1477
+ getUserConfig: async () => {
1478
+ if (!mockManager.isEnabled()) {
1479
+ throw new Error('Not in mock mode')
1480
+ }
1481
+
1482
+ // 返回默认配置
1483
+ return mockManager.response({
1484
+ user_id: '1',
1485
+ theme: 'dark',
1486
+ language: 'zh-CN',
1487
+ preferences: {},
1488
+ })
1489
+ },
1490
+
1491
+ /**
1492
+ * 登出
1493
+ */
1494
+ logout: async () => {
1495
+ if (!mockManager.isEnabled()) {
1496
+ throw new Error('Not in mock mode')
1497
+ }
1498
+
1499
+ return mockManager.response({ success: true })
1500
+ },
1501
+
1502
+ /**
1503
+ * 注册
1504
+ */
1505
+ register: async (data: any) => {
1506
+ if (!mockManager.isEnabled()) {
1507
+ throw new Error('Not in mock mode')
1508
+ }
1509
+
1510
+ return mockManager.response({ success: true })
1511
+ },
1512
+
1513
+ /**
1514
+ * 检查邮箱
1515
+ */
1516
+ checkEmail: async (data: any) => {
1517
+ if (!mockManager.isEnabled()) {
1518
+ throw new Error('Not in mock mode')
1519
+ }
1520
+
1521
+ const exists = data.email === 'admin@example.com'
1522
+ return mockManager.response({ exists })
1523
+ },
1524
+
1525
+ /**
1526
+ * 获取公钥
1527
+ */
1528
+ publicKey: async () => {
1529
+ if (!mockManager.isEnabled()) {
1530
+ throw new Error('Not in mock mode')
1531
+ }
1532
+
1533
+ return mockManager.response({
1534
+ public_key: 'mock-public-key-for-development',
1535
+ })
1536
+ },
1537
+ }
1538
+
1539
+ // ==================== 聊天相关 API ====================
1540
+ export const chatMockApi = {
1541
+ /**
1542
+ * 获取聊天列表
1543
+ */
1544
+ getChatThreads: async (data: any) => {
1545
+ if (!mockManager.isEnabled()) {
1546
+ throw new Error('Not in mock mode')
1547
+ }
1548
+
1549
+ // 返回 Mock 聊天列表
1550
+ const limit = data?.limit || 50
1551
+ return mockManager.response(
1552
+ [
1553
+ {
1554
+ id: 'thread-1',
1555
+ title: '第一个聊天',
1556
+ created_at: '2024-01-01T10:00:00Z',
1557
+ updated_at: '2024-01-01T10:00:00Z',
1558
+ user_id: '5',
1559
+ topStatus: 1,
1560
+ },
1561
+ {
1562
+ id: 'thread-2',
1563
+ title: '第二个聊天',
1564
+ created_at: '2024-01-02T10:00:00Z',
1565
+ updated_at: '2024-01-02T10:00:00Z',
1566
+ user_id: '5',
1567
+ topStatus: 0,
1568
+ },
1569
+ {
1570
+ id: 'thread-3',
1571
+ title: '测试对话',
1572
+ created_at: '2024-01-03T10:00:00Z',
1573
+ updated_at: '2024-01-03T10:00:00Z',
1574
+ user_id: '5',
1575
+ topStatus: 0,
1576
+ },
1577
+ ].slice(0, limit),
1578
+ )
1579
+ },
1580
+
1581
+ /**
1582
+ * 会话消息点赞/点踩(占位:真实接口路径待定)
1583
+ */
1584
+ submitMessageFeedback: async (data: {
1585
+ sessionId?: string
1586
+ session_id?: string
1587
+ turnId?: string
1588
+ turn_id?: string
1589
+ messageId?: string
1590
+ message_id?: string
1591
+ evaluationType?: number
1592
+ evaluation_type?: number
1593
+ score?: number
1594
+ }) => {
1595
+ if (!mockManager.isEnabled()) {
1596
+ throw new Error('Not in mock mode')
1597
+ }
1598
+
1599
+ const turnId = data.turnId ?? data.turn_id ?? data.messageId ?? data.message_id
1600
+ const evaluationType =
1601
+ data.evaluationType ?? data.evaluation_type ?? data.score ?? 0
1602
+
1603
+ return mockManager.response({
1604
+ success: true,
1605
+ session_id: data.sessionId ?? data.session_id,
1606
+ turnId,
1607
+ evaluationType,
1608
+ })
1609
+ },
1610
+
1611
+ updateChatTitle: async (_data: unknown) => {
1612
+ if (!mockManager.isEnabled()) {
1613
+ throw new Error('Not in mock mode')
1614
+ }
1615
+ return mockManager.response({ success: true })
1616
+ },
1617
+
1618
+ pinChat: async (_data: unknown) => {
1619
+ if (!mockManager.isEnabled()) {
1620
+ throw new Error('Not in mock mode')
1621
+ }
1622
+ return mockManager.response({ success: true })
1623
+ },
1624
+
1625
+ getChatTitle: async (data: unknown) => {
1626
+ if (!mockManager.isEnabled()) {
1627
+ throw new Error('Not in mock mode')
1628
+ }
1629
+ const d = data as { sessionId?: string }
1630
+ const sid = String(d?.sessionId ?? 'session')
1631
+ return mockManager.response({
1632
+ data: { title: `会话 ${sid.slice(0, 12)}` },
1633
+ })
1634
+ },
1635
+
1636
+ deleteSession: async (_data: unknown) => {
1637
+ if (!mockManager.isEnabled()) {
1638
+ throw new Error('Not in mock mode')
1639
+ }
1640
+ return mockManager.response({ success: true })
1641
+ },
1642
+ }