Skip to content

ChannelNav 频道导航 ​

模板标签:<qtx-channel-nav>

一级频道导航组件,只负责「可见的频道栏」。它是 @QtComponent 原生桥接组件加一层 Vue 薄壳:频道项的创建、复用、三态绘制、焦点跟随滚动居中全部由 native 侧的 RecyclerView 闭环完成,上层不需要自己拼列表或包滚动容器。

内容区切换请使用 qtx-tabs;本组件不渲染内容、不管理路由与页面缓存。两边写同名 linkId 可让它们在 native 层成对,由焦点直接驱动内容区切换(见底层联动)。完整 API 见 API 页,本页只写使用语义,不复制事实表。

整栏尺寸由 width / height 决定,频道序列在整栏里的位置由 align / crossAlign 决定,频道项自身尺寸与间距由 itemWidth / itemHeight / gap / itemPadding / iconMargin 决定,gravity 只改频道项内部「图标 + 文字」这组内容的对齐。四组属性互不干扰,详见整栏尺寸与对齐。

默认视觉(不写任何样式 props) ​

不传任何颜色 / 对齐属性时,频道栏就是国内 TV 首页常见的居中胶囊风格,文字默认粗体:

状态背景文字
普通(未选中、未获焦)透明灰白 #C2CAD4(非纯白)
获焦(含当前频道重新获焦)白色圆角胶囊 #FFFFFF,36px 圆角近黑 #141922
选中但未获焦透明纯白 #FFFFFF
禁用透明,整体 55% 不透明度#5A6675
  • 焦点优先于选中:当前频道重新获焦时看到的是白色胶囊 + 黑字,不是选中色块。
  • 默认 align="center" / crossAlign="center" / gravity="center",整组频道与项内文字都居中。
  • 默认不描边(focusBorderWidth=0),白色焦点底本身就是强指示。需要描边或彩色选中块时,用 focusBg / selectedBg / focusBorderWidth 等 props 逐项覆盖。
  • 焦点态只切换底色与字色,不提供焦点缩放动画。

默认间距(开箱即用) ​

不写任何尺寸 / 间距 props 时的取值,按「带图标 + 4~6 字频道名、焦点胶囊不粘连」给过,可直接用于上线页面:

属性默认值作用
itemWidth / itemHeight240 / 72单项宽高;240 足够容纳 32px 图标与「本地目录」「WebDAV」一类频道名,不出现省略号
gap24相邻频道项间距,约为频道项高度的 1/3
itemPadding16项内容区四边内边距,图标不贴边
iconSize / iconMargin32 / 16图标尺寸与图标到文字的固定留白
fontSize / borderRadius28 / 36粗体字与胶囊圆角

图标与文字作为一组按 gravity 摆在项内,因此两者之间的留白恒等于 iconMargin,不会随文案长短变化;最后一项不留尾间距,align 的居中 / 等距计算与真实绘制一致。需要更紧凑的排版再逐项覆盖,例如 :itemWidth="180" :gap="16"。

适用场景 ​

  • 国内 TV 应用首页的顶部频道栏(横排、胶囊选中态)与左侧频道栏(竖排、图标加文字)。
  • 需要与 qtx-tabs 保持同一套 active 值、由使用方统一驱动内容区切换的页面;写同名 linkId 后可由 native 直接驱动切换。
  • 频道数量较多、超出一屏且要求焦点项自动保持可见的 10-foot 界面。
  • 只有 3~6 个频道、但栏宽铺满整屏,需要把整组频道居左 / 居中 / 居右 / 两端对齐 / 等距分布。
  • 横排频道栏需要在垂直方向靠上 / 居中 / 靠下,或竖排频道栏需要在水平方向靠左 / 居中 / 靠右。

不适用场景 ​

  • 长列表逐行渲染:频道数量有限且顺序固定,长列表应使用内置 item 风格包与复用池。
  • 二级筛选、内容区、页面缓存、路由跳转:这些归 qtx-tabs 或使用方。
  • 频道栏与内容网格绑成一体容器的场景:内部隐藏组件不在本组件职责内。
  • 频道总尺寸已经超过整栏:此时 align / crossAlign 不生效,组件自动退回滚动居中;不要为了「对齐」再套一层滚动容器或改外层布局。

Web 演示 ​

Web 演示浏览器模拟演示 · TV 真机行为以实机为准
浏览器模拟演示 · TV 真机行为以实机为准
首页
电视剧
综艺
电影
少儿
纪录片
受控 active
home
焦点项
(未进入频道栏)
布局
horizontal
三态说明
普通焦点选中选中 + 焦点
选中底色与焦点描边正交叠加:焦点移回当前频道时,选中态不会消失。
最近事件:—

示例 ​

vue
<template>
  <div class="page" :width="1920" :height="1080">
    <!-- 顶部横排:受控 active + @change,与 qtx-tabs 共用同一个 current -->
    <qtx-channel-nav
      :width="1920"
      :height="132"
      :items="channels"
      :active="current"
      orientation="horizontal"
      @change="onChannelChange"
      @focus="onChannelFocus"
    />
    <qtx-tabs :width="1920" :height="700" :active="current" animationDirection="horizontal">
      <qtx-tab-content :width="1920" :height="700" />
    </qtx-tabs>

    <!-- 左侧竖排:v-model:active 语法糖,同一份数据、同一个 current -->
    <qtx-channel-nav
      :width="260"
      :height="1080"
      :items="channels"
      v-model:active="current"
      orientation="vertical"
      @focus="onChannelFocus"
    />
    <qt-text :width="600" :height="48" :text="focusLine" />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

// 频道数据一次性准备好;数组顺序即遥控器遍历顺序。
const channels = [
  { key: 'home', label: '首页' },
  { key: 'series', label: '电视剧' },
  { key: 'variety', label: '综艺' },
  { key: 'movie', label: '电影' },
  { key: 'kids', label: '少儿' },
  { key: 'doc', label: '纪录片' },
];

const current = ref('home');
const focusLine = ref('焦点: 尚未进入频道栏');

// 只更新受控值,频道栏与 qtx-tabs 永远同源。
function onChannelChange(key: string) {
  current.value = key;
}

function onChannelFocus(key: string) {
  focusLine.value = `焦点: ${key}`;
}
</script>

示例同时给出横排与竖排,并通过同一个 current 驱动 qtx-tabs;横排演示受控 active 加 @change,竖排演示 v-model:active。

vue
<template>
  <div class="page" :width="1920" :height="1080">
    <!-- 整栏尺寸由 width / height 决定;内容尺寸由 itemWidth / itemHeight / gap 决定。
         下面每条整栏 1400×96,6 个频道共 6×118 + 5×8 = 748px,剩余 652px 交给 align 分配。 -->
    <qt-text :width="1400" :height="30" text="整栏 1400×96 / 内容 748px:align 分配剩余 652px" />

    <!-- ① start(默认):频道贴左,留白全在右侧 -->
    <qtx-channel-nav
      :width="1400" :height="96" :items="channels" :active="current"
      align="start" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12"
      normalBg="#F2F4F7" normalText="#3C4A5A"
      selectedBg="#2E6BE6" selectedText="#FFFFFF"
      @change="onChange"
    />

    <!-- ② center:整组居中,左右各留 326px -->
    <qtx-channel-nav
      :width="1400" :height="96" :items="channels" :active="current"
      align="center" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />

    <!-- ③ end:整组贴右 -->
    <qtx-channel-nav
      :width="1400" :height="96" :items="channels" :active="current"
      align="end" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />

    <!-- ④ space-between:首尾贴边,额外间距只在项间均分 -->
    <qtx-channel-nav
      :width="1400" :height="96" :items="channels" :active="current"
      align="space-between" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />

    <!-- ⑤ space-around:每项两侧各分到一半间距,首尾留白是项间的一半 -->
    <qtx-channel-nav
      :width="1400" :height="96" :items="channels" :active="current"
      align="space-around" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />

    <!-- ⑥ space-evenly:首尾与项间完全等距 -->
    <qtx-channel-nav
      :width="1400" :height="96" :items="channels" :active="current"
      align="space-evenly" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />

    <!-- crossAlign 控制横排的垂直方向:整栏高 160、单项高 64,剩余 96px -->
    <qt-text :width="1400" :height="30" text="crossAlign:整栏 160 高 / 单项 64 高,剩余 96px 放在垂直方向" />
    <qtx-channel-nav
      :width="1400" :height="160" :items="channels" :active="current"
      align="center" crossAlign="center" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />
    <qtx-channel-nav
      :width="1400" :height="160" :items="channels" :active="current"
      align="center" crossAlign="end" :itemWidth="118" :itemHeight="64" :gap="8"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />

    <!-- 竖排时两轴互换:align 作用于垂直轴,crossAlign 作用于水平轴 -->
    <qt-text :width="1400" :height="30" text="竖排:整栏 260×720,align=center 垂直居中,crossAlign=center 水平居中" />
    <qtx-channel-nav
      :width="260" :height="720" :items="channels" :active="current"
      orientation="vertical" align="center" crossAlign="center"
      :itemWidth="200" :itemHeight="64" :gap="10"
      :fontSize="22" :borderRadius="12" @change="onChange"
    />

    <!-- gravity 只作用于项内文字,不移动频道序列本身 -->
    <qt-text :width="1400" :height="30" :text="status" />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

// 6 个频道,内容总宽 748px,明显小于 1400px 整栏,适合观察对齐效果。
const channels = [
  { key: 'home', label: '首页' },
  { key: 'series', label: '电视剧' },
  { key: 'variety', label: '综艺' },
  { key: 'movie', label: '电影' },
  { key: 'kids', label: '少儿' },
  { key: 'doc', label: '纪录片' },
];

const current = ref('home');
const status = ref('align / crossAlign 移动整组频道;gravity 只改项内文字对齐');

function onChange(key: string) {
  current.value = key;
  status.value = `change: ${key}`;
}
</script>

对齐示例逐条给出 6 种 align、3 种 crossAlign 与竖排两轴互换,是下一节的可运行对照。

vue
<template>
  <div class="page" :width="1920" :height="1080">
    <!-- ① TV 首页左侧竖排:SVG 图标 + 文字,与 qtx-tabs 共用同一个 current -->
    <qtx-channel-nav
      :width="280"
      :height="900"
      :items="channels"
      :active="current"
      :focusedKey="focusedKey"
      orientation="vertical"
      :itemWidth="248"
      :itemHeight="72"
      :gap="10"
      :itemPadding="18"
      :iconMargin="16"
      :fontSize="24"
      :borderRadius="16"
      :iconSize="30"
      iconPosition="left"
      :indicator="'bar'"
      :indicatorSize="6"
      indicatorColor="#22C55E"
      :maxPoolSize="20"
      scrollMode="center"
      @change="onChange"
      @focus="onFocus"
    />

    <qtx-tabs :width="1600" :height="900" :active="current">
      <qtx-tab-content tabKey="home"><qt-text :width="1600" :height="60" text="内容区:首页" /></qtx-tab-content>
      <qtx-tab-content tabKey="series"><qt-text :width="1600" :height="60" text="内容区:电视剧" /></qtx-tab-content>
      <qtx-tab-content tabKey="variety"><qt-text :width="1600" :height="60" text="内容区:综艺" /></qtx-tab-content>
      <qtx-tab-content tabKey="movie"><qt-text :width="1600" :height="60" text="内容区:电影" /></qtx-tab-content>
    </qtx-tabs>

    <!-- ② 图标在上 + 浅色主题:竖排时 align 作用于垂直轴、crossAlign 作用于水平轴 -->
    <qtx-channel-nav
      :width="280"
      :height="720"
      :items="shortChannels"
      :active="current"
      orientation="vertical"
      align="center"
      crossAlign="center"
      :itemWidth="240"
      :itemHeight="96"
      :gap="12"
      :fontSize="20"
      :borderRadius="12"
      :iconSize="28"
      iconPosition="top"
      normalBg="#F2F4F7"
      normalText="#3C4A5A"
      focusBorderColor="#2E6BE6"
      selectedBg="#2E6BE6"
      selectedText="#FFFFFF"
      scrollMode="none"
      @change="onChange"
    />

    <!-- ③ 长列表 + 反序 + 角标 / 禁用项 -->
    <qtx-channel-nav
      :width="280"
      :height="720"
      :items="richChannels"
      :active="current"
      orientation="vertical"
      :reverseLayout="true"
      :itemWidth="252"
      :itemHeight="64"
      :gap="8"
      :iconSize="24"
      :maxPoolSize="32"
      :focusMemory="true"
      badgeBg="#EF4444"
      badgeText="#FFFFFF"
      disabledBg="#14181E"
      disabledText="#4A5560"
      @change="onChange"
    />

    <qt-text :width="1200" :height="48" :text="status" />
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

// 内联 SVG 与 qtx-grid-tabs 竖排导航一样走 SvgImageView:
// data:image/svg+xml / http / file / hpfile / *.svg → loadSvgFromUrl,
// asset://xxx.svg → loadSvgFromAsset。
const ICON_COLORS = ['FFD479', '7DD3FC', 'A78BFA', '34D399', 'FB7185'];
function svgIcon(index: number): string {
  const color = ICON_COLORS[index % ICON_COLORS.length];
  return 'data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32">'
    + '<circle cx="16" cy="16" r="11" fill="%23' + color + '"/></svg>';
}

const KEYS = ['home', 'series', 'variety', 'movie', 'kids', 'doc', 'sports', 'anime'];
const NAMES = ['首页', '电视剧', '综艺', '电影', '少儿', '纪录片', '体育', '动漫'];
const channels = NAMES.map((label, i) => ({
  key: KEYS[i],
  label,
  icon: svgIcon(i),
  payload: { index: i },
}));

// 只有 5 个频道,整栏 720 高明显放不满,便于观察 align="center" 的垂直居中
const shortChannels = channels.slice(0, 5);

const richChannels = NAMES.concat(['音乐', '游戏', '资讯', '会员']).map((label, i) => ({
  key: i === 0 ? 'home' : 'c' + String(i).padStart(2, '0'),
  label,
  icon: svgIcon(i),
  badge: i % 4 === 2 ? '新' : '',
  disabled: i === 5,
  payload: { index: i },
}));

const current = ref('home');
const focusedKey = ref('home');
const status = ref('就绪 · 用方向键上下移动焦点、确认键切频道');
let focusIndex = 0;

function onChange(key: string) {
  current.value = key;
  status.value = `change: ${key}`;
}
function onFocus(key: string) {
  status.value = `focus: ${key}`;
}

// ES/Hippy 把方向键作为 DispatchKeyEvent 派发给页面,native view 收不到按键:
// 由页面维护焦点索引,回写受控 focusedKey 驱动频道栏三态。
function onKeyDown(e: any): void {
  if (!e || Number(e.action) !== 0) return;
  const code = Number(e.keyCode);
  const step = code === 20 ? 1 : code === 19 ? -1 : 0; // DPAD_DOWN / UP
  if (!step) {
    if (code === 66 || code === 23) onChange(focusedKey.value); // ENTER / DPAD_CENTER
    return;
  }
  focusIndex = Math.max(0, Math.min(channels.length - 1, focusIndex + step));
  focusedKey.value = channels[focusIndex].key;
  status.value = `focus: ${focusedKey.value}`;
}
</script>

竖排示例给出 TV 首页左侧频道栏的完整形态:内联 SVG 图标 + 文字、qtx-tabs 同源联动、图标在上、两轴对齐、长列表反序与角标 / 禁用项。真机上还有独立的「频道导航(竖排专项)」页,六栏并排穷举上述组合。

整栏尺寸与对齐 ​

三组尺寸口径 ​

属性作用说明
width / height整栏尺寸组件占位的宽高(px),也是对齐计算的基准;必须显式声明
itemWidth / itemHeight / gap单项尺寸决定频道序列的内容总尺寸,不影响整栏占位
paddingLeft / paddingTop / paddingRight / paddingBottom栏内边距先于对齐从可用空间里扣除

native 侧按下面的公式计算剩余空间,剩余 ≤ 0 时不做任何对齐、保持原有滚动与焦点居中行为:

主轴内容 = 频道数 × 单项主轴尺寸 + (频道数 - 1) × gap
主轴剩余 = 整栏主轴尺寸 - 主轴两侧 padding - 主轴内容
交叉轴剩余 = 整栏交叉轴尺寸 - 交叉轴两侧 padding - 单项交叉轴尺寸

横排时主轴是水平轴、交叉轴是垂直轴;竖排时两者互换(主轴 = 垂直轴,交叉轴 = 水平轴)。

align(主轴对齐) ​

取值剩余空间分配
start全部留在末尾,频道贴起始边
center(默认)首尾各留一半,整组居中
end全部留在开头,频道贴结束边
space-between首尾贴边,剩余只在项间均分
space-around每项两侧各分一半间距,首尾留白为项间的一半
space-evenly首尾与项间完全等距

space-* 是在 gap 基础上追加额外间距,不是替换 gap。

crossAlign(交叉轴对齐) ​

取值横排表现竖排表现
start频道项靠整栏顶部频道项靠整栏左侧
center(默认)频道项在整栏内垂直居中频道项在整栏内水平居中
end频道项靠整栏底部频道项靠整栏右侧

与 gravity 的区别 ​

gravity 只决定频道项内部「图标 + 文字」这组内容靠左 / 居中 / 靠右,不改变频道项在整栏中的位置。align / crossAlign 默认都是 center,不写任何对齐属性时整组频道就在整栏内居中;要贴左 / 贴顶写 align="start" / crossAlign="start"。只写 gravity="center"(本身也是默认值)不会移动任何频道。getState() 返回的 align / crossAlign / alignLeading / alignBetween / alignCross 可直接观测当前对齐偏移,gap / itemPadding / iconMargin 可直接核对当前间距。

竖排导航与 SVG 图标 ​

orientation="vertical" 即左侧竖排,两根轴互换:align 管上下、crossAlign 管左右;itemHeight 是纵向每项高度、itemWidth 是横向宽度;gap 变成纵向间距;reverseLayout 变成从下往上排列。焦点跟随滚动居中同样切换到垂直轴。

图标通道 ​

items[].icon 由 SvgImageView 渲染,与站内 qtx-grid-tabs 的竖排导航同一套解析口径:

取值加载方式
data:image/svg+xml,... / data:image/svg+xml;base64,...loadSvgFromUrl(内联 SVG,无需资源文件)
http(s):// / file:// / hpfile:// / *.svgloadSvgFromUrl
asset://xxx.svg / assets://xxx.svgloadSvgFromAsset

iconSize 控制图标尺寸(设为 0 隐藏);iconPosition 取 left / top / right / bottom,横竖排都生效。图标加载失败会被静默忽略,不影响文字与焦点。普通位图与已安装应用图标不在本组件能力内。

itemPadding 是频道项内容区的四边内边距(默认 16),iconMargin 是图标与文字之间的间距(默认 16,作用在 iconPosition 对应的方向)。默认值已按上线页面调过,带图标直接用即可;只有要做更紧凑的左侧竖排时才覆盖,例如:

vue
<qtx-channel-nav
  :items="channels" :active="current" orientation="vertical"
  :iconSize="30" iconPosition="left"
  :itemWidth="200" :gap="16" :iconMargin="12"
/>

同一 icon 地址只会加载一次:焦点切换、items 同值重发、样式刷新都不会重新清空并异步重载 SVG,因此不会出现「切换频道时图标闪一下」。只有 items[].icon 的值真的变了才会重新加载。

焦点前提与 focusedKey ​

ES/Hippy 把方向键作为 DispatchKeyEvent 派发给页面 onKeyDown,不会把按键交给 native 自定义 View,所以不能指望 Android 原生焦点链去移动 native RecyclerView 的频道项。正确的做法是在页面 onKeyDown 里维护焦点索引,回写组件的受控属性 focusedKey:

ts
const focusedKey = ref('home');
let focusIndex = 0;
function onKeyDown(e: any): void {
  if (!e || Number(e.action) !== 0) return; // 只处理 ACTION_DOWN
  const code = Number(e.keyCode);
  const step = code === 20 ? 1 : code === 19 ? -1 : 0; // DPAD_DOWN / UP
  if (!step) return;
  focusIndex = Math.max(0, Math.min(channels.length - 1, focusIndex + step));
  focusedKey.value = channels[focusIndex].key;
}
// 模板:<qtx-channel-nav :items="channels" :focusedKey="focusedKey" ... />

focusedKey 变化会即时刷新三态(默认焦点为白色 focusBg 胶囊)、派发 @focus / @blur 并把该项滚动到可见区域。页面仍应保留至少一个 :autofocus="true" 的可获焦节点(如返回按钮)作为 Hippy 焦点树的起点。同页挂多个频道栏时,建议只给其中一栏传 focusedKey,避免多栏同时显示焦点态。

反例:整页只有 qt-text + 频道栏、又没有任何 onKeyDown → logcat 只见 div requestFocus return false,按方向键画面完全不变。

竖排常见组合 ​

场景建议配置
TV 首页左侧频道栏iconSize=30 + iconPosition="left" + indicator="bar" + scrollMode="center"
图标在上、频道较少iconPosition="top" + 更大的 itemHeight(建议 ≥ 96)+ align="center"
少量频道垂直 / 水平居中align="center" + crossAlign="center" + scrollMode="none"
长频道栏(20+ 项)调大 maxPoolSize(如 32)+ focusMemory=true,scrollMode="center" 保持焦点可见
角标与禁用项items[].badge / disabled,配 badgeBg / badgeText / disabledBg / disabledText
从下往上排列reverseLayout=true,注意焦点遍历顺序也随之反转

遥控器确认键的官方接线 ​

ES/Hippy 把方向键与确认键作为 DispatchKeyEvent 派发给页面 onKeyDown,native 自定义 View 收不到按键,因此页面 onKeyDown 不能删除。正确接线是把它收敛成两件事:方向键维护焦点索引并回写受控 focusedKey,确认键调用组件 expose 的 setActive(focusedKey)。setActive 会回传 native onChange,由 Vue 壳统一派发 @change。

因此业务只需监听 @change 一个事件,无需同时监听 @onChange、也无需自己维护载荷兼容函数。@onChange 是 native 原始载荷透传,仅在需要 position / previous / item 时才使用。整栏自行获焦、不使用页面 onKeyDown 时,native 也会在 OK / ENTER 时派发 onChange,两条路径最终都汇到 @change;selectOnFocus=true 时焦点移动即派发 change,无需确认键。

vue
<template>
  <!-- 遥控器确认键的官方接线:页面 onKeyDown 只维护焦点,选中一律收敛到单一 @change。 -->
  <div class="page" :width="1920" :height="1080">
    <qtx-channel-nav
      ref="navRef" :width="1920" :height="96"
      :items="channels" :active="current" :focusedKey="focusedKey"
      orientation="horizontal" :itemWidth="160" :itemHeight="72" :gap="12"
      @change="onChannelChange"
    />

    <qtx-tabs :width="1920" :height="984" :active="current" :offscreen="2" :maxInstances="4">
      <qtx-tab-content tabKey="home" :width="1920" :height="984">
        <qt-text text="首页内容区" :width="1920" :height="984" class="body" />
      </qtx-tab-content>
      <qtx-tab-content tabKey="series" :width="1920" :height="984">
        <qt-text text="剧集内容区" :width="1920" :height="984" class="body" />
      </qtx-tab-content>
      <qtx-tab-content tabKey="movie" :width="1920" :height="984">
        <qt-text text="电影内容区" :width="1920" :height="984" class="body" />
      </qtx-tab-content>
    </qtx-tabs>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';

const navRef = ref<any>(null);
const channels = [
  { key: 'home', label: '首页' },
  { key: 'series', label: '电视剧' },
  { key: 'movie', label: '电影' },
];
const current = ref('home');
const focusedKey = ref('home');
let focusIndex = 0;

// 唯一需要监听的事件:@change。确认键由 setActive 转成它,不需要 @onChange 双监听。
function onChannelChange(key: string) {
  current.value = key;
  focusedKey.value = key;
  focusIndex = Math.max(0, channels.findIndex((c) => c.key === key));
}

// ES/Hippy 把按键作为 DispatchKeyEvent 派发给页面 onKeyDown,native 自定义 View
// 收不到按键,因此页面 onKeyDown 不能删。方向键维护焦点,确认键只调 setActive。
function onKeyDown(e: any): void {
  if (!e || Number(e.action) !== 0) return;
  const code = Number(e.keyCode);
  const step = code === 22 ? 1 : code === 21 ? -1 : 0;
  if (step) {
    focusIndex = Math.max(0, Math.min(channels.length - 1, focusIndex + step));
    focusedKey.value = channels[focusIndex].key;
    return;
  }
  if (code === 23 || code === 66) { // DPAD_CENTER / ENTER
    navRef.value?.setActive?.(focusedKey.value);
  }
}
</script>

<style scoped>
.page { width: 1920px; height: 1080px; background-color: #101418; flex-direction: column; }
.body { font-size: 36px; color: #FFFFFF; text-align: center; }
</style>

与 qtx-tabs 的底层联动(linkId) ​

给 qtx-channel-nav 与 qtx-tabs 写同一个 linkId,两个容器就在 native 层登记为一组。此后焦点移动到某个频道时,native 直接完成选中态更新与 tab 切换,再向页面派发 change;页面不必在 onKeyDown 里判断并回写 active 来驱动内容区。

vue
<qtx-channel-nav :items="channels" :active="current" :focusedKey="focusedKey"
  linkId="home" @change="onChannelChange" />
<qtx-tabs :active="current" linkId="home" :offscreen="2" :maxInstances="4">
  <qtx-tab-content tabKey="history" :width="1920" :height="948"><!-- 该屏内容 --></qtx-tab-content>
  <qtx-tab-content tabKey="local" :width="1920" :height="948"><!-- 该屏内容 --></qtx-tab-content>
</qtx-tabs>
  • 页面 onKeyDown 仍然不能删,但只负责维护 focusedKey;切换由组件完成。
  • @change(key, payload) 仍然要监听:数据加载、返回栈、按 tabId 保存排序 / 布局 / 焦点 / 滚动位、埋点都依赖它。payload.source 为 focus(焦点移动)、click(确认或点击)、api(程序化调用)、back(返回归位)。回调里把 current 写成 key 是同值回写,不会重复触发切换。
  • 写 linkId 即默认「焦点移动即切 Tab」,不需要再写 selectOnFocus;selectOnFocus 只作用于未建立关系的独立频道栏。不写 linkId 时行为与旧版完全一致。
  • 连续方向键在短窗内合并成最后一次切换,避免逐个 tab 懒创建与加载。
  • 上层 API 仍然可用:navRef.setActive(key) 可程序化驱动整组切换(事件的 source 为 api)。
  • ES/Hippy 把方向键派给页面时,「按键 → JS → focusedKey」这一跳仍然存在;下沉到 native 的是切换决策与 tab 驱动,不是按键采集。
vue
<template>
  <!-- nav 与 tabs 写同名 linkId:焦点移动由 native 直接切 Tab,再通知上层。
       页面 onKeyDown 只维护 focusedKey,不用自己回写 active 驱动内容区。
       顶部栏:品牌 + 频道栏居中 + 右上角动作组,不占独立工具条行。 -->
  <div class="nl-page" :width="QTX_TV.screen.width" :height="QTX_TV.screen.height">
    <div class="nl-top" :width="QTX_TV.screen.width" :height="QTX_TV.navHeight">
      <qt-text text="QTX TV" :width="QTX_TV.brand.width" :height="QTX_TV.brand.height" class="nl-brand" />
      <div class="nl-top-gap-left" :width="gaps.left" :height="QTX_TV.navBarHeight" />
      <qtx-channel-nav ref="navRef"
        :width="QTX_TV.channelNav.width" :height="QTX_TV.navBarHeight" :items="channels"
        :active="current" :focusedKey="focusedKey" linkId="home"
        :focusWithin="navFocused"
        initialActiveKey="history" initialFocusKey="history"
        @change="onChannelChange" @focus="onNavFocus" @blur="onContentFocus" />
      <div class="nl-top-gap-right" :width="gaps.right" :height="QTX_TV.navBarHeight" />
      <div class="nl-actions" :width="gaps.groupWidth" :height="QTX_TV.navBarHeight">
        <qtx-button text="搜索" :width="QTX_TV.action.width" :height="QTX_TV.action.height" :focusable="true" @click="onSearch" />
        <div class="nl-act-gap" :width="QTX_TV.action.gap" :height="QTX_TV.action.height" />
        <qtx-button text="筛选" :width="QTX_TV.action.width" :height="QTX_TV.action.height" :focusable="true" @click="onFilter" />
      </div>
    </div>

    <qtx-tabs :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight" :active="current"
      linkId="home" :offscreen="2" :maxInstances="4">

      <qtx-tab-content tabKey="history" :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight"
        :focusable="true" @focus="onContentFocus">
        <qtx-list decoration="tv" class="nl-feed" poolKey="home" :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight"
          :items="historyRows" :columns="COLUMNS" key-field="id" @item-click="onItemClick">
          <template #item="{ item }">
            <div class="nl-cell" :width="540" :height="200">
              <qt-text :text="item.title" :width="540" :height="200" class="nl-cell-t" />
            </div>
          </template>
        </qtx-list>
      </qtx-tab-content>

      <qtx-tab-content tabKey="local" :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight"
        :focusable="true" @focus="onContentFocus">
        <qtx-list decoration="tv" class="nl-feed" poolKey="home" :width="QTX_TV.screen.width" :height="QTX_TV.contentHeight"
          :items="localRows" :columns="COLUMNS" key-field="id" @item-click="onItemClick">
          <template #item="{ item }">
            <div class="nl-cell" :width="540" :height="200">
              <qt-text :text="item.title" :width="540" :height="200" class="nl-cell-t" />
            </div>
          </template>
        </qtx-list>
      </qtx-tab-content>
    </qtx-tabs>
  </div>
</template>

<script setup lang="ts">
import { ref } from 'vue';
import { useESRouter } from '@extscreen/es3-router';
import { QTX_TV, qtxTvTopGaps } from '@quicktvui/qtx';

const router = useESRouter();
const navRef = ref<any>(null);

// 尺寸全部取自包级主题 QTX_TV(@quicktvui/qtx),页面不再自抄常量表。
// 本页只保留两个「页面级选择」:动作按钮数量 2、栅格列数 3。
const gaps = qtxTvTopGaps(2);   // 2 个按钮时,频道栏居中的左右 gap 由主题自动反推
const COLUMNS = 3;              // 本页选 3 列(主题默认 6),只影响这一页

// 焦点区域:内容区拿焦点时置 false,nav 不再显示白色胶囊、也不再响应左右键
const navFocused = ref(true);
function onNavFocus() { navFocused.value = true; }
function onContentFocus() { navFocused.value = false; }

const channels = [
  { key: 'history', label: '历史' },
  { key: 'local', label: '本地目录' },
];
const current = ref('history');
const focusedKey = ref('history');
const focusIndex = ref(0);

function makeRows(prefix: string): Array<{ id: string; title: string }> {
  const rows: Array<{ id: string; title: string }> = [];
  for (let i = 0; i < 12; i++) {
    rows.push({ id: `${prefix}-${i}`, title: `${prefix} 卡片 ${i + 1}` });
  }
  return rows;
}
const historyRows = makeRows('历史');
const localRows = makeRows('本地');

/**
 * 切换已由 native 完成;这里同值回写是幂等的,
 * 业务用它做数据加载、返回栈、按 tabId 状态分桶与埋点。
 * payload.source: focus(焦点移动)/ click(确认或点击)/ api(程序化调用)
 */
function onChannelChange(key: string, payload: any) {
  current.value = key;
  loadTabData(key, payload && payload.source);
}
function loadTabData(key: string, source: string) {
  // 按 key 拉取该频道数据;source 可用于区分用户操作与程序化切换
  void key;
  void source;
}

/** 方向键只移动焦点,不切 Tab;切换由 linkId 关系在 native 内完成 */
function onKeyDown(e: any): void {
  if (!e || Number(e.action) !== 0) return;
  // 焦点在内容区时左右键属于内容区,页面不要回写 focusedKey
  if (!navFocused.value) return;
  const code = Number(e.keyCode);
  let step = 0;
  if (code === 22 || code === 20) step = 1;
  else if (code === 21 || code === 19) step = -1;
  if (step === 0) return;
  const next = focusIndex.value + step;
  if (next < 0 || next >= channels.length) return;
  focusIndex.value = next;
  focusedKey.value = channels[next].key;
}
function onItemClick(e: any) {
  const id = e && e.item ? e.item.id : '';
  if (id) router.push({ name: 'detail', params: { id: String(id) } });
}
function onSearch() {}
function onFilter() {}
function onESCreate() {}
function onBackPressed() {
  // 三段式返回:焦点先回频道栏 → 列表回顶 → 频道归位 → 页面退出。
  // 这一行必须保留:写成空实现时,焦点落在内容区就收不到 BACK,三段式不会生效。
  if (navRef.value && navRef.value.handleBack && navRef.value.handleBack()) return;
  router.back();
}
// 宿主按精确名字取页面级回调;<script setup> 不暴露时焦点落在内容区就收不到 BACK。
defineExpose({ onBackPressed });
</script>

<style>
/* 颜色是 QTX_TV.color 的运行时镜像:编译期样式解析器不支持 CSS 变量/JS 表达式,
   只能写字面量;取值必须等于 QTX_TV.color,换主题色时同步这些字面量。 */
.nl-page { width: 1920px; height: 1080px; background-color: #0B1016; flex-direction: column; padding-left: 0px; padding-right: 0px; padding-top: 0px; padding-bottom: 0px; }
.nl-top { width: 1920px; height: 128px; flex-direction: row; align-items: center; padding-left: 116px; padding-right: 116px; padding-top: 56px; }
.nl-brand { width: 240px; height: 64px; font-size: 40px; color: #FFFFFF; }
.nl-top-gap-left { width: 244px; height: 72px; }
.nl-top-gap-right { width: 258px; height: 72px; }
.nl-actions { width: 226px; height: 72px; flex-direction: row; align-items: center; }
.nl-act-gap { width: 10px; height: 44px; }
.nl-feed { width: 1920px; background-color: #0B1016; }
.nl-cell { width: 540px; height: 200px; background-color: #2563EB; }
.nl-cell-t { width: 540px; height: 200px; font-size: 30px; color: #FFFFFF; text-align: center; }
</style>

初始位置与三段式返回 ​

组件记住进页时的初始选中位置,并默认提供三段式返回。按返回时按下面顺序判断,每次只消费一段:

优先级条件动作本次返回
①当前 Tab 的 qtx-list 已滚离顶部先把焦点请求回频道栏当前选中项(恢复焦点态白色胶囊),再把列表滚回顶部;顺序不能反,否则滚动重排会带走焦点消费
②当前选中已不在初始频道切回初始频道;建立 linkId 时内容区一起切回消费
③以上都不满足不拦截交还页面退出

第①段只作用于当前 active Tab 的那个 qtx-list,Tab 之间的滚动状态互不影响。页面不需要排优先级、不需要判断焦点在哪、也不需要给列表绑定 ref —— 组件内部按 linkId 找到当前 Tab 的列表。

页面必须保留 onBackPressed → handleBack() 这一行。本 runtime 把 BACK 作为 DispatchKeyEvent{keyCode:4} 派给 JS 页面;页面写成空实现时,只有频道栏整栏持有 Android 焦点、native 的 dispatchKeyEvent 兜底才收得到 BACK,焦点落在内容区时三段式不会生效。两条路径各用 400ms 短窗去重,不会重复消费同一次返回。

属性作用
initialActiveKey初始选中位置(频道 key);留空时自动取首次生效的 active
initialFocusKey初始焦点位置;优先于 defaultFocusKey,留空回退到 defaultFocusKey / active
disableBackToInitial关闭第②段,按返回直接进入退出判断
disableBackToTop关闭第①段,按返回直接进入第②段

页面 onBackPressed 的接线是同步的,不需要 await;三段式除此之外不需要其它接线,但这一行不能省略。宿主按精确名字从页面实例取回调,所以 <script setup> 还必须 defineExpose 把它暴露出去,否则焦点落在内容区时收不到 BACK、按返回会直接退出应用:

js
function onBackPressed() {
  if (navRef.value?.handleBack?.()) return; // 组件已消费一段
  router.back();
}
defineExpose({ onBackPressed });

handleBack(): boolean 返回 true 表示本次返回已被消费;第②段会派发 change(source 为 back)。第①段会派发 focus(焦点回到频道栏),页面若用 :focusWithin="navFocused" 维护焦点区域,可监听 @focus 把 navFocused 置回 true;焦点移出频道栏时组件会派发 blur,可监听它同步 navFocused=false。getInitialActiveKey() 可读取当前认定的初始位置。

qtx-list 的滚动状态由组件维护:手势滚动超过约 300 逻辑像素,或列表首个可见行已不是第 0 行,即视为「已滚离顶部」;回顶后状态立即归零,下一次返回进入第②段。

焦点进出频道栏的三态由组件自动处理:焦点在频道栏上时,当前项显示焦点态(白色胶囊);按方向键把焦点移到 Tab 内容区后,组件自动清掉焦点态,当前选中频道改显选中态(纯白文字),页面不需要为此回写 focusedKey 或 focusWithin。按返回第①段会把焦点重新请求回频道栏,恢复焦点态。

焦点区域与内容区方向键 ​

focusedKey 是受控属性,由页面 onKeyDown 回写来移动频道栏焦点。建立 linkId 后焦点变化会在 native 内直接切换 Tab,因此页面必须明确告诉组件「焦点是否还在频道栏」。否则焦点进入 Tab 内容区后会出现两个现象:某个非选中项残留白色胶囊(焦点态没清),以及内容区按左右键仍把频道栏切走。

用 focusWithin 绑定页面自己的焦点区域状态:

vue
<qtx-channel-nav :focusWithin="navFocused" :focusedKey="focusedKey" linkId="home"
  @focus="navFocused = true" />
<qtx-tab-content :focusable="true" @focus="navFocused = false" :width="1920" :height="948">
  <!-- 该屏内容 -->
</qtx-tab-content>
js
const navFocused = ref(true);
function onKeyDown(e) {
  if (!navFocused.value) return; // 焦点在内容区,左右键属于内容区
  // 只在 Nav 内回写 focusedKey
}

focusWithin=false 时组件会:清除焦点态(白色胶囊消失,选中项保持纯白文字)、忽略方向键与确认键、忽略上层回写的 focusedKey。上层 active / setActive() 等程序化 API 不受影响;焦点回到频道栏时把 focusWithin 改回 true。

@focus 要绑在你们页面实际获焦的节点上;若焦点树由页面自己管理,直接把那个状态绑到 focusWithin 即可。完整接线见 nav-tabs-link.vue。不写 focusWithin 时默认 true —— 组件认为焦点一直在频道栏,旧行为不变。

使用约束与易错点 ​

  • active 是受控属性。未建立 linkId 时组件只回传 key、不自行修改选中值,change 回调里要把使用方的 current 更新为 key;建立 linkId 后切换由 native 完成,change 里的同值回写是幂等的。两种写法都要求 qtx-tabs 与频道栏保持同源。
  • 三态按「焦点 > 选中 > 普通」取色:获焦项一律白底黑字,选中但失焦项是纯白文字,其余是灰白文字。不要把三态写成互斥分支,也不要假设选中底色与焦点底色会叠加。
  • 标签必须显式声明 width / height(px),否则宿主布局可能把 RecyclerView 压成 0 高度;对齐计算也依赖这两个值。
  • width / height 是整栏,itemWidth / itemHeight 是单项。把两者写反会让对齐看起来「不生效」:整栏太小、内容已超出一屏时组件会退回滚动。
  • gravity 与 align 不是一回事:前者管项内「图标 + 文字」这组内容,后者管整组频道。竖排时 align 管上下、crossAlign 管左右,横排相反。
  • padding* 会先占掉可用空间再算对齐偏移;想要精确居中,检查四边 padding 是否对称。
  • 频道数据建议在进入页面时一次性准备好。items 同值重发只会走差量比对,不会重绑可见项或重载图标;key 序列变化仍会整表刷新。
  • 方向键与确认键统一由页面 onKeyDown 处理:方向键维护焦点索引并回写受控 focusedKey,确认键在页面回调中切换频道(见上节「焦点前提与 focusedKey」);不要直接操作 native 频道项,也不在组件内重复注册按键监听,native 侧只保证每个频道项可获焦且顺序与 items 一致。
  • 选中频道有两条事件入口:@change 由 Vue 壳转发,首参为 key: string、第二参为完整载荷;@onChange 透传 native 原始载荷(key / position / previous / item)。两者载荷形状不同,按 API 页 选一条处理。
  • native 只在整栏获焦时收到确认键并派发 onChange。页面用 onKeyDown + 受控 focusedKey 自管焦点时,按键不交给 native,确认切频道应在页面回调中回写 active;点击频道项走 native 通道,selectOnFocus=true 时焦点移动即派发 change。
  • items 每项的 key 必须唯一且与 qtx-tabs 的 tabKey 同源;label 是显示文案,icon 可选。

已知边界 ​

  • linkId 的配对按名称分桶、只持弱引用:同一名称下的 nav 与 tabs 成组,不同名称(不同页面、同页多组)互不干扰。任一方尚未创建或已销毁时,切换退回原有的 JS 驱动链路,不会报错也不会重复切换。
  • 滚动居中由 native 容器在全局焦点变化时计算偏移并平滑滚动,横排按水平轴、竖排按垂直轴;方向键跨界隔离沿用了站内既有导航条的同口径实现。不同运行时上的居中时机与留白会有差异,以实机为准。
  • 运行时切换 orientation 会清掉复用池并重建布局方向,焦点位置需要重新建立;建议把方向作为进入页面时的静态配置。
  • 焦点离开频道栏进入内容区后,若无平台失焦回调,焦点态会保留在最后获焦的频道项上;这是当前焦点通道的表达方式,不影响选中态。
  • icon 走站内 SvgImageView 通道,支持内联 data URI / 网络 URL / 本地文件 / asset:// SVG 资源;普通位图与已安装应用图标不在本组件能力内。同一图标地址只加载一次,因此焦点切换与 items 同值重发不会重新加载;加载失败时该项不会自动重试,直到 items[].icon 换成另一个值。
  • 视觉默认值集中在 native 常量中,并与设计规范的可下载 token(design/android-tv-tokens.json 的 qtxRecommendations.channelNav)保持一致;全部可由 props 逐项覆盖。包级主题 QTX_TV.channelNav 是首页紧凑顶栏的独立预设,由页面显式传入,不是组件默认值。
  • 组件注册时通过 eventNamesMap 保留 onXxx 事件名;自定义 CLI 生成模板时不可移除该映射,否则 native 派发的事件会被框架静默丢弃。
  • 对齐依赖整栏尺寸测量:首次布局前整栏宽高为 0,native 在 onSizeChanged 后重算一次;运行时改变 width / height 也会重算,但同帧内立即读 getState() 可能还是上一帧的偏移。
  • space-between / space-around / space-evenly 只在频道数 ≥ 2 时才会拉开项间距;只有 1 个频道时退化为首项偏移,三种取值视觉接近。
  • 对齐偏移通过 RecyclerView.ItemDecoration 施加,不改变 item 尺寸、padding 与复用池;内容不满一屏时生效,超出一屏时自动失效,焦点跟随滚动居中仍按 item 实际位置计算。
  • Hippy 自定义 View 不走 Android 标准 measure / layout 链:宿主只给一次确定的框,运行时改 props 后 requestLayout() / notifyDataSetChanged() / invalidateItemDecorations() 都不会让可见频道项重新摆放。native 因此沿用站内 GlintPosterView / GlintBannerView 的手动排版口径,对齐值变化时直接对可见 child 调 layout(...) 摆到目标坐标;ItemDecoration 仍保留,保证后续滚动与复用时按同一偏移自动摆放。这是实现细节,不影响上层用法,但二次开发时不要删掉这段手动重排。
  • 当前已发布的 npm 包尚未包含本组件,包内清单会先于线上版本更新;发布时机由维护者决定,本组件的开发不触发版本变更。

验证状态 ​

  • 静态:文档编译门禁、示例编译、全站生成物一致性检查均通过。
  • 构建:Java 编译、组件类型声明与库构建随 npm run build 验证,npm pack --dry-run 可见 dist/components/QtxChannelNav/*.d.ts。
  • 真机:192.168.7.181:5555(Android 9)取证通过——横竖两向渲染、焦点可达与滚动居中、@change / @focus 回传、受控 active 回写、三态取色(焦点优先)、独立页面直达;align 的 start / center / end / space-between / space-around / space-evenly 与 crossAlign 的 start / center / end 均已逐项切换截图,logcat 记录 align=center leading=326、align=space-between between=130、crossAlign=end crossOffset=38 等实际计算值。
  • 竖排专项:192.168.7.181:5555 上六栏并排取证——SVG 图标在左 / 在上、角标与禁用项、两轴居中、24 项反序长列表、焦点即选中与 space-evenly;逐项证据见 docs/assets/preset-shots/channel-nav-vertical-*.png 与 docs/QTX_CHANNEL_NAV_REPORT.md。

API 参考 ​

以下表格由 npm run docs:gen 从源码生成,禁止手工编辑;完整独立页见 ChannelNav 频道导航 API。

属性(Props · 51) ​

属性名类型必填默认值说明事实源
activestring否``当前选中频道 key,默认 '';受控属性,组件不自行修改ts-types+vue-sfc+java
align'start' | 'center' | 'end' | 'space-between' | 'space-around' | 'space-evenly' | string否center频道序列在整栏内的主轴对齐;横排=水平轴、竖排=垂直轴,默认 centerts-types+vue-sfc+java
badgeBgstring否#E5484D角标底色,默认 #E5484Dts-types+vue-sfc+java
badgeTextstring否#FFFFFF角标文字色,默认 #FFFFFFts-types+vue-sfc+java
borderRadiusnumber否36单项圆角(px),默认 36;配合白色焦点底形成胶囊ts-types+vue-sfc+java
crossAlign'start' | 'center' | 'end' | string否center频道项在整栏内的交叉轴对齐;横排=垂直轴、竖排=水平轴,默认 centerts-types+vue-sfc+java
defaultFocusKeystring否``首次进入时默认获焦的频道 key,默认 ''(回退到当前 active)ts-types+vue-sfc+java
disableBackToInitialboolean否false关闭「返回先归位」:默认开启归位,写该属性则按返回直接交给页面处理ts-types+vue-sfc+java
disableBackToTopboolean否false关闭三段式返回的第①段(列表滚离顶部时先回顶);默认开启。关闭后按返回直接进入频道归位ts-types+vue-sfc+java
disabledBgstring否#00000000禁用项底色,默认透明 #00000000ts-types+vue-sfc+java
disabledTextstring否#5A6675禁用项文字色,默认 #5A6675ts-types+vue-sfc+java
focusableboolean否true频道项是否可获焦,默认 true;关闭后只展示不参与遥控器焦点ts-types+vue-sfc+java
focusBgstring否#FFFFFF获焦态底色,默认白色圆角胶囊 #FFFFFFts-types+vue-sfc+java
focusBorderColorstring否#FFFFFF焦点描边颜色,默认 #FFFFFF;仅 focusBorderWidth 大于 0 时生效ts-types+vue-sfc+java
focusBorderWidthnumber否0焦点描边宽度(px),默认 0;白色焦点底已是强指示,需要描边时调大ts-types+vue-sfc+java
focusedKeystring否''受控焦点频道 key;ES 把方向键派发给页面 onKeyDown,由上层回写此属性驱动焦点态ts-types+vue-sfc+java
focusMemoryboolean否true数据更新后恢复之前的焦点项,默认 true,避免写操作后丢焦点ts-types+vue-sfc+java
focusTextstring否#141922获焦态文字色,默认近黑 #141922ts-types+vue-sfc+java
focusWithinboolean否true焦点是否属于频道栏;传 false 时清除焦点态(白色胶囊消失、选中项保持纯白文字)并忽略方向键与受控 focusedKey,避免内容区左右键误切 Tab。默认 truets-types+vue-sfc+java
fontSizenumber否28频道文字默认粗体;字号(px),默认 28ts-types+vue-sfc+java
gapnumber否24项间距(px),默认 24ts-types+vue-sfc+java
gravity'start' | 'center' | 'end' | string否center图标与文字组成的整组内容在项内对齐 start / center / end,默认 center(不移动频道序列)ts-types+vue-sfc+java
heightnumber | string否-整栏高度(px);显式声明可避免宿主布局把容器压成 0,也是 crossAlign 计算的基准ts-types
iconMarginnumber否16图标与频道文字之间的间距(px),随 iconPosition 作用于对应方向,默认 16ts-types+vue-sfc+java
iconPosition'left' | 'top' | 'right' | 'bottom' | string否left图标相对文字的位置 left / top / right / bottom,默认 leftts-types+vue-sfc+java
iconSizenumber否32图标尺寸(px),默认 32;设为 0 隐藏图标ts-types+vue-sfc+java
indicator'none' | 'underline' | 'bar' | string否none选中指示器 none / underline / bar,默认 nonets-types+vue-sfc+java
indicatorColorstring否#FFFFFF选中指示器颜色,默认 #FFFFFFts-types+vue-sfc+java
indicatorSizenumber否6选中指示器厚度(px),默认 6ts-types+vue-sfc+java
initialActiveKeystring否''初始选中位置(频道 key);在频道栏上按返回时若当前不在该位置,先回到这里。留空时自动记首次生效的 activets-types+vue-sfc+java
initialFocusKeystring否''初始焦点位置(频道 key);优先于 defaultFocusKey,留空时回退到 defaultFocusKey / activets-types+vue-sfc+java
itemHeightnumber否72单项高度(px),默认 72ts-types+vue-sfc+java
itemPaddingnumber否16频道项内容区内边距(px),四边统一;避免图标/文字贴着 item 边缘,默认 16ts-types+vue-sfc+java
itemsQtxChannelNavItem[]否[]频道数据,默认 [];数组顺序即遥控器遍历顺序ts-types+vue-sfc+java
itemWidthnumber否240单项宽度(px),默认 240;按「图标 + 4~6 字频道名」给出,不写也不会截断ts-types+vue-sfc+java
linkIdstring否''与 qtx-tabs 建立底层联动的关系标识,两边写同名即成组;建立关系后焦点移动由 native 直接驱动 tab 切换再通知上层。焦点即切由关系本身提供,selectOnFocus 仅作用于独立频道栏ts-types+vue-sfc+java
maxPoolSizenumber否16复用池容量上限(1~128),默认 16;长列表调大可减少创建次数ts-types+vue-sfc+java
normalBgstring否#00000000普通态底色,默认透明 #00000000ts-types+vue-sfc+java
normalTextstring否#C2CAD4普通态文字色,默认非纯白的灰白 #C2CAD4ts-types+vue-sfc+java
orientation'horizontal' | 'vertical' | string否horizontal布局方向,默认 horizontal(顶部横排),vertical 为左侧竖排ts-types+vue-sfc+java
paddingBottomnumber否0栏内下内边距(px),默认 0ts-types+vue-sfc+java
paddingLeftnumber否0栏内左内边距(px),默认 0ts-types+vue-sfc+java
paddingRightnumber否0栏内右内边距(px),默认 0ts-types+vue-sfc+java
paddingTopnumber否0栏内上内边距(px),默认 0ts-types+vue-sfc+java
reverseLayoutboolean否false反转排列方向:横排从右往左、竖排从下往上,默认 falsets-types+vue-sfc+java
scrollMode'center' | 'edge' | 'none' | string否center滚动策略 center / edge / none,默认 center(焦点项自动居中)ts-types+vue-sfc+java
selectedBgstring否#00000000选中态底色,默认透明 #00000000;选中只提亮文字,不靠色块ts-types+vue-sfc+java
selectedTextstring否#FFFFFF选中态文字色,默认纯白 #FFFFFFts-types+vue-sfc+java
selectOnFocusboolean否false焦点移动即切换选中频道,默认 false;开启后仍派发 changets-types+vue-sfc+java
smoothScrollboolean否true命令式滚动是否使用平滑动画,默认 truets-types+vue-sfc+java
widthnumber | string否-整栏宽度(px);显式声明可避免宿主布局把容器压成 0,也是 align 计算的基准ts-types

事件(Events · 11) ​

事件名载荷参数说明事实源
@blurkey: string, payload: QtxChannelNavEventPayload-vue-sfc
@changekey: string, payload: QtxChannelNavEventPayload-ts-types+vue-sfc
@focuskey: string, payload: QtxChannelNavEventPayload-vue-sfc
@longClickkey: string, payload: QtxChannelNavEventPayload-vue-sfc
@onBlurpayload?: any焦点离开某个频道时触发;载荷含 key / positionvue-sfc+java
@onChangepayload?: any确认某个频道时触发;载荷含 key / position / previous / item,组件不自行修改受控 activevue-sfc+java
@onFocuspayload?: any遥控器焦点落到某个频道时触发;载荷含 key / position / itemvue-sfc+java
@onLongClickpayload?: any长按某个频道时触发;载荷含 key / position / itemvue-sfc+java
@onScrollpayload?: any首个可见项变化时触发;载荷含 first / last,便于业务统计曝光vue-sfc+java
@scrollpayload: QtxChannelNavScrollPayload-vue-sfc
@update:activekey: string-vue-sfc

方法(Methods / Expose · 18) ​

方法名参数返回值说明事实源
clearFocus—Promise<string>清除频道栏焦点与焦点态ts-types+vue-sfc+java
focusBack——-vue-sfc+java
getActiveKey—Promise<string>读取当前选中频道 keyts-types+vue-sfc+java
getFocusedKey—Promise<string>读取当前获焦频道 keyts-types+vue-sfc+java
getInitialActiveKey—Promise<string>读取初始选中位置(频道 key)ts-types+vue-sfc+java
getItemAtindex: numberPromise<QtxChannelNavItem>按位置读取单个频道项ts-types+vue-sfc+java
getItemCount—Promise<number>读取频道总数ts-types+vue-sfc+java
getNativeNode—any取到底层原生节点,供高级场景直接调用ts-types+vue-sfc
getScrollState—Promise<QtxChannelNavState>读取可见区间与滚动状态快照ts-types+vue-sfc+java
getState—Promise<QtxChannelNavState>读取完整状态快照ts-types+vue-sfc+java
handleBack—boolean三段式返回(同步,页面 onBackPressed 必须调用):焦点先回频道栏再把列表滚回顶部 → 频道归位 → 交还页面;返回本次是否消费ts-types+vue-sfc+java
if——-vue-sfc
requestFocus—Promise<string>把遥控器焦点请求到当前选中频道ts-types+vue-sfc+java
scrollToKeykey: stringPromise<string>滚动到指定频道 keyts-types+vue-sfc+java
setActivekey: stringvoid命令式设置选中频道,并回传 change 供上层同步受控值ts-types+vue-sfc+java
setOrientationorientation: 'horizontal' | 'vertical' | stringPromise<string>运行时切换横竖方向,内部清池并重建布局ts-types+vue-sfc+java
setStyletokens: Partial<QtxChannelNavProps>Promise<string>批量覆盖视觉 token,避免逐个 prop 触发多次刷新ts-types+vue-sfc+java
updateItemsitems: QtxChannelNavItem[]Promise<string>差量更新频道数据;key 序列不变时只刷新内容变化的项ts-types+vue-sfc+java

插槽(Slots · 2) ​

插槽名说明事实源
default默认内容插槽,承载组件子内容js/qtx/src/components/QtxChannelNav/QtxChannelNav.vue
item列表行模板插槽,作用域参数包含 item / indexdocs-site/components/qtx-channel-nav/examples/nav-tabs-link.vue

API 事实由源码自动生成 · 请勿手工编辑