在 Microsoft Fabric 中,您可以使用多任務同時開啟多個專案。 當您開啟項目時,標籤頁會固定到左窗格。 根據預設,Fabric 支援一次開啟一個專案。 當項目分頁被初始化、停用及銷毀時,會觸發一組生命周期事件,而不需要涉及任何工作負載的操作。
變更預設的多任務屬性
editorTab 定義項目清單內的區段,用於編輯索引標籤屬性:
"editorTab": {
}
啟用同時開啟多個項目的功能
定義 maxInstanceCount 屬性,並指派您要同時開啟的項目數目(最多可開十個項目):
"editorTab": {
"maxInstanceCount": "10"
}
自定義動作和處理程式
當您決定實作索引標籤動作和相關處理程式(或其中一部分)時,需要在專案的前端指令清單中設定editorTab區段的屬性。 該屬性會在自己的程式代碼中接聽這些動作、據以處理動作,並傳回結果。 如果您未設定任何動作(或其中一部分),則會自動處理預設動作。
在 editorTab 區段中定義索引標籤動作的屬性:
"editorTab": {
"onInit": "item.tab.onInit",
"onDeactivate": "item.tab.onDeactivate",
"canDeactivate": "item.tab.canDeactivate",
"canDestroy": "item.tab.canDestroy",
"onDestroy": "item.tab.onDestroy",
"onDelete": "item.tab.onDelete"
}
當您註冊工作負載動作時,Fabric 預期動作會以特定格式傳回數據,讓 Fabric 可以讀取或顯示該資訊:
/*An OnInit event is triggered when the item is opened for the first
time. This event contains the ID of the tab being initialized. Based on
this tab ID, the handler needs to be able to return the display name
or metadata.*/
onInit: Action<never>;
/*A CanDeactivate event is triggered when the user moves away from the tab.
This event contains the ID of the tab being deactivated. The
CanDeactivate handler should return a Boolean value that indicates whether
the item tab can be deactivated. For an ideal multitasking experience,
the handler should always return True.*/
canDeactivate: Action<never>;
/*An OnDeactivate event is triggered immediately after CanDeactivate
returns True. This event contains the ID of the tab being deactivated.
The OnDeactivate handler should cache unsaved item changes and
the UI state.
The next time the user goes back to the item, the item needs
to be able to recover its data and UI state. The actual deactivation begins
only when this handler returns.*/
onDeactivate: Action<never>;
/*A CanDestroy event is triggered after the close button is selected,
before the item tab is closed. The event contains the ID of the tab
being destroyed and also an allowInteraction parameter.
The CanDeactivate handler should return a Boolean value that indicates
whether the given item tab can be destroyed.
If allowInteraction equals False, the implementation returns True
if there are no dirty changes, and False otherwise.
If allowInteraction equals True, a pop-up window can be used to ask
for the user's opinion. It returns True if the user saves or discards
dirty changes, and False if the user cancels the pop-up window.
The OnDestroy handler gives the item the opportunity to do some
cleanup work.*/
canDestroy: Action<never>;
/*An OnDestroy event is triggered when the tab is closed. The event
contains the ID of the tab being destroyed. The OnDestroy handler gives
the item the opportunity to do some cleanup work.*/
onDestroy: Action<never>;
/*An OnDelete event is triggered when the opened item is deleted.
The event contains the ID of the item being deleted, just to tell
the extension that the current item is deleted.*/
onDelete: Action<never>;
處理索引標籤動作的範例
此範例會接聽所有與 item.tab 相關動作,並據以處理每個動作:
workloadClient.action.onAction(async function ({ action, data }) {
switch (action) {
case 'item.tab.onInit':
const { id } = data as ItemTabActionContext;
try{
const getItemResult = await callItemGet(
id,
workloadClient
);
const item = convertGetItemResultToWorkloadItem<ItemPayload(getItemResult);
return {title: item.displayName};
} catch (error) {
console.error(
`Error loading the Item (object ID:${id})`,
error
);
return {};
}
case 'item.tab.canDeactivate':
return { canDeactivate: true };
case 'item.tab.onDeactivate':
return {};
case 'item.tab.canDestroy':
return { canDestroy: true };
case 'item.tab.onDestroy':
return {};
case 'item.tab.onDelete':
return {};
default:
throw new Error('Unknown action received');
}
});
-
item.tab.onInit:使用ID擷取物件數據,並傳回項目的標題。 -
item.tab.canDeactivate:傳回{ canDeactivate: true },可讓您輕鬆地在索引標籤之間切換。 -
item.tab.onDeactivate、item.tab.onDestroy、item.tab.onDelete:傳回空白物件以表示這些動作。 -
item.tab.canDestroy:傳回{ canDestroy: true }。
相關內容
如需處理索引標籤動作的完整範例,請參閱index.ui.ts範例存放庫中的 。 搜尋以item.tab開頭的動作。