qy-better-lib 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 (185) hide show
  1. package/.vscode/extensions.json +3 -0
  2. package/LICENSE +24 -0
  3. package/README.md +2 -0
  4. package/index.html +13 -0
  5. package/package.json +37 -0
  6. package/packages/core/DOCUMENTATION.md +2681 -0
  7. package/packages/core/LICENSE +24 -0
  8. package/packages/core/package.json +67 -0
  9. package/packages/core/types/index.d.ts +39 -0
  10. package/packages/core/types/json.d.ts +4 -0
  11. package/packages/core/types/vue.shim.d.ts +5 -0
  12. package/packages/core/vitest.config.ts +15 -0
  13. package/packages/core/yarn.lock +1233 -0
  14. package/packages/hooks/DOCUMENTATION.md +634 -0
  15. package/packages/hooks/LICENSE +24 -0
  16. package/packages/hooks/__tests__/use-chart/index.test.ts +287 -0
  17. package/packages/hooks/__tests__/use-emit/index.test.ts +248 -0
  18. package/packages/hooks/__tests__/use-fullscreen/index.test.ts +162 -0
  19. package/packages/hooks/__tests__/use-image/index.test.ts +230 -0
  20. package/packages/hooks/__tests__/use-layout-flow/index.test.ts +382 -0
  21. package/packages/hooks/__tests__/use-mqtt/index.test.ts +392 -0
  22. package/packages/hooks/__tests__/use-print/index.test.ts +378 -0
  23. package/packages/hooks/__tests__/use-watermark/index.test.ts +277 -0
  24. package/packages/hooks/__tests__/use-websocket/index.test.ts +402 -0
  25. package/packages/hooks/package.json +104 -0
  26. package/packages/hooks/types/index.d.ts +1 -0
  27. package/packages/hooks/types/json.d.ts +4 -0
  28. package/packages/hooks/types/vue.shim.d.ts +5 -0
  29. package/packages/hooks/yarn.lock +1832 -0
  30. package/packages/lowcode/core/package.json +60 -0
  31. package/packages/lowcode/core/types/index.d.ts +1 -0
  32. package/packages/lowcode/core/types/json.d.ts +4 -0
  33. package/packages/lowcode/core/types/vue.shim.d.ts +5 -0
  34. package/packages/lowcode/core/vite.dist.min.config.js +40 -0
  35. package/packages/lowcode/core/vite.dist.min.config.js.map +1 -0
  36. package/packages/lowcode/core/vite.lib.config.js +74 -0
  37. package/packages/lowcode/core/vite.lib.config.js.map +1 -0
  38. package/packages/lowcode/core/yarn.lock +1132 -0
  39. package/packages/lowcode/mobile/package.json +63 -0
  40. package/packages/lowcode/mobile/types/index.d.ts +1 -0
  41. package/packages/lowcode/mobile/types/json.d.ts +4 -0
  42. package/packages/lowcode/mobile/types/vue.shim.d.ts +77 -0
  43. package/packages/lowcode/mobile/vite.config.js +11 -0
  44. package/packages/lowcode/mobile/vite.config.js.map +1 -0
  45. package/packages/lowcode/mobile/vite.dist.min.config.js +71 -0
  46. package/packages/lowcode/mobile/vite.dist.min.config.js.map +1 -0
  47. package/packages/lowcode/mobile/vite.lib.config.js +137 -0
  48. package/packages/lowcode/mobile/vite.lib.config.js.map +1 -0
  49. package/packages/lowcode/mobile/yarn.lock +3888 -0
  50. package/packages/lowcode/pc/package.json +64 -0
  51. package/packages/lowcode/pc/vite.config.js +11 -0
  52. package/packages/lowcode/pc/vite.config.js.map +1 -0
  53. package/packages/lowcode/pc/vite.dist.min.config.js +71 -0
  54. package/packages/lowcode/pc/vite.dist.min.config.js.map +1 -0
  55. package/packages/lowcode/pc/vite.lib.config.js +137 -0
  56. package/packages/lowcode/pc/vite.lib.config.js.map +1 -0
  57. package/packages/lowcode/pc/yarn.lock +4026 -0
  58. package/packages/pc_components/DOCUMENTATION.md +566 -0
  59. package/packages/pc_components/LICENSE +24 -0
  60. package/packages/pc_components/lib/commDialog/index.d.ts +3 -0
  61. package/packages/pc_components/lib/commDialog/index.js +8 -0
  62. package/packages/pc_components/lib/commDialog/src/index.vue.d.ts +102 -0
  63. package/packages/pc_components/lib/commDialog/src/index.vue.js +43 -0
  64. package/packages/pc_components/lib/commDialog/src/index.vue2.js +4 -0
  65. package/packages/pc_components/lib/commDialog/src/props.d.ts +49 -0
  66. package/packages/pc_components/lib/commDialog/src/props.js +48 -0
  67. package/packages/pc_components/lib/commDialog/src/type.d.ts +39 -0
  68. package/packages/pc_components/lib/commForm/index.d.ts +3 -0
  69. package/packages/pc_components/lib/commForm/index.js +8 -0
  70. package/packages/pc_components/lib/commForm/src/index.vue.d.ts +95 -0
  71. package/packages/pc_components/lib/commForm/src/index.vue.js +50 -0
  72. package/packages/pc_components/lib/commForm/src/index.vue2.js +4 -0
  73. package/packages/pc_components/lib/commForm/src/props.d.ts +49 -0
  74. package/packages/pc_components/lib/commForm/src/props.js +47 -0
  75. package/packages/pc_components/lib/commForm/src/type.d.ts +8 -0
  76. package/packages/pc_components/lib/contextMenu/index.d.ts +5 -0
  77. package/packages/pc_components/lib/contextMenu/index.js +8 -0
  78. package/packages/pc_components/lib/contextMenu/src/index.vue.d.ts +91 -0
  79. package/packages/pc_components/lib/contextMenu/src/index.vue.js +153 -0
  80. package/packages/pc_components/lib/contextMenu/src/index.vue2.js +4 -0
  81. package/packages/pc_components/lib/contextMenu/src/props.d.ts +32 -0
  82. package/packages/pc_components/lib/contextMenu/src/props.js +27 -0
  83. package/packages/pc_components/lib/contextMenu/src/type.d.ts +11 -0
  84. package/packages/pc_components/lib/describeView/index.d.ts +2 -0
  85. package/packages/pc_components/lib/describeView/index.js +7 -0
  86. package/packages/pc_components/lib/describeView/src/index.vue.d.ts +61 -0
  87. package/packages/pc_components/lib/describeView/src/index.vue.js +84 -0
  88. package/packages/pc_components/lib/describeView/src/index.vue2.js +4 -0
  89. package/packages/pc_components/lib/describeView/src/props.d.ts +35 -0
  90. package/packages/pc_components/lib/describeView/src/props.js +33 -0
  91. package/packages/pc_components/lib/describeView/src/type.d.ts +10 -0
  92. package/packages/pc_components/lib/index.d.ts +18 -0
  93. package/packages/pc_components/lib/index.js +40 -0
  94. package/packages/pc_components/lib/simpleVirtualList/index.d.ts +2 -0
  95. package/packages/pc_components/lib/simpleVirtualList/index.js +7 -0
  96. package/packages/pc_components/lib/simpleVirtualList/src/index.vue.d.ts +28 -0
  97. package/packages/pc_components/lib/simpleVirtualList/src/index.vue.js +101 -0
  98. package/packages/pc_components/lib/simpleVirtualList/src/index.vue2.js +4 -0
  99. package/packages/pc_components/lib/simpleVirtualList/src/type.d.ts +12 -0
  100. package/packages/pc_components/lib/styles/comm-form.scss +4 -0
  101. package/packages/pc_components/lib/styles/context-menu.scss +47 -0
  102. package/packages/pc_components/lib/styles/describe-view.scss +25 -0
  103. package/packages/pc_components/lib/styles/index.scss +6 -0
  104. package/packages/pc_components/lib/styles/simple-virtual-list.scss +25 -0
  105. package/packages/pc_components/lib/styles/table-extend.scss +100 -0
  106. package/packages/pc_components/lib/styles/text-button.scss +71 -0
  107. package/packages/pc_components/lib/tableExtend/index.d.ts +3 -0
  108. package/packages/pc_components/lib/tableExtend/index.js +7 -0
  109. package/packages/pc_components/lib/tableExtend/props.d.ts +130 -0
  110. package/packages/pc_components/lib/tableExtend/props.js +128 -0
  111. package/packages/pc_components/lib/tableExtend/src/colVisible.vue.d.ts +3 -0
  112. package/packages/pc_components/lib/tableExtend/src/colVisible.vue.js +128 -0
  113. package/packages/pc_components/lib/tableExtend/src/colVisible.vue2.js +4 -0
  114. package/packages/pc_components/lib/tableExtend/src/index.vue.d.ts +186 -0
  115. package/packages/pc_components/lib/tableExtend/src/index.vue.js +234 -0
  116. package/packages/pc_components/lib/tableExtend/src/index.vue2.js +4 -0
  117. package/packages/pc_components/lib/tableExtend/src/valueCol.vue.d.ts +24 -0
  118. package/packages/pc_components/lib/tableExtend/src/valueCol.vue.js +29 -0
  119. package/packages/pc_components/lib/tableExtend/src/valueCol.vue2.js +4 -0
  120. package/packages/pc_components/lib/tableExtend/type.d.ts +165 -0
  121. package/packages/pc_components/lib/tableExtend/type.js +9 -0
  122. package/packages/pc_components/lib/tableExtend/useTable.d.ts +27 -0
  123. package/packages/pc_components/lib/tableExtend/useTable.js +115 -0
  124. package/packages/pc_components/lib/textButton/index.d.ts +2 -0
  125. package/packages/pc_components/lib/textButton/index.js +7 -0
  126. package/packages/pc_components/lib/textButton/src/index.vue.d.ts +42 -0
  127. package/packages/pc_components/lib/textButton/src/index.vue.js +44 -0
  128. package/packages/pc_components/lib/textButton/src/index.vue2.js +4 -0
  129. package/packages/pc_components/lib/textButton/src/props.d.ts +23 -0
  130. package/packages/pc_components/lib/textButton/src/props.js +30 -0
  131. package/packages/pc_components/lib/textButton/src/type.d.ts +30 -0
  132. package/packages/pc_components/lib/utils/index.d.ts +77 -0
  133. package/packages/pc_components/lib/utils/index.js +124 -0
  134. package/packages/pc_components/package.json +73 -0
  135. package/packages/pc_components/types/index.d.ts +9 -0
  136. package/packages/pc_components/types/json.d.ts +4 -0
  137. package/packages/pc_components/types/vue.shim.d.ts +5 -0
  138. package/packages/pc_components/yarn.lock +1641 -0
  139. package/postcss.config.js +19 -0
  140. package/public/vite.svg +1 -0
  141. package/src/App.vue +37 -0
  142. package/src/api/index.ts +42 -0
  143. package/src/assets/vue.svg +1 -0
  144. package/src/document/core.md +2680 -0
  145. package/src/document/hooks.md +632 -0
  146. package/src/document/pc_components.md +566 -0
  147. package/src/locales/en.json +1 -0
  148. package/src/locales/zh-cn.json +1 -0
  149. package/src/main.ts +13 -0
  150. package/src/plugins/element-plus.ts +16 -0
  151. package/src/plugins/i18n.ts +17 -0
  152. package/src/plugins/index.ts +13 -0
  153. package/src/plugins/store.ts +12 -0
  154. package/src/router/index.ts +20 -0
  155. package/src/shared/chartType.ts +279 -0
  156. package/src/shared/const.ts +160 -0
  157. package/src/shared/lib.ts +129 -0
  158. package/src/shared/request.ts +255 -0
  159. package/src/shared/type.ts +48 -0
  160. package/src/shared/utils/date.ts +83 -0
  161. package/src/shared/utils/utils.ts +85 -0
  162. package/src/store/index.ts +22 -0
  163. package/src/store/modules/app.ts +17 -0
  164. package/src/store/modules/shared.ts +21 -0
  165. package/src/styles/index.scss +169 -0
  166. package/src/types/app.d.ts +23 -0
  167. package/src/types/echarts.d.ts +5 -0
  168. package/src/types/index.d.ts +1 -0
  169. package/src/types/json.d.ts +4 -0
  170. package/src/types/scss.d.ts +9 -0
  171. package/src/types/vue.shim.d.ts +5 -0
  172. package/src/views/docs/docs-content.vue +379 -0
  173. package/src/views/docs/docs-header.vue +130 -0
  174. package/src/views/docs/docs-sidebar.vue +76 -0
  175. package/src/views/docs/hooks.ts +600 -0
  176. package/src/views/docs/index.vue +30 -0
  177. package/src/views/docs/styles/docs-content.scss +106 -0
  178. package/src/views/docs/styles/docs-header.scss +20 -0
  179. package/src/views/docs/styles/docs-sidebar.scss +182 -0
  180. package/src/views/docs/styles/index.scss +14 -0
  181. package/src/views/docs/type.ts +101 -0
  182. package/src/views/index.vue +34 -0
  183. package/tsconfig.json +37 -0
  184. package/tsconfig.node.json +8 -0
  185. package/vite.config.ts +54 -0
@@ -0,0 +1,600 @@
1
+ import { reactive, computed, onMounted, onUnmounted } from 'vue';
2
+ import MarkdownIt from 'markdown-it';
3
+ import hljs from 'highlight.js';
4
+ import 'highlight.js/styles/gradient-dark.css';
5
+ import type { DocsState, DocItem, ModuleChild, ModuleData } from './type';
6
+ import { on, off } from '@qy_better_lib/core';
7
+ import { guid } from '@qy_better_lib/core';
8
+ import core_md from '@/document/core.md?raw';
9
+ import hooks_md from '@/document/hooks.md?raw';
10
+ import pc_components_md from '@/document/pc_components.md?raw';
11
+
12
+ // 公共响应式状态
13
+ export const state = reactive<DocsState>({
14
+ search_query: '',
15
+ all_docs: [],
16
+ selected_doc: null,
17
+ default_openeds: [],
18
+ doc_content_map: {}
19
+ });
20
+
21
+
22
+
23
+ /**
24
+ * 解析 MD 文件内容,提取函数和组件信息
25
+ * @param content MD 文件内容
26
+ * @param module 模块名称
27
+ * @returns 解析后的文档项数组
28
+ */
29
+ /**
30
+ * 保存当前解析的文档项目
31
+ * @param docs 文档项目数组
32
+ * @param current_item 当前项目名称
33
+ * @param current_description 当前项目描述
34
+ * @param current_content 当前项目内容
35
+ * @param current_parent 当前项目父级ID
36
+ * @param module 模块名称
37
+ */
38
+ function save_current_item(
39
+ docs: DocItem[],
40
+ current_item: string | null,
41
+ current_description: string,
42
+ current_content: string,
43
+ current_parent: string | null,
44
+ module: string
45
+ ): void {
46
+ if (current_item) {
47
+ const item_guid = guid();
48
+ state.doc_content_map[item_guid] = current_content.trim();
49
+
50
+ docs.push({
51
+ id: item_guid,
52
+ name: current_item,
53
+ description: current_description,
54
+ module,
55
+ type: module === 'pc_components' ? 'component' : 'function',
56
+ content: current_content.trim(),
57
+ path: `packages/${module}/DOCUMENTATION.md`,
58
+ parentId: current_parent
59
+ });
60
+ }
61
+ }
62
+
63
+ /**
64
+ * 处理hooks模块的一级菜单
65
+ * @param original_item 原始菜单文本
66
+ * @returns 处理后的项目信息
67
+ */
68
+ function process_hooks_menu(original_item: string): { item: string; description: string; parent: null } {
69
+ const parts = original_item.split(' - ');
70
+ if (parts.length >= 2) {
71
+ const first_part = parts[0].trim();
72
+ const function_name = first_part.replace(/^\d+\.\s+/, '').trim();
73
+ const func_description = parts.slice(1).join(' - ').trim();
74
+ return {
75
+ item: `${func_description}(${function_name})`,
76
+ description: func_description,
77
+ parent: null
78
+ };
79
+ } else {
80
+ return {
81
+ item: original_item,
82
+ description: '',
83
+ parent: null
84
+ };
85
+ }
86
+ }
87
+
88
+ /**
89
+ * 处理core模块的一级菜单
90
+ * @param original_item 原始菜单文本
91
+ * @returns 处理后的项目信息
92
+ */
93
+ function process_core_menu(original_item: string): { item: null; description: string; parent: string } {
94
+ return {
95
+ item: null,
96
+ description: '',
97
+ parent: original_item.replace(/^\d+\.\s+/, '')
98
+ };
99
+ }
100
+
101
+ /**
102
+ * 处理pc_components模块的一级菜单
103
+ * @param original_item 原始菜单文本
104
+ * @returns 处理后的项目信息
105
+ */
106
+ function process_pc_components_menu(original_item: string): { item: string; description: string; parent: null } {
107
+ const original_item_clean = original_item.replace(/^\d+\.\s+/, '');
108
+ let item_name = original_item_clean;
109
+ let description = '';
110
+
111
+ if (original_item_clean.includes('-')) {
112
+ const parts = original_item_clean.split('-');
113
+ item_name = parts[0].trim();
114
+ description = parts.slice(1).join('-').trim();
115
+ return {
116
+ item: `${description}(${item_name})`,
117
+ description,
118
+ parent: null
119
+ };
120
+ } else {
121
+ return {
122
+ item: item_name,
123
+ description: '',
124
+ parent: null
125
+ };
126
+ }
127
+ }
128
+
129
+ /**
130
+ * 处理core模块的三级菜单
131
+ * @param original_item 原始菜单文本
132
+ * @returns 处理后的项目信息
133
+ */
134
+ function process_level3_menu(original_item: string): { item: string; description: string } {
135
+ let item_name = original_item.replace(/^\d+\.\s+/, '');
136
+ let description = '';
137
+
138
+ if (item_name.includes('-')) {
139
+ const parts = item_name.split('-');
140
+ item_name = parts[0].trim();
141
+ description = parts.slice(1).join('-').trim();
142
+ }
143
+
144
+ return {
145
+ item: item_name,
146
+ description
147
+ };
148
+ }
149
+
150
+ /**
151
+ * 解析 MD 文件内容,提取函数和组件信息
152
+ * @param content MD 文件内容
153
+ * @param module 模块名称
154
+ * @returns 解析后的文档项数组
155
+ */
156
+ function parse_md_content(content: string, module: string): DocItem[] {
157
+ const docs: DocItem[] = [];
158
+ const lines = content.split('\n');
159
+ let current_item: string | null = null;
160
+ let current_description = '';
161
+ let current_content = '';
162
+ let current_parent: string | null = null; // 用于core模块的一级菜单
163
+
164
+ lines.forEach(line => {
165
+ // 匹配一级菜单(以 ### 开头)
166
+ const level1_match = line.match(/^###\s+([^\n]+)$/);
167
+ // 匹配三级菜单(以 #### 开头,仅用于core模块)
168
+ const level3_match = line.match(/^####\s+([^\n]+)$/);
169
+
170
+ if (level1_match) {
171
+ // 如果已经有一个项目在解析中,先保存它
172
+ save_current_item(docs, current_item, current_description, current_content, current_parent, module);
173
+
174
+ // 开始解析新的一级菜单
175
+ const original_item = level1_match[1].trim();
176
+
177
+ if (module === 'hooks') {
178
+ const result = process_hooks_menu(original_item);
179
+ current_item = result.item;
180
+ current_description = result.description;
181
+ current_parent = result.parent;
182
+ } else if (module === 'core') {
183
+ const result = process_core_menu(original_item);
184
+ current_item = result.item;
185
+ current_description = result.description;
186
+ current_parent = result.parent;
187
+ } else {
188
+ const result = process_pc_components_menu(original_item);
189
+ current_item = result.item;
190
+ current_description = result.description;
191
+ current_parent = result.parent;
192
+ }
193
+ // 不包含标题行,只包含内容
194
+ current_content = '';
195
+ } else if (level3_match && module === 'core') {
196
+ // 如果已经有一个项目在解析中,先保存它
197
+ save_current_item(docs, current_item, current_description, current_content, current_parent, module);
198
+
199
+ // 开始解析新的三级菜单(仅用于core模块)
200
+ const result = process_level3_menu(level3_match[1].trim());
201
+ current_item = result.item;
202
+ current_description = result.description;
203
+ // 不包含标题行,只包含内容
204
+ current_content = '';
205
+ } else if (current_item) {
206
+ // 继续收集项目内容
207
+ current_content += line + '\n';
208
+ }
209
+ });
210
+
211
+ // 保存最后一个项目
212
+ save_current_item(docs, current_item, current_description, current_content, current_parent, module);
213
+
214
+ return docs;
215
+ }
216
+
217
+ /**
218
+ * 生成功能概览内容
219
+ * @param core_docs core模块文档
220
+ * @param hooks_docs hooks模块文档
221
+ * @param pc_components_docs pc_components模块文档
222
+ * @returns 功能概览内容
223
+ */
224
+ function generate_overview_content(core_docs: DocItem[], hooks_docs: DocItem[], pc_components_docs: DocItem[]): string {
225
+ let overview_content = '';
226
+
227
+ // 生成 core 模块概览(只显示名称)
228
+ overview_content += '## Core 工具函数\n\n';
229
+ overview_content += '<div class="overview-cards">\n';
230
+ const core_parent_set = new Set<string>();
231
+ core_docs.forEach(doc => {
232
+ if (doc.parentId) {
233
+ core_parent_set.add(doc.parentId);
234
+ }
235
+ });
236
+ core_parent_set.forEach(parent_name => {
237
+ // 解析格式:数字处理工具 (number.ts)
238
+ const match = parent_name.match(/^([^\(]+)\s*\(([^\)]+)\)/);
239
+ if (match) {
240
+ const description = match[1].trim();
241
+ const file_name = match[2].split('.')[0].trim(); // 提取number.ts中的number
242
+ // 找到该父级下的第一个文档项
243
+ const first_doc = core_docs.find(doc => doc.parentId === parent_name);
244
+ const doc_id = first_doc ? first_doc.id : '';
245
+ overview_content += `<div class="overview-card" data-id="${doc_id}" onclick="window.dispatchEvent(new CustomEvent('card-click', { detail: { id: '${doc_id}' } }))"><div class="card-name">${file_name}</div><div class="card-desc">${description}</div></div>\n`;
246
+ } else {
247
+ // 如果格式不符合,直接显示原始名称
248
+ overview_content += `<div class="overview-card">${parent_name}</div>\n`;
249
+ }
250
+ });
251
+ overview_content += '</div>\n\n';
252
+
253
+ // 生成 hooks 模块概览(只显示名称)
254
+ overview_content += '## Hooks 函数\n\n';
255
+ overview_content += '<div class="overview-cards">\n';
256
+ hooks_docs.forEach(doc => {
257
+ // 解析格式:打印功能(use-print)
258
+ const match = doc.name.match(/^([^\(]+)\(([^\)]+)\)/);
259
+ if (match) {
260
+ const description = match[1].trim();
261
+ const function_name = match[2].trim();
262
+ overview_content += `<div class="overview-card" data-id="${doc.id}" onclick="window.dispatchEvent(new CustomEvent('card-click', { detail: { id: '${doc.id}' } }))"><div class="card-name">${function_name}</div><div class="card-desc">${description}</div></div>\n`;
263
+ } else {
264
+ // 如果格式不符合,直接显示原始名称
265
+ overview_content += `<div class="overview-card" data-id="${doc.id}" onclick="window.dispatchEvent(new CustomEvent('card-click', { detail: { id: '${doc.id}' } }))">${doc.name}</div>\n`;
266
+ }
267
+ });
268
+ overview_content += '</div>\n\n';
269
+
270
+ // 生成 pc_components 模块概览(只显示名称)
271
+ overview_content += '## PC 组件\n\n';
272
+ overview_content += '<div class="overview-cards">\n';
273
+ pc_components_docs.forEach(doc => {
274
+ // 解析格式:表格扩展组件(tableExtend)
275
+ const match = doc.name.match(/^([^\(]+)\(([^\)]+)\)/);
276
+ if (match) {
277
+ const description = match[1].trim();
278
+ const component_name = match[2].trim();
279
+ overview_content += `<div class="overview-card" data-id="${doc.id}" onclick="window.dispatchEvent(new CustomEvent('card-click', { detail: { id: '${doc.id}' } }))"><div class="card-name">${component_name}</div><div class="card-desc">${description}</div></div>\n`;
280
+ } else {
281
+ // 如果格式不符合,直接显示原始名称
282
+ overview_content += `<div class="overview-card" data-id="${doc.id}" onclick="window.dispatchEvent(new CustomEvent('card-click', { detail: { id: '${doc.id}' } }))">${doc.name}</div>\n`;
283
+ }
284
+ });
285
+ overview_content += '</div>\n';
286
+
287
+ return overview_content;
288
+ }
289
+
290
+ /**
291
+ * 设置默认选中的文档和展开的菜单
292
+ * @param parsed_docs 解析后的文档列表
293
+ */
294
+ function set_default_selection(parsed_docs: DocItem[]): void {
295
+ if (parsed_docs.length > 0) {
296
+ // 首先查找功能概览文档
297
+ const overview_doc = parsed_docs.find(doc => doc.module === 'overview');
298
+ if (overview_doc) {
299
+ // 选中功能概览
300
+ state.selected_doc = overview_doc;
301
+ console.log('默认选中菜单:', state.selected_doc?.name);
302
+
303
+ // 设置默认展开的菜单
304
+ state.default_openeds = ['功能概览'];
305
+ } else {
306
+ // 找到core模块的第一个一级菜单对应的所有三级菜单
307
+ const core_module_docs = parsed_docs.filter(doc => doc.module === 'core');
308
+ if (core_module_docs.length > 0) {
309
+ // 选中第一个三级菜单
310
+ state.selected_doc = core_module_docs[0];
311
+ console.log('默认选中菜单:', state.selected_doc?.name);
312
+
313
+ // 设置默认展开的菜单
314
+ // 展开core模块菜单
315
+ state.default_openeds = ['Core 工具函数'];
316
+ // 找到对应的一级菜单ID并展开
317
+ if (core_module_docs[0].parentId) {
318
+ state.default_openeds.push(core_module_docs[0].parentId);
319
+ }
320
+ } else if (parsed_docs.length > 0) {
321
+ // 如果没有core模块的文档,选中第一个文档
322
+ state.selected_doc = parsed_docs[0];
323
+ console.log('默认选中菜单:', state.selected_doc?.name);
324
+
325
+ // 设置默认展开的菜单
326
+ const module_name = parsed_docs[0].module === 'hooks' ? 'Hooks 函数' : 'PC 组件';
327
+ state.default_openeds = [module_name];
328
+ }
329
+ }
330
+ }
331
+ }
332
+
333
+ /**
334
+ * 处理更新选中文档的事件
335
+ * @param event 自定义事件对象
336
+ */
337
+ const handle_update_selected_doc = (event: CustomEvent<{ id: string }>) => {
338
+ const doc_id = event.detail?.id;
339
+ if (doc_id) {
340
+ state.selected_doc = state.all_docs.find(doc => doc.id === doc_id) || null;
341
+ console.log('通过卡片点击选中文档:', state.selected_doc?.name);
342
+ }
343
+ };
344
+
345
+ /**
346
+ * 处理菜单选择事件
347
+ * @param node 选中的菜单节点
348
+ */
349
+ const handle_select = (node: ModuleChild): void => {
350
+ state.selected_doc = state.all_docs.find(doc => doc.id === node.id) || null;
351
+ };
352
+
353
+ /**
354
+ * 处理搜索选择事件
355
+ * @param event 自定义事件对象
356
+ */
357
+ const handle_search_select = (event: CustomEvent<{ id: string }>) => {
358
+ const doc_id = event.detail?.id;
359
+ if (doc_id) {
360
+ state.selected_doc = state.all_docs.find(doc => doc.id === doc_id) || null;
361
+ console.log('通过搜索选中文档:', state.selected_doc?.name);
362
+ }
363
+ };
364
+
365
+ /**
366
+ * 文档管理Hook
367
+ */
368
+ export function useDocs() {
369
+ /**
370
+ * Markdown渲染器
371
+ */
372
+ const md: any = new MarkdownIt({
373
+ html: true,
374
+ linkify: true,
375
+ highlight: function (str: string, lang: string) {
376
+ // 处理Vue相关的语言标记
377
+ if (lang === 'vue' || lang === 'template' || lang === 'vue-template') {
378
+ // 对于Vue代码,使用xml语言进行高亮
379
+ return hljs.highlight(str, { language: 'xml' }).value;
380
+ } else if (lang && hljs.getLanguage(lang)) {
381
+ try {
382
+ return hljs.highlight(str, { language: lang }).value;
383
+ } catch (__) {
384
+ // 如果高亮失败,返回原始代码
385
+ return md.utils.escapeHtml(str);
386
+ }
387
+ }
388
+ // 如果没有指定语言,返回原始代码
389
+ return md.utils.escapeHtml(str);
390
+ }
391
+ });
392
+
393
+ /**
394
+ * 渲染后的内容
395
+ */
396
+ const rendered_content = computed(() => {
397
+ if (!state.selected_doc) return '';
398
+ return md.render(state.selected_doc.content);
399
+ });
400
+
401
+ /**
402
+ * 树形数据
403
+ */
404
+ const tree_data = computed<ModuleData[]>(() => {
405
+ const modules = {
406
+ overview: { label: '功能概览', children: [] as ModuleChild[] },
407
+ core: { label: 'Core 工具函数', children: [] as ModuleChild[] },
408
+ hooks: { label: 'Hooks 函数', children: [] as ModuleChild[] },
409
+ pc_components: { label: 'PC 组件', children: [] as ModuleChild[] }
410
+ };
411
+
412
+ // 为core模块创建一级菜单和二级菜单结构
413
+ if (state.all_docs.length > 0) {
414
+ process_overview_module(modules);
415
+ process_core_module(modules);
416
+ process_hooks_module(modules);
417
+ process_pc_components_module(modules);
418
+ }
419
+
420
+ return Object.values(modules).filter(module => module.children.length > 0);
421
+ });
422
+
423
+ // 生命周期钩子
424
+ onMounted(() => {
425
+ try {
426
+ // 解析文档内容
427
+ const parsed_docs: DocItem[] = [];
428
+
429
+ // 解析 core 模块
430
+ const core_docs = parse_md_content(core_md, 'core');
431
+ parsed_docs.push(...core_docs);
432
+
433
+ // 解析 hooks 模块
434
+ const hooks_docs = parse_md_content(hooks_md, 'hooks');
435
+ parsed_docs.push(...hooks_docs);
436
+
437
+ // 解析 pc_components 模块
438
+ const pc_components_docs = parse_md_content(pc_components_md, 'pc_components');
439
+ parsed_docs.push(...pc_components_docs);
440
+
441
+ // 单独为功能概览生成内容(只显示名称)
442
+ const overview_id = guid();
443
+ const overview_content = generate_overview_content(core_docs, hooks_docs, pc_components_docs);
444
+
445
+ // 添加功能概览文档到 parsed_docs(单独解析,和其他菜单分开)
446
+ parsed_docs.unshift({
447
+ id: overview_id,
448
+ name: '功能概览',
449
+ description: '所有功能模块的概览',
450
+ module: 'overview',
451
+ type: 'overview',
452
+ content: overview_content,
453
+ path: '',
454
+ parentId: null
455
+ });
456
+
457
+ // 更新 all_docs
458
+ state.all_docs = parsed_docs;
459
+
460
+ // 设置默认选中的文档和展开的菜单
461
+ set_default_selection(parsed_docs);
462
+
463
+ // 监听更新选中文档的事件
464
+ on(window, 'update-selected-doc', handle_update_selected_doc as EventListener);
465
+ // 监听搜索选择事件
466
+ on(window, 'search-select', handle_search_select as EventListener);
467
+ } catch (error) {
468
+ console.error('Error loading documentation:', error);
469
+ }
470
+ });
471
+
472
+ // 组件卸载时清理事件监听器
473
+ onUnmounted(() => {
474
+ off(window, 'update-selected-doc', handle_update_selected_doc as EventListener);
475
+ off(window, 'search-select', handle_search_select as EventListener);
476
+ // 重置公共变量
477
+ reset_docs_variables();
478
+ });
479
+
480
+ /**
481
+ * 从文档内容中提取功能描述
482
+ * @param content 文档内容
483
+ * @param default_description 默认描述
484
+ * @returns 提取的功能描述
485
+ */
486
+ function extract_function_description(content: string, default_description: string): string {
487
+ if (!content) return default_description;
488
+
489
+ const lines = content.split('\n');
490
+ for (const line of lines) {
491
+ if (line.includes('**功能**: ')) {
492
+ const match = line.match(/\-\s*\*\*功能\*\*:\s*(.+)/);
493
+ if (match && match[1]) {
494
+ return match[1].trim();
495
+ }
496
+ }
497
+ }
498
+ return default_description;
499
+ }
500
+
501
+ /**
502
+ * 处理功能概览模块
503
+ * @param modules 模块数据对象
504
+ */
505
+ function process_overview_module(modules: Record<string, { label: string; children: ModuleChild[] }>): void {
506
+ const overview_doc = state.all_docs.find(doc => doc.module === 'overview');
507
+ if (overview_doc) {
508
+ modules.overview.children.push({
509
+ id: overview_doc.id,
510
+ label: overview_doc.name,
511
+ description: overview_doc.description
512
+ });
513
+ }
514
+ }
515
+
516
+ /**
517
+ * 处理core模块
518
+ * @param modules 模块数据对象
519
+ */
520
+ function process_core_module(modules: Record<string, { label: string; children: ModuleChild[] }>): void {
521
+ const core_module_docs = state.all_docs.filter(doc => doc.module === 'core');
522
+ if (core_module_docs.length > 0) {
523
+ // 按parentId分组
524
+ const parent_map = new Map<string, ModuleChild[]>();
525
+ core_module_docs.forEach(doc => {
526
+ if (doc.parentId) {
527
+ if (!parent_map.has(doc.parentId)) {
528
+ parent_map.set(doc.parentId, []);
529
+ }
530
+
531
+ const extracted_description = extract_function_description(doc.content, doc.description);
532
+ parent_map.get(doc.parentId)?.push({
533
+ id: doc.id,
534
+ label: doc.name,
535
+ description: extracted_description
536
+ });
537
+ }
538
+ });
539
+
540
+ // 为每个一级菜单创建子菜单
541
+ parent_map.forEach((children, parent_name) => {
542
+ modules.core.children.push({
543
+ id: guid(),
544
+ label: parent_name,
545
+ description: '',
546
+ children
547
+ });
548
+ });
549
+ }
550
+ }
551
+
552
+ /**
553
+ * 处理hooks模块
554
+ * @param modules 模块数据对象
555
+ */
556
+ function process_hooks_module(modules: Record<string, { label: string; children: ModuleChild[] }>): void {
557
+ const hooks_module_docs = state.all_docs.filter(doc => doc.module === 'hooks');
558
+ hooks_module_docs.forEach(doc => {
559
+ modules.hooks.children.push({
560
+ id: doc.id,
561
+ label: doc.name,
562
+ description: doc.description
563
+ });
564
+ });
565
+ }
566
+
567
+ /**
568
+ * 处理pc_components模块
569
+ * @param modules 模块数据对象
570
+ */
571
+ function process_pc_components_module(modules: Record<string, { label: string; children: ModuleChild[] }>): void {
572
+ const pc_components_module_docs = state.all_docs.filter(doc => doc.module === 'pc_components');
573
+ pc_components_module_docs.forEach(doc => {
574
+ modules.pc_components.children.push({
575
+ id: doc.id,
576
+ label: doc.name,
577
+ description: doc.description
578
+ });
579
+ });
580
+ }
581
+
582
+ /**
583
+ * 重置所有公共变量
584
+ */
585
+ function reset_docs_variables() {
586
+ state.search_query = '';
587
+ state.all_docs = [];
588
+ state.selected_doc = null;
589
+ state.default_openeds = [];
590
+ state.doc_content_map = {};
591
+ }
592
+
593
+ return {
594
+ state,
595
+ rendered_content,
596
+ tree_data,
597
+ handle_select,
598
+ reset_docs_variables
599
+ };
600
+ }
@@ -0,0 +1,30 @@
1
+ <script setup lang="ts">
2
+ import DocsHeader from './docs-header.vue';
3
+ import DocsSidebar from './docs-sidebar.vue';
4
+ import DocsContent from './docs-content.vue';
5
+ import { useDocs } from './hooks';
6
+
7
+ // 使用文档管理Hook
8
+ const { state, rendered_content, tree_data, handle_select } = useDocs();
9
+ </script>
10
+
11
+ <template>
12
+ <div class="docs-container">
13
+ <!-- 头部组件 -->
14
+ <DocsHeader v-model:searchQuery="state.search_query" :treeData="tree_data" />
15
+
16
+ <!-- 内容区 -->
17
+ <div class="docs-content">
18
+ <!-- 左侧文档列表组件 -->
19
+ <DocsSidebar :treeData="tree_data" :selectedDocId="state.selected_doc?.id" :defaultOpeneds="state.default_openeds"
20
+ @select="handle_select" />
21
+ <!-- 右侧文档详情组件 -->
22
+ <DocsContent :selectedDoc="state.selected_doc" :renderedContent="rendered_content" />
23
+ </div>
24
+
25
+ </div>
26
+ </template>
27
+
28
+ <style lang="scss" scoped>
29
+ @use './styles/index.scss';
30
+ </style>