(schema?: IPublicTypeProjectSchema, autoOpen?: boolean | string)
| 207 | */ |
| 208 | @action |
| 209 | load(schema?: IPublicTypeProjectSchema, autoOpen?: boolean | string) { |
| 210 | this.unload(); |
| 211 | // load new document |
| 212 | this.data = { |
| 213 | version: '1.0.0', |
| 214 | componentsMap: [], |
| 215 | componentsTree: [], |
| 216 | i18n: {}, |
| 217 | ...schema, |
| 218 | }; |
| 219 | this.config = schema?.config || this.config; |
| 220 | this.i18n = schema?.i18n || this.i18n; |
| 221 | |
| 222 | if (autoOpen) { |
| 223 | if (autoOpen === true) { |
| 224 | // auto open first document or open a blank page |
| 225 | // this.open(this.data.componentsTree[0]); |
| 226 | const documentInstances = this.data.componentsTree.map((data) => this.createDocument(data)); |
| 227 | // TODO: 暂时先读 config tabBar 里的值,后面看整个 layout 结构是否能作为引擎规范 |
| 228 | if (this.config?.layout?.props?.tabBar?.items?.length > 0) { |
| 229 | // slice(1) 这个贼不雅,默认任务 fileName 是类'/fileName'的形式 |
| 230 | documentInstances |
| 231 | .find((i) => i.fileName === this.config.layout.props.tabBar.items[0].path?.slice(1)) |
| 232 | ?.open(); |
| 233 | } else { |
| 234 | documentInstances[0].open(); |
| 235 | } |
| 236 | } else { |
| 237 | // auto open should be string of fileName |
| 238 | this.open(autoOpen); |
| 239 | } |
| 240 | } |
| 241 | } |
| 242 | |
| 243 | /** |
| 244 | * 卸载当前项目数据 |
no test coverage detected