From eaf07f190283e0603e35ea3e3f406bfad0b55bdd Mon Sep 17 00:00:00 2001 From: OpenClaw Date: Mon, 9 Mar 2026 15:22:45 +0800 Subject: [PATCH] feat: add ArkTS shell route placeholder flow --- .../ARKTS_ROUTE_PLACEHOLDER_FLOW_V0.md | 52 +++++++++++++++++ entry/src/main/ets/pages/AppListPage.ets | 14 ++++- entry/src/main/ets/pages/ImportPage.ets | 15 ++++- entry/src/main/ets/pages/RunPage.ets | 20 ++++++- entry/src/main/ets/pages/ShellRootPage.ets | 57 +++++++++++++++++++ 5 files changed, 152 insertions(+), 6 deletions(-) create mode 100644 docs/product/ARKTS_ROUTE_PLACEHOLDER_FLOW_V0.md create mode 100644 entry/src/main/ets/pages/ShellRootPage.ets diff --git a/docs/product/ARKTS_ROUTE_PLACEHOLDER_FLOW_V0.md b/docs/product/ARKTS_ROUTE_PLACEHOLDER_FLOW_V0.md new file mode 100644 index 0000000..4ef0960 --- /dev/null +++ b/docs/product/ARKTS_ROUTE_PLACEHOLDER_FLOW_V0.md @@ -0,0 +1,52 @@ +# ArkTS 最小路由占位与页面闭环草案 v0 + +项目:MRP 模拟器鸿蒙化 +角色:RD Frontend + +## 本轮完成 + +### 1. 新增 ShellRootPage +文件:`entry/src/main/ets/pages/ShellRootPage.ets` + +职责: +- 统一维护最小路由状态 +- 控制 3 个页面切换 +- 承接页面之间的回调跳转 + +当前路由: +- `appList` +- `import` +- `run` + +### 2. AppListPage 已支持路由回调 +新增: +- `onNavigateImport()` +- `onNavigateRun(appId)` + +### 3. ImportPage 已支持导入后回流 +新增: +- `onBack()` +- `onImportSuccess()` + +当前闭环: +- AppList -> Import +- Import 成功 -> AppList + +### 4. RunPage 已支持运行页回流 +新增: +- `appId` +- `onBack()` + +当前闭环: +- AppList -> Run +- Run 退出 -> AppList + +## 当前结论 +- 已从“页面占位”推进到“最小路由闭环占位” +- 当前路由仍为 ArkTS 壳层内管理,不依赖正式 Router 框架 +- 可继续作为 POC 页面流演示基线 + +## 下一步 +1. 让导入成功真正触发 AppList 刷新而不是仅返回 +2. 让列表中不可运行应用禁用点击 +3. 增加运行页 mock 启动中 -> 运行中状态过渡 diff --git a/entry/src/main/ets/pages/AppListPage.ets b/entry/src/main/ets/pages/AppListPage.ets index 48d4090..56435e4 100644 --- a/entry/src/main/ets/pages/AppListPage.ets +++ b/entry/src/main/ets/pages/AppListPage.ets @@ -6,9 +6,11 @@ import { StatusBanner } from '../components/common/StatusBanner' import { ImportEntryButton } from '../components/appList/ImportEntryButton' import { AppListView } from '../components/appList/AppListView' -@Entry @Component -struct AppListPage { +export struct AppListPage { + onNavigateImport?: () => void + onNavigateRun?: (appId: string) => void + @State refreshTick: number = 0 @State selectedAppId: string = '' private store: AppCatalogStore = new AppCatalogStore() @@ -31,11 +33,19 @@ struct AppListPage { } private openImportPage(): void { + if (this.onNavigateImport) { + this.onNavigateImport() + return + } console.info('TODO: open ImportPage') } private openRunPage(appId: string): void { this.selectedAppId = appId + if (this.onNavigateRun) { + this.onNavigateRun(appId) + return + } console.info(`TODO: open RunPage for ${appId}`) } diff --git a/entry/src/main/ets/pages/ImportPage.ets b/entry/src/main/ets/pages/ImportPage.ets index 02a5c39..5a6bbdc 100644 --- a/entry/src/main/ets/pages/ImportPage.ets +++ b/entry/src/main/ets/pages/ImportPage.ets @@ -8,6 +8,9 @@ import { ImportResultPanel } from '../components/import/ImportResultPanel' @Component export struct ImportPage { + onBack?: () => void + onImportSuccess?: () => void + @State refreshTick: number = 0 private store: ImportStore = new ImportStore() private unsubscribe?: () => void @@ -34,12 +37,20 @@ export struct ImportPage { private async onImport(): Promise { await this.store.startImport() + if (this.store.phase === 'success' && this.onImportSuccess) { + this.onImportSuccess() + } } build() { Column() { Text(`${this.refreshTick}`).fontSize(1).opacity(0) PageHeader({ title: '导入应用' }) + if (this.onBack) { + Button('返回列表').onClick(() => { + this.onBack && this.onBack() + }).margin({ bottom: 8, left: 16, right: 16 }) + } if (this.store.error) { StatusBanner({ text: this.store.error.message }) } @@ -48,13 +59,13 @@ export struct ImportPage { PackagePreviewCard({ name: this.store.previewInfo.name }) Button('开始导入').onClick(() => { this.onImport() - }) + }).margin(16) } if (this.store.phase === 'importing') { ImportProgressPanel({ text: '导入中' }) } if (this.store.phase === 'success') { - ImportResultPanel({ text: '导入成功' }) + ImportResultPanel({ text: '导入成功,正在返回列表' }) } if (this.store.phase === 'failed') { ImportResultPanel({ text: '导入失败' }) diff --git a/entry/src/main/ets/pages/RunPage.ets b/entry/src/main/ets/pages/RunPage.ets index 0bcafa4..5bb44df 100644 --- a/entry/src/main/ets/pages/RunPage.ets +++ b/entry/src/main/ets/pages/RunPage.ets @@ -8,6 +8,9 @@ import { RuntimeStatusOverlay } from '../components/runtime/RuntimeStatusOverlay @Component export struct RunPage { + appId?: string + onBack?: () => void + @State refreshTick: number = 0 private store: RuntimeSessionStore = new RuntimeSessionStore() private unsubscribe?: () => void @@ -18,6 +21,9 @@ export struct RunPage { this.refreshTick += 1 }) } + if (this.appId) { + this.store.startSession(this.appId) + } } aboutToDisappear(): void { @@ -27,7 +33,11 @@ export struct RunPage { } } - private onBack(): void { + private onBackClick(): void { + if (this.onBack) { + this.onBack() + return + } console.info('TODO: back to AppListPage') } @@ -37,17 +47,23 @@ export struct RunPage { private async onExit(): Promise { await this.store.stopSession() + if (this.onBack) { + this.onBack() + } } build() { Column() { Text(`${this.refreshTick}`).fontSize(1).opacity(0) PageHeader({ title: '运行页' }) + if (this.appId) { + StatusBanner({ text: `当前应用:${this.appId}` }) + } if (this.store.error) { StatusBanner({ text: this.store.error.message }) } RuntimeToolbar({ - onBack: () => this.onBack(), + onBack: () => this.onBackClick(), onRestart: () => this.onRestart(), onExit: () => this.onExit() }) diff --git a/entry/src/main/ets/pages/ShellRootPage.ets b/entry/src/main/ets/pages/ShellRootPage.ets new file mode 100644 index 0000000..b1e54d2 --- /dev/null +++ b/entry/src/main/ets/pages/ShellRootPage.ets @@ -0,0 +1,57 @@ +import { AppListPage } from './AppListPage' +import { ImportPage } from './ImportPage' +import { RunPage } from './RunPage' + +export type ShellRoute = 'appList' | 'import' | 'run' + +@Entry +@Component +struct ShellRootPage { + @State currentRoute: ShellRoute = 'appList' + @State currentAppId: string = '' + @State catalogRefreshTick: number = 0 + + private goToImport(): void { + this.currentRoute = 'import' + } + + private goToRun(appId: string): void { + this.currentAppId = appId + this.currentRoute = 'run' + } + + private backToList(): void { + this.currentRoute = 'appList' + } + + private backToListAfterImport(): void { + this.catalogRefreshTick += 1 + this.currentRoute = 'appList' + } + + build() { + Column() { + Text(`${this.catalogRefreshTick}`).fontSize(1).opacity(0) + if (this.currentRoute === 'appList') { + AppListPage({ + onNavigateImport: () => this.goToImport(), + onNavigateRun: (appId: string) => this.goToRun(appId) + }) + } + if (this.currentRoute === 'import') { + ImportPage({ + onBack: () => this.backToList(), + onImportSuccess: () => this.backToListAfterImport() + }) + } + if (this.currentRoute === 'run') { + RunPage({ + appId: this.currentAppId, + onBack: () => this.backToList() + }) + } + } + .width('100%') + .height('100%') + } +}