ad00f5c195
Update documentation to show that simple pages can define page models directly in views without creating a page driver. Adjust examples, section numbering, and naming guidance to better distinguish simple view state from reusable page-driver patterns.docs: clarify optional page drivers in page guide Update documentation to show that simple pages can define page models directly in views without creating a page driver. Adjust examples, section numbering, and naming guidance to better distinguish simple view state from reusable page-driver patterns.
1.4 KiB
1.4 KiB
Models Guide
models 放 domain model 與 page model 型別定義。model 只定義形狀(interface/type),不含業務邏輯、API 呼叫或 UI 狀態。
種類
- Domain Model:特定領域的資料型別,例如
StudentRecord。檔名用 domain 命名(student.ts),型別使用 domain 前綴。 - Page Model:
page.ts定義頁面驅動資料的 union type,供 page driver 組裝後傳給 page component。例如BasePageModel、MaintenancePageModel。
規則
- 用 interface 或 type,不加 class。
- domain model 應與 service response / store state 共用型別來源。
- page model 僅定義畫面需要的欄位,不鏡像整個 service response。
- 不 import component、view、store、composable。
- 型別 export 時明確命名,避免與其他層混淆。
Page Model 慣例
src/models/page.ts 定義基礎型別與 union:
BasePageModel:所有頁面共用欄位(title、loading、error)。- 各頁面的 specific model 擴展
BasePageModel(例如MaintenancePageModel加type、records)。 PageModelunion 供 page component props 型別使用。
新增頁面類型時,先擴充 PageModel union。若頁面需要協調多個 composable(搜尋、表單、CRUD flow、dialog 狀態),再建立對應的 page driver;簡單頁面直接在 view 用 computed 組裝 page model 即可。