feat: add ArkTS shell route placeholder flow
This commit is contained in:
1 parent
04cb1178dd
commit
eaf07f1902
5 files changed
+152
-6
No files matched your search
@@ -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 启动中 -> 运行中状态过渡
|
||||||
@@ -6,9 +6,11 @@ import { StatusBanner } from '../components/common/StatusBanner'
|
|||||||
import { ImportEntryButton } from '../components/appList/ImportEntryButton'
|
import { ImportEntryButton } from '../components/appList/ImportEntryButton'
|
||||||
import { AppListView } from '../components/appList/AppListView'
|
import { AppListView } from '../components/appList/AppListView'
|
||||||
|
|
||||||
@Entry
|
|
||||||
@Component
|
@Component
|
||||||
struct AppListPage {
|
export struct AppListPage {
|
||||||
|
onNavigateImport?: () => void
|
||||||
|
onNavigateRun?: (appId: string) => void
|
||||||
|
|
||||||
@State refreshTick: number = 0
|
@State refreshTick: number = 0
|
||||||
@State selectedAppId: string = ''
|
@State selectedAppId: string = ''
|
||||||
private store: AppCatalogStore = new AppCatalogStore()
|
private store: AppCatalogStore = new AppCatalogStore()
|
||||||
@@ -31,11 +33,19 @@ struct AppListPage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private openImportPage(): void {
|
private openImportPage(): void {
|
||||||
|
if (this.onNavigateImport) {
|
||||||
|
this.onNavigateImport()
|
||||||
|
return
|
||||||
|
}
|
||||||
console.info('TODO: open ImportPage')
|
console.info('TODO: open ImportPage')
|
||||||
}
|
}
|
||||||
|
|
||||||
private openRunPage(appId: string): void {
|
private openRunPage(appId: string): void {
|
||||||
this.selectedAppId = appId
|
this.selectedAppId = appId
|
||||||
|
if (this.onNavigateRun) {
|
||||||
|
this.onNavigateRun(appId)
|
||||||
|
return
|
||||||
|
}
|
||||||
console.info(`TODO: open RunPage for ${appId}`)
|
console.info(`TODO: open RunPage for ${appId}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import { ImportResultPanel } from '../components/import/ImportResultPanel'
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
export struct ImportPage {
|
export struct ImportPage {
|
||||||
|
onBack?: () => void
|
||||||
|
onImportSuccess?: () => void
|
||||||
|
|
||||||
@State refreshTick: number = 0
|
@State refreshTick: number = 0
|
||||||
private store: ImportStore = new ImportStore()
|
private store: ImportStore = new ImportStore()
|
||||||
private unsubscribe?: () => void
|
private unsubscribe?: () => void
|
||||||
@@ -34,12 +37,20 @@ export struct ImportPage {
|
|||||||
|
|
||||||
private async onImport(): Promise<void> {
|
private async onImport(): Promise<void> {
|
||||||
await this.store.startImport()
|
await this.store.startImport()
|
||||||
|
if (this.store.phase === 'success' && this.onImportSuccess) {
|
||||||
|
this.onImportSuccess()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column() {
|
||||||
Text(`${this.refreshTick}`).fontSize(1).opacity(0)
|
Text(`${this.refreshTick}`).fontSize(1).opacity(0)
|
||||||
PageHeader({ title: '导入应用' })
|
PageHeader({ title: '导入应用' })
|
||||||
|
if (this.onBack) {
|
||||||
|
Button('返回列表').onClick(() => {
|
||||||
|
this.onBack && this.onBack()
|
||||||
|
}).margin({ bottom: 8, left: 16, right: 16 })
|
||||||
|
}
|
||||||
if (this.store.error) {
|
if (this.store.error) {
|
||||||
StatusBanner({ text: this.store.error.message })
|
StatusBanner({ text: this.store.error.message })
|
||||||
}
|
}
|
||||||
@@ -48,13 +59,13 @@ export struct ImportPage {
|
|||||||
PackagePreviewCard({ name: this.store.previewInfo.name })
|
PackagePreviewCard({ name: this.store.previewInfo.name })
|
||||||
Button('开始导入').onClick(() => {
|
Button('开始导入').onClick(() => {
|
||||||
this.onImport()
|
this.onImport()
|
||||||
})
|
}).margin(16)
|
||||||
}
|
}
|
||||||
if (this.store.phase === 'importing') {
|
if (this.store.phase === 'importing') {
|
||||||
ImportProgressPanel({ text: '导入中' })
|
ImportProgressPanel({ text: '导入中' })
|
||||||
}
|
}
|
||||||
if (this.store.phase === 'success') {
|
if (this.store.phase === 'success') {
|
||||||
ImportResultPanel({ text: '导入成功' })
|
ImportResultPanel({ text: '导入成功,正在返回列表' })
|
||||||
}
|
}
|
||||||
if (this.store.phase === 'failed') {
|
if (this.store.phase === 'failed') {
|
||||||
ImportResultPanel({ text: '导入失败' })
|
ImportResultPanel({ text: '导入失败' })
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ import { RuntimeStatusOverlay } from '../components/runtime/RuntimeStatusOverlay
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
export struct RunPage {
|
export struct RunPage {
|
||||||
|
appId?: string
|
||||||
|
onBack?: () => void
|
||||||
|
|
||||||
@State refreshTick: number = 0
|
@State refreshTick: number = 0
|
||||||
private store: RuntimeSessionStore = new RuntimeSessionStore()
|
private store: RuntimeSessionStore = new RuntimeSessionStore()
|
||||||
private unsubscribe?: () => void
|
private unsubscribe?: () => void
|
||||||
@@ -18,6 +21,9 @@ export struct RunPage {
|
|||||||
this.refreshTick += 1
|
this.refreshTick += 1
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
if (this.appId) {
|
||||||
|
this.store.startSession(this.appId)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
aboutToDisappear(): void {
|
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')
|
console.info('TODO: back to AppListPage')
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,17 +47,23 @@ export struct RunPage {
|
|||||||
|
|
||||||
private async onExit(): Promise<void> {
|
private async onExit(): Promise<void> {
|
||||||
await this.store.stopSession()
|
await this.store.stopSession()
|
||||||
|
if (this.onBack) {
|
||||||
|
this.onBack()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
build() {
|
build() {
|
||||||
Column() {
|
Column() {
|
||||||
Text(`${this.refreshTick}`).fontSize(1).opacity(0)
|
Text(`${this.refreshTick}`).fontSize(1).opacity(0)
|
||||||
PageHeader({ title: '运行页' })
|
PageHeader({ title: '运行页' })
|
||||||
|
if (this.appId) {
|
||||||
|
StatusBanner({ text: `当前应用:${this.appId}` })
|
||||||
|
}
|
||||||
if (this.store.error) {
|
if (this.store.error) {
|
||||||
StatusBanner({ text: this.store.error.message })
|
StatusBanner({ text: this.store.error.message })
|
||||||
}
|
}
|
||||||
RuntimeToolbar({
|
RuntimeToolbar({
|
||||||
onBack: () => this.onBack(),
|
onBack: () => this.onBackClick(),
|
||||||
onRestart: () => this.onRestart(),
|
onRestart: () => this.onRestart(),
|
||||||
onExit: () => this.onExit()
|
onExit: () => this.onExit()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -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%')
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user