# tag（標籤）

```javascript
// 取得所有標籤
const tags = await eagle.tag.get();

// 按名稱篩選標籤
const designTags = await eagle.tag.get({ name: "design" });

// 取得最近使用標籤
const recents = await eagle.tag.getRecentTags();

// 取得常用標籤
const starred = await eagle.tag.getStarredTags();
```

## 方法 <a href="#z1a5y" id="z1a5y"></a>

## get(options) <a href="#x9nu2" id="x9nu2"></a>

取得標籤，可透過選項進行篩選。

* `options` Object (可選) - 查詢條件
  * `name` string (可選) - 按標籤名稱進行模糊搜尋，不區分大小寫
* 返回 `Promise<tags: Object[]>` - tags 查詢結果。

```javascript
// 取得所有標籤
const tags = await eagle.tag.get();

// 按名稱篩選標籤
const filteredTags = await eagle.tag.get({
    name: "design"
});
```

{% hint style="info" %}
提示：`name` 參數需要 Eagle 4.0 build12 以上版本支援。
{% endhint %}

***

## getRecentTags() <a href="#dwsxw" id="dwsxw"></a>

取得最近使用的標籤。

* 返回 `Promise<tags: Object[]>` - tags 查詢結果。

```javascript
const recents = await eagle.tag.getRecentTags();
```

***

## getStarredTags() <a href="#starred" id="starred"></a>

取得常用標籤（使用者收藏的標籤）。

* 返回 `Promise<tags: Object[]>` - tags 查詢結果。

```javascript
const starred = await eagle.tag.getStarredTags();
```

{% hint style="info" %}
提示：`getStarredTags()` 方法需要 Eagle 4.0 build18 以上版本支援。
{% endhint %}

***

## merge(options) <a href="#merge" id="merge"></a>

合併標籤：將來源標籤重新命名為目標標籤，所有使用來源標籤的素材都會自動更新。

* `options` Object - 選項參數
  * `source` string - 來源標籤名稱（將被移除）
  * `target` string - 目標標籤名稱（合併後保留）
* 返回 `Promise<Object>` - 合併結果
  * `affectedItems` number - 受影響的素材數量
  * `sourceRemoved` boolean - 來源標籤是否已移除

```javascript
// 將所有 "UI Design" 標籤合併為 "UI"
const result = await eagle.tag.merge({
    source: 'UI Design',
    target: 'UI'
});

console.log(`已合併 ${result.affectedItems} 個素材的標籤`);
```

{% hint style="info" %}
提示：`merge()` 方法需要 Eagle 4.0 build18 以上版本支援。
{% endhint %}

{% hint style="warning" %}
注意：合併操作會更新所有使用來源標籤的素材、標籤群組、收藏標籤和歷史標籤。此操作不可逆。
{% endhint %}

***

## 類別：Tag <a href="#tag-class" id="tag-class"></a>

由 Eagle API `get` 返回的 Object 類型，提供修改、保存功能。

{% hint style="success" %}
**🦄 最佳實踐：** 為了確保資料安全性，請使用 Tag 實例提供的 `save()` 方法進行資料的修改，應避免直接修改 Eagle 資源庫底下的標籤資料。
{% endhint %}

***

### 實例方法 <a href="#instance-methods" id="instance-methods"></a>

#### **save()**

保存標籤的修改。目前僅支援修改標籤名稱。

* 返回 `Promise<result: boolean>` - `result` 是否修改成功

```javascript
// 取得所有標籤
const tags = await eagle.tag.get();

// 找到要修改的標籤
const tag = tags.find(t => t.name === 'old-name');

// 修改標籤名稱
tag.name = 'new-name';

// 保存修改
await tag.save();
```

{% hint style="info" %}
提示：`save()` 方法需要 Eagle 4.0 build12 以上版本支援。
{% endhint %}

{% hint style="warning" %}
注意：修改標籤名稱後，所有使用該標籤的檔案都會自動更新為新的標籤名稱。
{% endhint %}

***

### 實例屬性 <a href="#instance-properties" id="instance-properties"></a>

#### **`name` string**

標籤名稱。可修改此屬性並透過 `save()` 方法保存。

#### **`count` number**

唯讀，使用此標籤的檔案數量。

#### **`color` string**

標籤顏色。

#### **`groups` string\[]**

唯讀，標籤所屬的分組。

#### **`pinyin` string**

唯讀，標籤名稱的拼音（用於搜尋和排序）。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://developer.eagle.cool/plugin-api/zh-tw/api/tag.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
