refactor: simplify page models and view driver usage

Move simple page models into page components and build trivial computed
models directly in views to avoid unnecessary page drivers. Update views
to destructure page driver returns and rely on template ref unwrapping,
and document the guidance for when page drivers should be introduced.refactor: simplify page models and view driver usage

Move simple page models into page components and build trivial computed
models directly in views to avoid unnecessary page drivers. Update views
to destructure page driver returns and rely on template ref unwrapping,
and document the guidance for when page drivers should be introduced.
This commit is contained in:
skytek_xinliang
2026-05-27 11:10:34 +08:00
parent 799b16578d
commit b8664b5c3e
19 changed files with 139 additions and 220 deletions
+13 -4
View File
@@ -22,14 +22,23 @@
## Page Driver
Page driver 負責
Page driver 只應在「需要協調多個 composable / store / route」時才成立。若頁面邏輯只有
- 組裝一個 `computed` page model3-5 個欄位)
- 沒有搜尋、沒有 dialog、沒有複雜事件
則**不要建立 page driver**,直接在 view 裡寫 `computed` 即可。
當需要 page driver 時,它負責:
- route param/query 轉成頁面資料
- 組裝 page model
- 組裝 page component 需要的 props/events
- 協調 store、command composable、表單 composable
- 組裝 page component 需要的 props/events
View 只呼叫 page driver 並掛載 page component。
View 以 destructure 方式取用 page driver 回傳值:
```ts
const { pageModel, search, handleSubmit } = useXxxPage()
```
模板中直接使用,不寫 `.value``:page="pageModel"``v-model="search"`
## Commands