@idooel/components 0.0.2-beta.29 → 0.0.2-beta.30

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.
@@ -0,0 +1,172 @@
1
+ # Utils 工具库目录结构
2
+
3
+ ## 📁 目录结构
4
+
5
+ ```
6
+ utils/
7
+ ├── README.md # 本说明文档
8
+ ├── index.js # 工具库主入口,导出所有工具和常量
9
+ └── runtime-context/ # Runtime Context 数据池模块
10
+ ├── index.js # 统一导出入口
11
+ ├── globalDataPool.js # 全局数据池核心架构
12
+ ├── dataPoolAPI.js # 统一的数据池 API 接口
13
+ └── modelSchema.js # 模型字段定义和类型验证
14
+ ```
15
+
16
+ ## 🚀 使用方式
17
+
18
+ ### 1. 传统工具(常量和函数)
19
+
20
+ ```javascript
21
+ import {
22
+ NAMESPACE,
23
+ CONTEXT,
24
+ BUILT_IN_EVENT_NAMES,
25
+ parseFieldMap
26
+ } from '@/utils'
27
+
28
+ // 使用常量和工具函数
29
+ const context = CONTEXT
30
+ const fieldMap = parseFieldMap(fieldMapConfig, dataSource)
31
+ ```
32
+
33
+ ### 2. Runtime Context 数据池
34
+
35
+ ```javascript
36
+ // 直接导入(推荐)
37
+ import { createTreeTableModel, createDataPoolAPI } from '@/utils/runtime-context'
38
+
39
+ // 使用示例
40
+ const model = createTreeTableModel('my-table')
41
+ const api = createDataPoolAPI()
42
+ ```
43
+
44
+ ### 3. TreeTable 模型(推荐用法)
45
+
46
+ ```javascript
47
+ import { createTreeTableModel } from '@/utils/runtime-context'
48
+
49
+ // 创建 TreeTable 模型实例
50
+ const model = createTreeTableModel('tree-table-instance')
51
+
52
+ // 使用模型方法
53
+ model.setCurrentRowData({ id: 1, name: '测试数据' })
54
+ const currentRow = model.getCurrentRowData()
55
+
56
+ // 订阅数据变化
57
+ model.subscribe('currentRowData', (event) => {
58
+ console.log('数据变化:', event.value)
59
+ })
60
+
61
+ // 设置共享数据(用于 modal table)
62
+ model.setSharedData({ parentData: '父级数据' })
63
+ ```
64
+
65
+ ### 4. 模型字段定义
66
+
67
+ ```javascript
68
+ import { TREE_TABLE_FIELDS, getSupportedFields, getFieldDefinition } from '@/utils/runtime-context'
69
+
70
+ // 查看支持的字段
71
+ console.log('支持的字段:', getSupportedFields()) // ['currentRowData']
72
+
73
+ // 查看字段定义
74
+ console.log('currentRowData 字段定义:', getFieldDefinition('currentRowData'))
75
+ // 输出: { type: 'object', default: {}, description: '当前表格选中的行数据' }
76
+
77
+ // 字段会在模型创建时自动初始化为默认值
78
+ const model = createTreeTableModel('my-table')
79
+ console.log(model.getCurrentRowData()) // {} (默认值)
80
+ ```
81
+
82
+ ## 📋 模块说明
83
+
84
+ ### Runtime Context 模块
85
+
86
+ 新一代的数据池管理系统,基于 `@idooel/runtime-context` 构建:
87
+
88
+ - **globalDataPool.js**: 核心架构,挂载到 `window.__idooel_data_pool__`
89
+ - **dataPoolAPI.js**: 统一的 API 接口,提供简洁易用的方法
90
+ - **modelSchema.js**: 模型字段定义和类型验证
91
+
92
+ ### 传统工具
93
+
94
+ 保持向后兼容的工具和常量:
95
+
96
+ - **index.js**: 常量定义和工具函数
97
+
98
+ ## 🔄 迁移指南
99
+
100
+ ### 从旧版数据池迁移
101
+
102
+ ```javascript
103
+ // 旧版 TreeTableDataPoolManager(已弃用)
104
+ import { createPoolManager, generateInstanceId } from '@/utils/treeTableDataPoolManager'
105
+
106
+ // 新版 runtime-context(推荐)
107
+ import { createTreeTableModel } from '@/utils/runtime-context'
108
+ const model = createTreeTableModel('instance-id')
109
+ ```
110
+
111
+ ### TreeTable 组件迁移
112
+
113
+ ✅ **已完成迁移** - 组件已从 TreeTableDataPoolManager 迁移到新的 runtime-context 架构:
114
+
115
+ ```javascript
116
+ // 新版用法(已实现)
117
+ import { createTreeTableModel } from '@/utils/runtime-context'
118
+
119
+ export default {
120
+ async created() {
121
+ // 确保全局数据池已初始化
122
+ if (!window.__idooel_data_pool__) {
123
+ console.error('Global data pool not initialized')
124
+ return
125
+ }
126
+
127
+ // 创建 TreeTable 模型实例
128
+ this.model = createTreeTableModel('treeTableModel')
129
+
130
+ // 使用模型方法
131
+ this.model.setCurrentRowData({ id: 1, name: '测试数据' })
132
+ const currentRow = this.model.getCurrentRowData()
133
+
134
+ // 订阅数据变化
135
+ this.unsubscribe = this.model.subscribe('currentRowData', (event) => {
136
+ this.currentRowData = event.value
137
+ this.$forceUpdate()
138
+ })
139
+ },
140
+
141
+ beforeDestroy() {
142
+ // 清理订阅
143
+ if (this.unsubscribe) this.unsubscribe()
144
+ if (this.model) this.model.cleanup()
145
+ }
146
+ }
147
+ ```
148
+
149
+ ## 🛠️ 开发建议
150
+
151
+ 1. **新项目**: 直接使用 `runtime-context` 模块
152
+ 2. **已迁移项目**: 使用新的 `createTreeTableModel` API
153
+ 3. **初始化检查**: 组件中检查 `window.__idooel_data_pool__` 确保数据池已初始化
154
+ 4. **错误处理**: 使用 try-catch 包裹模型创建,添加安全检查
155
+ 5. **共享数据**: 使用简单的 `setSharedData()` 和 `getSharedData()` 方法
156
+ 6. **调试**: 使用 `window.__idooel_data_pool__.manager.debug()` 查看状态
157
+ 7. **批量操作**: 使用 `setBatchModelData` 提高效率
158
+ 8. **数据管理**: 使用 `export/import` 方法进行数据备份和恢复
159
+ 9. **内存管理**: 在组件销毁时正确清理订阅和模型数据
160
+
161
+ ## ⚠️ 注意事项
162
+
163
+ - **初始化顺序**: 确保 `runtime-context` 模块在使用前已导入
164
+ - **错误处理**: 组件应处理模型创建失败的情况
165
+ - **清理工作**: 组件销毁时必须清理订阅和模型,避免内存泄漏
166
+ - **向后兼容**: 旧的 `TreeTableDataPoolManager` 已弃用,请使用新的 API
167
+
168
+ ## 📚 相关文档
169
+
170
+ - [API 接口文档](./runtime-context/dataPoolAPI.js)
171
+ - [全局数据池架构](./runtime-context/globalDataPool.js)
172
+ - [模型字段定义](./runtime-context/modelSchema.js)